Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * BSS client mode implementation |
Jouni Malinen | 5394af4 | 2009-01-08 13:31:59 +0200 | [diff] [blame] | 3 | * Copyright 2003-2008, Jouni Malinen <j@w1.fi> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4 | * Copyright 2004, Instant802 Networks, Inc. |
| 5 | * Copyright 2005, Devicescape Software, Inc. |
| 6 | * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> |
| 7 | * Copyright 2007, Michael Wu <flamingice@sourmilk.net> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
Geert Uytterhoeven | 5b323ed | 2007-05-08 18:40:27 -0700 | [diff] [blame] | 14 | #include <linux/delay.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 15 | #include <linux/if_ether.h> |
| 16 | #include <linux/skbuff.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 17 | #include <linux/if_arp.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 18 | #include <linux/etherdevice.h> |
Paul Gortmaker | d9b9384 | 2011-09-18 13:21:27 -0400 | [diff] [blame] | 19 | #include <linux/moduleparam.h> |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 20 | #include <linux/rtnetlink.h> |
Jean Pihet | e8db0be | 2011-08-25 15:35:03 +0200 | [diff] [blame] | 21 | #include <linux/pm_qos.h> |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 22 | #include <linux/crc32.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 24 | #include <linux/export.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 25 | #include <net/mac80211.h> |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 26 | #include <asm/unaligned.h> |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 27 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 28 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 29 | #include "driver-ops.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 30 | #include "rate.h" |
| 31 | #include "led.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 32 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 33 | #define IEEE80211_AUTH_TIMEOUT (HZ / 5) |
| 34 | #define IEEE80211_AUTH_MAX_TRIES 3 |
| 35 | #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5) |
| 36 | #define IEEE80211_ASSOC_TIMEOUT (HZ / 5) |
| 37 | #define IEEE80211_ASSOC_MAX_TRIES 3 |
| 38 | |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 39 | static int max_nullfunc_tries = 2; |
| 40 | module_param(max_nullfunc_tries, int, 0644); |
| 41 | MODULE_PARM_DESC(max_nullfunc_tries, |
| 42 | "Maximum nullfunc tx tries before disconnecting (reason 4)."); |
| 43 | |
| 44 | static int max_probe_tries = 5; |
| 45 | module_param(max_probe_tries, int, 0644); |
| 46 | MODULE_PARM_DESC(max_probe_tries, |
| 47 | "Maximum probe tries before disconnecting (reason 4)."); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 48 | |
| 49 | /* |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 50 | * Beacon loss timeout is calculated as N frames times the |
| 51 | * advertised beacon interval. This may need to be somewhat |
| 52 | * higher than what hardware might detect to account for |
| 53 | * delays in the host processing frames. But since we also |
| 54 | * probe on beacon miss before declaring the connection lost |
| 55 | * default to what we want. |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 56 | */ |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 57 | #define IEEE80211_BEACON_LOSS_COUNT 7 |
| 58 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 59 | /* |
| 60 | * Time the connection can be idle before we probe |
| 61 | * it to see if we can still talk to the AP. |
| 62 | */ |
Maxim Levitsky | d1c5091 | 2009-07-31 18:54:23 +0300 | [diff] [blame] | 63 | #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 64 | /* |
| 65 | * Time we wait for a probe response after sending |
| 66 | * a probe request because of beacon loss or for |
| 67 | * checking the connection still works. |
| 68 | */ |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 69 | static int probe_wait_ms = 500; |
| 70 | module_param(probe_wait_ms, int, 0644); |
| 71 | MODULE_PARM_DESC(probe_wait_ms, |
| 72 | "Maximum time(ms) to wait for probe response" |
| 73 | " before disconnecting (reason 4)."); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 74 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 75 | /* |
| 76 | * Weight given to the latest Beacon frame when calculating average signal |
| 77 | * strength for Beacon frames received in the current BSS. This must be |
| 78 | * between 1 and 15. |
| 79 | */ |
| 80 | #define IEEE80211_SIGNAL_AVE_WEIGHT 3 |
| 81 | |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 82 | /* |
| 83 | * How many Beacon frames need to have been used in average signal strength |
| 84 | * before starting to indicate signal change events. |
| 85 | */ |
| 86 | #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4 |
| 87 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 88 | #define TMR_RUNNING_TIMER 0 |
| 89 | #define TMR_RUNNING_CHANSW 1 |
| 90 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 91 | /* |
| 92 | * All cfg80211 functions have to be called outside a locked |
| 93 | * section so that they can acquire a lock themselves... This |
| 94 | * is much simpler than queuing up things in cfg80211, but we |
| 95 | * do need some indirection for that here. |
| 96 | */ |
| 97 | enum rx_mgmt_action { |
| 98 | /* no action required */ |
| 99 | RX_MGMT_NONE, |
| 100 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 101 | /* caller must call cfg80211_send_deauth() */ |
| 102 | RX_MGMT_CFG80211_DEAUTH, |
| 103 | |
| 104 | /* caller must call cfg80211_send_disassoc() */ |
| 105 | RX_MGMT_CFG80211_DISASSOC, |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 106 | |
| 107 | /* caller must call cfg80211_send_rx_auth() */ |
| 108 | RX_MGMT_CFG80211_RX_AUTH, |
| 109 | |
| 110 | /* caller must call cfg80211_send_rx_assoc() */ |
| 111 | RX_MGMT_CFG80211_RX_ASSOC, |
| 112 | |
| 113 | /* caller must call cfg80211_send_assoc_timeout() */ |
| 114 | RX_MGMT_CFG80211_ASSOC_TIMEOUT, |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 115 | }; |
| 116 | |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 117 | /* utils */ |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 118 | static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed *ifmgd) |
| 119 | { |
Johannes Berg | 46a5eba | 2010-09-15 13:28:15 +0200 | [diff] [blame] | 120 | lockdep_assert_held(&ifmgd->mtx); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 121 | } |
| 122 | |
Johannes Berg | ca386f3 | 2009-07-10 02:39:48 +0200 | [diff] [blame] | 123 | /* |
| 124 | * We can have multiple work items (and connection probing) |
| 125 | * scheduling this timer, but we need to take care to only |
| 126 | * reschedule it when it should fire _earlier_ than it was |
| 127 | * asked for before, or if it's not pending right now. This |
| 128 | * function ensures that. Note that it then is required to |
| 129 | * run this function for all timeouts after the first one |
| 130 | * has happened -- the work that runs from this timer will |
| 131 | * do that. |
| 132 | */ |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 133 | static void run_again(struct ieee80211_if_managed *ifmgd, unsigned long timeout) |
Johannes Berg | ca386f3 | 2009-07-10 02:39:48 +0200 | [diff] [blame] | 134 | { |
| 135 | ASSERT_MGD_MTX(ifmgd); |
| 136 | |
| 137 | if (!timer_pending(&ifmgd->timer) || |
| 138 | time_before(timeout, ifmgd->timer.expires)) |
| 139 | mod_timer(&ifmgd->timer, timeout); |
| 140 | } |
| 141 | |
Luis R. Rodriguez | d3a910a | 2010-09-16 15:12:32 -0400 | [diff] [blame] | 142 | void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 143 | { |
Johannes Berg | c1288b1 | 2012-01-19 09:29:57 +0100 | [diff] [blame] | 144 | if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 145 | return; |
| 146 | |
Johannes Berg | 7eeff74 | 2012-07-18 10:27:27 +0200 | [diff] [blame] | 147 | if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR) |
| 148 | return; |
| 149 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 150 | mod_timer(&sdata->u.mgd.bcn_mon_timer, |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 151 | round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout)); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 152 | } |
| 153 | |
Luis R. Rodriguez | be099e8 | 2010-09-16 15:12:29 -0400 | [diff] [blame] | 154 | void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata) |
| 155 | { |
Luis R. Rodriguez | 0c699c3 | 2010-09-16 15:12:30 -0400 | [diff] [blame] | 156 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 157 | |
Stanislaw Gruszka | 8628172 | 2011-02-25 14:46:02 +0100 | [diff] [blame] | 158 | if (unlikely(!sdata->u.mgd.associated)) |
| 159 | return; |
| 160 | |
Luis R. Rodriguez | be099e8 | 2010-09-16 15:12:29 -0400 | [diff] [blame] | 161 | if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR) |
| 162 | return; |
| 163 | |
| 164 | mod_timer(&sdata->u.mgd.conn_mon_timer, |
| 165 | round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME)); |
Luis R. Rodriguez | 0c699c3 | 2010-09-16 15:12:30 -0400 | [diff] [blame] | 166 | |
| 167 | ifmgd->probe_send_count = 0; |
Luis R. Rodriguez | be099e8 | 2010-09-16 15:12:29 -0400 | [diff] [blame] | 168 | } |
| 169 | |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 170 | static int ecw2cw(int ecw) |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 171 | { |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 172 | return (1 << ecw) - 1; |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 173 | } |
| 174 | |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 175 | static u32 ieee80211_config_ht_tx(struct ieee80211_sub_if_data *sdata, |
| 176 | struct ieee80211_ht_operation *ht_oper, |
| 177 | const u8 *bssid, bool reconfig) |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 178 | { |
| 179 | struct ieee80211_local *local = sdata->local; |
| 180 | struct ieee80211_supported_band *sband; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 181 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 182 | struct ieee80211_channel *chan; |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 183 | struct sta_info *sta; |
| 184 | u32 changed = 0; |
Johannes Berg | 9ed6bcc | 2009-05-08 20:47:39 +0200 | [diff] [blame] | 185 | u16 ht_opmode; |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 186 | bool disable_40 = false; |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 187 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 188 | rcu_read_lock(); |
| 189 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 190 | if (WARN_ON(!chanctx_conf)) { |
| 191 | rcu_read_unlock(); |
| 192 | return 0; |
| 193 | } |
| 194 | chan = chanctx_conf->channel; |
| 195 | rcu_read_unlock(); |
| 196 | sband = local->hw.wiphy->bands[chan->band]; |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 197 | |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 198 | switch (sdata->vif.bss_conf.channel_type) { |
| 199 | case NL80211_CHAN_HT40PLUS: |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 200 | if (chan->flags & IEEE80211_CHAN_NO_HT40PLUS) |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 201 | disable_40 = true; |
| 202 | break; |
| 203 | case NL80211_CHAN_HT40MINUS: |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 204 | if (chan->flags & IEEE80211_CHAN_NO_HT40MINUS) |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 205 | disable_40 = true; |
| 206 | break; |
| 207 | default: |
| 208 | break; |
| 209 | } |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 210 | |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 211 | /* This can change during the lifetime of the BSS */ |
| 212 | if (!(ht_oper->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 213 | disable_40 = true; |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 214 | |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 215 | mutex_lock(&local->sta_mtx); |
| 216 | sta = sta_info_get(sdata, bssid); |
| 217 | |
| 218 | WARN_ON_ONCE(!sta); |
| 219 | |
| 220 | if (sta && !sta->supports_40mhz) |
| 221 | disable_40 = true; |
| 222 | |
| 223 | if (sta && (!reconfig || |
Rajkumar Manoharan | 91a0099 | 2012-04-25 20:24:24 +0530 | [diff] [blame] | 224 | (disable_40 != !(sta->sta.ht_cap.cap & |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 225 | IEEE80211_HT_CAP_SUP_WIDTH_20_40)))) { |
Rajkumar Manoharan | 7cc44ed | 2011-09-16 15:32:34 +0530 | [diff] [blame] | 226 | |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 227 | if (disable_40) |
| 228 | sta->sta.ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 229 | else |
| 230 | sta->sta.ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
Rajkumar Manoharan | 7cc44ed | 2011-09-16 15:32:34 +0530 | [diff] [blame] | 231 | |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 232 | rate_control_rate_update(local, sband, sta, |
Johannes Berg | 8f727ef | 2012-03-30 08:43:32 +0200 | [diff] [blame] | 233 | IEEE80211_RC_BW_CHANGED); |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 234 | } |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 235 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 236 | |
Johannes Berg | 074d46d | 2012-03-15 19:45:16 +0100 | [diff] [blame] | 237 | ht_opmode = le16_to_cpu(ht_oper->operation_mode); |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 238 | |
| 239 | /* if bss configuration changed store the new one */ |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 240 | if (!reconfig || (sdata->vif.bss_conf.ht_operation_mode != ht_opmode)) { |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 241 | changed |= BSS_CHANGED_HT; |
Johannes Berg | 9ed6bcc | 2009-05-08 20:47:39 +0200 | [diff] [blame] | 242 | sdata->vif.bss_conf.ht_operation_mode = ht_opmode; |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | return changed; |
| 246 | } |
| 247 | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 248 | /* frame sending functions */ |
| 249 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 250 | static int ieee80211_compatible_rates(const u8 *supp_rates, int supp_rates_len, |
| 251 | struct ieee80211_supported_band *sband, |
| 252 | u32 *rates) |
| 253 | { |
| 254 | int i, j, count; |
| 255 | *rates = 0; |
| 256 | count = 0; |
| 257 | for (i = 0; i < supp_rates_len; i++) { |
| 258 | int rate = (supp_rates[i] & 0x7F) * 5; |
| 259 | |
| 260 | for (j = 0; j < sband->n_bitrates; j++) |
| 261 | if (sband->bitrates[j].bitrate == rate) { |
| 262 | *rates |= BIT(j); |
| 263 | count++; |
| 264 | break; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | return count; |
| 269 | } |
| 270 | |
| 271 | static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 272 | struct sk_buff *skb, u8 ap_ht_param, |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 273 | struct ieee80211_supported_band *sband, |
| 274 | struct ieee80211_channel *channel, |
| 275 | enum ieee80211_smps_mode smps) |
| 276 | { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 277 | u8 *pos; |
| 278 | u32 flags = channel->flags; |
| 279 | u16 cap; |
| 280 | struct ieee80211_sta_ht_cap ht_cap; |
| 281 | |
| 282 | BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap)); |
| 283 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 284 | memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap)); |
| 285 | ieee80211_apply_htcap_overrides(sdata, &ht_cap); |
| 286 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 287 | /* determine capability flags */ |
| 288 | cap = ht_cap.cap; |
| 289 | |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 290 | switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 291 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: |
| 292 | if (flags & IEEE80211_CHAN_NO_HT40PLUS) { |
| 293 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 294 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 295 | } |
| 296 | break; |
| 297 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: |
| 298 | if (flags & IEEE80211_CHAN_NO_HT40MINUS) { |
| 299 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 300 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 301 | } |
| 302 | break; |
| 303 | } |
| 304 | |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 305 | /* |
| 306 | * If 40 MHz was disabled associate as though we weren't |
| 307 | * capable of 40 MHz -- some broken APs will never fall |
| 308 | * back to trying to transmit in 20 MHz. |
| 309 | */ |
| 310 | if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) { |
| 311 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 312 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 313 | } |
| 314 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 315 | /* set SM PS mode properly */ |
| 316 | cap &= ~IEEE80211_HT_CAP_SM_PS; |
| 317 | switch (smps) { |
| 318 | case IEEE80211_SMPS_AUTOMATIC: |
| 319 | case IEEE80211_SMPS_NUM_MODES: |
| 320 | WARN_ON(1); |
| 321 | case IEEE80211_SMPS_OFF: |
| 322 | cap |= WLAN_HT_CAP_SM_PS_DISABLED << |
| 323 | IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 324 | break; |
| 325 | case IEEE80211_SMPS_STATIC: |
| 326 | cap |= WLAN_HT_CAP_SM_PS_STATIC << |
| 327 | IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 328 | break; |
| 329 | case IEEE80211_SMPS_DYNAMIC: |
| 330 | cap |= WLAN_HT_CAP_SM_PS_DYNAMIC << |
| 331 | IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 332 | break; |
| 333 | } |
| 334 | |
| 335 | /* reserve and fill IE */ |
| 336 | pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2); |
| 337 | ieee80211_ie_build_ht_cap(pos, &ht_cap, cap); |
| 338 | } |
| 339 | |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 340 | static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata, |
| 341 | struct sk_buff *skb, |
| 342 | struct ieee80211_supported_band *sband) |
| 343 | { |
| 344 | u8 *pos; |
| 345 | u32 cap; |
| 346 | struct ieee80211_sta_vht_cap vht_cap; |
| 347 | |
| 348 | BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap)); |
| 349 | |
| 350 | memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap)); |
| 351 | |
| 352 | /* determine capability flags */ |
| 353 | cap = vht_cap.cap; |
| 354 | |
| 355 | /* reserve and fill IE */ |
Mahesh Palivela | d495028 | 2012-10-10 11:25:40 +0000 | [diff] [blame] | 356 | pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2); |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 357 | ieee80211_ie_build_vht_cap(pos, &vht_cap, cap); |
| 358 | } |
| 359 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 360 | static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata) |
| 361 | { |
| 362 | struct ieee80211_local *local = sdata->local; |
| 363 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 364 | struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; |
| 365 | struct sk_buff *skb; |
| 366 | struct ieee80211_mgmt *mgmt; |
| 367 | u8 *pos, qos_info; |
| 368 | size_t offset = 0, noffset; |
| 369 | int i, count, rates_len, supp_rates_len; |
| 370 | u16 capab; |
| 371 | struct ieee80211_supported_band *sband; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 372 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 373 | struct ieee80211_channel *chan; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 374 | u32 rates = 0; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 375 | |
| 376 | lockdep_assert_held(&ifmgd->mtx); |
| 377 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 378 | rcu_read_lock(); |
| 379 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 380 | if (WARN_ON(!chanctx_conf)) { |
| 381 | rcu_read_unlock(); |
| 382 | return; |
| 383 | } |
| 384 | chan = chanctx_conf->channel; |
| 385 | rcu_read_unlock(); |
| 386 | sband = local->hw.wiphy->bands[chan->band]; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 387 | |
| 388 | if (assoc_data->supp_rates_len) { |
| 389 | /* |
| 390 | * Get all rates supported by the device and the AP as |
| 391 | * some APs don't like getting a superset of their rates |
| 392 | * in the association request (e.g. D-Link DAP 1353 in |
| 393 | * b-only mode)... |
| 394 | */ |
| 395 | rates_len = ieee80211_compatible_rates(assoc_data->supp_rates, |
| 396 | assoc_data->supp_rates_len, |
| 397 | sband, &rates); |
| 398 | } else { |
| 399 | /* |
| 400 | * In case AP not provide any supported rates information |
| 401 | * before association, we send information element(s) with |
| 402 | * all rates that we support. |
| 403 | */ |
| 404 | rates = ~0; |
| 405 | rates_len = sband->n_bitrates; |
| 406 | } |
| 407 | |
| 408 | skb = alloc_skb(local->hw.extra_tx_headroom + |
| 409 | sizeof(*mgmt) + /* bit too much but doesn't matter */ |
| 410 | 2 + assoc_data->ssid_len + /* SSID */ |
| 411 | 4 + rates_len + /* (extended) rates */ |
| 412 | 4 + /* power capability */ |
| 413 | 2 + 2 * sband->n_channels + /* supported channels */ |
| 414 | 2 + sizeof(struct ieee80211_ht_cap) + /* HT */ |
Mahesh Palivela | d495028 | 2012-10-10 11:25:40 +0000 | [diff] [blame] | 415 | 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */ |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 416 | assoc_data->ie_len + /* extra IEs */ |
| 417 | 9, /* WMM */ |
| 418 | GFP_KERNEL); |
| 419 | if (!skb) |
| 420 | return; |
| 421 | |
| 422 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 423 | |
| 424 | capab = WLAN_CAPABILITY_ESS; |
| 425 | |
| 426 | if (sband->band == IEEE80211_BAND_2GHZ) { |
| 427 | if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)) |
| 428 | capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME; |
| 429 | if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)) |
| 430 | capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
| 431 | } |
| 432 | |
| 433 | if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY) |
| 434 | capab |= WLAN_CAPABILITY_PRIVACY; |
| 435 | |
| 436 | if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) && |
| 437 | (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)) |
| 438 | capab |= WLAN_CAPABILITY_SPECTRUM_MGMT; |
| 439 | |
| 440 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 441 | memset(mgmt, 0, 24); |
| 442 | memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN); |
| 443 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
| 444 | memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN); |
| 445 | |
| 446 | if (!is_zero_ether_addr(assoc_data->prev_bssid)) { |
| 447 | skb_put(skb, 10); |
| 448 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 449 | IEEE80211_STYPE_REASSOC_REQ); |
| 450 | mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab); |
| 451 | mgmt->u.reassoc_req.listen_interval = |
| 452 | cpu_to_le16(local->hw.conf.listen_interval); |
| 453 | memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid, |
| 454 | ETH_ALEN); |
| 455 | } else { |
| 456 | skb_put(skb, 4); |
| 457 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 458 | IEEE80211_STYPE_ASSOC_REQ); |
| 459 | mgmt->u.assoc_req.capab_info = cpu_to_le16(capab); |
| 460 | mgmt->u.assoc_req.listen_interval = |
| 461 | cpu_to_le16(local->hw.conf.listen_interval); |
| 462 | } |
| 463 | |
| 464 | /* SSID */ |
| 465 | pos = skb_put(skb, 2 + assoc_data->ssid_len); |
| 466 | *pos++ = WLAN_EID_SSID; |
| 467 | *pos++ = assoc_data->ssid_len; |
| 468 | memcpy(pos, assoc_data->ssid, assoc_data->ssid_len); |
| 469 | |
| 470 | /* add all rates which were marked to be used above */ |
| 471 | supp_rates_len = rates_len; |
| 472 | if (supp_rates_len > 8) |
| 473 | supp_rates_len = 8; |
| 474 | |
| 475 | pos = skb_put(skb, supp_rates_len + 2); |
| 476 | *pos++ = WLAN_EID_SUPP_RATES; |
| 477 | *pos++ = supp_rates_len; |
| 478 | |
| 479 | count = 0; |
| 480 | for (i = 0; i < sband->n_bitrates; i++) { |
| 481 | if (BIT(i) & rates) { |
| 482 | int rate = sband->bitrates[i].bitrate; |
| 483 | *pos++ = (u8) (rate / 5); |
| 484 | if (++count == 8) |
| 485 | break; |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | if (rates_len > count) { |
| 490 | pos = skb_put(skb, rates_len - count + 2); |
| 491 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 492 | *pos++ = rates_len - count; |
| 493 | |
| 494 | for (i++; i < sband->n_bitrates; i++) { |
| 495 | if (BIT(i) & rates) { |
| 496 | int rate = sband->bitrates[i].bitrate; |
| 497 | *pos++ = (u8) (rate / 5); |
| 498 | } |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) { |
| 503 | /* 1. power capabilities */ |
| 504 | pos = skb_put(skb, 4); |
| 505 | *pos++ = WLAN_EID_PWR_CAPABILITY; |
| 506 | *pos++ = 2; |
| 507 | *pos++ = 0; /* min tx power */ |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 508 | *pos++ = chan->max_power; /* max tx power */ |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 509 | |
| 510 | /* 2. supported channels */ |
| 511 | /* TODO: get this in reg domain format */ |
| 512 | pos = skb_put(skb, 2 * sband->n_channels + 2); |
| 513 | *pos++ = WLAN_EID_SUPPORTED_CHANNELS; |
| 514 | *pos++ = 2 * sband->n_channels; |
| 515 | for (i = 0; i < sband->n_channels; i++) { |
| 516 | *pos++ = ieee80211_frequency_to_channel( |
| 517 | sband->channels[i].center_freq); |
| 518 | *pos++ = 1; /* one channel in the subband*/ |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | /* if present, add any custom IEs that go before HT */ |
| 523 | if (assoc_data->ie_len && assoc_data->ie) { |
| 524 | static const u8 before_ht[] = { |
| 525 | WLAN_EID_SSID, |
| 526 | WLAN_EID_SUPP_RATES, |
| 527 | WLAN_EID_EXT_SUPP_RATES, |
| 528 | WLAN_EID_PWR_CAPABILITY, |
| 529 | WLAN_EID_SUPPORTED_CHANNELS, |
| 530 | WLAN_EID_RSN, |
| 531 | WLAN_EID_QOS_CAPA, |
| 532 | WLAN_EID_RRM_ENABLED_CAPABILITIES, |
| 533 | WLAN_EID_MOBILITY_DOMAIN, |
| 534 | WLAN_EID_SUPPORTED_REGULATORY_CLASSES, |
| 535 | }; |
| 536 | noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len, |
| 537 | before_ht, ARRAY_SIZE(before_ht), |
| 538 | offset); |
| 539 | pos = skb_put(skb, noffset - offset); |
| 540 | memcpy(pos, assoc_data->ie + offset, noffset - offset); |
| 541 | offset = noffset; |
| 542 | } |
| 543 | |
Johannes Berg | 4e74bfd | 2012-03-08 15:02:04 +0100 | [diff] [blame] | 544 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 545 | ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param, |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 546 | sband, chan, sdata->smps_mode); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 547 | |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 548 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
| 549 | ieee80211_add_vht_ie(sdata, skb, sband); |
| 550 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 551 | /* if present, add any custom non-vendor IEs that go after HT */ |
| 552 | if (assoc_data->ie_len && assoc_data->ie) { |
| 553 | noffset = ieee80211_ie_split_vendor(assoc_data->ie, |
| 554 | assoc_data->ie_len, |
| 555 | offset); |
| 556 | pos = skb_put(skb, noffset - offset); |
| 557 | memcpy(pos, assoc_data->ie + offset, noffset - offset); |
| 558 | offset = noffset; |
| 559 | } |
| 560 | |
Johannes Berg | 76f0303 | 2012-03-08 15:02:05 +0100 | [diff] [blame] | 561 | if (assoc_data->wmm) { |
| 562 | if (assoc_data->uapsd) { |
Eliad Peller | dc41e4d | 2012-03-14 16:15:03 +0200 | [diff] [blame] | 563 | qos_info = ifmgd->uapsd_queues; |
| 564 | qos_info |= (ifmgd->uapsd_max_sp_len << |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 565 | IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT); |
| 566 | } else { |
| 567 | qos_info = 0; |
| 568 | } |
| 569 | |
| 570 | pos = skb_put(skb, 9); |
| 571 | *pos++ = WLAN_EID_VENDOR_SPECIFIC; |
| 572 | *pos++ = 7; /* len */ |
| 573 | *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */ |
| 574 | *pos++ = 0x50; |
| 575 | *pos++ = 0xf2; |
| 576 | *pos++ = 2; /* WME */ |
| 577 | *pos++ = 0; /* WME info */ |
| 578 | *pos++ = 1; /* WME ver */ |
| 579 | *pos++ = qos_info; |
| 580 | } |
| 581 | |
| 582 | /* add any remaining custom (i.e. vendor specific here) IEs */ |
| 583 | if (assoc_data->ie_len && assoc_data->ie) { |
| 584 | noffset = assoc_data->ie_len; |
| 585 | pos = skb_put(skb, noffset - offset); |
| 586 | memcpy(pos, assoc_data->ie + offset, noffset - offset); |
| 587 | } |
| 588 | |
Johannes Berg | a1845fc | 2012-06-27 13:18:36 +0200 | [diff] [blame] | 589 | drv_mgd_prepare_tx(local, sdata); |
| 590 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 591 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 592 | ieee80211_tx_skb(sdata, skb); |
| 593 | } |
| 594 | |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 595 | void ieee80211_send_pspoll(struct ieee80211_local *local, |
| 596 | struct ieee80211_sub_if_data *sdata) |
| 597 | { |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 598 | struct ieee80211_pspoll *pspoll; |
| 599 | struct sk_buff *skb; |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 600 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 601 | skb = ieee80211_pspoll_get(&local->hw, &sdata->vif); |
| 602 | if (!skb) |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 603 | return; |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 604 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 605 | pspoll = (struct ieee80211_pspoll *) skb->data; |
| 606 | pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 607 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 608 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 609 | ieee80211_tx_skb(sdata, skb); |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 610 | } |
| 611 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 612 | void ieee80211_send_nullfunc(struct ieee80211_local *local, |
| 613 | struct ieee80211_sub_if_data *sdata, |
| 614 | int powersave) |
| 615 | { |
| 616 | struct sk_buff *skb; |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 617 | struct ieee80211_hdr_3addr *nullfunc; |
Rajkumar Manoharan | b6f3530 | 2011-09-29 20:34:04 +0530 | [diff] [blame] | 618 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 619 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 620 | skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif); |
| 621 | if (!skb) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 622 | return; |
| 623 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 624 | nullfunc = (struct ieee80211_hdr_3addr *) skb->data; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 625 | if (powersave) |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 626 | nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 627 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 628 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
Rajkumar Manoharan | b6f3530 | 2011-09-29 20:34:04 +0530 | [diff] [blame] | 629 | if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL | |
| 630 | IEEE80211_STA_CONNECTION_POLL)) |
| 631 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE; |
| 632 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 633 | ieee80211_tx_skb(sdata, skb); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 634 | } |
| 635 | |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 636 | static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local, |
| 637 | struct ieee80211_sub_if_data *sdata) |
| 638 | { |
| 639 | struct sk_buff *skb; |
| 640 | struct ieee80211_hdr *nullfunc; |
| 641 | __le16 fc; |
| 642 | |
| 643 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) |
| 644 | return; |
| 645 | |
| 646 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30); |
Joe Perches | d15b845 | 2011-08-29 14:17:31 -0700 | [diff] [blame] | 647 | if (!skb) |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 648 | return; |
Joe Perches | d15b845 | 2011-08-29 14:17:31 -0700 | [diff] [blame] | 649 | |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 650 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 651 | |
| 652 | nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30); |
| 653 | memset(nullfunc, 0, 30); |
| 654 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | |
| 655 | IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); |
| 656 | nullfunc->frame_control = fc; |
| 657 | memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN); |
| 658 | memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); |
| 659 | memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN); |
| 660 | memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN); |
| 661 | |
| 662 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 663 | ieee80211_tx_skb(sdata, skb); |
| 664 | } |
| 665 | |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 666 | /* spectrum management related things */ |
| 667 | static void ieee80211_chswitch_work(struct work_struct *work) |
| 668 | { |
| 669 | struct ieee80211_sub_if_data *sdata = |
| 670 | container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 671 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 672 | |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 673 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 674 | return; |
| 675 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 676 | mutex_lock(&ifmgd->mtx); |
| 677 | if (!ifmgd->associated) |
| 678 | goto out; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 679 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 680 | sdata->local->_oper_channel = sdata->local->csa_channel; |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 681 | if (!sdata->local->ops->channel_switch) { |
| 682 | /* call "hw_config" only if doing sw channel switch */ |
| 683 | ieee80211_hw_config(sdata->local, |
| 684 | IEEE80211_CONF_CHANGE_CHANNEL); |
Shahar Levi | 1ea57b1 | 2011-09-08 08:44:05 +0300 | [diff] [blame] | 685 | } else { |
| 686 | /* update the device channel directly */ |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 687 | sdata->local->hw.conf.channel = sdata->local->_oper_channel; |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 688 | } |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 689 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 690 | /* XXX: shouldn't really modify cfg80211-owned data! */ |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 691 | ifmgd->associated->channel = sdata->local->_oper_channel; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 692 | |
Johannes Berg | 57eebdf | 2012-08-01 15:50:46 +0200 | [diff] [blame] | 693 | /* XXX: wait for a beacon first? */ |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 694 | ieee80211_wake_queues_by_reason(&sdata->local->hw, |
| 695 | IEEE80211_QUEUE_STOP_REASON_CSA); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 696 | out: |
| 697 | ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED; |
| 698 | mutex_unlock(&ifmgd->mtx); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 699 | } |
| 700 | |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 701 | void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success) |
| 702 | { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 703 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 704 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 705 | |
| 706 | trace_api_chswitch_done(sdata, success); |
| 707 | if (!success) { |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 708 | sdata_info(sdata, |
| 709 | "driver channel switch failed, disconnecting\n"); |
| 710 | ieee80211_queue_work(&sdata->local->hw, |
| 711 | &ifmgd->csa_connection_drop_work); |
| 712 | } else { |
| 713 | ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 714 | } |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 715 | } |
| 716 | EXPORT_SYMBOL(ieee80211_chswitch_done); |
| 717 | |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 718 | static void ieee80211_chswitch_timer(unsigned long data) |
| 719 | { |
| 720 | struct ieee80211_sub_if_data *sdata = |
| 721 | (struct ieee80211_sub_if_data *) data; |
| 722 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 723 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 724 | if (sdata->local->quiescing) { |
| 725 | set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running); |
| 726 | return; |
| 727 | } |
| 728 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 729 | ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata, |
| 733 | struct ieee80211_channel_sw_ie *sw_elem, |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 734 | struct ieee80211_bss *bss, |
| 735 | u64 timestamp) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 736 | { |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 737 | struct cfg80211_bss *cbss = |
| 738 | container_of((void *)bss, struct cfg80211_bss, priv); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 739 | struct ieee80211_channel *new_ch; |
| 740 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 741 | int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num, |
| 742 | cbss->channel->band); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 743 | struct ieee80211_chanctx *chanctx; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 744 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 745 | ASSERT_MGD_MTX(ifmgd); |
| 746 | |
| 747 | if (!ifmgd->associated) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 748 | return; |
| 749 | |
Helmut Schaa | fbe9c42 | 2009-07-23 12:14:04 +0200 | [diff] [blame] | 750 | if (sdata->local->scanning) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 751 | return; |
| 752 | |
| 753 | /* Disregard subsequent beacons if we are already running a timer |
| 754 | processing a CSA */ |
| 755 | |
| 756 | if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED) |
| 757 | return; |
| 758 | |
| 759 | new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq); |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 760 | if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED) { |
| 761 | sdata_info(sdata, |
| 762 | "AP %pM switches to unsupported channel (%d MHz), disconnecting\n", |
| 763 | ifmgd->associated->bssid, new_freq); |
| 764 | ieee80211_queue_work(&sdata->local->hw, |
| 765 | &ifmgd->csa_connection_drop_work); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 766 | return; |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 767 | } |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 768 | |
Johannes Berg | 57eebdf | 2012-08-01 15:50:46 +0200 | [diff] [blame] | 769 | ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED; |
| 770 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 771 | if (sdata->local->use_chanctx) { |
| 772 | sdata_info(sdata, |
| 773 | "not handling channel switch with channel contexts\n"); |
| 774 | ieee80211_queue_work(&sdata->local->hw, |
| 775 | &ifmgd->csa_connection_drop_work); |
| 776 | } |
| 777 | |
| 778 | mutex_lock(&sdata->local->chanctx_mtx); |
| 779 | if (WARN_ON(!rcu_access_pointer(sdata->vif.chanctx_conf))) { |
| 780 | mutex_unlock(&sdata->local->chanctx_mtx); |
| 781 | return; |
| 782 | } |
| 783 | chanctx = container_of(rcu_access_pointer(sdata->vif.chanctx_conf), |
| 784 | struct ieee80211_chanctx, conf); |
| 785 | if (chanctx->refcount > 1) { |
| 786 | sdata_info(sdata, |
| 787 | "channel switch with multiple interfaces on the same channel, disconnecting\n"); |
| 788 | ieee80211_queue_work(&sdata->local->hw, |
| 789 | &ifmgd->csa_connection_drop_work); |
| 790 | mutex_unlock(&sdata->local->chanctx_mtx); |
| 791 | return; |
| 792 | } |
| 793 | mutex_unlock(&sdata->local->chanctx_mtx); |
| 794 | |
| 795 | sdata->local->csa_channel = new_ch; |
| 796 | |
Johannes Berg | 57eebdf | 2012-08-01 15:50:46 +0200 | [diff] [blame] | 797 | if (sw_elem->mode) |
| 798 | ieee80211_stop_queues_by_reason(&sdata->local->hw, |
| 799 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 800 | |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 801 | if (sdata->local->ops->channel_switch) { |
| 802 | /* use driver's channel switch callback */ |
Johannes Berg | 57eebdf | 2012-08-01 15:50:46 +0200 | [diff] [blame] | 803 | struct ieee80211_channel_switch ch_switch = { |
| 804 | .timestamp = timestamp, |
| 805 | .block_tx = sw_elem->mode, |
| 806 | .channel = new_ch, |
| 807 | .count = sw_elem->count, |
| 808 | }; |
| 809 | |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 810 | drv_channel_switch(sdata->local, &ch_switch); |
| 811 | return; |
| 812 | } |
| 813 | |
| 814 | /* channel switch handled in software */ |
Johannes Berg | 57eebdf | 2012-08-01 15:50:46 +0200 | [diff] [blame] | 815 | if (sw_elem->count <= 1) |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 816 | ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); |
Johannes Berg | 57eebdf | 2012-08-01 15:50:46 +0200 | [diff] [blame] | 817 | else |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 818 | mod_timer(&ifmgd->chswitch_timer, |
Johannes Berg | 3049000 | 2012-08-01 15:53:45 +0200 | [diff] [blame] | 819 | TU_TO_EXP_TIME(sw_elem->count * |
| 820 | cbss->beacon_interval)); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 821 | } |
| 822 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame^] | 823 | static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata, |
| 824 | struct ieee80211_channel *channel, |
| 825 | const u8 *country_ie, u8 country_ie_len, |
| 826 | const u8 *pwr_constr_elem) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 827 | { |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 828 | struct ieee80211_country_ie_triplet *triplet; |
| 829 | int chan = ieee80211_frequency_to_channel(channel->center_freq); |
| 830 | int i, chan_pwr, chan_increment, new_ap_level; |
| 831 | bool have_chan_pwr = false; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 832 | |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 833 | /* Invalid IE */ |
| 834 | if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame^] | 835 | return 0; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 836 | |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 837 | triplet = (void *)(country_ie + 3); |
| 838 | country_ie_len -= 3; |
| 839 | |
| 840 | switch (channel->band) { |
| 841 | default: |
| 842 | WARN_ON_ONCE(1); |
| 843 | /* fall through */ |
| 844 | case IEEE80211_BAND_2GHZ: |
| 845 | case IEEE80211_BAND_60GHZ: |
| 846 | chan_increment = 1; |
| 847 | break; |
| 848 | case IEEE80211_BAND_5GHZ: |
| 849 | chan_increment = 4; |
| 850 | break; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 851 | } |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 852 | |
| 853 | /* find channel */ |
| 854 | while (country_ie_len >= 3) { |
| 855 | u8 first_channel = triplet->chans.first_channel; |
| 856 | |
| 857 | if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID) |
| 858 | goto next; |
| 859 | |
| 860 | for (i = 0; i < triplet->chans.num_channels; i++) { |
| 861 | if (first_channel + i * chan_increment == chan) { |
| 862 | have_chan_pwr = true; |
| 863 | chan_pwr = triplet->chans.max_power; |
| 864 | break; |
| 865 | } |
| 866 | } |
| 867 | if (have_chan_pwr) |
| 868 | break; |
| 869 | |
| 870 | next: |
| 871 | triplet++; |
| 872 | country_ie_len -= 3; |
| 873 | } |
| 874 | |
| 875 | if (!have_chan_pwr) |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame^] | 876 | return 0; |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 877 | |
| 878 | new_ap_level = max_t(int, 0, chan_pwr - *pwr_constr_elem); |
| 879 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame^] | 880 | if (sdata->ap_power_level == new_ap_level) |
| 881 | return 0; |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 882 | |
| 883 | sdata_info(sdata, |
| 884 | "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n", |
| 885 | new_ap_level, chan_pwr, *pwr_constr_elem, |
| 886 | sdata->u.mgd.bssid); |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame^] | 887 | sdata->ap_power_level = new_ap_level; |
| 888 | if (__ieee80211_recalc_txpower(sdata)) |
| 889 | return BSS_CHANGED_TXPOWER; |
| 890 | return 0; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 891 | } |
| 892 | |
Juuso Oikarinen | f90754c | 2010-06-21 08:59:39 +0300 | [diff] [blame] | 893 | void ieee80211_enable_dyn_ps(struct ieee80211_vif *vif) |
| 894 | { |
| 895 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 896 | struct ieee80211_local *local = sdata->local; |
| 897 | struct ieee80211_conf *conf = &local->hw.conf; |
| 898 | |
| 899 | WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION || |
| 900 | !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) || |
| 901 | (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)); |
| 902 | |
| 903 | local->disable_dynamic_ps = false; |
| 904 | conf->dynamic_ps_timeout = local->dynamic_ps_user_timeout; |
| 905 | } |
| 906 | EXPORT_SYMBOL(ieee80211_enable_dyn_ps); |
| 907 | |
| 908 | void ieee80211_disable_dyn_ps(struct ieee80211_vif *vif) |
| 909 | { |
| 910 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 911 | struct ieee80211_local *local = sdata->local; |
| 912 | struct ieee80211_conf *conf = &local->hw.conf; |
| 913 | |
| 914 | WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION || |
| 915 | !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) || |
| 916 | (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)); |
| 917 | |
| 918 | local->disable_dynamic_ps = true; |
| 919 | conf->dynamic_ps_timeout = 0; |
| 920 | del_timer_sync(&local->dynamic_ps_timer); |
| 921 | ieee80211_queue_work(&local->hw, |
| 922 | &local->dynamic_ps_enable_work); |
| 923 | } |
| 924 | EXPORT_SYMBOL(ieee80211_disable_dyn_ps); |
| 925 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 926 | /* powersave */ |
| 927 | static void ieee80211_enable_ps(struct ieee80211_local *local, |
| 928 | struct ieee80211_sub_if_data *sdata) |
| 929 | { |
| 930 | struct ieee80211_conf *conf = &local->hw.conf; |
| 931 | |
Johannes Berg | d5edaed | 2009-04-22 23:02:51 +0200 | [diff] [blame] | 932 | /* |
| 933 | * If we are scanning right now then the parameters will |
| 934 | * take effect when scan finishes. |
| 935 | */ |
Helmut Schaa | fbe9c42 | 2009-07-23 12:14:04 +0200 | [diff] [blame] | 936 | if (local->scanning) |
Johannes Berg | d5edaed | 2009-04-22 23:02:51 +0200 | [diff] [blame] | 937 | return; |
| 938 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 939 | if (conf->dynamic_ps_timeout > 0 && |
| 940 | !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) { |
| 941 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 942 | msecs_to_jiffies(conf->dynamic_ps_timeout)); |
| 943 | } else { |
| 944 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) |
| 945 | ieee80211_send_nullfunc(local, sdata, 1); |
Vivek Natarajan | 375177b | 2010-02-09 14:50:28 +0530 | [diff] [blame] | 946 | |
Juuso Oikarinen | 2a13052 | 2010-03-09 14:25:02 +0200 | [diff] [blame] | 947 | if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) && |
| 948 | (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)) |
| 949 | return; |
| 950 | |
| 951 | conf->flags |= IEEE80211_CONF_PS; |
| 952 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | |
| 956 | static void ieee80211_change_ps(struct ieee80211_local *local) |
| 957 | { |
| 958 | struct ieee80211_conf *conf = &local->hw.conf; |
| 959 | |
| 960 | if (local->ps_sdata) { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 961 | ieee80211_enable_ps(local, local->ps_sdata); |
| 962 | } else if (conf->flags & IEEE80211_CONF_PS) { |
| 963 | conf->flags &= ~IEEE80211_CONF_PS; |
| 964 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 965 | del_timer_sync(&local->dynamic_ps_timer); |
| 966 | cancel_work_sync(&local->dynamic_ps_enable_work); |
| 967 | } |
| 968 | } |
| 969 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 970 | static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata) |
| 971 | { |
| 972 | struct ieee80211_if_managed *mgd = &sdata->u.mgd; |
| 973 | struct sta_info *sta = NULL; |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 974 | bool authorized = false; |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 975 | |
| 976 | if (!mgd->powersave) |
| 977 | return false; |
| 978 | |
Johannes Berg | 05cb910 | 2011-10-28 11:59:47 +0200 | [diff] [blame] | 979 | if (mgd->broken_ap) |
| 980 | return false; |
| 981 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 982 | if (!mgd->associated) |
| 983 | return false; |
| 984 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 985 | if (mgd->flags & (IEEE80211_STA_BEACON_POLL | |
| 986 | IEEE80211_STA_CONNECTION_POLL)) |
| 987 | return false; |
| 988 | |
| 989 | rcu_read_lock(); |
| 990 | sta = sta_info_get(sdata, mgd->bssid); |
| 991 | if (sta) |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 992 | authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED); |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 993 | rcu_read_unlock(); |
| 994 | |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 995 | return authorized; |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 996 | } |
| 997 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 998 | /* need to hold RTNL or interface lock */ |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 999 | void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1000 | { |
| 1001 | struct ieee80211_sub_if_data *sdata, *found = NULL; |
| 1002 | int count = 0; |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 1003 | int timeout; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1004 | |
| 1005 | if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) { |
| 1006 | local->ps_sdata = NULL; |
| 1007 | return; |
| 1008 | } |
| 1009 | |
| 1010 | list_for_each_entry(sdata, &local->interfaces, list) { |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 1011 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1012 | continue; |
Rajkumar Manoharan | 8c7914d | 2011-02-01 00:28:59 +0530 | [diff] [blame] | 1013 | if (sdata->vif.type == NL80211_IFTYPE_AP) { |
| 1014 | /* If an AP vif is found, then disable PS |
| 1015 | * by setting the count to zero thereby setting |
| 1016 | * ps_sdata to NULL. |
| 1017 | */ |
| 1018 | count = 0; |
| 1019 | break; |
| 1020 | } |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1021 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 1022 | continue; |
| 1023 | found = sdata; |
| 1024 | count++; |
| 1025 | } |
| 1026 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1027 | if (count == 1 && ieee80211_powersave_allowed(found)) { |
Juuso Oikarinen | f90754c | 2010-06-21 08:59:39 +0300 | [diff] [blame] | 1028 | struct ieee80211_conf *conf = &local->hw.conf; |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1029 | s32 beaconint_us; |
| 1030 | |
| 1031 | if (latency < 0) |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 1032 | latency = pm_qos_request(PM_QOS_NETWORK_LATENCY); |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1033 | |
| 1034 | beaconint_us = ieee80211_tu_to_usec( |
| 1035 | found->vif.bss_conf.beacon_int); |
| 1036 | |
Juuso Oikarinen | ff61638 | 2010-06-09 09:51:52 +0300 | [diff] [blame] | 1037 | timeout = local->dynamic_ps_forced_timeout; |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 1038 | if (timeout < 0) { |
| 1039 | /* |
Juuso Oikarinen | ff61638 | 2010-06-09 09:51:52 +0300 | [diff] [blame] | 1040 | * Go to full PSM if the user configures a very low |
| 1041 | * latency requirement. |
Eliad Peller | 0ab82b0 | 2010-12-03 02:16:23 +0200 | [diff] [blame] | 1042 | * The 2000 second value is there for compatibility |
| 1043 | * until the PM_QOS_NETWORK_LATENCY is configured |
| 1044 | * with real values. |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 1045 | */ |
Eliad Peller | 0ab82b0 | 2010-12-03 02:16:23 +0200 | [diff] [blame] | 1046 | if (latency > (1900 * USEC_PER_MSEC) && |
| 1047 | latency != (2000 * USEC_PER_SEC)) |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 1048 | timeout = 0; |
Juuso Oikarinen | ff61638 | 2010-06-09 09:51:52 +0300 | [diff] [blame] | 1049 | else |
| 1050 | timeout = 100; |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 1051 | } |
Juuso Oikarinen | f90754c | 2010-06-21 08:59:39 +0300 | [diff] [blame] | 1052 | local->dynamic_ps_user_timeout = timeout; |
| 1053 | if (!local->disable_dynamic_ps) |
| 1054 | conf->dynamic_ps_timeout = |
| 1055 | local->dynamic_ps_user_timeout; |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 1056 | |
Johannes Berg | 04fe203 | 2009-04-22 18:44:37 +0200 | [diff] [blame] | 1057 | if (beaconint_us > latency) { |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1058 | local->ps_sdata = NULL; |
Johannes Berg | 04fe203 | 2009-04-22 18:44:37 +0200 | [diff] [blame] | 1059 | } else { |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 1060 | struct ieee80211_bss *bss; |
Johannes Berg | 04fe203 | 2009-04-22 18:44:37 +0200 | [diff] [blame] | 1061 | int maxslp = 1; |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 1062 | u8 dtimper; |
Johannes Berg | 04fe203 | 2009-04-22 18:44:37 +0200 | [diff] [blame] | 1063 | |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 1064 | bss = (void *)found->u.mgd.associated->priv; |
| 1065 | dtimper = bss->dtim_period; |
| 1066 | |
| 1067 | /* If the TIM IE is invalid, pretend the value is 1 */ |
| 1068 | if (!dtimper) |
| 1069 | dtimper = 1; |
| 1070 | else if (dtimper > 1) |
Johannes Berg | 04fe203 | 2009-04-22 18:44:37 +0200 | [diff] [blame] | 1071 | maxslp = min_t(int, dtimper, |
| 1072 | latency / beaconint_us); |
| 1073 | |
Johannes Berg | 9ccebe6 | 2009-04-23 10:32:36 +0200 | [diff] [blame] | 1074 | local->hw.conf.max_sleep_period = maxslp; |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 1075 | local->hw.conf.ps_dtim_period = dtimper; |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1076 | local->ps_sdata = found; |
Johannes Berg | 04fe203 | 2009-04-22 18:44:37 +0200 | [diff] [blame] | 1077 | } |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1078 | } else { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1079 | local->ps_sdata = NULL; |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1080 | } |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1081 | |
| 1082 | ieee80211_change_ps(local); |
| 1083 | } |
| 1084 | |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 1085 | void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata) |
| 1086 | { |
| 1087 | bool ps_allowed = ieee80211_powersave_allowed(sdata); |
| 1088 | |
| 1089 | if (sdata->vif.bss_conf.ps != ps_allowed) { |
| 1090 | sdata->vif.bss_conf.ps = ps_allowed; |
| 1091 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS); |
| 1092 | } |
| 1093 | } |
| 1094 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1095 | void ieee80211_dynamic_ps_disable_work(struct work_struct *work) |
| 1096 | { |
| 1097 | struct ieee80211_local *local = |
| 1098 | container_of(work, struct ieee80211_local, |
| 1099 | dynamic_ps_disable_work); |
| 1100 | |
| 1101 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 1102 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 1103 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 1104 | } |
| 1105 | |
| 1106 | ieee80211_wake_queues_by_reason(&local->hw, |
| 1107 | IEEE80211_QUEUE_STOP_REASON_PS); |
| 1108 | } |
| 1109 | |
| 1110 | void ieee80211_dynamic_ps_enable_work(struct work_struct *work) |
| 1111 | { |
| 1112 | struct ieee80211_local *local = |
| 1113 | container_of(work, struct ieee80211_local, |
| 1114 | dynamic_ps_enable_work); |
| 1115 | struct ieee80211_sub_if_data *sdata = local->ps_sdata; |
Christian Lamparter | 5e34069 | 2011-06-30 21:08:43 +0200 | [diff] [blame] | 1116 | struct ieee80211_if_managed *ifmgd; |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1117 | unsigned long flags; |
| 1118 | int q; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1119 | |
| 1120 | /* can only happen when PS was just disabled anyway */ |
| 1121 | if (!sdata) |
| 1122 | return; |
| 1123 | |
Christian Lamparter | 5e34069 | 2011-06-30 21:08:43 +0200 | [diff] [blame] | 1124 | ifmgd = &sdata->u.mgd; |
| 1125 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1126 | if (local->hw.conf.flags & IEEE80211_CONF_PS) |
| 1127 | return; |
| 1128 | |
Arik Nemtsov | 77b7023 | 2011-06-26 12:06:54 +0300 | [diff] [blame] | 1129 | if (!local->disable_dynamic_ps && |
| 1130 | local->hw.conf.dynamic_ps_timeout > 0) { |
| 1131 | /* don't enter PS if TX frames are pending */ |
| 1132 | if (drv_tx_frames_pending(local)) { |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1133 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 1134 | msecs_to_jiffies( |
| 1135 | local->hw.conf.dynamic_ps_timeout)); |
| 1136 | return; |
| 1137 | } |
Arik Nemtsov | 77b7023 | 2011-06-26 12:06:54 +0300 | [diff] [blame] | 1138 | |
| 1139 | /* |
| 1140 | * transmission can be stopped by others which leads to |
| 1141 | * dynamic_ps_timer expiry. Postpone the ps timer if it |
| 1142 | * is not the actual idle state. |
| 1143 | */ |
| 1144 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 1145 | for (q = 0; q < local->hw.queues; q++) { |
| 1146 | if (local->queue_stop_reasons[q]) { |
| 1147 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, |
| 1148 | flags); |
| 1149 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 1150 | msecs_to_jiffies( |
| 1151 | local->hw.conf.dynamic_ps_timeout)); |
| 1152 | return; |
| 1153 | } |
| 1154 | } |
| 1155 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1156 | } |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1157 | |
Vivek Natarajan | 375177b | 2010-02-09 14:50:28 +0530 | [diff] [blame] | 1158 | if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) && |
Mohammed Shafi Shajakhan | 9c38a8b | 2011-12-14 19:46:07 +0530 | [diff] [blame] | 1159 | !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) { |
Vivek Natarajan | f3e85b9 | 2011-02-23 13:04:32 +0530 | [diff] [blame] | 1160 | netif_tx_stop_all_queues(sdata->dev); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1161 | |
Vivek Natarajan | e8306f9 | 2011-04-06 11:41:10 +0530 | [diff] [blame] | 1162 | if (drv_tx_frames_pending(local)) |
| 1163 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 1164 | msecs_to_jiffies( |
| 1165 | local->hw.conf.dynamic_ps_timeout)); |
| 1166 | else { |
| 1167 | ieee80211_send_nullfunc(local, sdata, 1); |
| 1168 | /* Flush to get the tx status of nullfunc frame */ |
| 1169 | drv_flush(local, false); |
| 1170 | } |
Vivek Natarajan | f3e85b9 | 2011-02-23 13:04:32 +0530 | [diff] [blame] | 1171 | } |
| 1172 | |
Juuso Oikarinen | 2a13052 | 2010-03-09 14:25:02 +0200 | [diff] [blame] | 1173 | if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) && |
| 1174 | (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) || |
Vivek Natarajan | 375177b | 2010-02-09 14:50:28 +0530 | [diff] [blame] | 1175 | (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) { |
| 1176 | ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED; |
| 1177 | local->hw.conf.flags |= IEEE80211_CONF_PS; |
| 1178 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 1179 | } |
Vivek Natarajan | f3e85b9 | 2011-02-23 13:04:32 +0530 | [diff] [blame] | 1180 | |
Arik Nemtsov | 77b7023 | 2011-06-26 12:06:54 +0300 | [diff] [blame] | 1181 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) |
| 1182 | netif_tx_wake_all_queues(sdata->dev); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | void ieee80211_dynamic_ps_timer(unsigned long data) |
| 1186 | { |
| 1187 | struct ieee80211_local *local = (void *) data; |
| 1188 | |
Luis R. Rodriguez | 78f1a8b | 2009-07-27 08:38:25 -0700 | [diff] [blame] | 1189 | if (local->quiescing || local->suspended) |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 1190 | return; |
| 1191 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 1192 | ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1193 | } |
| 1194 | |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1195 | /* MLME */ |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1196 | static bool ieee80211_sta_wmm_params(struct ieee80211_local *local, |
Johannes Berg | 4ced3f7 | 2010-07-19 16:39:04 +0200 | [diff] [blame] | 1197 | struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1198 | u8 *wmm_param, size_t wmm_param_len) |
| 1199 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1200 | struct ieee80211_tx_queue_params params; |
Johannes Berg | 4ced3f7 | 2010-07-19 16:39:04 +0200 | [diff] [blame] | 1201 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1202 | size_t left; |
| 1203 | int count; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1204 | u8 *pos, uapsd_queues = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1205 | |
Stanislaw Gruszka | e1b3ec1 | 2010-03-29 12:18:34 +0200 | [diff] [blame] | 1206 | if (!local->ops->conf_tx) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1207 | return false; |
Stanislaw Gruszka | e1b3ec1 | 2010-03-29 12:18:34 +0200 | [diff] [blame] | 1208 | |
Johannes Berg | 32c5057 | 2012-03-28 11:04:29 +0200 | [diff] [blame] | 1209 | if (local->hw.queues < IEEE80211_NUM_ACS) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1210 | return false; |
Johannes Berg | 3434fbd | 2008-05-03 00:59:37 +0200 | [diff] [blame] | 1211 | |
| 1212 | if (!wmm_param) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1213 | return false; |
Johannes Berg | 3434fbd | 2008-05-03 00:59:37 +0200 | [diff] [blame] | 1214 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1215 | if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1216 | return false; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1217 | |
| 1218 | if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED) |
Eliad Peller | dc41e4d | 2012-03-14 16:15:03 +0200 | [diff] [blame] | 1219 | uapsd_queues = ifmgd->uapsd_queues; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1220 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1221 | count = wmm_param[6] & 0x0f; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1222 | if (count == ifmgd->wmm_last_param_set) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1223 | return false; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1224 | ifmgd->wmm_last_param_set = count; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1225 | |
| 1226 | pos = wmm_param + 8; |
| 1227 | left = wmm_param_len - 8; |
| 1228 | |
| 1229 | memset(¶ms, 0, sizeof(params)); |
| 1230 | |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 1231 | sdata->wmm_acm = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1232 | for (; left >= 4; left -= 4, pos += 4) { |
| 1233 | int aci = (pos[0] >> 5) & 0x03; |
| 1234 | int acm = (pos[0] >> 4) & 0x01; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1235 | bool uapsd = false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1236 | int queue; |
| 1237 | |
| 1238 | switch (aci) { |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 1239 | case 1: /* AC_BK */ |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 1240 | queue = 3; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 1241 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 1242 | sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1243 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) |
| 1244 | uapsd = true; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1245 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 1246 | case 2: /* AC_VI */ |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 1247 | queue = 1; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 1248 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 1249 | sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1250 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) |
| 1251 | uapsd = true; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1252 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 1253 | case 3: /* AC_VO */ |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 1254 | queue = 0; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 1255 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 1256 | sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1257 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) |
| 1258 | uapsd = true; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1259 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 1260 | case 0: /* AC_BE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1261 | default: |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 1262 | queue = 2; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 1263 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 1264 | sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1265 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) |
| 1266 | uapsd = true; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1267 | break; |
| 1268 | } |
| 1269 | |
| 1270 | params.aifs = pos[0] & 0x0f; |
| 1271 | params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4); |
| 1272 | params.cw_min = ecw2cw(pos[1] & 0x0f); |
Johannes Berg | f434b2d | 2008-07-10 11:22:31 +0200 | [diff] [blame] | 1273 | params.txop = get_unaligned_le16(pos + 2); |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1274 | params.uapsd = uapsd; |
| 1275 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 1276 | mlme_dbg(sdata, |
| 1277 | "WMM queue=%d aci=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d\n", |
| 1278 | queue, aci, acm, |
| 1279 | params.aifs, params.cw_min, params.cw_max, |
| 1280 | params.txop, params.uapsd); |
Eliad Peller | f6f3def | 2011-09-25 20:06:54 +0300 | [diff] [blame] | 1281 | sdata->tx_conf[queue] = params; |
| 1282 | if (drv_conf_tx(local, sdata, queue, ¶ms)) |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 1283 | sdata_err(sdata, |
| 1284 | "failed to set TX queue parameters for queue %d\n", |
| 1285 | queue); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1286 | } |
Stanislaw Gruszka | e1b3ec1 | 2010-03-29 12:18:34 +0200 | [diff] [blame] | 1287 | |
| 1288 | /* enable WMM or activate new settings */ |
Johannes Berg | 4ced3f7 | 2010-07-19 16:39:04 +0200 | [diff] [blame] | 1289 | sdata->vif.bss_conf.qos = true; |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1290 | return true; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1291 | } |
| 1292 | |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 1293 | static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata) |
| 1294 | { |
| 1295 | lockdep_assert_held(&sdata->local->mtx); |
| 1296 | |
| 1297 | sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL | |
| 1298 | IEEE80211_STA_BEACON_POLL); |
| 1299 | ieee80211_run_deferred_scan(sdata->local); |
| 1300 | } |
| 1301 | |
| 1302 | static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata) |
| 1303 | { |
| 1304 | mutex_lock(&sdata->local->mtx); |
| 1305 | __ieee80211_stop_poll(sdata); |
| 1306 | mutex_unlock(&sdata->local->mtx); |
| 1307 | } |
| 1308 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 1309 | static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata, |
| 1310 | u16 capab, bool erp_valid, u8 erp) |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1311 | { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 1312 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1313 | u32 changed = 0; |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 1314 | bool use_protection; |
| 1315 | bool use_short_preamble; |
| 1316 | bool use_short_slot; |
| 1317 | |
| 1318 | if (erp_valid) { |
| 1319 | use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0; |
| 1320 | use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0; |
| 1321 | } else { |
| 1322 | use_protection = false; |
| 1323 | use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE); |
| 1324 | } |
| 1325 | |
| 1326 | use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1327 | if (ieee80211_get_sdata_band(sdata) == IEEE80211_BAND_5GHZ) |
Felix Fietkau | 43d3534 | 2010-01-15 03:00:48 +0100 | [diff] [blame] | 1328 | use_short_slot = true; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1329 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1330 | if (use_protection != bss_conf->use_cts_prot) { |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1331 | bss_conf->use_cts_prot = use_protection; |
| 1332 | changed |= BSS_CHANGED_ERP_CTS_PROT; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1333 | } |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1334 | |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 1335 | if (use_short_preamble != bss_conf->use_short_preamble) { |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 1336 | bss_conf->use_short_preamble = use_short_preamble; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1337 | changed |= BSS_CHANGED_ERP_PREAMBLE; |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1338 | } |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1339 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 1340 | if (use_short_slot != bss_conf->use_short_slot) { |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 1341 | bss_conf->use_short_slot = use_short_slot; |
| 1342 | changed |= BSS_CHANGED_ERP_SLOT; |
John W. Linville | 50c4afb | 2008-04-15 14:09:27 -0400 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | return changed; |
| 1346 | } |
| 1347 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1348 | static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 1349 | struct cfg80211_bss *cbss, |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1350 | u32 bss_info_changed) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1351 | { |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 1352 | struct ieee80211_bss *bss = (void *)cbss->priv; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1353 | struct ieee80211_local *local = sdata->local; |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 1354 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1355 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1356 | bss_info_changed |= BSS_CHANGED_ASSOC; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1357 | bss_info_changed |= ieee80211_handle_bss_capability(sdata, |
Luciano Coelho | 50ae34a | 2012-06-20 17:23:24 +0300 | [diff] [blame] | 1358 | bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value); |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 1359 | |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 1360 | sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec( |
| 1361 | IEEE80211_BEACON_LOSS_COUNT * bss_conf->beacon_int)); |
| 1362 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 1363 | sdata->u.mgd.associated = cbss; |
| 1364 | memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1365 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 1366 | sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE; |
| 1367 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1368 | /* just to be sure */ |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 1369 | ieee80211_stop_poll(sdata); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1370 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 1371 | ieee80211_led_assoc(local, 1); |
| 1372 | |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 1373 | if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD) |
| 1374 | bss_conf->dtim_period = bss->dtim_period; |
| 1375 | else |
| 1376 | bss_conf->dtim_period = 0; |
| 1377 | |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 1378 | bss_conf->assoc = 1; |
Johannes Berg | 9cef873 | 2009-05-14 13:10:14 +0200 | [diff] [blame] | 1379 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 1380 | /* Tell the driver to monitor connection quality (if supported) */ |
Johannes Berg | ea08635 | 2012-01-19 09:29:58 +0100 | [diff] [blame] | 1381 | if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI && |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 1382 | bss_conf->cqm_rssi_thold) |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 1383 | bss_info_changed |= BSS_CHANGED_CQM; |
| 1384 | |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 1385 | /* Enable ARP filtering */ |
| 1386 | if (bss_conf->arp_filter_enabled != sdata->arp_filter_state) { |
| 1387 | bss_conf->arp_filter_enabled = sdata->arp_filter_state; |
| 1388 | bss_info_changed |= BSS_CHANGED_ARP_FILTER; |
| 1389 | } |
| 1390 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1391 | ieee80211_bss_info_change_notify(sdata, bss_info_changed); |
Guy Cohen | 8db9369 | 2008-07-03 19:56:13 +0300 | [diff] [blame] | 1392 | |
Johannes Berg | 056508d | 2009-07-30 21:43:55 +0200 | [diff] [blame] | 1393 | mutex_lock(&local->iflist_mtx); |
| 1394 | ieee80211_recalc_ps(local, -1); |
| 1395 | mutex_unlock(&local->iflist_mtx); |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 1396 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 1397 | ieee80211_recalc_smps(sdata); |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 1398 | ieee80211_recalc_ps_vif(sdata); |
| 1399 | |
John W. Linville | 8a5b33f | 2010-01-06 15:39:39 -0500 | [diff] [blame] | 1400 | netif_tx_start_all_queues(sdata->dev); |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 1401 | netif_carrier_on(sdata->dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1402 | } |
| 1403 | |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 1404 | static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 1405 | u16 stype, u16 reason, bool tx, |
| 1406 | u8 *frame_buf) |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1407 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1408 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1409 | struct ieee80211_local *local = sdata->local; |
| 1410 | struct sta_info *sta; |
Johannes Berg | 3cc5240 | 2012-03-09 13:12:35 +0100 | [diff] [blame] | 1411 | u32 changed = 0; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1412 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1413 | ASSERT_MGD_MTX(ifmgd); |
| 1414 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 1415 | if (WARN_ON_ONCE(tx && !frame_buf)) |
| 1416 | return; |
| 1417 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1418 | if (WARN_ON(!ifmgd->associated)) |
| 1419 | return; |
| 1420 | |
David Spinadel | 79543d8 | 2012-06-12 09:59:45 +0300 | [diff] [blame] | 1421 | ieee80211_stop_poll(sdata); |
| 1422 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1423 | ifmgd->associated = NULL; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1424 | |
| 1425 | /* |
| 1426 | * we need to commit the associated = NULL change because the |
| 1427 | * scan code uses that to determine whether this iface should |
| 1428 | * go to/wake up from powersave or not -- and could otherwise |
| 1429 | * wake the queues erroneously. |
| 1430 | */ |
| 1431 | smp_mb(); |
| 1432 | |
| 1433 | /* |
| 1434 | * Thus, we can only afterwards stop the queues -- to account |
| 1435 | * for the case where another CPU is finishing a scan at this |
| 1436 | * time -- we don't want the scan code to enable queues. |
| 1437 | */ |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1438 | |
John W. Linville | 8a5b33f | 2010-01-06 15:39:39 -0500 | [diff] [blame] | 1439 | netif_tx_stop_all_queues(sdata->dev); |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1440 | netif_carrier_off(sdata->dev); |
| 1441 | |
Johannes Berg | 2a41905 | 2010-06-10 10:21:29 +0200 | [diff] [blame] | 1442 | mutex_lock(&local->sta_mtx); |
Eliad Peller | 88a9e31 | 2012-06-01 11:14:03 +0300 | [diff] [blame] | 1443 | sta = sta_info_get(sdata, ifmgd->bssid); |
Sujith | 4cad6c7 | 2010-02-10 14:52:21 +0530 | [diff] [blame] | 1444 | if (sta) { |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1445 | set_sta_flag(sta, WLAN_STA_BLOCK_BA); |
Johannes Berg | 7f16114 | 2012-07-18 12:53:34 +0200 | [diff] [blame] | 1446 | ieee80211_sta_tear_down_BA_sessions(sta, false); |
Sujith | 4cad6c7 | 2010-02-10 14:52:21 +0530 | [diff] [blame] | 1447 | } |
Johannes Berg | 2a41905 | 2010-06-10 10:21:29 +0200 | [diff] [blame] | 1448 | mutex_unlock(&local->sta_mtx); |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1449 | |
Eliad Peller | 88bc40e | 2012-07-12 17:35:33 +0300 | [diff] [blame] | 1450 | /* |
| 1451 | * if we want to get out of ps before disassoc (why?) we have |
| 1452 | * to do it before sending disassoc, as otherwise the null-packet |
| 1453 | * won't be valid. |
| 1454 | */ |
| 1455 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 1456 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 1457 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 1458 | } |
| 1459 | local->ps_sdata = NULL; |
| 1460 | |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 1461 | /* disable per-vif ps */ |
| 1462 | ieee80211_recalc_ps_vif(sdata); |
| 1463 | |
Eliad Peller | f823981 | 2012-06-27 14:18:22 +0300 | [diff] [blame] | 1464 | /* flush out any pending frame (e.g. DELBA) before deauth/disassoc */ |
| 1465 | if (tx) |
| 1466 | drv_flush(local, false); |
| 1467 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 1468 | /* deauthenticate/disassociate now */ |
| 1469 | if (tx || frame_buf) |
Eliad Peller | 88a9e31 | 2012-06-01 11:14:03 +0300 | [diff] [blame] | 1470 | ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, stype, |
| 1471 | reason, tx, frame_buf); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 1472 | |
| 1473 | /* flush out frame */ |
| 1474 | if (tx) |
| 1475 | drv_flush(local, false); |
| 1476 | |
Eliad Peller | 88a9e31 | 2012-06-01 11:14:03 +0300 | [diff] [blame] | 1477 | /* clear bssid only after building the needed mgmt frames */ |
| 1478 | memset(ifmgd->bssid, 0, ETH_ALEN); |
| 1479 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 1480 | /* remove AP and TDLS peers */ |
| 1481 | sta_info_flush(local, sdata); |
| 1482 | |
| 1483 | /* finally reset all BSS / config parameters */ |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 1484 | changed |= ieee80211_reset_erp_info(sdata); |
| 1485 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 1486 | ieee80211_led_assoc(local, 0); |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1487 | changed |= BSS_CHANGED_ASSOC; |
| 1488 | sdata->vif.bss_conf.assoc = false; |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 1489 | |
Johannes Berg | 413ad50 | 2009-05-08 21:21:06 +0200 | [diff] [blame] | 1490 | /* on the next assoc, re-program HT parameters */ |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 1491 | memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa)); |
| 1492 | memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask)); |
Johannes Berg | 413ad50 | 2009-05-08 21:21:06 +0200 | [diff] [blame] | 1493 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame^] | 1494 | sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL; |
Vasanthakumar Thiagarajan | a8302de | 2009-01-09 18:14:15 +0530 | [diff] [blame] | 1495 | |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 1496 | del_timer_sync(&local->dynamic_ps_timer); |
| 1497 | cancel_work_sync(&local->dynamic_ps_enable_work); |
| 1498 | |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 1499 | /* Disable ARP filtering */ |
| 1500 | if (sdata->vif.bss_conf.arp_filter_enabled) { |
| 1501 | sdata->vif.bss_conf.arp_filter_enabled = false; |
| 1502 | changed |= BSS_CHANGED_ARP_FILTER; |
| 1503 | } |
| 1504 | |
Johannes Berg | 3abead5 | 2012-03-02 15:56:59 +0100 | [diff] [blame] | 1505 | sdata->vif.bss_conf.qos = false; |
| 1506 | changed |= BSS_CHANGED_QOS; |
| 1507 | |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 1508 | /* The BSSID (not really interesting) and HT changed */ |
| 1509 | changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT; |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1510 | ieee80211_bss_info_change_notify(sdata, changed); |
Tomas Winkler | 8e268e4 | 2008-11-25 13:05:44 +0200 | [diff] [blame] | 1511 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1512 | ieee80211_vif_release_channel(sdata); |
Johannes Berg | 3cc5240 | 2012-03-09 13:12:35 +0100 | [diff] [blame] | 1513 | |
Johannes Berg | 3abead5 | 2012-03-02 15:56:59 +0100 | [diff] [blame] | 1514 | /* disassociated - set to defaults now */ |
| 1515 | ieee80211_set_wmm_default(sdata, false); |
| 1516 | |
Johannes Berg | b9dcf71 | 2010-08-27 12:35:54 +0200 | [diff] [blame] | 1517 | del_timer_sync(&sdata->u.mgd.conn_mon_timer); |
| 1518 | del_timer_sync(&sdata->u.mgd.bcn_mon_timer); |
| 1519 | del_timer_sync(&sdata->u.mgd.timer); |
| 1520 | del_timer_sync(&sdata->u.mgd.chswitch_timer); |
Johannes Berg | 2d9957c | 2012-08-01 20:54:52 +0200 | [diff] [blame] | 1521 | |
| 1522 | sdata->u.mgd.timers_running = 0; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1523 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1524 | |
Kalle Valo | 3cf335d | 2009-03-22 21:57:06 +0200 | [diff] [blame] | 1525 | void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata, |
| 1526 | struct ieee80211_hdr *hdr) |
| 1527 | { |
| 1528 | /* |
| 1529 | * We can postpone the mgd.timer whenever receiving unicast frames |
| 1530 | * from AP because we know that the connection is working both ways |
| 1531 | * at that time. But multicast frames (and hence also beacons) must |
| 1532 | * be ignored here, because we need to trigger the timer during |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1533 | * data idle periods for sending the periodic probe request to the |
| 1534 | * AP we're connected to. |
Kalle Valo | 3cf335d | 2009-03-22 21:57:06 +0200 | [diff] [blame] | 1535 | */ |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1536 | if (is_multicast_ether_addr(hdr->addr1)) |
| 1537 | return; |
| 1538 | |
Luis R. Rodriguez | be099e8 | 2010-09-16 15:12:29 -0400 | [diff] [blame] | 1539 | ieee80211_sta_reset_conn_monitor(sdata); |
Kalle Valo | 3cf335d | 2009-03-22 21:57:06 +0200 | [diff] [blame] | 1540 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1541 | |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1542 | static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata) |
| 1543 | { |
| 1544 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 1545 | struct ieee80211_local *local = sdata->local; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1546 | |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 1547 | mutex_lock(&local->mtx); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1548 | if (!(ifmgd->flags & (IEEE80211_STA_BEACON_POLL | |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 1549 | IEEE80211_STA_CONNECTION_POLL))) { |
| 1550 | mutex_unlock(&local->mtx); |
| 1551 | return; |
| 1552 | } |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1553 | |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 1554 | __ieee80211_stop_poll(sdata); |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 1555 | |
| 1556 | mutex_lock(&local->iflist_mtx); |
| 1557 | ieee80211_recalc_ps(local, -1); |
| 1558 | mutex_unlock(&local->iflist_mtx); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1559 | |
| 1560 | if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR) |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 1561 | goto out; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1562 | |
| 1563 | /* |
| 1564 | * We've received a probe response, but are not sure whether |
| 1565 | * we have or will be receiving any beacons or data, so let's |
| 1566 | * schedule the timers again, just in case. |
| 1567 | */ |
| 1568 | ieee80211_sta_reset_beacon_monitor(sdata); |
| 1569 | |
| 1570 | mod_timer(&ifmgd->conn_mon_timer, |
| 1571 | round_jiffies_up(jiffies + |
| 1572 | IEEE80211_CONNECTION_IDLE_TIME)); |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 1573 | out: |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 1574 | mutex_unlock(&local->mtx); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata, |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 1578 | struct ieee80211_hdr *hdr, bool ack) |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1579 | { |
Felix Fietkau | 75706d0 | 2010-12-02 21:01:07 +0100 | [diff] [blame] | 1580 | if (!ieee80211_is_data(hdr->frame_control)) |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1581 | return; |
| 1582 | |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 1583 | if (ack) |
| 1584 | ieee80211_sta_reset_conn_monitor(sdata); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1585 | |
| 1586 | if (ieee80211_is_nullfunc(hdr->frame_control) && |
| 1587 | sdata->u.mgd.probe_send_count > 0) { |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 1588 | if (ack) |
| 1589 | sdata->u.mgd.probe_send_count = 0; |
| 1590 | else |
| 1591 | sdata->u.mgd.nullfunc_failed = true; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1592 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
| 1593 | } |
| 1594 | } |
| 1595 | |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 1596 | static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata) |
| 1597 | { |
| 1598 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 1599 | const u8 *ssid; |
Luis R. Rodriguez | f01a067 | 2010-09-16 15:12:34 -0400 | [diff] [blame] | 1600 | u8 *dst = ifmgd->associated->bssid; |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 1601 | u8 unicast_limit = max(1, max_probe_tries - 3); |
Luis R. Rodriguez | f01a067 | 2010-09-16 15:12:34 -0400 | [diff] [blame] | 1602 | |
| 1603 | /* |
| 1604 | * Try sending broadcast probe requests for the last three |
| 1605 | * probe requests after the first ones failed since some |
| 1606 | * buggy APs only support broadcast probe requests. |
| 1607 | */ |
| 1608 | if (ifmgd->probe_send_count >= unicast_limit) |
| 1609 | dst = NULL; |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 1610 | |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1611 | /* |
| 1612 | * When the hardware reports an accurate Tx ACK status, it's |
| 1613 | * better to send a nullfunc frame instead of a probe request, |
| 1614 | * as it will kick us off the AP quickly if we aren't associated |
| 1615 | * anymore. The timeout will be reset if the frame is ACKed by |
| 1616 | * the AP. |
| 1617 | */ |
Soumik Das | 992e68b | 2012-05-20 15:31:13 +0530 | [diff] [blame] | 1618 | ifmgd->probe_send_count++; |
| 1619 | |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 1620 | if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) { |
| 1621 | ifmgd->nullfunc_failed = false; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1622 | ieee80211_send_nullfunc(sdata->local, sdata, 0); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 1623 | } else { |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 1624 | int ssid_len; |
| 1625 | |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1626 | ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID); |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 1627 | if (WARN_ON_ONCE(ssid == NULL)) |
| 1628 | ssid_len = 0; |
| 1629 | else |
| 1630 | ssid_len = ssid[1]; |
| 1631 | |
| 1632 | ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid_len, NULL, |
Johannes Berg | fe94fe0 | 2012-07-30 12:26:34 +0200 | [diff] [blame] | 1633 | 0, (u32) -1, true, false, |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1634 | ifmgd->associated->channel, false); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1635 | } |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 1636 | |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 1637 | ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms); |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 1638 | run_again(ifmgd, ifmgd->probe_timeout); |
Rajkumar Manoharan | f69b9c7 | 2012-03-15 06:15:26 +0530 | [diff] [blame] | 1639 | if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) |
| 1640 | drv_flush(sdata->local, false); |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 1641 | } |
| 1642 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1643 | static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata, |
| 1644 | bool beacon) |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1645 | { |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1646 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1647 | bool already = false; |
Johannes Berg | 34bfc41 | 2009-05-12 19:58:12 +0200 | [diff] [blame] | 1648 | |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 1649 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | 0e2b628 | 2009-07-13 13:23:39 +0200 | [diff] [blame] | 1650 | return; |
| 1651 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1652 | mutex_lock(&ifmgd->mtx); |
| 1653 | |
| 1654 | if (!ifmgd->associated) |
| 1655 | goto out; |
| 1656 | |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 1657 | mutex_lock(&sdata->local->mtx); |
| 1658 | |
| 1659 | if (sdata->local->tmp_channel || sdata->local->scanning) { |
| 1660 | mutex_unlock(&sdata->local->mtx); |
| 1661 | goto out; |
| 1662 | } |
| 1663 | |
Joe Perches | e87cc47 | 2012-05-13 21:56:26 +0000 | [diff] [blame] | 1664 | if (beacon) |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 1665 | mlme_dbg_ratelimited(sdata, |
| 1666 | "detected beacon loss from AP - sending probe request\n"); |
| 1667 | |
Holger Schurig | 6efb71b | 2012-05-15 15:38:59 +0200 | [diff] [blame] | 1668 | ieee80211_cqm_rssi_notify(&sdata->vif, |
| 1669 | NL80211_CQM_RSSI_BEACON_LOSS_EVENT, GFP_KERNEL); |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1670 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1671 | /* |
| 1672 | * The driver/our work has already reported this event or the |
| 1673 | * connection monitoring has kicked in and we have already sent |
| 1674 | * a probe request. Or maybe the AP died and the driver keeps |
| 1675 | * reporting until we disassociate... |
| 1676 | * |
| 1677 | * In either case we have to ignore the current call to this |
| 1678 | * function (except for setting the correct probe reason bit) |
| 1679 | * because otherwise we would reset the timer every time and |
| 1680 | * never check whether we received a probe response! |
| 1681 | */ |
| 1682 | if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL | |
| 1683 | IEEE80211_STA_CONNECTION_POLL)) |
| 1684 | already = true; |
| 1685 | |
| 1686 | if (beacon) |
| 1687 | ifmgd->flags |= IEEE80211_STA_BEACON_POLL; |
| 1688 | else |
| 1689 | ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL; |
| 1690 | |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 1691 | mutex_unlock(&sdata->local->mtx); |
| 1692 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1693 | if (already) |
| 1694 | goto out; |
| 1695 | |
Johannes Berg | 4e75184 | 2009-06-10 15:16:52 +0200 | [diff] [blame] | 1696 | mutex_lock(&sdata->local->iflist_mtx); |
| 1697 | ieee80211_recalc_ps(sdata->local, -1); |
| 1698 | mutex_unlock(&sdata->local->iflist_mtx); |
| 1699 | |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 1700 | ifmgd->probe_send_count = 0; |
| 1701 | ieee80211_mgd_probe_ap_send(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1702 | out: |
| 1703 | mutex_unlock(&ifmgd->mtx); |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1704 | } |
| 1705 | |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 1706 | struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw, |
| 1707 | struct ieee80211_vif *vif) |
| 1708 | { |
| 1709 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 1710 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Eliad Peller | d9b3b28 | 2012-06-28 15:03:13 +0300 | [diff] [blame] | 1711 | struct cfg80211_bss *cbss; |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 1712 | struct sk_buff *skb; |
| 1713 | const u8 *ssid; |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 1714 | int ssid_len; |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 1715 | |
| 1716 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) |
| 1717 | return NULL; |
| 1718 | |
| 1719 | ASSERT_MGD_MTX(ifmgd); |
| 1720 | |
Eliad Peller | d9b3b28 | 2012-06-28 15:03:13 +0300 | [diff] [blame] | 1721 | if (ifmgd->associated) |
| 1722 | cbss = ifmgd->associated; |
| 1723 | else if (ifmgd->auth_data) |
| 1724 | cbss = ifmgd->auth_data->bss; |
| 1725 | else if (ifmgd->assoc_data) |
| 1726 | cbss = ifmgd->assoc_data->bss; |
| 1727 | else |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 1728 | return NULL; |
| 1729 | |
Eliad Peller | d9b3b28 | 2012-06-28 15:03:13 +0300 | [diff] [blame] | 1730 | ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID); |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 1731 | if (WARN_ON_ONCE(ssid == NULL)) |
| 1732 | ssid_len = 0; |
| 1733 | else |
| 1734 | ssid_len = ssid[1]; |
| 1735 | |
Eliad Peller | d9b3b28 | 2012-06-28 15:03:13 +0300 | [diff] [blame] | 1736 | skb = ieee80211_build_probe_req(sdata, cbss->bssid, |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1737 | (u32) -1, cbss->channel, |
Johannes Berg | 6b77863 | 2012-07-23 14:53:27 +0200 | [diff] [blame] | 1738 | ssid + 2, ssid_len, |
Johannes Berg | 85a237f | 2011-07-18 18:08:36 +0200 | [diff] [blame] | 1739 | NULL, 0, true); |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 1740 | |
| 1741 | return skb; |
| 1742 | } |
| 1743 | EXPORT_SYMBOL(ieee80211_ap_probereq_get); |
| 1744 | |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 1745 | static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata, |
| 1746 | bool transmit_frame) |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1747 | { |
| 1748 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 1749 | struct ieee80211_local *local = sdata->local; |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 1750 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1751 | |
| 1752 | mutex_lock(&ifmgd->mtx); |
| 1753 | if (!ifmgd->associated) { |
| 1754 | mutex_unlock(&ifmgd->mtx); |
| 1755 | return; |
| 1756 | } |
| 1757 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 1758 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
| 1759 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 1760 | transmit_frame, frame_buf); |
| 1761 | ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1762 | mutex_unlock(&ifmgd->mtx); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 1763 | |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1764 | /* |
| 1765 | * must be outside lock due to cfg80211, |
| 1766 | * but that's not a problem. |
| 1767 | */ |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 1768 | cfg80211_send_deauth(sdata->dev, frame_buf, IEEE80211_DEAUTH_FRAME_LEN); |
Felix Fietkau | fcac4fb | 2011-11-16 13:34:55 +0100 | [diff] [blame] | 1769 | |
| 1770 | mutex_lock(&local->mtx); |
| 1771 | ieee80211_recalc_idle(local); |
| 1772 | mutex_unlock(&local->mtx); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1773 | } |
| 1774 | |
Johannes Berg | cc74c0c | 2012-08-01 16:49:34 +0200 | [diff] [blame] | 1775 | static void ieee80211_beacon_connection_loss_work(struct work_struct *work) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1776 | { |
| 1777 | struct ieee80211_sub_if_data *sdata = |
| 1778 | container_of(work, struct ieee80211_sub_if_data, |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1779 | u.mgd.beacon_connection_loss_work); |
Paul Stewart | a85e1d5 | 2011-12-09 11:01:49 -0800 | [diff] [blame] | 1780 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 1781 | struct sta_info *sta; |
| 1782 | |
| 1783 | if (ifmgd->associated) { |
Mohammed Shafi Shajakhan | 30fa904 | 2011-12-27 18:54:07 +0530 | [diff] [blame] | 1784 | rcu_read_lock(); |
Paul Stewart | a85e1d5 | 2011-12-09 11:01:49 -0800 | [diff] [blame] | 1785 | sta = sta_info_get(sdata, ifmgd->bssid); |
| 1786 | if (sta) |
| 1787 | sta->beacon_loss_count++; |
Mohammed Shafi Shajakhan | 30fa904 | 2011-12-27 18:54:07 +0530 | [diff] [blame] | 1788 | rcu_read_unlock(); |
Paul Stewart | a85e1d5 | 2011-12-09 11:01:49 -0800 | [diff] [blame] | 1789 | } |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1790 | |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 1791 | if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR) { |
| 1792 | sdata_info(sdata, "Connection to AP %pM lost\n", |
| 1793 | ifmgd->bssid); |
| 1794 | __ieee80211_disconnect(sdata, false); |
| 1795 | } else { |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1796 | ieee80211_mgd_probe_ap(sdata, true); |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 1797 | } |
| 1798 | } |
| 1799 | |
| 1800 | static void ieee80211_csa_connection_drop_work(struct work_struct *work) |
| 1801 | { |
| 1802 | struct ieee80211_sub_if_data *sdata = |
| 1803 | container_of(work, struct ieee80211_sub_if_data, |
| 1804 | u.mgd.csa_connection_drop_work); |
| 1805 | |
| 1806 | ieee80211_wake_queues_by_reason(&sdata->local->hw, |
| 1807 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 1808 | __ieee80211_disconnect(sdata, true); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1809 | } |
| 1810 | |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1811 | void ieee80211_beacon_loss(struct ieee80211_vif *vif) |
| 1812 | { |
| 1813 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1814 | struct ieee80211_hw *hw = &sdata->local->hw; |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1815 | |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 1816 | trace_api_beacon_loss(sdata); |
| 1817 | |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1818 | WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR); |
| 1819 | ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work); |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1820 | } |
| 1821 | EXPORT_SYMBOL(ieee80211_beacon_loss); |
| 1822 | |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1823 | void ieee80211_connection_loss(struct ieee80211_vif *vif) |
| 1824 | { |
| 1825 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 1826 | struct ieee80211_hw *hw = &sdata->local->hw; |
| 1827 | |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 1828 | trace_api_connection_loss(sdata); |
| 1829 | |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1830 | WARN_ON(!(hw->flags & IEEE80211_HW_CONNECTION_MONITOR)); |
| 1831 | ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work); |
| 1832 | } |
| 1833 | EXPORT_SYMBOL(ieee80211_connection_loss); |
| 1834 | |
| 1835 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1836 | static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata, |
| 1837 | bool assoc) |
| 1838 | { |
| 1839 | struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data; |
| 1840 | |
| 1841 | lockdep_assert_held(&sdata->u.mgd.mtx); |
| 1842 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1843 | if (!assoc) { |
| 1844 | sta_info_destroy_addr(sdata, auth_data->bss->bssid); |
| 1845 | |
| 1846 | memset(sdata->u.mgd.bssid, 0, ETH_ALEN); |
| 1847 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1848 | ieee80211_vif_release_channel(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1849 | } |
| 1850 | |
| 1851 | cfg80211_put_bss(auth_data->bss); |
| 1852 | kfree(auth_data); |
| 1853 | sdata->u.mgd.auth_data = NULL; |
| 1854 | } |
| 1855 | |
| 1856 | static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata, |
| 1857 | struct ieee80211_mgmt *mgmt, size_t len) |
| 1858 | { |
| 1859 | struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data; |
| 1860 | u8 *pos; |
| 1861 | struct ieee802_11_elems elems; |
| 1862 | |
| 1863 | pos = mgmt->u.auth.variable; |
| 1864 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); |
| 1865 | if (!elems.challenge) |
| 1866 | return; |
| 1867 | auth_data->expected_transaction = 4; |
Johannes Berg | a1845fc | 2012-06-27 13:18:36 +0200 | [diff] [blame] | 1868 | drv_mgd_prepare_tx(sdata->local, sdata); |
Jouni Malinen | 700e8ea | 2012-09-30 19:29:37 +0300 | [diff] [blame] | 1869 | ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0, |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1870 | elems.challenge - 2, elems.challenge_len + 2, |
| 1871 | auth_data->bss->bssid, auth_data->bss->bssid, |
| 1872 | auth_data->key, auth_data->key_len, |
| 1873 | auth_data->key_idx); |
| 1874 | } |
| 1875 | |
| 1876 | static enum rx_mgmt_action __must_check |
| 1877 | ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata, |
| 1878 | struct ieee80211_mgmt *mgmt, size_t len) |
| 1879 | { |
| 1880 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 1881 | u8 bssid[ETH_ALEN]; |
| 1882 | u16 auth_alg, auth_transaction, status_code; |
| 1883 | struct sta_info *sta; |
| 1884 | |
| 1885 | lockdep_assert_held(&ifmgd->mtx); |
| 1886 | |
| 1887 | if (len < 24 + 6) |
| 1888 | return RX_MGMT_NONE; |
| 1889 | |
| 1890 | if (!ifmgd->auth_data || ifmgd->auth_data->done) |
| 1891 | return RX_MGMT_NONE; |
| 1892 | |
| 1893 | memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN); |
| 1894 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 1895 | if (!ether_addr_equal(bssid, mgmt->bssid)) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1896 | return RX_MGMT_NONE; |
| 1897 | |
| 1898 | auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); |
| 1899 | auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); |
| 1900 | status_code = le16_to_cpu(mgmt->u.auth.status_code); |
| 1901 | |
| 1902 | if (auth_alg != ifmgd->auth_data->algorithm || |
Jouni Malinen | 0f4126e | 2012-09-30 19:29:38 +0300 | [diff] [blame] | 1903 | auth_transaction != ifmgd->auth_data->expected_transaction) { |
| 1904 | sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n", |
| 1905 | mgmt->sa, auth_alg, ifmgd->auth_data->algorithm, |
| 1906 | auth_transaction, |
| 1907 | ifmgd->auth_data->expected_transaction); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1908 | return RX_MGMT_NONE; |
Jouni Malinen | 0f4126e | 2012-09-30 19:29:38 +0300 | [diff] [blame] | 1909 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1910 | |
| 1911 | if (status_code != WLAN_STATUS_SUCCESS) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 1912 | sdata_info(sdata, "%pM denied authentication (status %d)\n", |
| 1913 | mgmt->sa, status_code); |
Eliad Peller | dac211e | 2012-05-13 18:07:04 +0300 | [diff] [blame] | 1914 | ieee80211_destroy_auth_data(sdata, false); |
| 1915 | return RX_MGMT_CFG80211_RX_AUTH; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | switch (ifmgd->auth_data->algorithm) { |
| 1919 | case WLAN_AUTH_OPEN: |
| 1920 | case WLAN_AUTH_LEAP: |
| 1921 | case WLAN_AUTH_FT: |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 1922 | case WLAN_AUTH_SAE: |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1923 | break; |
| 1924 | case WLAN_AUTH_SHARED_KEY: |
| 1925 | if (ifmgd->auth_data->expected_transaction != 4) { |
| 1926 | ieee80211_auth_challenge(sdata, mgmt, len); |
| 1927 | /* need another frame */ |
| 1928 | return RX_MGMT_NONE; |
| 1929 | } |
| 1930 | break; |
| 1931 | default: |
| 1932 | WARN_ONCE(1, "invalid auth alg %d", |
| 1933 | ifmgd->auth_data->algorithm); |
| 1934 | return RX_MGMT_NONE; |
| 1935 | } |
| 1936 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 1937 | sdata_info(sdata, "authenticated\n"); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1938 | ifmgd->auth_data->done = true; |
| 1939 | ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC; |
| 1940 | run_again(ifmgd, ifmgd->auth_data->timeout); |
| 1941 | |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 1942 | if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE && |
| 1943 | ifmgd->auth_data->expected_transaction != 2) { |
| 1944 | /* |
| 1945 | * Report auth frame to user space for processing since another |
| 1946 | * round of Authentication frames is still needed. |
| 1947 | */ |
| 1948 | return RX_MGMT_CFG80211_RX_AUTH; |
| 1949 | } |
| 1950 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1951 | /* move station state to auth */ |
| 1952 | mutex_lock(&sdata->local->sta_mtx); |
| 1953 | sta = sta_info_get(sdata, bssid); |
| 1954 | if (!sta) { |
| 1955 | WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid); |
| 1956 | goto out_err; |
| 1957 | } |
| 1958 | if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 1959 | sdata_info(sdata, "failed moving %pM to auth\n", bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1960 | goto out_err; |
| 1961 | } |
| 1962 | mutex_unlock(&sdata->local->sta_mtx); |
| 1963 | |
| 1964 | return RX_MGMT_CFG80211_RX_AUTH; |
| 1965 | out_err: |
| 1966 | mutex_unlock(&sdata->local->sta_mtx); |
| 1967 | /* ignore frame -- wait for timeout */ |
| 1968 | return RX_MGMT_NONE; |
| 1969 | } |
| 1970 | |
| 1971 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1972 | static enum rx_mgmt_action __must_check |
| 1973 | ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1974 | struct ieee80211_mgmt *mgmt, size_t len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1975 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1976 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1977 | const u8 *bssid = NULL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1978 | u16 reason_code; |
| 1979 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1980 | lockdep_assert_held(&ifmgd->mtx); |
| 1981 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1982 | if (len < 24 + 2) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1983 | return RX_MGMT_NONE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1984 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1985 | if (!ifmgd->associated || |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 1986 | !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1987 | return RX_MGMT_NONE; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1988 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 1989 | bssid = ifmgd->associated->bssid; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1990 | |
| 1991 | reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); |
| 1992 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 1993 | sdata_info(sdata, "deauthenticated from %pM (Reason: %u)\n", |
| 1994 | bssid, reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1995 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 1996 | ieee80211_set_disassoc(sdata, 0, 0, false, NULL); |
| 1997 | |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 1998 | mutex_lock(&sdata->local->mtx); |
Johannes Berg | 63f170e | 2009-12-23 13:15:33 +0100 | [diff] [blame] | 1999 | ieee80211_recalc_idle(sdata->local); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 2000 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2001 | |
| 2002 | return RX_MGMT_CFG80211_DEAUTH; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2006 | static enum rx_mgmt_action __must_check |
| 2007 | ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata, |
| 2008 | struct ieee80211_mgmt *mgmt, size_t len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2009 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2010 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2011 | u16 reason_code; |
| 2012 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2013 | lockdep_assert_held(&ifmgd->mtx); |
| 2014 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 2015 | if (len < 24 + 2) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2016 | return RX_MGMT_NONE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2017 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2018 | if (!ifmgd->associated || |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2019 | !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2020 | return RX_MGMT_NONE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2021 | |
| 2022 | reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); |
| 2023 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2024 | sdata_info(sdata, "disassociated from %pM (Reason: %u)\n", |
| 2025 | mgmt->sa, reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2026 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2027 | ieee80211_set_disassoc(sdata, 0, 0, false, NULL); |
| 2028 | |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 2029 | mutex_lock(&sdata->local->mtx); |
Johannes Berg | bc83b68 | 2009-11-29 12:19:06 +0100 | [diff] [blame] | 2030 | ieee80211_recalc_idle(sdata->local); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 2031 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2032 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2033 | return RX_MGMT_CFG80211_DISASSOC; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2034 | } |
| 2035 | |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 2036 | static void ieee80211_get_rates(struct ieee80211_supported_band *sband, |
| 2037 | u8 *supp_rates, unsigned int supp_rates_len, |
| 2038 | u32 *rates, u32 *basic_rates, |
| 2039 | bool *have_higher_than_11mbit, |
| 2040 | int *min_rate, int *min_rate_index) |
| 2041 | { |
| 2042 | int i, j; |
| 2043 | |
| 2044 | for (i = 0; i < supp_rates_len; i++) { |
| 2045 | int rate = (supp_rates[i] & 0x7f) * 5; |
| 2046 | bool is_basic = !!(supp_rates[i] & 0x80); |
| 2047 | |
| 2048 | if (rate > 110) |
| 2049 | *have_higher_than_11mbit = true; |
| 2050 | |
| 2051 | /* |
| 2052 | * BSS_MEMBERSHIP_SELECTOR_HT_PHY is defined in 802.11n-2009 |
| 2053 | * 7.3.2.2 as a magic value instead of a rate. Hence, skip it. |
| 2054 | * |
| 2055 | * Note: Even through the membership selector and the basic |
| 2056 | * rate flag share the same bit, they are not exactly |
| 2057 | * the same. |
| 2058 | */ |
| 2059 | if (!!(supp_rates[i] & 0x80) && |
| 2060 | (supp_rates[i] & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY) |
| 2061 | continue; |
| 2062 | |
| 2063 | for (j = 0; j < sband->n_bitrates; j++) { |
| 2064 | if (sband->bitrates[j].bitrate == rate) { |
| 2065 | *rates |= BIT(j); |
| 2066 | if (is_basic) |
| 2067 | *basic_rates |= BIT(j); |
| 2068 | if (rate < *min_rate) { |
| 2069 | *min_rate = rate; |
| 2070 | *min_rate_index = j; |
| 2071 | } |
| 2072 | break; |
| 2073 | } |
| 2074 | } |
| 2075 | } |
| 2076 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2077 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2078 | static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata, |
| 2079 | bool assoc) |
| 2080 | { |
| 2081 | struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data; |
| 2082 | |
| 2083 | lockdep_assert_held(&sdata->u.mgd.mtx); |
| 2084 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2085 | if (!assoc) { |
| 2086 | sta_info_destroy_addr(sdata, assoc_data->bss->bssid); |
| 2087 | |
| 2088 | memset(sdata->u.mgd.bssid, 0, ETH_ALEN); |
| 2089 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2090 | ieee80211_vif_release_channel(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2091 | } |
| 2092 | |
| 2093 | kfree(assoc_data); |
| 2094 | sdata->u.mgd.assoc_data = NULL; |
| 2095 | } |
| 2096 | |
| 2097 | static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata, |
| 2098 | struct cfg80211_bss *cbss, |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2099 | struct ieee80211_mgmt *mgmt, size_t len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2100 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2101 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2102 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2103 | struct ieee80211_supported_band *sband; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2104 | struct sta_info *sta; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2105 | u8 *pos; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2106 | u16 capab_info, aid; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2107 | struct ieee802_11_elems elems; |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 2108 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2109 | u32 changed = 0; |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 2110 | int err; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2111 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2112 | /* AssocResp and ReassocResp have identical structure */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2113 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2114 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2115 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2116 | |
Johannes Berg | 1dd84aa | 2007-10-10 12:03:41 +0200 | [diff] [blame] | 2117 | if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2118 | sdata_info(sdata, "invalid AID value 0x%x; bits 15:14 not set\n", |
| 2119 | aid); |
Johannes Berg | 1dd84aa | 2007-10-10 12:03:41 +0200 | [diff] [blame] | 2120 | aid &= ~(BIT(15) | BIT(14)); |
| 2121 | |
Johannes Berg | 05cb910 | 2011-10-28 11:59:47 +0200 | [diff] [blame] | 2122 | ifmgd->broken_ap = false; |
| 2123 | |
| 2124 | if (aid == 0 || aid > IEEE80211_MAX_AID) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2125 | sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n", |
| 2126 | aid); |
Johannes Berg | 05cb910 | 2011-10-28 11:59:47 +0200 | [diff] [blame] | 2127 | aid = 0; |
| 2128 | ifmgd->broken_ap = true; |
| 2129 | } |
| 2130 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2131 | pos = mgmt->u.assoc_resp.variable; |
| 2132 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); |
| 2133 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2134 | if (!elems.supp_rates) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2135 | sdata_info(sdata, "no SuppRates element in AssocResp\n"); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2136 | return false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2137 | } |
| 2138 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2139 | ifmgd->aid = aid; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2140 | |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 2141 | mutex_lock(&sdata->local->sta_mtx); |
| 2142 | /* |
| 2143 | * station info was already allocated and inserted before |
| 2144 | * the association and should be available to us |
| 2145 | */ |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 2146 | sta = sta_info_get(sdata, cbss->bssid); |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 2147 | if (WARN_ON(!sta)) { |
| 2148 | mutex_unlock(&sdata->local->sta_mtx); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2149 | return false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2150 | } |
| 2151 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2152 | sband = local->hw.wiphy->bands[ieee80211_get_sdata_band(sdata)]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2153 | |
Johannes Berg | ab1faea | 2009-07-01 21:41:17 +0200 | [diff] [blame] | 2154 | if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 2155 | ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband, |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 2156 | elems.ht_cap_elem, &sta->sta.ht_cap); |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2157 | |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 2158 | sta->supports_40mhz = |
| 2159 | sta->sta.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 2160 | |
Mahesh Palivela | 818255e | 2012-10-10 11:33:04 +0000 | [diff] [blame] | 2161 | if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
| 2162 | ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband, |
| 2163 | elems.vht_cap_elem, |
| 2164 | &sta->sta.vht_cap); |
| 2165 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 2166 | rate_control_rate_init(sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2167 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2168 | if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 2169 | set_sta_flag(sta, WLAN_STA_MFP); |
Jouni Malinen | 5394af4 | 2009-01-08 13:31:59 +0200 | [diff] [blame] | 2170 | |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 2171 | if (elems.wmm_param) |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 2172 | set_sta_flag(sta, WLAN_STA_WME); |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 2173 | |
Johannes Berg | c898787 | 2012-01-20 13:55:17 +0100 | [diff] [blame] | 2174 | err = sta_info_move_state(sta, IEEE80211_STA_AUTH); |
| 2175 | if (!err) |
| 2176 | err = sta_info_move_state(sta, IEEE80211_STA_ASSOC); |
| 2177 | if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT)) |
| 2178 | err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED); |
| 2179 | if (err) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2180 | sdata_info(sdata, |
| 2181 | "failed to move station %pM to desired state\n", |
| 2182 | sta->sta.addr); |
Johannes Berg | c898787 | 2012-01-20 13:55:17 +0100 | [diff] [blame] | 2183 | WARN_ON(__sta_info_destroy(sta)); |
| 2184 | mutex_unlock(&sdata->local->sta_mtx); |
| 2185 | return false; |
| 2186 | } |
| 2187 | |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 2188 | mutex_unlock(&sdata->local->sta_mtx); |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 2189 | |
Juuso Oikarinen | f2176d7 | 2010-09-28 14:39:32 +0300 | [diff] [blame] | 2190 | /* |
| 2191 | * Always handle WMM once after association regardless |
| 2192 | * of the first value the AP uses. Setting -1 here has |
| 2193 | * that effect because the AP values is an unsigned |
| 2194 | * 4-bit value. |
| 2195 | */ |
| 2196 | ifmgd->wmm_last_param_set = -1; |
| 2197 | |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 2198 | if (elems.wmm_param) |
Johannes Berg | 4ced3f7 | 2010-07-19 16:39:04 +0200 | [diff] [blame] | 2199 | ieee80211_sta_wmm_params(local, sdata, elems.wmm_param, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2200 | elems.wmm_param_len); |
Johannes Berg | aa837e1 | 2009-05-07 16:16:24 +0200 | [diff] [blame] | 2201 | else |
Johannes Berg | 3abead5 | 2012-03-02 15:56:59 +0100 | [diff] [blame] | 2202 | ieee80211_set_wmm_default(sdata, false); |
| 2203 | changed |= BSS_CHANGED_QOS; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2204 | |
Johannes Berg | 074d46d | 2012-03-15 19:45:16 +0100 | [diff] [blame] | 2205 | if (elems.ht_operation && elems.wmm_param && |
Johannes Berg | ab1faea | 2009-07-01 21:41:17 +0200 | [diff] [blame] | 2206 | !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 2207 | changed |= ieee80211_config_ht_tx(sdata, elems.ht_operation, |
| 2208 | cbss->bssid, false); |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2209 | |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 2210 | /* set AID and assoc capability, |
| 2211 | * ieee80211_set_associated() will tell the driver */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2212 | bss_conf->aid = aid; |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 2213 | bss_conf->assoc_capability = capab_info; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2214 | ieee80211_set_associated(sdata, cbss, changed); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2215 | |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 2216 | /* |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 2217 | * If we're using 4-addr mode, let the AP know that we're |
| 2218 | * doing so, so that it can create the STA VLAN on its side |
| 2219 | */ |
| 2220 | if (ifmgd->use_4addr) |
| 2221 | ieee80211_send_4addr_nullfunc(local, sdata); |
| 2222 | |
| 2223 | /* |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2224 | * Start timer to probe the connection to the AP now. |
| 2225 | * Also start the timer that will detect beacon loss. |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 2226 | */ |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2227 | ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt); |
Luis R. Rodriguez | d3a910a | 2010-09-16 15:12:32 -0400 | [diff] [blame] | 2228 | ieee80211_sta_reset_beacon_monitor(sdata); |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 2229 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2230 | return true; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2231 | } |
| 2232 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2233 | static enum rx_mgmt_action __must_check |
| 2234 | ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata, |
| 2235 | struct ieee80211_mgmt *mgmt, size_t len, |
| 2236 | struct cfg80211_bss **bss) |
| 2237 | { |
| 2238 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 2239 | struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; |
| 2240 | u16 capab_info, status_code, aid; |
| 2241 | struct ieee802_11_elems elems; |
| 2242 | u8 *pos; |
| 2243 | bool reassoc; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2244 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2245 | lockdep_assert_held(&ifmgd->mtx); |
| 2246 | |
| 2247 | if (!assoc_data) |
| 2248 | return RX_MGMT_NONE; |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2249 | if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid)) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2250 | return RX_MGMT_NONE; |
| 2251 | |
| 2252 | /* |
| 2253 | * AssocResp and ReassocResp have identical structure, so process both |
| 2254 | * of them in this function. |
| 2255 | */ |
| 2256 | |
| 2257 | if (len < 24 + 6) |
| 2258 | return RX_MGMT_NONE; |
| 2259 | |
| 2260 | reassoc = ieee80211_is_reassoc_req(mgmt->frame_control); |
| 2261 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); |
| 2262 | status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); |
| 2263 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); |
| 2264 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2265 | sdata_info(sdata, |
| 2266 | "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n", |
| 2267 | reassoc ? "Rea" : "A", mgmt->sa, |
| 2268 | capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14)))); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2269 | |
| 2270 | pos = mgmt->u.assoc_resp.variable; |
| 2271 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); |
| 2272 | |
| 2273 | if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY && |
| 2274 | elems.timeout_int && elems.timeout_int_len == 5 && |
| 2275 | elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) { |
| 2276 | u32 tu, ms; |
| 2277 | tu = get_unaligned_le32(elems.timeout_int + 1); |
| 2278 | ms = tu * 1024 / 1000; |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2279 | sdata_info(sdata, |
| 2280 | "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n", |
| 2281 | mgmt->sa, tu, ms); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2282 | assoc_data->timeout = jiffies + msecs_to_jiffies(ms); |
| 2283 | if (ms > IEEE80211_ASSOC_TIMEOUT) |
| 2284 | run_again(ifmgd, assoc_data->timeout); |
| 2285 | return RX_MGMT_NONE; |
| 2286 | } |
| 2287 | |
| 2288 | *bss = assoc_data->bss; |
| 2289 | |
| 2290 | if (status_code != WLAN_STATUS_SUCCESS) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2291 | sdata_info(sdata, "%pM denied association (code=%d)\n", |
| 2292 | mgmt->sa, status_code); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2293 | ieee80211_destroy_assoc_data(sdata, false); |
| 2294 | } else { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2295 | if (!ieee80211_assoc_success(sdata, *bss, mgmt, len)) { |
| 2296 | /* oops -- internal error -- send timeout for now */ |
Eliad Peller | 10a9109 | 2012-07-02 14:42:03 +0300 | [diff] [blame] | 2297 | ieee80211_destroy_assoc_data(sdata, false); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2298 | cfg80211_put_bss(*bss); |
| 2299 | return RX_MGMT_CFG80211_ASSOC_TIMEOUT; |
| 2300 | } |
John W. Linville | 635d999 | 2012-07-09 16:34:34 -0400 | [diff] [blame] | 2301 | sdata_info(sdata, "associated\n"); |
Johannes Berg | 79ebfb8 | 2012-02-20 14:19:58 +0100 | [diff] [blame] | 2302 | |
| 2303 | /* |
| 2304 | * destroy assoc_data afterwards, as otherwise an idle |
| 2305 | * recalc after assoc_data is NULL but before associated |
| 2306 | * is set can cause the interface to go idle |
| 2307 | */ |
| 2308 | ieee80211_destroy_assoc_data(sdata, true); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | return RX_MGMT_CFG80211_RX_ASSOC; |
| 2312 | } |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2313 | static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2314 | struct ieee80211_mgmt *mgmt, |
| 2315 | size_t len, |
| 2316 | struct ieee80211_rx_status *rx_status, |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 2317 | struct ieee802_11_elems *elems, |
| 2318 | bool beacon) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2319 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2320 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 2321 | int freq; |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 2322 | struct ieee80211_bss *bss; |
Johannes Berg | fab7d4a | 2008-03-16 18:42:44 +0100 | [diff] [blame] | 2323 | struct ieee80211_channel *channel; |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 2324 | bool need_ps = false; |
| 2325 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2326 | if (sdata->u.mgd.associated && |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2327 | ether_addr_equal(mgmt->bssid, sdata->u.mgd.associated->bssid)) { |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 2328 | bss = (void *)sdata->u.mgd.associated->priv; |
| 2329 | /* not previously set so we may need to recalc */ |
| 2330 | need_ps = !bss->dtim_period; |
| 2331 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2332 | |
Johannes Berg | 5bda617 | 2008-09-08 11:05:10 +0200 | [diff] [blame] | 2333 | if (elems->ds_params && elems->ds_params_len == 1) |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 2334 | freq = ieee80211_channel_to_frequency(elems->ds_params[0], |
| 2335 | rx_status->band); |
Johannes Berg | 5bda617 | 2008-09-08 11:05:10 +0200 | [diff] [blame] | 2336 | else |
| 2337 | freq = rx_status->freq; |
| 2338 | |
| 2339 | channel = ieee80211_get_channel(local->hw.wiphy, freq); |
| 2340 | |
| 2341 | if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) |
| 2342 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2343 | |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 2344 | bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2345 | channel, beacon); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2346 | if (bss) |
| 2347 | ieee80211_rx_bss_put(local, bss); |
| 2348 | |
| 2349 | if (!sdata->u.mgd.associated) |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 2350 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2351 | |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 2352 | if (need_ps) { |
| 2353 | mutex_lock(&local->iflist_mtx); |
| 2354 | ieee80211_recalc_ps(local, -1); |
| 2355 | mutex_unlock(&local->iflist_mtx); |
| 2356 | } |
| 2357 | |
Johannes Berg | 5bc1420 | 2012-08-01 16:13:02 +0200 | [diff] [blame] | 2358 | if (elems->ch_switch_ie && |
| 2359 | memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid, ETH_ALEN) == 0) |
| 2360 | ieee80211_sta_process_chanswitch(sdata, elems->ch_switch_ie, |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 2361 | bss, rx_status->mactime); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2365 | static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2366 | struct sk_buff *skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2367 | { |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2368 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 2369 | struct ieee80211_if_managed *ifmgd; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2370 | struct ieee80211_rx_status *rx_status = (void *) skb->cb; |
| 2371 | size_t baselen, len = skb->len; |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2372 | struct ieee802_11_elems elems; |
| 2373 | |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 2374 | ifmgd = &sdata->u.mgd; |
| 2375 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2376 | ASSERT_MGD_MTX(ifmgd); |
| 2377 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2378 | if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) |
Tomas Winkler | 8e7cdbb | 2008-08-03 14:32:01 +0300 | [diff] [blame] | 2379 | return; /* ignore ProbeResp to foreign address */ |
| 2380 | |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2381 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; |
| 2382 | if (baselen > len) |
| 2383 | return; |
| 2384 | |
| 2385 | ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, |
| 2386 | &elems); |
| 2387 | |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 2388 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false); |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 2389 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2390 | if (ifmgd->associated && |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2391 | ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2392 | ieee80211_reset_ap_probe(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2393 | |
| 2394 | if (ifmgd->auth_data && !ifmgd->auth_data->bss->proberesp_ies && |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2395 | ether_addr_equal(mgmt->bssid, ifmgd->auth_data->bss->bssid)) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2396 | /* got probe response, continue with auth */ |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2397 | sdata_info(sdata, "direct probe responded\n"); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2398 | ifmgd->auth_data->tries = 0; |
| 2399 | ifmgd->auth_data->timeout = jiffies; |
| 2400 | run_again(ifmgd, ifmgd->auth_data->timeout); |
| 2401 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2402 | } |
| 2403 | |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 2404 | /* |
| 2405 | * This is the canonical list of information elements we care about, |
| 2406 | * the filter code also gives us all changes to the Microsoft OUI |
| 2407 | * (00:50:F2) vendor IE which is used for WMM which we need to track. |
| 2408 | * |
| 2409 | * We implement beacon filtering in software since that means we can |
| 2410 | * avoid processing the frame here and in cfg80211, and userspace |
| 2411 | * will not be able to tell whether the hardware supports it or not. |
| 2412 | * |
| 2413 | * XXX: This list needs to be dynamic -- userspace needs to be able to |
| 2414 | * add items it requires. It also needs to be able to tell us to |
| 2415 | * look out for other vendor IEs. |
| 2416 | */ |
| 2417 | static const u64 care_about_ies = |
Johannes Berg | 1d4df3a | 2009-04-22 11:25:43 +0200 | [diff] [blame] | 2418 | (1ULL << WLAN_EID_COUNTRY) | |
| 2419 | (1ULL << WLAN_EID_ERP_INFO) | |
| 2420 | (1ULL << WLAN_EID_CHANNEL_SWITCH) | |
| 2421 | (1ULL << WLAN_EID_PWR_CONSTRAINT) | |
| 2422 | (1ULL << WLAN_EID_HT_CAPABILITY) | |
Johannes Berg | 074d46d | 2012-03-15 19:45:16 +0100 | [diff] [blame] | 2423 | (1ULL << WLAN_EID_HT_OPERATION); |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 2424 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2425 | static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2426 | struct ieee80211_mgmt *mgmt, |
| 2427 | size_t len, |
| 2428 | struct ieee80211_rx_status *rx_status) |
| 2429 | { |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 2430 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 2431 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2432 | size_t baselen; |
| 2433 | struct ieee802_11_elems elems; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2434 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2435 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 2436 | struct ieee80211_channel *chan; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2437 | u32 changed = 0; |
Rami Rosen | f87ad63 | 2012-10-25 10:16:23 +0200 | [diff] [blame] | 2438 | bool erp_valid; |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2439 | u8 erp_value = 0; |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 2440 | u32 ncrc; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2441 | u8 *bssid; |
| 2442 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2443 | lockdep_assert_held(&ifmgd->mtx); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2444 | |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2445 | /* Process beacon from the current BSS */ |
| 2446 | baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; |
| 2447 | if (baselen > len) |
| 2448 | return; |
| 2449 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2450 | rcu_read_lock(); |
| 2451 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 2452 | if (!chanctx_conf) { |
| 2453 | rcu_read_unlock(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2454 | return; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2455 | } |
| 2456 | |
| 2457 | if (rx_status->freq != chanctx_conf->channel->center_freq) { |
| 2458 | rcu_read_unlock(); |
| 2459 | return; |
| 2460 | } |
| 2461 | chan = chanctx_conf->channel; |
| 2462 | rcu_read_unlock(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2463 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2464 | if (ifmgd->assoc_data && !ifmgd->assoc_data->have_beacon && |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2465 | ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2466 | ieee802_11_parse_elems(mgmt->u.beacon.variable, |
| 2467 | len - baselen, &elems); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2468 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2469 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, |
| 2470 | false); |
| 2471 | ifmgd->assoc_data->have_beacon = true; |
| 2472 | ifmgd->assoc_data->sent_assoc = false; |
| 2473 | /* continue assoc process */ |
| 2474 | ifmgd->assoc_data->timeout = jiffies; |
| 2475 | run_again(ifmgd, ifmgd->assoc_data->timeout); |
| 2476 | return; |
| 2477 | } |
| 2478 | |
| 2479 | if (!ifmgd->associated || |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2480 | !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2481 | return; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2482 | bssid = ifmgd->associated->bssid; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2483 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 2484 | /* Track average RSSI from the Beacon frames of the current AP */ |
| 2485 | ifmgd->last_beacon_signal = rx_status->signal; |
| 2486 | if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) { |
| 2487 | ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE; |
Jouni Malinen | 3ba06c6 | 2010-08-27 22:21:13 +0300 | [diff] [blame] | 2488 | ifmgd->ave_beacon_signal = rx_status->signal * 16; |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 2489 | ifmgd->last_cqm_event_signal = 0; |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 2490 | ifmgd->count_beacon_signal = 1; |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 2491 | ifmgd->last_ave_beacon_signal = 0; |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 2492 | } else { |
| 2493 | ifmgd->ave_beacon_signal = |
| 2494 | (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 + |
| 2495 | (16 - IEEE80211_SIGNAL_AVE_WEIGHT) * |
| 2496 | ifmgd->ave_beacon_signal) / 16; |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 2497 | ifmgd->count_beacon_signal++; |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 2498 | } |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 2499 | |
| 2500 | if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold && |
| 2501 | ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) { |
| 2502 | int sig = ifmgd->ave_beacon_signal; |
| 2503 | int last_sig = ifmgd->last_ave_beacon_signal; |
| 2504 | |
| 2505 | /* |
| 2506 | * if signal crosses either of the boundaries, invoke callback |
| 2507 | * with appropriate parameters |
| 2508 | */ |
| 2509 | if (sig > ifmgd->rssi_max_thold && |
| 2510 | (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) { |
| 2511 | ifmgd->last_ave_beacon_signal = sig; |
| 2512 | drv_rssi_callback(local, RSSI_EVENT_HIGH); |
| 2513 | } else if (sig < ifmgd->rssi_min_thold && |
| 2514 | (last_sig >= ifmgd->rssi_max_thold || |
| 2515 | last_sig == 0)) { |
| 2516 | ifmgd->last_ave_beacon_signal = sig; |
| 2517 | drv_rssi_callback(local, RSSI_EVENT_LOW); |
| 2518 | } |
| 2519 | } |
| 2520 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 2521 | if (bss_conf->cqm_rssi_thold && |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 2522 | ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT && |
Johannes Berg | ea08635 | 2012-01-19 09:29:58 +0100 | [diff] [blame] | 2523 | !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) { |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 2524 | int sig = ifmgd->ave_beacon_signal / 16; |
| 2525 | int last_event = ifmgd->last_cqm_event_signal; |
| 2526 | int thold = bss_conf->cqm_rssi_thold; |
| 2527 | int hyst = bss_conf->cqm_rssi_hyst; |
| 2528 | if (sig < thold && |
| 2529 | (last_event == 0 || sig < last_event - hyst)) { |
| 2530 | ifmgd->last_cqm_event_signal = sig; |
| 2531 | ieee80211_cqm_rssi_notify( |
| 2532 | &sdata->vif, |
| 2533 | NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW, |
| 2534 | GFP_KERNEL); |
| 2535 | } else if (sig > thold && |
| 2536 | (last_event == 0 || sig > last_event + hyst)) { |
| 2537 | ifmgd->last_cqm_event_signal = sig; |
| 2538 | ieee80211_cqm_rssi_notify( |
| 2539 | &sdata->vif, |
| 2540 | NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, |
| 2541 | GFP_KERNEL); |
| 2542 | } |
| 2543 | } |
| 2544 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2545 | if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2546 | mlme_dbg_ratelimited(sdata, |
| 2547 | "cancelling probereq poll due to a received beacon\n"); |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 2548 | mutex_lock(&local->mtx); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2549 | ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL; |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 2550 | ieee80211_run_deferred_scan(local); |
| 2551 | mutex_unlock(&local->mtx); |
| 2552 | |
Johannes Berg | 4e75184 | 2009-06-10 15:16:52 +0200 | [diff] [blame] | 2553 | mutex_lock(&local->iflist_mtx); |
| 2554 | ieee80211_recalc_ps(local, -1); |
| 2555 | mutex_unlock(&local->iflist_mtx); |
Jouni Malinen | 9277818 | 2009-05-14 21:15:36 +0300 | [diff] [blame] | 2556 | } |
| 2557 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2558 | /* |
| 2559 | * Push the beacon loss detection into the future since |
| 2560 | * we are processing a beacon from the AP just now. |
| 2561 | */ |
Luis R. Rodriguez | d3a910a | 2010-09-16 15:12:32 -0400 | [diff] [blame] | 2562 | ieee80211_sta_reset_beacon_monitor(sdata); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2563 | |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 2564 | ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4); |
| 2565 | ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable, |
| 2566 | len - baselen, &elems, |
| 2567 | care_about_ies, ncrc); |
| 2568 | |
Vivek Natarajan | 25c9c87 | 2009-03-02 20:20:30 +0530 | [diff] [blame] | 2569 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) { |
Rami Rosen | f87ad63 | 2012-10-25 10:16:23 +0200 | [diff] [blame] | 2570 | bool directed_tim = ieee80211_check_tim(elems.tim, |
| 2571 | elems.tim_len, |
| 2572 | ifmgd->aid); |
Kalle Valo | 1fb3606 | 2009-02-10 17:09:24 +0200 | [diff] [blame] | 2573 | if (directed_tim) { |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 2574 | if (local->hw.conf.dynamic_ps_timeout > 0) { |
Ronald Wahl | 70b12f2 | 2012-03-19 14:37:20 +0100 | [diff] [blame] | 2575 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 2576 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 2577 | ieee80211_hw_config(local, |
| 2578 | IEEE80211_CONF_CHANGE_PS); |
| 2579 | } |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 2580 | ieee80211_send_nullfunc(local, sdata, 0); |
Rajkumar Manoharan | 6f0756a | 2012-03-15 05:50:36 +0530 | [diff] [blame] | 2581 | } else if (!local->pspolling && sdata->u.mgd.powersave) { |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 2582 | local->pspolling = true; |
| 2583 | |
| 2584 | /* |
| 2585 | * Here is assumed that the driver will be |
| 2586 | * able to send ps-poll frame and receive a |
| 2587 | * response even though power save mode is |
| 2588 | * enabled, but some drivers might require |
| 2589 | * to disable power save here. This needs |
| 2590 | * to be investigated. |
| 2591 | */ |
| 2592 | ieee80211_send_pspoll(local, sdata); |
| 2593 | } |
Vivek Natarajan | a97b77b | 2008-12-23 18:39:02 -0800 | [diff] [blame] | 2594 | } |
| 2595 | } |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2596 | |
Juuso Oikarinen | d8ec443 | 2010-10-01 16:02:31 +0300 | [diff] [blame] | 2597 | if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid) |
Jouni Malinen | 3019667 | 2009-05-19 17:01:43 +0300 | [diff] [blame] | 2598 | return; |
| 2599 | ifmgd->beacon_crc = ncrc; |
Juuso Oikarinen | d8ec443 | 2010-10-01 16:02:31 +0300 | [diff] [blame] | 2600 | ifmgd->beacon_crc_valid = true; |
Jouni Malinen | 3019667 | 2009-05-19 17:01:43 +0300 | [diff] [blame] | 2601 | |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 2602 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, |
| 2603 | true); |
| 2604 | |
| 2605 | if (ieee80211_sta_wmm_params(local, sdata, elems.wmm_param, |
| 2606 | elems.wmm_param_len)) |
| 2607 | changed |= BSS_CHANGED_QOS; |
| 2608 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2609 | if (elems.erp_info && elems.erp_info_len >= 1) { |
| 2610 | erp_valid = true; |
| 2611 | erp_value = elems.erp_info[0]; |
| 2612 | } else { |
| 2613 | erp_valid = false; |
John W. Linville | 50c4afb | 2008-04-15 14:09:27 -0400 | [diff] [blame] | 2614 | } |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2615 | changed |= ieee80211_handle_bss_capability(sdata, |
| 2616 | le16_to_cpu(mgmt->u.beacon.capab_info), |
| 2617 | erp_valid, erp_value); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2618 | |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 2619 | |
Johannes Berg | 074d46d | 2012-03-15 19:45:16 +0100 | [diff] [blame] | 2620 | if (elems.ht_cap_elem && elems.ht_operation && elems.wmm_param && |
Johannes Berg | 444e380 | 2012-09-30 17:08:35 +0200 | [diff] [blame] | 2621 | !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 2622 | changed |= ieee80211_config_ht_tx(sdata, elems.ht_operation, |
| 2623 | bssid, true); |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 2624 | |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 2625 | if (elems.country_elem && elems.pwr_constr_elem && |
| 2626 | mgmt->u.probe_resp.capab_info & |
| 2627 | cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT)) |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame^] | 2628 | changed |= ieee80211_handle_pwr_constr(sdata, chan, |
| 2629 | elems.country_elem, |
| 2630 | elems.country_elem_len, |
| 2631 | elems.pwr_constr_elem); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2632 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2633 | ieee80211_bss_info_change_notify(sdata, changed); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2634 | } |
| 2635 | |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 2636 | void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, |
| 2637 | struct sk_buff *skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2638 | { |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2639 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2640 | struct ieee80211_rx_status *rx_status; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2641 | struct ieee80211_mgmt *mgmt; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2642 | struct cfg80211_bss *bss = NULL; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2643 | enum rx_mgmt_action rma = RX_MGMT_NONE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2644 | u16 fc; |
| 2645 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2646 | rx_status = (struct ieee80211_rx_status *) skb->cb; |
| 2647 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 2648 | fc = le16_to_cpu(mgmt->frame_control); |
| 2649 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2650 | mutex_lock(&ifmgd->mtx); |
| 2651 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2652 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 2653 | case IEEE80211_STYPE_BEACON: |
| 2654 | ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status); |
| 2655 | break; |
| 2656 | case IEEE80211_STYPE_PROBE_RESP: |
| 2657 | ieee80211_rx_mgmt_probe_resp(sdata, skb); |
| 2658 | break; |
| 2659 | case IEEE80211_STYPE_AUTH: |
| 2660 | rma = ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len); |
| 2661 | break; |
| 2662 | case IEEE80211_STYPE_DEAUTH: |
| 2663 | rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len); |
| 2664 | break; |
| 2665 | case IEEE80211_STYPE_DISASSOC: |
| 2666 | rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len); |
| 2667 | break; |
| 2668 | case IEEE80211_STYPE_ASSOC_RESP: |
| 2669 | case IEEE80211_STYPE_REASSOC_RESP: |
| 2670 | rma = ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, &bss); |
| 2671 | break; |
| 2672 | case IEEE80211_STYPE_ACTION: |
| 2673 | switch (mgmt->u.action.category) { |
| 2674 | case WLAN_CATEGORY_SPECTRUM_MGMT: |
| 2675 | ieee80211_sta_process_chanswitch(sdata, |
| 2676 | &mgmt->u.action.u.chan_switch.sw_elem, |
| 2677 | (void *)ifmgd->associated->priv, |
| 2678 | rx_status->mactime); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2679 | break; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2680 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2681 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2682 | mutex_unlock(&ifmgd->mtx); |
| 2683 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2684 | switch (rma) { |
| 2685 | case RX_MGMT_NONE: |
| 2686 | /* no action */ |
| 2687 | break; |
| 2688 | case RX_MGMT_CFG80211_DEAUTH: |
Holger Schurig | ce47061 | 2009-10-13 13:28:13 +0200 | [diff] [blame] | 2689 | cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2690 | break; |
| 2691 | case RX_MGMT_CFG80211_DISASSOC: |
| 2692 | cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len); |
| 2693 | break; |
| 2694 | case RX_MGMT_CFG80211_RX_AUTH: |
| 2695 | cfg80211_send_rx_auth(sdata->dev, (u8 *)mgmt, skb->len); |
| 2696 | break; |
| 2697 | case RX_MGMT_CFG80211_RX_ASSOC: |
| 2698 | cfg80211_send_rx_assoc(sdata->dev, bss, (u8 *)mgmt, skb->len); |
| 2699 | break; |
| 2700 | case RX_MGMT_CFG80211_ASSOC_TIMEOUT: |
| 2701 | cfg80211_send_assoc_timeout(sdata->dev, mgmt->bssid); |
| 2702 | break; |
| 2703 | default: |
| 2704 | WARN(1, "unexpected: %d", rma); |
Johannes Berg | b054b74 | 2010-06-07 21:50:07 +0200 | [diff] [blame] | 2705 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2706 | } |
| 2707 | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2708 | static void ieee80211_sta_timer(unsigned long data) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2709 | { |
| 2710 | struct ieee80211_sub_if_data *sdata = |
| 2711 | (struct ieee80211_sub_if_data *) data; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2712 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2713 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2714 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 2715 | if (local->quiescing) { |
| 2716 | set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running); |
| 2717 | return; |
| 2718 | } |
| 2719 | |
Johannes Berg | 64592c8 | 2010-06-10 10:21:31 +0200 | [diff] [blame] | 2720 | ieee80211_queue_work(&local->hw, &sdata->work); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2721 | } |
| 2722 | |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2723 | static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 2724 | u8 *bssid, u8 reason) |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2725 | { |
| 2726 | struct ieee80211_local *local = sdata->local; |
| 2727 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 2728 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2729 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2730 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason, |
| 2731 | false, frame_buf); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2732 | mutex_unlock(&ifmgd->mtx); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2733 | |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2734 | /* |
| 2735 | * must be outside lock due to cfg80211, |
| 2736 | * but that's not a problem. |
| 2737 | */ |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 2738 | cfg80211_send_deauth(sdata->dev, frame_buf, IEEE80211_DEAUTH_FRAME_LEN); |
Felix Fietkau | fcac4fb | 2011-11-16 13:34:55 +0100 | [diff] [blame] | 2739 | |
| 2740 | mutex_lock(&local->mtx); |
| 2741 | ieee80211_recalc_idle(local); |
| 2742 | mutex_unlock(&local->mtx); |
| 2743 | |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2744 | mutex_lock(&ifmgd->mtx); |
| 2745 | } |
| 2746 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2747 | static int ieee80211_probe_auth(struct ieee80211_sub_if_data *sdata) |
| 2748 | { |
| 2749 | struct ieee80211_local *local = sdata->local; |
| 2750 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 2751 | struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data; |
| 2752 | |
| 2753 | lockdep_assert_held(&ifmgd->mtx); |
| 2754 | |
| 2755 | if (WARN_ON_ONCE(!auth_data)) |
| 2756 | return -EINVAL; |
| 2757 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2758 | auth_data->tries++; |
| 2759 | |
| 2760 | if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2761 | sdata_info(sdata, "authentication with %pM timed out\n", |
| 2762 | auth_data->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2763 | |
| 2764 | /* |
| 2765 | * Most likely AP is not in the range so remove the |
| 2766 | * bss struct for that AP. |
| 2767 | */ |
| 2768 | cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss); |
| 2769 | |
| 2770 | return -ETIMEDOUT; |
| 2771 | } |
| 2772 | |
Johannes Berg | a1845fc | 2012-06-27 13:18:36 +0200 | [diff] [blame] | 2773 | drv_mgd_prepare_tx(local, sdata); |
| 2774 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2775 | if (auth_data->bss->proberesp_ies) { |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 2776 | u16 trans = 1; |
| 2777 | u16 status = 0; |
| 2778 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2779 | sdata_info(sdata, "send auth to %pM (try %d/%d)\n", |
| 2780 | auth_data->bss->bssid, auth_data->tries, |
| 2781 | IEEE80211_AUTH_MAX_TRIES); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2782 | |
| 2783 | auth_data->expected_transaction = 2; |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 2784 | |
| 2785 | if (auth_data->algorithm == WLAN_AUTH_SAE) { |
| 2786 | trans = auth_data->sae_trans; |
| 2787 | status = auth_data->sae_status; |
| 2788 | auth_data->expected_transaction = trans; |
| 2789 | } |
| 2790 | |
| 2791 | ieee80211_send_auth(sdata, trans, auth_data->algorithm, status, |
| 2792 | auth_data->data, auth_data->data_len, |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2793 | auth_data->bss->bssid, |
| 2794 | auth_data->bss->bssid, NULL, 0, 0); |
| 2795 | } else { |
| 2796 | const u8 *ssidie; |
| 2797 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2798 | sdata_info(sdata, "direct probe to %pM (try %d/%i)\n", |
| 2799 | auth_data->bss->bssid, auth_data->tries, |
| 2800 | IEEE80211_AUTH_MAX_TRIES); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2801 | |
| 2802 | ssidie = ieee80211_bss_get_ie(auth_data->bss, WLAN_EID_SSID); |
| 2803 | if (!ssidie) |
| 2804 | return -EINVAL; |
| 2805 | /* |
| 2806 | * Direct probe is sent to broadcast address as some APs |
| 2807 | * will not answer to direct packet in unassociated state. |
| 2808 | */ |
| 2809 | ieee80211_send_probe_req(sdata, NULL, ssidie + 2, ssidie[1], |
Johannes Berg | fe94fe0 | 2012-07-30 12:26:34 +0200 | [diff] [blame] | 2810 | NULL, 0, (u32) -1, true, false, |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2811 | auth_data->bss->channel, false); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2812 | } |
| 2813 | |
| 2814 | auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT; |
| 2815 | run_again(ifmgd, auth_data->timeout); |
| 2816 | |
| 2817 | return 0; |
| 2818 | } |
| 2819 | |
| 2820 | static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata) |
| 2821 | { |
| 2822 | struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data; |
| 2823 | struct ieee80211_local *local = sdata->local; |
| 2824 | |
| 2825 | lockdep_assert_held(&sdata->u.mgd.mtx); |
| 2826 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2827 | assoc_data->tries++; |
| 2828 | if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2829 | sdata_info(sdata, "association with %pM timed out\n", |
| 2830 | assoc_data->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2831 | |
| 2832 | /* |
| 2833 | * Most likely AP is not in the range so remove the |
| 2834 | * bss struct for that AP. |
| 2835 | */ |
| 2836 | cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss); |
| 2837 | |
| 2838 | return -ETIMEDOUT; |
| 2839 | } |
| 2840 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2841 | sdata_info(sdata, "associate with %pM (try %d/%d)\n", |
| 2842 | assoc_data->bss->bssid, assoc_data->tries, |
| 2843 | IEEE80211_ASSOC_MAX_TRIES); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2844 | ieee80211_send_assoc(sdata); |
| 2845 | |
| 2846 | assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT; |
| 2847 | run_again(&sdata->u.mgd, assoc_data->timeout); |
| 2848 | |
| 2849 | return 0; |
| 2850 | } |
| 2851 | |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 2852 | void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 2853 | { |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 2854 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 2855 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 2856 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2857 | mutex_lock(&ifmgd->mtx); |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 2858 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2859 | if (ifmgd->auth_data && |
| 2860 | time_after(jiffies, ifmgd->auth_data->timeout)) { |
| 2861 | if (ifmgd->auth_data->done) { |
| 2862 | /* |
| 2863 | * ok ... we waited for assoc but userspace didn't, |
| 2864 | * so let's just kill the auth data |
| 2865 | */ |
| 2866 | ieee80211_destroy_auth_data(sdata, false); |
| 2867 | } else if (ieee80211_probe_auth(sdata)) { |
| 2868 | u8 bssid[ETH_ALEN]; |
| 2869 | |
| 2870 | memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN); |
| 2871 | |
| 2872 | ieee80211_destroy_auth_data(sdata, false); |
| 2873 | |
| 2874 | mutex_unlock(&ifmgd->mtx); |
| 2875 | cfg80211_send_auth_timeout(sdata->dev, bssid); |
| 2876 | mutex_lock(&ifmgd->mtx); |
| 2877 | } |
| 2878 | } else if (ifmgd->auth_data) |
| 2879 | run_again(ifmgd, ifmgd->auth_data->timeout); |
| 2880 | |
| 2881 | if (ifmgd->assoc_data && |
| 2882 | time_after(jiffies, ifmgd->assoc_data->timeout)) { |
| 2883 | if (!ifmgd->assoc_data->have_beacon || |
| 2884 | ieee80211_do_assoc(sdata)) { |
| 2885 | u8 bssid[ETH_ALEN]; |
| 2886 | |
| 2887 | memcpy(bssid, ifmgd->assoc_data->bss->bssid, ETH_ALEN); |
| 2888 | |
| 2889 | ieee80211_destroy_assoc_data(sdata, false); |
| 2890 | |
| 2891 | mutex_unlock(&ifmgd->mtx); |
| 2892 | cfg80211_send_assoc_timeout(sdata->dev, bssid); |
| 2893 | mutex_lock(&ifmgd->mtx); |
| 2894 | } |
| 2895 | } else if (ifmgd->assoc_data) |
| 2896 | run_again(ifmgd, ifmgd->assoc_data->timeout); |
| 2897 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2898 | if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL | |
| 2899 | IEEE80211_STA_CONNECTION_POLL) && |
| 2900 | ifmgd->associated) { |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2901 | u8 bssid[ETH_ALEN]; |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 2902 | int max_tries; |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2903 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2904 | memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2905 | |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 2906 | if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 2907 | max_tries = max_nullfunc_tries; |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 2908 | else |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 2909 | max_tries = max_probe_tries; |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 2910 | |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2911 | /* ACK received for nullfunc probing frame */ |
| 2912 | if (!ifmgd->probe_send_count) |
| 2913 | ieee80211_reset_ap_probe(sdata); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2914 | else if (ifmgd->nullfunc_failed) { |
| 2915 | if (ifmgd->probe_send_count < max_tries) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2916 | mlme_dbg(sdata, |
| 2917 | "No ack for nullfunc frame to AP %pM, try %d/%i\n", |
| 2918 | bssid, ifmgd->probe_send_count, |
| 2919 | max_tries); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2920 | ieee80211_mgd_probe_ap_send(sdata); |
| 2921 | } else { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2922 | mlme_dbg(sdata, |
| 2923 | "No ack for nullfunc frame to AP %pM, disconnecting.\n", |
| 2924 | bssid); |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 2925 | ieee80211_sta_connection_lost(sdata, bssid, |
| 2926 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2927 | } |
| 2928 | } else if (time_is_after_jiffies(ifmgd->probe_timeout)) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2929 | run_again(ifmgd, ifmgd->probe_timeout); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2930 | else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2931 | mlme_dbg(sdata, |
| 2932 | "Failed to send nullfunc to AP %pM after %dms, disconnecting\n", |
| 2933 | bssid, probe_wait_ms); |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 2934 | ieee80211_sta_connection_lost(sdata, bssid, |
| 2935 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2936 | } else if (ifmgd->probe_send_count < max_tries) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2937 | mlme_dbg(sdata, |
| 2938 | "No probe response from AP %pM after %dms, try %d/%i\n", |
| 2939 | bssid, probe_wait_ms, |
| 2940 | ifmgd->probe_send_count, max_tries); |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2941 | ieee80211_mgd_probe_ap_send(sdata); |
| 2942 | } else { |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2943 | /* |
| 2944 | * We actually lost the connection ... or did we? |
| 2945 | * Let's make sure! |
| 2946 | */ |
Ben Greear | b38afa8 | 2010-10-07 16:12:06 -0700 | [diff] [blame] | 2947 | wiphy_debug(local->hw.wiphy, |
| 2948 | "%s: No probe response from AP %pM" |
| 2949 | " after %dms, disconnecting.\n", |
| 2950 | sdata->name, |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 2951 | bssid, probe_wait_ms); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2952 | |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 2953 | ieee80211_sta_connection_lost(sdata, bssid, |
| 2954 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2955 | } |
| 2956 | } |
| 2957 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2958 | mutex_unlock(&ifmgd->mtx); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2959 | |
| 2960 | mutex_lock(&local->mtx); |
| 2961 | ieee80211_recalc_idle(local); |
| 2962 | mutex_unlock(&local->mtx); |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 2963 | } |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 2964 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2965 | static void ieee80211_sta_bcn_mon_timer(unsigned long data) |
| 2966 | { |
| 2967 | struct ieee80211_sub_if_data *sdata = |
| 2968 | (struct ieee80211_sub_if_data *) data; |
| 2969 | struct ieee80211_local *local = sdata->local; |
| 2970 | |
| 2971 | if (local->quiescing) |
| 2972 | return; |
| 2973 | |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2974 | ieee80211_queue_work(&sdata->local->hw, |
| 2975 | &sdata->u.mgd.beacon_connection_loss_work); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2976 | } |
| 2977 | |
| 2978 | static void ieee80211_sta_conn_mon_timer(unsigned long data) |
| 2979 | { |
| 2980 | struct ieee80211_sub_if_data *sdata = |
| 2981 | (struct ieee80211_sub_if_data *) data; |
| 2982 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 2983 | struct ieee80211_local *local = sdata->local; |
| 2984 | |
| 2985 | if (local->quiescing) |
| 2986 | return; |
| 2987 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 2988 | ieee80211_queue_work(&local->hw, &ifmgd->monitor_work); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2989 | } |
| 2990 | |
| 2991 | static void ieee80211_sta_monitor_work(struct work_struct *work) |
| 2992 | { |
| 2993 | struct ieee80211_sub_if_data *sdata = |
| 2994 | container_of(work, struct ieee80211_sub_if_data, |
| 2995 | u.mgd.monitor_work); |
| 2996 | |
| 2997 | ieee80211_mgd_probe_ap(sdata, false); |
| 2998 | } |
| 2999 | |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 3000 | static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata) |
| 3001 | { |
Eliad Peller | 494f1fe | 2012-02-19 15:26:09 +0200 | [diff] [blame] | 3002 | u32 flags; |
| 3003 | |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 3004 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 3005 | __ieee80211_stop_poll(sdata); |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 3006 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3007 | /* let's probe the connection once */ |
Eliad Peller | 494f1fe | 2012-02-19 15:26:09 +0200 | [diff] [blame] | 3008 | flags = sdata->local->hw.flags; |
| 3009 | if (!(flags & IEEE80211_HW_CONNECTION_MONITOR)) |
| 3010 | ieee80211_queue_work(&sdata->local->hw, |
| 3011 | &sdata->u.mgd.monitor_work); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3012 | /* and do all the other regular work too */ |
Johannes Berg | 64592c8 | 2010-06-10 10:21:31 +0200 | [diff] [blame] | 3013 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 3014 | } |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 3015 | } |
| 3016 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 3017 | #ifdef CONFIG_PM |
| 3018 | void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata) |
| 3019 | { |
| 3020 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3021 | |
| 3022 | /* |
| 3023 | * we need to use atomic bitops for the running bits |
| 3024 | * only because both timers might fire at the same |
| 3025 | * time -- the code here is properly synchronised. |
| 3026 | */ |
| 3027 | |
Johannes Berg | d1f5b7a | 2010-08-05 17:05:55 +0200 | [diff] [blame] | 3028 | cancel_work_sync(&ifmgd->request_smps_work); |
| 3029 | |
Johannes Berg | 0ecfe80 | 2011-11-09 12:14:16 +0100 | [diff] [blame] | 3030 | cancel_work_sync(&ifmgd->monitor_work); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 3031 | cancel_work_sync(&ifmgd->beacon_connection_loss_work); |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 3032 | cancel_work_sync(&ifmgd->csa_connection_drop_work); |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 3033 | if (del_timer_sync(&ifmgd->timer)) |
| 3034 | set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running); |
| 3035 | |
| 3036 | cancel_work_sync(&ifmgd->chswitch_work); |
| 3037 | if (del_timer_sync(&ifmgd->chswitch_timer)) |
| 3038 | set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3039 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3040 | /* these will just be re-established on connection */ |
| 3041 | del_timer_sync(&ifmgd->conn_mon_timer); |
| 3042 | del_timer_sync(&ifmgd->bcn_mon_timer); |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 3043 | } |
| 3044 | |
| 3045 | void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata) |
| 3046 | { |
| 3047 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3048 | |
Rajkumar Manoharan | 676b58c | 2011-07-07 23:33:39 +0530 | [diff] [blame] | 3049 | if (!ifmgd->associated) |
| 3050 | return; |
| 3051 | |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 3052 | if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) { |
| 3053 | sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME; |
| 3054 | mutex_lock(&ifmgd->mtx); |
| 3055 | if (ifmgd->associated) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3056 | mlme_dbg(sdata, |
| 3057 | "driver requested disconnect after resume\n"); |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 3058 | ieee80211_sta_connection_lost(sdata, |
| 3059 | ifmgd->associated->bssid, |
| 3060 | WLAN_REASON_UNSPECIFIED); |
| 3061 | mutex_unlock(&ifmgd->mtx); |
| 3062 | return; |
| 3063 | } |
| 3064 | mutex_unlock(&ifmgd->mtx); |
| 3065 | } |
| 3066 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 3067 | if (test_and_clear_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running)) |
| 3068 | add_timer(&ifmgd->timer); |
| 3069 | if (test_and_clear_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running)) |
| 3070 | add_timer(&ifmgd->chswitch_timer); |
Felix Fietkau | c8a7972 | 2010-11-19 22:55:37 +0100 | [diff] [blame] | 3071 | ieee80211_sta_reset_beacon_monitor(sdata); |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 3072 | |
| 3073 | mutex_lock(&sdata->local->mtx); |
Felix Fietkau | 4609097 | 2010-11-23 20:28:03 +0100 | [diff] [blame] | 3074 | ieee80211_restart_sta_timer(sdata); |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 3075 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 3076 | } |
| 3077 | #endif |
| 3078 | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 3079 | /* interface setup */ |
| 3080 | void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata) |
| 3081 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3082 | struct ieee80211_if_managed *ifmgd; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 3083 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3084 | ifmgd = &sdata->u.mgd; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3085 | INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3086 | INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 3087 | INIT_WORK(&ifmgd->beacon_connection_loss_work, |
| 3088 | ieee80211_beacon_connection_loss_work); |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 3089 | INIT_WORK(&ifmgd->csa_connection_drop_work, |
| 3090 | ieee80211_csa_connection_drop_work); |
Johannes Berg | d1f5b7a | 2010-08-05 17:05:55 +0200 | [diff] [blame] | 3091 | INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3092 | setup_timer(&ifmgd->timer, ieee80211_sta_timer, |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 3093 | (unsigned long) sdata); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3094 | setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, |
| 3095 | (unsigned long) sdata); |
| 3096 | setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, |
| 3097 | (unsigned long) sdata); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3098 | setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, |
Sujith | c481ec9 | 2009-01-06 09:28:37 +0530 | [diff] [blame] | 3099 | (unsigned long) sdata); |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 3100 | |
Johannes Berg | ab1faea | 2009-07-01 21:41:17 +0200 | [diff] [blame] | 3101 | ifmgd->flags = 0; |
Mohammed Shafi Shajakhan | 1478acb | 2011-12-14 19:46:08 +0530 | [diff] [blame] | 3102 | ifmgd->powersave = sdata->wdev.ps; |
Eliad Peller | dc41e4d | 2012-03-14 16:15:03 +0200 | [diff] [blame] | 3103 | ifmgd->uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES; |
| 3104 | ifmgd->uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN; |
Johannes Berg | bbbdff9 | 2009-04-16 13:27:42 +0200 | [diff] [blame] | 3105 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3106 | mutex_init(&ifmgd->mtx); |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 3107 | |
| 3108 | if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS) |
| 3109 | ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC; |
| 3110 | else |
| 3111 | ifmgd->req_smps = IEEE80211_SMPS_OFF; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 3112 | } |
| 3113 | |
| 3114 | /* scan finished notification */ |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 3115 | void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local) |
| 3116 | { |
Johannes Berg | 31ee67a | 2012-07-06 21:18:24 +0200 | [diff] [blame] | 3117 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 3118 | |
| 3119 | /* Restart STA timers */ |
| 3120 | rcu_read_lock(); |
| 3121 | list_for_each_entry_rcu(sdata, &local->interfaces, list) |
| 3122 | ieee80211_restart_sta_timer(sdata); |
| 3123 | rcu_read_unlock(); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 3124 | } |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 3125 | |
| 3126 | int ieee80211_max_network_latency(struct notifier_block *nb, |
| 3127 | unsigned long data, void *dummy) |
| 3128 | { |
| 3129 | s32 latency_usec = (s32) data; |
| 3130 | struct ieee80211_local *local = |
| 3131 | container_of(nb, struct ieee80211_local, |
| 3132 | network_latency_notifier); |
| 3133 | |
| 3134 | mutex_lock(&local->iflist_mtx); |
| 3135 | ieee80211_recalc_ps(local, latency_usec); |
| 3136 | mutex_unlock(&local->iflist_mtx); |
| 3137 | |
| 3138 | return 0; |
| 3139 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3140 | |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 3141 | static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata, |
| 3142 | struct cfg80211_bss *cbss) |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 3143 | { |
| 3144 | struct ieee80211_local *local = sdata->local; |
| 3145 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 3146 | int ht_cfreq; |
| 3147 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 3148 | const u8 *ht_oper_ie; |
| 3149 | const struct ieee80211_ht_operation *ht_oper = NULL; |
| 3150 | struct ieee80211_supported_band *sband; |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 3151 | |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 3152 | sband = local->hw.wiphy->bands[cbss->channel->band]; |
| 3153 | |
| 3154 | ifmgd->flags &= ~IEEE80211_STA_DISABLE_40MHZ; |
| 3155 | |
| 3156 | if (sband->ht_cap.ht_supported) { |
| 3157 | ht_oper_ie = cfg80211_find_ie(WLAN_EID_HT_OPERATION, |
| 3158 | cbss->information_elements, |
| 3159 | cbss->len_information_elements); |
| 3160 | if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper)) |
| 3161 | ht_oper = (void *)(ht_oper_ie + 2); |
| 3162 | } |
| 3163 | |
| 3164 | if (ht_oper) { |
| 3165 | ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan, |
| 3166 | cbss->channel->band); |
| 3167 | /* check that channel matches the right operating channel */ |
| 3168 | if (cbss->channel->center_freq != ht_cfreq) { |
| 3169 | /* |
| 3170 | * It's possible that some APs are confused here; |
| 3171 | * Netgear WNDR3700 sometimes reports 4 higher than |
| 3172 | * the actual channel in association responses, but |
| 3173 | * since we look at probe response/beacon data here |
| 3174 | * it should be OK. |
| 3175 | */ |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3176 | sdata_info(sdata, |
| 3177 | "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n", |
| 3178 | cbss->channel->center_freq, |
| 3179 | ht_cfreq, ht_oper->primary_chan, |
| 3180 | cbss->channel->band); |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 3181 | ht_oper = NULL; |
Johannes Berg | 3a40414 | 2012-10-01 15:52:00 +0200 | [diff] [blame] | 3182 | } else { |
| 3183 | channel_type = NL80211_CHAN_HT20; |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 3184 | } |
| 3185 | } |
| 3186 | |
Johannes Berg | 3a40414 | 2012-10-01 15:52:00 +0200 | [diff] [blame] | 3187 | if (ht_oper && sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) { |
| 3188 | /* |
| 3189 | * cfg80211 already verified that the channel itself can |
| 3190 | * be used, but it didn't check that we can do the right |
| 3191 | * HT type, so do that here as well. If HT40 isn't allowed |
| 3192 | * on this channel, disable 40 MHz operation. |
| 3193 | */ |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 3194 | const u8 *ht_cap_ie; |
| 3195 | const struct ieee80211_ht_cap *ht_cap; |
| 3196 | u8 chains = 1; |
| 3197 | |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 3198 | channel_type = NL80211_CHAN_HT20; |
| 3199 | |
Johannes Berg | 3a40414 | 2012-10-01 15:52:00 +0200 | [diff] [blame] | 3200 | switch (ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { |
| 3201 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: |
| 3202 | if (cbss->channel->flags & IEEE80211_CHAN_NO_HT40PLUS) |
| 3203 | ifmgd->flags |= IEEE80211_STA_DISABLE_40MHZ; |
| 3204 | else |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 3205 | channel_type = NL80211_CHAN_HT40PLUS; |
Johannes Berg | 3a40414 | 2012-10-01 15:52:00 +0200 | [diff] [blame] | 3206 | break; |
| 3207 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: |
| 3208 | if (cbss->channel->flags & IEEE80211_CHAN_NO_HT40MINUS) |
| 3209 | ifmgd->flags |= IEEE80211_STA_DISABLE_40MHZ; |
| 3210 | else |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 3211 | channel_type = NL80211_CHAN_HT40MINUS; |
Johannes Berg | 3a40414 | 2012-10-01 15:52:00 +0200 | [diff] [blame] | 3212 | break; |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 3213 | } |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 3214 | |
| 3215 | ht_cap_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, |
| 3216 | cbss->information_elements, |
| 3217 | cbss->len_information_elements); |
| 3218 | if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) { |
| 3219 | ht_cap = (void *)(ht_cap_ie + 2); |
| 3220 | chains = ieee80211_mcs_to_chains(&ht_cap->mcs); |
| 3221 | } |
| 3222 | sdata->needed_rx_chains = min(chains, local->rx_chains); |
| 3223 | } else { |
| 3224 | sdata->needed_rx_chains = 1; |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 3225 | } |
| 3226 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 3227 | /* will change later if needed */ |
| 3228 | sdata->smps_mode = IEEE80211_SMPS_OFF; |
| 3229 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 3230 | ieee80211_vif_release_channel(sdata); |
| 3231 | return ieee80211_vif_use_channel(sdata, cbss->channel, channel_type, |
| 3232 | IEEE80211_CHANCTX_SHARED); |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 3233 | } |
| 3234 | |
| 3235 | static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata, |
| 3236 | struct cfg80211_bss *cbss, bool assoc) |
| 3237 | { |
| 3238 | struct ieee80211_local *local = sdata->local; |
| 3239 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3240 | struct ieee80211_bss *bss = (void *)cbss->priv; |
| 3241 | struct sta_info *new_sta = NULL; |
| 3242 | bool have_sta = false; |
| 3243 | int err; |
| 3244 | |
| 3245 | if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data)) |
| 3246 | return -EINVAL; |
| 3247 | |
| 3248 | if (assoc) { |
| 3249 | rcu_read_lock(); |
| 3250 | have_sta = sta_info_get(sdata, cbss->bssid); |
| 3251 | rcu_read_unlock(); |
| 3252 | } |
| 3253 | |
| 3254 | if (!have_sta) { |
| 3255 | new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL); |
| 3256 | if (!new_sta) |
| 3257 | return -ENOMEM; |
| 3258 | } |
| 3259 | |
| 3260 | mutex_lock(&local->mtx); |
| 3261 | ieee80211_recalc_idle(sdata->local); |
| 3262 | mutex_unlock(&local->mtx); |
| 3263 | |
Johannes Berg | 13e0c8e | 2012-07-27 10:43:16 +0200 | [diff] [blame] | 3264 | if (new_sta) { |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 3265 | u32 rates = 0, basic_rates = 0; |
| 3266 | bool have_higher_than_11mbit; |
| 3267 | int min_rate = INT_MAX, min_rate_index = -1; |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 3268 | struct ieee80211_supported_band *sband; |
| 3269 | |
| 3270 | sband = local->hw.wiphy->bands[cbss->channel->band]; |
| 3271 | |
| 3272 | err = ieee80211_prep_channel(sdata, cbss); |
| 3273 | if (err) { |
| 3274 | sta_info_free(local, new_sta); |
| 3275 | return err; |
| 3276 | } |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 3277 | |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 3278 | ieee80211_get_rates(sband, bss->supp_rates, |
| 3279 | bss->supp_rates_len, |
| 3280 | &rates, &basic_rates, |
| 3281 | &have_higher_than_11mbit, |
| 3282 | &min_rate, &min_rate_index); |
| 3283 | |
| 3284 | /* |
| 3285 | * This used to be a workaround for basic rates missing |
| 3286 | * in the association response frame. Now that we no |
| 3287 | * longer use the basic rates from there, it probably |
| 3288 | * doesn't happen any more, but keep the workaround so |
| 3289 | * in case some *other* APs are buggy in different ways |
| 3290 | * we can connect -- with a warning. |
| 3291 | */ |
| 3292 | if (!basic_rates && min_rate_index >= 0) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3293 | sdata_info(sdata, |
| 3294 | "No basic rates, using min rate instead\n"); |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 3295 | basic_rates = BIT(min_rate_index); |
| 3296 | } |
| 3297 | |
Johannes Berg | 13e0c8e | 2012-07-27 10:43:16 +0200 | [diff] [blame] | 3298 | new_sta->sta.supp_rates[cbss->channel->band] = rates; |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 3299 | sdata->vif.bss_conf.basic_rates = basic_rates; |
| 3300 | |
| 3301 | /* cf. IEEE 802.11 9.2.12 */ |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 3302 | if (cbss->channel->band == IEEE80211_BAND_2GHZ && |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 3303 | have_higher_than_11mbit) |
| 3304 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; |
| 3305 | else |
| 3306 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; |
| 3307 | |
| 3308 | memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN); |
| 3309 | |
Johannes Berg | 8c358bc | 2012-05-22 22:13:05 +0200 | [diff] [blame] | 3310 | /* set timing information */ |
| 3311 | sdata->vif.bss_conf.beacon_int = cbss->beacon_interval; |
| 3312 | sdata->vif.bss_conf.sync_tsf = cbss->tsf; |
| 3313 | sdata->vif.bss_conf.sync_device_ts = bss->device_ts; |
| 3314 | |
| 3315 | /* tell driver about BSSID, basic rates and timing */ |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 3316 | ieee80211_bss_info_change_notify(sdata, |
Johannes Berg | 8c358bc | 2012-05-22 22:13:05 +0200 | [diff] [blame] | 3317 | BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES | |
| 3318 | BSS_CHANGED_BEACON_INT); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 3319 | |
| 3320 | if (assoc) |
Johannes Berg | 13e0c8e | 2012-07-27 10:43:16 +0200 | [diff] [blame] | 3321 | sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 3322 | |
Johannes Berg | 13e0c8e | 2012-07-27 10:43:16 +0200 | [diff] [blame] | 3323 | err = sta_info_insert(new_sta); |
| 3324 | new_sta = NULL; |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 3325 | if (err) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3326 | sdata_info(sdata, |
| 3327 | "failed to insert STA entry for the AP (error %d)\n", |
| 3328 | err); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 3329 | return err; |
| 3330 | } |
| 3331 | } else |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 3332 | WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid)); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 3333 | |
| 3334 | return 0; |
| 3335 | } |
| 3336 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3337 | /* config hooks */ |
| 3338 | int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata, |
| 3339 | struct cfg80211_auth_request *req) |
| 3340 | { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3341 | struct ieee80211_local *local = sdata->local; |
| 3342 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3343 | struct ieee80211_mgd_auth_data *auth_data; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3344 | u16 auth_alg; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3345 | int err; |
| 3346 | |
| 3347 | /* prepare auth data structure */ |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3348 | |
| 3349 | switch (req->auth_type) { |
| 3350 | case NL80211_AUTHTYPE_OPEN_SYSTEM: |
| 3351 | auth_alg = WLAN_AUTH_OPEN; |
| 3352 | break; |
| 3353 | case NL80211_AUTHTYPE_SHARED_KEY: |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3354 | if (IS_ERR(local->wep_tx_tfm)) |
Johannes Berg | 9dca9c4 | 2010-07-21 10:09:25 +0200 | [diff] [blame] | 3355 | return -EOPNOTSUPP; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3356 | auth_alg = WLAN_AUTH_SHARED_KEY; |
| 3357 | break; |
| 3358 | case NL80211_AUTHTYPE_FT: |
| 3359 | auth_alg = WLAN_AUTH_FT; |
| 3360 | break; |
| 3361 | case NL80211_AUTHTYPE_NETWORK_EAP: |
| 3362 | auth_alg = WLAN_AUTH_LEAP; |
| 3363 | break; |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 3364 | case NL80211_AUTHTYPE_SAE: |
| 3365 | auth_alg = WLAN_AUTH_SAE; |
| 3366 | break; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3367 | default: |
| 3368 | return -EOPNOTSUPP; |
| 3369 | } |
| 3370 | |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 3371 | auth_data = kzalloc(sizeof(*auth_data) + req->sae_data_len + |
| 3372 | req->ie_len, GFP_KERNEL); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3373 | if (!auth_data) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3374 | return -ENOMEM; |
| 3375 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3376 | auth_data->bss = req->bss; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3377 | |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 3378 | if (req->sae_data_len >= 4) { |
| 3379 | __le16 *pos = (__le16 *) req->sae_data; |
| 3380 | auth_data->sae_trans = le16_to_cpu(pos[0]); |
| 3381 | auth_data->sae_status = le16_to_cpu(pos[1]); |
| 3382 | memcpy(auth_data->data, req->sae_data + 4, |
| 3383 | req->sae_data_len - 4); |
| 3384 | auth_data->data_len += req->sae_data_len - 4; |
| 3385 | } |
| 3386 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3387 | if (req->ie && req->ie_len) { |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 3388 | memcpy(&auth_data->data[auth_data->data_len], |
| 3389 | req->ie, req->ie_len); |
| 3390 | auth_data->data_len += req->ie_len; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3391 | } |
| 3392 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3393 | if (req->key && req->key_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3394 | auth_data->key_len = req->key_len; |
| 3395 | auth_data->key_idx = req->key_idx; |
| 3396 | memcpy(auth_data->key, req->key, req->key_len); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3397 | } |
| 3398 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3399 | auth_data->algorithm = auth_alg; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3400 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3401 | /* try to authenticate/probe */ |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 3402 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3403 | mutex_lock(&ifmgd->mtx); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3404 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3405 | if ((ifmgd->auth_data && !ifmgd->auth_data->done) || |
| 3406 | ifmgd->assoc_data) { |
| 3407 | err = -EBUSY; |
| 3408 | goto err_free; |
| 3409 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3410 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3411 | if (ifmgd->auth_data) |
| 3412 | ieee80211_destroy_auth_data(sdata, false); |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 3413 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3414 | /* prep auth_data so we don't go into idle on disassoc */ |
| 3415 | ifmgd->auth_data = auth_data; |
| 3416 | |
| 3417 | if (ifmgd->associated) |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 3418 | ieee80211_set_disassoc(sdata, 0, 0, false, NULL); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3419 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3420 | sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3421 | |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 3422 | err = ieee80211_prep_connection(sdata, req->bss, false); |
| 3423 | if (err) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3424 | goto err_clear; |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 3425 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3426 | err = ieee80211_probe_auth(sdata); |
| 3427 | if (err) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3428 | sta_info_destroy_addr(sdata, req->bss->bssid); |
| 3429 | goto err_clear; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3430 | } |
| 3431 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3432 | /* hold our own reference */ |
| 3433 | cfg80211_ref_bss(auth_data->bss); |
| 3434 | err = 0; |
| 3435 | goto out_unlock; |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 3436 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3437 | err_clear: |
Eliad Peller | 3d2abdf | 2012-09-04 17:44:45 +0300 | [diff] [blame] | 3438 | memset(ifmgd->bssid, 0, ETH_ALEN); |
| 3439 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3440 | ifmgd->auth_data = NULL; |
| 3441 | err_free: |
| 3442 | kfree(auth_data); |
| 3443 | out_unlock: |
| 3444 | mutex_unlock(&ifmgd->mtx); |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 3445 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3446 | return err; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3447 | } |
| 3448 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3449 | int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, |
| 3450 | struct cfg80211_assoc_request *req) |
| 3451 | { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3452 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3453 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 3454 | struct ieee80211_bss *bss = (void *)req->bss->priv; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3455 | struct ieee80211_mgd_assoc_data *assoc_data; |
Johannes Berg | 4e74bfd | 2012-03-08 15:02:04 +0100 | [diff] [blame] | 3456 | struct ieee80211_supported_band *sband; |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 3457 | const u8 *ssidie, *ht_ie; |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 3458 | int i, err; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3459 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3460 | ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID); |
| 3461 | if (!ssidie) |
| 3462 | return -EINVAL; |
Jouni Malinen | 9c87ba6 | 2010-02-28 12:13:46 +0200 | [diff] [blame] | 3463 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3464 | assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL); |
| 3465 | if (!assoc_data) |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3466 | return -ENOMEM; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3467 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3468 | mutex_lock(&ifmgd->mtx); |
| 3469 | |
| 3470 | if (ifmgd->associated) |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 3471 | ieee80211_set_disassoc(sdata, 0, 0, false, NULL); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3472 | |
| 3473 | if (ifmgd->auth_data && !ifmgd->auth_data->done) { |
| 3474 | err = -EBUSY; |
| 3475 | goto err_free; |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 3476 | } |
| 3477 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3478 | if (ifmgd->assoc_data) { |
| 3479 | err = -EBUSY; |
| 3480 | goto err_free; |
| 3481 | } |
| 3482 | |
| 3483 | if (ifmgd->auth_data) { |
| 3484 | bool match; |
| 3485 | |
| 3486 | /* keep sta info, bssid if matching */ |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 3487 | match = ether_addr_equal(ifmgd->bssid, req->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3488 | ieee80211_destroy_auth_data(sdata, match); |
| 3489 | } |
| 3490 | |
| 3491 | /* prepare assoc data */ |
Johannes Berg | 19c3b83 | 2012-08-01 20:13:36 +0200 | [diff] [blame] | 3492 | |
| 3493 | /* |
| 3494 | * keep only the 40 MHz disable bit set as it might have |
| 3495 | * been set during authentication already, all other bits |
| 3496 | * should be reset for a new connection |
| 3497 | */ |
| 3498 | ifmgd->flags &= IEEE80211_STA_DISABLE_40MHZ; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3499 | |
Juuso Oikarinen | d8ec443 | 2010-10-01 16:02:31 +0300 | [diff] [blame] | 3500 | ifmgd->beacon_crc_valid = false; |
| 3501 | |
Johannes Berg | de5036a | 2012-03-08 15:02:03 +0100 | [diff] [blame] | 3502 | /* |
| 3503 | * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode. |
| 3504 | * We still associate in non-HT mode (11a/b/g) if any one of these |
| 3505 | * ciphers is configured as pairwise. |
| 3506 | * We can set this to true for non-11n hardware, that'll be checked |
| 3507 | * separately along with the peer capabilities. |
| 3508 | */ |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 3509 | for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) { |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3510 | if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 || |
| 3511 | req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP || |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 3512 | req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) { |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3513 | ifmgd->flags |= IEEE80211_STA_DISABLE_11N; |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 3514 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 3515 | netdev_info(sdata->dev, |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 3516 | "disabling HT/VHT due to WEP/TKIP use\n"); |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 3517 | } |
| 3518 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3519 | |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 3520 | if (req->flags & ASSOC_REQ_DISABLE_HT) { |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 3521 | ifmgd->flags |= IEEE80211_STA_DISABLE_11N; |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 3522 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
| 3523 | } |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 3524 | |
Johannes Berg | 4e74bfd | 2012-03-08 15:02:04 +0100 | [diff] [blame] | 3525 | /* Also disable HT if we don't support it or the AP doesn't use WMM */ |
| 3526 | sband = local->hw.wiphy->bands[req->bss->channel->band]; |
| 3527 | if (!sband->ht_cap.ht_supported || |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 3528 | local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) { |
Johannes Berg | 4e74bfd | 2012-03-08 15:02:04 +0100 | [diff] [blame] | 3529 | ifmgd->flags |= IEEE80211_STA_DISABLE_11N; |
Johannes Berg | 1b49de2 | 2012-07-27 10:29:14 +0200 | [diff] [blame] | 3530 | if (!bss->wmm_used) |
| 3531 | netdev_info(sdata->dev, |
| 3532 | "disabling HT as WMM/QoS is not supported by the AP\n"); |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 3533 | } |
Johannes Berg | 4e74bfd | 2012-03-08 15:02:04 +0100 | [diff] [blame] | 3534 | |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 3535 | /* disable VHT if we don't support it or the AP doesn't use WMM */ |
| 3536 | if (!sband->vht_cap.vht_supported || |
| 3537 | local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) { |
| 3538 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 1b49de2 | 2012-07-27 10:29:14 +0200 | [diff] [blame] | 3539 | if (!bss->wmm_used) |
| 3540 | netdev_info(sdata->dev, |
| 3541 | "disabling VHT as WMM/QoS is not supported by the AP\n"); |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 3542 | } |
| 3543 | |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 3544 | memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa)); |
| 3545 | memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask, |
| 3546 | sizeof(ifmgd->ht_capa_mask)); |
| 3547 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3548 | if (req->ie && req->ie_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3549 | memcpy(assoc_data->ie, req->ie, req->ie_len); |
| 3550 | assoc_data->ie_len = req->ie_len; |
| 3551 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3552 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3553 | assoc_data->bss = req->bss; |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 3554 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3555 | if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) { |
| 3556 | if (ifmgd->powersave) |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 3557 | sdata->smps_mode = IEEE80211_SMPS_DYNAMIC; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3558 | else |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 3559 | sdata->smps_mode = IEEE80211_SMPS_OFF; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3560 | } else |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 3561 | sdata->smps_mode = ifmgd->req_smps; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3562 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3563 | assoc_data->capability = req->bss->capability; |
Johannes Berg | 32c5057 | 2012-03-28 11:04:29 +0200 | [diff] [blame] | 3564 | assoc_data->wmm = bss->wmm_used && |
| 3565 | (local->hw.queues >= IEEE80211_NUM_ACS); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3566 | assoc_data->supp_rates = bss->supp_rates; |
| 3567 | assoc_data->supp_rates_len = bss->supp_rates_len; |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 3568 | |
| 3569 | ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION); |
| 3570 | if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation)) |
| 3571 | assoc_data->ap_ht_param = |
| 3572 | ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param; |
| 3573 | else |
| 3574 | ifmgd->flags |= IEEE80211_STA_DISABLE_11N; |
Johannes Berg | 63f170e | 2009-12-23 13:15:33 +0100 | [diff] [blame] | 3575 | |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 3576 | if (bss->wmm_used && bss->uapsd_supported && |
| 3577 | (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) { |
Johannes Berg | 76f0303 | 2012-03-08 15:02:05 +0100 | [diff] [blame] | 3578 | assoc_data->uapsd = true; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 3579 | ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED; |
| 3580 | } else { |
Johannes Berg | 76f0303 | 2012-03-08 15:02:05 +0100 | [diff] [blame] | 3581 | assoc_data->uapsd = false; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 3582 | ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED; |
| 3583 | } |
| 3584 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3585 | memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]); |
| 3586 | assoc_data->ssid_len = ssidie[1]; |
Johannes Berg | 63f170e | 2009-12-23 13:15:33 +0100 | [diff] [blame] | 3587 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3588 | if (req->prev_bssid) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3589 | memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3590 | |
| 3591 | if (req->use_mfp) { |
| 3592 | ifmgd->mfp = IEEE80211_MFP_REQUIRED; |
| 3593 | ifmgd->flags |= IEEE80211_STA_MFP_ENABLED; |
| 3594 | } else { |
| 3595 | ifmgd->mfp = IEEE80211_MFP_DISABLED; |
| 3596 | ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED; |
| 3597 | } |
| 3598 | |
| 3599 | if (req->crypto.control_port) |
| 3600 | ifmgd->flags |= IEEE80211_STA_CONTROL_PORT; |
| 3601 | else |
| 3602 | ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT; |
| 3603 | |
Johannes Berg | a621fa4 | 2010-08-27 14:26:54 +0300 | [diff] [blame] | 3604 | sdata->control_port_protocol = req->crypto.control_port_ethertype; |
| 3605 | sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt; |
| 3606 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3607 | /* kick off associate process */ |
| 3608 | |
| 3609 | ifmgd->assoc_data = assoc_data; |
| 3610 | |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 3611 | err = ieee80211_prep_connection(sdata, req->bss, true); |
| 3612 | if (err) |
| 3613 | goto err_clear; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3614 | |
| 3615 | if (!bss->dtim_period && |
| 3616 | sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD) { |
| 3617 | /* |
| 3618 | * Wait up to one beacon interval ... |
| 3619 | * should this be more if we miss one? |
| 3620 | */ |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3621 | sdata_info(sdata, "waiting for beacon from %pM\n", |
| 3622 | ifmgd->bssid); |
Johannes Berg | 3f9768a | 2012-03-28 21:02:46 +0200 | [diff] [blame] | 3623 | assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3624 | } else { |
| 3625 | assoc_data->have_beacon = true; |
| 3626 | assoc_data->sent_assoc = false; |
| 3627 | assoc_data->timeout = jiffies; |
| 3628 | } |
| 3629 | run_again(ifmgd, assoc_data->timeout); |
| 3630 | |
Paul Stewart | fcff4f1 | 2012-02-23 17:59:53 -0800 | [diff] [blame] | 3631 | if (bss->corrupt_data) { |
| 3632 | char *corrupt_type = "data"; |
| 3633 | if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) { |
| 3634 | if (bss->corrupt_data & |
| 3635 | IEEE80211_BSS_CORRUPT_PROBE_RESP) |
| 3636 | corrupt_type = "beacon and probe response"; |
| 3637 | else |
| 3638 | corrupt_type = "beacon"; |
| 3639 | } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP) |
| 3640 | corrupt_type = "probe response"; |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3641 | sdata_info(sdata, "associating with AP with corrupt %s\n", |
| 3642 | corrupt_type); |
Paul Stewart | fcff4f1 | 2012-02-23 17:59:53 -0800 | [diff] [blame] | 3643 | } |
| 3644 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3645 | err = 0; |
| 3646 | goto out; |
| 3647 | err_clear: |
Eliad Peller | 3d2abdf | 2012-09-04 17:44:45 +0300 | [diff] [blame] | 3648 | memset(ifmgd->bssid, 0, ETH_ALEN); |
| 3649 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3650 | ifmgd->assoc_data = NULL; |
| 3651 | err_free: |
| 3652 | kfree(assoc_data); |
| 3653 | out: |
| 3654 | mutex_unlock(&ifmgd->mtx); |
| 3655 | |
| 3656 | return err; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3657 | } |
| 3658 | |
| 3659 | int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 63c9c5e | 2012-02-24 13:50:51 +0100 | [diff] [blame] | 3660 | struct cfg80211_deauth_request *req) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3661 | { |
| 3662 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 3663 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Stanislaw Gruszka | 6863255 | 2012-10-15 14:52:41 +0200 | [diff] [blame] | 3664 | bool tx = !req->local_state_change; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3665 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3666 | mutex_lock(&ifmgd->mtx); |
| 3667 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 3668 | if (ifmgd->auth_data) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3669 | ieee80211_destroy_auth_data(sdata, false); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3670 | mutex_unlock(&ifmgd->mtx); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3671 | return 0; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3672 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3673 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3674 | sdata_info(sdata, |
| 3675 | "deauthenticating from %pM by local choice (reason=%d)\n", |
| 3676 | req->bssid, req->reason_code); |
Johannes Berg | 0ff7161 | 2009-09-26 14:45:41 +0200 | [diff] [blame] | 3677 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 3678 | if (ifmgd->associated && |
Emmanuel Grumbach | 8c7d857 | 2012-07-25 01:42:36 +0300 | [diff] [blame] | 3679 | ether_addr_equal(ifmgd->associated->bssid, req->bssid)) { |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 3680 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
Stanislaw Gruszka | 6863255 | 2012-10-15 14:52:41 +0200 | [diff] [blame] | 3681 | req->reason_code, tx, frame_buf); |
Emmanuel Grumbach | 8c7d857 | 2012-07-25 01:42:36 +0300 | [diff] [blame] | 3682 | } else { |
| 3683 | drv_mgd_prepare_tx(sdata->local, sdata); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 3684 | ieee80211_send_deauth_disassoc(sdata, req->bssid, |
| 3685 | IEEE80211_STYPE_DEAUTH, |
Stanislaw Gruszka | 6863255 | 2012-10-15 14:52:41 +0200 | [diff] [blame] | 3686 | req->reason_code, tx, |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 3687 | frame_buf); |
Emmanuel Grumbach | 8c7d857 | 2012-07-25 01:42:36 +0300 | [diff] [blame] | 3688 | } |
| 3689 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 3690 | mutex_unlock(&ifmgd->mtx); |
| 3691 | |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 3692 | __cfg80211_send_deauth(sdata->dev, frame_buf, |
| 3693 | IEEE80211_DEAUTH_FRAME_LEN); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3694 | |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 3695 | mutex_lock(&sdata->local->mtx); |
Johannes Berg | bc83b68 | 2009-11-29 12:19:06 +0100 | [diff] [blame] | 3696 | ieee80211_recalc_idle(sdata->local); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 3697 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | bc83b68 | 2009-11-29 12:19:06 +0100 | [diff] [blame] | 3698 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3699 | return 0; |
| 3700 | } |
| 3701 | |
| 3702 | int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 63c9c5e | 2012-02-24 13:50:51 +0100 | [diff] [blame] | 3703 | struct cfg80211_disassoc_request *req) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3704 | { |
| 3705 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 3706 | u8 bssid[ETH_ALEN]; |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 3707 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3708 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3709 | mutex_lock(&ifmgd->mtx); |
| 3710 | |
Johannes Berg | 8d8b261 | 2009-07-25 11:58:36 +0200 | [diff] [blame] | 3711 | /* |
| 3712 | * cfg80211 should catch this ... but it's racy since |
| 3713 | * we can receive a disassoc frame, process it, hand it |
| 3714 | * to cfg80211 while that's in a locked section already |
| 3715 | * trying to tell us that the user wants to disconnect. |
| 3716 | */ |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 3717 | if (ifmgd->associated != req->bss) { |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3718 | mutex_unlock(&ifmgd->mtx); |
| 3719 | return -ENOLINK; |
| 3720 | } |
| 3721 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3722 | sdata_info(sdata, |
| 3723 | "disassociating from %pM by local choice (reason=%d)\n", |
| 3724 | req->bss->bssid, req->reason_code); |
Johannes Berg | 0ff7161 | 2009-09-26 14:45:41 +0200 | [diff] [blame] | 3725 | |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 3726 | memcpy(bssid, req->bss->bssid, ETH_ALEN); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 3727 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC, |
| 3728 | req->reason_code, !req->local_state_change, |
| 3729 | frame_buf); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3730 | mutex_unlock(&ifmgd->mtx); |
| 3731 | |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 3732 | __cfg80211_send_disassoc(sdata->dev, frame_buf, |
| 3733 | IEEE80211_DEAUTH_FRAME_LEN); |
Johannes Berg | bc83b68 | 2009-11-29 12:19:06 +0100 | [diff] [blame] | 3734 | |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 3735 | mutex_lock(&sdata->local->mtx); |
Johannes Berg | bc83b68 | 2009-11-29 12:19:06 +0100 | [diff] [blame] | 3736 | ieee80211_recalc_idle(sdata->local); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 3737 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | bc83b68 | 2009-11-29 12:19:06 +0100 | [diff] [blame] | 3738 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3739 | return 0; |
| 3740 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 3741 | |
Eliad Peller | afa762f | 2012-04-23 14:45:15 +0300 | [diff] [blame] | 3742 | void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 54e4ffb | 2012-02-25 21:48:08 +0100 | [diff] [blame] | 3743 | { |
| 3744 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3745 | |
| 3746 | mutex_lock(&ifmgd->mtx); |
| 3747 | if (ifmgd->assoc_data) |
| 3748 | ieee80211_destroy_assoc_data(sdata, false); |
| 3749 | if (ifmgd->auth_data) |
| 3750 | ieee80211_destroy_auth_data(sdata, false); |
| 3751 | del_timer_sync(&ifmgd->timer); |
| 3752 | mutex_unlock(&ifmgd->mtx); |
| 3753 | } |
| 3754 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 3755 | void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif, |
| 3756 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 3757 | gfp_t gfp) |
| 3758 | { |
| 3759 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 3760 | |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 3761 | trace_api_cqm_rssi_notify(sdata, rssi_event); |
| 3762 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 3763 | cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp); |
| 3764 | } |
| 3765 | EXPORT_SYMBOL(ieee80211_cqm_rssi_notify); |