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