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 |
| 50 | * receive an assocation 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 |
| 52 | * the peer imediately upon device open. When using AP mode we add stations |
| 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 | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 70 | s = local->sta_hash[STA_HASH(sta->sta.addr)]; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 71 | if (!s) |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 72 | return -ENOENT; |
| 73 | if (s == sta) { |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 74 | rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 75 | s->hnext); |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 76 | return 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 79 | while (s->hnext && s->hnext != sta) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 80 | s = s->hnext; |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 81 | if (s->hnext) { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 82 | rcu_assign_pointer(s->hnext, sta->hnext); |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 83 | return 0; |
| 84 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 85 | |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 86 | return -ENOENT; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 89 | /* protected by RCU */ |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 90 | struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata, |
| 91 | const u8 *addr) |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 92 | { |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 93 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 94 | struct sta_info *sta; |
| 95 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 96 | sta = rcu_dereference(local->sta_hash[STA_HASH(addr)]); |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 97 | while (sta) { |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 98 | if (sta->sdata == sdata && |
| 99 | memcmp(sta->sta.addr, addr, ETH_ALEN) == 0) |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 100 | break; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 101 | sta = rcu_dereference(sta->hnext); |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 102 | } |
| 103 | return sta; |
| 104 | } |
| 105 | |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 106 | /* |
| 107 | * Get sta info either from the specified interface |
| 108 | * or from one of its vlans |
| 109 | */ |
| 110 | struct sta_info *sta_info_get_bss(struct ieee80211_sub_if_data *sdata, |
| 111 | const u8 *addr) |
| 112 | { |
| 113 | struct ieee80211_local *local = sdata->local; |
| 114 | struct sta_info *sta; |
| 115 | |
| 116 | sta = rcu_dereference(local->sta_hash[STA_HASH(addr)]); |
| 117 | while (sta) { |
| 118 | if ((sta->sdata == sdata || |
| 119 | sta->sdata->bss == sdata->bss) && |
| 120 | memcmp(sta->sta.addr, addr, ETH_ALEN) == 0) |
| 121 | break; |
| 122 | sta = rcu_dereference(sta->hnext); |
| 123 | } |
| 124 | return sta; |
| 125 | } |
| 126 | |
Johannes Berg | 3b53fde8 | 2009-11-16 12:00:37 +0100 | [diff] [blame] | 127 | struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata, |
| 128 | int idx) |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 129 | { |
Johannes Berg | 3b53fde8 | 2009-11-16 12:00:37 +0100 | [diff] [blame] | 130 | struct ieee80211_local *local = sdata->local; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 131 | struct sta_info *sta; |
| 132 | int i = 0; |
| 133 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 134 | list_for_each_entry_rcu(sta, &local->sta_list, list) { |
Johannes Berg | 3b53fde8 | 2009-11-16 12:00:37 +0100 | [diff] [blame] | 135 | if (sdata != sta->sdata) |
Luis Carlos Cobo | 2a8ca29 | 2008-02-29 17:51:25 -0800 | [diff] [blame] | 136 | continue; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 137 | if (i < idx) { |
| 138 | ++i; |
| 139 | continue; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 140 | } |
Luis Carlos Cobo | 2a8ca29 | 2008-02-29 17:51:25 -0800 | [diff] [blame] | 141 | return sta; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 142 | } |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 143 | |
| 144 | return NULL; |
| 145 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 146 | |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 147 | /** |
| 148 | * __sta_info_free - internal STA free helper |
| 149 | * |
Randy Dunlap | 6ef307b | 2008-07-03 13:52:18 -0700 | [diff] [blame] | 150 | * @local: pointer to the global information |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 151 | * @sta: STA info to free |
| 152 | * |
| 153 | * This function must undo everything done by sta_info_alloc() |
| 154 | * that may happen before sta_info_insert(). |
| 155 | */ |
| 156 | static void __sta_info_free(struct ieee80211_local *local, |
| 157 | struct sta_info *sta) |
| 158 | { |
Johannes Berg | af65cd96 | 2009-11-17 18:18:36 +0100 | [diff] [blame] | 159 | if (sta->rate_ctrl) { |
| 160 | rate_control_free_sta(sta); |
| 161 | rate_control_put(sta->rate_ctrl); |
| 162 | } |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 163 | |
| 164 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 165 | printk(KERN_DEBUG "%s: Destroyed STA %pM\n", |
| 166 | wiphy_name(local->hw.wiphy), sta->sta.addr); |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 167 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 168 | |
| 169 | kfree(sta); |
| 170 | } |
| 171 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 172 | /* Caller must hold local->sta_lock */ |
| 173 | static void sta_info_hash_add(struct ieee80211_local *local, |
| 174 | struct sta_info *sta) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 175 | { |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 176 | sta->hnext = local->sta_hash[STA_HASH(sta->sta.addr)]; |
| 177 | rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 178 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 179 | |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 180 | static void sta_unblock(struct work_struct *wk) |
| 181 | { |
| 182 | struct sta_info *sta; |
| 183 | |
| 184 | sta = container_of(wk, struct sta_info, drv_unblock_wk); |
| 185 | |
| 186 | if (sta->dead) |
| 187 | return; |
| 188 | |
| 189 | if (!test_sta_flags(sta, WLAN_STA_PS_STA)) |
| 190 | ieee80211_sta_ps_deliver_wakeup(sta); |
| 191 | else if (test_and_clear_sta_flags(sta, WLAN_STA_PSPOLL)) |
| 192 | ieee80211_sta_ps_deliver_poll_response(sta); |
| 193 | } |
| 194 | |
Johannes Berg | af65cd96 | 2009-11-17 18:18:36 +0100 | [diff] [blame] | 195 | static int sta_prepare_rate_control(struct ieee80211_local *local, |
| 196 | struct sta_info *sta, gfp_t gfp) |
| 197 | { |
| 198 | if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) |
| 199 | return 0; |
| 200 | |
| 201 | sta->rate_ctrl = rate_control_get(local->rate_ctrl); |
| 202 | sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl, |
| 203 | &sta->sta, gfp); |
| 204 | if (!sta->rate_ctrl_priv) { |
| 205 | rate_control_put(sta->rate_ctrl); |
| 206 | return -ENOMEM; |
| 207 | } |
| 208 | |
| 209 | return 0; |
| 210 | } |
| 211 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 212 | struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata, |
| 213 | u8 *addr, gfp_t gfp) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 214 | { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 215 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 216 | struct sta_info *sta; |
Ron Rindjunsky | 16c5f15 | 2007-12-25 17:00:34 +0200 | [diff] [blame] | 217 | int i; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 218 | |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 219 | sta = kzalloc(sizeof(*sta) + local->hw.sta_data_size, gfp); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 220 | if (!sta) |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 221 | return NULL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 222 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 223 | spin_lock_init(&sta->lock); |
Johannes Berg | 5a9f7b0 | 2008-06-18 14:58:09 +0200 | [diff] [blame] | 224 | spin_lock_init(&sta->flaglock); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 225 | INIT_WORK(&sta->drv_unblock_wk, sta_unblock); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 226 | |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 227 | memcpy(sta->sta.addr, addr, ETH_ALEN); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 228 | sta->local = local; |
| 229 | sta->sdata = sdata; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 230 | |
Johannes Berg | af65cd96 | 2009-11-17 18:18:36 +0100 | [diff] [blame] | 231 | if (sta_prepare_rate_control(local, sta, gfp)) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 232 | kfree(sta); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 233 | return NULL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Ron Rindjunsky | 16c5f15 | 2007-12-25 17:00:34 +0200 | [diff] [blame] | 236 | for (i = 0; i < STA_TID_NUM; i++) { |
| 237 | /* timer_to_tid must be initialized with identity mapping to |
| 238 | * enable session_timer's data differentiation. refer to |
| 239 | * sta_rx_agg_session_timer_expired for useage */ |
| 240 | sta->timer_to_tid[i] = i; |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 241 | /* tx */ |
| 242 | sta->ampdu_mlme.tid_state_tx[i] = HT_AGG_STATE_IDLE; |
| 243 | sta->ampdu_mlme.tid_tx[i] = NULL; |
| 244 | sta->ampdu_mlme.addba_req_num[i] = 0; |
Ron Rindjunsky | 16c5f15 | 2007-12-25 17:00:34 +0200 | [diff] [blame] | 245 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 246 | skb_queue_head_init(&sta->ps_tx_buf); |
| 247 | skb_queue_head_init(&sta->tx_filtered); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 248 | |
Senthil Balasubramanian | cccaec9 | 2009-05-14 18:42:08 +0530 | [diff] [blame] | 249 | for (i = 0; i < NUM_RX_DATA_QUEUES; i++) |
| 250 | sta->last_seq_ctrl[i] = cpu_to_le16(USHORT_MAX); |
| 251 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 252 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 253 | printk(KERN_DEBUG "%s: Allocated STA %pM\n", |
| 254 | wiphy_name(local->hw.wiphy), sta->sta.addr); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 255 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 256 | |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 257 | #ifdef CONFIG_MAC80211_MESH |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 258 | sta->plink_state = PLINK_LISTEN; |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 259 | init_timer(&sta->plink_timer); |
| 260 | #endif |
| 261 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 262 | return sta; |
| 263 | } |
| 264 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 265 | static int sta_info_finish_insert(struct sta_info *sta, bool async) |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 266 | { |
| 267 | struct ieee80211_local *local = sta->local; |
| 268 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 269 | struct station_info sinfo; |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 270 | unsigned long flags; |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 271 | int err = 0; |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 272 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 273 | WARN_ON(!mutex_is_locked(&local->sta_mtx)); |
| 274 | |
| 275 | /* notify driver */ |
| 276 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
| 277 | sdata = container_of(sdata->bss, |
| 278 | struct ieee80211_sub_if_data, |
| 279 | u.ap); |
| 280 | err = drv_sta_add(local, sdata, &sta->sta); |
| 281 | if (err) { |
| 282 | if (!async) |
| 283 | return err; |
| 284 | printk(KERN_DEBUG "%s: failed to add IBSS STA %pM to driver (%d)" |
| 285 | " - keeping it anyway.\n", |
| 286 | sdata->name, sta->sta.addr, err); |
| 287 | } else { |
| 288 | sta->uploaded = true; |
| 289 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
| 290 | if (async) |
| 291 | printk(KERN_DEBUG "%s: Finished adding IBSS STA %pM\n", |
| 292 | wiphy_name(local->hw.wiphy), sta->sta.addr); |
| 293 | #endif |
| 294 | } |
| 295 | |
| 296 | sdata = sta->sdata; |
| 297 | |
| 298 | if (!async) { |
| 299 | local->num_sta++; |
| 300 | local->sta_generation++; |
| 301 | smp_mb(); |
| 302 | |
| 303 | /* make the station visible */ |
| 304 | spin_lock_irqsave(&local->sta_lock, flags); |
| 305 | sta_info_hash_add(local, sta); |
| 306 | spin_unlock_irqrestore(&local->sta_lock, flags); |
| 307 | } |
| 308 | |
| 309 | list_add(&sta->list, &local->sta_list); |
| 310 | |
| 311 | ieee80211_sta_debugfs_add(sta); |
| 312 | rate_control_add_sta_debugfs(sta); |
| 313 | |
| 314 | sinfo.filled = 0; |
| 315 | sinfo.generation = local->sta_generation; |
| 316 | cfg80211_new_sta(sdata->dev, sta->sta.addr, &sinfo, GFP_KERNEL); |
| 317 | |
| 318 | |
| 319 | return 0; |
| 320 | } |
| 321 | |
| 322 | static void sta_info_finish_pending(struct ieee80211_local *local) |
| 323 | { |
| 324 | struct sta_info *sta; |
| 325 | unsigned long flags; |
| 326 | |
| 327 | spin_lock_irqsave(&local->sta_lock, flags); |
| 328 | while (!list_empty(&local->sta_pending_list)) { |
| 329 | sta = list_first_entry(&local->sta_pending_list, |
| 330 | struct sta_info, list); |
| 331 | list_del(&sta->list); |
| 332 | spin_unlock_irqrestore(&local->sta_lock, flags); |
| 333 | |
| 334 | sta_info_finish_insert(sta, true); |
| 335 | |
| 336 | spin_lock_irqsave(&local->sta_lock, flags); |
| 337 | } |
| 338 | spin_unlock_irqrestore(&local->sta_lock, flags); |
| 339 | } |
| 340 | |
| 341 | static void sta_info_finish_work(struct work_struct *work) |
| 342 | { |
| 343 | struct ieee80211_local *local = |
| 344 | container_of(work, struct ieee80211_local, sta_finish_work); |
| 345 | |
| 346 | mutex_lock(&local->sta_mtx); |
| 347 | sta_info_finish_pending(local); |
| 348 | mutex_unlock(&local->sta_mtx); |
| 349 | } |
| 350 | |
| 351 | int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU) |
| 352 | { |
| 353 | struct ieee80211_local *local = sta->local; |
| 354 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 355 | unsigned long flags; |
| 356 | int err = 0; |
| 357 | |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 358 | /* |
| 359 | * Can't be a WARN_ON because it can be triggered through a race: |
| 360 | * something inserts a STA (on one CPU) without holding the RTNL |
| 361 | * and another CPU turns off the net device. |
| 362 | */ |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 363 | if (unlikely(!ieee80211_sdata_running(sdata))) { |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 364 | err = -ENETDOWN; |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 365 | rcu_read_lock(); |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 366 | goto out_free; |
| 367 | } |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 368 | |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 369 | if (WARN_ON(compare_ether_addr(sta->sta.addr, sdata->vif.addr) == 0 || |
Johannes Berg | c6a1fa1 | 2008-10-07 12:04:32 +0200 | [diff] [blame] | 370 | is_multicast_ether_addr(sta->sta.addr))) { |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 371 | err = -EINVAL; |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 372 | rcu_read_lock(); |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 373 | goto out_free; |
| 374 | } |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 375 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 376 | /* |
| 377 | * In ad-hoc mode, we sometimes need to insert stations |
| 378 | * from tasklet context from the RX path. To avoid races, |
| 379 | * always do so in that case -- see the comment below. |
| 380 | */ |
| 381 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { |
| 382 | spin_lock_irqsave(&local->sta_lock, flags); |
| 383 | /* check if STA exists already */ |
| 384 | if (sta_info_get_bss(sdata, sta->sta.addr)) { |
| 385 | spin_unlock_irqrestore(&local->sta_lock, flags); |
| 386 | rcu_read_lock(); |
| 387 | err = -EEXIST; |
| 388 | goto out_free; |
| 389 | } |
| 390 | |
| 391 | local->num_sta++; |
| 392 | local->sta_generation++; |
| 393 | smp_mb(); |
| 394 | sta_info_hash_add(local, sta); |
| 395 | |
| 396 | list_add_tail(&sta->list, &local->sta_pending_list); |
| 397 | |
| 398 | rcu_read_lock(); |
| 399 | spin_unlock_irqrestore(&local->sta_lock, flags); |
| 400 | |
| 401 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
| 402 | printk(KERN_DEBUG "%s: Added IBSS STA %pM\n", |
| 403 | wiphy_name(local->hw.wiphy), sta->sta.addr); |
| 404 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 405 | |
| 406 | ieee80211_queue_work(&local->hw, &local->sta_finish_work); |
| 407 | |
| 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | /* |
| 412 | * On first glance, this will look racy, because the code |
| 413 | * below this point, which inserts a station with sleeping, |
| 414 | * unlocks the sta_lock between checking existence in the |
| 415 | * hash table and inserting into it. |
| 416 | * |
| 417 | * However, it is not racy against itself because it keeps |
| 418 | * the mutex locked. It still seems to race against the |
| 419 | * above code that atomically inserts the station... That, |
| 420 | * however, is not true because the above code can only |
| 421 | * be invoked for IBSS interfaces, and the below code will |
| 422 | * not be -- and the two do not race against each other as |
| 423 | * the hash table also keys off the interface. |
| 424 | */ |
| 425 | |
| 426 | might_sleep(); |
| 427 | |
| 428 | mutex_lock(&local->sta_mtx); |
| 429 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 430 | spin_lock_irqsave(&local->sta_lock, flags); |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 431 | /* check if STA exists already */ |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 432 | if (sta_info_get_bss(sdata, sta->sta.addr)) { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 433 | spin_unlock_irqrestore(&local->sta_lock, flags); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 434 | rcu_read_lock(); |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 435 | err = -EEXIST; |
| 436 | goto out_free; |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 437 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 438 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 439 | spin_unlock_irqrestore(&local->sta_lock, flags); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 440 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 441 | err = sta_info_finish_insert(sta, false); |
| 442 | if (err) { |
| 443 | mutex_unlock(&local->sta_mtx); |
| 444 | rcu_read_lock(); |
| 445 | goto out_free; |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 446 | } |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 447 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 448 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 449 | printk(KERN_DEBUG "%s: Inserted STA %pM\n", |
| 450 | wiphy_name(local->hw.wiphy), sta->sta.addr); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 451 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 452 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 453 | /* move reference to rcu-protected */ |
| 454 | rcu_read_lock(); |
| 455 | mutex_unlock(&local->sta_mtx); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 456 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 457 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
| 458 | mesh_accept_plinks_update(sdata); |
| 459 | |
| 460 | return 0; |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 461 | out_free: |
| 462 | BUG_ON(!err); |
| 463 | __sta_info_free(local, sta); |
| 464 | return err; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 467 | int sta_info_insert(struct sta_info *sta) |
| 468 | { |
| 469 | int err = sta_info_insert_rcu(sta); |
| 470 | |
| 471 | rcu_read_unlock(); |
| 472 | |
| 473 | return err; |
| 474 | } |
| 475 | |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 476 | static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid) |
| 477 | { |
| 478 | /* |
| 479 | * This format has been mandated by the IEEE specifications, |
| 480 | * so this line may not be changed to use the __set_bit() format. |
| 481 | */ |
| 482 | bss->tim[aid / 8] |= (1 << (aid % 8)); |
| 483 | } |
| 484 | |
| 485 | static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, u16 aid) |
| 486 | { |
| 487 | /* |
| 488 | * This format has been mandated by the IEEE specifications, |
| 489 | * so this line may not be changed to use the __clear_bit() format. |
| 490 | */ |
| 491 | bss->tim[aid / 8] &= ~(1 << (aid % 8)); |
| 492 | } |
| 493 | |
| 494 | static void __sta_info_set_tim_bit(struct ieee80211_if_ap *bss, |
| 495 | struct sta_info *sta) |
| 496 | { |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 497 | BUG_ON(!bss); |
| 498 | |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 499 | __bss_tim_set(bss, sta->sta.aid); |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 500 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 501 | if (sta->local->ops->set_tim) { |
| 502 | sta->local->tim_in_locked_section = true; |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 503 | drv_set_tim(sta->local, &sta->sta, true); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 504 | sta->local->tim_in_locked_section = false; |
| 505 | } |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | void sta_info_set_tim_bit(struct sta_info *sta) |
| 509 | { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 510 | unsigned long flags; |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 511 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 512 | BUG_ON(!sta->sdata->bss); |
| 513 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 514 | spin_lock_irqsave(&sta->local->sta_lock, flags); |
| 515 | __sta_info_set_tim_bit(sta->sdata->bss, sta); |
| 516 | spin_unlock_irqrestore(&sta->local->sta_lock, flags); |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | static void __sta_info_clear_tim_bit(struct ieee80211_if_ap *bss, |
| 520 | struct sta_info *sta) |
| 521 | { |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 522 | BUG_ON(!bss); |
| 523 | |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 524 | __bss_tim_clear(bss, sta->sta.aid); |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 525 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 526 | if (sta->local->ops->set_tim) { |
| 527 | sta->local->tim_in_locked_section = true; |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 528 | drv_set_tim(sta->local, &sta->sta, false); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 529 | sta->local->tim_in_locked_section = false; |
| 530 | } |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | void sta_info_clear_tim_bit(struct sta_info *sta) |
| 534 | { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 535 | unsigned long flags; |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 536 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 537 | BUG_ON(!sta->sdata->bss); |
| 538 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 539 | spin_lock_irqsave(&sta->local->sta_lock, flags); |
| 540 | __sta_info_clear_tim_bit(sta->sdata->bss, sta); |
| 541 | spin_unlock_irqrestore(&sta->local->sta_lock, flags); |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 542 | } |
| 543 | |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 544 | static int sta_info_buffer_expired(struct sta_info *sta, |
| 545 | struct sk_buff *skb) |
Jiri Benc | f0706e8 | 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 | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 548 | int timeout; |
| 549 | |
| 550 | if (!skb) |
| 551 | return 0; |
| 552 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 553 | info = IEEE80211_SKB_CB(skb); |
Jiri Benc | f0706e8 | 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 | f0706e8 | 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 | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | |
| 565 | static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local, |
| 566 | struct sta_info *sta) |
| 567 | { |
| 568 | unsigned long flags; |
| 569 | struct sk_buff *skb; |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 570 | struct ieee80211_sub_if_data *sdata; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 571 | |
| 572 | if (skb_queue_empty(&sta->ps_tx_buf)) |
| 573 | return; |
| 574 | |
| 575 | for (;;) { |
| 576 | spin_lock_irqsave(&sta->ps_tx_buf.lock, flags); |
| 577 | skb = skb_peek(&sta->ps_tx_buf); |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 578 | if (sta_info_buffer_expired(sta, skb)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 579 | skb = __skb_dequeue(&sta->ps_tx_buf); |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 580 | else |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 581 | skb = NULL; |
| 582 | spin_unlock_irqrestore(&sta->ps_tx_buf.lock, flags); |
| 583 | |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 584 | if (!skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 585 | break; |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 586 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 587 | sdata = sta->sdata; |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 588 | local->total_ps_buffered--; |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 589 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 590 | printk(KERN_DEBUG "Buffered frame expired (STA %pM)\n", |
| 591 | sta->sta.addr); |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 592 | #endif |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 593 | dev_kfree_skb(skb); |
| 594 | |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 595 | if (skb_queue_empty(&sta->ps_tx_buf)) |
| 596 | sta_info_clear_tim_bit(sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 600 | static int __must_check __sta_info_destroy(struct sta_info *sta) |
| 601 | { |
| 602 | struct ieee80211_local *local; |
| 603 | struct ieee80211_sub_if_data *sdata; |
| 604 | struct sk_buff *skb; |
| 605 | unsigned long flags; |
Johannes Berg | 098a607 | 2010-04-06 11:18:47 +0200 | [diff] [blame^] | 606 | int ret; |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 607 | |
| 608 | might_sleep(); |
| 609 | |
| 610 | if (!sta) |
| 611 | return -ENOENT; |
| 612 | |
| 613 | local = sta->local; |
| 614 | sdata = sta->sdata; |
| 615 | |
Johannes Berg | 098a607 | 2010-04-06 11:18:47 +0200 | [diff] [blame^] | 616 | /* |
| 617 | * Before removing the station from the driver and |
| 618 | * rate control, it might still start new aggregation |
| 619 | * sessions -- block that to make sure the tear-down |
| 620 | * will be sufficient. |
| 621 | */ |
| 622 | set_sta_flags(sta, WLAN_STA_BLOCK_BA); |
| 623 | ieee80211_sta_tear_down_BA_sessions(sta); |
| 624 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 625 | spin_lock_irqsave(&local->sta_lock, flags); |
| 626 | ret = sta_info_hash_del(local, sta); |
| 627 | /* this might still be the pending list ... which is fine */ |
| 628 | if (!ret) |
| 629 | list_del(&sta->list); |
| 630 | spin_unlock_irqrestore(&local->sta_lock, flags); |
| 631 | if (ret) |
| 632 | return ret; |
| 633 | |
| 634 | if (sta->key) { |
| 635 | ieee80211_key_free(sta->key); |
| 636 | /* |
| 637 | * We have only unlinked the key, and actually destroying it |
| 638 | * may mean it is removed from hardware which requires that |
| 639 | * the key->sta pointer is still valid, so flush the key todo |
| 640 | * list here. |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 641 | */ |
| 642 | ieee80211_key_todo(); |
| 643 | |
| 644 | WARN_ON(sta->key); |
| 645 | } |
| 646 | |
| 647 | sta->dead = true; |
| 648 | |
| 649 | if (test_and_clear_sta_flags(sta, |
| 650 | WLAN_STA_PS_STA | WLAN_STA_PS_DRIVER)) { |
| 651 | BUG_ON(!sdata->bss); |
| 652 | |
| 653 | atomic_dec(&sdata->bss->num_sta_ps); |
| 654 | __sta_info_clear_tim_bit(sdata->bss, sta); |
| 655 | } |
| 656 | |
| 657 | local->num_sta--; |
| 658 | local->sta_generation++; |
| 659 | |
| 660 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
| 661 | rcu_assign_pointer(sdata->u.vlan.sta, NULL); |
| 662 | |
| 663 | if (sta->uploaded) { |
| 664 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
| 665 | sdata = container_of(sdata->bss, |
| 666 | struct ieee80211_sub_if_data, |
| 667 | u.ap); |
| 668 | drv_sta_remove(local, sdata, &sta->sta); |
| 669 | sdata = sta->sdata; |
| 670 | } |
| 671 | |
Johannes Berg | e64b379 | 2010-04-06 11:18:43 +0200 | [diff] [blame] | 672 | /* |
| 673 | * At this point, after we wait for an RCU grace period, |
| 674 | * neither mac80211 nor the driver can reference this |
| 675 | * sta struct any more except by still existing timers |
| 676 | * associated with this station that we clean up below. |
| 677 | */ |
| 678 | synchronize_rcu(); |
| 679 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 680 | #ifdef CONFIG_MAC80211_MESH |
Johannes Berg | e64b379 | 2010-04-06 11:18:43 +0200 | [diff] [blame] | 681 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 682 | mesh_accept_plinks_update(sdata); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 683 | #endif |
| 684 | |
| 685 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
| 686 | printk(KERN_DEBUG "%s: Removed STA %pM\n", |
| 687 | wiphy_name(local->hw.wiphy), sta->sta.addr); |
| 688 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 689 | cancel_work_sync(&sta->drv_unblock_wk); |
| 690 | |
| 691 | rate_control_remove_sta_debugfs(sta); |
| 692 | ieee80211_sta_debugfs_remove(sta); |
| 693 | |
| 694 | #ifdef CONFIG_MAC80211_MESH |
| 695 | if (ieee80211_vif_is_mesh(&sta->sdata->vif)) { |
| 696 | mesh_plink_deactivate(sta); |
| 697 | del_timer_sync(&sta->plink_timer); |
| 698 | } |
| 699 | #endif |
| 700 | |
| 701 | while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) { |
| 702 | local->total_ps_buffered--; |
| 703 | dev_kfree_skb_any(skb); |
| 704 | } |
| 705 | |
| 706 | while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) |
| 707 | dev_kfree_skb_any(skb); |
| 708 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 709 | __sta_info_free(local, sta); |
| 710 | |
| 711 | return 0; |
| 712 | } |
| 713 | |
| 714 | int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata, const u8 *addr) |
| 715 | { |
| 716 | struct sta_info *sta; |
| 717 | int ret; |
| 718 | |
| 719 | mutex_lock(&sdata->local->sta_mtx); |
| 720 | sta = sta_info_get(sdata, addr); |
| 721 | ret = __sta_info_destroy(sta); |
| 722 | mutex_unlock(&sdata->local->sta_mtx); |
| 723 | |
| 724 | return ret; |
| 725 | } |
| 726 | |
| 727 | int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata, |
| 728 | const u8 *addr) |
| 729 | { |
| 730 | struct sta_info *sta; |
| 731 | int ret; |
| 732 | |
| 733 | mutex_lock(&sdata->local->sta_mtx); |
| 734 | sta = sta_info_get_bss(sdata, addr); |
| 735 | ret = __sta_info_destroy(sta); |
| 736 | mutex_unlock(&sdata->local->sta_mtx); |
| 737 | |
| 738 | return ret; |
| 739 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 740 | |
| 741 | static void sta_info_cleanup(unsigned long data) |
| 742 | { |
| 743 | struct ieee80211_local *local = (struct ieee80211_local *) data; |
| 744 | struct sta_info *sta; |
| 745 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 746 | rcu_read_lock(); |
| 747 | list_for_each_entry_rcu(sta, &local->sta_list, list) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 748 | sta_info_cleanup_expire_buffered(local, sta); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 749 | rcu_read_unlock(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 750 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 751 | if (local->quiescing) |
| 752 | return; |
| 753 | |
Johannes Berg | 0d17440 | 2007-12-17 15:07:43 +0100 | [diff] [blame] | 754 | local->sta_cleanup.expires = |
| 755 | round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 756 | add_timer(&local->sta_cleanup); |
| 757 | } |
| 758 | |
| 759 | void sta_info_init(struct ieee80211_local *local) |
| 760 | { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 761 | spin_lock_init(&local->sta_lock); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 762 | mutex_init(&local->sta_mtx); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 763 | INIT_LIST_HEAD(&local->sta_list); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 764 | INIT_LIST_HEAD(&local->sta_pending_list); |
| 765 | INIT_WORK(&local->sta_finish_work, sta_info_finish_work); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 766 | |
Pavel Emelyanov | b24b8a2 | 2008-01-23 21:20:07 -0800 | [diff] [blame] | 767 | setup_timer(&local->sta_cleanup, sta_info_cleanup, |
| 768 | (unsigned long)local); |
Johannes Berg | 0d17440 | 2007-12-17 15:07:43 +0100 | [diff] [blame] | 769 | local->sta_cleanup.expires = |
| 770 | round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | int sta_info_start(struct ieee80211_local *local) |
| 774 | { |
| 775 | add_timer(&local->sta_cleanup); |
| 776 | return 0; |
| 777 | } |
| 778 | |
| 779 | void sta_info_stop(struct ieee80211_local *local) |
| 780 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 781 | del_timer(&local->sta_cleanup); |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 782 | sta_info_flush(local, NULL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 785 | /** |
| 786 | * sta_info_flush - flush matching STA entries from the STA table |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 787 | * |
| 788 | * Returns the number of removed STA entries. |
| 789 | * |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 790 | * @local: local interface data |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 791 | * @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] | 792 | */ |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 793 | int sta_info_flush(struct ieee80211_local *local, |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 794 | struct ieee80211_sub_if_data *sdata) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 795 | { |
| 796 | struct sta_info *sta, *tmp; |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 797 | int ret = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 798 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 799 | might_sleep(); |
| 800 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 801 | mutex_lock(&local->sta_mtx); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 802 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 803 | sta_info_finish_pending(local); |
| 804 | |
| 805 | list_for_each_entry_safe(sta, tmp, &local->sta_list, list) { |
| 806 | if (!sdata || sdata == sta->sdata) |
| 807 | WARN_ON(__sta_info_destroy(sta)); |
| 808 | } |
| 809 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | 44213b5 | 2008-02-25 16:27:49 +0100 | [diff] [blame] | 810 | |
| 811 | return ret; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 812 | } |
Johannes Berg | dc6676b | 2008-03-31 19:23:03 +0200 | [diff] [blame] | 813 | |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 814 | void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata, |
| 815 | unsigned long exp_time) |
| 816 | { |
| 817 | struct ieee80211_local *local = sdata->local; |
| 818 | struct sta_info *sta, *tmp; |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 819 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 820 | mutex_lock(&local->sta_mtx); |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 821 | list_for_each_entry_safe(sta, tmp, &local->sta_list, list) |
| 822 | if (time_after(jiffies, sta->last_rx + exp_time)) { |
| 823 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 824 | printk(KERN_DEBUG "%s: expiring inactive STA %pM\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 825 | sdata->name, sta->sta.addr); |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 826 | #endif |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 827 | WARN_ON(__sta_info_destroy(sta)); |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 828 | } |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 829 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | 24723d1 | 2008-09-11 00:01:46 +0200 | [diff] [blame] | 830 | } |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 831 | |
Johannes Berg | 5ed176e | 2009-11-04 14:42:28 +0100 | [diff] [blame] | 832 | struct ieee80211_sta *ieee80211_find_sta_by_hw(struct ieee80211_hw *hw, |
| 833 | const u8 *addr) |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 834 | { |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 835 | struct sta_info *sta, *nxt; |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 836 | |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 837 | /* Just return a random station ... first in list ... */ |
| 838 | for_each_sta_info(hw_to_local(hw), addr, sta, nxt) |
| 839 | return &sta->sta; |
| 840 | return NULL; |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 841 | } |
Johannes Berg | 5ed176e | 2009-11-04 14:42:28 +0100 | [diff] [blame] | 842 | EXPORT_SYMBOL_GPL(ieee80211_find_sta_by_hw); |
| 843 | |
| 844 | struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_vif *vif, |
| 845 | const u8 *addr) |
| 846 | { |
| 847 | struct ieee80211_sub_if_data *sdata; |
| 848 | |
| 849 | if (!vif) |
| 850 | return NULL; |
| 851 | |
| 852 | sdata = vif_to_sdata(vif); |
| 853 | |
| 854 | return ieee80211_find_sta_by_hw(&sdata->local->hw, addr); |
| 855 | } |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 856 | EXPORT_SYMBOL(ieee80211_find_sta); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 857 | |
| 858 | /* powersave support code */ |
| 859 | void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta) |
| 860 | { |
| 861 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 862 | struct ieee80211_local *local = sdata->local; |
| 863 | int sent, buffered; |
| 864 | |
Johannes Berg | 12375ef | 2009-11-25 20:30:31 +0100 | [diff] [blame] | 865 | drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 866 | |
| 867 | if (!skb_queue_empty(&sta->ps_tx_buf)) |
| 868 | sta_info_clear_tim_bit(sta); |
| 869 | |
| 870 | /* Send all buffered frames to the station */ |
| 871 | sent = ieee80211_add_pending_skbs(local, &sta->tx_filtered); |
| 872 | buffered = ieee80211_add_pending_skbs(local, &sta->ps_tx_buf); |
| 873 | sent += buffered; |
| 874 | local->total_ps_buffered -= buffered; |
| 875 | |
| 876 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
| 877 | 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] | 878 | "since STA not sleeping anymore\n", sdata->name, |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 879 | sta->sta.addr, sta->sta.aid, sent - buffered, buffered); |
| 880 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
| 881 | } |
| 882 | |
| 883 | void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta) |
| 884 | { |
| 885 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 886 | struct ieee80211_local *local = sdata->local; |
| 887 | struct sk_buff *skb; |
| 888 | int no_pending_pkts; |
| 889 | |
| 890 | skb = skb_dequeue(&sta->tx_filtered); |
| 891 | if (!skb) { |
| 892 | skb = skb_dequeue(&sta->ps_tx_buf); |
| 893 | if (skb) |
| 894 | local->total_ps_buffered--; |
| 895 | } |
| 896 | no_pending_pkts = skb_queue_empty(&sta->tx_filtered) && |
| 897 | skb_queue_empty(&sta->ps_tx_buf); |
| 898 | |
| 899 | if (skb) { |
| 900 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 901 | struct ieee80211_hdr *hdr = |
| 902 | (struct ieee80211_hdr *) skb->data; |
| 903 | |
| 904 | /* |
| 905 | * Tell TX path to send this frame even though the STA may |
| 906 | * still remain is PS mode after this frame exchange. |
| 907 | */ |
| 908 | info->flags |= IEEE80211_TX_CTL_PSPOLL_RESPONSE; |
| 909 | |
| 910 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
| 911 | printk(KERN_DEBUG "STA %pM aid %d: PS Poll (entries after %d)\n", |
| 912 | sta->sta.addr, sta->sta.aid, |
| 913 | skb_queue_len(&sta->ps_tx_buf)); |
| 914 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
| 915 | |
| 916 | /* Use MoreData flag to indicate whether there are more |
| 917 | * buffered frames for this STA */ |
| 918 | if (no_pending_pkts) |
| 919 | hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA); |
| 920 | else |
| 921 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA); |
| 922 | |
| 923 | ieee80211_add_pending_skb(local, skb); |
| 924 | |
| 925 | if (no_pending_pkts) |
| 926 | sta_info_clear_tim_bit(sta); |
| 927 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
| 928 | } else { |
| 929 | /* |
| 930 | * FIXME: This can be the result of a race condition between |
| 931 | * us expiring a frame and the station polling for it. |
| 932 | * Should we send it a null-func frame indicating we |
| 933 | * have nothing buffered for it? |
| 934 | */ |
| 935 | printk(KERN_DEBUG "%s: STA %pM sent PS Poll even " |
| 936 | "though there are no buffered frames for it\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 937 | sdata->name, sta->sta.addr); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 938 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | void ieee80211_sta_block_awake(struct ieee80211_hw *hw, |
| 943 | struct ieee80211_sta *pubsta, bool block) |
| 944 | { |
| 945 | struct sta_info *sta = container_of(pubsta, struct sta_info, sta); |
| 946 | |
| 947 | if (block) |
| 948 | set_sta_flags(sta, WLAN_STA_PS_DRIVER); |
| 949 | else |
| 950 | ieee80211_queue_work(hw, &sta->drv_unblock_wk); |
| 951 | } |
| 952 | EXPORT_SYMBOL(ieee80211_sta_block_awake); |