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