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