Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2 | /* |
| 3 | * BSS client mode implementation |
Jouni Malinen | 5394af4 | 2009-01-08 13:31:59 +0200 | [diff] [blame] | 4 | * Copyright 2003-2008, Jouni Malinen <j@w1.fi> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 5 | * Copyright 2004, Instant802 Networks, Inc. |
| 6 | * Copyright 2005, Devicescape Software, Inc. |
| 7 | * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> |
| 8 | * Copyright 2007, Michael Wu <flamingice@sourmilk.net> |
Johannes Berg | d98ad83 | 2014-09-03 15:24:57 +0300 | [diff] [blame] | 9 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
Avraham Stern | e38a017 | 2017-04-26 10:58:47 +0300 | [diff] [blame] | 10 | * Copyright (C) 2015 - 2017 Intel Deutschland GmbH |
Sara Sharon | 2bf973f | 2020-01-31 13:12:51 +0200 | [diff] [blame] | 11 | * Copyright (C) 2018 - 2020 Intel Corporation |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 12 | */ |
| 13 | |
Geert Uytterhoeven | 5b323ed | 2007-05-08 18:40:27 -0700 | [diff] [blame] | 14 | #include <linux/delay.h> |
Ard Biesheuvel | 5fdb373 | 2019-06-12 18:19:54 +0200 | [diff] [blame] | 15 | #include <linux/fips.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 16 | #include <linux/if_ether.h> |
| 17 | #include <linux/skbuff.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 18 | #include <linux/if_arp.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 19 | #include <linux/etherdevice.h> |
Paul Gortmaker | d9b9384 | 2011-09-18 13:21:27 -0400 | [diff] [blame] | 20 | #include <linux/moduleparam.h> |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 21 | #include <linux/rtnetlink.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 | 60f8b39c | 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" |
Jouni Malinen | 39404fe | 2016-10-27 00:42:05 +0300 | [diff] [blame] | 32 | #include "fils_aead.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 33 | |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 34 | #define IEEE80211_AUTH_TIMEOUT (HZ / 5) |
Johannes Berg | cb236d2 | 2013-07-29 23:07:43 +0200 | [diff] [blame] | 35 | #define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2) |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 36 | #define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10) |
Ilan Peer | 407879b | 2018-04-20 13:49:20 +0300 | [diff] [blame] | 37 | #define IEEE80211_AUTH_TIMEOUT_SAE (HZ * 2) |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 38 | #define IEEE80211_AUTH_MAX_TRIES 3 |
| 39 | #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5) |
| 40 | #define IEEE80211_ASSOC_TIMEOUT (HZ / 5) |
Johannes Berg | cb236d2 | 2013-07-29 23:07:43 +0200 | [diff] [blame] | 41 | #define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2) |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 42 | #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10) |
| 43 | #define IEEE80211_ASSOC_MAX_TRIES 3 |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 44 | |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 45 | static int max_nullfunc_tries = 2; |
| 46 | module_param(max_nullfunc_tries, int, 0644); |
| 47 | MODULE_PARM_DESC(max_nullfunc_tries, |
| 48 | "Maximum nullfunc tx tries before disconnecting (reason 4)."); |
| 49 | |
| 50 | static int max_probe_tries = 5; |
| 51 | module_param(max_probe_tries, int, 0644); |
| 52 | MODULE_PARM_DESC(max_probe_tries, |
| 53 | "Maximum probe tries before disconnecting (reason 4)."); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 54 | |
| 55 | /* |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 56 | * Beacon loss timeout is calculated as N frames times the |
| 57 | * advertised beacon interval. This may need to be somewhat |
| 58 | * higher than what hardware might detect to account for |
| 59 | * delays in the host processing frames. But since we also |
| 60 | * probe on beacon miss before declaring the connection lost |
| 61 | * default to what we want. |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 62 | */ |
Ben Greear | 59c1ec2 | 2013-03-19 14:19:56 -0700 | [diff] [blame] | 63 | static int beacon_loss_count = 7; |
| 64 | module_param(beacon_loss_count, int, 0644); |
| 65 | MODULE_PARM_DESC(beacon_loss_count, |
| 66 | "Number of beacon intervals before we decide beacon was lost."); |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 67 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 68 | /* |
| 69 | * Time the connection can be idle before we probe |
| 70 | * it to see if we can still talk to the AP. |
| 71 | */ |
Maxim Levitsky | d1c5091 | 2009-07-31 18:54:23 +0300 | [diff] [blame] | 72 | #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 73 | /* |
| 74 | * Time we wait for a probe response after sending |
| 75 | * a probe request because of beacon loss or for |
| 76 | * checking the connection still works. |
| 77 | */ |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 78 | static int probe_wait_ms = 500; |
| 79 | module_param(probe_wait_ms, int, 0644); |
| 80 | MODULE_PARM_DESC(probe_wait_ms, |
| 81 | "Maximum time(ms) to wait for probe response" |
| 82 | " before disconnecting (reason 4)."); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 83 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 84 | /* |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 85 | * How many Beacon frames need to have been used in average signal strength |
| 86 | * before starting to indicate signal change events. |
| 87 | */ |
| 88 | #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4 |
| 89 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 90 | /* |
Johannes Berg | ca386f3 | 2009-07-10 02:39:48 +0200 | [diff] [blame] | 91 | * We can have multiple work items (and connection probing) |
| 92 | * scheduling this timer, but we need to take care to only |
| 93 | * reschedule it when it should fire _earlier_ than it was |
| 94 | * asked for before, or if it's not pending right now. This |
| 95 | * function ensures that. Note that it then is required to |
| 96 | * run this function for all timeouts after the first one |
| 97 | * has happened -- the work that runs from this timer will |
| 98 | * do that. |
| 99 | */ |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 100 | static void run_again(struct ieee80211_sub_if_data *sdata, |
| 101 | unsigned long timeout) |
Johannes Berg | ca386f3 | 2009-07-10 02:39:48 +0200 | [diff] [blame] | 102 | { |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 103 | sdata_assert_lock(sdata); |
Johannes Berg | ca386f3 | 2009-07-10 02:39:48 +0200 | [diff] [blame] | 104 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 105 | if (!timer_pending(&sdata->u.mgd.timer) || |
| 106 | time_before(timeout, sdata->u.mgd.timer.expires)) |
| 107 | mod_timer(&sdata->u.mgd.timer, timeout); |
Johannes Berg | ca386f3 | 2009-07-10 02:39:48 +0200 | [diff] [blame] | 108 | } |
| 109 | |
Luis R. Rodriguez | d3a910a | 2010-09-16 15:12:32 -0400 | [diff] [blame] | 110 | void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 111 | { |
Johannes Berg | c1288b1 | 2012-01-19 09:29:57 +0100 | [diff] [blame] | 112 | if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 113 | return; |
| 114 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 115 | if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR)) |
Johannes Berg | 7eeff74 | 2012-07-18 10:27:27 +0200 | [diff] [blame] | 116 | return; |
| 117 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 118 | mod_timer(&sdata->u.mgd.bcn_mon_timer, |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 119 | round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout)); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 120 | } |
| 121 | |
Luis R. Rodriguez | be099e8 | 2010-09-16 15:12:29 -0400 | [diff] [blame] | 122 | void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata) |
| 123 | { |
Luis R. Rodriguez | 0c699c3 | 2010-09-16 15:12:30 -0400 | [diff] [blame] | 124 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 125 | |
Johannes Berg | b100e5d | 2016-03-17 15:41:37 +0200 | [diff] [blame] | 126 | if (unlikely(!ifmgd->associated)) |
Stanislaw Gruszka | 8628172 | 2011-02-25 14:46:02 +0100 | [diff] [blame] | 127 | return; |
| 128 | |
Johannes Berg | b100e5d | 2016-03-17 15:41:37 +0200 | [diff] [blame] | 129 | if (ifmgd->probe_send_count) |
| 130 | ifmgd->probe_send_count = 0; |
Eliad Peller | 448cd2e | 2014-02-11 12:30:18 +0200 | [diff] [blame] | 131 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 132 | if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR)) |
Luis R. Rodriguez | be099e8 | 2010-09-16 15:12:29 -0400 | [diff] [blame] | 133 | return; |
| 134 | |
Johannes Berg | b100e5d | 2016-03-17 15:41:37 +0200 | [diff] [blame] | 135 | mod_timer(&ifmgd->conn_mon_timer, |
Luis R. Rodriguez | be099e8 | 2010-09-16 15:12:29 -0400 | [diff] [blame] | 136 | round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME)); |
| 137 | } |
| 138 | |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 139 | static int ecw2cw(int ecw) |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 140 | { |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 141 | return (1 << ecw) - 1; |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 142 | } |
| 143 | |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 144 | static u32 |
| 145 | ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata, |
| 146 | struct ieee80211_supported_band *sband, |
| 147 | struct ieee80211_channel *channel, |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 148 | u32 vht_cap_info, |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 149 | const struct ieee80211_ht_operation *ht_oper, |
| 150 | const struct ieee80211_vht_operation *vht_oper, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 151 | const struct ieee80211_he_operation *he_oper, |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 152 | struct cfg80211_chan_def *chandef, bool tracking) |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 153 | { |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 154 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 155 | struct cfg80211_chan_def vht_chandef; |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 156 | struct ieee80211_sta_ht_cap sta_ht_cap; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 157 | u32 ht_cfreq, ret; |
| 158 | |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 159 | memset(chandef, 0, sizeof(struct cfg80211_chan_def)); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 160 | chandef->chan = channel; |
| 161 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 162 | chandef->center_freq1 = channel->center_freq; |
Thomas Pedersen | b6011960 | 2020-04-01 18:18:04 -0700 | [diff] [blame] | 163 | chandef->freq1_offset = channel->freq_offset; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 164 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 165 | if (channel->band == NL80211_BAND_6GHZ) { |
| 166 | if (!ieee80211_chandef_he_6ghz_oper(sdata, he_oper, chandef)) |
| 167 | ret = IEEE80211_STA_DISABLE_HT | |
| 168 | IEEE80211_STA_DISABLE_VHT | |
| 169 | IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 523f3ec | 2020-06-03 11:15:03 +0200 | [diff] [blame] | 170 | else |
| 171 | ret = 0; |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 172 | vht_chandef = *chandef; |
| 173 | goto out; |
| 174 | } |
| 175 | |
| 176 | memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap)); |
| 177 | ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap); |
| 178 | |
Johannes Berg | b1b1ae2 | 2017-10-13 15:26:01 +0300 | [diff] [blame] | 179 | if (!ht_oper || !sta_ht_cap.ht_supported) { |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 180 | ret = IEEE80211_STA_DISABLE_HT | |
| 181 | IEEE80211_STA_DISABLE_VHT | |
| 182 | IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 183 | goto out; |
| 184 | } |
| 185 | |
| 186 | chandef->width = NL80211_CHAN_WIDTH_20; |
| 187 | |
| 188 | ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan, |
| 189 | channel->band); |
| 190 | /* check that channel matches the right operating channel */ |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 191 | if (!tracking && channel->center_freq != ht_cfreq) { |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 192 | /* |
| 193 | * It's possible that some APs are confused here; |
| 194 | * Netgear WNDR3700 sometimes reports 4 higher than |
| 195 | * the actual channel in association responses, but |
| 196 | * since we look at probe response/beacon data here |
| 197 | * it should be OK. |
| 198 | */ |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 199 | sdata_info(sdata, |
| 200 | "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n", |
| 201 | channel->center_freq, ht_cfreq, |
| 202 | ht_oper->primary_chan, channel->band); |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 203 | ret = IEEE80211_STA_DISABLE_HT | |
| 204 | IEEE80211_STA_DISABLE_VHT | |
| 205 | IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 206 | goto out; |
| 207 | } |
| 208 | |
| 209 | /* check 40 MHz support, if we have it */ |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 210 | if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) { |
Johannes Berg | 8ac3c704 | 2015-12-18 15:08:34 +0100 | [diff] [blame] | 211 | ieee80211_chandef_ht_oper(ht_oper, chandef); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 212 | } else { |
| 213 | /* 40 MHz (and 80 MHz) must be supported for VHT */ |
| 214 | ret = IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 85220d7 | 2013-03-25 18:29:27 +0100 | [diff] [blame] | 215 | /* also mark 40 MHz disabled */ |
| 216 | ret |= IEEE80211_STA_DISABLE_40MHZ; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 217 | goto out; |
| 218 | } |
| 219 | |
| 220 | if (!vht_oper || !sband->vht_cap.vht_supported) { |
| 221 | ret = IEEE80211_STA_DISABLE_VHT; |
| 222 | goto out; |
| 223 | } |
| 224 | |
Johannes Berg | 8ac3c704 | 2015-12-18 15:08:34 +0100 | [diff] [blame] | 225 | vht_chandef = *chandef; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 226 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && he_oper && |
| 227 | (le32_to_cpu(he_oper->he_oper_params) & |
| 228 | IEEE80211_HE_OPERATION_VHT_OPER_INFO)) { |
| 229 | struct ieee80211_vht_operation he_oper_vht_cap; |
| 230 | |
| 231 | /* |
| 232 | * Set only first 3 bytes (other 2 aren't used in |
| 233 | * ieee80211_chandef_vht_oper() anyway) |
| 234 | */ |
| 235 | memcpy(&he_oper_vht_cap, he_oper->optional, 3); |
| 236 | he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0); |
| 237 | |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 238 | if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_cap_info, |
Johannes Berg | 7eb26df | 2018-08-31 11:31:18 +0300 | [diff] [blame] | 239 | &he_oper_vht_cap, ht_oper, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 240 | &vht_chandef)) { |
| 241 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) |
| 242 | sdata_info(sdata, |
| 243 | "HE AP VHT information is invalid, disable HE\n"); |
| 244 | ret = IEEE80211_STA_DISABLE_HE; |
| 245 | goto out; |
| 246 | } |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 247 | } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw, |
| 248 | vht_cap_info, |
| 249 | vht_oper, ht_oper, |
| 250 | &vht_chandef)) { |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 251 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 252 | sdata_info(sdata, |
Johannes Berg | 8ac3c704 | 2015-12-18 15:08:34 +0100 | [diff] [blame] | 253 | "AP VHT information is invalid, disable VHT\n"); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 254 | ret = IEEE80211_STA_DISABLE_VHT; |
| 255 | goto out; |
| 256 | } |
| 257 | |
| 258 | if (!cfg80211_chandef_valid(&vht_chandef)) { |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 259 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 260 | sdata_info(sdata, |
| 261 | "AP VHT information is invalid, disable VHT\n"); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 262 | ret = IEEE80211_STA_DISABLE_VHT; |
| 263 | goto out; |
| 264 | } |
| 265 | |
| 266 | if (cfg80211_chandef_identical(chandef, &vht_chandef)) { |
| 267 | ret = 0; |
| 268 | goto out; |
| 269 | } |
| 270 | |
| 271 | if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) { |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 272 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 273 | sdata_info(sdata, |
| 274 | "AP VHT information doesn't match HT, disable VHT\n"); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 275 | ret = IEEE80211_STA_DISABLE_VHT; |
| 276 | goto out; |
| 277 | } |
| 278 | |
| 279 | *chandef = vht_chandef; |
| 280 | |
| 281 | ret = 0; |
| 282 | |
| 283 | out: |
Johannes Berg | 963a1852 | 2014-02-21 20:34:34 +0100 | [diff] [blame] | 284 | /* |
| 285 | * When tracking the current AP, don't do any further checks if the |
| 286 | * new chandef is identical to the one we're currently using for the |
| 287 | * connection. This keeps us from playing ping-pong with regulatory, |
| 288 | * without it the following can happen (for example): |
| 289 | * - connect to an AP with 80 MHz, world regdom allows 80 MHz |
| 290 | * - AP advertises regdom US |
| 291 | * - CRDA loads regdom US with 80 MHz prohibited (old database) |
| 292 | * - the code below detects an unsupported channel, downgrades, and |
| 293 | * we disconnect from the AP in the caller |
| 294 | * - disconnect causes CRDA to reload world regdomain and the game |
| 295 | * starts anew. |
| 296 | * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881) |
| 297 | * |
| 298 | * It seems possible that there are still scenarios with CSA or real |
| 299 | * bandwidth changes where a this could happen, but those cases are |
| 300 | * less common and wouldn't completely prevent using the AP. |
| 301 | */ |
| 302 | if (tracking && |
| 303 | cfg80211_chandef_identical(chandef, &sdata->vif.bss_conf.chandef)) |
| 304 | return ret; |
| 305 | |
Johannes Berg | 586e01e | 2013-02-14 12:13:53 +0100 | [diff] [blame] | 306 | /* don't print the message below for VHT mismatch if VHT is disabled */ |
| 307 | if (ret & IEEE80211_STA_DISABLE_VHT) |
| 308 | vht_chandef = *chandef; |
| 309 | |
Johannes Berg | ddfe49b | 2013-07-31 20:52:03 +0200 | [diff] [blame] | 310 | /* |
| 311 | * Ignore the DISABLED flag when we're already connected and only |
| 312 | * tracking the APs beacon for bandwidth changes - otherwise we |
| 313 | * might get disconnected here if we connect to an AP, update our |
| 314 | * regulatory information based on the AP's country IE and the |
| 315 | * information we have is wrong/outdated and disables the channel |
| 316 | * that we're actually using for the connection to the AP. |
| 317 | */ |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 318 | while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef, |
Johannes Berg | ddfe49b | 2013-07-31 20:52:03 +0200 | [diff] [blame] | 319 | tracking ? 0 : |
| 320 | IEEE80211_CHAN_DISABLED)) { |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 321 | if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) { |
| 322 | ret = IEEE80211_STA_DISABLE_HT | |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 323 | IEEE80211_STA_DISABLE_VHT | |
| 324 | IEEE80211_STA_DISABLE_HE; |
Chris Wright | b56e4b8 | 2013-07-31 12:12:24 -0700 | [diff] [blame] | 325 | break; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 326 | } |
| 327 | |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 328 | ret |= ieee80211_chandef_downgrade(chandef); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 329 | } |
| 330 | |
Daniel Gabay | 8cadb20 | 2020-01-31 13:12:52 +0200 | [diff] [blame] | 331 | if (!he_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef, |
| 332 | IEEE80211_CHAN_NO_HE)) |
Haim Dreyfuss | b5db1ac | 2020-01-31 13:12:44 +0200 | [diff] [blame] | 333 | ret |= IEEE80211_STA_DISABLE_HE; |
| 334 | |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 335 | if (chandef->width != vht_chandef.width && !tracking) |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 336 | sdata_info(sdata, |
| 337 | "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n"); |
| 338 | |
| 339 | WARN_ON_ONCE(!cfg80211_chandef_valid(chandef)); |
| 340 | return ret; |
| 341 | } |
| 342 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 343 | static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata, |
| 344 | struct sta_info *sta, |
Eliad Peller | 53b954e | 2014-07-24 11:20:05 +0300 | [diff] [blame] | 345 | const struct ieee80211_ht_cap *ht_cap, |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 346 | const struct ieee80211_vht_cap *vht_cap, |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 347 | const struct ieee80211_ht_operation *ht_oper, |
| 348 | const struct ieee80211_vht_operation *vht_oper, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 349 | const struct ieee80211_he_operation *he_oper, |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 350 | const u8 *bssid, u32 *changed) |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 351 | { |
| 352 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 353 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 354 | struct ieee80211_channel *chan = sdata->vif.bss_conf.chandef.chan; |
| 355 | struct ieee80211_supported_band *sband = |
| 356 | local->hw.wiphy->bands[chan->band]; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 357 | struct cfg80211_chan_def chandef; |
Johannes Berg | 9ed6bcc | 2009-05-08 20:47:39 +0200 | [diff] [blame] | 358 | u16 ht_opmode; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 359 | u32 flags; |
| 360 | enum ieee80211_sta_rx_bandwidth new_sta_bw; |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 361 | u32 vht_cap_info = 0; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 362 | int ret; |
| 363 | |
| 364 | /* if HT was/is disabled, don't track any bandwidth changes */ |
| 365 | if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper) |
| 366 | return 0; |
| 367 | |
| 368 | /* don't check VHT if we associated as non-VHT station */ |
| 369 | if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT) |
| 370 | vht_oper = NULL; |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 371 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 372 | /* don't check HE if we associated as non-HE station */ |
| 373 | if (ifmgd->flags & IEEE80211_STA_DISABLE_HE || |
| 374 | !ieee80211_get_he_sta_cap(sband)) |
| 375 | he_oper = NULL; |
| 376 | |
Johannes Berg | 1128958 | 2013-02-07 17:36:12 +0100 | [diff] [blame] | 377 | if (WARN_ON_ONCE(!sta)) |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 378 | return -EINVAL; |
Johannes Berg | 1128958 | 2013-02-07 17:36:12 +0100 | [diff] [blame] | 379 | |
Avri Altman | 017b45b | 2013-11-18 19:06:48 +0200 | [diff] [blame] | 380 | /* |
| 381 | * if bss configuration changed store the new one - |
| 382 | * this may be applicable even if channel is identical |
| 383 | */ |
| 384 | ht_opmode = le16_to_cpu(ht_oper->operation_mode); |
| 385 | if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) { |
| 386 | *changed |= BSS_CHANGED_HT; |
| 387 | sdata->vif.bss_conf.ht_operation_mode = ht_opmode; |
| 388 | } |
| 389 | |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 390 | if (vht_cap) |
| 391 | vht_cap_info = le32_to_cpu(vht_cap->vht_cap_info); |
| 392 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 393 | /* calculate new channel (type) based on HT/VHT/HE operation IEs */ |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 394 | flags = ieee80211_determine_chantype(sdata, sband, chan, vht_cap_info, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 395 | ht_oper, vht_oper, he_oper, |
Eliad Peller | 53b954e | 2014-07-24 11:20:05 +0300 | [diff] [blame] | 396 | &chandef, true); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 397 | |
| 398 | /* |
| 399 | * Downgrade the new channel if we associated with restricted |
| 400 | * capabilities. For example, if we associated as a 20 MHz STA |
| 401 | * to a 40 MHz AP (due to regulatory, capabilities or config |
| 402 | * reasons) then switching to a 40 MHz channel now won't do us |
| 403 | * any good -- we couldn't use it with the AP. |
| 404 | */ |
| 405 | if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ && |
| 406 | chandef.width == NL80211_CHAN_WIDTH_80P80) |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 407 | flags |= ieee80211_chandef_downgrade(&chandef); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 408 | if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ && |
| 409 | chandef.width == NL80211_CHAN_WIDTH_160) |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 410 | flags |= ieee80211_chandef_downgrade(&chandef); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 411 | if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ && |
| 412 | chandef.width > NL80211_CHAN_WIDTH_20) |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 413 | flags |= ieee80211_chandef_downgrade(&chandef); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 414 | |
| 415 | if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef)) |
| 416 | return 0; |
| 417 | |
| 418 | sdata_info(sdata, |
Thomas Pedersen | b6011960 | 2020-04-01 18:18:04 -0700 | [diff] [blame] | 419 | "AP %pM changed bandwidth, new config is %d.%03d MHz, " |
| 420 | "width %d (%d.%03d/%d MHz)\n", |
| 421 | ifmgd->bssid, chandef.chan->center_freq, |
| 422 | chandef.chan->freq_offset, chandef.width, |
| 423 | chandef.center_freq1, chandef.freq1_offset, |
| 424 | chandef.center_freq2); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 425 | |
| 426 | if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT | |
| 427 | IEEE80211_STA_DISABLE_VHT | |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 428 | IEEE80211_STA_DISABLE_HE | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 429 | IEEE80211_STA_DISABLE_40MHZ | |
| 430 | IEEE80211_STA_DISABLE_80P80MHZ | |
| 431 | IEEE80211_STA_DISABLE_160MHZ)) || |
| 432 | !cfg80211_chandef_valid(&chandef)) { |
| 433 | sdata_info(sdata, |
| 434 | "AP %pM changed bandwidth in a way we can't support - disconnect\n", |
| 435 | ifmgd->bssid); |
| 436 | return -EINVAL; |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 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 | switch (chandef.width) { |
| 440 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 441 | case NL80211_CHAN_WIDTH_20: |
| 442 | new_sta_bw = IEEE80211_STA_RX_BW_20; |
| 443 | break; |
| 444 | case NL80211_CHAN_WIDTH_40: |
| 445 | new_sta_bw = IEEE80211_STA_RX_BW_40; |
| 446 | break; |
| 447 | case NL80211_CHAN_WIDTH_80: |
| 448 | new_sta_bw = IEEE80211_STA_RX_BW_80; |
| 449 | break; |
| 450 | case NL80211_CHAN_WIDTH_80P80: |
| 451 | case NL80211_CHAN_WIDTH_160: |
| 452 | new_sta_bw = IEEE80211_STA_RX_BW_160; |
| 453 | break; |
| 454 | default: |
| 455 | return -EINVAL; |
| 456 | } |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 457 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 458 | if (new_sta_bw > sta->cur_max_bandwidth) |
| 459 | new_sta_bw = sta->cur_max_bandwidth; |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 460 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 461 | if (new_sta_bw < sta->sta.bandwidth) { |
| 462 | sta->sta.bandwidth = new_sta_bw; |
| 463 | rate_control_rate_update(local, sband, sta, |
| 464 | IEEE80211_RC_BW_CHANGED); |
| 465 | } |
Rajkumar Manoharan | 7cc44ed | 2011-09-16 15:32:34 +0530 | [diff] [blame] | 466 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 467 | ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed); |
| 468 | if (ret) { |
| 469 | sdata_info(sdata, |
| 470 | "AP %pM changed bandwidth to incompatible one - disconnect\n", |
| 471 | ifmgd->bssid); |
| 472 | return ret; |
| 473 | } |
| 474 | |
| 475 | if (new_sta_bw > sta->sta.bandwidth) { |
| 476 | sta->sta.bandwidth = new_sta_bw; |
| 477 | rate_control_rate_update(local, sband, sta, |
| 478 | IEEE80211_RC_BW_CHANGED); |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 479 | } |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 480 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 481 | return 0; |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 482 | } |
| 483 | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 484 | /* frame sending functions */ |
| 485 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 486 | static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 487 | struct sk_buff *skb, u8 ap_ht_param, |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 488 | struct ieee80211_supported_band *sband, |
| 489 | struct ieee80211_channel *channel, |
| 490 | enum ieee80211_smps_mode smps) |
| 491 | { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 492 | u8 *pos; |
| 493 | u32 flags = channel->flags; |
| 494 | u16 cap; |
| 495 | struct ieee80211_sta_ht_cap ht_cap; |
| 496 | |
| 497 | BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap)); |
| 498 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 499 | memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap)); |
| 500 | ieee80211_apply_htcap_overrides(sdata, &ht_cap); |
| 501 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 502 | /* determine capability flags */ |
| 503 | cap = ht_cap.cap; |
| 504 | |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 505 | switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 506 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: |
| 507 | if (flags & IEEE80211_CHAN_NO_HT40PLUS) { |
| 508 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 509 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 510 | } |
| 511 | break; |
| 512 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: |
| 513 | if (flags & IEEE80211_CHAN_NO_HT40MINUS) { |
| 514 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 515 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 516 | } |
| 517 | break; |
| 518 | } |
| 519 | |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 520 | /* |
| 521 | * If 40 MHz was disabled associate as though we weren't |
| 522 | * capable of 40 MHz -- some broken APs will never fall |
| 523 | * back to trying to transmit in 20 MHz. |
| 524 | */ |
| 525 | if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) { |
| 526 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 527 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 528 | } |
| 529 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 530 | /* set SM PS mode properly */ |
| 531 | cap &= ~IEEE80211_HT_CAP_SM_PS; |
| 532 | switch (smps) { |
| 533 | case IEEE80211_SMPS_AUTOMATIC: |
| 534 | case IEEE80211_SMPS_NUM_MODES: |
| 535 | WARN_ON(1); |
Gustavo A. R. Silva | fc0561d | 2020-07-07 15:45:48 -0500 | [diff] [blame] | 536 | fallthrough; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 537 | case IEEE80211_SMPS_OFF: |
| 538 | cap |= WLAN_HT_CAP_SM_PS_DISABLED << |
| 539 | IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 540 | break; |
| 541 | case IEEE80211_SMPS_STATIC: |
| 542 | cap |= WLAN_HT_CAP_SM_PS_STATIC << |
| 543 | IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 544 | break; |
| 545 | case IEEE80211_SMPS_DYNAMIC: |
| 546 | cap |= WLAN_HT_CAP_SM_PS_DYNAMIC << |
| 547 | IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 548 | break; |
| 549 | } |
| 550 | |
| 551 | /* reserve and fill IE */ |
| 552 | pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2); |
| 553 | ieee80211_ie_build_ht_cap(pos, &ht_cap, cap); |
| 554 | } |
| 555 | |
Sara Sharon | 322cd40 | 2015-07-08 15:41:43 +0300 | [diff] [blame] | 556 | /* This function determines vht capability flags for the association |
| 557 | * and builds the IE. |
| 558 | * Note - the function may set the owner of the MU-MIMO capability |
| 559 | */ |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 560 | static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata, |
| 561 | struct sk_buff *skb, |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 562 | struct ieee80211_supported_band *sband, |
| 563 | struct ieee80211_vht_cap *ap_vht_cap) |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 564 | { |
Sara Sharon | 322cd40 | 2015-07-08 15:41:43 +0300 | [diff] [blame] | 565 | struct ieee80211_local *local = sdata->local; |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 566 | u8 *pos; |
| 567 | u32 cap; |
| 568 | struct ieee80211_sta_vht_cap vht_cap; |
Eyal Shapira | c1cf6d4 | 2014-01-08 15:49:08 +0200 | [diff] [blame] | 569 | u32 mask, ap_bf_sts, our_bf_sts; |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 570 | |
| 571 | BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap)); |
| 572 | |
| 573 | memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap)); |
Johannes Berg | dd5ecfe | 2013-02-21 17:40:19 +0100 | [diff] [blame] | 574 | ieee80211_apply_vhtcap_overrides(sdata, &vht_cap); |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 575 | |
| 576 | /* determine capability flags */ |
| 577 | cap = vht_cap.cap; |
| 578 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 579 | if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) { |
Johannes Berg | 575f053 | 2014-11-24 16:51:33 +0100 | [diff] [blame] | 580 | u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; |
| 581 | |
| 582 | cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; |
| 583 | if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ || |
| 584 | bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ) |
| 585 | cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) { |
| 589 | cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160; |
Johannes Berg | 575f053 | 2014-11-24 16:51:33 +0100 | [diff] [blame] | 590 | cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 591 | } |
| 592 | |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 593 | /* |
| 594 | * Some APs apparently get confused if our capabilities are better |
| 595 | * than theirs, so restrict what we advertise in the assoc request. |
| 596 | */ |
| 597 | if (!(ap_vht_cap->vht_cap_info & |
| 598 | cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE))) |
Sara Sharon | 322cd40 | 2015-07-08 15:41:43 +0300 | [diff] [blame] | 599 | cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
| 600 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE); |
| 601 | else if (!(ap_vht_cap->vht_cap_info & |
| 602 | cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))) |
| 603 | cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE; |
| 604 | |
| 605 | /* |
| 606 | * If some other vif is using the MU-MIMO capablity we cannot associate |
| 607 | * using MU-MIMO - this will lead to contradictions in the group-id |
| 608 | * mechanism. |
| 609 | * Ownership is defined since association request, in order to avoid |
| 610 | * simultaneous associations with MU-MIMO. |
| 611 | */ |
| 612 | if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) { |
| 613 | bool disable_mu_mimo = false; |
| 614 | struct ieee80211_sub_if_data *other; |
| 615 | |
| 616 | list_for_each_entry_rcu(other, &local->interfaces, list) { |
Sara Sharon | b5a33d5 | 2016-02-16 12:48:18 +0200 | [diff] [blame] | 617 | if (other->vif.mu_mimo_owner) { |
Sara Sharon | 322cd40 | 2015-07-08 15:41:43 +0300 | [diff] [blame] | 618 | disable_mu_mimo = true; |
| 619 | break; |
| 620 | } |
| 621 | } |
| 622 | if (disable_mu_mimo) |
| 623 | cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE; |
| 624 | else |
Sara Sharon | b5a33d5 | 2016-02-16 12:48:18 +0200 | [diff] [blame] | 625 | sdata->vif.mu_mimo_owner = true; |
Sara Sharon | 322cd40 | 2015-07-08 15:41:43 +0300 | [diff] [blame] | 626 | } |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 627 | |
Eyal Shapira | c1cf6d4 | 2014-01-08 15:49:08 +0200 | [diff] [blame] | 628 | mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK; |
| 629 | |
| 630 | ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask; |
| 631 | our_bf_sts = cap & mask; |
| 632 | |
| 633 | if (ap_bf_sts < our_bf_sts) { |
| 634 | cap &= ~mask; |
| 635 | cap |= ap_bf_sts; |
| 636 | } |
| 637 | |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 638 | /* reserve and fill IE */ |
Mahesh Palivela | d495028 | 2012-10-10 11:25:40 +0000 | [diff] [blame] | 639 | pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2); |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 640 | ieee80211_ie_build_vht_cap(pos, &vht_cap, cap); |
| 641 | } |
| 642 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 643 | /* This function determines HE capability flags for the association |
| 644 | * and builds the IE. |
| 645 | */ |
| 646 | static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata, |
| 647 | struct sk_buff *skb, |
| 648 | struct ieee80211_supported_band *sband) |
| 649 | { |
| 650 | u8 *pos; |
| 651 | const struct ieee80211_sta_he_cap *he_cap = NULL; |
Haim Dreyfuss | b5db1ac | 2020-01-31 13:12:44 +0200 | [diff] [blame] | 652 | struct ieee80211_chanctx_conf *chanctx_conf; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 653 | u8 he_cap_size; |
Haim Dreyfuss | b5db1ac | 2020-01-31 13:12:44 +0200 | [diff] [blame] | 654 | bool reg_cap = false; |
| 655 | |
| 656 | rcu_read_lock(); |
| 657 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 658 | if (!WARN_ON_ONCE(!chanctx_conf)) |
| 659 | reg_cap = cfg80211_chandef_usable(sdata->wdev.wiphy, |
| 660 | &chanctx_conf->def, |
| 661 | IEEE80211_CHAN_NO_HE); |
| 662 | |
| 663 | rcu_read_unlock(); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 664 | |
| 665 | he_cap = ieee80211_get_he_sta_cap(sband); |
Haim Dreyfuss | b5db1ac | 2020-01-31 13:12:44 +0200 | [diff] [blame] | 666 | if (!he_cap || !reg_cap) |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 667 | return; |
| 668 | |
| 669 | /* |
| 670 | * TODO: the 1 added is because this temporarily is under the EXTENSION |
| 671 | * IE. Get rid of it when it moves. |
| 672 | */ |
| 673 | he_cap_size = |
| 674 | 2 + 1 + sizeof(he_cap->he_cap_elem) + |
| 675 | ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) + |
| 676 | ieee80211_he_ppe_size(he_cap->ppe_thres[0], |
| 677 | he_cap->he_cap_elem.phy_cap_info); |
| 678 | pos = skb_put(skb, he_cap_size); |
| 679 | ieee80211_ie_build_he_cap(pos, he_cap, pos + he_cap_size); |
Rajkumar Manoharan | 24a2042 | 2020-05-28 21:34:32 +0200 | [diff] [blame] | 680 | |
| 681 | ieee80211_ie_build_he_6ghz_cap(sdata, skb); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 682 | } |
| 683 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 684 | static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata) |
| 685 | { |
| 686 | struct ieee80211_local *local = sdata->local; |
| 687 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 688 | struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; |
| 689 | struct sk_buff *skb; |
| 690 | struct ieee80211_mgmt *mgmt; |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 691 | u8 *pos, qos_info, *ie_start; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 692 | size_t offset = 0, noffset; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 693 | int i, count, rates_len, supp_rates_len, shift; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 694 | u16 capab; |
| 695 | struct ieee80211_supported_band *sband; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 696 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 697 | struct ieee80211_channel *chan; |
Johannes Berg | 44f6d42 | 2017-06-10 13:52:44 +0300 | [diff] [blame] | 698 | u32 rates = 0; |
Johannes Berg | 2ff69b0 | 2020-01-31 13:31:11 +0200 | [diff] [blame] | 699 | struct element *ext_capa = NULL; |
| 700 | |
| 701 | /* we know it's writable, cast away the const */ |
| 702 | if (assoc_data->ie_len) |
| 703 | ext_capa = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, |
| 704 | assoc_data->ie, |
| 705 | assoc_data->ie_len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 706 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 707 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 708 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 709 | rcu_read_lock(); |
| 710 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 711 | if (WARN_ON(!chanctx_conf)) { |
| 712 | rcu_read_unlock(); |
| 713 | return; |
| 714 | } |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 715 | chan = chanctx_conf->def.chan; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 716 | rcu_read_unlock(); |
| 717 | sband = local->hw.wiphy->bands[chan->band]; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 718 | shift = ieee80211_vif_get_shift(&sdata->vif); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 719 | |
| 720 | if (assoc_data->supp_rates_len) { |
| 721 | /* |
| 722 | * Get all rates supported by the device and the AP as |
| 723 | * some APs don't like getting a superset of their rates |
| 724 | * in the association request (e.g. D-Link DAP 1353 in |
| 725 | * b-only mode)... |
| 726 | */ |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 727 | rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband, |
| 728 | assoc_data->supp_rates, |
| 729 | assoc_data->supp_rates_len, |
| 730 | &rates); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 731 | } else { |
| 732 | /* |
| 733 | * In case AP not provide any supported rates information |
| 734 | * before association, we send information element(s) with |
| 735 | * all rates that we support. |
| 736 | */ |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 737 | rates_len = 0; |
| 738 | for (i = 0; i < sband->n_bitrates; i++) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 739 | rates |= BIT(i); |
| 740 | rates_len++; |
| 741 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | skb = alloc_skb(local->hw.extra_tx_headroom + |
| 745 | sizeof(*mgmt) + /* bit too much but doesn't matter */ |
| 746 | 2 + assoc_data->ssid_len + /* SSID */ |
| 747 | 4 + rates_len + /* (extended) rates */ |
| 748 | 4 + /* power capability */ |
| 749 | 2 + 2 * sband->n_channels + /* supported channels */ |
| 750 | 2 + sizeof(struct ieee80211_ht_cap) + /* HT */ |
Mahesh Palivela | d495028 | 2012-10-10 11:25:40 +0000 | [diff] [blame] | 751 | 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */ |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 752 | 2 + 1 + sizeof(struct ieee80211_he_cap_elem) + /* HE */ |
| 753 | sizeof(struct ieee80211_he_mcs_nss_supp) + |
| 754 | IEEE80211_HE_PPE_THRES_MAX_LEN + |
Rajkumar Manoharan | 24a2042 | 2020-05-28 21:34:32 +0200 | [diff] [blame] | 755 | 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa) + |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 756 | assoc_data->ie_len + /* extra IEs */ |
Jouni Malinen | 39404fe | 2016-10-27 00:42:05 +0300 | [diff] [blame] | 757 | (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) + |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 758 | 9, /* WMM */ |
| 759 | GFP_KERNEL); |
| 760 | if (!skb) |
| 761 | return; |
| 762 | |
| 763 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 764 | |
| 765 | capab = WLAN_CAPABILITY_ESS; |
| 766 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 767 | if (sband->band == NL80211_BAND_2GHZ) { |
Johannes Berg | ea1b2b45 | 2015-06-02 20:15:49 +0200 | [diff] [blame] | 768 | capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME; |
| 769 | capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY) |
| 773 | capab |= WLAN_CAPABILITY_PRIVACY; |
| 774 | |
| 775 | if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) && |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 776 | ieee80211_hw_check(&local->hw, SPECTRUM_MGMT)) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 777 | capab |= WLAN_CAPABILITY_SPECTRUM_MGMT; |
| 778 | |
Assaf Krauss | cd2f5dd | 2014-09-03 15:25:02 +0300 | [diff] [blame] | 779 | if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM) |
| 780 | capab |= WLAN_CAPABILITY_RADIO_MEASURE; |
| 781 | |
Johannes Berg | b080db5 | 2017-06-16 14:29:19 +0200 | [diff] [blame] | 782 | mgmt = skb_put_zero(skb, 24); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 783 | memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN); |
| 784 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
| 785 | memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN); |
| 786 | |
| 787 | if (!is_zero_ether_addr(assoc_data->prev_bssid)) { |
| 788 | skb_put(skb, 10); |
| 789 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 790 | IEEE80211_STYPE_REASSOC_REQ); |
| 791 | mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab); |
| 792 | mgmt->u.reassoc_req.listen_interval = |
| 793 | cpu_to_le16(local->hw.conf.listen_interval); |
| 794 | memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid, |
| 795 | ETH_ALEN); |
| 796 | } else { |
| 797 | skb_put(skb, 4); |
| 798 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 799 | IEEE80211_STYPE_ASSOC_REQ); |
| 800 | mgmt->u.assoc_req.capab_info = cpu_to_le16(capab); |
| 801 | mgmt->u.assoc_req.listen_interval = |
| 802 | cpu_to_le16(local->hw.conf.listen_interval); |
| 803 | } |
| 804 | |
| 805 | /* SSID */ |
| 806 | pos = skb_put(skb, 2 + assoc_data->ssid_len); |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 807 | ie_start = pos; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 808 | *pos++ = WLAN_EID_SSID; |
| 809 | *pos++ = assoc_data->ssid_len; |
| 810 | memcpy(pos, assoc_data->ssid, assoc_data->ssid_len); |
| 811 | |
| 812 | /* add all rates which were marked to be used above */ |
| 813 | supp_rates_len = rates_len; |
| 814 | if (supp_rates_len > 8) |
| 815 | supp_rates_len = 8; |
| 816 | |
| 817 | pos = skb_put(skb, supp_rates_len + 2); |
| 818 | *pos++ = WLAN_EID_SUPP_RATES; |
| 819 | *pos++ = supp_rates_len; |
| 820 | |
| 821 | count = 0; |
| 822 | for (i = 0; i < sband->n_bitrates; i++) { |
| 823 | if (BIT(i) & rates) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 824 | int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate, |
| 825 | 5 * (1 << shift)); |
| 826 | *pos++ = (u8) rate; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 827 | if (++count == 8) |
| 828 | break; |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | if (rates_len > count) { |
| 833 | pos = skb_put(skb, rates_len - count + 2); |
| 834 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 835 | *pos++ = rates_len - count; |
| 836 | |
| 837 | for (i++; i < sband->n_bitrates; i++) { |
| 838 | if (BIT(i) & rates) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 839 | int rate; |
| 840 | rate = DIV_ROUND_UP(sband->bitrates[i].bitrate, |
| 841 | 5 * (1 << shift)); |
| 842 | *pos++ = (u8) rate; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 843 | } |
| 844 | } |
| 845 | } |
| 846 | |
Assaf Krauss | cd2f5dd | 2014-09-03 15:25:02 +0300 | [diff] [blame] | 847 | if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT || |
| 848 | capab & WLAN_CAPABILITY_RADIO_MEASURE) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 849 | pos = skb_put(skb, 4); |
| 850 | *pos++ = WLAN_EID_PWR_CAPABILITY; |
| 851 | *pos++ = 2; |
| 852 | *pos++ = 0; /* min tx power */ |
Simon Wunderlich | 0430c88 | 2013-07-08 16:55:55 +0200 | [diff] [blame] | 853 | /* max tx power */ |
| 854 | *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def); |
Assaf Krauss | cd2f5dd | 2014-09-03 15:25:02 +0300 | [diff] [blame] | 855 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 856 | |
Johannes Berg | 2ff69b0 | 2020-01-31 13:31:11 +0200 | [diff] [blame] | 857 | /* |
| 858 | * Per spec, we shouldn't include the list of channels if we advertise |
| 859 | * support for extended channel switching, but we've always done that; |
| 860 | * (for now?) apply this restriction only on the (new) 6 GHz band. |
| 861 | */ |
| 862 | if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT && |
| 863 | (sband->band != NL80211_BAND_6GHZ || |
| 864 | !ext_capa || ext_capa->datalen < 1 || |
| 865 | !(ext_capa->data[0] & WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING))) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 866 | /* TODO: get this in reg domain format */ |
| 867 | pos = skb_put(skb, 2 * sband->n_channels + 2); |
| 868 | *pos++ = WLAN_EID_SUPPORTED_CHANNELS; |
| 869 | *pos++ = 2 * sband->n_channels; |
| 870 | for (i = 0; i < sband->n_channels; i++) { |
| 871 | *pos++ = ieee80211_frequency_to_channel( |
| 872 | sband->channels[i].center_freq); |
| 873 | *pos++ = 1; /* one channel in the subband*/ |
| 874 | } |
| 875 | } |
| 876 | |
Sara Sharon | caf5633 | 2019-01-16 23:03:25 +0200 | [diff] [blame] | 877 | /* Set MBSSID support for HE AP if needed */ |
| 878 | if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) && |
Johannes Berg | 2ff69b0 | 2020-01-31 13:31:11 +0200 | [diff] [blame] | 879 | !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && assoc_data->ie_len && |
| 880 | ext_capa && ext_capa->datalen >= 3) |
| 881 | ext_capa->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT; |
Sara Sharon | caf5633 | 2019-01-16 23:03:25 +0200 | [diff] [blame] | 882 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 883 | /* if present, add any custom IEs that go before HT */ |
Johannes Berg | b3f51e9 | 2013-10-25 11:31:42 +0200 | [diff] [blame] | 884 | if (assoc_data->ie_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 885 | static const u8 before_ht[] = { |
| 886 | WLAN_EID_SSID, |
| 887 | WLAN_EID_SUPP_RATES, |
| 888 | WLAN_EID_EXT_SUPP_RATES, |
| 889 | WLAN_EID_PWR_CAPABILITY, |
| 890 | WLAN_EID_SUPPORTED_CHANNELS, |
| 891 | WLAN_EID_RSN, |
| 892 | WLAN_EID_QOS_CAPA, |
| 893 | WLAN_EID_RRM_ENABLED_CAPABILITIES, |
| 894 | WLAN_EID_MOBILITY_DOMAIN, |
Johannes Berg | 8ed2874 | 2014-10-27 12:03:19 +0100 | [diff] [blame] | 895 | WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */ |
| 896 | WLAN_EID_RIC_DATA, /* reassoc only */ |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 897 | WLAN_EID_SUPPORTED_REGULATORY_CLASSES, |
| 898 | }; |
Johannes Berg | 8ed2874 | 2014-10-27 12:03:19 +0100 | [diff] [blame] | 899 | static const u8 after_ric[] = { |
| 900 | WLAN_EID_SUPPORTED_REGULATORY_CLASSES, |
| 901 | WLAN_EID_HT_CAPABILITY, |
| 902 | WLAN_EID_BSS_COEX_2040, |
Johannes Berg | a7f26d8 | 2017-08-05 11:44:32 +0300 | [diff] [blame] | 903 | /* luckily this is almost always there */ |
Johannes Berg | 8ed2874 | 2014-10-27 12:03:19 +0100 | [diff] [blame] | 904 | WLAN_EID_EXT_CAPABILITY, |
| 905 | WLAN_EID_QOS_TRAFFIC_CAPA, |
| 906 | WLAN_EID_TIM_BCAST_REQ, |
| 907 | WLAN_EID_INTERWORKING, |
Johannes Berg | a7f26d8 | 2017-08-05 11:44:32 +0300 | [diff] [blame] | 908 | /* 60 GHz (Multi-band, DMG, MMS) can't happen */ |
Johannes Berg | 8ed2874 | 2014-10-27 12:03:19 +0100 | [diff] [blame] | 909 | WLAN_EID_VHT_CAPABILITY, |
| 910 | WLAN_EID_OPMODE_NOTIF, |
| 911 | }; |
| 912 | |
| 913 | noffset = ieee80211_ie_split_ric(assoc_data->ie, |
| 914 | assoc_data->ie_len, |
| 915 | before_ht, |
| 916 | ARRAY_SIZE(before_ht), |
| 917 | after_ric, |
| 918 | ARRAY_SIZE(after_ric), |
| 919 | offset); |
yuan linyu | b952f4d | 2017-06-18 22:52:04 +0800 | [diff] [blame] | 920 | skb_put_data(skb, assoc_data->ie + offset, noffset - offset); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 921 | offset = noffset; |
| 922 | } |
| 923 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 924 | if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) && |
| 925 | !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))) |
| 926 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
| 927 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 928 | if (sband->band != NL80211_BAND_6GHZ && |
| 929 | !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 930 | ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param, |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 931 | sband, chan, sdata->smps_mode); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 932 | |
Johannes Berg | 3de3802 | 2014-02-04 09:54:07 +0100 | [diff] [blame] | 933 | /* if present, add any custom IEs that go before VHT */ |
| 934 | if (assoc_data->ie_len) { |
| 935 | static const u8 before_vht[] = { |
Johannes Berg | a7f26d8 | 2017-08-05 11:44:32 +0300 | [diff] [blame] | 936 | /* |
| 937 | * no need to list the ones split off before HT |
| 938 | * or generated here |
| 939 | */ |
Johannes Berg | 3de3802 | 2014-02-04 09:54:07 +0100 | [diff] [blame] | 940 | WLAN_EID_BSS_COEX_2040, |
| 941 | WLAN_EID_EXT_CAPABILITY, |
| 942 | WLAN_EID_QOS_TRAFFIC_CAPA, |
| 943 | WLAN_EID_TIM_BCAST_REQ, |
| 944 | WLAN_EID_INTERWORKING, |
Johannes Berg | a7f26d8 | 2017-08-05 11:44:32 +0300 | [diff] [blame] | 945 | /* 60 GHz (Multi-band, DMG, MMS) can't happen */ |
Johannes Berg | 3de3802 | 2014-02-04 09:54:07 +0100 | [diff] [blame] | 946 | }; |
Johannes Berg | 8ed2874 | 2014-10-27 12:03:19 +0100 | [diff] [blame] | 947 | |
| 948 | /* RIC already taken above, so no need to handle here anymore */ |
Johannes Berg | 3de3802 | 2014-02-04 09:54:07 +0100 | [diff] [blame] | 949 | noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len, |
| 950 | before_vht, ARRAY_SIZE(before_vht), |
| 951 | offset); |
yuan linyu | b952f4d | 2017-06-18 22:52:04 +0800 | [diff] [blame] | 952 | skb_put_data(skb, assoc_data->ie + offset, noffset - offset); |
Johannes Berg | 3de3802 | 2014-02-04 09:54:07 +0100 | [diff] [blame] | 953 | offset = noffset; |
| 954 | } |
| 955 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 956 | /* if present, add any custom IEs that go before HE */ |
| 957 | if (assoc_data->ie_len) { |
| 958 | static const u8 before_he[] = { |
| 959 | /* |
| 960 | * no need to list the ones split off before VHT |
| 961 | * or generated here |
| 962 | */ |
| 963 | WLAN_EID_OPMODE_NOTIF, |
| 964 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE, |
| 965 | /* 11ai elements */ |
| 966 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION, |
| 967 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY, |
| 968 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM, |
| 969 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER, |
| 970 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN, |
| 971 | /* TODO: add 11ah/11aj/11ak elements */ |
| 972 | }; |
| 973 | |
| 974 | /* RIC already taken above, so no need to handle here anymore */ |
| 975 | noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len, |
| 976 | before_he, ARRAY_SIZE(before_he), |
| 977 | offset); |
| 978 | pos = skb_put(skb, noffset - offset); |
| 979 | memcpy(pos, assoc_data->ie + offset, noffset - offset); |
| 980 | offset = noffset; |
| 981 | } |
| 982 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 983 | if (sband->band != NL80211_BAND_6GHZ && |
| 984 | !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 985 | ieee80211_add_vht_ie(sdata, skb, sband, |
| 986 | &assoc_data->ap_vht_cap); |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 987 | |
Shaul Triebitz | dc7eb0f | 2018-12-15 11:03:20 +0200 | [diff] [blame] | 988 | /* |
| 989 | * If AP doesn't support HT, mark HE as disabled. |
| 990 | * If on the 5GHz band, make sure it supports VHT. |
| 991 | */ |
| 992 | if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || |
| 993 | (sband->band == NL80211_BAND_5GHZ && |
| 994 | ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
| 995 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
| 996 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 997 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) |
| 998 | ieee80211_add_he_ie(sdata, skb, sband); |
| 999 | |
| 1000 | /* if present, add any custom non-vendor IEs that go after HE */ |
Johannes Berg | b3f51e9 | 2013-10-25 11:31:42 +0200 | [diff] [blame] | 1001 | if (assoc_data->ie_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1002 | noffset = ieee80211_ie_split_vendor(assoc_data->ie, |
| 1003 | assoc_data->ie_len, |
| 1004 | offset); |
yuan linyu | b952f4d | 2017-06-18 22:52:04 +0800 | [diff] [blame] | 1005 | skb_put_data(skb, assoc_data->ie + offset, noffset - offset); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1006 | offset = noffset; |
| 1007 | } |
| 1008 | |
Johannes Berg | 76f0303 | 2012-03-08 15:02:05 +0100 | [diff] [blame] | 1009 | if (assoc_data->wmm) { |
| 1010 | if (assoc_data->uapsd) { |
Eliad Peller | dc41e4d | 2012-03-14 16:15:03 +0200 | [diff] [blame] | 1011 | qos_info = ifmgd->uapsd_queues; |
| 1012 | qos_info |= (ifmgd->uapsd_max_sp_len << |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1013 | IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT); |
| 1014 | } else { |
| 1015 | qos_info = 0; |
| 1016 | } |
| 1017 | |
Arik Nemtsov | 40b861a | 2014-07-17 17:14:23 +0300 | [diff] [blame] | 1018 | pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | /* add any remaining custom (i.e. vendor specific here) IEs */ |
Johannes Berg | b3f51e9 | 2013-10-25 11:31:42 +0200 | [diff] [blame] | 1022 | if (assoc_data->ie_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1023 | noffset = assoc_data->ie_len; |
yuan linyu | b952f4d | 2017-06-18 22:52:04 +0800 | [diff] [blame] | 1024 | skb_put_data(skb, assoc_data->ie + offset, noffset - offset); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1025 | } |
| 1026 | |
Jouni Malinen | 39404fe | 2016-10-27 00:42:05 +0300 | [diff] [blame] | 1027 | if (assoc_data->fils_kek_len && |
| 1028 | fils_encrypt_assoc_req(skb, assoc_data) < 0) { |
| 1029 | dev_kfree_skb(skb); |
| 1030 | return; |
| 1031 | } |
| 1032 | |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 1033 | pos = skb_tail_pointer(skb); |
| 1034 | kfree(ifmgd->assoc_req_ies); |
| 1035 | ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC); |
| 1036 | ifmgd->assoc_req_ies_len = pos - ie_start; |
| 1037 | |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 1038 | drv_mgd_prepare_tx(local, sdata, 0); |
Johannes Berg | a1845fc | 2012-06-27 13:18:36 +0200 | [diff] [blame] | 1039 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1040 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1041 | if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 1042 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS | |
| 1043 | IEEE80211_TX_INTFL_MLME_CONN_TX; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1044 | ieee80211_tx_skb(sdata, skb); |
| 1045 | } |
| 1046 | |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1047 | void ieee80211_send_pspoll(struct ieee80211_local *local, |
| 1048 | struct ieee80211_sub_if_data *sdata) |
| 1049 | { |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1050 | struct ieee80211_pspoll *pspoll; |
| 1051 | struct sk_buff *skb; |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1052 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1053 | skb = ieee80211_pspoll_get(&local->hw, &sdata->vif); |
| 1054 | if (!skb) |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1055 | return; |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1056 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1057 | pspoll = (struct ieee80211_pspoll *) skb->data; |
| 1058 | pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1059 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 1060 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 1061 | ieee80211_tx_skb(sdata, skb); |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1062 | } |
| 1063 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1064 | void ieee80211_send_nullfunc(struct ieee80211_local *local, |
| 1065 | struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 076cdcb | 2015-09-24 16:14:55 +0200 | [diff] [blame] | 1066 | bool powersave) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1067 | { |
| 1068 | struct sk_buff *skb; |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1069 | struct ieee80211_hdr_3addr *nullfunc; |
Rajkumar Manoharan | b6f3530 | 2011-09-29 20:34:04 +0530 | [diff] [blame] | 1070 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1071 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 1072 | /* Don't send NDPs when STA is connected HE */ |
| 1073 | if (sdata->vif.type == NL80211_IFTYPE_STATION && |
| 1074 | !(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) |
| 1075 | return; |
| 1076 | |
Ben Caradoc-Davies | 7c181f4 | 2018-03-19 12:57:44 +1300 | [diff] [blame] | 1077 | skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif, |
| 1078 | !ieee80211_hw_check(&local->hw, DOESNT_SUPPORT_QOS_NDP)); |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1079 | if (!skb) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1080 | return; |
| 1081 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1082 | nullfunc = (struct ieee80211_hdr_3addr *) skb->data; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1083 | if (powersave) |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1084 | nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1085 | |
Seth Forshee | 6c17b77 | 2013-02-11 11:21:07 -0600 | [diff] [blame] | 1086 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT | |
| 1087 | IEEE80211_TX_INTFL_OFFCHAN_TX_OK; |
Pontus Fuchs | ff40b42 | 2013-06-04 12:44:52 +0200 | [diff] [blame] | 1088 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1089 | if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
Pontus Fuchs | ff40b42 | 2013-06-04 12:44:52 +0200 | [diff] [blame] | 1090 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; |
| 1091 | |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 1092 | if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) |
Rajkumar Manoharan | b6f3530 | 2011-09-29 20:34:04 +0530 | [diff] [blame] | 1093 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE; |
| 1094 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 1095 | ieee80211_tx_skb(sdata, skb); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1096 | } |
| 1097 | |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 1098 | static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local, |
| 1099 | struct ieee80211_sub_if_data *sdata) |
| 1100 | { |
| 1101 | struct sk_buff *skb; |
| 1102 | struct ieee80211_hdr *nullfunc; |
| 1103 | __le16 fc; |
| 1104 | |
| 1105 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) |
| 1106 | return; |
| 1107 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 1108 | /* Don't send NDPs when connected HE */ |
| 1109 | if (!(sdata->u.mgd.flags & IEEE80211_STA_DISABLE_HE)) |
| 1110 | return; |
| 1111 | |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 1112 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30); |
Joe Perches | d15b845 | 2011-08-29 14:17:31 -0700 | [diff] [blame] | 1113 | if (!skb) |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 1114 | return; |
Joe Perches | d15b845 | 2011-08-29 14:17:31 -0700 | [diff] [blame] | 1115 | |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 1116 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 1117 | |
Johannes Berg | b080db5 | 2017-06-16 14:29:19 +0200 | [diff] [blame] | 1118 | nullfunc = skb_put_zero(skb, 30); |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 1119 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | |
| 1120 | IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); |
| 1121 | nullfunc->frame_control = fc; |
| 1122 | memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN); |
| 1123 | memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); |
| 1124 | memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN); |
| 1125 | memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN); |
| 1126 | |
| 1127 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 1128 | ieee80211_tx_skb(sdata, skb); |
| 1129 | } |
| 1130 | |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1131 | /* spectrum management related things */ |
| 1132 | static void ieee80211_chswitch_work(struct work_struct *work) |
| 1133 | { |
| 1134 | struct ieee80211_sub_if_data *sdata = |
| 1135 | container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work); |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 1136 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1137 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Arik Nemtsov | 7578d57 | 2013-09-01 17:15:51 +0300 | [diff] [blame] | 1138 | int ret; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1139 | |
Johannes Berg | 9607e6b66 | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 1140 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1141 | return; |
| 1142 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 1143 | sdata_lock(sdata); |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1144 | mutex_lock(&local->mtx); |
| 1145 | mutex_lock(&local->chanctx_mtx); |
| 1146 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1147 | if (!ifmgd->associated) |
| 1148 | goto out; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1149 | |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1150 | if (!sdata->vif.csa_active) |
| 1151 | goto out; |
| 1152 | |
| 1153 | /* |
| 1154 | * using reservation isn't immediate as it may be deferred until later |
| 1155 | * with multi-vif. once reservation is complete it will re-schedule the |
| 1156 | * work with no reserved_chanctx so verify chandef to check if it |
| 1157 | * completed successfully |
| 1158 | */ |
| 1159 | |
| 1160 | if (sdata->reserved_chanctx) { |
Ilan Peer | 0007e94 | 2018-08-31 11:31:10 +0300 | [diff] [blame] | 1161 | struct ieee80211_supported_band *sband = NULL; |
| 1162 | struct sta_info *mgd_sta = NULL; |
| 1163 | enum ieee80211_sta_rx_bandwidth bw = IEEE80211_STA_RX_BW_20; |
| 1164 | |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1165 | /* |
| 1166 | * with multi-vif csa driver may call ieee80211_csa_finish() |
| 1167 | * many times while waiting for other interfaces to use their |
| 1168 | * reservations |
| 1169 | */ |
| 1170 | if (sdata->reserved_ready) |
| 1171 | goto out; |
| 1172 | |
Ilan Peer | 0007e94 | 2018-08-31 11:31:10 +0300 | [diff] [blame] | 1173 | if (sdata->vif.bss_conf.chandef.width != |
| 1174 | sdata->csa_chandef.width) { |
| 1175 | /* |
| 1176 | * For managed interface, we need to also update the AP |
| 1177 | * station bandwidth and align the rate scale algorithm |
| 1178 | * on the bandwidth change. Here we only consider the |
| 1179 | * bandwidth of the new channel definition (as channel |
| 1180 | * switch flow does not have the full HT/VHT/HE |
| 1181 | * information), assuming that if additional changes are |
| 1182 | * required they would be done as part of the processing |
| 1183 | * of the next beacon from the AP. |
| 1184 | */ |
| 1185 | switch (sdata->csa_chandef.width) { |
| 1186 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 1187 | case NL80211_CHAN_WIDTH_20: |
| 1188 | default: |
| 1189 | bw = IEEE80211_STA_RX_BW_20; |
| 1190 | break; |
| 1191 | case NL80211_CHAN_WIDTH_40: |
| 1192 | bw = IEEE80211_STA_RX_BW_40; |
| 1193 | break; |
| 1194 | case NL80211_CHAN_WIDTH_80: |
| 1195 | bw = IEEE80211_STA_RX_BW_80; |
| 1196 | break; |
| 1197 | case NL80211_CHAN_WIDTH_80P80: |
| 1198 | case NL80211_CHAN_WIDTH_160: |
| 1199 | bw = IEEE80211_STA_RX_BW_160; |
| 1200 | break; |
| 1201 | } |
| 1202 | |
| 1203 | mgd_sta = sta_info_get(sdata, ifmgd->bssid); |
| 1204 | sband = |
| 1205 | local->hw.wiphy->bands[sdata->csa_chandef.chan->band]; |
| 1206 | } |
| 1207 | |
| 1208 | if (sdata->vif.bss_conf.chandef.width > |
| 1209 | sdata->csa_chandef.width) { |
| 1210 | mgd_sta->sta.bandwidth = bw; |
| 1211 | rate_control_rate_update(local, sband, mgd_sta, |
| 1212 | IEEE80211_RC_BW_CHANGED); |
| 1213 | } |
| 1214 | |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1215 | ret = ieee80211_vif_use_reserved_context(sdata); |
| 1216 | if (ret) { |
| 1217 | sdata_info(sdata, |
| 1218 | "failed to use reserved channel context, disconnecting (err=%d)\n", |
| 1219 | ret); |
| 1220 | ieee80211_queue_work(&sdata->local->hw, |
| 1221 | &ifmgd->csa_connection_drop_work); |
| 1222 | goto out; |
| 1223 | } |
| 1224 | |
Ilan Peer | 0007e94 | 2018-08-31 11:31:10 +0300 | [diff] [blame] | 1225 | if (sdata->vif.bss_conf.chandef.width < |
| 1226 | sdata->csa_chandef.width) { |
| 1227 | mgd_sta->sta.bandwidth = bw; |
| 1228 | rate_control_rate_update(local, sband, mgd_sta, |
| 1229 | IEEE80211_RC_BW_CHANGED); |
| 1230 | } |
| 1231 | |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1232 | goto out; |
| 1233 | } |
| 1234 | |
| 1235 | if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef, |
| 1236 | &sdata->csa_chandef)) { |
Arik Nemtsov | 7578d57 | 2013-09-01 17:15:51 +0300 | [diff] [blame] | 1237 | sdata_info(sdata, |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1238 | "failed to finalize channel switch, disconnecting\n"); |
Arik Nemtsov | 7578d57 | 2013-09-01 17:15:51 +0300 | [diff] [blame] | 1239 | ieee80211_queue_work(&sdata->local->hw, |
| 1240 | &ifmgd->csa_connection_drop_work); |
| 1241 | goto out; |
| 1242 | } |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 1243 | |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 1244 | ifmgd->csa_waiting_bcn = true; |
Luciano Coelho | f1d6558 | 2014-10-08 09:48:38 +0300 | [diff] [blame] | 1245 | |
Michal Kazior | e5593f5 | 2014-04-09 15:45:36 +0200 | [diff] [blame] | 1246 | ieee80211_sta_reset_beacon_monitor(sdata); |
| 1247 | ieee80211_sta_reset_conn_monitor(sdata); |
| 1248 | |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 1249 | out: |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1250 | mutex_unlock(&local->chanctx_mtx); |
| 1251 | mutex_unlock(&local->mtx); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 1252 | sdata_unlock(sdata); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1253 | } |
| 1254 | |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 1255 | static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data *sdata) |
| 1256 | { |
| 1257 | struct ieee80211_local *local = sdata->local; |
| 1258 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 1259 | int ret; |
| 1260 | |
| 1261 | sdata_assert_lock(sdata); |
| 1262 | |
| 1263 | WARN_ON(!sdata->vif.csa_active); |
| 1264 | |
| 1265 | if (sdata->csa_block_tx) { |
| 1266 | ieee80211_wake_vif_queues(local, sdata, |
| 1267 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 1268 | sdata->csa_block_tx = false; |
| 1269 | } |
| 1270 | |
| 1271 | sdata->vif.csa_active = false; |
| 1272 | ifmgd->csa_waiting_bcn = false; |
| 1273 | |
| 1274 | ret = drv_post_channel_switch(sdata); |
| 1275 | if (ret) { |
| 1276 | sdata_info(sdata, |
| 1277 | "driver post channel switch failed, disconnecting\n"); |
| 1278 | ieee80211_queue_work(&local->hw, |
| 1279 | &ifmgd->csa_connection_drop_work); |
| 1280 | return; |
| 1281 | } |
Luciano Coelho | 688b1ec | 2014-12-16 16:01:39 +0200 | [diff] [blame] | 1282 | |
| 1283 | cfg80211_ch_switch_notify(sdata->dev, &sdata->reserved_chandef); |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 1284 | } |
| 1285 | |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1286 | void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success) |
| 1287 | { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1288 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 1289 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1290 | |
| 1291 | trace_api_chswitch_done(sdata, success); |
| 1292 | if (!success) { |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 1293 | sdata_info(sdata, |
| 1294 | "driver channel switch failed, disconnecting\n"); |
| 1295 | ieee80211_queue_work(&sdata->local->hw, |
| 1296 | &ifmgd->csa_connection_drop_work); |
| 1297 | } else { |
| 1298 | ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1299 | } |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1300 | } |
| 1301 | EXPORT_SYMBOL(ieee80211_chswitch_done); |
| 1302 | |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 1303 | static void ieee80211_chswitch_timer(struct timer_list *t) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1304 | { |
| 1305 | struct ieee80211_sub_if_data *sdata = |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 1306 | from_timer(sdata, t, u.mgd.chswitch_timer); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1307 | |
Stanislaw Gruszka | 9b7d72c | 2013-02-28 10:55:27 +0100 | [diff] [blame] | 1308 | ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1309 | } |
| 1310 | |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 1311 | static void |
Sara Sharon | b9cc81d | 2019-02-06 13:17:10 +0200 | [diff] [blame] | 1312 | ieee80211_sta_abort_chanswitch(struct ieee80211_sub_if_data *sdata) |
| 1313 | { |
| 1314 | struct ieee80211_local *local = sdata->local; |
| 1315 | |
| 1316 | if (!local->ops->abort_channel_switch) |
| 1317 | return; |
| 1318 | |
| 1319 | mutex_lock(&local->mtx); |
| 1320 | |
| 1321 | mutex_lock(&local->chanctx_mtx); |
| 1322 | ieee80211_vif_unreserve_chanctx(sdata); |
| 1323 | mutex_unlock(&local->chanctx_mtx); |
| 1324 | |
| 1325 | if (sdata->csa_block_tx) |
| 1326 | ieee80211_wake_vif_queues(local, sdata, |
| 1327 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 1328 | |
| 1329 | sdata->csa_block_tx = false; |
| 1330 | sdata->vif.csa_active = false; |
| 1331 | |
| 1332 | mutex_unlock(&local->mtx); |
| 1333 | |
| 1334 | drv_abort_channel_switch(sdata); |
| 1335 | } |
| 1336 | |
| 1337 | static void |
Johannes Berg | 4a3cb70 | 2013-02-12 16:43:19 +0100 | [diff] [blame] | 1338 | ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata, |
Luciano Coelho | 2ba4538 | 2014-10-08 09:48:35 +0300 | [diff] [blame] | 1339 | u64 timestamp, u32 device_timestamp, |
| 1340 | struct ieee802_11_elems *elems, |
Johannes Berg | 04a161f | 2013-05-03 09:35:35 +0200 | [diff] [blame] | 1341 | bool beacon) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1342 | { |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1343 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1344 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 1345 | struct cfg80211_bss *cbss = ifmgd->associated; |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1346 | struct ieee80211_chanctx_conf *conf; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1347 | struct ieee80211_chanctx *chanctx; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1348 | enum nl80211_band current_band; |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1349 | struct ieee80211_csa_ie csa_ie; |
Luciano Coelho | 6d027bc | 2014-10-08 09:48:37 +0300 | [diff] [blame] | 1350 | struct ieee80211_channel_switch ch_switch; |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 1351 | struct ieee80211_bss *bss; |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 1352 | int res; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1353 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 1354 | sdata_assert_lock(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1355 | |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 1356 | if (!cbss) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1357 | return; |
| 1358 | |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1359 | if (local->scanning) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1360 | return; |
| 1361 | |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 1362 | current_band = cbss->channel->band; |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 1363 | bss = (void *)cbss->priv; |
Luciano Coelho | 84469a4 | 2014-10-28 13:33:04 +0200 | [diff] [blame] | 1364 | res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band, |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 1365 | bss->vht_cap_info, |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 1366 | ifmgd->flags, |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1367 | ifmgd->associated->bssid, &csa_ie); |
Sara Sharon | fafd2bc | 2019-02-06 13:17:15 +0200 | [diff] [blame] | 1368 | |
| 1369 | if (!res) { |
| 1370 | ch_switch.timestamp = timestamp; |
| 1371 | ch_switch.device_timestamp = device_timestamp; |
Sara Sharon | 2bf973f | 2020-01-31 13:12:51 +0200 | [diff] [blame] | 1372 | ch_switch.block_tx = csa_ie.mode; |
Sara Sharon | fafd2bc | 2019-02-06 13:17:15 +0200 | [diff] [blame] | 1373 | ch_switch.chandef = csa_ie.chandef; |
| 1374 | ch_switch.count = csa_ie.count; |
| 1375 | ch_switch.delay = csa_ie.max_switch_time; |
| 1376 | } |
| 1377 | |
Sara Sharon | b9cc81d | 2019-02-06 13:17:10 +0200 | [diff] [blame] | 1378 | if (res < 0) { |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1379 | ieee80211_queue_work(&local->hw, |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 1380 | &ifmgd->csa_connection_drop_work); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1381 | return; |
Sara Sharon | b9cc81d | 2019-02-06 13:17:10 +0200 | [diff] [blame] | 1382 | } |
| 1383 | |
Sara Sharon | fafd2bc | 2019-02-06 13:17:15 +0200 | [diff] [blame] | 1384 | if (beacon && sdata->vif.csa_active && !ifmgd->csa_waiting_bcn) { |
| 1385 | if (res) |
| 1386 | ieee80211_sta_abort_chanswitch(sdata); |
| 1387 | else |
| 1388 | drv_channel_switch_rx_beacon(sdata, &ch_switch); |
Sara Sharon | b9cc81d | 2019-02-06 13:17:10 +0200 | [diff] [blame] | 1389 | return; |
| 1390 | } else if (sdata->vif.csa_active || res) { |
| 1391 | /* disregard subsequent announcements if already processing */ |
| 1392 | return; |
| 1393 | } |
Johannes Berg | cd64f2a | 2013-03-28 10:44:18 +0100 | [diff] [blame] | 1394 | |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1395 | if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef, |
Johannes Berg | 85220d7 | 2013-03-25 18:29:27 +0100 | [diff] [blame] | 1396 | IEEE80211_CHAN_DISABLED)) { |
| 1397 | sdata_info(sdata, |
Thomas Pedersen | b6011960 | 2020-04-01 18:18:04 -0700 | [diff] [blame] | 1398 | "AP %pM switches to unsupported channel " |
| 1399 | "(%d.%03d MHz, width:%d, CF1/2: %d.%03d/%d MHz), " |
| 1400 | "disconnecting\n", |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 1401 | ifmgd->associated->bssid, |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1402 | csa_ie.chandef.chan->center_freq, |
Thomas Pedersen | b6011960 | 2020-04-01 18:18:04 -0700 | [diff] [blame] | 1403 | csa_ie.chandef.chan->freq_offset, |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1404 | csa_ie.chandef.width, csa_ie.chandef.center_freq1, |
Thomas Pedersen | b6011960 | 2020-04-01 18:18:04 -0700 | [diff] [blame] | 1405 | csa_ie.chandef.freq1_offset, |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1406 | csa_ie.chandef.center_freq2); |
Johannes Berg | 85220d7 | 2013-03-25 18:29:27 +0100 | [diff] [blame] | 1407 | ieee80211_queue_work(&local->hw, |
| 1408 | &ifmgd->csa_connection_drop_work); |
| 1409 | return; |
| 1410 | } |
| 1411 | |
Johannes Berg | f84eaa1 | 2015-03-12 08:53:26 +0200 | [diff] [blame] | 1412 | if (cfg80211_chandef_identical(&csa_ie.chandef, |
Sara Sharon | 9792875 | 2019-02-06 13:17:16 +0200 | [diff] [blame] | 1413 | &sdata->vif.bss_conf.chandef) && |
| 1414 | (!csa_ie.mode || !beacon)) { |
Johannes Berg | f84eaa1 | 2015-03-12 08:53:26 +0200 | [diff] [blame] | 1415 | if (ifmgd->csa_ignored_same_chan) |
| 1416 | return; |
| 1417 | sdata_info(sdata, |
| 1418 | "AP %pM tries to chanswitch to same channel, ignore\n", |
| 1419 | ifmgd->associated->bssid); |
| 1420 | ifmgd->csa_ignored_same_chan = true; |
| 1421 | return; |
| 1422 | } |
| 1423 | |
Arik Nemtsov | c5a7168 | 2015-05-19 14:36:48 +0300 | [diff] [blame] | 1424 | /* |
| 1425 | * Drop all TDLS peers - either we disconnect or move to a different |
| 1426 | * channel from this point on. There's no telling what our peer will do. |
| 1427 | * The TDLS WIDER_BW scenario is also problematic, as peers might now |
| 1428 | * have an incompatible wider chandef. |
| 1429 | */ |
| 1430 | ieee80211_teardown_tdls_peers(sdata); |
| 1431 | |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1432 | mutex_lock(&local->mtx); |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1433 | mutex_lock(&local->chanctx_mtx); |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1434 | conf = rcu_dereference_protected(sdata->vif.chanctx_conf, |
| 1435 | lockdep_is_held(&local->chanctx_mtx)); |
| 1436 | if (!conf) { |
| 1437 | sdata_info(sdata, |
| 1438 | "no channel context assigned to vif?, disconnecting\n"); |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1439 | goto drop_connection; |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1440 | } |
| 1441 | |
| 1442 | chanctx = container_of(conf, struct ieee80211_chanctx, conf); |
| 1443 | |
Luciano Coelho | 0f791eb4 | 2014-10-08 09:48:40 +0300 | [diff] [blame] | 1444 | if (local->use_chanctx && |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1445 | !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) { |
Luciano Coelho | 0f791eb4 | 2014-10-08 09:48:40 +0300 | [diff] [blame] | 1446 | sdata_info(sdata, |
| 1447 | "driver doesn't support chan-switch with channel contexts\n"); |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1448 | goto drop_connection; |
Arik Nemtsov | 7578d57 | 2013-09-01 17:15:51 +0300 | [diff] [blame] | 1449 | } |
| 1450 | |
Luciano Coelho | 6d027bc | 2014-10-08 09:48:37 +0300 | [diff] [blame] | 1451 | if (drv_pre_channel_switch(sdata, &ch_switch)) { |
| 1452 | sdata_info(sdata, |
| 1453 | "preparing for channel switch failed, disconnecting\n"); |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1454 | goto drop_connection; |
Luciano Coelho | 6d027bc | 2014-10-08 09:48:37 +0300 | [diff] [blame] | 1455 | } |
| 1456 | |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1457 | res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef, |
| 1458 | chanctx->mode, false); |
| 1459 | if (res) { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1460 | sdata_info(sdata, |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1461 | "failed to reserve channel context for channel switch, disconnecting (err=%d)\n", |
| 1462 | res); |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1463 | goto drop_connection; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1464 | } |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1465 | mutex_unlock(&local->chanctx_mtx); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1466 | |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 1467 | sdata->vif.csa_active = true; |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1468 | sdata->csa_chandef = csa_ie.chandef; |
Sara Sharon | 2bf973f | 2020-01-31 13:12:51 +0200 | [diff] [blame] | 1469 | sdata->csa_block_tx = csa_ie.mode; |
Johannes Berg | f84eaa1 | 2015-03-12 08:53:26 +0200 | [diff] [blame] | 1470 | ifmgd->csa_ignored_same_chan = false; |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 1471 | |
| 1472 | if (sdata->csa_block_tx) |
Luciano Coelho | a46992b | 2014-06-13 16:30:07 +0300 | [diff] [blame] | 1473 | ieee80211_stop_vif_queues(local, sdata, |
| 1474 | IEEE80211_QUEUE_STOP_REASON_CSA); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 1475 | mutex_unlock(&local->mtx); |
Johannes Berg | 57eebdf | 2012-08-01 15:50:46 +0200 | [diff] [blame] | 1476 | |
Luciano Coelho | 2f45729 | 2014-11-07 14:31:36 +0200 | [diff] [blame] | 1477 | cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef, |
| 1478 | csa_ie.count); |
| 1479 | |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1480 | if (local->ops->channel_switch) { |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1481 | /* use driver's channel switch callback */ |
Luciano Coelho | 0f791eb4 | 2014-10-08 09:48:40 +0300 | [diff] [blame] | 1482 | drv_channel_switch(local, sdata, &ch_switch); |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1483 | return; |
| 1484 | } |
| 1485 | |
| 1486 | /* channel switch handled in software */ |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1487 | if (csa_ie.count <= 1) |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1488 | ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work); |
Johannes Berg | 57eebdf | 2012-08-01 15:50:46 +0200 | [diff] [blame] | 1489 | else |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1490 | mod_timer(&ifmgd->chswitch_timer, |
Luciano Coelho | ff1e417 | 2014-10-28 13:33:05 +0200 | [diff] [blame] | 1491 | TU_TO_EXP_TIME((csa_ie.count - 1) * |
| 1492 | cbss->beacon_interval)); |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1493 | return; |
| 1494 | drop_connection: |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 1495 | /* |
| 1496 | * This is just so that the disconnect flow will know that |
| 1497 | * we were trying to switch channel and failed. In case the |
| 1498 | * mode is 1 (we are not allowed to Tx), we will know not to |
| 1499 | * send a deauthentication frame. Those two fields will be |
| 1500 | * reset when the disconnection worker runs. |
| 1501 | */ |
| 1502 | sdata->vif.csa_active = true; |
Sara Sharon | 2bf973f | 2020-01-31 13:12:51 +0200 | [diff] [blame] | 1503 | sdata->csa_block_tx = csa_ie.mode; |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 1504 | |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1505 | ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work); |
| 1506 | mutex_unlock(&local->chanctx_mtx); |
| 1507 | mutex_unlock(&local->mtx); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1508 | } |
| 1509 | |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1510 | static bool |
| 1511 | ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata, |
| 1512 | struct ieee80211_channel *channel, |
| 1513 | const u8 *country_ie, u8 country_ie_len, |
| 1514 | const u8 *pwr_constr_elem, |
| 1515 | int *chan_pwr, int *pwr_reduction) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1516 | { |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1517 | struct ieee80211_country_ie_triplet *triplet; |
| 1518 | int chan = ieee80211_frequency_to_channel(channel->center_freq); |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1519 | int i, chan_increment; |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1520 | bool have_chan_pwr = false; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1521 | |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1522 | /* Invalid IE */ |
| 1523 | if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1524 | return false; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1525 | |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1526 | triplet = (void *)(country_ie + 3); |
| 1527 | country_ie_len -= 3; |
| 1528 | |
| 1529 | switch (channel->band) { |
| 1530 | default: |
| 1531 | WARN_ON_ONCE(1); |
Gustavo A. R. Silva | fc0561d | 2020-07-07 15:45:48 -0500 | [diff] [blame] | 1532 | fallthrough; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1533 | case NL80211_BAND_2GHZ: |
| 1534 | case NL80211_BAND_60GHZ: |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1535 | chan_increment = 1; |
| 1536 | break; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1537 | case NL80211_BAND_5GHZ: |
Ilan Peer | 6fcb56c | 2020-05-28 21:34:45 +0200 | [diff] [blame] | 1538 | case NL80211_BAND_6GHZ: |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1539 | chan_increment = 4; |
| 1540 | break; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1541 | } |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1542 | |
| 1543 | /* find channel */ |
| 1544 | while (country_ie_len >= 3) { |
| 1545 | u8 first_channel = triplet->chans.first_channel; |
| 1546 | |
| 1547 | if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID) |
| 1548 | goto next; |
| 1549 | |
| 1550 | for (i = 0; i < triplet->chans.num_channels; i++) { |
| 1551 | if (first_channel + i * chan_increment == chan) { |
| 1552 | have_chan_pwr = true; |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1553 | *chan_pwr = triplet->chans.max_power; |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1554 | break; |
| 1555 | } |
| 1556 | } |
| 1557 | if (have_chan_pwr) |
| 1558 | break; |
| 1559 | |
| 1560 | next: |
| 1561 | triplet++; |
| 1562 | country_ie_len -= 3; |
| 1563 | } |
| 1564 | |
Moshe Benji | a5fee9c | 2014-12-14 11:05:50 +0200 | [diff] [blame] | 1565 | if (have_chan_pwr && pwr_constr_elem) |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1566 | *pwr_reduction = *pwr_constr_elem; |
Moshe Benji | a5fee9c | 2014-12-14 11:05:50 +0200 | [diff] [blame] | 1567 | else |
| 1568 | *pwr_reduction = 0; |
| 1569 | |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1570 | return have_chan_pwr; |
| 1571 | } |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1572 | |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1573 | static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata, |
| 1574 | struct ieee80211_channel *channel, |
| 1575 | const u8 *cisco_dtpc_ie, |
| 1576 | int *pwr_level) |
| 1577 | { |
| 1578 | /* From practical testing, the first data byte of the DTPC element |
| 1579 | * seems to contain the requested dBm level, and the CLI on Cisco |
| 1580 | * APs clearly state the range is -127 to 127 dBm, which indicates |
| 1581 | * a signed byte, although it seemingly never actually goes negative. |
| 1582 | * The other byte seems to always be zero. |
| 1583 | */ |
| 1584 | *pwr_level = (__s8)cisco_dtpc_ie[4]; |
| 1585 | } |
| 1586 | |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1587 | static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata, |
| 1588 | struct ieee80211_channel *channel, |
| 1589 | struct ieee80211_mgmt *mgmt, |
| 1590 | const u8 *country_ie, u8 country_ie_len, |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1591 | const u8 *pwr_constr_ie, |
| 1592 | const u8 *cisco_dtpc_ie) |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1593 | { |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1594 | bool has_80211h_pwr = false, has_cisco_pwr = false; |
| 1595 | int chan_pwr = 0, pwr_reduction_80211h = 0; |
| 1596 | int pwr_level_cisco, pwr_level_80211h; |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1597 | int new_ap_level; |
Moshe Benji | a5fee9c | 2014-12-14 11:05:50 +0200 | [diff] [blame] | 1598 | __le16 capab = mgmt->u.probe_resp.capab_info; |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1599 | |
Moshe Benji | a5fee9c | 2014-12-14 11:05:50 +0200 | [diff] [blame] | 1600 | if (country_ie && |
| 1601 | (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) || |
| 1602 | capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) { |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1603 | has_80211h_pwr = ieee80211_find_80211h_pwr_constr( |
| 1604 | sdata, channel, country_ie, country_ie_len, |
| 1605 | pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h); |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1606 | pwr_level_80211h = |
| 1607 | max_t(int, 0, chan_pwr - pwr_reduction_80211h); |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1608 | } |
| 1609 | |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1610 | if (cisco_dtpc_ie) { |
| 1611 | ieee80211_find_cisco_dtpc( |
| 1612 | sdata, channel, cisco_dtpc_ie, &pwr_level_cisco); |
| 1613 | has_cisco_pwr = true; |
| 1614 | } |
| 1615 | |
| 1616 | if (!has_80211h_pwr && !has_cisco_pwr) |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1617 | return 0; |
| 1618 | |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1619 | /* If we have both 802.11h and Cisco DTPC, apply both limits |
| 1620 | * by picking the smallest of the two power levels advertised. |
| 1621 | */ |
| 1622 | if (has_80211h_pwr && |
| 1623 | (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) { |
Johannes Berg | a87da0c | 2015-12-08 16:04:37 +0200 | [diff] [blame] | 1624 | new_ap_level = pwr_level_80211h; |
| 1625 | |
| 1626 | if (sdata->ap_power_level == new_ap_level) |
| 1627 | return 0; |
| 1628 | |
John Linville | cef2fc1 | 2015-03-31 10:49:14 -0400 | [diff] [blame] | 1629 | sdata_dbg(sdata, |
| 1630 | "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n", |
| 1631 | pwr_level_80211h, chan_pwr, pwr_reduction_80211h, |
| 1632 | sdata->u.mgd.bssid); |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1633 | } else { /* has_cisco_pwr is always true here. */ |
Johannes Berg | a87da0c | 2015-12-08 16:04:37 +0200 | [diff] [blame] | 1634 | new_ap_level = pwr_level_cisco; |
| 1635 | |
| 1636 | if (sdata->ap_power_level == new_ap_level) |
| 1637 | return 0; |
| 1638 | |
John Linville | cef2fc1 | 2015-03-31 10:49:14 -0400 | [diff] [blame] | 1639 | sdata_dbg(sdata, |
| 1640 | "Limiting TX power to %d dBm as advertised by %pM\n", |
| 1641 | pwr_level_cisco, sdata->u.mgd.bssid); |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1642 | } |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1643 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 1644 | sdata->ap_power_level = new_ap_level; |
| 1645 | if (__ieee80211_recalc_txpower(sdata)) |
| 1646 | return BSS_CHANGED_TXPOWER; |
| 1647 | return 0; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1648 | } |
| 1649 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1650 | /* powersave */ |
| 1651 | static void ieee80211_enable_ps(struct ieee80211_local *local, |
| 1652 | struct ieee80211_sub_if_data *sdata) |
| 1653 | { |
| 1654 | struct ieee80211_conf *conf = &local->hw.conf; |
| 1655 | |
Johannes Berg | d5edaed | 2009-04-22 23:02:51 +0200 | [diff] [blame] | 1656 | /* |
| 1657 | * If we are scanning right now then the parameters will |
| 1658 | * take effect when scan finishes. |
| 1659 | */ |
Helmut Schaa | fbe9c429 | 2009-07-23 12:14:04 +0200 | [diff] [blame] | 1660 | if (local->scanning) |
Johannes Berg | d5edaed | 2009-04-22 23:02:51 +0200 | [diff] [blame] | 1661 | return; |
| 1662 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1663 | if (conf->dynamic_ps_timeout > 0 && |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1664 | !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1665 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 1666 | msecs_to_jiffies(conf->dynamic_ps_timeout)); |
| 1667 | } else { |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1668 | if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) |
Johannes Berg | 076cdcb | 2015-09-24 16:14:55 +0200 | [diff] [blame] | 1669 | ieee80211_send_nullfunc(local, sdata, true); |
Vivek Natarajan | 375177b | 2010-02-09 14:50:28 +0530 | [diff] [blame] | 1670 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1671 | if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) && |
| 1672 | ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
Juuso Oikarinen | 2a13052 | 2010-03-09 14:25:02 +0200 | [diff] [blame] | 1673 | return; |
| 1674 | |
| 1675 | conf->flags |= IEEE80211_CONF_PS; |
| 1676 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1677 | } |
| 1678 | } |
| 1679 | |
| 1680 | static void ieee80211_change_ps(struct ieee80211_local *local) |
| 1681 | { |
| 1682 | struct ieee80211_conf *conf = &local->hw.conf; |
| 1683 | |
| 1684 | if (local->ps_sdata) { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1685 | ieee80211_enable_ps(local, local->ps_sdata); |
| 1686 | } else if (conf->flags & IEEE80211_CONF_PS) { |
| 1687 | conf->flags &= ~IEEE80211_CONF_PS; |
| 1688 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 1689 | del_timer_sync(&local->dynamic_ps_timer); |
| 1690 | cancel_work_sync(&local->dynamic_ps_enable_work); |
| 1691 | } |
| 1692 | } |
| 1693 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1694 | static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata) |
| 1695 | { |
| 1696 | struct ieee80211_if_managed *mgd = &sdata->u.mgd; |
| 1697 | struct sta_info *sta = NULL; |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1698 | bool authorized = false; |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1699 | |
| 1700 | if (!mgd->powersave) |
| 1701 | return false; |
| 1702 | |
Johannes Berg | 05cb910 | 2011-10-28 11:59:47 +0200 | [diff] [blame] | 1703 | if (mgd->broken_ap) |
| 1704 | return false; |
| 1705 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1706 | if (!mgd->associated) |
| 1707 | return false; |
| 1708 | |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 1709 | if (mgd->flags & IEEE80211_STA_CONNECTION_POLL) |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1710 | return false; |
| 1711 | |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 1712 | if (!mgd->have_beacon) |
Alexander Bondar | ce85788 | 2013-05-06 17:17:04 +0300 | [diff] [blame] | 1713 | return false; |
| 1714 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1715 | rcu_read_lock(); |
| 1716 | sta = sta_info_get(sdata, mgd->bssid); |
| 1717 | if (sta) |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1718 | authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED); |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1719 | rcu_read_unlock(); |
| 1720 | |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1721 | return authorized; |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1722 | } |
| 1723 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1724 | /* need to hold RTNL or interface lock */ |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 1725 | void ieee80211_recalc_ps(struct ieee80211_local *local) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1726 | { |
| 1727 | struct ieee80211_sub_if_data *sdata, *found = NULL; |
| 1728 | int count = 0; |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 1729 | int timeout; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1730 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1731 | if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1732 | local->ps_sdata = NULL; |
| 1733 | return; |
| 1734 | } |
| 1735 | |
| 1736 | list_for_each_entry(sdata, &local->interfaces, list) { |
Johannes Berg | 9607e6b66 | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 1737 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1738 | continue; |
Rajkumar Manoharan | 8c7914d | 2011-02-01 00:28:59 +0530 | [diff] [blame] | 1739 | if (sdata->vif.type == NL80211_IFTYPE_AP) { |
| 1740 | /* If an AP vif is found, then disable PS |
| 1741 | * by setting the count to zero thereby setting |
| 1742 | * ps_sdata to NULL. |
| 1743 | */ |
| 1744 | count = 0; |
| 1745 | break; |
| 1746 | } |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1747 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 1748 | continue; |
| 1749 | found = sdata; |
| 1750 | count++; |
| 1751 | } |
| 1752 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1753 | if (count == 1 && ieee80211_powersave_allowed(found)) { |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 1754 | u8 dtimper = found->u.mgd.dtim_period; |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1755 | |
Juuso Oikarinen | ff61638 | 2010-06-09 09:51:52 +0300 | [diff] [blame] | 1756 | timeout = local->dynamic_ps_forced_timeout; |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 1757 | if (timeout < 0) |
| 1758 | timeout = 100; |
Johannes Berg | 09b8556 | 2013-02-06 23:07:41 +0100 | [diff] [blame] | 1759 | local->hw.conf.dynamic_ps_timeout = timeout; |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 1760 | |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 1761 | /* If the TIM IE is invalid, pretend the value is 1 */ |
| 1762 | if (!dtimper) |
| 1763 | dtimper = 1; |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 1764 | |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 1765 | local->hw.conf.ps_dtim_period = dtimper; |
| 1766 | local->ps_sdata = found; |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1767 | } else { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1768 | local->ps_sdata = NULL; |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1769 | } |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1770 | |
| 1771 | ieee80211_change_ps(local); |
| 1772 | } |
| 1773 | |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 1774 | void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata) |
| 1775 | { |
| 1776 | bool ps_allowed = ieee80211_powersave_allowed(sdata); |
| 1777 | |
| 1778 | if (sdata->vif.bss_conf.ps != ps_allowed) { |
| 1779 | sdata->vif.bss_conf.ps = ps_allowed; |
| 1780 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS); |
| 1781 | } |
| 1782 | } |
| 1783 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1784 | void ieee80211_dynamic_ps_disable_work(struct work_struct *work) |
| 1785 | { |
| 1786 | struct ieee80211_local *local = |
| 1787 | container_of(work, struct ieee80211_local, |
| 1788 | dynamic_ps_disable_work); |
| 1789 | |
| 1790 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 1791 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 1792 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 1793 | } |
| 1794 | |
| 1795 | ieee80211_wake_queues_by_reason(&local->hw, |
Johannes Berg | 445ea4e | 2013-02-13 12:25:28 +0100 | [diff] [blame] | 1796 | IEEE80211_MAX_QUEUE_MAP, |
Luciano Coelho | cca07b0 | 2014-06-13 16:30:05 +0300 | [diff] [blame] | 1797 | IEEE80211_QUEUE_STOP_REASON_PS, |
| 1798 | false); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | void ieee80211_dynamic_ps_enable_work(struct work_struct *work) |
| 1802 | { |
| 1803 | struct ieee80211_local *local = |
| 1804 | container_of(work, struct ieee80211_local, |
| 1805 | dynamic_ps_enable_work); |
| 1806 | struct ieee80211_sub_if_data *sdata = local->ps_sdata; |
Christian Lamparter | 5e34069 | 2011-06-30 21:08:43 +0200 | [diff] [blame] | 1807 | struct ieee80211_if_managed *ifmgd; |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1808 | unsigned long flags; |
| 1809 | int q; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1810 | |
| 1811 | /* can only happen when PS was just disabled anyway */ |
| 1812 | if (!sdata) |
| 1813 | return; |
| 1814 | |
Christian Lamparter | 5e34069 | 2011-06-30 21:08:43 +0200 | [diff] [blame] | 1815 | ifmgd = &sdata->u.mgd; |
| 1816 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1817 | if (local->hw.conf.flags & IEEE80211_CONF_PS) |
| 1818 | return; |
| 1819 | |
Johannes Berg | 09b8556 | 2013-02-06 23:07:41 +0100 | [diff] [blame] | 1820 | if (local->hw.conf.dynamic_ps_timeout > 0) { |
Arik Nemtsov | 77b7023 | 2011-06-26 12:06:54 +0300 | [diff] [blame] | 1821 | /* don't enter PS if TX frames are pending */ |
| 1822 | if (drv_tx_frames_pending(local)) { |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1823 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 1824 | msecs_to_jiffies( |
| 1825 | local->hw.conf.dynamic_ps_timeout)); |
| 1826 | return; |
| 1827 | } |
Arik Nemtsov | 77b7023 | 2011-06-26 12:06:54 +0300 | [diff] [blame] | 1828 | |
| 1829 | /* |
| 1830 | * transmission can be stopped by others which leads to |
| 1831 | * dynamic_ps_timer expiry. Postpone the ps timer if it |
| 1832 | * is not the actual idle state. |
| 1833 | */ |
| 1834 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 1835 | for (q = 0; q < local->hw.queues; q++) { |
| 1836 | if (local->queue_stop_reasons[q]) { |
| 1837 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, |
| 1838 | flags); |
| 1839 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 1840 | msecs_to_jiffies( |
| 1841 | local->hw.conf.dynamic_ps_timeout)); |
| 1842 | return; |
| 1843 | } |
| 1844 | } |
| 1845 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1846 | } |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1847 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1848 | if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) && |
Mohammed Shafi Shajakhan | 9c38a8b | 2011-12-14 19:46:07 +0530 | [diff] [blame] | 1849 | !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) { |
Johannes Berg | a1598383 | 2013-03-26 22:02:42 +0100 | [diff] [blame] | 1850 | if (drv_tx_frames_pending(local)) { |
Vivek Natarajan | e8306f9 | 2011-04-06 11:41:10 +0530 | [diff] [blame] | 1851 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 1852 | msecs_to_jiffies( |
| 1853 | local->hw.conf.dynamic_ps_timeout)); |
Johannes Berg | a1598383 | 2013-03-26 22:02:42 +0100 | [diff] [blame] | 1854 | } else { |
Johannes Berg | 076cdcb | 2015-09-24 16:14:55 +0200 | [diff] [blame] | 1855 | ieee80211_send_nullfunc(local, sdata, true); |
Vivek Natarajan | e8306f9 | 2011-04-06 11:41:10 +0530 | [diff] [blame] | 1856 | /* Flush to get the tx status of nullfunc frame */ |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 1857 | ieee80211_flush_queues(local, sdata, false); |
Vivek Natarajan | e8306f9 | 2011-04-06 11:41:10 +0530 | [diff] [blame] | 1858 | } |
Vivek Natarajan | f3e85b9 | 2011-02-23 13:04:32 +0530 | [diff] [blame] | 1859 | } |
| 1860 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1861 | if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) && |
| 1862 | ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) || |
Vivek Natarajan | 375177b | 2010-02-09 14:50:28 +0530 | [diff] [blame] | 1863 | (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) { |
| 1864 | ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED; |
| 1865 | local->hw.conf.flags |= IEEE80211_CONF_PS; |
| 1866 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 1867 | } |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1868 | } |
| 1869 | |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 1870 | void ieee80211_dynamic_ps_timer(struct timer_list *t) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1871 | { |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 1872 | struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1873 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 1874 | ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1875 | } |
| 1876 | |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 1877 | void ieee80211_dfs_cac_timer_work(struct work_struct *work) |
| 1878 | { |
Geliang Tang | a85a7e2 | 2016-01-01 23:48:52 +0800 | [diff] [blame] | 1879 | struct delayed_work *delayed_work = to_delayed_work(work); |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 1880 | struct ieee80211_sub_if_data *sdata = |
| 1881 | container_of(delayed_work, struct ieee80211_sub_if_data, |
| 1882 | dfs_cac_timer_work); |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 1883 | struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef; |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 1884 | |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 1885 | mutex_lock(&sdata->local->mtx); |
| 1886 | if (sdata->wdev.cac_started) { |
| 1887 | ieee80211_vif_release_channel(sdata); |
| 1888 | cfg80211_cac_event(sdata->dev, &chandef, |
| 1889 | NL80211_RADAR_CAC_FINISHED, |
| 1890 | GFP_KERNEL); |
| 1891 | } |
| 1892 | mutex_unlock(&sdata->local->mtx); |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 1893 | } |
| 1894 | |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 1895 | static bool |
| 1896 | __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata) |
| 1897 | { |
| 1898 | struct ieee80211_local *local = sdata->local; |
| 1899 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
John Linville | cc72f6e | 2015-01-06 14:39:33 -0500 | [diff] [blame] | 1900 | bool ret = false; |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 1901 | int ac; |
| 1902 | |
| 1903 | if (local->hw.queues < IEEE80211_NUM_ACS) |
| 1904 | return false; |
| 1905 | |
| 1906 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 1907 | struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac]; |
| 1908 | int non_acm_ac; |
| 1909 | unsigned long now = jiffies; |
| 1910 | |
| 1911 | if (tx_tspec->action == TX_TSPEC_ACTION_NONE && |
| 1912 | tx_tspec->admitted_time && |
| 1913 | time_after(now, tx_tspec->time_slice_start + HZ)) { |
| 1914 | tx_tspec->consumed_tx_time = 0; |
| 1915 | tx_tspec->time_slice_start = now; |
| 1916 | |
| 1917 | if (tx_tspec->downgraded) |
| 1918 | tx_tspec->action = |
| 1919 | TX_TSPEC_ACTION_STOP_DOWNGRADE; |
| 1920 | } |
| 1921 | |
| 1922 | switch (tx_tspec->action) { |
| 1923 | case TX_TSPEC_ACTION_STOP_DOWNGRADE: |
| 1924 | /* take the original parameters */ |
| 1925 | if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac])) |
| 1926 | sdata_err(sdata, |
| 1927 | "failed to set TX queue parameters for queue %d\n", |
| 1928 | ac); |
| 1929 | tx_tspec->action = TX_TSPEC_ACTION_NONE; |
| 1930 | tx_tspec->downgraded = false; |
| 1931 | ret = true; |
| 1932 | break; |
| 1933 | case TX_TSPEC_ACTION_DOWNGRADE: |
| 1934 | if (time_after(now, tx_tspec->time_slice_start + HZ)) { |
| 1935 | tx_tspec->action = TX_TSPEC_ACTION_NONE; |
| 1936 | ret = true; |
| 1937 | break; |
| 1938 | } |
| 1939 | /* downgrade next lower non-ACM AC */ |
| 1940 | for (non_acm_ac = ac + 1; |
| 1941 | non_acm_ac < IEEE80211_NUM_ACS; |
| 1942 | non_acm_ac++) |
| 1943 | if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac))) |
| 1944 | break; |
Johannes Berg | 93db1d9 | 2016-09-14 09:23:51 +0200 | [diff] [blame] | 1945 | /* Usually the loop will result in using BK even if it |
| 1946 | * requires admission control, but such a configuration |
| 1947 | * makes no sense and we have to transmit somehow - the |
| 1948 | * AC selection does the same thing. |
| 1949 | * If we started out trying to downgrade from BK, then |
| 1950 | * the extra condition here might be needed. |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 1951 | */ |
Johannes Berg | 93db1d9 | 2016-09-14 09:23:51 +0200 | [diff] [blame] | 1952 | if (non_acm_ac >= IEEE80211_NUM_ACS) |
| 1953 | non_acm_ac = IEEE80211_AC_BK; |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 1954 | if (drv_conf_tx(local, sdata, ac, |
| 1955 | &sdata->tx_conf[non_acm_ac])) |
| 1956 | sdata_err(sdata, |
| 1957 | "failed to set TX queue parameters for queue %d\n", |
| 1958 | ac); |
| 1959 | tx_tspec->action = TX_TSPEC_ACTION_NONE; |
| 1960 | ret = true; |
| 1961 | schedule_delayed_work(&ifmgd->tx_tspec_wk, |
| 1962 | tx_tspec->time_slice_start + HZ - now + 1); |
| 1963 | break; |
| 1964 | case TX_TSPEC_ACTION_NONE: |
| 1965 | /* nothing now */ |
| 1966 | break; |
| 1967 | } |
| 1968 | } |
| 1969 | |
| 1970 | return ret; |
| 1971 | } |
| 1972 | |
| 1973 | void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata) |
| 1974 | { |
| 1975 | if (__ieee80211_sta_handle_tspec_ac_params(sdata)) |
| 1976 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS); |
| 1977 | } |
| 1978 | |
| 1979 | static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work) |
| 1980 | { |
| 1981 | struct ieee80211_sub_if_data *sdata; |
| 1982 | |
| 1983 | sdata = container_of(work, struct ieee80211_sub_if_data, |
| 1984 | u.mgd.tx_tspec_wk.work); |
| 1985 | ieee80211_sta_handle_tspec_ac_params(sdata); |
| 1986 | } |
| 1987 | |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1988 | /* MLME */ |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 1989 | static bool |
| 1990 | ieee80211_sta_wmm_params(struct ieee80211_local *local, |
| 1991 | struct ieee80211_sub_if_data *sdata, |
| 1992 | const u8 *wmm_param, size_t wmm_param_len, |
| 1993 | const struct ieee80211_mu_edca_param_set *mu_edca) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1994 | { |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 1995 | struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS]; |
Johannes Berg | 4ced3f7 | 2010-07-19 16:39:04 +0200 | [diff] [blame] | 1996 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1997 | size_t left; |
Shaul Triebitz | 2e249fc | 2018-12-15 11:03:15 +0200 | [diff] [blame] | 1998 | int count, mu_edca_count, ac; |
Johannes Berg | 4a3cb70 | 2013-02-12 16:43:19 +0100 | [diff] [blame] | 1999 | const u8 *pos; |
| 2000 | u8 uapsd_queues = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2001 | |
Stanislaw Gruszka | e1b3ec1 | 2010-03-29 12:18:34 +0200 | [diff] [blame] | 2002 | if (!local->ops->conf_tx) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 2003 | return false; |
Stanislaw Gruszka | e1b3ec1 | 2010-03-29 12:18:34 +0200 | [diff] [blame] | 2004 | |
Johannes Berg | 32c5057 | 2012-03-28 11:04:29 +0200 | [diff] [blame] | 2005 | if (local->hw.queues < IEEE80211_NUM_ACS) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 2006 | return false; |
Johannes Berg | 3434fbd | 2008-05-03 00:59:37 +0200 | [diff] [blame] | 2007 | |
| 2008 | if (!wmm_param) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 2009 | return false; |
Johannes Berg | 3434fbd | 2008-05-03 00:59:37 +0200 | [diff] [blame] | 2010 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2011 | if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 2012 | return false; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2013 | |
| 2014 | if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED) |
Eliad Peller | dc41e4d | 2012-03-14 16:15:03 +0200 | [diff] [blame] | 2015 | uapsd_queues = ifmgd->uapsd_queues; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2016 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2017 | count = wmm_param[6] & 0x0f; |
Shaul Triebitz | 2e249fc | 2018-12-15 11:03:15 +0200 | [diff] [blame] | 2018 | /* -1 is the initial value of ifmgd->mu_edca_last_param_set. |
| 2019 | * if mu_edca was preset before and now it disappeared tell |
| 2020 | * the driver about it. |
| 2021 | */ |
| 2022 | mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1; |
| 2023 | if (count == ifmgd->wmm_last_param_set && |
| 2024 | mu_edca_count == ifmgd->mu_edca_last_param_set) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 2025 | return false; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2026 | ifmgd->wmm_last_param_set = count; |
Shaul Triebitz | 2e249fc | 2018-12-15 11:03:15 +0200 | [diff] [blame] | 2027 | ifmgd->mu_edca_last_param_set = mu_edca_count; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2028 | |
| 2029 | pos = wmm_param + 8; |
| 2030 | left = wmm_param_len - 8; |
| 2031 | |
| 2032 | memset(¶ms, 0, sizeof(params)); |
| 2033 | |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 2034 | sdata->wmm_acm = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2035 | for (; left >= 4; left -= 4, pos += 4) { |
| 2036 | int aci = (pos[0] >> 5) & 0x03; |
| 2037 | int acm = (pos[0] >> 4) & 0x01; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2038 | bool uapsd = false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2039 | |
| 2040 | switch (aci) { |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 2041 | case 1: /* AC_BK */ |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2042 | ac = IEEE80211_AC_BK; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 2043 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 2044 | sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2045 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) |
| 2046 | uapsd = true; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 2047 | params[ac].mu_edca = !!mu_edca; |
| 2048 | if (mu_edca) |
| 2049 | params[ac].mu_edca_param_rec = mu_edca->ac_bk; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2050 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 2051 | case 2: /* AC_VI */ |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2052 | ac = IEEE80211_AC_VI; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 2053 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 2054 | sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2055 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) |
| 2056 | uapsd = true; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 2057 | params[ac].mu_edca = !!mu_edca; |
| 2058 | if (mu_edca) |
| 2059 | params[ac].mu_edca_param_rec = mu_edca->ac_vi; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2060 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 2061 | case 3: /* AC_VO */ |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2062 | ac = IEEE80211_AC_VO; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 2063 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 2064 | sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2065 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) |
| 2066 | uapsd = true; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 2067 | params[ac].mu_edca = !!mu_edca; |
| 2068 | if (mu_edca) |
| 2069 | params[ac].mu_edca_param_rec = mu_edca->ac_vo; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2070 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 2071 | case 0: /* AC_BE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2072 | default: |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2073 | ac = IEEE80211_AC_BE; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 2074 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 2075 | sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2076 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) |
| 2077 | uapsd = true; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 2078 | params[ac].mu_edca = !!mu_edca; |
| 2079 | if (mu_edca) |
| 2080 | params[ac].mu_edca_param_rec = mu_edca->ac_be; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2081 | break; |
| 2082 | } |
| 2083 | |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2084 | params[ac].aifs = pos[0] & 0x0f; |
Emmanuel Grumbach | 730a7550 | 2015-10-22 17:46:05 +0200 | [diff] [blame] | 2085 | |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2086 | if (params[ac].aifs < 2) { |
Emmanuel Grumbach | 730a7550 | 2015-10-22 17:46:05 +0200 | [diff] [blame] | 2087 | sdata_info(sdata, |
| 2088 | "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n", |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2089 | params[ac].aifs, aci); |
| 2090 | params[ac].aifs = 2; |
Emmanuel Grumbach | 730a7550 | 2015-10-22 17:46:05 +0200 | [diff] [blame] | 2091 | } |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2092 | params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4); |
| 2093 | params[ac].cw_min = ecw2cw(pos[1] & 0x0f); |
| 2094 | params[ac].txop = get_unaligned_le16(pos + 2); |
| 2095 | params[ac].acm = acm; |
| 2096 | params[ac].uapsd = uapsd; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2097 | |
Ilan Peer | 911a264 | 2018-04-03 11:35:22 +0300 | [diff] [blame] | 2098 | if (params[ac].cw_min == 0 || |
Emmanuel Grumbach | c470bdc | 2018-03-26 16:21:04 +0300 | [diff] [blame] | 2099 | params[ac].cw_min > params[ac].cw_max) { |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2100 | sdata_info(sdata, |
| 2101 | "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n", |
| 2102 | params[ac].cw_min, params[ac].cw_max, aci); |
| 2103 | return false; |
| 2104 | } |
Haim Dreyfuss | e552af0 | 2018-03-28 13:24:10 +0300 | [diff] [blame] | 2105 | ieee80211_regulatory_limit_wmm_params(sdata, ¶ms[ac], ac); |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2106 | } |
| 2107 | |
Brian Norris | 05aaa5c | 2019-07-26 15:47:58 -0700 | [diff] [blame] | 2108 | /* WMM specification requires all 4 ACIs. */ |
| 2109 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 2110 | if (params[ac].cw_min == 0) { |
| 2111 | sdata_info(sdata, |
| 2112 | "AP has invalid WMM params (missing AC %d), using defaults\n", |
| 2113 | ac); |
| 2114 | return false; |
| 2115 | } |
| 2116 | } |
| 2117 | |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2118 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2119 | mlme_dbg(sdata, |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2120 | "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n", |
| 2121 | ac, params[ac].acm, |
| 2122 | params[ac].aifs, params[ac].cw_min, params[ac].cw_max, |
| 2123 | params[ac].txop, params[ac].uapsd, |
| 2124 | ifmgd->tx_tspec[ac].downgraded); |
| 2125 | sdata->tx_conf[ac] = params[ac]; |
| 2126 | if (!ifmgd->tx_tspec[ac].downgraded && |
| 2127 | drv_conf_tx(local, sdata, ac, ¶ms[ac])) |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2128 | sdata_err(sdata, |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2129 | "failed to set TX queue parameters for AC %d\n", |
| 2130 | ac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2131 | } |
Stanislaw Gruszka | e1b3ec1 | 2010-03-29 12:18:34 +0200 | [diff] [blame] | 2132 | |
| 2133 | /* enable WMM or activate new settings */ |
Johannes Berg | 4ced3f7 | 2010-07-19 16:39:04 +0200 | [diff] [blame] | 2134 | sdata->vif.bss_conf.qos = true; |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 2135 | return true; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2136 | } |
| 2137 | |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 2138 | static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata) |
| 2139 | { |
| 2140 | lockdep_assert_held(&sdata->local->mtx); |
| 2141 | |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 2142 | sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL; |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 2143 | ieee80211_run_deferred_scan(sdata->local); |
| 2144 | } |
| 2145 | |
| 2146 | static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata) |
| 2147 | { |
| 2148 | mutex_lock(&sdata->local->mtx); |
| 2149 | __ieee80211_stop_poll(sdata); |
| 2150 | mutex_unlock(&sdata->local->mtx); |
| 2151 | } |
| 2152 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2153 | static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata, |
| 2154 | u16 capab, bool erp_valid, u8 erp) |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 2155 | { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 2156 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 2157 | struct ieee80211_supported_band *sband; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2158 | u32 changed = 0; |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2159 | bool use_protection; |
| 2160 | bool use_short_preamble; |
| 2161 | bool use_short_slot; |
| 2162 | |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 2163 | sband = ieee80211_get_sband(sdata); |
| 2164 | if (!sband) |
| 2165 | return changed; |
| 2166 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2167 | if (erp_valid) { |
| 2168 | use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0; |
| 2169 | use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0; |
| 2170 | } else { |
| 2171 | use_protection = false; |
| 2172 | use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE); |
| 2173 | } |
| 2174 | |
| 2175 | use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME); |
Tova Mussai | 07c12d6 | 2020-05-28 21:34:46 +0200 | [diff] [blame] | 2176 | if (sband->band == NL80211_BAND_5GHZ || |
| 2177 | sband->band == NL80211_BAND_6GHZ) |
Felix Fietkau | 43d3534 | 2010-01-15 03:00:48 +0100 | [diff] [blame] | 2178 | use_short_slot = true; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 2179 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2180 | if (use_protection != bss_conf->use_cts_prot) { |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2181 | bss_conf->use_cts_prot = use_protection; |
| 2182 | changed |= BSS_CHANGED_ERP_CTS_PROT; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 2183 | } |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 2184 | |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 2185 | if (use_short_preamble != bss_conf->use_short_preamble) { |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 2186 | bss_conf->use_short_preamble = use_short_preamble; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2187 | changed |= BSS_CHANGED_ERP_PREAMBLE; |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 2188 | } |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 2189 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2190 | if (use_short_slot != bss_conf->use_short_slot) { |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2191 | bss_conf->use_short_slot = use_short_slot; |
| 2192 | changed |= BSS_CHANGED_ERP_SLOT; |
John W. Linville | 50c4afb | 2008-04-15 14:09:27 -0400 | [diff] [blame] | 2193 | } |
| 2194 | |
| 2195 | return changed; |
| 2196 | } |
| 2197 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2198 | static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2199 | struct cfg80211_bss *cbss, |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2200 | u32 bss_info_changed) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2201 | { |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2202 | struct ieee80211_bss *bss = (void *)cbss->priv; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2203 | struct ieee80211_local *local = sdata->local; |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2204 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2205 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2206 | bss_info_changed |= BSS_CHANGED_ASSOC; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2207 | bss_info_changed |= ieee80211_handle_bss_capability(sdata, |
Luciano Coelho | 50ae34a | 2012-06-20 17:23:24 +0300 | [diff] [blame] | 2208 | bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value); |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 2209 | |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 2210 | sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec( |
Ben Greear | 59c1ec2 | 2013-03-19 14:19:56 -0700 | [diff] [blame] | 2211 | beacon_loss_count * bss_conf->beacon_int)); |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 2212 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2213 | sdata->u.mgd.associated = cbss; |
| 2214 | memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2215 | |
Johannes Berg | e8e4f52 | 2017-03-08 11:12:10 +0100 | [diff] [blame] | 2216 | ieee80211_check_rate_mask(sdata); |
| 2217 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 2218 | sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE; |
| 2219 | |
Janusz.Dziedzic@tieto.com | b115b97 | 2015-10-27 08:38:40 +0100 | [diff] [blame] | 2220 | if (sdata->vif.p2p || |
| 2221 | sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2222 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 2223 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2224 | rcu_read_lock(); |
| 2225 | ies = rcu_dereference(cbss->ies); |
| 2226 | if (ies) { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2227 | int ret; |
| 2228 | |
| 2229 | ret = cfg80211_get_p2p_attr( |
| 2230 | ies->data, ies->len, |
| 2231 | IEEE80211_P2P_ATTR_ABSENCE_NOTICE, |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 2232 | (u8 *) &bss_conf->p2p_noa_attr, |
| 2233 | sizeof(bss_conf->p2p_noa_attr)); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2234 | if (ret >= 2) { |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 2235 | sdata->u.mgd.p2p_noa_index = |
| 2236 | bss_conf->p2p_noa_attr.index; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2237 | bss_info_changed |= BSS_CHANGED_P2P_PS; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2238 | } |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 2239 | } |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2240 | rcu_read_unlock(); |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 2241 | } |
| 2242 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2243 | /* just to be sure */ |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 2244 | ieee80211_stop_poll(sdata); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2245 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 2246 | ieee80211_led_assoc(local, 1); |
| 2247 | |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 2248 | if (sdata->u.mgd.have_beacon) { |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 2249 | /* |
| 2250 | * If the AP is buggy we may get here with no DTIM period |
| 2251 | * known, so assume it's 1 which is the only safe assumption |
| 2252 | * in that case, although if the TIM IE is broken powersave |
| 2253 | * probably just won't work at all. |
| 2254 | */ |
| 2255 | bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1; |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 2256 | bss_conf->beacon_rate = bss->beacon_rate; |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 2257 | bss_info_changed |= BSS_CHANGED_BEACON_INFO; |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 2258 | } else { |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 2259 | bss_conf->beacon_rate = NULL; |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 2260 | bss_conf->dtim_period = 0; |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 2261 | } |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 2262 | |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2263 | bss_conf->assoc = 1; |
Johannes Berg | 9cef873 | 2009-05-14 13:10:14 +0200 | [diff] [blame] | 2264 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 2265 | /* Tell the driver to monitor connection quality (if supported) */ |
Johannes Berg | ea08635 | 2012-01-19 09:29:58 +0100 | [diff] [blame] | 2266 | if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI && |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2267 | bss_conf->cqm_rssi_thold) |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 2268 | bss_info_changed |= BSS_CHANGED_CQM; |
| 2269 | |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2270 | /* Enable ARP filtering */ |
Johannes Berg | 0f19b41 | 2013-01-14 16:39:07 +0100 | [diff] [blame] | 2271 | if (bss_conf->arp_addr_cnt) |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2272 | bss_info_changed |= BSS_CHANGED_ARP_FILTER; |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2273 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2274 | ieee80211_bss_info_change_notify(sdata, bss_info_changed); |
Guy Cohen | 8db9369 | 2008-07-03 19:56:13 +0300 | [diff] [blame] | 2275 | |
Johannes Berg | 056508d | 2009-07-30 21:43:55 +0200 | [diff] [blame] | 2276 | mutex_lock(&local->iflist_mtx); |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 2277 | ieee80211_recalc_ps(local); |
Johannes Berg | 056508d | 2009-07-30 21:43:55 +0200 | [diff] [blame] | 2278 | mutex_unlock(&local->iflist_mtx); |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 2279 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 2280 | ieee80211_recalc_smps(sdata); |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 2281 | ieee80211_recalc_ps_vif(sdata); |
| 2282 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 2283 | netif_carrier_on(sdata->dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2284 | } |
| 2285 | |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 2286 | static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2287 | u16 stype, u16 reason, bool tx, |
| 2288 | u8 *frame_buf) |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2289 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2290 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2291 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 3cc5240 | 2012-03-09 13:12:35 +0100 | [diff] [blame] | 2292 | u32 changed = 0; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2293 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2294 | sdata_assert_lock(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2295 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2296 | if (WARN_ON_ONCE(tx && !frame_buf)) |
| 2297 | return; |
| 2298 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2299 | if (WARN_ON(!ifmgd->associated)) |
| 2300 | return; |
| 2301 | |
David Spinadel | 79543d8 | 2012-06-12 09:59:45 +0300 | [diff] [blame] | 2302 | ieee80211_stop_poll(sdata); |
| 2303 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2304 | ifmgd->associated = NULL; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2305 | netif_carrier_off(sdata->dev); |
| 2306 | |
Eliad Peller | 88bc40e | 2012-07-12 17:35:33 +0300 | [diff] [blame] | 2307 | /* |
| 2308 | * if we want to get out of ps before disassoc (why?) we have |
| 2309 | * to do it before sending disassoc, as otherwise the null-packet |
| 2310 | * won't be valid. |
| 2311 | */ |
| 2312 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 2313 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 2314 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 2315 | } |
| 2316 | local->ps_sdata = NULL; |
| 2317 | |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 2318 | /* disable per-vif ps */ |
| 2319 | ieee80211_recalc_ps_vif(sdata); |
| 2320 | |
Emmanuel Grumbach | 14f2ae8 | 2015-01-22 23:30:19 +0200 | [diff] [blame] | 2321 | /* make sure ongoing transmission finishes */ |
| 2322 | synchronize_net(); |
| 2323 | |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 2324 | /* |
| 2325 | * drop any frame before deauth/disassoc, this can be data or |
| 2326 | * management frame. Since we are disconnecting, we should not |
| 2327 | * insist sending these frames which can take time and delay |
| 2328 | * the disconnection and possible the roaming. |
| 2329 | */ |
Eliad Peller | f823981 | 2012-06-27 14:18:22 +0300 | [diff] [blame] | 2330 | if (tx) |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 2331 | ieee80211_flush_queues(local, sdata, true); |
Eliad Peller | f823981 | 2012-06-27 14:18:22 +0300 | [diff] [blame] | 2332 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2333 | /* deauthenticate/disassociate now */ |
Ilan Peer | 94ba927 | 2018-02-19 14:48:41 +0200 | [diff] [blame] | 2334 | if (tx || frame_buf) { |
Ilan Peer | 94ba927 | 2018-02-19 14:48:41 +0200 | [diff] [blame] | 2335 | /* |
| 2336 | * In multi channel scenarios guarantee that the virtual |
| 2337 | * interface is granted immediate airtime to transmit the |
| 2338 | * deauthentication frame by calling mgd_prepare_tx, if the |
| 2339 | * driver requested so. |
| 2340 | */ |
| 2341 | if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) && |
| 2342 | !ifmgd->have_beacon) |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 2343 | drv_mgd_prepare_tx(sdata->local, sdata, 0); |
Ilan Peer | 94ba927 | 2018-02-19 14:48:41 +0200 | [diff] [blame] | 2344 | |
Johannes Berg | 4b08d1b | 2019-08-30 14:24:51 +0300 | [diff] [blame] | 2345 | ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, |
| 2346 | ifmgd->bssid, stype, reason, |
| 2347 | tx, frame_buf); |
Ilan Peer | 94ba927 | 2018-02-19 14:48:41 +0200 | [diff] [blame] | 2348 | } |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2349 | |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 2350 | /* flush out frame - make sure the deauth was actually sent */ |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2351 | if (tx) |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 2352 | ieee80211_flush_queues(local, sdata, false); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2353 | |
Eliad Peller | 88a9e31 | 2012-06-01 11:14:03 +0300 | [diff] [blame] | 2354 | /* clear bssid only after building the needed mgmt frames */ |
Joe Perches | c84a67a | 2015-03-02 19:54:57 -0800 | [diff] [blame] | 2355 | eth_zero_addr(ifmgd->bssid); |
Eliad Peller | 88a9e31 | 2012-06-01 11:14:03 +0300 | [diff] [blame] | 2356 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2357 | /* remove AP and TDLS peers */ |
Johannes Berg | d34ba21 | 2013-12-04 22:46:11 +0100 | [diff] [blame] | 2358 | sta_info_flush(sdata); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2359 | |
| 2360 | /* finally reset all BSS / config parameters */ |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 2361 | changed |= ieee80211_reset_erp_info(sdata); |
| 2362 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 2363 | ieee80211_led_assoc(local, 0); |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2364 | changed |= BSS_CHANGED_ASSOC; |
| 2365 | sdata->vif.bss_conf.assoc = false; |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 2366 | |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 2367 | ifmgd->p2p_noa_index = -1; |
| 2368 | memset(&sdata->vif.bss_conf.p2p_noa_attr, 0, |
| 2369 | sizeof(sdata->vif.bss_conf.p2p_noa_attr)); |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 2370 | |
Johannes Berg | dd5ecfe | 2013-02-21 17:40:19 +0100 | [diff] [blame] | 2371 | /* on the next assoc, re-program HT/VHT parameters */ |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 2372 | memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa)); |
| 2373 | memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask)); |
Johannes Berg | dd5ecfe | 2013-02-21 17:40:19 +0100 | [diff] [blame] | 2374 | memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa)); |
| 2375 | memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask)); |
Sara Sharon | 23a1f8d | 2015-12-08 16:04:31 +0200 | [diff] [blame] | 2376 | |
| 2377 | /* reset MU-MIMO ownership and group data */ |
| 2378 | memset(sdata->vif.bss_conf.mu_group.membership, 0, |
| 2379 | sizeof(sdata->vif.bss_conf.mu_group.membership)); |
| 2380 | memset(sdata->vif.bss_conf.mu_group.position, 0, |
| 2381 | sizeof(sdata->vif.bss_conf.mu_group.position)); |
| 2382 | changed |= BSS_CHANGED_MU_GROUPS; |
Sara Sharon | b5a33d5 | 2016-02-16 12:48:18 +0200 | [diff] [blame] | 2383 | sdata->vif.mu_mimo_owner = false; |
Johannes Berg | 413ad50 | 2009-05-08 21:21:06 +0200 | [diff] [blame] | 2384 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2385 | sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL; |
Vasanthakumar Thiagarajan | a8302de | 2009-01-09 18:14:15 +0530 | [diff] [blame] | 2386 | |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 2387 | del_timer_sync(&local->dynamic_ps_timer); |
| 2388 | cancel_work_sync(&local->dynamic_ps_enable_work); |
| 2389 | |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2390 | /* Disable ARP filtering */ |
Johannes Berg | 0f19b41 | 2013-01-14 16:39:07 +0100 | [diff] [blame] | 2391 | if (sdata->vif.bss_conf.arp_addr_cnt) |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2392 | changed |= BSS_CHANGED_ARP_FILTER; |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2393 | |
Johannes Berg | 3abead5 | 2012-03-02 15:56:59 +0100 | [diff] [blame] | 2394 | sdata->vif.bss_conf.qos = false; |
| 2395 | changed |= BSS_CHANGED_QOS; |
| 2396 | |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 2397 | /* The BSSID (not really interesting) and HT changed */ |
| 2398 | changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT; |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2399 | ieee80211_bss_info_change_notify(sdata, changed); |
Tomas Winkler | 8e268e4 | 2008-11-25 13:05:44 +0200 | [diff] [blame] | 2400 | |
Johannes Berg | 3abead5 | 2012-03-02 15:56:59 +0100 | [diff] [blame] | 2401 | /* disassociated - set to defaults now */ |
Johannes Berg | cec6628 | 2015-10-22 17:46:04 +0200 | [diff] [blame] | 2402 | ieee80211_set_wmm_default(sdata, false, false); |
Johannes Berg | 3abead5 | 2012-03-02 15:56:59 +0100 | [diff] [blame] | 2403 | |
Johannes Berg | b9dcf71 | 2010-08-27 12:35:54 +0200 | [diff] [blame] | 2404 | del_timer_sync(&sdata->u.mgd.conn_mon_timer); |
| 2405 | del_timer_sync(&sdata->u.mgd.bcn_mon_timer); |
| 2406 | del_timer_sync(&sdata->u.mgd.timer); |
| 2407 | del_timer_sync(&sdata->u.mgd.chswitch_timer); |
Johannes Berg | 2d9957c | 2012-08-01 20:54:52 +0200 | [diff] [blame] | 2408 | |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 2409 | sdata->vif.bss_conf.dtim_period = 0; |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 2410 | sdata->vif.bss_conf.beacon_rate = NULL; |
| 2411 | |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 2412 | ifmgd->have_beacon = false; |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 2413 | |
Johannes Berg | 028e8da0 | 2012-11-26 11:57:41 +0100 | [diff] [blame] | 2414 | ifmgd->flags = 0; |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2415 | mutex_lock(&local->mtx); |
Johannes Berg | 028e8da0 | 2012-11-26 11:57:41 +0100 | [diff] [blame] | 2416 | ieee80211_vif_release_channel(sdata); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 2417 | |
| 2418 | sdata->vif.csa_active = false; |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 2419 | ifmgd->csa_waiting_bcn = false; |
Johannes Berg | f84eaa1 | 2015-03-12 08:53:26 +0200 | [diff] [blame] | 2420 | ifmgd->csa_ignored_same_chan = false; |
Luciano Coelho | a46992b | 2014-06-13 16:30:07 +0300 | [diff] [blame] | 2421 | if (sdata->csa_block_tx) { |
| 2422 | ieee80211_wake_vif_queues(local, sdata, |
| 2423 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 2424 | sdata->csa_block_tx = false; |
| 2425 | } |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2426 | mutex_unlock(&local->mtx); |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 2427 | |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 2428 | /* existing TX TSPEC sessions no longer exist */ |
| 2429 | memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec)); |
| 2430 | cancel_delayed_work_sync(&ifmgd->tx_tspec_wk); |
| 2431 | |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 2432 | sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2433 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2434 | |
Kalle Valo | 3cf335d5 | 2009-03-22 21:57:06 +0200 | [diff] [blame] | 2435 | void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata, |
| 2436 | struct ieee80211_hdr *hdr) |
| 2437 | { |
| 2438 | /* |
| 2439 | * We can postpone the mgd.timer whenever receiving unicast frames |
| 2440 | * from AP because we know that the connection is working both ways |
| 2441 | * at that time. But multicast frames (and hence also beacons) must |
| 2442 | * be ignored here, because we need to trigger the timer during |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2443 | * data idle periods for sending the periodic probe request to the |
| 2444 | * AP we're connected to. |
Kalle Valo | 3cf335d5 | 2009-03-22 21:57:06 +0200 | [diff] [blame] | 2445 | */ |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2446 | if (is_multicast_ether_addr(hdr->addr1)) |
| 2447 | return; |
| 2448 | |
Luis R. Rodriguez | be099e8 | 2010-09-16 15:12:29 -0400 | [diff] [blame] | 2449 | ieee80211_sta_reset_conn_monitor(sdata); |
Kalle Valo | 3cf335d5 | 2009-03-22 21:57:06 +0200 | [diff] [blame] | 2450 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2451 | |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2452 | static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata) |
| 2453 | { |
| 2454 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2455 | struct ieee80211_local *local = sdata->local; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2456 | |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2457 | mutex_lock(&local->mtx); |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 2458 | if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)) |
| 2459 | goto out; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2460 | |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 2461 | __ieee80211_stop_poll(sdata); |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2462 | |
| 2463 | mutex_lock(&local->iflist_mtx); |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 2464 | ieee80211_recalc_ps(local); |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2465 | mutex_unlock(&local->iflist_mtx); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2466 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2467 | if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR)) |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2468 | goto out; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2469 | |
| 2470 | /* |
| 2471 | * We've received a probe response, but are not sure whether |
| 2472 | * we have or will be receiving any beacons or data, so let's |
| 2473 | * schedule the timers again, just in case. |
| 2474 | */ |
| 2475 | ieee80211_sta_reset_beacon_monitor(sdata); |
| 2476 | |
| 2477 | mod_timer(&ifmgd->conn_mon_timer, |
| 2478 | round_jiffies_up(jiffies + |
| 2479 | IEEE80211_CONNECTION_IDLE_TIME)); |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2480 | out: |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2481 | mutex_unlock(&local->mtx); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2482 | } |
| 2483 | |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 2484 | static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata, |
| 2485 | struct ieee80211_hdr *hdr, |
| 2486 | u16 tx_time) |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2487 | { |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 2488 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Sara Sharon | a1f2ba04c | 2018-02-19 14:48:40 +0200 | [diff] [blame] | 2489 | u16 tid = ieee80211_get_tid(hdr); |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 2490 | int ac = ieee80211_ac_from_tid(tid); |
| 2491 | struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac]; |
| 2492 | unsigned long now = jiffies; |
| 2493 | |
| 2494 | if (likely(!tx_tspec->admitted_time)) |
| 2495 | return; |
| 2496 | |
| 2497 | if (time_after(now, tx_tspec->time_slice_start + HZ)) { |
| 2498 | tx_tspec->consumed_tx_time = 0; |
| 2499 | tx_tspec->time_slice_start = now; |
| 2500 | |
| 2501 | if (tx_tspec->downgraded) { |
| 2502 | tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE; |
| 2503 | schedule_delayed_work(&ifmgd->tx_tspec_wk, 0); |
| 2504 | } |
| 2505 | } |
| 2506 | |
| 2507 | if (tx_tspec->downgraded) |
| 2508 | return; |
| 2509 | |
| 2510 | tx_tspec->consumed_tx_time += tx_time; |
| 2511 | |
| 2512 | if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) { |
| 2513 | tx_tspec->downgraded = true; |
| 2514 | tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE; |
| 2515 | schedule_delayed_work(&ifmgd->tx_tspec_wk, 0); |
| 2516 | } |
| 2517 | } |
| 2518 | |
| 2519 | void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata, |
| 2520 | struct ieee80211_hdr *hdr, bool ack, u16 tx_time) |
| 2521 | { |
| 2522 | ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time); |
| 2523 | |
Felix Fietkau | 75706d0 | 2010-12-02 21:01:07 +0100 | [diff] [blame] | 2524 | if (!ieee80211_is_data(hdr->frame_control)) |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2525 | return; |
| 2526 | |
Thomas Pedersen | 30b2f0b | 2020-01-13 21:59:40 -0800 | [diff] [blame] | 2527 | if (ieee80211_is_any_nullfunc(hdr->frame_control) && |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2528 | sdata->u.mgd.probe_send_count > 0) { |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2529 | if (ack) |
Wojciech Dubowik | cab1c7f | 2013-02-14 14:08:37 +0100 | [diff] [blame] | 2530 | ieee80211_sta_reset_conn_monitor(sdata); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2531 | else |
| 2532 | sdata->u.mgd.nullfunc_failed = true; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2533 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
Wojciech Dubowik | cab1c7f | 2013-02-14 14:08:37 +0100 | [diff] [blame] | 2534 | return; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2535 | } |
Wojciech Dubowik | cab1c7f | 2013-02-14 14:08:37 +0100 | [diff] [blame] | 2536 | |
| 2537 | if (ack) |
| 2538 | ieee80211_sta_reset_conn_monitor(sdata); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2539 | } |
| 2540 | |
Johannes Berg | 45ad683 | 2018-05-28 15:47:39 +0200 | [diff] [blame] | 2541 | static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata, |
| 2542 | const u8 *src, const u8 *dst, |
| 2543 | const u8 *ssid, size_t ssid_len, |
| 2544 | struct ieee80211_channel *channel) |
| 2545 | { |
| 2546 | struct sk_buff *skb; |
| 2547 | |
| 2548 | skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel, |
| 2549 | ssid, ssid_len, NULL, 0, |
| 2550 | IEEE80211_PROBE_FLAG_DIRECTED); |
| 2551 | if (skb) |
| 2552 | ieee80211_tx_skb(sdata, skb); |
| 2553 | } |
| 2554 | |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2555 | static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata) |
| 2556 | { |
| 2557 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 2558 | const u8 *ssid; |
Luis R. Rodriguez | f01a067 | 2010-09-16 15:12:34 -0400 | [diff] [blame] | 2559 | u8 *dst = ifmgd->associated->bssid; |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 2560 | u8 unicast_limit = max(1, max_probe_tries - 3); |
Johannes Berg | 49ddf8e | 2016-03-31 20:02:10 +0300 | [diff] [blame] | 2561 | struct sta_info *sta; |
Luis R. Rodriguez | f01a067 | 2010-09-16 15:12:34 -0400 | [diff] [blame] | 2562 | |
| 2563 | /* |
| 2564 | * Try sending broadcast probe requests for the last three |
| 2565 | * probe requests after the first ones failed since some |
| 2566 | * buggy APs only support broadcast probe requests. |
| 2567 | */ |
| 2568 | if (ifmgd->probe_send_count >= unicast_limit) |
| 2569 | dst = NULL; |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2570 | |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2571 | /* |
| 2572 | * When the hardware reports an accurate Tx ACK status, it's |
| 2573 | * better to send a nullfunc frame instead of a probe request, |
| 2574 | * as it will kick us off the AP quickly if we aren't associated |
| 2575 | * anymore. The timeout will be reset if the frame is ACKed by |
| 2576 | * the AP. |
| 2577 | */ |
Soumik Das | 992e68b | 2012-05-20 15:31:13 +0530 | [diff] [blame] | 2578 | ifmgd->probe_send_count++; |
| 2579 | |
Johannes Berg | 49ddf8e | 2016-03-31 20:02:10 +0300 | [diff] [blame] | 2580 | if (dst) { |
| 2581 | mutex_lock(&sdata->local->sta_mtx); |
| 2582 | sta = sta_info_get(sdata, dst); |
| 2583 | if (!WARN_ON(!sta)) |
| 2584 | ieee80211_check_fast_rx(sta); |
| 2585 | mutex_unlock(&sdata->local->sta_mtx); |
| 2586 | } |
| 2587 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2588 | if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) { |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2589 | ifmgd->nullfunc_failed = false; |
Shay Bar | f39b07f | 2019-07-03 16:18:48 +0300 | [diff] [blame] | 2590 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) |
| 2591 | ifmgd->probe_send_count--; |
| 2592 | else |
| 2593 | ieee80211_send_nullfunc(sdata->local, sdata, false); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2594 | } else { |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 2595 | int ssid_len; |
| 2596 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2597 | rcu_read_lock(); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2598 | ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID); |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 2599 | if (WARN_ON_ONCE(ssid == NULL)) |
| 2600 | ssid_len = 0; |
| 2601 | else |
| 2602 | ssid_len = ssid[1]; |
| 2603 | |
Johannes Berg | 45ad683 | 2018-05-28 15:47:39 +0200 | [diff] [blame] | 2604 | ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst, |
| 2605 | ssid + 2, ssid_len, |
| 2606 | ifmgd->associated->channel); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2607 | rcu_read_unlock(); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2608 | } |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2609 | |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 2610 | ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2611 | run_again(sdata, ifmgd->probe_timeout); |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2612 | } |
| 2613 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2614 | static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata, |
| 2615 | bool beacon) |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2616 | { |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2617 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2618 | bool already = false; |
Johannes Berg | 34bfc41 | 2009-05-12 19:58:12 +0200 | [diff] [blame] | 2619 | |
Johannes Berg | 9607e6b66 | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 2620 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | 0e2b628 | 2009-07-13 13:23:39 +0200 | [diff] [blame] | 2621 | return; |
| 2622 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2623 | sdata_lock(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2624 | |
| 2625 | if (!ifmgd->associated) |
| 2626 | goto out; |
| 2627 | |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2628 | mutex_lock(&sdata->local->mtx); |
| 2629 | |
| 2630 | if (sdata->local->tmp_channel || sdata->local->scanning) { |
| 2631 | mutex_unlock(&sdata->local->mtx); |
| 2632 | goto out; |
| 2633 | } |
| 2634 | |
Ben Greear | a13fbe5 | 2013-03-25 11:19:35 -0700 | [diff] [blame] | 2635 | if (beacon) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2636 | mlme_dbg_ratelimited(sdata, |
Ben Greear | 59c1ec2 | 2013-03-19 14:19:56 -0700 | [diff] [blame] | 2637 | "detected beacon loss from AP (missed %d beacons) - probing\n", |
| 2638 | beacon_loss_count); |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2639 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 2640 | ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL); |
Ben Greear | a13fbe5 | 2013-03-25 11:19:35 -0700 | [diff] [blame] | 2641 | } |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2642 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2643 | /* |
| 2644 | * The driver/our work has already reported this event or the |
| 2645 | * connection monitoring has kicked in and we have already sent |
| 2646 | * a probe request. Or maybe the AP died and the driver keeps |
| 2647 | * reporting until we disassociate... |
| 2648 | * |
| 2649 | * In either case we have to ignore the current call to this |
| 2650 | * function (except for setting the correct probe reason bit) |
| 2651 | * because otherwise we would reset the timer every time and |
| 2652 | * never check whether we received a probe response! |
| 2653 | */ |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 2654 | if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2655 | already = true; |
| 2656 | |
Eliad Peller | 12b5f34 | 2013-11-18 19:06:46 +0200 | [diff] [blame] | 2657 | ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL; |
| 2658 | |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2659 | mutex_unlock(&sdata->local->mtx); |
| 2660 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2661 | if (already) |
| 2662 | goto out; |
| 2663 | |
Johannes Berg | 4e75184 | 2009-06-10 15:16:52 +0200 | [diff] [blame] | 2664 | mutex_lock(&sdata->local->iflist_mtx); |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 2665 | ieee80211_recalc_ps(sdata->local); |
Johannes Berg | 4e75184 | 2009-06-10 15:16:52 +0200 | [diff] [blame] | 2666 | mutex_unlock(&sdata->local->iflist_mtx); |
| 2667 | |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2668 | ifmgd->probe_send_count = 0; |
| 2669 | ieee80211_mgd_probe_ap_send(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2670 | out: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2671 | sdata_unlock(sdata); |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2672 | } |
| 2673 | |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2674 | struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw, |
| 2675 | struct ieee80211_vif *vif) |
| 2676 | { |
| 2677 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 2678 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Eliad Peller | d9b3b28 | 2012-06-28 15:03:13 +0300 | [diff] [blame] | 2679 | struct cfg80211_bss *cbss; |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2680 | struct sk_buff *skb; |
| 2681 | const u8 *ssid; |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 2682 | int ssid_len; |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2683 | |
| 2684 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) |
| 2685 | return NULL; |
| 2686 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2687 | sdata_assert_lock(sdata); |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2688 | |
Eliad Peller | d9b3b28 | 2012-06-28 15:03:13 +0300 | [diff] [blame] | 2689 | if (ifmgd->associated) |
| 2690 | cbss = ifmgd->associated; |
| 2691 | else if (ifmgd->auth_data) |
| 2692 | cbss = ifmgd->auth_data->bss; |
| 2693 | else if (ifmgd->assoc_data) |
| 2694 | cbss = ifmgd->assoc_data->bss; |
| 2695 | else |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2696 | return NULL; |
| 2697 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2698 | rcu_read_lock(); |
Eliad Peller | d9b3b28 | 2012-06-28 15:03:13 +0300 | [diff] [blame] | 2699 | ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID); |
Will Deacon | 4152561 | 2019-10-04 10:51:31 +0100 | [diff] [blame] | 2700 | if (WARN_ONCE(!ssid || ssid[1] > IEEE80211_MAX_SSID_LEN, |
| 2701 | "invalid SSID element (len=%d)", ssid ? ssid[1] : -1)) |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 2702 | ssid_len = 0; |
| 2703 | else |
| 2704 | ssid_len = ssid[1]; |
| 2705 | |
Johannes Berg | a344d67 | 2014-06-12 22:24:31 +0200 | [diff] [blame] | 2706 | skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid, |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2707 | (u32) -1, cbss->channel, |
Johannes Berg | 6b77863 | 2012-07-23 14:53:27 +0200 | [diff] [blame] | 2708 | ssid + 2, ssid_len, |
Johannes Berg | 00387f3 | 2018-05-28 15:47:38 +0200 | [diff] [blame] | 2709 | NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2710 | rcu_read_unlock(); |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2711 | |
| 2712 | return skb; |
| 2713 | } |
| 2714 | EXPORT_SYMBOL(ieee80211_ap_probereq_get); |
| 2715 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 2716 | static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata, |
| 2717 | const u8 *buf, size_t len, bool tx, |
| 2718 | u16 reason) |
| 2719 | { |
| 2720 | struct ieee80211_event event = { |
| 2721 | .type = MLME_EVENT, |
| 2722 | .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT, |
| 2723 | .u.mlme.reason = reason, |
| 2724 | }; |
| 2725 | |
| 2726 | if (tx) |
| 2727 | cfg80211_tx_mlme_mgmt(sdata->dev, buf, len); |
| 2728 | else |
| 2729 | cfg80211_rx_mlme_mgmt(sdata->dev, buf, len); |
| 2730 | |
| 2731 | drv_event_callback(sdata->local, sdata, &event); |
| 2732 | } |
| 2733 | |
Johannes Berg | eef9e54 | 2013-01-29 13:09:34 +0100 | [diff] [blame] | 2734 | static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata) |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2735 | { |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 2736 | struct ieee80211_local *local = sdata->local; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2737 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 2738 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 2739 | bool tx; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2740 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2741 | sdata_lock(sdata); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2742 | if (!ifmgd->associated) { |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2743 | sdata_unlock(sdata); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2744 | return; |
| 2745 | } |
| 2746 | |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 2747 | tx = !sdata->csa_block_tx; |
| 2748 | |
David Spinadel | 20eb7ea | 2016-05-03 16:05:02 +0300 | [diff] [blame] | 2749 | /* AP is probably out of range (or not reachable for another reason) so |
| 2750 | * remove the bss struct for that AP. |
| 2751 | */ |
| 2752 | cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated); |
| 2753 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2754 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
| 2755 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 2756 | tx, frame_buf); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 2757 | mutex_lock(&local->mtx); |
Arik Nemtsov | 7578d57 | 2013-09-01 17:15:51 +0300 | [diff] [blame] | 2758 | sdata->vif.csa_active = false; |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 2759 | ifmgd->csa_waiting_bcn = false; |
Luciano Coelho | a46992b | 2014-06-13 16:30:07 +0300 | [diff] [blame] | 2760 | if (sdata->csa_block_tx) { |
| 2761 | ieee80211_wake_vif_queues(local, sdata, |
| 2762 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 2763 | sdata->csa_block_tx = false; |
| 2764 | } |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 2765 | mutex_unlock(&local->mtx); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 2766 | |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 2767 | ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx, |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 2768 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY); |
| 2769 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2770 | sdata_unlock(sdata); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2771 | } |
| 2772 | |
Johannes Berg | cc74c0c | 2012-08-01 16:49:34 +0200 | [diff] [blame] | 2773 | static void ieee80211_beacon_connection_loss_work(struct work_struct *work) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2774 | { |
| 2775 | struct ieee80211_sub_if_data *sdata = |
| 2776 | container_of(work, struct ieee80211_sub_if_data, |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2777 | u.mgd.beacon_connection_loss_work); |
Paul Stewart | a85e1d5 | 2011-12-09 11:01:49 -0800 | [diff] [blame] | 2778 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Paul Stewart | a85e1d5 | 2011-12-09 11:01:49 -0800 | [diff] [blame] | 2779 | |
Johannes Berg | 976bd9e | 2015-10-16 17:18:11 +0200 | [diff] [blame] | 2780 | if (ifmgd->associated) |
| 2781 | ifmgd->beacon_loss_count++; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2782 | |
Johannes Berg | 682bd38 | 2013-01-29 13:13:50 +0100 | [diff] [blame] | 2783 | if (ifmgd->connection_loss) { |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 2784 | sdata_info(sdata, "Connection to AP %pM lost\n", |
| 2785 | ifmgd->bssid); |
Johannes Berg | eef9e54 | 2013-01-29 13:09:34 +0100 | [diff] [blame] | 2786 | __ieee80211_disconnect(sdata); |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 2787 | } else { |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2788 | ieee80211_mgd_probe_ap(sdata, true); |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 2789 | } |
| 2790 | } |
| 2791 | |
| 2792 | static void ieee80211_csa_connection_drop_work(struct work_struct *work) |
| 2793 | { |
| 2794 | struct ieee80211_sub_if_data *sdata = |
| 2795 | container_of(work, struct ieee80211_sub_if_data, |
| 2796 | u.mgd.csa_connection_drop_work); |
| 2797 | |
Johannes Berg | eef9e54 | 2013-01-29 13:09:34 +0100 | [diff] [blame] | 2798 | __ieee80211_disconnect(sdata); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2799 | } |
| 2800 | |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2801 | void ieee80211_beacon_loss(struct ieee80211_vif *vif) |
| 2802 | { |
| 2803 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2804 | struct ieee80211_hw *hw = &sdata->local->hw; |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2805 | |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 2806 | trace_api_beacon_loss(sdata); |
| 2807 | |
Johannes Berg | 682bd38 | 2013-01-29 13:13:50 +0100 | [diff] [blame] | 2808 | sdata->u.mgd.connection_loss = false; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2809 | ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work); |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2810 | } |
| 2811 | EXPORT_SYMBOL(ieee80211_beacon_loss); |
| 2812 | |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2813 | void ieee80211_connection_loss(struct ieee80211_vif *vif) |
| 2814 | { |
| 2815 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 2816 | struct ieee80211_hw *hw = &sdata->local->hw; |
| 2817 | |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 2818 | trace_api_connection_loss(sdata); |
| 2819 | |
Johannes Berg | 682bd38 | 2013-01-29 13:13:50 +0100 | [diff] [blame] | 2820 | sdata->u.mgd.connection_loss = true; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2821 | ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work); |
| 2822 | } |
| 2823 | EXPORT_SYMBOL(ieee80211_connection_loss); |
| 2824 | |
| 2825 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2826 | static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata, |
| 2827 | bool assoc) |
| 2828 | { |
| 2829 | struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data; |
| 2830 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2831 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2832 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2833 | if (!assoc) { |
Emmanuel Grumbach | c1e140b | 2015-01-19 16:53:06 +0200 | [diff] [blame] | 2834 | /* |
| 2835 | * we are not authenticated yet, the only timer that could be |
| 2836 | * running is the timeout for the authentication response which |
| 2837 | * which is not relevant anymore. |
| 2838 | */ |
| 2839 | del_timer_sync(&sdata->u.mgd.timer); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2840 | sta_info_destroy_addr(sdata, auth_data->bss->bssid); |
| 2841 | |
Joe Perches | c84a67a | 2015-03-02 19:54:57 -0800 | [diff] [blame] | 2842 | eth_zero_addr(sdata->u.mgd.bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2843 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
Johannes Berg | 028e8da0 | 2012-11-26 11:57:41 +0100 | [diff] [blame] | 2844 | sdata->u.mgd.flags = 0; |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2845 | mutex_lock(&sdata->local->mtx); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2846 | ieee80211_vif_release_channel(sdata); |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2847 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2848 | } |
| 2849 | |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 2850 | cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2851 | kfree(auth_data); |
| 2852 | sdata->u.mgd.auth_data = NULL; |
| 2853 | } |
| 2854 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 2855 | static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 2856 | bool assoc, bool abandon) |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 2857 | { |
| 2858 | struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data; |
| 2859 | |
| 2860 | sdata_assert_lock(sdata); |
| 2861 | |
| 2862 | if (!assoc) { |
| 2863 | /* |
| 2864 | * we are not associated yet, the only timer that could be |
| 2865 | * running is the timeout for the association response which |
| 2866 | * which is not relevant anymore. |
| 2867 | */ |
| 2868 | del_timer_sync(&sdata->u.mgd.timer); |
| 2869 | sta_info_destroy_addr(sdata, assoc_data->bss->bssid); |
| 2870 | |
| 2871 | eth_zero_addr(sdata->u.mgd.bssid); |
| 2872 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
| 2873 | sdata->u.mgd.flags = 0; |
Sara Sharon | b5a33d5 | 2016-02-16 12:48:18 +0200 | [diff] [blame] | 2874 | sdata->vif.mu_mimo_owner = false; |
| 2875 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 2876 | mutex_lock(&sdata->local->mtx); |
| 2877 | ieee80211_vif_release_channel(sdata); |
| 2878 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 2879 | |
| 2880 | if (abandon) |
| 2881 | cfg80211_abandon_assoc(sdata->dev, assoc_data->bss); |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 2882 | } |
| 2883 | |
| 2884 | kfree(assoc_data); |
| 2885 | sdata->u.mgd.assoc_data = NULL; |
| 2886 | } |
| 2887 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2888 | static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata, |
| 2889 | struct ieee80211_mgmt *mgmt, size_t len) |
| 2890 | { |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 2891 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2892 | struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data; |
| 2893 | u8 *pos; |
| 2894 | struct ieee802_11_elems elems; |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 2895 | u32 tx_flags = 0; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2896 | |
| 2897 | pos = mgmt->u.auth.variable; |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 2898 | ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems, |
| 2899 | mgmt->bssid, auth_data->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2900 | if (!elems.challenge) |
| 2901 | return; |
| 2902 | auth_data->expected_transaction = 4; |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 2903 | drv_mgd_prepare_tx(sdata->local, sdata, 0); |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2904 | if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 2905 | tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS | |
| 2906 | IEEE80211_TX_INTFL_MLME_CONN_TX; |
Jouni Malinen | 700e8ea | 2012-09-30 19:29:37 +0300 | [diff] [blame] | 2907 | ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0, |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2908 | elems.challenge - 2, elems.challenge_len + 2, |
| 2909 | auth_data->bss->bssid, auth_data->bss->bssid, |
| 2910 | auth_data->key, auth_data->key_len, |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 2911 | auth_data->key_idx, tx_flags); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2912 | } |
| 2913 | |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2914 | static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata, |
| 2915 | const u8 *bssid) |
| 2916 | { |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 2917 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2918 | struct sta_info *sta; |
Wei Yongjun | 33483a6 | 2018-10-16 02:35:30 +0000 | [diff] [blame] | 2919 | bool result = true; |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2920 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 2921 | sdata_info(sdata, "authenticated\n"); |
| 2922 | ifmgd->auth_data->done = true; |
| 2923 | ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC; |
| 2924 | ifmgd->auth_data->timeout_started = true; |
| 2925 | run_again(sdata, ifmgd->auth_data->timeout); |
| 2926 | |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2927 | /* move station state to auth */ |
| 2928 | mutex_lock(&sdata->local->sta_mtx); |
| 2929 | sta = sta_info_get(sdata, bssid); |
| 2930 | if (!sta) { |
| 2931 | WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid); |
Wei Yongjun | 33483a6 | 2018-10-16 02:35:30 +0000 | [diff] [blame] | 2932 | result = false; |
| 2933 | goto out; |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2934 | } |
| 2935 | if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) { |
| 2936 | sdata_info(sdata, "failed moving %pM to auth\n", bssid); |
Wei Yongjun | 33483a6 | 2018-10-16 02:35:30 +0000 | [diff] [blame] | 2937 | result = false; |
| 2938 | goto out; |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2939 | } |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2940 | |
Wei Yongjun | 33483a6 | 2018-10-16 02:35:30 +0000 | [diff] [blame] | 2941 | out: |
| 2942 | mutex_unlock(&sdata->local->sta_mtx); |
| 2943 | return result; |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2944 | } |
| 2945 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2946 | static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata, |
| 2947 | struct ieee80211_mgmt *mgmt, size_t len) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2948 | { |
| 2949 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 2950 | u8 bssid[ETH_ALEN]; |
| 2951 | u16 auth_alg, auth_transaction, status_code; |
Emmanuel Grumbach | a940909 | 2015-03-16 23:23:35 +0200 | [diff] [blame] | 2952 | struct ieee80211_event event = { |
| 2953 | .type = MLME_EVENT, |
| 2954 | .u.mlme.data = AUTH_EVENT, |
| 2955 | }; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2956 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2957 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2958 | |
| 2959 | if (len < 24 + 6) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2960 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2961 | |
| 2962 | if (!ifmgd->auth_data || ifmgd->auth_data->done) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2963 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2964 | |
| 2965 | memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN); |
| 2966 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2967 | if (!ether_addr_equal(bssid, mgmt->bssid)) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2968 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2969 | |
| 2970 | auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); |
| 2971 | auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); |
| 2972 | status_code = le16_to_cpu(mgmt->u.auth.status_code); |
| 2973 | |
| 2974 | if (auth_alg != ifmgd->auth_data->algorithm || |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 2975 | (auth_alg != WLAN_AUTH_SAE && |
| 2976 | auth_transaction != ifmgd->auth_data->expected_transaction) || |
| 2977 | (auth_alg == WLAN_AUTH_SAE && |
| 2978 | (auth_transaction < ifmgd->auth_data->expected_transaction || |
| 2979 | auth_transaction > 2))) { |
Jouni Malinen | 0f4126e | 2012-09-30 19:29:38 +0300 | [diff] [blame] | 2980 | sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n", |
| 2981 | mgmt->sa, auth_alg, ifmgd->auth_data->algorithm, |
| 2982 | auth_transaction, |
| 2983 | ifmgd->auth_data->expected_transaction); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2984 | return; |
Jouni Malinen | 0f4126e | 2012-09-30 19:29:38 +0300 | [diff] [blame] | 2985 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2986 | |
| 2987 | if (status_code != WLAN_STATUS_SUCCESS) { |
Andrei Otcheretianski | a4055e7 | 2020-03-26 15:09:34 +0200 | [diff] [blame] | 2988 | cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len); |
| 2989 | |
| 2990 | if (auth_alg == WLAN_AUTH_SAE && |
Jouni Malinen | 4e56cde | 2020-07-31 21:38:30 +0300 | [diff] [blame] | 2991 | (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED || |
| 2992 | (auth_transaction == 1 && |
| 2993 | (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT || |
| 2994 | status_code == WLAN_STATUS_SAE_PK)))) |
Andrei Otcheretianski | a4055e7 | 2020-03-26 15:09:34 +0200 | [diff] [blame] | 2995 | return; |
| 2996 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2997 | sdata_info(sdata, "%pM denied authentication (status %d)\n", |
| 2998 | mgmt->sa, status_code); |
Eliad Peller | dac211e | 2012-05-13 18:07:04 +0300 | [diff] [blame] | 2999 | ieee80211_destroy_auth_data(sdata, false); |
Emmanuel Grumbach | a940909 | 2015-03-16 23:23:35 +0200 | [diff] [blame] | 3000 | event.u.mlme.status = MLME_DENIED; |
| 3001 | event.u.mlme.reason = status_code; |
| 3002 | drv_event_callback(sdata->local, sdata, &event); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3003 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3004 | } |
| 3005 | |
| 3006 | switch (ifmgd->auth_data->algorithm) { |
| 3007 | case WLAN_AUTH_OPEN: |
| 3008 | case WLAN_AUTH_LEAP: |
| 3009 | case WLAN_AUTH_FT: |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 3010 | case WLAN_AUTH_SAE: |
Jouni Malinen | dbc0c2c | 2016-10-27 00:42:04 +0300 | [diff] [blame] | 3011 | case WLAN_AUTH_FILS_SK: |
| 3012 | case WLAN_AUTH_FILS_SK_PFS: |
| 3013 | case WLAN_AUTH_FILS_PK: |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3014 | break; |
| 3015 | case WLAN_AUTH_SHARED_KEY: |
| 3016 | if (ifmgd->auth_data->expected_transaction != 4) { |
| 3017 | ieee80211_auth_challenge(sdata, mgmt, len); |
| 3018 | /* need another frame */ |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3019 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3020 | } |
| 3021 | break; |
| 3022 | default: |
| 3023 | WARN_ONCE(1, "invalid auth alg %d", |
| 3024 | ifmgd->auth_data->algorithm); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3025 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3026 | } |
| 3027 | |
Emmanuel Grumbach | a940909 | 2015-03-16 23:23:35 +0200 | [diff] [blame] | 3028 | event.u.mlme.status = MLME_SUCCESS; |
| 3029 | drv_event_callback(sdata->local, sdata, &event); |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 3030 | if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE || |
| 3031 | (auth_transaction == 2 && |
| 3032 | ifmgd->auth_data->expected_transaction == 2)) { |
| 3033 | if (!ieee80211_mark_sta_auth(sdata, bssid)) |
Andrei Otcheretianski | 0daa63e | 2020-02-21 10:47:20 +0100 | [diff] [blame] | 3034 | return; /* ignore frame -- wait for timeout */ |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 3035 | } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE && |
| 3036 | auth_transaction == 2) { |
| 3037 | sdata_info(sdata, "SAE peer confirmed\n"); |
| 3038 | ifmgd->auth_data->peer_confirmed = true; |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 3039 | } |
| 3040 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 3041 | cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3042 | } |
| 3043 | |
Calvin Owens | dfa1ad2 | 2014-02-11 12:36:24 -0600 | [diff] [blame] | 3044 | #define case_WLAN(type) \ |
| 3045 | case WLAN_REASON_##type: return #type |
| 3046 | |
Yu Wang | 79c92ca | 2019-05-10 17:04:52 +0800 | [diff] [blame] | 3047 | const char *ieee80211_get_reason_code_string(u16 reason_code) |
Calvin Owens | dfa1ad2 | 2014-02-11 12:36:24 -0600 | [diff] [blame] | 3048 | { |
| 3049 | switch (reason_code) { |
| 3050 | case_WLAN(UNSPECIFIED); |
| 3051 | case_WLAN(PREV_AUTH_NOT_VALID); |
| 3052 | case_WLAN(DEAUTH_LEAVING); |
| 3053 | case_WLAN(DISASSOC_DUE_TO_INACTIVITY); |
| 3054 | case_WLAN(DISASSOC_AP_BUSY); |
| 3055 | case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA); |
| 3056 | case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA); |
| 3057 | case_WLAN(DISASSOC_STA_HAS_LEFT); |
| 3058 | case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH); |
| 3059 | case_WLAN(DISASSOC_BAD_POWER); |
| 3060 | case_WLAN(DISASSOC_BAD_SUPP_CHAN); |
| 3061 | case_WLAN(INVALID_IE); |
| 3062 | case_WLAN(MIC_FAILURE); |
| 3063 | case_WLAN(4WAY_HANDSHAKE_TIMEOUT); |
| 3064 | case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT); |
| 3065 | case_WLAN(IE_DIFFERENT); |
| 3066 | case_WLAN(INVALID_GROUP_CIPHER); |
| 3067 | case_WLAN(INVALID_PAIRWISE_CIPHER); |
| 3068 | case_WLAN(INVALID_AKMP); |
| 3069 | case_WLAN(UNSUPP_RSN_VERSION); |
| 3070 | case_WLAN(INVALID_RSN_IE_CAP); |
| 3071 | case_WLAN(IEEE8021X_FAILED); |
| 3072 | case_WLAN(CIPHER_SUITE_REJECTED); |
| 3073 | case_WLAN(DISASSOC_UNSPECIFIED_QOS); |
| 3074 | case_WLAN(DISASSOC_QAP_NO_BANDWIDTH); |
| 3075 | case_WLAN(DISASSOC_LOW_ACK); |
| 3076 | case_WLAN(DISASSOC_QAP_EXCEED_TXOP); |
| 3077 | case_WLAN(QSTA_LEAVE_QBSS); |
| 3078 | case_WLAN(QSTA_NOT_USE); |
| 3079 | case_WLAN(QSTA_REQUIRE_SETUP); |
| 3080 | case_WLAN(QSTA_TIMEOUT); |
| 3081 | case_WLAN(QSTA_CIPHER_NOT_SUPP); |
| 3082 | case_WLAN(MESH_PEER_CANCELED); |
| 3083 | case_WLAN(MESH_MAX_PEERS); |
| 3084 | case_WLAN(MESH_CONFIG); |
| 3085 | case_WLAN(MESH_CLOSE); |
| 3086 | case_WLAN(MESH_MAX_RETRIES); |
| 3087 | case_WLAN(MESH_CONFIRM_TIMEOUT); |
| 3088 | case_WLAN(MESH_INVALID_GTK); |
| 3089 | case_WLAN(MESH_INCONSISTENT_PARAM); |
| 3090 | case_WLAN(MESH_INVALID_SECURITY); |
| 3091 | case_WLAN(MESH_PATH_ERROR); |
| 3092 | case_WLAN(MESH_PATH_NOFORWARD); |
| 3093 | case_WLAN(MESH_PATH_DEST_UNREACHABLE); |
| 3094 | case_WLAN(MAC_EXISTS_IN_MBSS); |
| 3095 | case_WLAN(MESH_CHAN_REGULATORY); |
| 3096 | case_WLAN(MESH_CHAN); |
| 3097 | default: return "<unknown>"; |
| 3098 | } |
| 3099 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3100 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3101 | static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata, |
| 3102 | struct ieee80211_mgmt *mgmt, size_t len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3103 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3104 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3105 | u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3106 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3107 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3108 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 3109 | if (len < 24 + 2) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3110 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3111 | |
Yu Wang | 79c92ca | 2019-05-10 17:04:52 +0800 | [diff] [blame] | 3112 | if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) { |
| 3113 | ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code); |
| 3114 | return; |
| 3115 | } |
| 3116 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3117 | if (ifmgd->associated && |
| 3118 | ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) { |
| 3119 | const u8 *bssid = ifmgd->associated->bssid; |
| 3120 | |
| 3121 | sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n", |
| 3122 | bssid, reason_code, |
| 3123 | ieee80211_get_reason_code_string(reason_code)); |
| 3124 | |
| 3125 | ieee80211_set_disassoc(sdata, 0, 0, false, NULL); |
| 3126 | |
| 3127 | ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, |
| 3128 | reason_code); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3129 | return; |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3130 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3131 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3132 | if (ifmgd->assoc_data && |
| 3133 | ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) { |
| 3134 | const u8 *bssid = ifmgd->assoc_data->bss->bssid; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3135 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3136 | sdata_info(sdata, |
| 3137 | "deauthenticated from %pM while associating (Reason: %u=%s)\n", |
| 3138 | bssid, reason_code, |
| 3139 | ieee80211_get_reason_code_string(reason_code)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3140 | |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 3141 | ieee80211_destroy_assoc_data(sdata, false, true); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3142 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3143 | cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len); |
| 3144 | return; |
| 3145 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3146 | } |
| 3147 | |
| 3148 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3149 | static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata, |
| 3150 | struct ieee80211_mgmt *mgmt, size_t len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3151 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3152 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3153 | u16 reason_code; |
| 3154 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3155 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3156 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 3157 | if (len < 24 + 2) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3158 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3159 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3160 | if (!ifmgd->associated || |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 3161 | !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3162 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3163 | |
| 3164 | reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); |
| 3165 | |
Yu Wang | 79c92ca | 2019-05-10 17:04:52 +0800 | [diff] [blame] | 3166 | if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) { |
| 3167 | ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code); |
| 3168 | return; |
| 3169 | } |
| 3170 | |
Arkadiusz Miskiewicz | 68506e9 | 2017-02-15 14:21:27 +0100 | [diff] [blame] | 3171 | sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n", |
| 3172 | mgmt->sa, reason_code, |
| 3173 | ieee80211_get_reason_code_string(reason_code)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3174 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 3175 | ieee80211_set_disassoc(sdata, 0, 0, false, NULL); |
| 3176 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 3177 | ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3178 | } |
| 3179 | |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3180 | static void ieee80211_get_rates(struct ieee80211_supported_band *sband, |
| 3181 | u8 *supp_rates, unsigned int supp_rates_len, |
| 3182 | u32 *rates, u32 *basic_rates, |
| 3183 | bool *have_higher_than_11mbit, |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3184 | int *min_rate, int *min_rate_index, |
Johannes Berg | 44f6d42 | 2017-06-10 13:52:44 +0300 | [diff] [blame] | 3185 | int shift) |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3186 | { |
| 3187 | int i, j; |
| 3188 | |
| 3189 | for (i = 0; i < supp_rates_len; i++) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3190 | int rate = supp_rates[i] & 0x7f; |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3191 | bool is_basic = !!(supp_rates[i] & 0x80); |
| 3192 | |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3193 | if ((rate * 5 * (1 << shift)) > 110) |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3194 | *have_higher_than_11mbit = true; |
| 3195 | |
| 3196 | /* |
Ilan Peer | 4826e72 | 2020-03-26 15:09:36 +0200 | [diff] [blame] | 3197 | * Skip HT, VHT and HE BSS membership selectors since they're |
| 3198 | * not rates. |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3199 | * |
Johannes Berg | a6289d3 | 2017-03-06 22:59:04 +0100 | [diff] [blame] | 3200 | * Note: Even though the membership selector and the basic |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3201 | * rate flag share the same bit, they are not exactly |
| 3202 | * the same. |
| 3203 | */ |
Johannes Berg | a6289d3 | 2017-03-06 22:59:04 +0100 | [diff] [blame] | 3204 | if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) || |
Ilan Peer | 4826e72 | 2020-03-26 15:09:36 +0200 | [diff] [blame] | 3205 | supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY) || |
| 3206 | supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY)) |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3207 | continue; |
| 3208 | |
| 3209 | for (j = 0; j < sband->n_bitrates; j++) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3210 | struct ieee80211_rate *br; |
| 3211 | int brate; |
| 3212 | |
| 3213 | br = &sband->bitrates[j]; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3214 | |
| 3215 | brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5); |
| 3216 | if (brate == rate) { |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3217 | *rates |= BIT(j); |
| 3218 | if (is_basic) |
| 3219 | *basic_rates |= BIT(j); |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3220 | if ((rate * 5) < *min_rate) { |
| 3221 | *min_rate = rate * 5; |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3222 | *min_rate_index = j; |
| 3223 | } |
| 3224 | break; |
| 3225 | } |
| 3226 | } |
| 3227 | } |
| 3228 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3229 | |
Emmanuel Grumbach | 55ebd6e | 2018-12-15 11:03:04 +0200 | [diff] [blame] | 3230 | static bool ieee80211_twt_req_supported(const struct sta_info *sta, |
| 3231 | const struct ieee802_11_elems *elems) |
| 3232 | { |
| 3233 | if (elems->ext_capab_len < 10) |
| 3234 | return false; |
| 3235 | |
| 3236 | if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT)) |
| 3237 | return false; |
| 3238 | |
| 3239 | return sta->sta.he_cap.he_cap_elem.mac_cap_info[0] & |
| 3240 | IEEE80211_HE_MAC_CAP0_TWT_RES; |
| 3241 | } |
| 3242 | |
John Crispin | c9d3245 | 2019-05-28 13:49:47 +0200 | [diff] [blame] | 3243 | static int ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata, |
| 3244 | struct sta_info *sta, |
| 3245 | struct ieee802_11_elems *elems) |
| 3246 | { |
| 3247 | bool twt = ieee80211_twt_req_supported(sta, elems); |
| 3248 | |
| 3249 | if (sdata->vif.bss_conf.twt_requester != twt) { |
| 3250 | sdata->vif.bss_conf.twt_requester = twt; |
| 3251 | return BSS_CHANGED_TWT; |
| 3252 | } |
| 3253 | return 0; |
| 3254 | } |
| 3255 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3256 | static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata, |
| 3257 | struct cfg80211_bss *cbss, |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3258 | struct ieee80211_mgmt *mgmt, size_t len, |
| 3259 | struct ieee802_11_elems *elems) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3260 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3261 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 3262 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3263 | struct ieee80211_supported_band *sband; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3264 | struct sta_info *sta; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3265 | u16 capab_info, aid; |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 3266 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3267 | const struct cfg80211_bss_ies *bss_ies = NULL; |
| 3268 | struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 3269 | bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ; |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 3270 | u32 changed = 0; |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3271 | int err; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3272 | bool ret; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3273 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3274 | /* AssocResp and ReassocResp have identical structure */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3275 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3276 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3277 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3278 | |
Johannes Berg | c7c477b | 2017-12-01 13:50:51 +0200 | [diff] [blame] | 3279 | /* |
| 3280 | * The 5 MSB of the AID field are reserved |
| 3281 | * (802.11-2016 9.4.1.8 AID field) |
| 3282 | */ |
| 3283 | aid &= 0x7ff; |
Johannes Berg | 1dd84aa | 2007-10-10 12:03:41 +0200 | [diff] [blame] | 3284 | |
Johannes Berg | 05cb910 | 2011-10-28 11:59:47 +0200 | [diff] [blame] | 3285 | ifmgd->broken_ap = false; |
| 3286 | |
| 3287 | if (aid == 0 || aid > IEEE80211_MAX_AID) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3288 | sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n", |
| 3289 | aid); |
Johannes Berg | 05cb910 | 2011-10-28 11:59:47 +0200 | [diff] [blame] | 3290 | aid = 0; |
| 3291 | ifmgd->broken_ap = true; |
| 3292 | } |
| 3293 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3294 | if (!elems->supp_rates) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3295 | sdata_info(sdata, "no SuppRates element in AssocResp\n"); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3296 | return false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3297 | } |
| 3298 | |
Johannes Berg | 1db364c | 2020-04-17 12:38:04 +0200 | [diff] [blame] | 3299 | sdata->vif.bss_conf.aid = aid; |
Arik Nemtsov | 9041c1f | 2014-11-09 18:50:15 +0200 | [diff] [blame] | 3300 | ifmgd->tdls_chan_switch_prohibited = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3301 | elems->ext_capab && elems->ext_capab_len >= 5 && |
| 3302 | (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3303 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3304 | /* |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3305 | * Some APs are erroneously not including some information in their |
| 3306 | * (re)association response frames. Try to recover by using the data |
| 3307 | * from the beacon or probe response. This seems to afflict mobile |
| 3308 | * 2G/3G/4G wifi routers, reported models include the "Onda PN51T", |
| 3309 | * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device. |
| 3310 | */ |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 3311 | if (!is_6ghz && |
| 3312 | ((assoc_data->wmm && !elems->wmm_param) || |
| 3313 | (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) && |
| 3314 | (!elems->ht_cap_elem || !elems->ht_operation)) || |
| 3315 | (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && |
| 3316 | (!elems->vht_cap_elem || !elems->vht_operation)))) { |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3317 | const struct cfg80211_bss_ies *ies; |
| 3318 | struct ieee802_11_elems bss_elems; |
| 3319 | |
| 3320 | rcu_read_lock(); |
| 3321 | ies = rcu_dereference(cbss->ies); |
| 3322 | if (ies) |
| 3323 | bss_ies = kmemdup(ies, sizeof(*ies) + ies->len, |
| 3324 | GFP_ATOMIC); |
| 3325 | rcu_read_unlock(); |
| 3326 | if (!bss_ies) |
| 3327 | return false; |
| 3328 | |
| 3329 | ieee802_11_parse_elems(bss_ies->data, bss_ies->len, |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3330 | false, &bss_elems, |
| 3331 | mgmt->bssid, |
| 3332 | assoc_data->bss->bssid); |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3333 | if (assoc_data->wmm && |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3334 | !elems->wmm_param && bss_elems.wmm_param) { |
| 3335 | elems->wmm_param = bss_elems.wmm_param; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3336 | sdata_info(sdata, |
| 3337 | "AP bug: WMM param missing from AssocResp\n"); |
| 3338 | } |
| 3339 | |
| 3340 | /* |
| 3341 | * Also check if we requested HT/VHT, otherwise the AP doesn't |
| 3342 | * have to include the IEs in the (re)association response. |
| 3343 | */ |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3344 | if (!elems->ht_cap_elem && bss_elems.ht_cap_elem && |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3345 | !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) { |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3346 | elems->ht_cap_elem = bss_elems.ht_cap_elem; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3347 | sdata_info(sdata, |
| 3348 | "AP bug: HT capability missing from AssocResp\n"); |
| 3349 | } |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3350 | if (!elems->ht_operation && bss_elems.ht_operation && |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3351 | !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) { |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3352 | elems->ht_operation = bss_elems.ht_operation; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3353 | sdata_info(sdata, |
| 3354 | "AP bug: HT operation missing from AssocResp\n"); |
| 3355 | } |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3356 | if (!elems->vht_cap_elem && bss_elems.vht_cap_elem && |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3357 | !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) { |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3358 | elems->vht_cap_elem = bss_elems.vht_cap_elem; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3359 | sdata_info(sdata, |
| 3360 | "AP bug: VHT capa missing from AssocResp\n"); |
| 3361 | } |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3362 | if (!elems->vht_operation && bss_elems.vht_operation && |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3363 | !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) { |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3364 | elems->vht_operation = bss_elems.vht_operation; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3365 | sdata_info(sdata, |
| 3366 | "AP bug: VHT operation missing from AssocResp\n"); |
| 3367 | } |
| 3368 | } |
| 3369 | |
| 3370 | /* |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3371 | * We previously checked these in the beacon/probe response, so |
| 3372 | * they should be present here. This is just a safety net. |
| 3373 | */ |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 3374 | if (!is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT) && |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3375 | (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) { |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3376 | sdata_info(sdata, |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3377 | "HT AP is missing WMM params or HT capability/operation\n"); |
| 3378 | ret = false; |
| 3379 | goto out; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3380 | } |
| 3381 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 3382 | if (!is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3383 | (!elems->vht_cap_elem || !elems->vht_operation)) { |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3384 | sdata_info(sdata, |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3385 | "VHT AP is missing VHT capability/operation\n"); |
| 3386 | ret = false; |
| 3387 | goto out; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3388 | } |
| 3389 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 3390 | if (is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && |
| 3391 | !elems->he_6ghz_capa) { |
| 3392 | sdata_info(sdata, |
| 3393 | "HE 6 GHz AP is missing HE 6 GHz band capability\n"); |
| 3394 | ret = false; |
| 3395 | goto out; |
| 3396 | } |
| 3397 | |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 3398 | mutex_lock(&sdata->local->sta_mtx); |
| 3399 | /* |
| 3400 | * station info was already allocated and inserted before |
| 3401 | * the association and should be available to us |
| 3402 | */ |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 3403 | sta = sta_info_get(sdata, cbss->bssid); |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 3404 | if (WARN_ON(!sta)) { |
| 3405 | mutex_unlock(&sdata->local->sta_mtx); |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3406 | ret = false; |
| 3407 | goto out; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3408 | } |
| 3409 | |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 3410 | sband = ieee80211_get_sband(sdata); |
| 3411 | if (!sband) { |
| 3412 | mutex_unlock(&sdata->local->sta_mtx); |
| 3413 | ret = false; |
| 3414 | goto out; |
| 3415 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3416 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3417 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3418 | (!elems->he_cap || !elems->he_operation)) { |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3419 | mutex_unlock(&sdata->local->sta_mtx); |
| 3420 | sdata_info(sdata, |
| 3421 | "HE AP is missing HE capability/operation\n"); |
| 3422 | ret = false; |
| 3423 | goto out; |
| 3424 | } |
| 3425 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3426 | /* Set up internal HT/VHT capabilities */ |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3427 | if (elems->ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 3428 | ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband, |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3429 | elems->ht_cap_elem, sta); |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 3430 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3431 | if (elems->vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
Mahesh Palivela | 818255e | 2012-10-10 11:33:04 +0000 | [diff] [blame] | 3432 | ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband, |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3433 | elems->vht_cap_elem, sta); |
Mahesh Palivela | 818255e | 2012-10-10 11:33:04 +0000 | [diff] [blame] | 3434 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3435 | if (elems->he_operation && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && |
| 3436 | elems->he_cap) { |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3437 | ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband, |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3438 | elems->he_cap, |
| 3439 | elems->he_cap_len, |
Johannes Berg | 1bb9a8a | 2020-05-28 21:34:38 +0200 | [diff] [blame] | 3440 | elems->he_6ghz_capa, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3441 | sta); |
| 3442 | |
| 3443 | bss_conf->he_support = sta->sta.he_cap.has_he; |
Shaul Triebitz | d46b4ab8 | 2020-03-26 15:09:33 +0200 | [diff] [blame] | 3444 | if (elems->rsnx && elems->rsnx_len && |
| 3445 | (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) && |
| 3446 | wiphy_ext_feature_isset(local->hw.wiphy, |
| 3447 | NL80211_EXT_FEATURE_PROTECTED_TWT)) |
| 3448 | bss_conf->twt_protected = true; |
| 3449 | else |
| 3450 | bss_conf->twt_protected = false; |
| 3451 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3452 | changed |= ieee80211_recalc_twt_req(sdata, sta, elems); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3453 | } else { |
| 3454 | bss_conf->he_support = false; |
Emmanuel Grumbach | 55ebd6e | 2018-12-15 11:03:04 +0200 | [diff] [blame] | 3455 | bss_conf->twt_requester = false; |
Shaul Triebitz | d46b4ab8 | 2020-03-26 15:09:33 +0200 | [diff] [blame] | 3456 | bss_conf->twt_protected = false; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3457 | } |
| 3458 | |
| 3459 | if (bss_conf->he_support) { |
John Crispin | dd56e90 | 2019-12-17 15:19:19 +0100 | [diff] [blame] | 3460 | bss_conf->he_bss_color.color = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3461 | le32_get_bits(elems->he_operation->he_oper_params, |
Naftali Goldstein | 77cbbc3 | 2018-09-05 08:06:07 +0300 | [diff] [blame] | 3462 | IEEE80211_HE_OPERATION_BSS_COLOR_MASK); |
John Crispin | dd56e90 | 2019-12-17 15:19:19 +0100 | [diff] [blame] | 3463 | bss_conf->he_bss_color.partial = |
| 3464 | le32_get_bits(elems->he_operation->he_oper_params, |
| 3465 | IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR); |
Johannes Berg | 75e6b59 | 2020-07-30 13:00:52 +0200 | [diff] [blame] | 3466 | bss_conf->he_bss_color.enabled = |
| 3467 | !le32_get_bits(elems->he_operation->he_oper_params, |
| 3468 | IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED); |
P Praneesh | 322cd27 | 2020-07-09 08:16:21 +0530 | [diff] [blame] | 3469 | |
Johannes Berg | 75e6b59 | 2020-07-30 13:00:52 +0200 | [diff] [blame] | 3470 | if (bss_conf->he_bss_color.enabled) |
P Praneesh | 322cd27 | 2020-07-09 08:16:21 +0530 | [diff] [blame] | 3471 | changed |= BSS_CHANGED_HE_BSS_COLOR; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3472 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3473 | bss_conf->htc_trig_based_pkt_ext = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3474 | le32_get_bits(elems->he_operation->he_oper_params, |
Naftali Goldstein | 77cbbc3 | 2018-09-05 08:06:07 +0300 | [diff] [blame] | 3475 | IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3476 | bss_conf->frame_time_rts_th = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3477 | le32_get_bits(elems->he_operation->he_oper_params, |
Naftali Goldstein | 77cbbc3 | 2018-09-05 08:06:07 +0300 | [diff] [blame] | 3478 | IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3479 | |
| 3480 | bss_conf->multi_sta_back_32bit = |
| 3481 | sta->sta.he_cap.he_cap_elem.mac_cap_info[2] & |
| 3482 | IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP; |
| 3483 | |
| 3484 | bss_conf->ack_enabled = |
| 3485 | sta->sta.he_cap.he_cap_elem.mac_cap_info[2] & |
| 3486 | IEEE80211_HE_MAC_CAP2_ACK_EN; |
| 3487 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3488 | bss_conf->uora_exists = !!elems->uora_element; |
| 3489 | if (elems->uora_element) |
| 3490 | bss_conf->uora_ocw_range = elems->uora_element[0]; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3491 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3492 | ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation); |
| 3493 | ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3494 | /* TODO: OPEN: what happens if BSS color disable is set? */ |
| 3495 | } |
| 3496 | |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3497 | if (cbss->transmitted_bss) { |
| 3498 | bss_conf->nontransmitted = true; |
| 3499 | ether_addr_copy(bss_conf->transmitter_bssid, |
| 3500 | cbss->transmitted_bss->bssid); |
| 3501 | bss_conf->bssid_indicator = cbss->max_bssid_indicator; |
| 3502 | bss_conf->bssid_index = cbss->bssid_index; |
| 3503 | } |
| 3504 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3505 | /* |
| 3506 | * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data |
| 3507 | * in their association response, so ignore that data for our own |
| 3508 | * configuration. If it changed since the last beacon, we'll get the |
| 3509 | * next beacon and update then. |
| 3510 | */ |
Johannes Berg | 1128958 | 2013-02-07 17:36:12 +0100 | [diff] [blame] | 3511 | |
Johannes Berg | bee7f586 | 2013-02-07 22:24:55 +0100 | [diff] [blame] | 3512 | /* |
| 3513 | * If an operating mode notification IE is present, override the |
| 3514 | * NSS calculation (that would be done in rate_control_rate_init()) |
| 3515 | * and use the # of streams from that element. |
| 3516 | */ |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3517 | if (elems->opmode_notif && |
| 3518 | !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) { |
Johannes Berg | bee7f586 | 2013-02-07 22:24:55 +0100 | [diff] [blame] | 3519 | u8 nss; |
| 3520 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3521 | nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK; |
Johannes Berg | bee7f586 | 2013-02-07 22:24:55 +0100 | [diff] [blame] | 3522 | nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT; |
| 3523 | nss += 1; |
| 3524 | sta->sta.rx_nss = nss; |
| 3525 | } |
| 3526 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 3527 | rate_control_rate_init(sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3528 | |
Tamizh chelvam | 93f0490 | 2015-10-07 10:40:04 +0530 | [diff] [blame] | 3529 | if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) { |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 3530 | set_sta_flag(sta, WLAN_STA_MFP); |
Tamizh chelvam | 93f0490 | 2015-10-07 10:40:04 +0530 | [diff] [blame] | 3531 | sta->sta.mfp = true; |
| 3532 | } else { |
| 3533 | sta->sta.mfp = false; |
| 3534 | } |
Jouni Malinen | 5394af4 | 2009-01-08 13:31:59 +0200 | [diff] [blame] | 3535 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3536 | sta->sta.wme = elems->wmm_param && local->hw.queues >= IEEE80211_NUM_ACS; |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 3537 | |
Johannes Berg | 3e4d40f | 2013-02-07 17:19:08 +0100 | [diff] [blame] | 3538 | err = sta_info_move_state(sta, IEEE80211_STA_ASSOC); |
Johannes Berg | c898787 | 2012-01-20 13:55:17 +0100 | [diff] [blame] | 3539 | if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT)) |
| 3540 | err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED); |
| 3541 | if (err) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3542 | sdata_info(sdata, |
| 3543 | "failed to move station %pM to desired state\n", |
| 3544 | sta->sta.addr); |
Johannes Berg | c898787 | 2012-01-20 13:55:17 +0100 | [diff] [blame] | 3545 | WARN_ON(__sta_info_destroy(sta)); |
| 3546 | mutex_unlock(&sdata->local->sta_mtx); |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3547 | ret = false; |
| 3548 | goto out; |
Johannes Berg | c898787 | 2012-01-20 13:55:17 +0100 | [diff] [blame] | 3549 | } |
| 3550 | |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 3551 | mutex_unlock(&sdata->local->sta_mtx); |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 3552 | |
Juuso Oikarinen | f2176d7 | 2010-09-28 14:39:32 +0300 | [diff] [blame] | 3553 | /* |
| 3554 | * Always handle WMM once after association regardless |
| 3555 | * of the first value the AP uses. Setting -1 here has |
| 3556 | * that effect because the AP values is an unsigned |
| 3557 | * 4-bit value. |
| 3558 | */ |
| 3559 | ifmgd->wmm_last_param_set = -1; |
Shaul Triebitz | 2e249fc | 2018-12-15 11:03:15 +0200 | [diff] [blame] | 3560 | ifmgd->mu_edca_last_param_set = -1; |
Juuso Oikarinen | f2176d7 | 2010-09-28 14:39:32 +0300 | [diff] [blame] | 3561 | |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 3562 | if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) { |
Johannes Berg | cec6628 | 2015-10-22 17:46:04 +0200 | [diff] [blame] | 3563 | ieee80211_set_wmm_default(sdata, false, false); |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3564 | } else if (!ieee80211_sta_wmm_params(local, sdata, elems->wmm_param, |
| 3565 | elems->wmm_param_len, |
| 3566 | elems->mu_edca_param_set)) { |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 3567 | /* still enable QoS since we might have HT/VHT */ |
| 3568 | ieee80211_set_wmm_default(sdata, false, true); |
| 3569 | /* set the disable-WMM flag in this case to disable |
| 3570 | * tracking WMM parameter changes in the beacon if |
| 3571 | * the parameters weren't actually valid. Doing so |
| 3572 | * avoids changing parameters very strangely when |
| 3573 | * the AP is going back and forth between valid and |
| 3574 | * invalid parameters. |
| 3575 | */ |
| 3576 | ifmgd->flags |= IEEE80211_STA_DISABLE_WMM; |
| 3577 | } |
Johannes Berg | 3abead5 | 2012-03-02 15:56:59 +0100 | [diff] [blame] | 3578 | changed |= BSS_CHANGED_QOS; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3579 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3580 | if (elems->max_idle_period_ie) { |
Avraham Stern | e38a017 | 2017-04-26 10:58:47 +0300 | [diff] [blame] | 3581 | bss_conf->max_idle_period = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3582 | le16_to_cpu(elems->max_idle_period_ie->max_idle_period); |
Avraham Stern | e38a017 | 2017-04-26 10:58:47 +0300 | [diff] [blame] | 3583 | bss_conf->protected_keep_alive = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3584 | !!(elems->max_idle_period_ie->idle_options & |
Avraham Stern | e38a017 | 2017-04-26 10:58:47 +0300 | [diff] [blame] | 3585 | WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE); |
| 3586 | changed |= BSS_CHANGED_KEEP_ALIVE; |
| 3587 | } else { |
| 3588 | bss_conf->max_idle_period = 0; |
| 3589 | bss_conf->protected_keep_alive = false; |
| 3590 | } |
| 3591 | |
Johannes Berg | 1db364c | 2020-04-17 12:38:04 +0200 | [diff] [blame] | 3592 | /* set assoc capability (AID was already set earlier), |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 3593 | * ieee80211_set_associated() will tell the driver */ |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 3594 | bss_conf->assoc_capability = capab_info; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 3595 | ieee80211_set_associated(sdata, cbss, changed); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3596 | |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 3597 | /* |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 3598 | * If we're using 4-addr mode, let the AP know that we're |
| 3599 | * doing so, so that it can create the STA VLAN on its side |
| 3600 | */ |
| 3601 | if (ifmgd->use_4addr) |
| 3602 | ieee80211_send_4addr_nullfunc(local, sdata); |
| 3603 | |
| 3604 | /* |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3605 | * Start timer to probe the connection to the AP now. |
| 3606 | * Also start the timer that will detect beacon loss. |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 3607 | */ |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3608 | ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt); |
Luis R. Rodriguez | d3a910a | 2010-09-16 15:12:32 -0400 | [diff] [blame] | 3609 | ieee80211_sta_reset_beacon_monitor(sdata); |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 3610 | |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3611 | ret = true; |
| 3612 | out: |
| 3613 | kfree(bss_ies); |
| 3614 | return ret; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3615 | } |
| 3616 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3617 | static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata, |
| 3618 | struct ieee80211_mgmt *mgmt, |
| 3619 | size_t len) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3620 | { |
| 3621 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3622 | struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; |
| 3623 | u16 capab_info, status_code, aid; |
| 3624 | struct ieee802_11_elems elems; |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 3625 | int ac, uapsd_queues = -1; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3626 | u8 *pos; |
| 3627 | bool reassoc; |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3628 | struct cfg80211_bss *bss; |
Emmanuel Grumbach | d0d1a12 | 2015-03-16 23:23:36 +0200 | [diff] [blame] | 3629 | struct ieee80211_event event = { |
| 3630 | .type = MLME_EVENT, |
| 3631 | .u.mlme.data = ASSOC_EVENT, |
| 3632 | }; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3633 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3634 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3635 | |
| 3636 | if (!assoc_data) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3637 | return; |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 3638 | if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid)) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3639 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3640 | |
| 3641 | /* |
| 3642 | * AssocResp and ReassocResp have identical structure, so process both |
| 3643 | * of them in this function. |
| 3644 | */ |
| 3645 | |
| 3646 | if (len < 24 + 6) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3647 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3648 | |
Simon Dinkin | 7a7d3e4 | 2017-08-31 13:09:36 +0300 | [diff] [blame] | 3649 | reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3650 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); |
| 3651 | status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); |
| 3652 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); |
| 3653 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3654 | sdata_info(sdata, |
| 3655 | "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n", |
| 3656 | reassoc ? "Rea" : "A", mgmt->sa, |
| 3657 | capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14)))); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3658 | |
Jouni Malinen | 39404fe | 2016-10-27 00:42:05 +0300 | [diff] [blame] | 3659 | if (assoc_data->fils_kek_len && |
| 3660 | fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0) |
| 3661 | return; |
| 3662 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3663 | pos = mgmt->u.assoc_resp.variable; |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3664 | ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems, |
| 3665 | mgmt->bssid, assoc_data->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3666 | |
| 3667 | if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY && |
Johannes Berg | 79ba1d8 | 2013-03-27 14:38:07 +0100 | [diff] [blame] | 3668 | elems.timeout_int && |
| 3669 | elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3670 | u32 tu, ms; |
Johannes Berg | 79ba1d8 | 2013-03-27 14:38:07 +0100 | [diff] [blame] | 3671 | tu = le32_to_cpu(elems.timeout_int->value); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3672 | ms = tu * 1024 / 1000; |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3673 | sdata_info(sdata, |
| 3674 | "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n", |
| 3675 | mgmt->sa, tu, ms); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3676 | assoc_data->timeout = jiffies + msecs_to_jiffies(ms); |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 3677 | assoc_data->timeout_started = true; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3678 | if (ms > IEEE80211_ASSOC_TIMEOUT) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3679 | run_again(sdata, assoc_data->timeout); |
| 3680 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3681 | } |
| 3682 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3683 | bss = assoc_data->bss; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3684 | |
| 3685 | if (status_code != WLAN_STATUS_SUCCESS) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3686 | sdata_info(sdata, "%pM denied association (code=%d)\n", |
| 3687 | mgmt->sa, status_code); |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 3688 | ieee80211_destroy_assoc_data(sdata, false, false); |
Emmanuel Grumbach | d0d1a12 | 2015-03-16 23:23:36 +0200 | [diff] [blame] | 3689 | event.u.mlme.status = MLME_DENIED; |
| 3690 | event.u.mlme.reason = status_code; |
| 3691 | drv_event_callback(sdata->local, sdata, &event); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3692 | } else { |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3693 | if (!ieee80211_assoc_success(sdata, bss, mgmt, len, &elems)) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3694 | /* oops -- internal error -- send timeout for now */ |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 3695 | ieee80211_destroy_assoc_data(sdata, false, false); |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 3696 | cfg80211_assoc_timeout(sdata->dev, bss); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3697 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3698 | } |
Emmanuel Grumbach | d0d1a12 | 2015-03-16 23:23:36 +0200 | [diff] [blame] | 3699 | event.u.mlme.status = MLME_SUCCESS; |
| 3700 | drv_event_callback(sdata->local, sdata, &event); |
John W. Linville | 635d999 | 2012-07-09 16:34:34 -0400 | [diff] [blame] | 3701 | sdata_info(sdata, "associated\n"); |
Johannes Berg | 79ebfb8 | 2012-02-20 14:19:58 +0100 | [diff] [blame] | 3702 | |
| 3703 | /* |
| 3704 | * destroy assoc_data afterwards, as otherwise an idle |
| 3705 | * recalc after assoc_data is NULL but before associated |
| 3706 | * is set can cause the interface to go idle |
| 3707 | */ |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 3708 | ieee80211_destroy_assoc_data(sdata, true, false); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 3709 | |
| 3710 | /* get uapsd queues configuration */ |
| 3711 | uapsd_queues = 0; |
| 3712 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) |
| 3713 | if (sdata->tx_conf[ac].uapsd) |
Emmanuel Grumbach | f438ceb | 2016-10-18 23:12:12 +0300 | [diff] [blame] | 3714 | uapsd_queues |= ieee80211_ac_to_qos_mask[ac]; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3715 | } |
| 3716 | |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 3717 | cfg80211_rx_assoc_resp(sdata->dev, bss, (u8 *)mgmt, len, uapsd_queues, |
| 3718 | ifmgd->assoc_req_ies, ifmgd->assoc_req_ies_len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3719 | } |
Johannes Berg | 8e3c1b7 | 2012-12-10 13:44:19 +0100 | [diff] [blame] | 3720 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3721 | static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 8e3c1b7 | 2012-12-10 13:44:19 +0100 | [diff] [blame] | 3722 | struct ieee80211_mgmt *mgmt, size_t len, |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3723 | struct ieee80211_rx_status *rx_status) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3724 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3725 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 3726 | struct ieee80211_bss *bss; |
Johannes Berg | fab7d4a | 2008-03-16 18:42:44 +0100 | [diff] [blame] | 3727 | struct ieee80211_channel *channel; |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 3728 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3729 | sdata_assert_lock(sdata); |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 3730 | |
Thomas Pedersen | 3b23c184 | 2020-04-01 18:18:05 -0700 | [diff] [blame] | 3731 | channel = ieee80211_get_channel_khz(local->hw.wiphy, |
| 3732 | ieee80211_rx_status_to_khz(rx_status)); |
Emmanuel Grumbach | 3afc216 | 2014-03-04 16:50:13 +0200 | [diff] [blame] | 3733 | if (!channel) |
Johannes Berg | 5bda617 | 2008-09-08 11:05:10 +0200 | [diff] [blame] | 3734 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3735 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3736 | bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel); |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 3737 | if (bss) { |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 3738 | sdata->vif.bss_conf.beacon_rate = bss->beacon_rate; |
Johannes Berg | d2722f8 | 2014-03-04 11:43:28 +0100 | [diff] [blame] | 3739 | ieee80211_rx_bss_put(local, bss); |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 3740 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3741 | } |
| 3742 | |
| 3743 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3744 | 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] | 3745 | struct sk_buff *skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3746 | { |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3747 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 3748 | struct ieee80211_if_managed *ifmgd; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3749 | struct ieee80211_rx_status *rx_status = (void *) skb->cb; |
Andrei Otcheretianski | 85b27ef | 2020-01-31 13:12:50 +0200 | [diff] [blame] | 3750 | struct ieee80211_channel *channel; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3751 | size_t baselen, len = skb->len; |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 3752 | |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 3753 | ifmgd = &sdata->u.mgd; |
| 3754 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3755 | sdata_assert_lock(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3756 | |
Andrei Otcheretianski | 85b27ef | 2020-01-31 13:12:50 +0200 | [diff] [blame] | 3757 | /* |
| 3758 | * According to Draft P802.11ax D6.0 clause 26.17.2.3.2: |
| 3759 | * "If a 6 GHz AP receives a Probe Request frame and responds with |
| 3760 | * a Probe Response frame [..], the Address 1 field of the Probe |
| 3761 | * Response frame shall be set to the broadcast address [..]" |
| 3762 | * So, on 6GHz band we should also accept broadcast responses. |
| 3763 | */ |
| 3764 | channel = ieee80211_get_channel(sdata->local->hw.wiphy, |
| 3765 | rx_status->freq); |
| 3766 | if (!channel) |
| 3767 | return; |
| 3768 | |
| 3769 | if (!ether_addr_equal(mgmt->da, sdata->vif.addr) && |
| 3770 | (channel->band != NL80211_BAND_6GHZ || |
| 3771 | !is_broadcast_ether_addr(mgmt->da))) |
Tomas Winkler | 8e7cdbb | 2008-08-03 14:32:01 +0300 | [diff] [blame] | 3772 | return; /* ignore ProbeResp to foreign address */ |
| 3773 | |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 3774 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; |
| 3775 | if (baselen > len) |
| 3776 | return; |
| 3777 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3778 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status); |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 3779 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3780 | if (ifmgd->associated && |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 3781 | ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 3782 | ieee80211_reset_ap_probe(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3783 | } |
| 3784 | |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 3785 | /* |
| 3786 | * This is the canonical list of information elements we care about, |
| 3787 | * the filter code also gives us all changes to the Microsoft OUI |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 3788 | * (00:50:F2) vendor IE which is used for WMM which we need to track, |
| 3789 | * as well as the DTPC IE (part of the Cisco OUI) used for signaling |
| 3790 | * changes to requested client power. |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 3791 | * |
| 3792 | * We implement beacon filtering in software since that means we can |
| 3793 | * avoid processing the frame here and in cfg80211, and userspace |
| 3794 | * will not be able to tell whether the hardware supports it or not. |
| 3795 | * |
| 3796 | * XXX: This list needs to be dynamic -- userspace needs to be able to |
| 3797 | * add items it requires. It also needs to be able to tell us to |
| 3798 | * look out for other vendor IEs. |
| 3799 | */ |
| 3800 | static const u64 care_about_ies = |
Johannes Berg | 1d4df3a | 2009-04-22 11:25:43 +0200 | [diff] [blame] | 3801 | (1ULL << WLAN_EID_COUNTRY) | |
| 3802 | (1ULL << WLAN_EID_ERP_INFO) | |
| 3803 | (1ULL << WLAN_EID_CHANNEL_SWITCH) | |
| 3804 | (1ULL << WLAN_EID_PWR_CONSTRAINT) | |
| 3805 | (1ULL << WLAN_EID_HT_CAPABILITY) | |
Johannes Berg | 70a3fd6 | 2015-03-12 08:53:29 +0200 | [diff] [blame] | 3806 | (1ULL << WLAN_EID_HT_OPERATION) | |
| 3807 | (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN); |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 3808 | |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3809 | static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data *sdata, |
| 3810 | struct ieee80211_if_managed *ifmgd, |
| 3811 | struct ieee80211_bss_conf *bss_conf, |
| 3812 | struct ieee80211_local *local, |
| 3813 | struct ieee80211_rx_status *rx_status) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3814 | { |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3815 | /* Track average RSSI from the Beacon frames of the current AP */ |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3816 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3817 | if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) { |
| 3818 | ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE; |
Johannes Berg | 338c17a | 2015-08-28 10:52:54 +0200 | [diff] [blame] | 3819 | ewma_beacon_signal_init(&ifmgd->ave_beacon_signal); |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3820 | ifmgd->last_cqm_event_signal = 0; |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 3821 | ifmgd->count_beacon_signal = 1; |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3822 | ifmgd->last_ave_beacon_signal = 0; |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3823 | } else { |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 3824 | ifmgd->count_beacon_signal++; |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3825 | } |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3826 | |
Johannes Berg | 338c17a | 2015-08-28 10:52:54 +0200 | [diff] [blame] | 3827 | ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal); |
| 3828 | |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3829 | if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold && |
| 3830 | ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) { |
Johannes Berg | 338c17a | 2015-08-28 10:52:54 +0200 | [diff] [blame] | 3831 | int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal); |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3832 | int last_sig = ifmgd->last_ave_beacon_signal; |
Emmanuel Grumbach | a818292 | 2015-03-16 23:23:34 +0200 | [diff] [blame] | 3833 | struct ieee80211_event event = { |
| 3834 | .type = RSSI_EVENT, |
| 3835 | }; |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3836 | |
| 3837 | /* |
| 3838 | * if signal crosses either of the boundaries, invoke callback |
| 3839 | * with appropriate parameters |
| 3840 | */ |
| 3841 | if (sig > ifmgd->rssi_max_thold && |
| 3842 | (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) { |
| 3843 | ifmgd->last_ave_beacon_signal = sig; |
Emmanuel Grumbach | a818292 | 2015-03-16 23:23:34 +0200 | [diff] [blame] | 3844 | event.u.rssi.data = RSSI_EVENT_HIGH; |
| 3845 | drv_event_callback(local, sdata, &event); |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3846 | } else if (sig < ifmgd->rssi_min_thold && |
| 3847 | (last_sig >= ifmgd->rssi_max_thold || |
| 3848 | last_sig == 0)) { |
| 3849 | ifmgd->last_ave_beacon_signal = sig; |
Emmanuel Grumbach | a818292 | 2015-03-16 23:23:34 +0200 | [diff] [blame] | 3850 | event.u.rssi.data = RSSI_EVENT_LOW; |
| 3851 | drv_event_callback(local, sdata, &event); |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3852 | } |
| 3853 | } |
| 3854 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3855 | if (bss_conf->cqm_rssi_thold && |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 3856 | ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT && |
Johannes Berg | ea08635 | 2012-01-19 09:29:58 +0100 | [diff] [blame] | 3857 | !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) { |
Johannes Berg | 338c17a | 2015-08-28 10:52:54 +0200 | [diff] [blame] | 3858 | int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal); |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3859 | int last_event = ifmgd->last_cqm_event_signal; |
| 3860 | int thold = bss_conf->cqm_rssi_thold; |
| 3861 | int hyst = bss_conf->cqm_rssi_hyst; |
Johannes Berg | 338c17a | 2015-08-28 10:52:54 +0200 | [diff] [blame] | 3862 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3863 | if (sig < thold && |
| 3864 | (last_event == 0 || sig < last_event - hyst)) { |
| 3865 | ifmgd->last_cqm_event_signal = sig; |
| 3866 | ieee80211_cqm_rssi_notify( |
| 3867 | &sdata->vif, |
| 3868 | NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW, |
Andrzej Zaborowski | 769f07d | 2017-01-25 12:43:40 +0100 | [diff] [blame] | 3869 | sig, GFP_KERNEL); |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3870 | } else if (sig > thold && |
| 3871 | (last_event == 0 || sig > last_event + hyst)) { |
| 3872 | ifmgd->last_cqm_event_signal = sig; |
| 3873 | ieee80211_cqm_rssi_notify( |
| 3874 | &sdata->vif, |
| 3875 | NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, |
Andrzej Zaborowski | 769f07d | 2017-01-25 12:43:40 +0100 | [diff] [blame] | 3876 | sig, GFP_KERNEL); |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3877 | } |
| 3878 | } |
| 3879 | |
Andrew Zaborowski | 2c3c5f8c | 2017-02-10 04:50:22 +0100 | [diff] [blame] | 3880 | if (bss_conf->cqm_rssi_low && |
| 3881 | ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) { |
| 3882 | int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal); |
| 3883 | int last_event = ifmgd->last_cqm_event_signal; |
| 3884 | int low = bss_conf->cqm_rssi_low; |
| 3885 | int high = bss_conf->cqm_rssi_high; |
| 3886 | |
| 3887 | if (sig < low && |
| 3888 | (last_event == 0 || last_event >= low)) { |
| 3889 | ifmgd->last_cqm_event_signal = sig; |
| 3890 | ieee80211_cqm_rssi_notify( |
| 3891 | &sdata->vif, |
| 3892 | NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW, |
| 3893 | sig, GFP_KERNEL); |
| 3894 | } else if (sig > high && |
| 3895 | (last_event == 0 || last_event <= high)) { |
| 3896 | ifmgd->last_cqm_event_signal = sig; |
| 3897 | ieee80211_cqm_rssi_notify( |
| 3898 | &sdata->vif, |
| 3899 | NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, |
| 3900 | sig, GFP_KERNEL); |
| 3901 | } |
| 3902 | } |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3903 | } |
| 3904 | |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3905 | static bool ieee80211_rx_our_beacon(const u8 *tx_bssid, |
| 3906 | struct cfg80211_bss *bss) |
| 3907 | { |
| 3908 | if (ether_addr_equal(tx_bssid, bss->bssid)) |
| 3909 | return true; |
| 3910 | if (!bss->transmitted_bss) |
| 3911 | return false; |
| 3912 | return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid); |
| 3913 | } |
| 3914 | |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3915 | static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata, |
| 3916 | struct ieee80211_mgmt *mgmt, size_t len, |
| 3917 | struct ieee80211_rx_status *rx_status) |
| 3918 | { |
| 3919 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3920 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
| 3921 | size_t baselen; |
| 3922 | struct ieee802_11_elems elems; |
| 3923 | struct ieee80211_local *local = sdata->local; |
| 3924 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 3925 | struct ieee80211_channel *chan; |
| 3926 | struct sta_info *sta; |
| 3927 | u32 changed = 0; |
| 3928 | bool erp_valid; |
| 3929 | u8 erp_value = 0; |
| 3930 | u32 ncrc; |
| 3931 | u8 *bssid; |
| 3932 | u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
| 3933 | |
| 3934 | sdata_assert_lock(sdata); |
| 3935 | |
| 3936 | /* Process beacon from the current BSS */ |
| 3937 | baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; |
| 3938 | if (baselen > len) |
| 3939 | return; |
| 3940 | |
| 3941 | rcu_read_lock(); |
| 3942 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 3943 | if (!chanctx_conf) { |
| 3944 | rcu_read_unlock(); |
| 3945 | return; |
| 3946 | } |
| 3947 | |
Thomas Pedersen | 3b23c184 | 2020-04-01 18:18:05 -0700 | [diff] [blame] | 3948 | if (ieee80211_rx_status_to_khz(rx_status) != |
| 3949 | ieee80211_channel_to_khz(chanctx_conf->def.chan)) { |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3950 | rcu_read_unlock(); |
| 3951 | return; |
| 3952 | } |
| 3953 | chan = chanctx_conf->def.chan; |
| 3954 | rcu_read_unlock(); |
| 3955 | |
| 3956 | if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon && |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3957 | ieee80211_rx_our_beacon(mgmt->bssid, ifmgd->assoc_data->bss)) { |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3958 | ieee802_11_parse_elems(mgmt->u.beacon.variable, |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3959 | len - baselen, false, &elems, |
| 3960 | mgmt->bssid, |
| 3961 | ifmgd->assoc_data->bss->bssid); |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3962 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3963 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status); |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3964 | |
| 3965 | if (elems.dtim_period) |
| 3966 | ifmgd->dtim_period = elems.dtim_period; |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3967 | ifmgd->have_beacon = true; |
| 3968 | ifmgd->assoc_data->need_beacon = false; |
| 3969 | if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) { |
| 3970 | sdata->vif.bss_conf.sync_tsf = |
| 3971 | le64_to_cpu(mgmt->u.beacon.timestamp); |
| 3972 | sdata->vif.bss_conf.sync_device_ts = |
| 3973 | rx_status->device_timestamp; |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3974 | sdata->vif.bss_conf.sync_dtim_count = elems.dtim_count; |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3975 | } |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3976 | |
| 3977 | if (elems.mbssid_config_ie) |
| 3978 | bss_conf->profile_periodicity = |
| 3979 | elems.mbssid_config_ie->profile_periodicity; |
| 3980 | |
| 3981 | if (elems.ext_capab_len >= 11 && |
| 3982 | (elems.ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT)) |
| 3983 | bss_conf->ema_ap = true; |
| 3984 | |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3985 | /* continue assoc process */ |
| 3986 | ifmgd->assoc_data->timeout = jiffies; |
| 3987 | ifmgd->assoc_data->timeout_started = true; |
| 3988 | run_again(sdata, ifmgd->assoc_data->timeout); |
| 3989 | return; |
| 3990 | } |
| 3991 | |
| 3992 | if (!ifmgd->associated || |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3993 | !ieee80211_rx_our_beacon(mgmt->bssid, ifmgd->associated)) |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3994 | return; |
| 3995 | bssid = ifmgd->associated->bssid; |
| 3996 | |
| 3997 | if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL)) |
| 3998 | ieee80211_handle_beacon_sig(sdata, ifmgd, bss_conf, |
| 3999 | local, rx_status); |
Andrew Zaborowski | 2c3c5f8c | 2017-02-10 04:50:22 +0100 | [diff] [blame] | 4000 | |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 4001 | if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4002 | mlme_dbg_ratelimited(sdata, |
Johannes Berg | 112c31f | 2013-02-08 22:59:00 +0100 | [diff] [blame] | 4003 | "cancelling AP probe due to a received beacon\n"); |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 4004 | ieee80211_reset_ap_probe(sdata); |
Jouni Malinen | 9277818 | 2009-05-14 21:15:36 +0300 | [diff] [blame] | 4005 | } |
| 4006 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4007 | /* |
| 4008 | * Push the beacon loss detection into the future since |
| 4009 | * we are processing a beacon from the AP just now. |
| 4010 | */ |
Luis R. Rodriguez | d3a910a | 2010-09-16 15:12:32 -0400 | [diff] [blame] | 4011 | ieee80211_sta_reset_beacon_monitor(sdata); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4012 | |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 4013 | ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4); |
| 4014 | ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable, |
Johannes Berg | b2e506b | 2013-03-26 14:54:16 +0100 | [diff] [blame] | 4015 | len - baselen, false, &elems, |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 4016 | care_about_ies, ncrc, |
| 4017 | mgmt->bssid, bssid); |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 4018 | |
Johannes Berg | 90d13e8 | 2015-09-24 16:13:07 +0200 | [diff] [blame] | 4019 | if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) && |
Johannes Berg | 1db364c | 2020-04-17 12:38:04 +0200 | [diff] [blame] | 4020 | ieee80211_check_tim(elems.tim, elems.tim_len, bss_conf->aid)) { |
Johannes Berg | 90d13e8 | 2015-09-24 16:13:07 +0200 | [diff] [blame] | 4021 | if (local->hw.conf.dynamic_ps_timeout > 0) { |
| 4022 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 4023 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 4024 | ieee80211_hw_config(local, |
| 4025 | IEEE80211_CONF_CHANGE_PS); |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 4026 | } |
Johannes Berg | 076cdcb | 2015-09-24 16:14:55 +0200 | [diff] [blame] | 4027 | ieee80211_send_nullfunc(local, sdata, false); |
Johannes Berg | 90d13e8 | 2015-09-24 16:13:07 +0200 | [diff] [blame] | 4028 | } else if (!local->pspolling && sdata->u.mgd.powersave) { |
| 4029 | local->pspolling = true; |
| 4030 | |
| 4031 | /* |
| 4032 | * Here is assumed that the driver will be |
| 4033 | * able to send ps-poll frame and receive a |
| 4034 | * response even though power save mode is |
| 4035 | * enabled, but some drivers might require |
| 4036 | * to disable power save here. This needs |
| 4037 | * to be investigated. |
| 4038 | */ |
| 4039 | ieee80211_send_pspoll(local, sdata); |
Vivek Natarajan | a97b77b | 2008-12-23 18:39:02 -0800 | [diff] [blame] | 4040 | } |
| 4041 | } |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 4042 | |
Janusz.Dziedzic@tieto.com | b115b97 | 2015-10-27 08:38:40 +0100 | [diff] [blame] | 4043 | if (sdata->vif.p2p || |
| 4044 | sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) { |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 4045 | struct ieee80211_p2p_noa_attr noa = {}; |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 4046 | int ret; |
| 4047 | |
| 4048 | ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable, |
| 4049 | len - baselen, |
| 4050 | IEEE80211_P2P_ATTR_ABSENCE_NOTICE, |
Janusz Dziedzic | 934457e | 2013-03-21 15:47:55 +0100 | [diff] [blame] | 4051 | (u8 *) &noa, sizeof(noa)); |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 4052 | if (ret >= 2) { |
| 4053 | if (sdata->u.mgd.p2p_noa_index != noa.index) { |
| 4054 | /* valid noa_attr and index changed */ |
| 4055 | sdata->u.mgd.p2p_noa_index = noa.index; |
| 4056 | memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa)); |
| 4057 | changed |= BSS_CHANGED_P2P_PS; |
| 4058 | /* |
| 4059 | * make sure we update all information, the CRC |
| 4060 | * mechanism doesn't look at P2P attributes. |
| 4061 | */ |
| 4062 | ifmgd->beacon_crc_valid = false; |
| 4063 | } |
| 4064 | } else if (sdata->u.mgd.p2p_noa_index != -1) { |
| 4065 | /* noa_attr not found and we had valid noa_attr before */ |
| 4066 | sdata->u.mgd.p2p_noa_index = -1; |
| 4067 | 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] | 4068 | changed |= BSS_CHANGED_P2P_PS; |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 4069 | ifmgd->beacon_crc_valid = false; |
| 4070 | } |
| 4071 | } |
| 4072 | |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 4073 | if (ifmgd->csa_waiting_bcn) |
| 4074 | ieee80211_chswitch_post_beacon(sdata); |
| 4075 | |
Alexander Bondar | 2ecc390 | 2015-03-01 09:10:00 +0200 | [diff] [blame] | 4076 | /* |
| 4077 | * Update beacon timing and dtim count on every beacon appearance. This |
| 4078 | * will allow the driver to use the most updated values. Do it before |
| 4079 | * comparing this one with last received beacon. |
| 4080 | * IMPORTANT: These parameters would possibly be out of sync by the time |
| 4081 | * the driver will use them. The synchronized view is currently |
| 4082 | * guaranteed only in certain callbacks. |
| 4083 | */ |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 4084 | if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) { |
Alexander Bondar | 2ecc390 | 2015-03-01 09:10:00 +0200 | [diff] [blame] | 4085 | sdata->vif.bss_conf.sync_tsf = |
| 4086 | le64_to_cpu(mgmt->u.beacon.timestamp); |
| 4087 | sdata->vif.bss_conf.sync_device_ts = |
| 4088 | rx_status->device_timestamp; |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 4089 | sdata->vif.bss_conf.sync_dtim_count = elems.dtim_count; |
Alexander Bondar | 2ecc390 | 2015-03-01 09:10:00 +0200 | [diff] [blame] | 4090 | } |
| 4091 | |
Juuso Oikarinen | d8ec443 | 2010-10-01 16:02:31 +0300 | [diff] [blame] | 4092 | if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4093 | return; |
Jouni Malinen | 3019667 | 2009-05-19 17:01:43 +0300 | [diff] [blame] | 4094 | ifmgd->beacon_crc = ncrc; |
Juuso Oikarinen | d8ec443 | 2010-10-01 16:02:31 +0300 | [diff] [blame] | 4095 | ifmgd->beacon_crc_valid = true; |
Jouni Malinen | 3019667 | 2009-05-19 17:01:43 +0300 | [diff] [blame] | 4096 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 4097 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status); |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 4098 | |
Johannes Berg | d70b761 | 2013-08-23 15:48:48 +0200 | [diff] [blame] | 4099 | ieee80211_sta_process_chanswitch(sdata, rx_status->mactime, |
Luciano Coelho | 2ba4538 | 2014-10-08 09:48:35 +0300 | [diff] [blame] | 4100 | rx_status->device_timestamp, |
Johannes Berg | d70b761 | 2013-08-23 15:48:48 +0200 | [diff] [blame] | 4101 | &elems, true); |
| 4102 | |
Johannes Berg | 095d81c | 2013-10-15 12:25:07 +0200 | [diff] [blame] | 4103 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) && |
| 4104 | ieee80211_sta_wmm_params(local, sdata, elems.wmm_param, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4105 | elems.wmm_param_len, |
| 4106 | elems.mu_edca_param_set)) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 4107 | changed |= BSS_CHANGED_QOS; |
| 4108 | |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 4109 | /* |
| 4110 | * 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] | 4111 | * DTIM period (and beacon timing if desired) now. |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 4112 | */ |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 4113 | if (!ifmgd->have_beacon) { |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 4114 | /* a few bogus AP send dtim_period = 0 or no TIM IE */ |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 4115 | bss_conf->dtim_period = elems.dtim_period ?: 1; |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 4116 | |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 4117 | changed |= BSS_CHANGED_BEACON_INFO; |
| 4118 | ifmgd->have_beacon = true; |
Alexander Bondar | 482a9c7 | 2013-06-03 17:29:33 +0300 | [diff] [blame] | 4119 | |
| 4120 | mutex_lock(&local->iflist_mtx); |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 4121 | ieee80211_recalc_ps(local); |
Alexander Bondar | 482a9c7 | 2013-06-03 17:29:33 +0300 | [diff] [blame] | 4122 | mutex_unlock(&local->iflist_mtx); |
| 4123 | |
Alexander Bondar | ce85788 | 2013-05-06 17:17:04 +0300 | [diff] [blame] | 4124 | ieee80211_recalc_ps_vif(sdata); |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 4125 | } |
| 4126 | |
Johannes Berg | 1946bed | 2013-03-27 14:31:53 +0100 | [diff] [blame] | 4127 | if (elems.erp_info) { |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 4128 | erp_valid = true; |
| 4129 | erp_value = elems.erp_info[0]; |
| 4130 | } else { |
| 4131 | erp_valid = false; |
John W. Linville | 50c4afb | 2008-04-15 14:09:27 -0400 | [diff] [blame] | 4132 | } |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 4133 | changed |= ieee80211_handle_bss_capability(sdata, |
| 4134 | le16_to_cpu(mgmt->u.beacon.capab_info), |
| 4135 | erp_valid, erp_value); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4136 | |
Johannes Berg | 1128958 | 2013-02-07 17:36:12 +0100 | [diff] [blame] | 4137 | mutex_lock(&local->sta_mtx); |
Johannes Berg | bee7f586 | 2013-02-07 22:24:55 +0100 | [diff] [blame] | 4138 | sta = sta_info_get(sdata, bssid); |
| 4139 | |
John Crispin | c9d3245 | 2019-05-28 13:49:47 +0200 | [diff] [blame] | 4140 | changed |= ieee80211_recalc_twt_req(sdata, sta, &elems); |
| 4141 | |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 4142 | if (ieee80211_config_bw(sdata, sta, elems.ht_cap_elem, |
| 4143 | elems.vht_cap_elem, elems.ht_operation, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4144 | elems.vht_operation, elems.he_operation, |
| 4145 | bssid, &changed)) { |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 4146 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | 89f774e | 2016-01-25 15:46:36 +0200 | [diff] [blame] | 4147 | sdata_info(sdata, |
| 4148 | "failed to follow AP %pM bandwidth change, disconnect\n", |
| 4149 | bssid); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 4150 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
| 4151 | WLAN_REASON_DEAUTH_LEAVING, |
| 4152 | true, deauth_buf); |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 4153 | ieee80211_report_disconnect(sdata, deauth_buf, |
| 4154 | sizeof(deauth_buf), true, |
| 4155 | WLAN_REASON_DEAUTH_LEAVING); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4156 | return; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 4157 | } |
Johannes Berg | bee7f586 | 2013-02-07 22:24:55 +0100 | [diff] [blame] | 4158 | |
| 4159 | if (sta && elems.opmode_notif) |
| 4160 | ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif, |
Eyal Shapira | cf1e05c | 2015-12-08 16:04:36 +0200 | [diff] [blame] | 4161 | rx_status->band); |
Johannes Berg | 1128958 | 2013-02-07 17:36:12 +0100 | [diff] [blame] | 4162 | mutex_unlock(&local->sta_mtx); |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 4163 | |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 4164 | changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt, |
| 4165 | elems.country_elem, |
| 4166 | elems.country_elem_len, |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 4167 | elems.pwr_constr_elem, |
| 4168 | elems.cisco_dtpc_elem); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 4169 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4170 | ieee80211_bss_info_change_notify(sdata, changed); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4171 | } |
| 4172 | |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 4173 | void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, |
| 4174 | struct sk_buff *skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4175 | { |
| 4176 | struct ieee80211_rx_status *rx_status; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4177 | struct ieee80211_mgmt *mgmt; |
| 4178 | u16 fc; |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 4179 | struct ieee802_11_elems elems; |
| 4180 | int ies_len; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4181 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4182 | rx_status = (struct ieee80211_rx_status *) skb->cb; |
| 4183 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 4184 | fc = le16_to_cpu(mgmt->frame_control); |
| 4185 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4186 | sdata_lock(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 4187 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4188 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 4189 | case IEEE80211_STYPE_BEACON: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4190 | ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4191 | break; |
| 4192 | case IEEE80211_STYPE_PROBE_RESP: |
| 4193 | ieee80211_rx_mgmt_probe_resp(sdata, skb); |
| 4194 | break; |
| 4195 | case IEEE80211_STYPE_AUTH: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4196 | ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4197 | break; |
| 4198 | case IEEE80211_STYPE_DEAUTH: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4199 | ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4200 | break; |
| 4201 | case IEEE80211_STYPE_DISASSOC: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4202 | ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4203 | break; |
| 4204 | case IEEE80211_STYPE_ASSOC_RESP: |
| 4205 | case IEEE80211_STYPE_REASSOC_RESP: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4206 | ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4207 | break; |
| 4208 | case IEEE80211_STYPE_ACTION: |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 4209 | if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) { |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 4210 | ies_len = skb->len - |
| 4211 | offsetof(struct ieee80211_mgmt, |
| 4212 | u.action.u.chan_switch.variable); |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 4213 | |
| 4214 | if (ies_len < 0) |
| 4215 | break; |
| 4216 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 4217 | /* CSA IE cannot be overridden, no need for BSSID */ |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 4218 | ieee802_11_parse_elems( |
| 4219 | mgmt->u.action.u.chan_switch.variable, |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 4220 | ies_len, true, &elems, mgmt->bssid, NULL); |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 4221 | |
| 4222 | if (elems.parse_error) |
| 4223 | break; |
| 4224 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4225 | ieee80211_sta_process_chanswitch(sdata, |
Luciano Coelho | 2ba4538 | 2014-10-08 09:48:35 +0300 | [diff] [blame] | 4226 | rx_status->mactime, |
| 4227 | rx_status->device_timestamp, |
| 4228 | &elems, false); |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 4229 | } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) { |
| 4230 | ies_len = skb->len - |
| 4231 | offsetof(struct ieee80211_mgmt, |
| 4232 | u.action.u.ext_chan_switch.variable); |
| 4233 | |
| 4234 | if (ies_len < 0) |
| 4235 | break; |
| 4236 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 4237 | /* |
| 4238 | * extended CSA IE can't be overridden, no need for |
| 4239 | * BSSID |
| 4240 | */ |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 4241 | ieee802_11_parse_elems( |
| 4242 | mgmt->u.action.u.ext_chan_switch.variable, |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 4243 | ies_len, true, &elems, mgmt->bssid, NULL); |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 4244 | |
| 4245 | if (elems.parse_error) |
| 4246 | break; |
| 4247 | |
| 4248 | /* for the handling code pretend this was also an IE */ |
| 4249 | elems.ext_chansw_ie = |
| 4250 | &mgmt->u.action.u.ext_chan_switch.data; |
| 4251 | |
| 4252 | ieee80211_sta_process_chanswitch(sdata, |
Luciano Coelho | 2ba4538 | 2014-10-08 09:48:35 +0300 | [diff] [blame] | 4253 | rx_status->mactime, |
| 4254 | rx_status->device_timestamp, |
| 4255 | &elems, false); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 4256 | } |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 4257 | break; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 4258 | } |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4259 | sdata_unlock(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4260 | } |
| 4261 | |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4262 | static void ieee80211_sta_timer(struct timer_list *t) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4263 | { |
| 4264 | struct ieee80211_sub_if_data *sdata = |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4265 | from_timer(sdata, t, u.mgd.timer); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4266 | |
Stanislaw Gruszka | 9b7d72c | 2013-02-28 10:55:27 +0100 | [diff] [blame] | 4267 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4268 | } |
| 4269 | |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4270 | static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 6b684db | 2013-01-29 11:35:29 +0100 | [diff] [blame] | 4271 | u8 *bssid, u8 reason, bool tx) |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4272 | { |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 4273 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4274 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 4275 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason, |
Johannes Berg | 6b684db | 2013-01-29 11:35:29 +0100 | [diff] [blame] | 4276 | tx, frame_buf); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 4277 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 4278 | ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true, |
| 4279 | reason); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4280 | } |
| 4281 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4282 | static int ieee80211_auth(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4283 | { |
| 4284 | struct ieee80211_local *local = sdata->local; |
| 4285 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 4286 | struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data; |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4287 | u32 tx_flags = 0; |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4288 | u16 trans = 1; |
| 4289 | u16 status = 0; |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 4290 | u16 prepare_tx_duration = 0; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4291 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4292 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4293 | |
| 4294 | if (WARN_ON_ONCE(!auth_data)) |
| 4295 | return -EINVAL; |
| 4296 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4297 | auth_data->tries++; |
| 4298 | |
| 4299 | if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4300 | sdata_info(sdata, "authentication with %pM timed out\n", |
| 4301 | auth_data->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4302 | |
| 4303 | /* |
| 4304 | * Most likely AP is not in the range so remove the |
| 4305 | * bss struct for that AP. |
| 4306 | */ |
| 4307 | cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss); |
| 4308 | |
| 4309 | return -ETIMEDOUT; |
| 4310 | } |
| 4311 | |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 4312 | if (auth_data->algorithm == WLAN_AUTH_SAE) |
| 4313 | prepare_tx_duration = |
| 4314 | jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE); |
| 4315 | |
| 4316 | drv_mgd_prepare_tx(local, sdata, prepare_tx_duration); |
Johannes Berg | a1845fc | 2012-06-27 13:18:36 +0200 | [diff] [blame] | 4317 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4318 | sdata_info(sdata, "send auth to %pM (try %d/%d)\n", |
| 4319 | auth_data->bss->bssid, auth_data->tries, |
| 4320 | IEEE80211_AUTH_MAX_TRIES); |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 4321 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4322 | auth_data->expected_transaction = 2; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4323 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4324 | if (auth_data->algorithm == WLAN_AUTH_SAE) { |
| 4325 | trans = auth_data->sae_trans; |
| 4326 | status = auth_data->sae_status; |
| 4327 | auth_data->expected_transaction = trans; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4328 | } |
| 4329 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4330 | if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
| 4331 | tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS | |
| 4332 | IEEE80211_TX_INTFL_MLME_CONN_TX; |
| 4333 | |
| 4334 | ieee80211_send_auth(sdata, trans, auth_data->algorithm, status, |
| 4335 | auth_data->data, auth_data->data_len, |
| 4336 | auth_data->bss->bssid, |
| 4337 | auth_data->bss->bssid, NULL, 0, 0, |
| 4338 | tx_flags); |
| 4339 | |
Stanislaw Gruszka | 6211dd1 | 2013-05-17 13:43:04 +0200 | [diff] [blame] | 4340 | if (tx_flags == 0) { |
Ilan Peer | 407879b | 2018-04-20 13:49:20 +0300 | [diff] [blame] | 4341 | if (auth_data->algorithm == WLAN_AUTH_SAE) |
| 4342 | auth_data->timeout = jiffies + |
| 4343 | IEEE80211_AUTH_TIMEOUT_SAE; |
| 4344 | else |
| 4345 | auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT; |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4346 | } else { |
Johannes Berg | cb236d2 | 2013-07-29 23:07:43 +0200 | [diff] [blame] | 4347 | auth_data->timeout = |
| 4348 | round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG); |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4349 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4350 | |
Ilan Peer | 407879b | 2018-04-20 13:49:20 +0300 | [diff] [blame] | 4351 | auth_data->timeout_started = true; |
| 4352 | run_again(sdata, auth_data->timeout); |
| 4353 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4354 | return 0; |
| 4355 | } |
| 4356 | |
| 4357 | static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata) |
| 4358 | { |
| 4359 | struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data; |
| 4360 | struct ieee80211_local *local = sdata->local; |
| 4361 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4362 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4363 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4364 | assoc_data->tries++; |
| 4365 | if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4366 | sdata_info(sdata, "association with %pM timed out\n", |
| 4367 | assoc_data->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4368 | |
| 4369 | /* |
| 4370 | * Most likely AP is not in the range so remove the |
| 4371 | * bss struct for that AP. |
| 4372 | */ |
| 4373 | cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss); |
| 4374 | |
| 4375 | return -ETIMEDOUT; |
| 4376 | } |
| 4377 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4378 | sdata_info(sdata, "associate with %pM (try %d/%d)\n", |
| 4379 | assoc_data->bss->bssid, assoc_data->tries, |
| 4380 | IEEE80211_ASSOC_MAX_TRIES); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4381 | ieee80211_send_assoc(sdata); |
| 4382 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 4383 | if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) { |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4384 | assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT; |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4385 | assoc_data->timeout_started = true; |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4386 | run_again(sdata, assoc_data->timeout); |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4387 | } else { |
Johannes Berg | cb236d2 | 2013-07-29 23:07:43 +0200 | [diff] [blame] | 4388 | assoc_data->timeout = |
| 4389 | round_jiffies_up(jiffies + |
| 4390 | IEEE80211_ASSOC_TIMEOUT_LONG); |
| 4391 | assoc_data->timeout_started = true; |
| 4392 | run_again(sdata, assoc_data->timeout); |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4393 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4394 | |
| 4395 | return 0; |
| 4396 | } |
| 4397 | |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4398 | void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata, |
| 4399 | __le16 fc, bool acked) |
| 4400 | { |
| 4401 | struct ieee80211_local *local = sdata->local; |
| 4402 | |
| 4403 | sdata->u.mgd.status_fc = fc; |
| 4404 | sdata->u.mgd.status_acked = acked; |
| 4405 | sdata->u.mgd.status_received = true; |
| 4406 | |
| 4407 | ieee80211_queue_work(&local->hw, &sdata->work); |
| 4408 | } |
| 4409 | |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 4410 | void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 4411 | { |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 4412 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 4413 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 4414 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4415 | sdata_lock(sdata); |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 4416 | |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4417 | if (ifmgd->status_received) { |
| 4418 | __le16 fc = ifmgd->status_fc; |
| 4419 | bool status_acked = ifmgd->status_acked; |
| 4420 | |
| 4421 | ifmgd->status_received = false; |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4422 | if (ifmgd->auth_data && ieee80211_is_auth(fc)) { |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4423 | if (status_acked) { |
Ilan Peer | 407879b | 2018-04-20 13:49:20 +0300 | [diff] [blame] | 4424 | if (ifmgd->auth_data->algorithm == |
| 4425 | WLAN_AUTH_SAE) |
| 4426 | ifmgd->auth_data->timeout = |
| 4427 | jiffies + |
| 4428 | IEEE80211_AUTH_TIMEOUT_SAE; |
| 4429 | else |
| 4430 | ifmgd->auth_data->timeout = |
| 4431 | jiffies + |
| 4432 | IEEE80211_AUTH_TIMEOUT_SHORT; |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4433 | run_again(sdata, ifmgd->auth_data->timeout); |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4434 | } else { |
| 4435 | ifmgd->auth_data->timeout = jiffies - 1; |
| 4436 | } |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4437 | ifmgd->auth_data->timeout_started = true; |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4438 | } else if (ifmgd->assoc_data && |
| 4439 | (ieee80211_is_assoc_req(fc) || |
| 4440 | ieee80211_is_reassoc_req(fc))) { |
| 4441 | if (status_acked) { |
| 4442 | ifmgd->assoc_data->timeout = |
| 4443 | jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT; |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4444 | run_again(sdata, ifmgd->assoc_data->timeout); |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4445 | } else { |
| 4446 | ifmgd->assoc_data->timeout = jiffies - 1; |
| 4447 | } |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4448 | ifmgd->assoc_data->timeout_started = true; |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4449 | } |
| 4450 | } |
| 4451 | |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4452 | if (ifmgd->auth_data && ifmgd->auth_data->timeout_started && |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4453 | time_after(jiffies, ifmgd->auth_data->timeout)) { |
| 4454 | if (ifmgd->auth_data->done) { |
| 4455 | /* |
| 4456 | * ok ... we waited for assoc but userspace didn't, |
| 4457 | * so let's just kill the auth data |
| 4458 | */ |
| 4459 | ieee80211_destroy_auth_data(sdata, false); |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4460 | } else if (ieee80211_auth(sdata)) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4461 | u8 bssid[ETH_ALEN]; |
Emmanuel Grumbach | a940909 | 2015-03-16 23:23:35 +0200 | [diff] [blame] | 4462 | struct ieee80211_event event = { |
| 4463 | .type = MLME_EVENT, |
| 4464 | .u.mlme.data = AUTH_EVENT, |
| 4465 | .u.mlme.status = MLME_TIMEOUT, |
| 4466 | }; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4467 | |
| 4468 | memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN); |
| 4469 | |
| 4470 | ieee80211_destroy_auth_data(sdata, false); |
| 4471 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 4472 | cfg80211_auth_timeout(sdata->dev, bssid); |
Emmanuel Grumbach | a940909 | 2015-03-16 23:23:35 +0200 | [diff] [blame] | 4473 | drv_event_callback(sdata->local, sdata, &event); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4474 | } |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4475 | } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4476 | run_again(sdata, ifmgd->auth_data->timeout); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4477 | |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4478 | if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started && |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4479 | time_after(jiffies, ifmgd->assoc_data->timeout)) { |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 4480 | if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) || |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4481 | ieee80211_do_assoc(sdata)) { |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 4482 | struct cfg80211_bss *bss = ifmgd->assoc_data->bss; |
Emmanuel Grumbach | d0d1a12 | 2015-03-16 23:23:36 +0200 | [diff] [blame] | 4483 | struct ieee80211_event event = { |
| 4484 | .type = MLME_EVENT, |
| 4485 | .u.mlme.data = ASSOC_EVENT, |
| 4486 | .u.mlme.status = MLME_TIMEOUT, |
| 4487 | }; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4488 | |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 4489 | ieee80211_destroy_assoc_data(sdata, false, false); |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 4490 | cfg80211_assoc_timeout(sdata->dev, bss); |
Emmanuel Grumbach | d0d1a12 | 2015-03-16 23:23:36 +0200 | [diff] [blame] | 4491 | drv_event_callback(sdata->local, sdata, &event); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4492 | } |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4493 | } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4494 | run_again(sdata, ifmgd->assoc_data->timeout); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4495 | |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 4496 | if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL && |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4497 | ifmgd->associated) { |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 4498 | u8 bssid[ETH_ALEN]; |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 4499 | int max_tries; |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 4500 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 4501 | memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 4502 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 4503 | if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 4504 | max_tries = max_nullfunc_tries; |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 4505 | else |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 4506 | max_tries = max_probe_tries; |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 4507 | |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 4508 | /* ACK received for nullfunc probing frame */ |
| 4509 | if (!ifmgd->probe_send_count) |
| 4510 | ieee80211_reset_ap_probe(sdata); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4511 | else if (ifmgd->nullfunc_failed) { |
| 4512 | if (ifmgd->probe_send_count < max_tries) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4513 | mlme_dbg(sdata, |
| 4514 | "No ack for nullfunc frame to AP %pM, try %d/%i\n", |
| 4515 | bssid, ifmgd->probe_send_count, |
| 4516 | max_tries); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4517 | ieee80211_mgd_probe_ap_send(sdata); |
| 4518 | } else { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4519 | mlme_dbg(sdata, |
| 4520 | "No ack for nullfunc frame to AP %pM, disconnecting.\n", |
| 4521 | bssid); |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 4522 | ieee80211_sta_connection_lost(sdata, bssid, |
Johannes Berg | 6b684db | 2013-01-29 11:35:29 +0100 | [diff] [blame] | 4523 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, |
| 4524 | false); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4525 | } |
| 4526 | } else if (time_is_after_jiffies(ifmgd->probe_timeout)) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4527 | run_again(sdata, ifmgd->probe_timeout); |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 4528 | else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4529 | mlme_dbg(sdata, |
| 4530 | "Failed to send nullfunc to AP %pM after %dms, disconnecting\n", |
| 4531 | bssid, probe_wait_ms); |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 4532 | ieee80211_sta_connection_lost(sdata, bssid, |
Johannes Berg | 6b684db | 2013-01-29 11:35:29 +0100 | [diff] [blame] | 4533 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4534 | } else if (ifmgd->probe_send_count < max_tries) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4535 | mlme_dbg(sdata, |
| 4536 | "No probe response from AP %pM after %dms, try %d/%i\n", |
| 4537 | bssid, probe_wait_ms, |
| 4538 | ifmgd->probe_send_count, max_tries); |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 4539 | ieee80211_mgd_probe_ap_send(sdata); |
| 4540 | } else { |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4541 | /* |
| 4542 | * We actually lost the connection ... or did we? |
| 4543 | * Let's make sure! |
| 4544 | */ |
Johannes Berg | 89f774e | 2016-01-25 15:46:36 +0200 | [diff] [blame] | 4545 | mlme_dbg(sdata, |
| 4546 | "No probe response from AP %pM after %dms, disconnecting.\n", |
| 4547 | bssid, probe_wait_ms); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4548 | |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 4549 | ieee80211_sta_connection_lost(sdata, bssid, |
Johannes Berg | 6b684db | 2013-01-29 11:35:29 +0100 | [diff] [blame] | 4550 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4551 | } |
| 4552 | } |
| 4553 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4554 | sdata_unlock(sdata); |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 4555 | } |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 4556 | |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4557 | static void ieee80211_sta_bcn_mon_timer(struct timer_list *t) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4558 | { |
| 4559 | struct ieee80211_sub_if_data *sdata = |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4560 | from_timer(sdata, t, u.mgd.bcn_mon_timer); |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 4561 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4562 | |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 4563 | if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn) |
Michal Kazior | e5593f5 | 2014-04-09 15:45:36 +0200 | [diff] [blame] | 4564 | return; |
| 4565 | |
Loic Poulain | 0b91111 | 2020-06-18 11:17:42 +0200 | [diff] [blame] | 4566 | if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER) |
| 4567 | return; |
| 4568 | |
Johannes Berg | 682bd38 | 2013-01-29 13:13:50 +0100 | [diff] [blame] | 4569 | sdata->u.mgd.connection_loss = false; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 4570 | ieee80211_queue_work(&sdata->local->hw, |
| 4571 | &sdata->u.mgd.beacon_connection_loss_work); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4572 | } |
| 4573 | |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4574 | static void ieee80211_sta_conn_mon_timer(struct timer_list *t) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4575 | { |
| 4576 | struct ieee80211_sub_if_data *sdata = |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4577 | from_timer(sdata, t, u.mgd.conn_mon_timer); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4578 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 4579 | struct ieee80211_local *local = sdata->local; |
| 4580 | |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 4581 | if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn) |
Michal Kazior | e5593f5 | 2014-04-09 15:45:36 +0200 | [diff] [blame] | 4582 | return; |
| 4583 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 4584 | ieee80211_queue_work(&local->hw, &ifmgd->monitor_work); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4585 | } |
| 4586 | |
| 4587 | static void ieee80211_sta_monitor_work(struct work_struct *work) |
| 4588 | { |
| 4589 | struct ieee80211_sub_if_data *sdata = |
| 4590 | container_of(work, struct ieee80211_sub_if_data, |
| 4591 | u.mgd.monitor_work); |
| 4592 | |
| 4593 | ieee80211_mgd_probe_ap(sdata, false); |
| 4594 | } |
| 4595 | |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 4596 | static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata) |
| 4597 | { |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 4598 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 4599 | __ieee80211_stop_poll(sdata); |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 4600 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4601 | /* let's probe the connection once */ |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 4602 | if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR)) |
Eliad Peller | 494f1fe | 2012-02-19 15:26:09 +0200 | [diff] [blame] | 4603 | ieee80211_queue_work(&sdata->local->hw, |
| 4604 | &sdata->u.mgd.monitor_work); |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 4605 | } |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 4606 | } |
| 4607 | |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4608 | #ifdef CONFIG_PM |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4609 | void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata) |
| 4610 | { |
| 4611 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 4612 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
| 4613 | |
| 4614 | sdata_lock(sdata); |
| 4615 | |
Emmanuel Grumbach | c52666a | 2014-05-13 12:54:09 +0300 | [diff] [blame] | 4616 | if (ifmgd->auth_data || ifmgd->assoc_data) { |
| 4617 | const u8 *bssid = ifmgd->auth_data ? |
| 4618 | ifmgd->auth_data->bss->bssid : |
| 4619 | ifmgd->assoc_data->bss->bssid; |
| 4620 | |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4621 | /* |
Emmanuel Grumbach | c52666a | 2014-05-13 12:54:09 +0300 | [diff] [blame] | 4622 | * If we are trying to authenticate / associate while suspending, |
| 4623 | * cfg80211 won't know and won't actually abort those attempts, |
| 4624 | * thus we need to do that ourselves. |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4625 | */ |
Johannes Berg | 4b08d1b | 2019-08-30 14:24:51 +0300 | [diff] [blame] | 4626 | ieee80211_send_deauth_disassoc(sdata, bssid, bssid, |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4627 | IEEE80211_STYPE_DEAUTH, |
| 4628 | WLAN_REASON_DEAUTH_LEAVING, |
| 4629 | false, frame_buf); |
Emmanuel Grumbach | c52666a | 2014-05-13 12:54:09 +0300 | [diff] [blame] | 4630 | if (ifmgd->assoc_data) |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 4631 | ieee80211_destroy_assoc_data(sdata, false, true); |
Emmanuel Grumbach | c52666a | 2014-05-13 12:54:09 +0300 | [diff] [blame] | 4632 | if (ifmgd->auth_data) |
| 4633 | ieee80211_destroy_auth_data(sdata, false); |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4634 | cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf, |
| 4635 | IEEE80211_DEAUTH_FRAME_LEN); |
| 4636 | } |
| 4637 | |
Johannes Berg | be72afe | 2015-03-01 09:10:03 +0200 | [diff] [blame] | 4638 | /* This is a bit of a hack - we should find a better and more generic |
| 4639 | * solution to this. Normally when suspending, cfg80211 will in fact |
| 4640 | * deauthenticate. However, it doesn't (and cannot) stop an ongoing |
| 4641 | * auth (not so important) or assoc (this is the problem) process. |
| 4642 | * |
| 4643 | * As a consequence, it can happen that we are in the process of both |
| 4644 | * associating and suspending, and receive an association response |
| 4645 | * after cfg80211 has checked if it needs to disconnect, but before |
| 4646 | * we actually set the flag to drop incoming frames. This will then |
| 4647 | * cause the workqueue flush to process the association response in |
| 4648 | * the suspend, resulting in a successful association just before it |
| 4649 | * tries to remove the interface from the driver, which now though |
| 4650 | * has a channel context assigned ... this results in issues. |
| 4651 | * |
| 4652 | * To work around this (for now) simply deauth here again if we're |
| 4653 | * now connected. |
| 4654 | */ |
| 4655 | if (ifmgd->associated && !sdata->local->wowlan) { |
| 4656 | u8 bssid[ETH_ALEN]; |
| 4657 | struct cfg80211_deauth_request req = { |
| 4658 | .reason_code = WLAN_REASON_DEAUTH_LEAVING, |
| 4659 | .bssid = bssid, |
| 4660 | }; |
| 4661 | |
| 4662 | memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN); |
| 4663 | ieee80211_mgd_deauth(sdata, &req); |
| 4664 | } |
| 4665 | |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4666 | sdata_unlock(sdata); |
| 4667 | } |
| 4668 | |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4669 | void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata) |
| 4670 | { |
| 4671 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 4672 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4673 | sdata_lock(sdata); |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4674 | if (!ifmgd->associated) { |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4675 | sdata_unlock(sdata); |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4676 | return; |
| 4677 | } |
| 4678 | |
| 4679 | if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) { |
| 4680 | sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME; |
| 4681 | mlme_dbg(sdata, "driver requested disconnect after resume\n"); |
| 4682 | ieee80211_sta_connection_lost(sdata, |
| 4683 | ifmgd->associated->bssid, |
| 4684 | WLAN_REASON_UNSPECIFIED, |
| 4685 | true); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4686 | sdata_unlock(sdata); |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4687 | return; |
| 4688 | } |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4689 | sdata_unlock(sdata); |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4690 | } |
| 4691 | #endif |
| 4692 | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 4693 | /* interface setup */ |
| 4694 | void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata) |
| 4695 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 4696 | struct ieee80211_if_managed *ifmgd; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 4697 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 4698 | ifmgd = &sdata->u.mgd; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4699 | INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 4700 | INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 4701 | INIT_WORK(&ifmgd->beacon_connection_loss_work, |
| 4702 | ieee80211_beacon_connection_loss_work); |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 4703 | INIT_WORK(&ifmgd->csa_connection_drop_work, |
| 4704 | ieee80211_csa_connection_drop_work); |
Emmanuel Grumbach | 687da13 | 2013-10-01 16:45:43 +0300 | [diff] [blame] | 4705 | INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work); |
Arik Nemtsov | 81dd2b8 | 2014-07-17 17:14:25 +0300 | [diff] [blame] | 4706 | INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work, |
| 4707 | ieee80211_tdls_peer_del_work); |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4708 | timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0); |
| 4709 | timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0); |
| 4710 | timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0); |
| 4711 | timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0); |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 4712 | INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk, |
| 4713 | ieee80211_sta_handle_tspec_ac_params_wk); |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 4714 | |
Johannes Berg | ab1faea | 2009-07-01 21:41:17 +0200 | [diff] [blame] | 4715 | ifmgd->flags = 0; |
Mohammed Shafi Shajakhan | 1478acb | 2011-12-14 19:46:08 +0530 | [diff] [blame] | 4716 | ifmgd->powersave = sdata->wdev.ps; |
Alexander Bondar | 219c386 | 2013-01-22 16:52:23 +0200 | [diff] [blame] | 4717 | ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues; |
| 4718 | ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len; |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 4719 | ifmgd->p2p_noa_index = -1; |
Johannes Berg | bbbdff9 | 2009-04-16 13:27:42 +0200 | [diff] [blame] | 4720 | |
Eliad Peller | 0d8614b | 2014-09-10 14:07:36 +0300 | [diff] [blame] | 4721 | if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS) |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 4722 | ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC; |
| 4723 | else |
| 4724 | ifmgd->req_smps = IEEE80211_SMPS_OFF; |
Liad Kaufman | 1277b4a | 2014-11-09 18:50:08 +0200 | [diff] [blame] | 4725 | |
| 4726 | /* Setup TDLS data */ |
| 4727 | spin_lock_init(&ifmgd->teardown_lock); |
| 4728 | ifmgd->teardown_skb = NULL; |
| 4729 | ifmgd->orig_teardown_skb = NULL; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 4730 | } |
| 4731 | |
| 4732 | /* scan finished notification */ |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 4733 | void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local) |
| 4734 | { |
Johannes Berg | 31ee67a | 2012-07-06 21:18:24 +0200 | [diff] [blame] | 4735 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 4736 | |
| 4737 | /* Restart STA timers */ |
| 4738 | rcu_read_lock(); |
Ben Greear | 370bd00 | 2013-03-19 17:50:50 -0700 | [diff] [blame] | 4739 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
| 4740 | if (ieee80211_sdata_running(sdata)) |
| 4741 | ieee80211_restart_sta_timer(sdata); |
| 4742 | } |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 4743 | rcu_read_unlock(); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 4744 | } |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 4745 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4746 | static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata, |
| 4747 | struct cfg80211_bss *cbss) |
| 4748 | { |
| 4749 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 4750 | const u8 *ht_cap_ie, *vht_cap_ie; |
| 4751 | const struct ieee80211_ht_cap *ht_cap; |
| 4752 | const struct ieee80211_vht_cap *vht_cap; |
| 4753 | u8 chains = 1; |
| 4754 | |
| 4755 | if (ifmgd->flags & IEEE80211_STA_DISABLE_HT) |
| 4756 | return chains; |
| 4757 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 4758 | ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY); |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4759 | if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) { |
| 4760 | ht_cap = (void *)(ht_cap_ie + 2); |
| 4761 | chains = ieee80211_mcs_to_chains(&ht_cap->mcs); |
| 4762 | /* |
| 4763 | * TODO: use "Tx Maximum Number Spatial Streams Supported" and |
| 4764 | * "Tx Unequal Modulation Supported" fields. |
| 4765 | */ |
| 4766 | } |
| 4767 | |
| 4768 | if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT) |
| 4769 | return chains; |
| 4770 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 4771 | vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY); |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4772 | if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) { |
| 4773 | u8 nss; |
| 4774 | u16 tx_mcs_map; |
| 4775 | |
| 4776 | vht_cap = (void *)(vht_cap_ie + 2); |
| 4777 | tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map); |
| 4778 | for (nss = 8; nss > 0; nss--) { |
| 4779 | if (((tx_mcs_map >> (2 * (nss - 1))) & 3) != |
| 4780 | IEEE80211_VHT_MCS_NOT_SUPPORTED) |
| 4781 | break; |
| 4782 | } |
| 4783 | /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */ |
| 4784 | chains = max(chains, nss); |
| 4785 | } |
| 4786 | |
| 4787 | return chains; |
| 4788 | } |
| 4789 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4790 | static bool |
| 4791 | ieee80211_verify_sta_he_mcs_support(struct ieee80211_supported_band *sband, |
| 4792 | const struct ieee80211_he_operation *he_op) |
| 4793 | { |
| 4794 | const struct ieee80211_sta_he_cap *sta_he_cap = |
| 4795 | ieee80211_get_he_sta_cap(sband); |
Gustavo A. R. Silva | 47aa786 | 2018-06-18 07:41:34 -0500 | [diff] [blame] | 4796 | u16 ap_min_req_set; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4797 | int i; |
| 4798 | |
| 4799 | if (!sta_he_cap || !he_op) |
| 4800 | return false; |
| 4801 | |
Gustavo A. R. Silva | 47aa786 | 2018-06-18 07:41:34 -0500 | [diff] [blame] | 4802 | ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set); |
| 4803 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4804 | /* Need to go over for 80MHz, 160MHz and for 80+80 */ |
| 4805 | for (i = 0; i < 3; i++) { |
| 4806 | const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp = |
| 4807 | &sta_he_cap->he_mcs_nss_supp; |
| 4808 | u16 sta_mcs_map_rx = |
| 4809 | le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]); |
| 4810 | u16 sta_mcs_map_tx = |
| 4811 | le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]); |
| 4812 | u8 nss; |
| 4813 | bool verified = true; |
| 4814 | |
| 4815 | /* |
| 4816 | * For each band there is a maximum of 8 spatial streams |
| 4817 | * possible. Each of the sta_mcs_map_* is a 16-bit struct built |
| 4818 | * of 2 bits per NSS (1-8), with the values defined in enum |
| 4819 | * ieee80211_he_mcs_support. Need to make sure STA TX and RX |
| 4820 | * capabilities aren't less than the AP's minimum requirements |
| 4821 | * for this HE BSS per SS. |
| 4822 | * It is enough to find one such band that meets the reqs. |
| 4823 | */ |
| 4824 | for (nss = 8; nss > 0; nss--) { |
| 4825 | u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3; |
| 4826 | u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3; |
| 4827 | u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3; |
| 4828 | |
| 4829 | if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED) |
| 4830 | continue; |
| 4831 | |
| 4832 | /* |
| 4833 | * Make sure the HE AP doesn't require MCSs that aren't |
| 4834 | * supported by the client |
| 4835 | */ |
| 4836 | if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED || |
| 4837 | sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED || |
| 4838 | (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) { |
| 4839 | verified = false; |
| 4840 | break; |
| 4841 | } |
| 4842 | } |
| 4843 | |
| 4844 | if (verified) |
| 4845 | return true; |
| 4846 | } |
| 4847 | |
| 4848 | /* If here, STA doesn't meet AP's HE min requirements */ |
| 4849 | return false; |
| 4850 | } |
| 4851 | |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 4852 | static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata, |
| 4853 | struct cfg80211_bss *cbss) |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 4854 | { |
| 4855 | struct ieee80211_local *local = sdata->local; |
| 4856 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Eliad Peller | 53b954e | 2014-07-24 11:20:05 +0300 | [diff] [blame] | 4857 | const struct ieee80211_ht_cap *ht_cap = NULL; |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4858 | const struct ieee80211_ht_operation *ht_oper = NULL; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4859 | const struct ieee80211_vht_operation *vht_oper = NULL; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4860 | const struct ieee80211_he_operation *he_oper = NULL; |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4861 | struct ieee80211_supported_band *sband; |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 4862 | struct cfg80211_chan_def chandef; |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 4863 | bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ; |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 4864 | struct ieee80211_bss *bss = (void *)cbss->priv; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4865 | int ret; |
Arik Nemtsov | 52a45f3 | 2015-08-15 22:39:53 +0300 | [diff] [blame] | 4866 | u32 i; |
| 4867 | bool have_80mhz; |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 4868 | |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4869 | sband = local->hw.wiphy->bands[cbss->channel->band]; |
| 4870 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4871 | ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ | |
| 4872 | IEEE80211_STA_DISABLE_80P80MHZ | |
| 4873 | IEEE80211_STA_DISABLE_160MHZ); |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4874 | |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 4875 | /* disable HT/VHT/HE if we don't support them */ |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 4876 | if (!sband->ht_cap.ht_supported && !is_6ghz) { |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 4877 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
| 4878 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
| 4879 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
| 4880 | } |
| 4881 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 4882 | if (!sband->vht_cap.vht_supported && !is_6ghz) { |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 4883 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 4884 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
| 4885 | } |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 4886 | |
| 4887 | if (!ieee80211_get_he_sta_cap(sband)) |
| 4888 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
| 4889 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 4890 | rcu_read_lock(); |
| 4891 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 4892 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) && !is_6ghz) { |
Eliad Peller | 53b954e | 2014-07-24 11:20:05 +0300 | [diff] [blame] | 4893 | const u8 *ht_oper_ie, *ht_cap_ie; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4894 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 4895 | ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION); |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4896 | if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper)) |
| 4897 | ht_oper = (void *)(ht_oper_ie + 2); |
Johannes Berg | 08e6effa | 2013-02-07 23:33:32 +0100 | [diff] [blame] | 4898 | |
Eliad Peller | 53b954e | 2014-07-24 11:20:05 +0300 | [diff] [blame] | 4899 | ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY); |
| 4900 | if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) |
| 4901 | ht_cap = (void *)(ht_cap_ie + 2); |
| 4902 | |
| 4903 | if (!ht_cap) { |
Johannes Berg | 08e6effa | 2013-02-07 23:33:32 +0100 | [diff] [blame] | 4904 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
| 4905 | ht_oper = NULL; |
| 4906 | } |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4907 | } |
| 4908 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 4909 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && !is_6ghz) { |
Johannes Berg | 08e6effa | 2013-02-07 23:33:32 +0100 | [diff] [blame] | 4910 | const u8 *vht_oper_ie, *vht_cap; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4911 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 4912 | vht_oper_ie = ieee80211_bss_get_ie(cbss, |
| 4913 | WLAN_EID_VHT_OPERATION); |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4914 | if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper)) |
| 4915 | vht_oper = (void *)(vht_oper_ie + 2); |
| 4916 | if (vht_oper && !ht_oper) { |
| 4917 | vht_oper = NULL; |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4918 | sdata_info(sdata, |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 4919 | "AP advertised VHT without HT, disabling HT/VHT/HE\n"); |
Johannes Berg | cb14502 | 2013-02-07 20:41:50 +0100 | [diff] [blame] | 4920 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
| 4921 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 4922 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4923 | } |
Johannes Berg | 08e6effa | 2013-02-07 23:33:32 +0100 | [diff] [blame] | 4924 | |
| 4925 | vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY); |
| 4926 | if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) { |
| 4927 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
| 4928 | vht_oper = NULL; |
| 4929 | } |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4930 | } |
| 4931 | |
Shaul Triebitz | 002245e | 2018-12-15 11:03:19 +0200 | [diff] [blame] | 4932 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) { |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4933 | const struct cfg80211_bss_ies *ies; |
| 4934 | const u8 *he_oper_ie; |
| 4935 | |
| 4936 | ies = rcu_dereference(cbss->ies); |
| 4937 | he_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION, |
| 4938 | ies->data, ies->len); |
| 4939 | if (he_oper_ie && |
| 4940 | he_oper_ie[1] == ieee80211_he_oper_size(&he_oper_ie[3])) |
| 4941 | he_oper = (void *)(he_oper_ie + 3); |
| 4942 | else |
| 4943 | he_oper = NULL; |
| 4944 | |
Johannes Berg | f0c0407 | 2018-06-29 09:51:39 +0200 | [diff] [blame] | 4945 | if (!ieee80211_verify_sta_he_mcs_support(sband, he_oper)) |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4946 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
| 4947 | } |
| 4948 | |
Arik Nemtsov | 52a45f3 | 2015-08-15 22:39:53 +0300 | [diff] [blame] | 4949 | /* Allow VHT if at least one channel on the sband supports 80 MHz */ |
| 4950 | have_80mhz = false; |
| 4951 | for (i = 0; i < sband->n_channels; i++) { |
| 4952 | if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED | |
| 4953 | IEEE80211_CHAN_NO_80MHZ)) |
| 4954 | continue; |
| 4955 | |
| 4956 | have_80mhz = true; |
| 4957 | break; |
| 4958 | } |
| 4959 | |
| 4960 | if (!have_80mhz) |
| 4961 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
| 4962 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4963 | ifmgd->flags |= ieee80211_determine_chantype(sdata, sband, |
| 4964 | cbss->channel, |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 4965 | bss->vht_cap_info, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4966 | ht_oper, vht_oper, he_oper, |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 4967 | &chandef, false); |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 4968 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4969 | sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss), |
| 4970 | local->rx_chains); |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4971 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 4972 | rcu_read_unlock(); |
| 4973 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 4974 | if (ifmgd->flags & IEEE80211_STA_DISABLE_HE && is_6ghz) { |
| 4975 | sdata_info(sdata, "Rejecting non-HE 6/7 GHz connection"); |
| 4976 | return -EINVAL; |
| 4977 | } |
| 4978 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 4979 | /* will change later if needed */ |
| 4980 | sdata->smps_mode = IEEE80211_SMPS_OFF; |
| 4981 | |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 4982 | mutex_lock(&local->mtx); |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4983 | /* |
| 4984 | * If this fails (possibly due to channel context sharing |
| 4985 | * on incompatible channels, e.g. 80+80 and 160 sharing the |
| 4986 | * same control channel) try to use a smaller bandwidth. |
| 4987 | */ |
| 4988 | ret = ieee80211_vif_use_channel(sdata, &chandef, |
| 4989 | IEEE80211_CHANCTX_SHARED); |
Simon Wunderlich | 0418a44 | 2013-05-16 13:00:31 +0200 | [diff] [blame] | 4990 | |
| 4991 | /* don't downgrade for 5 and 10 MHz channels, though. */ |
| 4992 | if (chandef.width == NL80211_CHAN_WIDTH_5 || |
| 4993 | chandef.width == NL80211_CHAN_WIDTH_10) |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 4994 | goto out; |
Simon Wunderlich | 0418a44 | 2013-05-16 13:00:31 +0200 | [diff] [blame] | 4995 | |
Johannes Berg | d601cd8 | 2013-02-07 20:54:51 +0100 | [diff] [blame] | 4996 | while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) { |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 4997 | ifmgd->flags |= ieee80211_chandef_downgrade(&chandef); |
Johannes Berg | d601cd8 | 2013-02-07 20:54:51 +0100 | [diff] [blame] | 4998 | ret = ieee80211_vif_use_channel(sdata, &chandef, |
| 4999 | IEEE80211_CHANCTX_SHARED); |
| 5000 | } |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 5001 | out: |
| 5002 | mutex_unlock(&local->mtx); |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 5003 | return ret; |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 5004 | } |
| 5005 | |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 5006 | static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies, |
| 5007 | u8 *dtim_count, u8 *dtim_period) |
| 5008 | { |
| 5009 | const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len); |
| 5010 | const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data, |
| 5011 | ies->len); |
| 5012 | const struct ieee80211_tim_ie *tim = NULL; |
| 5013 | const struct ieee80211_bssid_index *idx; |
| 5014 | bool valid = tim_ie && tim_ie[1] >= 2; |
| 5015 | |
| 5016 | if (valid) |
| 5017 | tim = (void *)(tim_ie + 2); |
| 5018 | |
| 5019 | if (dtim_count) |
| 5020 | *dtim_count = valid ? tim->dtim_count : 0; |
| 5021 | |
| 5022 | if (dtim_period) |
| 5023 | *dtim_period = valid ? tim->dtim_period : 0; |
| 5024 | |
| 5025 | /* Check if value is overridden by non-transmitted profile */ |
| 5026 | if (!idx_ie || idx_ie[1] < 3) |
| 5027 | return valid; |
| 5028 | |
| 5029 | idx = (void *)(idx_ie + 2); |
| 5030 | |
| 5031 | if (dtim_count) |
| 5032 | *dtim_count = idx->dtim_count; |
| 5033 | |
| 5034 | if (dtim_period) |
| 5035 | *dtim_period = idx->dtim_period; |
| 5036 | |
| 5037 | return true; |
| 5038 | } |
| 5039 | |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 5040 | static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata, |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 5041 | struct cfg80211_bss *cbss, bool assoc, |
| 5042 | bool override) |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 5043 | { |
| 5044 | struct ieee80211_local *local = sdata->local; |
| 5045 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 5046 | struct ieee80211_bss *bss = (void *)cbss->priv; |
| 5047 | struct sta_info *new_sta = NULL; |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 5048 | struct ieee80211_supported_band *sband; |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 5049 | bool have_sta = false; |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 5050 | int err; |
| 5051 | |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 5052 | sband = local->hw.wiphy->bands[cbss->channel->band]; |
| 5053 | |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 5054 | if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data)) |
| 5055 | return -EINVAL; |
| 5056 | |
Luca Coelho | f8860ce | 2017-05-02 17:56:21 +0300 | [diff] [blame] | 5057 | /* If a reconfig is happening, bail out */ |
| 5058 | if (local->in_reconfig) |
| 5059 | return -EBUSY; |
| 5060 | |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 5061 | if (assoc) { |
| 5062 | rcu_read_lock(); |
| 5063 | have_sta = sta_info_get(sdata, cbss->bssid); |
| 5064 | rcu_read_unlock(); |
| 5065 | } |
| 5066 | |
| 5067 | if (!have_sta) { |
| 5068 | new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL); |
| 5069 | if (!new_sta) |
| 5070 | return -ENOMEM; |
| 5071 | } |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 5072 | |
Johannes Berg | c87905b | 2017-06-10 13:52:43 +0300 | [diff] [blame] | 5073 | /* |
| 5074 | * Set up the information for the new channel before setting the |
| 5075 | * new channel. We can't - completely race-free - change the basic |
| 5076 | * rates bitmap and the channel (sband) that it refers to, but if |
| 5077 | * we set it up before we at least avoid calling into the driver's |
| 5078 | * bss_info_changed() method with invalid information (since we do |
| 5079 | * call that from changing the channel - only for IDLE and perhaps |
| 5080 | * some others, but ...). |
| 5081 | * |
| 5082 | * So to avoid that, just set up all the new information before the |
| 5083 | * channel, but tell the driver to apply it only afterwards, since |
| 5084 | * it might need the new channel for that. |
| 5085 | */ |
Johannes Berg | 13e0c8e | 2012-07-27 10:43:16 +0200 | [diff] [blame] | 5086 | if (new_sta) { |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5087 | u32 rates = 0, basic_rates = 0; |
| 5088 | bool have_higher_than_11mbit; |
| 5089 | int min_rate = INT_MAX, min_rate_index = -1; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5090 | const struct cfg80211_bss_ies *ies; |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 5091 | int shift = ieee80211_vif_get_shift(&sdata->vif); |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5092 | |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5093 | ieee80211_get_rates(sband, bss->supp_rates, |
| 5094 | bss->supp_rates_len, |
| 5095 | &rates, &basic_rates, |
| 5096 | &have_higher_than_11mbit, |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 5097 | &min_rate, &min_rate_index, |
Johannes Berg | 44f6d42 | 2017-06-10 13:52:44 +0300 | [diff] [blame] | 5098 | shift); |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5099 | |
| 5100 | /* |
| 5101 | * This used to be a workaround for basic rates missing |
| 5102 | * in the association response frame. Now that we no |
| 5103 | * longer use the basic rates from there, it probably |
| 5104 | * doesn't happen any more, but keep the workaround so |
| 5105 | * in case some *other* APs are buggy in different ways |
| 5106 | * we can connect -- with a warning. |
Ilan Peer | 302ff8b | 2020-03-26 15:09:39 +0200 | [diff] [blame] | 5107 | * Allow this workaround only in case the AP provided at least |
| 5108 | * one rate. |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5109 | */ |
Ilan Peer | 302ff8b | 2020-03-26 15:09:39 +0200 | [diff] [blame] | 5110 | if (min_rate_index < 0) { |
| 5111 | sdata_info(sdata, |
| 5112 | "No legacy rates in association response\n"); |
| 5113 | |
| 5114 | sta_info_free(local, new_sta); |
| 5115 | return -EINVAL; |
| 5116 | } else if (!basic_rates) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 5117 | sdata_info(sdata, |
| 5118 | "No basic rates, using min rate instead\n"); |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5119 | basic_rates = BIT(min_rate_index); |
| 5120 | } |
| 5121 | |
Johannes Berg | bd718fc | 2019-05-29 15:25:35 +0300 | [diff] [blame] | 5122 | if (rates) |
| 5123 | new_sta->sta.supp_rates[cbss->channel->band] = rates; |
| 5124 | else |
| 5125 | sdata_info(sdata, |
| 5126 | "No rates found, keeping mandatory only\n"); |
| 5127 | |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5128 | sdata->vif.bss_conf.basic_rates = basic_rates; |
| 5129 | |
| 5130 | /* cf. IEEE 802.11 9.2.12 */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5131 | if (cbss->channel->band == NL80211_BAND_2GHZ && |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5132 | have_higher_than_11mbit) |
| 5133 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; |
| 5134 | else |
| 5135 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; |
| 5136 | |
| 5137 | memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN); |
| 5138 | |
Johannes Berg | 8c358bc | 2012-05-22 22:13:05 +0200 | [diff] [blame] | 5139 | /* set timing information */ |
| 5140 | sdata->vif.bss_conf.beacon_int = cbss->beacon_interval; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5141 | rcu_read_lock(); |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5142 | ies = rcu_dereference(cbss->beacon_ies); |
| 5143 | if (ies) { |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5144 | sdata->vif.bss_conf.sync_tsf = ies->tsf; |
| 5145 | sdata->vif.bss_conf.sync_device_ts = |
| 5146 | bss->device_ts_beacon; |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 5147 | |
| 5148 | ieee80211_get_dtim(ies, |
| 5149 | &sdata->vif.bss_conf.sync_dtim_count, |
| 5150 | NULL); |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 5151 | } else if (!ieee80211_hw_check(&sdata->local->hw, |
| 5152 | TIMING_BEACON_ONLY)) { |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5153 | ies = rcu_dereference(cbss->proberesp_ies); |
| 5154 | /* must be non-NULL since beacon IEs were NULL */ |
| 5155 | sdata->vif.bss_conf.sync_tsf = ies->tsf; |
| 5156 | sdata->vif.bss_conf.sync_device_ts = |
| 5157 | bss->device_ts_presp; |
| 5158 | sdata->vif.bss_conf.sync_dtim_count = 0; |
| 5159 | } else { |
| 5160 | sdata->vif.bss_conf.sync_tsf = 0; |
| 5161 | sdata->vif.bss_conf.sync_device_ts = 0; |
| 5162 | sdata->vif.bss_conf.sync_dtim_count = 0; |
| 5163 | } |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5164 | rcu_read_unlock(); |
Johannes Berg | c87905b | 2017-06-10 13:52:43 +0300 | [diff] [blame] | 5165 | } |
Johannes Berg | 8c358bc | 2012-05-22 22:13:05 +0200 | [diff] [blame] | 5166 | |
Johannes Berg | c87905b | 2017-06-10 13:52:43 +0300 | [diff] [blame] | 5167 | if (new_sta || override) { |
| 5168 | err = ieee80211_prep_channel(sdata, cbss); |
| 5169 | if (err) { |
| 5170 | if (new_sta) |
| 5171 | sta_info_free(local, new_sta); |
| 5172 | return -EINVAL; |
| 5173 | } |
| 5174 | } |
| 5175 | |
| 5176 | if (new_sta) { |
| 5177 | /* |
| 5178 | * tell driver about BSSID, basic rates and timing |
| 5179 | * this was set up above, before setting the channel |
| 5180 | */ |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5181 | ieee80211_bss_info_change_notify(sdata, |
Johannes Berg | 8c358bc | 2012-05-22 22:13:05 +0200 | [diff] [blame] | 5182 | BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES | |
| 5183 | BSS_CHANGED_BEACON_INT); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5184 | |
| 5185 | if (assoc) |
Johannes Berg | 13e0c8e | 2012-07-27 10:43:16 +0200 | [diff] [blame] | 5186 | sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5187 | |
Johannes Berg | 13e0c8e | 2012-07-27 10:43:16 +0200 | [diff] [blame] | 5188 | err = sta_info_insert(new_sta); |
| 5189 | new_sta = NULL; |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5190 | if (err) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 5191 | sdata_info(sdata, |
| 5192 | "failed to insert STA entry for the AP (error %d)\n", |
| 5193 | err); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5194 | return err; |
| 5195 | } |
| 5196 | } else |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 5197 | WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid)); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5198 | |
David Spinadel | 7d830a1 | 2015-03-17 19:58:38 +0200 | [diff] [blame] | 5199 | /* Cancel scan to ensure that nothing interferes with connection */ |
| 5200 | if (local->scanning) |
| 5201 | ieee80211_scan_cancel(local); |
| 5202 | |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5203 | return 0; |
| 5204 | } |
| 5205 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5206 | /* config hooks */ |
| 5207 | int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata, |
| 5208 | struct cfg80211_auth_request *req) |
| 5209 | { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5210 | struct ieee80211_local *local = sdata->local; |
| 5211 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 5212 | struct ieee80211_mgd_auth_data *auth_data; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5213 | u16 auth_alg; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5214 | int err; |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5215 | bool cont_auth; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5216 | |
| 5217 | /* prepare auth data structure */ |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5218 | |
| 5219 | switch (req->auth_type) { |
| 5220 | case NL80211_AUTHTYPE_OPEN_SYSTEM: |
| 5221 | auth_alg = WLAN_AUTH_OPEN; |
| 5222 | break; |
| 5223 | case NL80211_AUTHTYPE_SHARED_KEY: |
Ard Biesheuvel | 5fdb373 | 2019-06-12 18:19:54 +0200 | [diff] [blame] | 5224 | if (fips_enabled) |
Johannes Berg | 9dca9c4 | 2010-07-21 10:09:25 +0200 | [diff] [blame] | 5225 | return -EOPNOTSUPP; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5226 | auth_alg = WLAN_AUTH_SHARED_KEY; |
| 5227 | break; |
| 5228 | case NL80211_AUTHTYPE_FT: |
| 5229 | auth_alg = WLAN_AUTH_FT; |
| 5230 | break; |
| 5231 | case NL80211_AUTHTYPE_NETWORK_EAP: |
| 5232 | auth_alg = WLAN_AUTH_LEAP; |
| 5233 | break; |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 5234 | case NL80211_AUTHTYPE_SAE: |
| 5235 | auth_alg = WLAN_AUTH_SAE; |
| 5236 | break; |
Jouni Malinen | dbc0c2c | 2016-10-27 00:42:04 +0300 | [diff] [blame] | 5237 | case NL80211_AUTHTYPE_FILS_SK: |
| 5238 | auth_alg = WLAN_AUTH_FILS_SK; |
| 5239 | break; |
| 5240 | case NL80211_AUTHTYPE_FILS_SK_PFS: |
| 5241 | auth_alg = WLAN_AUTH_FILS_SK_PFS; |
| 5242 | break; |
| 5243 | case NL80211_AUTHTYPE_FILS_PK: |
| 5244 | auth_alg = WLAN_AUTH_FILS_PK; |
| 5245 | break; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5246 | default: |
| 5247 | return -EOPNOTSUPP; |
| 5248 | } |
| 5249 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5250 | if (ifmgd->assoc_data) |
Jouni Malinen | 8d7432a | 2018-10-11 00:21:20 +0300 | [diff] [blame] | 5251 | return -EBUSY; |
| 5252 | |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 5253 | auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len + |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 5254 | req->ie_len, GFP_KERNEL); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5255 | if (!auth_data) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5256 | return -ENOMEM; |
| 5257 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5258 | auth_data->bss = req->bss; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5259 | |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 5260 | if (req->auth_data_len >= 4) { |
Jouni Malinen | 6ec6361 | 2016-10-27 00:41:59 +0300 | [diff] [blame] | 5261 | if (req->auth_type == NL80211_AUTHTYPE_SAE) { |
| 5262 | __le16 *pos = (__le16 *) req->auth_data; |
| 5263 | |
| 5264 | auth_data->sae_trans = le16_to_cpu(pos[0]); |
| 5265 | auth_data->sae_status = le16_to_cpu(pos[1]); |
| 5266 | } |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 5267 | memcpy(auth_data->data, req->auth_data + 4, |
| 5268 | req->auth_data_len - 4); |
| 5269 | auth_data->data_len += req->auth_data_len - 4; |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 5270 | } |
| 5271 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5272 | /* Check if continuing authentication or trying to authenticate with the |
| 5273 | * same BSS that we were in the process of authenticating with and avoid |
| 5274 | * removal and re-addition of the STA entry in |
| 5275 | * ieee80211_prep_connection(). |
| 5276 | */ |
| 5277 | cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss; |
| 5278 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5279 | if (req->ie && req->ie_len) { |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 5280 | memcpy(&auth_data->data[auth_data->data_len], |
| 5281 | req->ie, req->ie_len); |
| 5282 | auth_data->data_len += req->ie_len; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5283 | } |
| 5284 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5285 | if (req->key && req->key_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5286 | auth_data->key_len = req->key_len; |
| 5287 | auth_data->key_idx = req->key_idx; |
| 5288 | memcpy(auth_data->key, req->key, req->key_len); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5289 | } |
| 5290 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5291 | auth_data->algorithm = auth_alg; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5292 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5293 | /* try to authenticate/probe */ |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 5294 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5295 | if (ifmgd->auth_data) { |
| 5296 | if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) { |
| 5297 | auth_data->peer_confirmed = |
| 5298 | ifmgd->auth_data->peer_confirmed; |
| 5299 | } |
| 5300 | ieee80211_destroy_auth_data(sdata, cont_auth); |
| 5301 | } |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 5302 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5303 | /* prep auth_data so we don't go into idle on disassoc */ |
| 5304 | ifmgd->auth_data = auth_data; |
| 5305 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5306 | /* If this is continuation of an ongoing SAE authentication exchange |
| 5307 | * (i.e., request to send SAE Confirm) and the peer has already |
| 5308 | * confirmed, mark authentication completed since we are about to send |
| 5309 | * out SAE Confirm. |
| 5310 | */ |
| 5311 | if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE && |
| 5312 | auth_data->peer_confirmed && auth_data->sae_trans == 2) |
| 5313 | ieee80211_mark_sta_auth(sdata, req->bss->bssid); |
| 5314 | |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5315 | if (ifmgd->associated) { |
| 5316 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
| 5317 | |
Johannes Berg | 89f774e | 2016-01-25 15:46:36 +0200 | [diff] [blame] | 5318 | sdata_info(sdata, |
| 5319 | "disconnect from AP %pM for new auth to %pM\n", |
| 5320 | ifmgd->associated->bssid, req->bss->bssid); |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5321 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
| 5322 | WLAN_REASON_UNSPECIFIED, |
| 5323 | false, frame_buf); |
| 5324 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 5325 | ieee80211_report_disconnect(sdata, frame_buf, |
| 5326 | sizeof(frame_buf), true, |
| 5327 | WLAN_REASON_UNSPECIFIED); |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5328 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5329 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 5330 | sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5331 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5332 | err = ieee80211_prep_connection(sdata, req->bss, cont_auth, false); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5333 | if (err) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5334 | goto err_clear; |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 5335 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 5336 | err = ieee80211_auth(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5337 | if (err) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5338 | sta_info_destroy_addr(sdata, req->bss->bssid); |
| 5339 | goto err_clear; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5340 | } |
| 5341 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5342 | /* hold our own reference */ |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 5343 | cfg80211_ref_bss(local->hw.wiphy, auth_data->bss); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 5344 | return 0; |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 5345 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5346 | err_clear: |
Joe Perches | c84a67a | 2015-03-02 19:54:57 -0800 | [diff] [blame] | 5347 | eth_zero_addr(ifmgd->bssid); |
Eliad Peller | 3d2abdf | 2012-09-04 17:44:45 +0300 | [diff] [blame] | 5348 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5349 | ifmgd->auth_data = NULL; |
Michal Kazior | d01f858 | 2015-06-03 08:36:13 +0200 | [diff] [blame] | 5350 | mutex_lock(&sdata->local->mtx); |
| 5351 | ieee80211_vif_release_channel(sdata); |
| 5352 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5353 | kfree(auth_data); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5354 | return err; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5355 | } |
| 5356 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5357 | int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, |
| 5358 | struct cfg80211_assoc_request *req) |
| 5359 | { |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 5360 | bool is_6ghz = req->bss->channel->band == NL80211_BAND_6GHZ; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5361 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5362 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 5363 | struct ieee80211_bss *bss = (void *)req->bss->priv; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5364 | struct ieee80211_mgd_assoc_data *assoc_data; |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5365 | const struct cfg80211_bss_ies *beacon_ies; |
Johannes Berg | 4e74bfd | 2012-03-08 15:02:04 +0100 | [diff] [blame] | 5366 | struct ieee80211_supported_band *sband; |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 5367 | const u8 *ssidie, *ht_ie, *vht_ie; |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 5368 | int i, err; |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 5369 | bool override = false; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5370 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5371 | assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL); |
| 5372 | if (!assoc_data) |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5373 | return -ENOMEM; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5374 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5375 | rcu_read_lock(); |
| 5376 | ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID); |
Will Deacon | 4152561 | 2019-10-04 10:51:31 +0100 | [diff] [blame] | 5377 | if (!ssidie || ssidie[1] > sizeof(assoc_data->ssid)) { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5378 | rcu_read_unlock(); |
| 5379 | kfree(assoc_data); |
| 5380 | return -EINVAL; |
| 5381 | } |
| 5382 | memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]); |
| 5383 | assoc_data->ssid_len = ssidie[1]; |
| 5384 | rcu_read_unlock(); |
| 5385 | |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5386 | if (ifmgd->associated) { |
| 5387 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
| 5388 | |
Johannes Berg | 89f774e | 2016-01-25 15:46:36 +0200 | [diff] [blame] | 5389 | sdata_info(sdata, |
| 5390 | "disconnect from AP %pM for new assoc to %pM\n", |
| 5391 | ifmgd->associated->bssid, req->bss->bssid); |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5392 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
| 5393 | WLAN_REASON_UNSPECIFIED, |
| 5394 | false, frame_buf); |
| 5395 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 5396 | ieee80211_report_disconnect(sdata, frame_buf, |
| 5397 | sizeof(frame_buf), true, |
| 5398 | WLAN_REASON_UNSPECIFIED); |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5399 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5400 | |
| 5401 | if (ifmgd->auth_data && !ifmgd->auth_data->done) { |
| 5402 | err = -EBUSY; |
| 5403 | goto err_free; |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 5404 | } |
| 5405 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5406 | if (ifmgd->assoc_data) { |
| 5407 | err = -EBUSY; |
| 5408 | goto err_free; |
| 5409 | } |
| 5410 | |
| 5411 | if (ifmgd->auth_data) { |
| 5412 | bool match; |
| 5413 | |
| 5414 | /* keep sta info, bssid if matching */ |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 5415 | match = ether_addr_equal(ifmgd->bssid, req->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5416 | ieee80211_destroy_auth_data(sdata, match); |
| 5417 | } |
| 5418 | |
| 5419 | /* prepare assoc data */ |
Johannes Berg | 095d81c | 2013-10-15 12:25:07 +0200 | [diff] [blame] | 5420 | |
Juuso Oikarinen | d8ec443 | 2010-10-01 16:02:31 +0300 | [diff] [blame] | 5421 | ifmgd->beacon_crc_valid = false; |
| 5422 | |
Johannes Berg | 095d81c | 2013-10-15 12:25:07 +0200 | [diff] [blame] | 5423 | assoc_data->wmm = bss->wmm_used && |
| 5424 | (local->hw.queues >= IEEE80211_NUM_ACS); |
Johannes Berg | 095d81c | 2013-10-15 12:25:07 +0200 | [diff] [blame] | 5425 | |
Johannes Berg | de5036a | 2012-03-08 15:02:03 +0100 | [diff] [blame] | 5426 | /* |
| 5427 | * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode. |
| 5428 | * We still associate in non-HT mode (11a/b/g) if any one of these |
| 5429 | * ciphers is configured as pairwise. |
| 5430 | * We can set this to true for non-11n hardware, that'll be checked |
| 5431 | * separately along with the peer capabilities. |
| 5432 | */ |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 5433 | for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) { |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5434 | if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 || |
| 5435 | req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP || |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 5436 | req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) { |
Johannes Berg | a8243b7 | 2012-11-22 14:32:09 +0100 | [diff] [blame] | 5437 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 5438 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 5439 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 5440 | netdev_info(sdata->dev, |
Johannes Berg | 5462632 | 2019-08-30 14:24:46 +0300 | [diff] [blame] | 5441 | "disabling HT/VHT/HE due to WEP/TKIP use\n"); |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 5442 | } |
| 5443 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5444 | |
Johannes Berg | 4e74bfd | 2012-03-08 15:02:04 +0100 | [diff] [blame] | 5445 | sband = local->hw.wiphy->bands[req->bss->channel->band]; |
Johannes Berg | 4e74bfd | 2012-03-08 15:02:04 +0100 | [diff] [blame] | 5446 | |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 5447 | /* also disable HT/VHT/HE if the AP doesn't use WMM */ |
| 5448 | if (!bss->wmm_used) { |
| 5449 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 5450 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 5451 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
| 5452 | netdev_info(sdata->dev, |
| 5453 | "disabling HT/VHT/HE as WMM/QoS is not supported by the AP\n"); |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 5454 | } |
| 5455 | |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 5456 | memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa)); |
| 5457 | memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask, |
| 5458 | sizeof(ifmgd->ht_capa_mask)); |
| 5459 | |
Johannes Berg | dd5ecfe | 2013-02-21 17:40:19 +0100 | [diff] [blame] | 5460 | memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa)); |
| 5461 | memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask, |
| 5462 | sizeof(ifmgd->vht_capa_mask)); |
| 5463 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5464 | if (req->ie && req->ie_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5465 | memcpy(assoc_data->ie, req->ie, req->ie_len); |
| 5466 | assoc_data->ie_len = req->ie_len; |
| 5467 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5468 | |
Jouni Malinen | 39404fe | 2016-10-27 00:42:05 +0300 | [diff] [blame] | 5469 | if (req->fils_kek) { |
| 5470 | /* should already be checked in cfg80211 - so warn */ |
| 5471 | if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) { |
| 5472 | err = -EINVAL; |
| 5473 | goto err_free; |
| 5474 | } |
| 5475 | memcpy(assoc_data->fils_kek, req->fils_kek, |
| 5476 | req->fils_kek_len); |
| 5477 | assoc_data->fils_kek_len = req->fils_kek_len; |
| 5478 | } |
| 5479 | |
| 5480 | if (req->fils_nonces) |
| 5481 | memcpy(assoc_data->fils_nonces, req->fils_nonces, |
| 5482 | 2 * FILS_NONCE_LEN); |
| 5483 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5484 | assoc_data->bss = req->bss; |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 5485 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5486 | if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) { |
| 5487 | if (ifmgd->powersave) |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 5488 | sdata->smps_mode = IEEE80211_SMPS_DYNAMIC; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5489 | else |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 5490 | sdata->smps_mode = IEEE80211_SMPS_OFF; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5491 | } else |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 5492 | sdata->smps_mode = ifmgd->req_smps; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5493 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5494 | assoc_data->capability = req->bss->capability; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5495 | assoc_data->supp_rates = bss->supp_rates; |
| 5496 | assoc_data->supp_rates_len = bss->supp_rates_len; |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 5497 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5498 | rcu_read_lock(); |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 5499 | ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION); |
| 5500 | if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation)) |
| 5501 | assoc_data->ap_ht_param = |
| 5502 | ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param; |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 5503 | else if (!is_6ghz) |
Johannes Berg | a8243b7 | 2012-11-22 14:32:09 +0100 | [diff] [blame] | 5504 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 5505 | vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY); |
| 5506 | if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap)) |
| 5507 | memcpy(&assoc_data->ap_vht_cap, vht_ie + 2, |
| 5508 | sizeof(struct ieee80211_vht_cap)); |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 5509 | else if (!is_6ghz) |
| 5510 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT | |
| 5511 | IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5512 | rcu_read_unlock(); |
Johannes Berg | 63f170e | 2009-12-23 13:15:33 +0100 | [diff] [blame] | 5513 | |
Johannes Berg | 848955c | 2014-11-11 12:48:42 +0100 | [diff] [blame] | 5514 | if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) && |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 5515 | ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK), |
Johannes Berg | 848955c | 2014-11-11 12:48:42 +0100 | [diff] [blame] | 5516 | "U-APSD not supported with HW_PS_NULLFUNC_STACK\n")) |
| 5517 | sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; |
| 5518 | |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 5519 | if (bss->wmm_used && bss->uapsd_supported && |
Johannes Berg | 848955c | 2014-11-11 12:48:42 +0100 | [diff] [blame] | 5520 | (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) { |
Johannes Berg | 76f0303 | 2012-03-08 15:02:05 +0100 | [diff] [blame] | 5521 | assoc_data->uapsd = true; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 5522 | ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED; |
| 5523 | } else { |
Johannes Berg | 76f0303 | 2012-03-08 15:02:05 +0100 | [diff] [blame] | 5524 | assoc_data->uapsd = false; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 5525 | ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED; |
| 5526 | } |
| 5527 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5528 | if (req->prev_bssid) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5529 | memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5530 | |
| 5531 | if (req->use_mfp) { |
| 5532 | ifmgd->mfp = IEEE80211_MFP_REQUIRED; |
| 5533 | ifmgd->flags |= IEEE80211_STA_MFP_ENABLED; |
| 5534 | } else { |
| 5535 | ifmgd->mfp = IEEE80211_MFP_DISABLED; |
| 5536 | ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED; |
| 5537 | } |
| 5538 | |
Assaf Krauss | cd2f5dd | 2014-09-03 15:25:02 +0300 | [diff] [blame] | 5539 | if (req->flags & ASSOC_REQ_USE_RRM) |
| 5540 | ifmgd->flags |= IEEE80211_STA_ENABLE_RRM; |
| 5541 | else |
| 5542 | ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM; |
| 5543 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5544 | if (req->crypto.control_port) |
| 5545 | ifmgd->flags |= IEEE80211_STA_CONTROL_PORT; |
| 5546 | else |
| 5547 | ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT; |
| 5548 | |
Johannes Berg | a621fa4 | 2010-08-27 14:26:54 +0300 | [diff] [blame] | 5549 | sdata->control_port_protocol = req->crypto.control_port_ethertype; |
| 5550 | sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt; |
Denis Kenzior | 018f6fb | 2018-03-26 12:52:51 -0500 | [diff] [blame] | 5551 | sdata->control_port_over_nl80211 = |
| 5552 | req->crypto.control_port_over_nl80211; |
Markus Theil | 7f3f96c | 2020-03-12 10:10:54 +0100 | [diff] [blame] | 5553 | sdata->control_port_no_preauth = req->crypto.control_port_no_preauth; |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 5554 | sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto, |
| 5555 | sdata->vif.type); |
Johannes Berg | a621fa4 | 2010-08-27 14:26:54 +0300 | [diff] [blame] | 5556 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5557 | /* kick off associate process */ |
| 5558 | |
| 5559 | ifmgd->assoc_data = assoc_data; |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 5560 | ifmgd->dtim_period = 0; |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 5561 | ifmgd->have_beacon = false; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5562 | |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 5563 | /* override HT/VHT configuration only if the AP and we support it */ |
| 5564 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) { |
| 5565 | struct ieee80211_sta_ht_cap sta_ht_cap; |
| 5566 | |
| 5567 | if (req->flags & ASSOC_REQ_DISABLE_HT) |
| 5568 | override = true; |
| 5569 | |
| 5570 | memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap)); |
| 5571 | ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap); |
| 5572 | |
| 5573 | /* check for 40 MHz disable override */ |
| 5574 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) && |
| 5575 | sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 && |
| 5576 | !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) |
| 5577 | override = true; |
| 5578 | |
| 5579 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && |
| 5580 | req->flags & ASSOC_REQ_DISABLE_VHT) |
| 5581 | override = true; |
| 5582 | } |
| 5583 | |
| 5584 | if (req->flags & ASSOC_REQ_DISABLE_HT) { |
| 5585 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
| 5586 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 5587 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 5588 | } |
| 5589 | |
| 5590 | if (req->flags & ASSOC_REQ_DISABLE_VHT) |
| 5591 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
| 5592 | |
| 5593 | err = ieee80211_prep_connection(sdata, req->bss, true, override); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5594 | if (err) |
| 5595 | goto err_clear; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5596 | |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5597 | rcu_read_lock(); |
| 5598 | beacon_ies = rcu_dereference(req->bss->beacon_ies); |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 5599 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 5600 | if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) && |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5601 | !beacon_ies) { |
| 5602 | /* |
| 5603 | * Wait up to one beacon interval ... |
| 5604 | * should this be more if we miss one? |
| 5605 | */ |
| 5606 | sdata_info(sdata, "waiting for beacon from %pM\n", |
| 5607 | ifmgd->bssid); |
| 5608 | assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval); |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 5609 | assoc_data->timeout_started = true; |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5610 | assoc_data->need_beacon = true; |
| 5611 | } else if (beacon_ies) { |
Shaul Triebitz | 3b3ec3d | 2020-05-28 21:34:37 +0200 | [diff] [blame] | 5612 | const struct element *elem; |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5613 | u8 dtim_count = 0; |
| 5614 | |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 5615 | ieee80211_get_dtim(beacon_ies, &dtim_count, |
| 5616 | &ifmgd->dtim_period); |
| 5617 | |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 5618 | ifmgd->have_beacon = true; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5619 | assoc_data->timeout = jiffies; |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 5620 | assoc_data->timeout_started = true; |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5621 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 5622 | if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) { |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5623 | sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf; |
| 5624 | sdata->vif.bss_conf.sync_device_ts = |
| 5625 | bss->device_ts_beacon; |
| 5626 | sdata->vif.bss_conf.sync_dtim_count = dtim_count; |
| 5627 | } |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 5628 | |
Shaul Triebitz | 3b3ec3d | 2020-05-28 21:34:37 +0200 | [diff] [blame] | 5629 | elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION, |
| 5630 | beacon_ies->data, beacon_ies->len); |
| 5631 | if (elem && elem->datalen >= 3) |
| 5632 | sdata->vif.bss_conf.profile_periodicity = elem->data[2]; |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 5633 | |
Shaul Triebitz | 3b3ec3d | 2020-05-28 21:34:37 +0200 | [diff] [blame] | 5634 | elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, |
| 5635 | beacon_ies->data, beacon_ies->len); |
| 5636 | if (elem && elem->datalen >= 11 && |
| 5637 | (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT)) |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 5638 | sdata->vif.bss_conf.ema_ap = true; |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5639 | } else { |
| 5640 | assoc_data->timeout = jiffies; |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 5641 | assoc_data->timeout_started = true; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5642 | } |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5643 | rcu_read_unlock(); |
| 5644 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 5645 | run_again(sdata, assoc_data->timeout); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5646 | |
Paul Stewart | fcff4f1 | 2012-02-23 17:59:53 -0800 | [diff] [blame] | 5647 | if (bss->corrupt_data) { |
| 5648 | char *corrupt_type = "data"; |
| 5649 | if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) { |
| 5650 | if (bss->corrupt_data & |
| 5651 | IEEE80211_BSS_CORRUPT_PROBE_RESP) |
| 5652 | corrupt_type = "beacon and probe response"; |
| 5653 | else |
| 5654 | corrupt_type = "beacon"; |
| 5655 | } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP) |
| 5656 | corrupt_type = "probe response"; |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 5657 | sdata_info(sdata, "associating with AP with corrupt %s\n", |
| 5658 | corrupt_type); |
Paul Stewart | fcff4f1 | 2012-02-23 17:59:53 -0800 | [diff] [blame] | 5659 | } |
| 5660 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 5661 | return 0; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5662 | err_clear: |
Joe Perches | c84a67a | 2015-03-02 19:54:57 -0800 | [diff] [blame] | 5663 | eth_zero_addr(ifmgd->bssid); |
Eliad Peller | 3d2abdf | 2012-09-04 17:44:45 +0300 | [diff] [blame] | 5664 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5665 | ifmgd->assoc_data = NULL; |
| 5666 | err_free: |
| 5667 | kfree(assoc_data); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5668 | return err; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5669 | } |
| 5670 | |
| 5671 | int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 63c9c5e | 2012-02-24 13:50:51 +0100 | [diff] [blame] | 5672 | struct cfg80211_deauth_request *req) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5673 | { |
| 5674 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 5675 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Stanislaw Gruszka | 6863255 | 2012-10-15 14:52:41 +0200 | [diff] [blame] | 5676 | bool tx = !req->local_state_change; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5677 | |
Johannes Berg | c9c3a06 | 2014-03-19 09:11:19 +0100 | [diff] [blame] | 5678 | if (ifmgd->auth_data && |
| 5679 | ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) { |
| 5680 | sdata_info(sdata, |
| 5681 | "aborting authentication with %pM by local choice (Reason: %u=%s)\n", |
| 5682 | req->bssid, req->reason_code, |
| 5683 | ieee80211_get_reason_code_string(req->reason_code)); |
Johannes Berg | 0ff7161 | 2009-09-26 14:45:41 +0200 | [diff] [blame] | 5684 | |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 5685 | drv_mgd_prepare_tx(sdata->local, sdata, 0); |
Johannes Berg | 4b08d1b | 2019-08-30 14:24:51 +0300 | [diff] [blame] | 5686 | ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid, |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 5687 | IEEE80211_STYPE_DEAUTH, |
Stanislaw Gruszka | 6863255 | 2012-10-15 14:52:41 +0200 | [diff] [blame] | 5688 | req->reason_code, tx, |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 5689 | frame_buf); |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 5690 | ieee80211_destroy_auth_data(sdata, false); |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 5691 | ieee80211_report_disconnect(sdata, frame_buf, |
| 5692 | sizeof(frame_buf), true, |
| 5693 | req->reason_code); |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 5694 | |
Johannes Berg | c9c3a06 | 2014-03-19 09:11:19 +0100 | [diff] [blame] | 5695 | return 0; |
Emmanuel Grumbach | 8c7d857 | 2012-07-25 01:42:36 +0300 | [diff] [blame] | 5696 | } |
| 5697 | |
Andrei Otcheretianski | a64cba3 | 2015-10-25 10:59:38 +0200 | [diff] [blame] | 5698 | if (ifmgd->assoc_data && |
| 5699 | ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) { |
| 5700 | sdata_info(sdata, |
| 5701 | "aborting association with %pM by local choice (Reason: %u=%s)\n", |
| 5702 | req->bssid, req->reason_code, |
| 5703 | ieee80211_get_reason_code_string(req->reason_code)); |
| 5704 | |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 5705 | drv_mgd_prepare_tx(sdata->local, sdata, 0); |
Johannes Berg | 4b08d1b | 2019-08-30 14:24:51 +0300 | [diff] [blame] | 5706 | ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid, |
Andrei Otcheretianski | a64cba3 | 2015-10-25 10:59:38 +0200 | [diff] [blame] | 5707 | IEEE80211_STYPE_DEAUTH, |
| 5708 | req->reason_code, tx, |
| 5709 | frame_buf); |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 5710 | ieee80211_destroy_assoc_data(sdata, false, true); |
Andrei Otcheretianski | a64cba3 | 2015-10-25 10:59:38 +0200 | [diff] [blame] | 5711 | ieee80211_report_disconnect(sdata, frame_buf, |
| 5712 | sizeof(frame_buf), true, |
| 5713 | req->reason_code); |
| 5714 | return 0; |
| 5715 | } |
| 5716 | |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 5717 | if (ifmgd->associated && |
| 5718 | ether_addr_equal(ifmgd->associated->bssid, req->bssid)) { |
Johannes Berg | c9c3a06 | 2014-03-19 09:11:19 +0100 | [diff] [blame] | 5719 | sdata_info(sdata, |
| 5720 | "deauthenticating from %pM by local choice (Reason: %u=%s)\n", |
| 5721 | req->bssid, req->reason_code, |
| 5722 | ieee80211_get_reason_code_string(req->reason_code)); |
| 5723 | |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 5724 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
| 5725 | req->reason_code, tx, frame_buf); |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 5726 | ieee80211_report_disconnect(sdata, frame_buf, |
| 5727 | sizeof(frame_buf), true, |
| 5728 | req->reason_code); |
Johannes Berg | c9c3a06 | 2014-03-19 09:11:19 +0100 | [diff] [blame] | 5729 | return 0; |
| 5730 | } |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 5731 | |
Johannes Berg | c9c3a06 | 2014-03-19 09:11:19 +0100 | [diff] [blame] | 5732 | return -ENOTCONN; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5733 | } |
| 5734 | |
| 5735 | int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 63c9c5e | 2012-02-24 13:50:51 +0100 | [diff] [blame] | 5736 | struct cfg80211_disassoc_request *req) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5737 | { |
| 5738 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 5739 | u8 bssid[ETH_ALEN]; |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 5740 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5741 | |
Johannes Berg | 8d8b261 | 2009-07-25 11:58:36 +0200 | [diff] [blame] | 5742 | /* |
| 5743 | * cfg80211 should catch this ... but it's racy since |
| 5744 | * we can receive a disassoc frame, process it, hand it |
| 5745 | * to cfg80211 while that's in a locked section already |
| 5746 | * trying to tell us that the user wants to disconnect. |
| 5747 | */ |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 5748 | if (ifmgd->associated != req->bss) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5749 | return -ENOLINK; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5750 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 5751 | sdata_info(sdata, |
Calvin Owens | dfa1ad2 | 2014-02-11 12:36:24 -0600 | [diff] [blame] | 5752 | "disassociating from %pM by local choice (Reason: %u=%s)\n", |
| 5753 | req->bss->bssid, req->reason_code, ieee80211_get_reason_code_string(req->reason_code)); |
Johannes Berg | 0ff7161 | 2009-09-26 14:45:41 +0200 | [diff] [blame] | 5754 | |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 5755 | memcpy(bssid, req->bss->bssid, ETH_ALEN); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 5756 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC, |
| 5757 | req->reason_code, !req->local_state_change, |
| 5758 | frame_buf); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5759 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 5760 | ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true, |
| 5761 | req->reason_code); |
Johannes Berg | bc83b68 | 2009-11-29 12:19:06 +0100 | [diff] [blame] | 5762 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5763 | return 0; |
| 5764 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5765 | |
Eliad Peller | afa762f | 2012-04-23 14:45:15 +0300 | [diff] [blame] | 5766 | void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 54e4ffb | 2012-02-25 21:48:08 +0100 | [diff] [blame] | 5767 | { |
| 5768 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 5769 | |
Ben Greear | 4992185 | 2013-02-20 09:41:09 -0800 | [diff] [blame] | 5770 | /* |
| 5771 | * Make sure some work items will not run after this, |
| 5772 | * they will not do anything but might not have been |
| 5773 | * cancelled when disconnecting. |
| 5774 | */ |
| 5775 | cancel_work_sync(&ifmgd->monitor_work); |
| 5776 | cancel_work_sync(&ifmgd->beacon_connection_loss_work); |
| 5777 | cancel_work_sync(&ifmgd->request_smps_work); |
| 5778 | cancel_work_sync(&ifmgd->csa_connection_drop_work); |
| 5779 | cancel_work_sync(&ifmgd->chswitch_work); |
Arik Nemtsov | 81dd2b8 | 2014-07-17 17:14:25 +0300 | [diff] [blame] | 5780 | cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work); |
Ben Greear | 4992185 | 2013-02-20 09:41:09 -0800 | [diff] [blame] | 5781 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 5782 | sdata_lock(sdata); |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 5783 | if (ifmgd->assoc_data) { |
| 5784 | struct cfg80211_bss *bss = ifmgd->assoc_data->bss; |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 5785 | ieee80211_destroy_assoc_data(sdata, false, false); |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 5786 | cfg80211_assoc_timeout(sdata->dev, bss); |
| 5787 | } |
Johannes Berg | 54e4ffb | 2012-02-25 21:48:08 +0100 | [diff] [blame] | 5788 | if (ifmgd->auth_data) |
| 5789 | ieee80211_destroy_auth_data(sdata, false); |
Liad Kaufman | 1277b4a | 2014-11-09 18:50:08 +0200 | [diff] [blame] | 5790 | spin_lock_bh(&ifmgd->teardown_lock); |
| 5791 | if (ifmgd->teardown_skb) { |
| 5792 | kfree_skb(ifmgd->teardown_skb); |
| 5793 | ifmgd->teardown_skb = NULL; |
| 5794 | ifmgd->orig_teardown_skb = NULL; |
| 5795 | } |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 5796 | kfree(ifmgd->assoc_req_ies); |
| 5797 | ifmgd->assoc_req_ies = NULL; |
| 5798 | ifmgd->assoc_req_ies_len = 0; |
Liad Kaufman | 1277b4a | 2014-11-09 18:50:08 +0200 | [diff] [blame] | 5799 | spin_unlock_bh(&ifmgd->teardown_lock); |
Johannes Berg | 54e4ffb | 2012-02-25 21:48:08 +0100 | [diff] [blame] | 5800 | del_timer_sync(&ifmgd->timer); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 5801 | sdata_unlock(sdata); |
Johannes Berg | 54e4ffb | 2012-02-25 21:48:08 +0100 | [diff] [blame] | 5802 | } |
| 5803 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 5804 | void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif, |
| 5805 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
Andrzej Zaborowski | 769f07d | 2017-01-25 12:43:40 +0100 | [diff] [blame] | 5806 | s32 rssi_level, |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 5807 | gfp_t gfp) |
| 5808 | { |
| 5809 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 5810 | |
Andrzej Zaborowski | 769f07d | 2017-01-25 12:43:40 +0100 | [diff] [blame] | 5811 | trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level); |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 5812 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 5813 | cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp); |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 5814 | } |
| 5815 | EXPORT_SYMBOL(ieee80211_cqm_rssi_notify); |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 5816 | |
| 5817 | void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp) |
| 5818 | { |
| 5819 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 5820 | |
| 5821 | trace_api_cqm_beacon_loss_notify(sdata->local, sdata); |
| 5822 | |
| 5823 | cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp); |
| 5824 | } |
| 5825 | EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify); |