Jiri Benc | f0706e82 | 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> |
Felix Fietkau | 888d04d | 2012-03-01 15:22:09 +0100 | [diff] [blame] | 12 | #include <linux/etherdevice.h> |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 13 | #include <linux/netdevice.h> |
| 14 | #include <linux/types.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/skbuff.h> |
| 17 | #include <linux/if_arp.h> |
Johannes Berg | 0d17440 | 2007-12-17 15:07:43 +0100 | [diff] [blame] | 18 | #include <linux/timer.h> |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 19 | #include <linux/rtnetlink.h> |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 20 | |
| 21 | #include <net/mac80211.h> |
| 22 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 23 | #include "driver-ops.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 24 | #include "rate.h" |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 25 | #include "sta_info.h" |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 26 | #include "debugfs_sta.h" |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 27 | #include "mesh.h" |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 28 | #include "wme.h" |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 29 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 30 | /** |
| 31 | * DOC: STA information lifetime rules |
| 32 | * |
| 33 | * STA info structures (&struct sta_info) are managed in a hash table |
| 34 | * for faster lookup and a list for iteration. They are managed using |
| 35 | * RCU, i.e. access to the list and hash table is protected by RCU. |
| 36 | * |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 37 | * Upon allocating a STA info structure with sta_info_alloc(), the caller |
| 38 | * owns that structure. It must then insert it into the hash table using |
| 39 | * either sta_info_insert() or sta_info_insert_rcu(); only in the latter |
| 40 | * case (which acquires an rcu read section but must not be called from |
| 41 | * within one) will the pointer still be valid after the call. Note that |
| 42 | * the caller may not do much with the STA info before inserting it, in |
| 43 | * particular, it may not start any mesh peer link management or add |
| 44 | * encryption keys. |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 45 | * |
| 46 | * When the insertion fails (sta_info_insert()) returns non-zero), the |
| 47 | * structure will have been freed by sta_info_insert()! |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 48 | * |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 49 | * 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] | 50 | * peer. This means different things for the different type of interfaces |
| 51 | * 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] | 52 | * receive an association response from the AP. For IBSS this occurs when |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 53 | * 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] | 54 | * 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] | 55 | * for each respective station upon request from userspace through nl80211. |
Luis R. Rodriguez | 7e189a1 | 2009-06-02 18:38:14 -0400 | [diff] [blame] | 56 | * |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 57 | * In order to remove a STA info structure, various sta_info_destroy_*() |
| 58 | * calls are available. |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 59 | * |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 60 | * There is no concept of ownership on a STA entry, each structure is |
| 61 | * owned by the global hash table/list until it is removed. All users of |
| 62 | * the structure need to be RCU protected so that the structure won't be |
| 63 | * freed before they are done using it. |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 64 | */ |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 65 | |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 66 | /* Caller must hold local->sta_mtx */ |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 67 | static int sta_info_hash_del(struct ieee80211_local *local, |
| 68 | struct sta_info *sta) |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 69 | { |
| 70 | struct sta_info *s; |
| 71 | |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 72 | s = rcu_dereference_protected(local->sta_hash[STA_HASH(sta->sta.addr)], |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 73 | lockdep_is_held(&local->sta_mtx)); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 74 | if (!s) |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 75 | return -ENOENT; |
| 76 | if (s == sta) { |
Eric Dumazet | cf778b0 | 2012-01-12 04:41:32 +0000 | [diff] [blame] | 77 | rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 78 | s->hnext); |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 79 | return 0; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 82 | while (rcu_access_pointer(s->hnext) && |
| 83 | rcu_access_pointer(s->hnext) != sta) |
| 84 | s = rcu_dereference_protected(s->hnext, |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 85 | lockdep_is_held(&local->sta_mtx)); |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 86 | if (rcu_access_pointer(s->hnext)) { |
Eric Dumazet | cf778b0 | 2012-01-12 04:41:32 +0000 | [diff] [blame] | 87 | rcu_assign_pointer(s->hnext, sta->hnext); |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 88 | return 0; |
| 89 | } |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 90 | |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 91 | return -ENOENT; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 94 | /* protected by RCU */ |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 95 | struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata, |
| 96 | const u8 *addr) |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 97 | { |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 98 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 99 | struct sta_info *sta; |
| 100 | |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 101 | sta = rcu_dereference_check(local->sta_hash[STA_HASH(addr)], |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 102 | lockdep_is_held(&local->sta_mtx)); |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 103 | while (sta) { |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 104 | if (sta->sdata == sdata && |
Felix Fietkau | 888d04d | 2012-03-01 15:22:09 +0100 | [diff] [blame] | 105 | compare_ether_addr(sta->sta.addr, addr) == 0) |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 106 | break; |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 107 | sta = rcu_dereference_check(sta->hnext, |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 108 | lockdep_is_held(&local->sta_mtx)); |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 109 | } |
| 110 | return sta; |
| 111 | } |
| 112 | |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 113 | /* |
| 114 | * Get sta info either from the specified interface |
| 115 | * or from one of its vlans |
| 116 | */ |
| 117 | struct sta_info *sta_info_get_bss(struct ieee80211_sub_if_data *sdata, |
| 118 | const u8 *addr) |
| 119 | { |
| 120 | struct ieee80211_local *local = sdata->local; |
| 121 | struct sta_info *sta; |
| 122 | |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 123 | sta = rcu_dereference_check(local->sta_hash[STA_HASH(addr)], |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 124 | lockdep_is_held(&local->sta_mtx)); |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 125 | while (sta) { |
| 126 | if ((sta->sdata == sdata || |
Johannes Berg | a2c1e3d | 2010-09-14 21:34:14 +0200 | [diff] [blame] | 127 | (sta->sdata->bss && sta->sdata->bss == sdata->bss)) && |
Felix Fietkau | 888d04d | 2012-03-01 15:22:09 +0100 | [diff] [blame] | 128 | compare_ether_addr(sta->sta.addr, addr) == 0) |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 129 | break; |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 130 | sta = rcu_dereference_check(sta->hnext, |
Johannes Berg | 0379185 | 2010-04-06 11:18:42 +0200 | [diff] [blame] | 131 | lockdep_is_held(&local->sta_mtx)); |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 132 | } |
| 133 | return sta; |
| 134 | } |
| 135 | |
Johannes Berg | 3b53fde8 | 2009-11-16 12:00:37 +0100 | [diff] [blame] | 136 | struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata, |
| 137 | int idx) |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 138 | { |
Johannes Berg | 3b53fde8 | 2009-11-16 12:00:37 +0100 | [diff] [blame] | 139 | struct ieee80211_local *local = sdata->local; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 140 | struct sta_info *sta; |
| 141 | int i = 0; |
| 142 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 143 | list_for_each_entry_rcu(sta, &local->sta_list, list) { |
Johannes Berg | 3b53fde8 | 2009-11-16 12:00:37 +0100 | [diff] [blame] | 144 | if (sdata != sta->sdata) |
Luis Carlos Cobo | 2a8ca29 | 2008-02-29 17:51:25 -0800 | [diff] [blame] | 145 | continue; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 146 | if (i < idx) { |
| 147 | ++i; |
| 148 | continue; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 149 | } |
Luis Carlos Cobo | 2a8ca29 | 2008-02-29 17:51:25 -0800 | [diff] [blame] | 150 | return sta; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 151 | } |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 152 | |
| 153 | return NULL; |
| 154 | } |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 155 | |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 156 | /** |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 157 | * sta_info_free - free STA |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 158 | * |
Randy Dunlap | 6ef307b | 2008-07-03 13:52:18 -0700 | [diff] [blame] | 159 | * @local: pointer to the global information |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 160 | * @sta: STA info to free |
| 161 | * |
| 162 | * This function must undo everything done by sta_info_alloc() |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 163 | * that may happen before sta_info_insert(). It may only be |
| 164 | * called when sta_info_insert() has not been attempted (and |
| 165 | * if that fails, the station is freed anyway.) |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 166 | */ |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 167 | void sta_info_free(struct ieee80211_local *local, struct sta_info *sta) |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 168 | { |
Johannes Berg | 889cbb9 | 2012-01-17 10:33:29 +0100 | [diff] [blame] | 169 | if (sta->rate_ctrl) |
Johannes Berg | af65cd9 | 2009-11-17 18:18:36 +0100 | [diff] [blame] | 170 | rate_control_free_sta(sta); |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 171 | |
| 172 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Joe Perches | 0fb9a9e | 2010-08-20 16:25:38 -0700 | [diff] [blame] | 173 | wiphy_debug(local->hw.wiphy, "Destroyed STA %pM\n", sta->sta.addr); |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 174 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 175 | |
| 176 | kfree(sta); |
| 177 | } |
| 178 | |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 179 | /* Caller must hold local->sta_mtx */ |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 180 | static void sta_info_hash_add(struct ieee80211_local *local, |
| 181 | struct sta_info *sta) |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 182 | { |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 183 | lockdep_assert_held(&local->sta_mtx); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 184 | sta->hnext = local->sta_hash[STA_HASH(sta->sta.addr)]; |
Eric Dumazet | cf778b0 | 2012-01-12 04:41:32 +0000 | [diff] [blame] | 185 | rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], sta); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 186 | } |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 187 | |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 188 | static void sta_unblock(struct work_struct *wk) |
| 189 | { |
| 190 | struct sta_info *sta; |
| 191 | |
| 192 | sta = container_of(wk, struct sta_info, drv_unblock_wk); |
| 193 | |
| 194 | if (sta->dead) |
| 195 | return; |
| 196 | |
Helmut Schaa | 5442047 | 2012-01-17 09:22:49 +0100 | [diff] [blame] | 197 | if (!test_sta_flag(sta, WLAN_STA_PS_STA)) { |
| 198 | local_bh_disable(); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 199 | ieee80211_sta_ps_deliver_wakeup(sta); |
Helmut Schaa | 5442047 | 2012-01-17 09:22:49 +0100 | [diff] [blame] | 200 | local_bh_enable(); |
| 201 | } else if (test_and_clear_sta_flag(sta, WLAN_STA_PSPOLL)) { |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 202 | clear_sta_flag(sta, WLAN_STA_PS_DRIVER); |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 203 | |
| 204 | local_bh_disable(); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 205 | ieee80211_sta_ps_deliver_poll_response(sta); |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 206 | local_bh_enable(); |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 207 | } else if (test_and_clear_sta_flag(sta, WLAN_STA_UAPSD)) { |
| 208 | clear_sta_flag(sta, WLAN_STA_PS_DRIVER); |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 209 | |
| 210 | local_bh_disable(); |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 211 | ieee80211_sta_ps_deliver_uapsd(sta); |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 212 | local_bh_enable(); |
Johannes Berg | 50a9432 | 2010-11-16 11:50:28 -0800 | [diff] [blame] | 213 | } else |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 214 | clear_sta_flag(sta, WLAN_STA_PS_DRIVER); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 215 | } |
| 216 | |
Johannes Berg | af65cd9 | 2009-11-17 18:18:36 +0100 | [diff] [blame] | 217 | static int sta_prepare_rate_control(struct ieee80211_local *local, |
| 218 | struct sta_info *sta, gfp_t gfp) |
| 219 | { |
| 220 | if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) |
| 221 | return 0; |
| 222 | |
Johannes Berg | 889cbb9 | 2012-01-17 10:33:29 +0100 | [diff] [blame] | 223 | sta->rate_ctrl = local->rate_ctrl; |
Johannes Berg | af65cd9 | 2009-11-17 18:18:36 +0100 | [diff] [blame] | 224 | sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl, |
| 225 | &sta->sta, gfp); |
Johannes Berg | 889cbb9 | 2012-01-17 10:33:29 +0100 | [diff] [blame] | 226 | if (!sta->rate_ctrl_priv) |
Johannes Berg | af65cd9 | 2009-11-17 18:18:36 +0100 | [diff] [blame] | 227 | return -ENOMEM; |
Johannes Berg | af65cd9 | 2009-11-17 18:18:36 +0100 | [diff] [blame] | 228 | |
| 229 | return 0; |
| 230 | } |
| 231 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 232 | struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 5654416 | 2011-12-14 13:28:46 +0100 | [diff] [blame] | 233 | const u8 *addr, gfp_t gfp) |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 234 | { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 235 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 236 | struct sta_info *sta; |
Mohammed Shafi Shajakhan | ebe27c9 | 2011-04-08 21:24:24 +0530 | [diff] [blame] | 237 | struct timespec uptime; |
Ron Rindjunsky | 16c5f15 | 2007-12-25 17:00:34 +0200 | [diff] [blame] | 238 | int i; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 239 | |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 240 | sta = kzalloc(sizeof(*sta) + local->hw.sta_data_size, gfp); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 241 | if (!sta) |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 242 | return NULL; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 243 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 244 | spin_lock_init(&sta->lock); |
Emmanuel Grumbach | 63ef223 | 2014-02-20 09:22:11 +0200 | [diff] [blame] | 245 | spin_lock_init(&sta->ps_lock); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 246 | INIT_WORK(&sta->drv_unblock_wk, sta_unblock); |
Johannes Berg | 67c282c | 2010-06-10 10:21:43 +0200 | [diff] [blame] | 247 | INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work); |
Johannes Berg | a93e364 | 2010-06-10 10:21:46 +0200 | [diff] [blame] | 248 | mutex_init(&sta->ampdu_mlme.mtx); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 249 | |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 250 | memcpy(sta->sta.addr, addr, ETH_ALEN); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 251 | sta->local = local; |
| 252 | sta->sdata = sdata; |
Felix Fietkau | 8bc8aec | 2011-03-21 20:01:00 +0100 | [diff] [blame] | 253 | sta->last_rx = jiffies; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 254 | |
Johannes Berg | 71ec375 | 2012-01-20 13:55:20 +0100 | [diff] [blame] | 255 | sta->sta_state = IEEE80211_STA_NONE; |
| 256 | |
Mohammed Shafi Shajakhan | ebe27c9 | 2011-04-08 21:24:24 +0530 | [diff] [blame] | 257 | do_posix_clock_monotonic_gettime(&uptime); |
| 258 | sta->last_connected = uptime.tv_sec; |
Bruno Randolf | 541a45a | 2010-12-02 19:12:43 +0900 | [diff] [blame] | 259 | ewma_init(&sta->avg_signal, 1024, 8); |
| 260 | |
Johannes Berg | af65cd9 | 2009-11-17 18:18:36 +0100 | [diff] [blame] | 261 | if (sta_prepare_rate_control(local, sta, gfp)) { |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 262 | kfree(sta); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 263 | return NULL; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Ron Rindjunsky | 16c5f15 | 2007-12-25 17:00:34 +0200 | [diff] [blame] | 266 | for (i = 0; i < STA_TID_NUM; i++) { |
Johannes Berg | a622ab7 | 2010-06-10 10:21:39 +0200 | [diff] [blame] | 267 | /* |
| 268 | * timer_to_tid must be initialized with identity mapping |
| 269 | * to enable session_timer's data differentiation. See |
| 270 | * sta_rx_agg_session_timer_expired for usage. |
| 271 | */ |
Ron Rindjunsky | 16c5f15 | 2007-12-25 17:00:34 +0200 | [diff] [blame] | 272 | sta->timer_to_tid[i] = i; |
Ron Rindjunsky | 16c5f15 | 2007-12-25 17:00:34 +0200 | [diff] [blame] | 273 | } |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 274 | for (i = 0; i < IEEE80211_NUM_ACS; i++) { |
| 275 | skb_queue_head_init(&sta->ps_tx_buf[i]); |
| 276 | skb_queue_head_init(&sta->tx_filtered[i]); |
| 277 | } |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 278 | |
Senthil Balasubramanian | cccaec9 | 2009-05-14 18:42:08 +0530 | [diff] [blame] | 279 | for (i = 0; i < NUM_RX_DATA_QUEUES; i++) |
Alexey Dobriyan | 4be929b | 2010-05-24 14:33:03 -0700 | [diff] [blame] | 280 | sta->last_seq_ctrl[i] = cpu_to_le16(USHRT_MAX); |
Senthil Balasubramanian | cccaec9 | 2009-05-14 18:42:08 +0530 | [diff] [blame] | 281 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 282 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Joe Perches | 0fb9a9e | 2010-08-20 16:25:38 -0700 | [diff] [blame] | 283 | wiphy_debug(local->hw.wiphy, "Allocated STA %pM\n", sta->sta.addr); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 284 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 285 | |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 286 | #ifdef CONFIG_MAC80211_MESH |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 287 | sta->plink_state = NL80211_PLINK_LISTEN; |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 288 | init_timer(&sta->plink_timer); |
| 289 | #endif |
| 290 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 291 | return sta; |
| 292 | } |
| 293 | |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 294 | static int sta_info_insert_check(struct sta_info *sta) |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 295 | { |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 296 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 297 | |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 298 | /* |
| 299 | * Can't be a WARN_ON because it can be triggered through a race: |
| 300 | * something inserts a STA (on one CPU) without holding the RTNL |
| 301 | * and another CPU turns off the net device. |
| 302 | */ |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 303 | if (unlikely(!ieee80211_sdata_running(sdata))) |
| 304 | return -ENETDOWN; |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 305 | |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 306 | 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] | 307 | is_multicast_ether_addr(sta->sta.addr))) |
| 308 | return -EINVAL; |
| 309 | |
| 310 | return 0; |
| 311 | } |
| 312 | |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 313 | static int sta_info_insert_drv_state(struct ieee80211_local *local, |
| 314 | struct ieee80211_sub_if_data *sdata, |
| 315 | struct sta_info *sta) |
| 316 | { |
| 317 | enum ieee80211_sta_state state; |
| 318 | int err = 0; |
| 319 | |
| 320 | for (state = IEEE80211_STA_NOTEXIST; state < sta->sta_state; state++) { |
| 321 | err = drv_sta_state(local, sdata, sta, state, state + 1); |
| 322 | if (err) |
| 323 | break; |
| 324 | } |
| 325 | |
| 326 | if (!err) { |
Johannes Berg | a4ec45a | 2012-01-20 13:55:22 +0100 | [diff] [blame] | 327 | /* |
| 328 | * Drivers using legacy sta_add/sta_remove callbacks only |
| 329 | * get uploaded set to true after sta_add is called. |
| 330 | */ |
| 331 | if (!local->ops->sta_add) |
| 332 | sta->uploaded = true; |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 333 | return 0; |
| 334 | } |
| 335 | |
| 336 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { |
| 337 | printk(KERN_DEBUG |
| 338 | "%s: failed to move IBSS STA %pM to state %d (%d) - keeping it anyway.\n", |
| 339 | sdata->name, sta->sta.addr, state + 1, err); |
| 340 | err = 0; |
| 341 | } |
| 342 | |
| 343 | /* unwind on error */ |
| 344 | for (; state > IEEE80211_STA_NOTEXIST; state--) |
| 345 | WARN_ON(drv_sta_state(local, sdata, sta, state, state - 1)); |
| 346 | |
| 347 | return err; |
| 348 | } |
| 349 | |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 350 | /* |
| 351 | * should be called with sta_mtx locked |
| 352 | * this function replaces the mutex lock |
| 353 | * with a RCU lock |
| 354 | */ |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 355 | static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU) |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 356 | { |
| 357 | struct ieee80211_local *local = sta->local; |
| 358 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 359 | struct station_info sinfo; |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 360 | int err = 0; |
| 361 | |
| 362 | lockdep_assert_held(&local->sta_mtx); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 363 | |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 364 | /* check if STA exists already */ |
| 365 | if (sta_info_get_bss(sdata, sta->sta.addr)) { |
| 366 | err = -EEXIST; |
| 367 | goto out_err; |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 368 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 369 | |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 370 | /* notify driver */ |
| 371 | err = sta_info_insert_drv_state(local, sdata, sta); |
| 372 | if (err) |
| 373 | goto out_err; |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 374 | |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 375 | local->num_sta++; |
| 376 | local->sta_generation++; |
| 377 | smp_mb(); |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 378 | |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 379 | /* make the station visible */ |
| 380 | sta_info_hash_add(local, sta); |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 381 | |
Arik Nemtsov | 10b34e7 | 2012-06-03 23:32:32 +0300 | [diff] [blame] | 382 | list_add_rcu(&sta->list, &local->sta_list); |
Johannes Berg | 83d5cc0 | 2012-01-12 09:31:10 +0100 | [diff] [blame] | 383 | |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 384 | set_sta_flag(sta, WLAN_STA_INSERTED); |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 385 | |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 386 | ieee80211_sta_debugfs_add(sta); |
| 387 | rate_control_add_sta_debugfs(sta); |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 388 | |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 389 | memset(&sinfo, 0, sizeof(sinfo)); |
| 390 | sinfo.filled = 0; |
| 391 | sinfo.generation = local->sta_generation; |
| 392 | cfg80211_new_sta(sdata->dev, sta->sta.addr, &sinfo, GFP_KERNEL); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 393 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 394 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 395 | wiphy_debug(local->hw.wiphy, "Inserted STA %pM\n", sta->sta.addr); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 396 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 397 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 398 | /* move reference to rcu-protected */ |
| 399 | rcu_read_lock(); |
| 400 | mutex_unlock(&local->sta_mtx); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 401 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 402 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
| 403 | mesh_accept_plinks_update(sdata); |
| 404 | |
| 405 | return 0; |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 406 | out_err: |
| 407 | mutex_unlock(&local->sta_mtx); |
| 408 | rcu_read_lock(); |
| 409 | return err; |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU) |
| 413 | { |
| 414 | struct ieee80211_local *local = sta->local; |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 415 | int err = 0; |
| 416 | |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 417 | might_sleep(); |
| 418 | |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 419 | err = sta_info_insert_check(sta); |
| 420 | if (err) { |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 421 | rcu_read_lock(); |
| 422 | goto out_free; |
| 423 | } |
| 424 | |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 425 | mutex_lock(&local->sta_mtx); |
| 426 | |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 427 | err = sta_info_insert_finish(sta); |
Guy Eilam | 8c71df7 | 2011-08-17 15:18:14 +0300 | [diff] [blame] | 428 | if (err) |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 429 | goto out_free; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 430 | |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 431 | return 0; |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 432 | out_free: |
| 433 | BUG_ON(!err); |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 434 | sta_info_free(local, sta); |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 435 | return err; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 436 | } |
| 437 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 438 | int sta_info_insert(struct sta_info *sta) |
| 439 | { |
| 440 | int err = sta_info_insert_rcu(sta); |
| 441 | |
| 442 | rcu_read_unlock(); |
| 443 | |
| 444 | return err; |
| 445 | } |
| 446 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 447 | static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid) |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 448 | { |
| 449 | /* |
| 450 | * This format has been mandated by the IEEE specifications, |
| 451 | * so this line may not be changed to use the __set_bit() format. |
| 452 | */ |
| 453 | bss->tim[aid / 8] |= (1 << (aid % 8)); |
| 454 | } |
| 455 | |
| 456 | static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, u16 aid) |
| 457 | { |
| 458 | /* |
| 459 | * This format has been mandated by the IEEE specifications, |
| 460 | * so this line may not be changed to use the __clear_bit() format. |
| 461 | */ |
| 462 | bss->tim[aid / 8] &= ~(1 << (aid % 8)); |
| 463 | } |
| 464 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 465 | static unsigned long ieee80211_tids_for_ac(int ac) |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 466 | { |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 467 | /* If we ever support TIDs > 7, this obviously needs to be adjusted */ |
| 468 | switch (ac) { |
| 469 | case IEEE80211_AC_VO: |
| 470 | return BIT(6) | BIT(7); |
| 471 | case IEEE80211_AC_VI: |
| 472 | return BIT(4) | BIT(5); |
| 473 | case IEEE80211_AC_BE: |
| 474 | return BIT(0) | BIT(3); |
| 475 | case IEEE80211_AC_BK: |
| 476 | return BIT(1) | BIT(2); |
| 477 | default: |
| 478 | WARN_ON(1); |
| 479 | return 0; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 480 | } |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 481 | } |
| 482 | |
Johannes Berg | c868cb3 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 483 | void sta_info_recalc_tim(struct sta_info *sta) |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 484 | { |
Johannes Berg | c868cb3 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 485 | struct ieee80211_local *local = sta->local; |
| 486 | struct ieee80211_if_ap *bss = sta->sdata->bss; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 487 | unsigned long flags; |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 488 | bool indicate_tim = false; |
| 489 | u8 ignore_for_tim = sta->sta.uapsd_queues; |
| 490 | int ac; |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 491 | |
Johannes Berg | c868cb3 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 492 | if (WARN_ON_ONCE(!sta->sdata->bss)) |
| 493 | return; |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 494 | |
Johannes Berg | c868cb3 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 495 | /* No need to do anything if the driver does all */ |
| 496 | if (local->hw.flags & IEEE80211_HW_AP_LINK_PS) |
| 497 | return; |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 498 | |
Johannes Berg | c868cb3 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 499 | if (sta->dead) |
| 500 | goto done; |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 501 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 502 | /* |
| 503 | * If all ACs are delivery-enabled then we should build |
| 504 | * the TIM bit for all ACs anyway; if only some are then |
| 505 | * we ignore those and build the TIM bit using only the |
| 506 | * non-enabled ones. |
| 507 | */ |
| 508 | if (ignore_for_tim == BIT(IEEE80211_NUM_ACS) - 1) |
| 509 | ignore_for_tim = 0; |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 510 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 511 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 512 | unsigned long tids; |
| 513 | |
| 514 | if (ignore_for_tim & BIT(ac)) |
| 515 | continue; |
| 516 | |
| 517 | indicate_tim |= !skb_queue_empty(&sta->tx_filtered[ac]) || |
| 518 | !skb_queue_empty(&sta->ps_tx_buf[ac]); |
| 519 | if (indicate_tim) |
| 520 | break; |
| 521 | |
| 522 | tids = ieee80211_tids_for_ac(ac); |
| 523 | |
| 524 | indicate_tim |= |
| 525 | sta->driver_buffered_tids & tids; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 526 | } |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 527 | |
Johannes Berg | c868cb3 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 528 | done: |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 529 | spin_lock_irqsave(&local->tim_lock, flags); |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 530 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 531 | if (indicate_tim) |
Johannes Berg | c868cb3 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 532 | __bss_tim_set(bss, sta->sta.aid); |
| 533 | else |
| 534 | __bss_tim_clear(bss, sta->sta.aid); |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 535 | |
Johannes Berg | c868cb3 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 536 | if (local->ops->set_tim) { |
| 537 | local->tim_in_locked_section = true; |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 538 | drv_set_tim(local, &sta->sta, indicate_tim); |
Johannes Berg | c868cb3 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 539 | local->tim_in_locked_section = false; |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 540 | } |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 541 | |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 542 | spin_unlock_irqrestore(&local->tim_lock, flags); |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 543 | } |
| 544 | |
Johannes Berg | cd0b8d8 | 2011-09-06 14:13:06 +0200 | [diff] [blame] | 545 | static bool sta_info_buffer_expired(struct sta_info *sta, struct sk_buff *skb) |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 546 | { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 547 | struct ieee80211_tx_info *info; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 548 | int timeout; |
| 549 | |
| 550 | if (!skb) |
Johannes Berg | cd0b8d8 | 2011-09-06 14:13:06 +0200 | [diff] [blame] | 551 | return false; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 552 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 553 | info = IEEE80211_SKB_CB(skb); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 554 | |
| 555 | /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */ |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 556 | timeout = (sta->listen_interval * |
| 557 | sta->sdata->vif.bss_conf.beacon_int * |
| 558 | 32 / 15625) * HZ; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 559 | if (timeout < STA_TX_BUFFER_EXPIRE) |
| 560 | timeout = STA_TX_BUFFER_EXPIRE; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 561 | return time_after(jiffies, info->control.jiffies + timeout); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 565 | static bool sta_info_cleanup_expire_buffered_ac(struct ieee80211_local *local, |
| 566 | struct sta_info *sta, int ac) |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 567 | { |
| 568 | unsigned long flags; |
| 569 | struct sk_buff *skb; |
| 570 | |
Johannes Berg | 6075039 | 2011-09-29 16:04:28 +0200 | [diff] [blame] | 571 | /* |
| 572 | * First check for frames that should expire on the filtered |
| 573 | * queue. Frames here were rejected by the driver and are on |
| 574 | * a separate queue to avoid reordering with normal PS-buffered |
| 575 | * frames. They also aren't accounted for right now in the |
| 576 | * total_ps_buffered counter. |
| 577 | */ |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 578 | for (;;) { |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 579 | spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags); |
| 580 | skb = skb_peek(&sta->tx_filtered[ac]); |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 581 | if (sta_info_buffer_expired(sta, skb)) |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 582 | skb = __skb_dequeue(&sta->tx_filtered[ac]); |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 583 | else |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 584 | skb = NULL; |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 585 | spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 586 | |
Johannes Berg | 6075039 | 2011-09-29 16:04:28 +0200 | [diff] [blame] | 587 | /* |
| 588 | * Frames are queued in order, so if this one |
| 589 | * hasn't expired yet we can stop testing. If |
| 590 | * we actually reached the end of the queue we |
| 591 | * also need to stop, of course. |
| 592 | */ |
| 593 | if (!skb) |
| 594 | break; |
| 595 | dev_kfree_skb(skb); |
| 596 | } |
| 597 | |
| 598 | /* |
| 599 | * Now also check the normal PS-buffered queue, this will |
| 600 | * only find something if the filtered queue was emptied |
| 601 | * since the filtered frames are all before the normal PS |
| 602 | * buffered frames. |
| 603 | */ |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 604 | for (;;) { |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 605 | spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags); |
| 606 | skb = skb_peek(&sta->ps_tx_buf[ac]); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 607 | if (sta_info_buffer_expired(sta, skb)) |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 608 | skb = __skb_dequeue(&sta->ps_tx_buf[ac]); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 609 | else |
| 610 | skb = NULL; |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 611 | spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 612 | |
Johannes Berg | 6075039 | 2011-09-29 16:04:28 +0200 | [diff] [blame] | 613 | /* |
| 614 | * frames are queued in order, so if this one |
| 615 | * hasn't expired yet (or we reached the end of |
| 616 | * the queue) we can stop testing |
| 617 | */ |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 618 | if (!skb) |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 619 | break; |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 620 | |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 621 | local->total_ps_buffered--; |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 622 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 623 | printk(KERN_DEBUG "Buffered frame expired (STA %pM)\n", |
| 624 | sta->sta.addr); |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 625 | #endif |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 626 | dev_kfree_skb(skb); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 627 | } |
Juuso Oikarinen | 3393a60 | 2010-04-19 10:12:52 +0300 | [diff] [blame] | 628 | |
Johannes Berg | 6075039 | 2011-09-29 16:04:28 +0200 | [diff] [blame] | 629 | /* |
| 630 | * Finally, recalculate the TIM bit for this station -- it might |
| 631 | * now be clear because the station was too slow to retrieve its |
| 632 | * frames. |
| 633 | */ |
| 634 | sta_info_recalc_tim(sta); |
| 635 | |
| 636 | /* |
| 637 | * Return whether there are any frames still buffered, this is |
| 638 | * used to check whether the cleanup timer still needs to run, |
| 639 | * if there are no frames we don't need to rearm the timer. |
| 640 | */ |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 641 | return !(skb_queue_empty(&sta->ps_tx_buf[ac]) && |
| 642 | skb_queue_empty(&sta->tx_filtered[ac])); |
| 643 | } |
| 644 | |
| 645 | static bool sta_info_cleanup_expire_buffered(struct ieee80211_local *local, |
| 646 | struct sta_info *sta) |
| 647 | { |
| 648 | bool have_buffered = false; |
| 649 | int ac; |
| 650 | |
| 651 | /* This is only necessary for stations on BSS interfaces */ |
| 652 | if (!sta->sdata->bss) |
| 653 | return false; |
| 654 | |
| 655 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) |
| 656 | have_buffered |= |
| 657 | sta_info_cleanup_expire_buffered_ac(local, sta, ac); |
| 658 | |
| 659 | return have_buffered; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 660 | } |
| 661 | |
Johannes Berg | 83d5cc0 | 2012-01-12 09:31:10 +0100 | [diff] [blame] | 662 | int __must_check __sta_info_destroy(struct sta_info *sta) |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 663 | { |
| 664 | struct ieee80211_local *local; |
| 665 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 666 | int ret, i, ac; |
Yogesh Ashok Powar | 42624d4 | 2011-12-08 14:56:15 +0530 | [diff] [blame] | 667 | struct tid_ampdu_tx *tid_tx; |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 668 | |
| 669 | might_sleep(); |
| 670 | |
| 671 | if (!sta) |
| 672 | return -ENOENT; |
| 673 | |
| 674 | local = sta->local; |
| 675 | sdata = sta->sdata; |
| 676 | |
Johannes Berg | 83d5cc0 | 2012-01-12 09:31:10 +0100 | [diff] [blame] | 677 | lockdep_assert_held(&local->sta_mtx); |
| 678 | |
Johannes Berg | 098a607 | 2010-04-06 11:18:47 +0200 | [diff] [blame] | 679 | /* |
| 680 | * Before removing the station from the driver and |
| 681 | * rate control, it might still start new aggregation |
| 682 | * sessions -- block that to make sure the tear-down |
| 683 | * will be sufficient. |
| 684 | */ |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 685 | set_sta_flag(sta, WLAN_STA_BLOCK_BA); |
Johannes Berg | 53f73c0 | 2010-10-05 19:37:40 +0200 | [diff] [blame] | 686 | ieee80211_sta_tear_down_BA_sessions(sta, true); |
Johannes Berg | 098a607 | 2010-04-06 11:18:47 +0200 | [diff] [blame] | 687 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 688 | ret = sta_info_hash_del(local, sta); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 689 | if (ret) |
| 690 | return ret; |
| 691 | |
Arik Nemtsov | 10b34e7 | 2012-06-03 23:32:32 +0300 | [diff] [blame] | 692 | list_del_rcu(&sta->list); |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 693 | |
Johannes Berg | 8cb2315 | 2011-05-12 15:07:15 +0200 | [diff] [blame] | 694 | mutex_lock(&local->key_mtx); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 695 | for (i = 0; i < NUM_DEFAULT_KEYS; i++) |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 696 | __ieee80211_key_free(key_mtx_dereference(local, sta->gtk[i])); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 697 | if (sta->ptk) |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 698 | __ieee80211_key_free(key_mtx_dereference(local, sta->ptk)); |
Johannes Berg | 8cb2315 | 2011-05-12 15:07:15 +0200 | [diff] [blame] | 699 | mutex_unlock(&local->key_mtx); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 700 | |
| 701 | sta->dead = true; |
| 702 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 703 | local->num_sta--; |
| 704 | local->sta_generation++; |
| 705 | |
| 706 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
Stephen Hemminger | a9b3cd7 | 2011-08-01 16:19:00 +0000 | [diff] [blame] | 707 | RCU_INIT_POINTER(sdata->u.vlan.sta, NULL); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 708 | |
Johannes Berg | 83d5cc0 | 2012-01-12 09:31:10 +0100 | [diff] [blame] | 709 | while (sta->sta_state > IEEE80211_STA_NONE) { |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 710 | ret = sta_info_move_state(sta, sta->sta_state - 1); |
| 711 | if (ret) { |
Johannes Berg | 83d5cc0 | 2012-01-12 09:31:10 +0100 | [diff] [blame] | 712 | WARN_ON_ONCE(1); |
| 713 | break; |
| 714 | } |
| 715 | } |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 716 | |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 717 | if (sta->uploaded) { |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 718 | ret = drv_sta_state(local, sdata, sta, IEEE80211_STA_NONE, |
| 719 | IEEE80211_STA_NOTEXIST); |
| 720 | WARN_ON_ONCE(ret != 0); |
| 721 | } |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 722 | |
Johannes Berg | e64b379 | 2010-04-06 11:18:43 +0200 | [diff] [blame] | 723 | /* |
| 724 | * At this point, after we wait for an RCU grace period, |
| 725 | * neither mac80211 nor the driver can reference this |
| 726 | * sta struct any more except by still existing timers |
| 727 | * associated with this station that we clean up below. |
| 728 | */ |
| 729 | synchronize_rcu(); |
| 730 | |
Helmut Schaa | 4f3eb0b | 2012-01-27 11:02:53 +0100 | [diff] [blame] | 731 | if (test_sta_flag(sta, WLAN_STA_PS_STA)) { |
| 732 | BUG_ON(!sdata->bss); |
| 733 | |
| 734 | clear_sta_flag(sta, WLAN_STA_PS_STA); |
| 735 | |
| 736 | atomic_dec(&sdata->bss->num_sta_ps); |
| 737 | sta_info_recalc_tim(sta); |
| 738 | } |
| 739 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 740 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 741 | local->total_ps_buffered -= skb_queue_len(&sta->ps_tx_buf[ac]); |
Felix Fietkau | b144f945 | 2012-11-10 03:44:14 +0100 | [diff] [blame] | 742 | ieee80211_purge_tx_queue(&local->hw, &sta->ps_tx_buf[ac]); |
| 743 | ieee80211_purge_tx_queue(&local->hw, &sta->tx_filtered[ac]); |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 744 | } |
Johannes Berg | c868cb3 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 745 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 746 | #ifdef CONFIG_MAC80211_MESH |
Johannes Berg | e64b379 | 2010-04-06 11:18:43 +0200 | [diff] [blame] | 747 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 748 | mesh_accept_plinks_update(sdata); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 749 | #endif |
| 750 | |
| 751 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Joe Perches | 0fb9a9e | 2010-08-20 16:25:38 -0700 | [diff] [blame] | 752 | wiphy_debug(local->hw.wiphy, "Removed STA %pM\n", sta->sta.addr); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 753 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 754 | cancel_work_sync(&sta->drv_unblock_wk); |
| 755 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 756 | cfg80211_del_sta(sdata->dev, sta->sta.addr, GFP_KERNEL); |
| 757 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 758 | rate_control_remove_sta_debugfs(sta); |
| 759 | ieee80211_sta_debugfs_remove(sta); |
| 760 | |
| 761 | #ifdef CONFIG_MAC80211_MESH |
| 762 | if (ieee80211_vif_is_mesh(&sta->sdata->vif)) { |
| 763 | mesh_plink_deactivate(sta); |
| 764 | del_timer_sync(&sta->plink_timer); |
| 765 | } |
| 766 | #endif |
| 767 | |
Johannes Berg | 151a02f | 2012-01-17 10:30:01 +0100 | [diff] [blame] | 768 | /* |
| 769 | * Destroy aggregation state here. It would be nice to wait for the |
| 770 | * driver to finish aggregation stop and then clean up, but for now |
| 771 | * drivers have to handle aggregation stop being requested, followed |
| 772 | * directly by station destruction. |
Yogesh Ashok Powar | 42624d4 | 2011-12-08 14:56:15 +0530 | [diff] [blame] | 773 | */ |
| 774 | for (i = 0; i < STA_TID_NUM; i++) { |
Johannes Berg | 151a02f | 2012-01-17 10:30:01 +0100 | [diff] [blame] | 775 | tid_tx = rcu_dereference_raw(sta->ampdu_mlme.tid_tx[i]); |
Yogesh Ashok Powar | 27bf888 | 2011-12-16 11:47:15 +0530 | [diff] [blame] | 776 | if (!tid_tx) |
Yogesh Ashok Powar | 42624d4 | 2011-12-08 14:56:15 +0530 | [diff] [blame] | 777 | continue; |
Felix Fietkau | b144f945 | 2012-11-10 03:44:14 +0100 | [diff] [blame] | 778 | ieee80211_purge_tx_queue(&local->hw, &tid_tx->pending); |
Johannes Berg | 151a02f | 2012-01-17 10:30:01 +0100 | [diff] [blame] | 779 | kfree(tid_tx); |
Yogesh Ashok Powar | 42624d4 | 2011-12-08 14:56:15 +0530 | [diff] [blame] | 780 | } |
| 781 | |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 782 | sta_info_free(local, sta); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 783 | |
| 784 | return 0; |
| 785 | } |
| 786 | |
| 787 | int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata, const u8 *addr) |
| 788 | { |
| 789 | struct sta_info *sta; |
| 790 | int ret; |
| 791 | |
| 792 | mutex_lock(&sdata->local->sta_mtx); |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 793 | sta = sta_info_get(sdata, addr); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 794 | ret = __sta_info_destroy(sta); |
| 795 | mutex_unlock(&sdata->local->sta_mtx); |
| 796 | |
| 797 | return ret; |
| 798 | } |
| 799 | |
| 800 | int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata, |
| 801 | const u8 *addr) |
| 802 | { |
| 803 | struct sta_info *sta; |
| 804 | int ret; |
| 805 | |
| 806 | mutex_lock(&sdata->local->sta_mtx); |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 807 | sta = sta_info_get_bss(sdata, addr); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 808 | ret = __sta_info_destroy(sta); |
| 809 | mutex_unlock(&sdata->local->sta_mtx); |
| 810 | |
| 811 | return ret; |
| 812 | } |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 813 | |
| 814 | static void sta_info_cleanup(unsigned long data) |
| 815 | { |
| 816 | struct ieee80211_local *local = (struct ieee80211_local *) data; |
| 817 | struct sta_info *sta; |
Juuso Oikarinen | 3393a60 | 2010-04-19 10:12:52 +0300 | [diff] [blame] | 818 | bool timer_needed = false; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 819 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 820 | rcu_read_lock(); |
| 821 | list_for_each_entry_rcu(sta, &local->sta_list, list) |
Juuso Oikarinen | 3393a60 | 2010-04-19 10:12:52 +0300 | [diff] [blame] | 822 | if (sta_info_cleanup_expire_buffered(local, sta)) |
| 823 | timer_needed = true; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 824 | rcu_read_unlock(); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 825 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 826 | if (local->quiescing) |
| 827 | return; |
| 828 | |
Juuso Oikarinen | 3393a60 | 2010-04-19 10:12:52 +0300 | [diff] [blame] | 829 | if (!timer_needed) |
| 830 | return; |
| 831 | |
Johannes Berg | 26d5953 | 2011-04-01 13:52:48 +0200 | [diff] [blame] | 832 | mod_timer(&local->sta_cleanup, |
| 833 | round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL)); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | void sta_info_init(struct ieee80211_local *local) |
| 837 | { |
Johannes Berg | 4d33960 | 2011-12-15 11:24:20 +0100 | [diff] [blame] | 838 | spin_lock_init(&local->tim_lock); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 839 | mutex_init(&local->sta_mtx); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 840 | INIT_LIST_HEAD(&local->sta_list); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 841 | |
Pavel Emelyanov | b24b8a2 | 2008-01-23 21:20:07 -0800 | [diff] [blame] | 842 | setup_timer(&local->sta_cleanup, sta_info_cleanup, |
| 843 | (unsigned long)local); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | void sta_info_stop(struct ieee80211_local *local) |
| 847 | { |
Johannes Berg | 4d2a32d | 2012-12-13 23:08:52 +0100 | [diff] [blame] | 848 | del_timer_sync(&local->sta_cleanup); |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 849 | sta_info_flush(local, NULL); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 850 | } |
| 851 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 852 | /** |
| 853 | * sta_info_flush - flush matching STA entries from the STA table |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 854 | * |
| 855 | * Returns the number of removed STA entries. |
| 856 | * |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 857 | * @local: local interface data |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 858 | * @sdata: matching rule for the net device (sta->dev) or %NULL to match all STAs |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 859 | */ |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 860 | int sta_info_flush(struct ieee80211_local *local, |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 861 | struct ieee80211_sub_if_data *sdata) |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 862 | { |
| 863 | struct sta_info *sta, *tmp; |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 864 | int ret = 0; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 865 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 866 | might_sleep(); |
| 867 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 868 | mutex_lock(&local->sta_mtx); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 869 | list_for_each_entry_safe(sta, tmp, &local->sta_list, list) { |
Johannes Berg | 3431683 | 2012-02-25 21:40:46 +0100 | [diff] [blame] | 870 | if (!sdata || sdata == sta->sdata) { |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 871 | WARN_ON(__sta_info_destroy(sta)); |
Johannes Berg | 3431683 | 2012-02-25 21:40:46 +0100 | [diff] [blame] | 872 | ret++; |
| 873 | } |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 874 | } |
| 875 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 876 | |
| 877 | return ret; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 878 | } |
Johannes Berg | dc6676b | 2008-03-31 19:23:03 +0200 | [diff] [blame] | 879 | |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 880 | void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata, |
| 881 | unsigned long exp_time) |
| 882 | { |
| 883 | struct ieee80211_local *local = sdata->local; |
| 884 | struct sta_info *sta, *tmp; |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 885 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 886 | mutex_lock(&local->sta_mtx); |
Mohammed Shafi Shajakhan | e46a2cf | 2011-12-26 10:43:29 +0530 | [diff] [blame] | 887 | |
| 888 | list_for_each_entry_safe(sta, tmp, &local->sta_list, list) { |
Marek Lindner | ec2b774 | 2011-12-20 23:16:52 +0800 | [diff] [blame] | 889 | if (sdata != sta->sdata) |
| 890 | continue; |
| 891 | |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 892 | if (time_after(jiffies, sta->last_rx + exp_time)) { |
| 893 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 894 | printk(KERN_DEBUG "%s: expiring inactive STA %pM\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 895 | sdata->name, sta->sta.addr); |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 896 | #endif |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 897 | WARN_ON(__sta_info_destroy(sta)); |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 898 | } |
Mohammed Shafi Shajakhan | e46a2cf | 2011-12-26 10:43:29 +0530 | [diff] [blame] | 899 | } |
| 900 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 901 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 902 | } |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 903 | |
Ben Greear | 686b9cb | 2010-09-23 09:44:36 -0700 | [diff] [blame] | 904 | struct ieee80211_sta *ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw, |
| 905 | const u8 *addr, |
| 906 | const u8 *localaddr) |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 907 | { |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 908 | struct sta_info *sta, *nxt; |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 909 | |
Ben Greear | 686b9cb | 2010-09-23 09:44:36 -0700 | [diff] [blame] | 910 | /* |
| 911 | * Just return a random station if localaddr is NULL |
| 912 | * ... first in list. |
| 913 | */ |
Johannes Berg | f7c6559 | 2010-04-30 13:48:36 +0200 | [diff] [blame] | 914 | for_each_sta_info(hw_to_local(hw), addr, sta, nxt) { |
Ben Greear | 686b9cb | 2010-09-23 09:44:36 -0700 | [diff] [blame] | 915 | if (localaddr && |
| 916 | compare_ether_addr(sta->sdata->vif.addr, localaddr) != 0) |
| 917 | continue; |
Johannes Berg | f7c6559 | 2010-04-30 13:48:36 +0200 | [diff] [blame] | 918 | if (!sta->uploaded) |
| 919 | return NULL; |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 920 | return &sta->sta; |
Johannes Berg | f7c6559 | 2010-04-30 13:48:36 +0200 | [diff] [blame] | 921 | } |
| 922 | |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 923 | return NULL; |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 924 | } |
Ben Greear | 686b9cb | 2010-09-23 09:44:36 -0700 | [diff] [blame] | 925 | EXPORT_SYMBOL_GPL(ieee80211_find_sta_by_ifaddr); |
Johannes Berg | 5ed176e | 2009-11-04 14:42:28 +0100 | [diff] [blame] | 926 | |
| 927 | struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_vif *vif, |
| 928 | const u8 *addr) |
| 929 | { |
Johannes Berg | f7c6559 | 2010-04-30 13:48:36 +0200 | [diff] [blame] | 930 | struct sta_info *sta; |
Johannes Berg | 5ed176e | 2009-11-04 14:42:28 +0100 | [diff] [blame] | 931 | |
| 932 | if (!vif) |
| 933 | return NULL; |
| 934 | |
Johannes Berg | f7c6559 | 2010-04-30 13:48:36 +0200 | [diff] [blame] | 935 | sta = sta_info_get_bss(vif_to_sdata(vif), addr); |
| 936 | if (!sta) |
| 937 | return NULL; |
Johannes Berg | 5ed176e | 2009-11-04 14:42:28 +0100 | [diff] [blame] | 938 | |
Johannes Berg | f7c6559 | 2010-04-30 13:48:36 +0200 | [diff] [blame] | 939 | if (!sta->uploaded) |
| 940 | return NULL; |
| 941 | |
| 942 | return &sta->sta; |
Johannes Berg | 5ed176e | 2009-11-04 14:42:28 +0100 | [diff] [blame] | 943 | } |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 944 | EXPORT_SYMBOL(ieee80211_find_sta); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 945 | |
Johannes Berg | 50a9432 | 2010-11-16 11:50:28 -0800 | [diff] [blame] | 946 | static void clear_sta_ps_flags(void *_sta) |
| 947 | { |
| 948 | struct sta_info *sta = _sta; |
Helmut Schaa | 608383b | 2012-01-30 15:18:00 +0100 | [diff] [blame] | 949 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Johannes Berg | 50a9432 | 2010-11-16 11:50:28 -0800 | [diff] [blame] | 950 | |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 951 | clear_sta_flag(sta, WLAN_STA_PS_DRIVER); |
Helmut Schaa | 608383b | 2012-01-30 15:18:00 +0100 | [diff] [blame] | 952 | if (test_and_clear_sta_flag(sta, WLAN_STA_PS_STA)) |
| 953 | atomic_dec(&sdata->bss->num_sta_ps); |
Johannes Berg | 50a9432 | 2010-11-16 11:50:28 -0800 | [diff] [blame] | 954 | } |
| 955 | |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 956 | /* powersave support code */ |
| 957 | void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta) |
| 958 | { |
| 959 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 960 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 961 | struct sk_buff_head pending; |
| 962 | int filtered = 0, buffered = 0, ac; |
Arik Nemtsov | 6040700 | 2012-11-05 10:27:52 +0200 | [diff] [blame] | 963 | unsigned long flags; |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 964 | |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 965 | clear_sta_flag(sta, WLAN_STA_SP); |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 966 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 967 | BUILD_BUG_ON(BITS_TO_LONGS(STA_TID_NUM) > 1); |
| 968 | sta->driver_buffered_tids = 0; |
| 969 | |
Arik Nemtsov | d057e5a | 2011-01-31 22:29:13 +0200 | [diff] [blame] | 970 | if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS)) |
| 971 | drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 972 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 973 | skb_queue_head_init(&pending); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 974 | |
Emmanuel Grumbach | 63ef223 | 2014-02-20 09:22:11 +0200 | [diff] [blame] | 975 | /* sync with ieee80211_tx_h_unicast_ps_buf */ |
| 976 | spin_lock(&sta->ps_lock); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 977 | /* Send all buffered frames to the station */ |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 978 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 979 | int count = skb_queue_len(&pending), tmp; |
| 980 | |
Arik Nemtsov | 6040700 | 2012-11-05 10:27:52 +0200 | [diff] [blame] | 981 | spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags); |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 982 | skb_queue_splice_tail_init(&sta->tx_filtered[ac], &pending); |
Arik Nemtsov | 6040700 | 2012-11-05 10:27:52 +0200 | [diff] [blame] | 983 | spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags); |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 984 | tmp = skb_queue_len(&pending); |
| 985 | filtered += tmp - count; |
| 986 | count = tmp; |
| 987 | |
Arik Nemtsov | 6040700 | 2012-11-05 10:27:52 +0200 | [diff] [blame] | 988 | spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags); |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 989 | skb_queue_splice_tail_init(&sta->ps_tx_buf[ac], &pending); |
Arik Nemtsov | 6040700 | 2012-11-05 10:27:52 +0200 | [diff] [blame] | 990 | spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags); |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 991 | tmp = skb_queue_len(&pending); |
| 992 | buffered += tmp - count; |
| 993 | } |
| 994 | |
| 995 | ieee80211_add_pending_skbs_fn(local, &pending, clear_sta_ps_flags, sta); |
Emmanuel Grumbach | 63ef223 | 2014-02-20 09:22:11 +0200 | [diff] [blame] | 996 | spin_unlock(&sta->ps_lock); |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 997 | |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 998 | local->total_ps_buffered -= buffered; |
| 999 | |
Johannes Berg | c868cb3 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 1000 | sta_info_recalc_tim(sta); |
| 1001 | |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1002 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
| 1003 | 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] | 1004 | "since STA not sleeping anymore\n", sdata->name, |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1005 | sta->sta.addr, sta->sta.aid, filtered, buffered); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1006 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
| 1007 | } |
| 1008 | |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1009 | static void ieee80211_send_null_response(struct ieee80211_sub_if_data *sdata, |
| 1010 | struct sta_info *sta, int tid, |
Johannes Berg | 40b9640 | 2011-09-29 16:04:38 +0200 | [diff] [blame] | 1011 | enum ieee80211_frame_release_type reason) |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1012 | { |
| 1013 | struct ieee80211_local *local = sdata->local; |
| 1014 | struct ieee80211_qos_hdr *nullfunc; |
| 1015 | struct sk_buff *skb; |
| 1016 | int size = sizeof(*nullfunc); |
| 1017 | __le16 fc; |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1018 | bool qos = test_sta_flag(sta, WLAN_STA_WME); |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1019 | struct ieee80211_tx_info *info; |
| 1020 | |
| 1021 | if (qos) { |
| 1022 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | |
| 1023 | IEEE80211_STYPE_QOS_NULLFUNC | |
| 1024 | IEEE80211_FCTL_FROMDS); |
| 1025 | } else { |
| 1026 | size -= 2; |
| 1027 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | |
| 1028 | IEEE80211_STYPE_NULLFUNC | |
| 1029 | IEEE80211_FCTL_FROMDS); |
| 1030 | } |
| 1031 | |
| 1032 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + size); |
| 1033 | if (!skb) |
| 1034 | return; |
| 1035 | |
| 1036 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 1037 | |
| 1038 | nullfunc = (void *) skb_put(skb, size); |
| 1039 | nullfunc->frame_control = fc; |
| 1040 | nullfunc->duration_id = 0; |
| 1041 | memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN); |
| 1042 | memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); |
| 1043 | memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN); |
| 1044 | |
Johannes Berg | 59b6625 | 2011-10-13 13:19:19 +0200 | [diff] [blame] | 1045 | skb->priority = tid; |
| 1046 | skb_set_queue_mapping(skb, ieee802_1d_to_ac[tid]); |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1047 | if (qos) { |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1048 | nullfunc->qos_ctrl = cpu_to_le16(tid); |
| 1049 | |
Johannes Berg | 40b9640 | 2011-09-29 16:04:38 +0200 | [diff] [blame] | 1050 | if (reason == IEEE80211_FRAME_RELEASE_UAPSD) |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1051 | nullfunc->qos_ctrl |= |
| 1052 | cpu_to_le16(IEEE80211_QOS_CTL_EOSP); |
| 1053 | } |
| 1054 | |
| 1055 | info = IEEE80211_SKB_CB(skb); |
| 1056 | |
| 1057 | /* |
| 1058 | * Tell TX path to send this frame even though the |
| 1059 | * STA may still remain is PS mode after this frame |
Johannes Berg | deeaee1 | 2011-09-29 16:04:35 +0200 | [diff] [blame] | 1060 | * exchange. Also set EOSP to indicate this packet |
| 1061 | * ends the poll/service period. |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1062 | */ |
Johannes Berg | 02f2f1a | 2012-02-27 12:18:30 +0100 | [diff] [blame] | 1063 | info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER | |
Johannes Berg | deeaee1 | 2011-09-29 16:04:35 +0200 | [diff] [blame] | 1064 | IEEE80211_TX_STATUS_EOSP | |
| 1065 | IEEE80211_TX_CTL_REQ_TX_STATUS; |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1066 | |
Johannes Berg | 40b9640 | 2011-09-29 16:04:38 +0200 | [diff] [blame] | 1067 | drv_allow_buffered_frames(local, sta, BIT(tid), 1, reason, false); |
| 1068 | |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1069 | ieee80211_xmit(sdata, skb); |
| 1070 | } |
| 1071 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1072 | static void |
| 1073 | ieee80211_sta_ps_deliver_response(struct sta_info *sta, |
| 1074 | int n_frames, u8 ignored_acs, |
| 1075 | enum ieee80211_frame_release_type reason) |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1076 | { |
| 1077 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 1078 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1079 | bool found = false; |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1080 | bool more_data = false; |
| 1081 | int ac; |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1082 | unsigned long driver_release_tids = 0; |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1083 | struct sk_buff_head frames; |
| 1084 | |
Johannes Berg | deeaee1 | 2011-09-29 16:04:35 +0200 | [diff] [blame] | 1085 | /* Service or PS-Poll period starts */ |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1086 | set_sta_flag(sta, WLAN_STA_SP); |
Johannes Berg | deeaee1 | 2011-09-29 16:04:35 +0200 | [diff] [blame] | 1087 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1088 | __skb_queue_head_init(&frames); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1089 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1090 | /* |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1091 | * Get response frame(s) and more data bit for it. |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1092 | */ |
| 1093 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1094 | unsigned long tids; |
| 1095 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1096 | if (ignored_acs & BIT(ac)) |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1097 | continue; |
| 1098 | |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1099 | tids = ieee80211_tids_for_ac(ac); |
| 1100 | |
| 1101 | if (!found) { |
| 1102 | driver_release_tids = sta->driver_buffered_tids & tids; |
| 1103 | if (driver_release_tids) { |
| 1104 | found = true; |
| 1105 | } else { |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1106 | struct sk_buff *skb; |
| 1107 | |
| 1108 | while (n_frames > 0) { |
| 1109 | skb = skb_dequeue(&sta->tx_filtered[ac]); |
| 1110 | if (!skb) { |
| 1111 | skb = skb_dequeue( |
| 1112 | &sta->ps_tx_buf[ac]); |
| 1113 | if (skb) |
| 1114 | local->total_ps_buffered--; |
| 1115 | } |
| 1116 | if (!skb) |
| 1117 | break; |
| 1118 | n_frames--; |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1119 | found = true; |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1120 | __skb_queue_tail(&frames, skb); |
| 1121 | } |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | /* |
| 1125 | * If the driver has data on more than one TID then |
| 1126 | * certainly there's more data if we release just a |
| 1127 | * single frame now (from a single TID). |
| 1128 | */ |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1129 | if (reason == IEEE80211_FRAME_RELEASE_PSPOLL && |
| 1130 | hweight16(driver_release_tids) > 1) { |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1131 | more_data = true; |
| 1132 | driver_release_tids = |
| 1133 | BIT(ffs(driver_release_tids) - 1); |
| 1134 | break; |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1135 | } |
| 1136 | } |
| 1137 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1138 | if (!skb_queue_empty(&sta->tx_filtered[ac]) || |
| 1139 | !skb_queue_empty(&sta->ps_tx_buf[ac])) { |
| 1140 | more_data = true; |
| 1141 | break; |
| 1142 | } |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1143 | } |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1144 | |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1145 | if (!found) { |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1146 | int tid; |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1147 | |
Johannes Berg | ce662b44 | 2011-09-29 16:04:34 +0200 | [diff] [blame] | 1148 | /* |
| 1149 | * For PS-Poll, this can only happen due to a race condition |
| 1150 | * when we set the TIM bit and the station notices it, but |
| 1151 | * before it can poll for the frame we expire it. |
| 1152 | * |
| 1153 | * For uAPSD, this is said in the standard (11.2.1.5 h): |
| 1154 | * At each unscheduled SP for a non-AP STA, the AP shall |
| 1155 | * attempt to transmit at least one MSDU or MMPDU, but no |
| 1156 | * more than the value specified in the Max SP Length field |
| 1157 | * in the QoS Capability element from delivery-enabled ACs, |
| 1158 | * that are destined for the non-AP STA. |
| 1159 | * |
| 1160 | * Since we have no other MSDU/MMPDU, transmit a QoS null frame. |
| 1161 | */ |
| 1162 | |
| 1163 | /* This will evaluate to 1, 3, 5 or 7. */ |
| 1164 | tid = 7 - ((ffs(~ignored_acs) - 1) << 1); |
| 1165 | |
Johannes Berg | 40b9640 | 2011-09-29 16:04:38 +0200 | [diff] [blame] | 1166 | ieee80211_send_null_response(sdata, sta, tid, reason); |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1167 | return; |
| 1168 | } |
| 1169 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1170 | if (!driver_release_tids) { |
| 1171 | struct sk_buff_head pending; |
| 1172 | struct sk_buff *skb; |
Johannes Berg | 40b9640 | 2011-09-29 16:04:38 +0200 | [diff] [blame] | 1173 | int num = 0; |
| 1174 | u16 tids = 0; |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1175 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1176 | skb_queue_head_init(&pending); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1177 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1178 | while ((skb = __skb_dequeue(&frames))) { |
| 1179 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1180 | struct ieee80211_hdr *hdr = (void *) skb->data; |
Johannes Berg | 40b9640 | 2011-09-29 16:04:38 +0200 | [diff] [blame] | 1181 | u8 *qoshdr = NULL; |
| 1182 | |
| 1183 | num++; |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1184 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1185 | /* |
| 1186 | * Tell TX path to send this frame even though the |
| 1187 | * STA may still remain is PS mode after this frame |
| 1188 | * exchange. |
| 1189 | */ |
Johannes Berg | 02f2f1a | 2012-02-27 12:18:30 +0100 | [diff] [blame] | 1190 | info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER; |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1191 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1192 | /* |
| 1193 | * Use MoreData flag to indicate whether there are |
| 1194 | * more buffered frames for this STA |
| 1195 | */ |
Janusz.Dziedzic@tieto.com | 24b9c37 | 2011-11-07 09:47:47 +0200 | [diff] [blame] | 1196 | if (more_data || !skb_queue_empty(&frames)) |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1197 | hdr->frame_control |= |
| 1198 | cpu_to_le16(IEEE80211_FCTL_MOREDATA); |
Janusz.Dziedzic@tieto.com | 24b9c37 | 2011-11-07 09:47:47 +0200 | [diff] [blame] | 1199 | else |
| 1200 | hdr->frame_control &= |
| 1201 | cpu_to_le16(~IEEE80211_FCTL_MOREDATA); |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1202 | |
Johannes Berg | 40b9640 | 2011-09-29 16:04:38 +0200 | [diff] [blame] | 1203 | if (ieee80211_is_data_qos(hdr->frame_control) || |
| 1204 | ieee80211_is_qos_nullfunc(hdr->frame_control)) |
| 1205 | qoshdr = ieee80211_get_qos_ctl(hdr); |
| 1206 | |
| 1207 | /* set EOSP for the frame */ |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1208 | if (reason == IEEE80211_FRAME_RELEASE_UAPSD && |
Johannes Berg | 40b9640 | 2011-09-29 16:04:38 +0200 | [diff] [blame] | 1209 | qoshdr && skb_queue_empty(&frames)) |
| 1210 | *qoshdr |= IEEE80211_QOS_CTL_EOSP; |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1211 | |
Johannes Berg | deeaee1 | 2011-09-29 16:04:35 +0200 | [diff] [blame] | 1212 | info->flags |= IEEE80211_TX_STATUS_EOSP | |
| 1213 | IEEE80211_TX_CTL_REQ_TX_STATUS; |
| 1214 | |
Johannes Berg | 40b9640 | 2011-09-29 16:04:38 +0200 | [diff] [blame] | 1215 | if (qoshdr) |
| 1216 | tids |= BIT(*qoshdr & IEEE80211_QOS_CTL_TID_MASK); |
| 1217 | else |
| 1218 | tids |= BIT(0); |
| 1219 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1220 | __skb_queue_tail(&pending, skb); |
| 1221 | } |
| 1222 | |
Johannes Berg | 40b9640 | 2011-09-29 16:04:38 +0200 | [diff] [blame] | 1223 | drv_allow_buffered_frames(local, sta, tids, num, |
| 1224 | reason, more_data); |
| 1225 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1226 | ieee80211_add_pending_skbs(local, &pending); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1227 | |
Johannes Berg | c868cb3 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 1228 | sta_info_recalc_tim(sta); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1229 | } else { |
| 1230 | /* |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1231 | * We need to release a frame that is buffered somewhere in the |
| 1232 | * driver ... it'll have to handle that. |
| 1233 | * Note that, as per the comment above, it'll also have to see |
| 1234 | * if there is more than just one frame on the specific TID that |
| 1235 | * we're releasing from, and it needs to set the more-data bit |
| 1236 | * accordingly if we tell it that there's no more data. If we do |
| 1237 | * tell it there's more data, then of course the more-data bit |
| 1238 | * needs to be set anyway. |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1239 | */ |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1240 | drv_release_buffered_frames(local, sta, driver_release_tids, |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1241 | n_frames, reason, more_data); |
Johannes Berg | 4049e09 | 2011-09-29 16:04:32 +0200 | [diff] [blame] | 1242 | |
| 1243 | /* |
| 1244 | * Note that we don't recalculate the TIM bit here as it would |
| 1245 | * most likely have no effect at all unless the driver told us |
| 1246 | * that the TID became empty before returning here from the |
| 1247 | * release function. |
| 1248 | * Either way, however, when the driver tells us that the TID |
| 1249 | * became empty we'll do the TIM recalculation. |
| 1250 | */ |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1251 | } |
| 1252 | } |
| 1253 | |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1254 | void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta) |
| 1255 | { |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1256 | u8 ignore_for_response = sta->sta.uapsd_queues; |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1257 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1258 | /* |
| 1259 | * If all ACs are delivery-enabled then we should reply |
| 1260 | * from any of them, if only some are enabled we reply |
| 1261 | * only from the non-enabled ones. |
| 1262 | */ |
| 1263 | if (ignore_for_response == BIT(IEEE80211_NUM_ACS) - 1) |
| 1264 | ignore_for_response = 0; |
| 1265 | |
| 1266 | ieee80211_sta_ps_deliver_response(sta, 1, ignore_for_response, |
| 1267 | IEEE80211_FRAME_RELEASE_PSPOLL); |
| 1268 | } |
| 1269 | |
| 1270 | void ieee80211_sta_ps_deliver_uapsd(struct sta_info *sta) |
| 1271 | { |
| 1272 | int n_frames = sta->sta.max_sp; |
| 1273 | u8 delivery_enabled = sta->sta.uapsd_queues; |
| 1274 | |
| 1275 | /* |
| 1276 | * If we ever grow support for TSPEC this might happen if |
| 1277 | * the TSPEC update from hostapd comes in between a trigger |
| 1278 | * frame setting WLAN_STA_UAPSD in the RX path and this |
| 1279 | * actually getting called. |
| 1280 | */ |
| 1281 | if (!delivery_enabled) |
| 1282 | return; |
| 1283 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1284 | switch (sta->sta.max_sp) { |
| 1285 | case 1: |
| 1286 | n_frames = 2; |
| 1287 | break; |
| 1288 | case 2: |
| 1289 | n_frames = 4; |
| 1290 | break; |
| 1291 | case 3: |
| 1292 | n_frames = 6; |
| 1293 | break; |
| 1294 | case 0: |
| 1295 | /* XXX: what is a good value? */ |
| 1296 | n_frames = 8; |
| 1297 | break; |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1298 | } |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1299 | |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1300 | ieee80211_sta_ps_deliver_response(sta, n_frames, ~delivery_enabled, |
| 1301 | IEEE80211_FRAME_RELEASE_UAPSD); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | void ieee80211_sta_block_awake(struct ieee80211_hw *hw, |
| 1305 | struct ieee80211_sta *pubsta, bool block) |
| 1306 | { |
| 1307 | struct sta_info *sta = container_of(pubsta, struct sta_info, sta); |
| 1308 | |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 1309 | trace_api_sta_block_awake(sta->local, pubsta, block); |
| 1310 | |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1311 | if (block) |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1312 | set_sta_flag(sta, WLAN_STA_PS_DRIVER); |
| 1313 | else if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1314 | ieee80211_queue_work(hw, &sta->drv_unblock_wk); |
| 1315 | } |
| 1316 | EXPORT_SYMBOL(ieee80211_sta_block_awake); |
Felix Fietkau | dcf55fb | 2011-04-17 17:45:00 +0200 | [diff] [blame] | 1317 | |
Johannes Berg | 37fbd90 | 2011-09-29 16:04:39 +0200 | [diff] [blame] | 1318 | void ieee80211_sta_eosp_irqsafe(struct ieee80211_sta *pubsta) |
| 1319 | { |
| 1320 | struct sta_info *sta = container_of(pubsta, struct sta_info, sta); |
| 1321 | struct ieee80211_local *local = sta->local; |
| 1322 | struct sk_buff *skb; |
| 1323 | struct skb_eosp_msg_data *data; |
| 1324 | |
| 1325 | trace_api_eosp(local, pubsta); |
| 1326 | |
| 1327 | skb = alloc_skb(0, GFP_ATOMIC); |
| 1328 | if (!skb) { |
| 1329 | /* too bad ... but race is better than loss */ |
| 1330 | clear_sta_flag(sta, WLAN_STA_SP); |
| 1331 | return; |
| 1332 | } |
| 1333 | |
| 1334 | data = (void *)skb->cb; |
| 1335 | memcpy(data->sta, pubsta->addr, ETH_ALEN); |
| 1336 | memcpy(data->iface, sta->sdata->vif.addr, ETH_ALEN); |
| 1337 | skb->pkt_type = IEEE80211_EOSP_MSG; |
| 1338 | skb_queue_tail(&local->skb_queue, skb); |
| 1339 | tasklet_schedule(&local->tasklet); |
| 1340 | } |
| 1341 | EXPORT_SYMBOL(ieee80211_sta_eosp_irqsafe); |
| 1342 | |
Johannes Berg | 042ec45 | 2011-09-29 16:04:26 +0200 | [diff] [blame] | 1343 | void ieee80211_sta_set_buffered(struct ieee80211_sta *pubsta, |
| 1344 | u8 tid, bool buffered) |
Felix Fietkau | dcf55fb | 2011-04-17 17:45:00 +0200 | [diff] [blame] | 1345 | { |
| 1346 | struct sta_info *sta = container_of(pubsta, struct sta_info, sta); |
| 1347 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1348 | if (WARN_ON(tid >= STA_TID_NUM)) |
Johannes Berg | 042ec45 | 2011-09-29 16:04:26 +0200 | [diff] [blame] | 1349 | return; |
| 1350 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 1351 | if (buffered) |
| 1352 | set_bit(tid, &sta->driver_buffered_tids); |
| 1353 | else |
| 1354 | clear_bit(tid, &sta->driver_buffered_tids); |
| 1355 | |
Johannes Berg | c868cb3 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 1356 | sta_info_recalc_tim(sta); |
Felix Fietkau | dcf55fb | 2011-04-17 17:45:00 +0200 | [diff] [blame] | 1357 | } |
Johannes Berg | 042ec45 | 2011-09-29 16:04:26 +0200 | [diff] [blame] | 1358 | EXPORT_SYMBOL(ieee80211_sta_set_buffered); |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1359 | |
Johannes Berg | 83d5cc0 | 2012-01-12 09:31:10 +0100 | [diff] [blame] | 1360 | int sta_info_move_state(struct sta_info *sta, |
| 1361 | enum ieee80211_sta_state new_state) |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1362 | { |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 1363 | might_sleep(); |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1364 | |
| 1365 | if (sta->sta_state == new_state) |
| 1366 | return 0; |
| 1367 | |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 1368 | /* check allowed transitions first */ |
| 1369 | |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1370 | switch (new_state) { |
| 1371 | case IEEE80211_STA_NONE: |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 1372 | if (sta->sta_state != IEEE80211_STA_AUTH) |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1373 | return -EINVAL; |
| 1374 | break; |
| 1375 | case IEEE80211_STA_AUTH: |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 1376 | if (sta->sta_state != IEEE80211_STA_NONE && |
| 1377 | sta->sta_state != IEEE80211_STA_ASSOC) |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1378 | return -EINVAL; |
| 1379 | break; |
| 1380 | case IEEE80211_STA_ASSOC: |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 1381 | if (sta->sta_state != IEEE80211_STA_AUTH && |
| 1382 | sta->sta_state != IEEE80211_STA_AUTHORIZED) |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1383 | return -EINVAL; |
| 1384 | break; |
| 1385 | case IEEE80211_STA_AUTHORIZED: |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 1386 | if (sta->sta_state != IEEE80211_STA_ASSOC) |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1387 | return -EINVAL; |
| 1388 | break; |
| 1389 | default: |
| 1390 | WARN(1, "invalid state %d", new_state); |
| 1391 | return -EINVAL; |
| 1392 | } |
| 1393 | |
Felix Fietkau | 7902759 | 2012-02-07 12:45:44 +0100 | [diff] [blame] | 1394 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1395 | printk(KERN_DEBUG "%s: moving STA %pM to state %d\n", |
| 1396 | sta->sdata->name, sta->sta.addr, new_state); |
Felix Fietkau | 7902759 | 2012-02-07 12:45:44 +0100 | [diff] [blame] | 1397 | #endif |
Johannes Berg | f09603a | 2012-01-20 13:55:21 +0100 | [diff] [blame] | 1398 | |
| 1399 | /* |
| 1400 | * notify the driver before the actual changes so it can |
| 1401 | * fail the transition |
| 1402 | */ |
| 1403 | if (test_sta_flag(sta, WLAN_STA_INSERTED)) { |
| 1404 | int err = drv_sta_state(sta->local, sta->sdata, sta, |
| 1405 | sta->sta_state, new_state); |
| 1406 | if (err) |
| 1407 | return err; |
| 1408 | } |
| 1409 | |
| 1410 | /* reflect the change in all state variables */ |
| 1411 | |
| 1412 | switch (new_state) { |
| 1413 | case IEEE80211_STA_NONE: |
| 1414 | if (sta->sta_state == IEEE80211_STA_AUTH) |
| 1415 | clear_bit(WLAN_STA_AUTH, &sta->_flags); |
| 1416 | break; |
| 1417 | case IEEE80211_STA_AUTH: |
| 1418 | if (sta->sta_state == IEEE80211_STA_NONE) |
| 1419 | set_bit(WLAN_STA_AUTH, &sta->_flags); |
| 1420 | else if (sta->sta_state == IEEE80211_STA_ASSOC) |
| 1421 | clear_bit(WLAN_STA_ASSOC, &sta->_flags); |
| 1422 | break; |
| 1423 | case IEEE80211_STA_ASSOC: |
| 1424 | if (sta->sta_state == IEEE80211_STA_AUTH) { |
| 1425 | set_bit(WLAN_STA_ASSOC, &sta->_flags); |
| 1426 | } else if (sta->sta_state == IEEE80211_STA_AUTHORIZED) { |
| 1427 | if (sta->sdata->vif.type == NL80211_IFTYPE_AP) |
| 1428 | atomic_dec(&sta->sdata->u.ap.num_sta_authorized); |
| 1429 | clear_bit(WLAN_STA_AUTHORIZED, &sta->_flags); |
| 1430 | } |
| 1431 | break; |
| 1432 | case IEEE80211_STA_AUTHORIZED: |
| 1433 | if (sta->sta_state == IEEE80211_STA_ASSOC) { |
| 1434 | if (sta->sdata->vif.type == NL80211_IFTYPE_AP) |
| 1435 | atomic_inc(&sta->sdata->u.ap.num_sta_authorized); |
| 1436 | set_bit(WLAN_STA_AUTHORIZED, &sta->_flags); |
| 1437 | } |
| 1438 | break; |
| 1439 | default: |
| 1440 | break; |
| 1441 | } |
| 1442 | |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1443 | sta->sta_state = new_state; |
| 1444 | |
| 1445 | return 0; |
| 1446 | } |