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