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; |
| 170 | vht_chandef = *chandef; |
| 171 | goto out; |
| 172 | } |
| 173 | |
| 174 | memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap)); |
| 175 | ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap); |
| 176 | |
Johannes Berg | b1b1ae2 | 2017-10-13 15:26:01 +0300 | [diff] [blame] | 177 | if (!ht_oper || !sta_ht_cap.ht_supported) { |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 178 | ret = IEEE80211_STA_DISABLE_HT | |
| 179 | IEEE80211_STA_DISABLE_VHT | |
| 180 | IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 181 | goto out; |
| 182 | } |
| 183 | |
| 184 | chandef->width = NL80211_CHAN_WIDTH_20; |
| 185 | |
| 186 | ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan, |
| 187 | channel->band); |
| 188 | /* check that channel matches the right operating channel */ |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 189 | if (!tracking && channel->center_freq != ht_cfreq) { |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 190 | /* |
| 191 | * It's possible that some APs are confused here; |
| 192 | * Netgear WNDR3700 sometimes reports 4 higher than |
| 193 | * the actual channel in association responses, but |
| 194 | * since we look at probe response/beacon data here |
| 195 | * it should be OK. |
| 196 | */ |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 197 | sdata_info(sdata, |
| 198 | "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n", |
| 199 | channel->center_freq, ht_cfreq, |
| 200 | ht_oper->primary_chan, channel->band); |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 201 | ret = IEEE80211_STA_DISABLE_HT | |
| 202 | IEEE80211_STA_DISABLE_VHT | |
| 203 | IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 204 | goto out; |
| 205 | } |
| 206 | |
| 207 | /* check 40 MHz support, if we have it */ |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 208 | if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) { |
Johannes Berg | 8ac3c704 | 2015-12-18 15:08:34 +0100 | [diff] [blame] | 209 | ieee80211_chandef_ht_oper(ht_oper, chandef); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 210 | } else { |
| 211 | /* 40 MHz (and 80 MHz) must be supported for VHT */ |
| 212 | ret = IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 85220d7 | 2013-03-25 18:29:27 +0100 | [diff] [blame] | 213 | /* also mark 40 MHz disabled */ |
| 214 | ret |= IEEE80211_STA_DISABLE_40MHZ; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 215 | goto out; |
| 216 | } |
| 217 | |
| 218 | if (!vht_oper || !sband->vht_cap.vht_supported) { |
| 219 | ret = IEEE80211_STA_DISABLE_VHT; |
| 220 | goto out; |
| 221 | } |
| 222 | |
Johannes Berg | 8ac3c704 | 2015-12-18 15:08:34 +0100 | [diff] [blame] | 223 | vht_chandef = *chandef; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 224 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && he_oper && |
| 225 | (le32_to_cpu(he_oper->he_oper_params) & |
| 226 | IEEE80211_HE_OPERATION_VHT_OPER_INFO)) { |
| 227 | struct ieee80211_vht_operation he_oper_vht_cap; |
| 228 | |
| 229 | /* |
| 230 | * Set only first 3 bytes (other 2 aren't used in |
| 231 | * ieee80211_chandef_vht_oper() anyway) |
| 232 | */ |
| 233 | memcpy(&he_oper_vht_cap, he_oper->optional, 3); |
| 234 | he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0); |
| 235 | |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 236 | if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_cap_info, |
Johannes Berg | 7eb26df | 2018-08-31 11:31:18 +0300 | [diff] [blame] | 237 | &he_oper_vht_cap, ht_oper, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 238 | &vht_chandef)) { |
| 239 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) |
| 240 | sdata_info(sdata, |
| 241 | "HE AP VHT information is invalid, disable HE\n"); |
| 242 | ret = IEEE80211_STA_DISABLE_HE; |
| 243 | goto out; |
| 244 | } |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 245 | } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw, |
| 246 | vht_cap_info, |
| 247 | vht_oper, ht_oper, |
| 248 | &vht_chandef)) { |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 249 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 250 | sdata_info(sdata, |
Johannes Berg | 8ac3c704 | 2015-12-18 15:08:34 +0100 | [diff] [blame] | 251 | "AP VHT information is invalid, disable VHT\n"); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 252 | ret = IEEE80211_STA_DISABLE_VHT; |
| 253 | goto out; |
| 254 | } |
| 255 | |
| 256 | if (!cfg80211_chandef_valid(&vht_chandef)) { |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 257 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 258 | sdata_info(sdata, |
| 259 | "AP VHT information is invalid, disable VHT\n"); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 260 | ret = IEEE80211_STA_DISABLE_VHT; |
| 261 | goto out; |
| 262 | } |
| 263 | |
| 264 | if (cfg80211_chandef_identical(chandef, &vht_chandef)) { |
| 265 | ret = 0; |
| 266 | goto out; |
| 267 | } |
| 268 | |
| 269 | if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) { |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 270 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 271 | sdata_info(sdata, |
| 272 | "AP VHT information doesn't match HT, disable VHT\n"); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 273 | ret = IEEE80211_STA_DISABLE_VHT; |
| 274 | goto out; |
| 275 | } |
| 276 | |
| 277 | *chandef = vht_chandef; |
| 278 | |
| 279 | ret = 0; |
| 280 | |
| 281 | out: |
Johannes Berg | 963a1852 | 2014-02-21 20:34:34 +0100 | [diff] [blame] | 282 | /* |
| 283 | * When tracking the current AP, don't do any further checks if the |
| 284 | * new chandef is identical to the one we're currently using for the |
| 285 | * connection. This keeps us from playing ping-pong with regulatory, |
| 286 | * without it the following can happen (for example): |
| 287 | * - connect to an AP with 80 MHz, world regdom allows 80 MHz |
| 288 | * - AP advertises regdom US |
| 289 | * - CRDA loads regdom US with 80 MHz prohibited (old database) |
| 290 | * - the code below detects an unsupported channel, downgrades, and |
| 291 | * we disconnect from the AP in the caller |
| 292 | * - disconnect causes CRDA to reload world regdomain and the game |
| 293 | * starts anew. |
| 294 | * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881) |
| 295 | * |
| 296 | * It seems possible that there are still scenarios with CSA or real |
| 297 | * bandwidth changes where a this could happen, but those cases are |
| 298 | * less common and wouldn't completely prevent using the AP. |
| 299 | */ |
| 300 | if (tracking && |
| 301 | cfg80211_chandef_identical(chandef, &sdata->vif.bss_conf.chandef)) |
| 302 | return ret; |
| 303 | |
Johannes Berg | 586e01e | 2013-02-14 12:13:53 +0100 | [diff] [blame] | 304 | /* don't print the message below for VHT mismatch if VHT is disabled */ |
| 305 | if (ret & IEEE80211_STA_DISABLE_VHT) |
| 306 | vht_chandef = *chandef; |
| 307 | |
Johannes Berg | ddfe49b | 2013-07-31 20:52:03 +0200 | [diff] [blame] | 308 | /* |
| 309 | * Ignore the DISABLED flag when we're already connected and only |
| 310 | * tracking the APs beacon for bandwidth changes - otherwise we |
| 311 | * might get disconnected here if we connect to an AP, update our |
| 312 | * regulatory information based on the AP's country IE and the |
| 313 | * information we have is wrong/outdated and disables the channel |
| 314 | * that we're actually using for the connection to the AP. |
| 315 | */ |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 316 | while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef, |
Johannes Berg | ddfe49b | 2013-07-31 20:52:03 +0200 | [diff] [blame] | 317 | tracking ? 0 : |
| 318 | IEEE80211_CHAN_DISABLED)) { |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 319 | if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) { |
| 320 | ret = IEEE80211_STA_DISABLE_HT | |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 321 | IEEE80211_STA_DISABLE_VHT | |
| 322 | IEEE80211_STA_DISABLE_HE; |
Chris Wright | b56e4b8 | 2013-07-31 12:12:24 -0700 | [diff] [blame] | 323 | break; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 324 | } |
| 325 | |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 326 | ret |= ieee80211_chandef_downgrade(chandef); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 327 | } |
| 328 | |
Daniel Gabay | 8cadb20 | 2020-01-31 13:12:52 +0200 | [diff] [blame] | 329 | if (!he_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef, |
| 330 | IEEE80211_CHAN_NO_HE)) |
Haim Dreyfuss | b5db1ac | 2020-01-31 13:12:44 +0200 | [diff] [blame] | 331 | ret |= IEEE80211_STA_DISABLE_HE; |
| 332 | |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 333 | if (chandef->width != vht_chandef.width && !tracking) |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 334 | sdata_info(sdata, |
| 335 | "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n"); |
| 336 | |
| 337 | WARN_ON_ONCE(!cfg80211_chandef_valid(chandef)); |
| 338 | return ret; |
| 339 | } |
| 340 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 341 | static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata, |
| 342 | struct sta_info *sta, |
Eliad Peller | 53b954e | 2014-07-24 11:20:05 +0300 | [diff] [blame] | 343 | const struct ieee80211_ht_cap *ht_cap, |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 344 | const struct ieee80211_vht_cap *vht_cap, |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 345 | const struct ieee80211_ht_operation *ht_oper, |
| 346 | const struct ieee80211_vht_operation *vht_oper, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 347 | const struct ieee80211_he_operation *he_oper, |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 348 | const u8 *bssid, u32 *changed) |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 349 | { |
| 350 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 351 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 352 | struct ieee80211_channel *chan = sdata->vif.bss_conf.chandef.chan; |
| 353 | struct ieee80211_supported_band *sband = |
| 354 | local->hw.wiphy->bands[chan->band]; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 355 | struct cfg80211_chan_def chandef; |
Johannes Berg | 9ed6bcc | 2009-05-08 20:47:39 +0200 | [diff] [blame] | 356 | u16 ht_opmode; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 357 | u32 flags; |
| 358 | enum ieee80211_sta_rx_bandwidth new_sta_bw; |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 359 | u32 vht_cap_info = 0; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 360 | int ret; |
| 361 | |
| 362 | /* if HT was/is disabled, don't track any bandwidth changes */ |
| 363 | if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper) |
| 364 | return 0; |
| 365 | |
| 366 | /* don't check VHT if we associated as non-VHT station */ |
| 367 | if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT) |
| 368 | vht_oper = NULL; |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 369 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 370 | /* don't check HE if we associated as non-HE station */ |
| 371 | if (ifmgd->flags & IEEE80211_STA_DISABLE_HE || |
| 372 | !ieee80211_get_he_sta_cap(sband)) |
| 373 | he_oper = NULL; |
| 374 | |
Johannes Berg | 1128958 | 2013-02-07 17:36:12 +0100 | [diff] [blame] | 375 | if (WARN_ON_ONCE(!sta)) |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 376 | return -EINVAL; |
Johannes Berg | 1128958 | 2013-02-07 17:36:12 +0100 | [diff] [blame] | 377 | |
Avri Altman | 017b45b | 2013-11-18 19:06:48 +0200 | [diff] [blame] | 378 | /* |
| 379 | * if bss configuration changed store the new one - |
| 380 | * this may be applicable even if channel is identical |
| 381 | */ |
| 382 | ht_opmode = le16_to_cpu(ht_oper->operation_mode); |
| 383 | if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) { |
| 384 | *changed |= BSS_CHANGED_HT; |
| 385 | sdata->vif.bss_conf.ht_operation_mode = ht_opmode; |
| 386 | } |
| 387 | |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 388 | if (vht_cap) |
| 389 | vht_cap_info = le32_to_cpu(vht_cap->vht_cap_info); |
| 390 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 391 | /* calculate new channel (type) based on HT/VHT/HE operation IEs */ |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 392 | flags = ieee80211_determine_chantype(sdata, sband, chan, vht_cap_info, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 393 | ht_oper, vht_oper, he_oper, |
Eliad Peller | 53b954e | 2014-07-24 11:20:05 +0300 | [diff] [blame] | 394 | &chandef, true); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 395 | |
| 396 | /* |
| 397 | * Downgrade the new channel if we associated with restricted |
| 398 | * capabilities. For example, if we associated as a 20 MHz STA |
| 399 | * to a 40 MHz AP (due to regulatory, capabilities or config |
| 400 | * reasons) then switching to a 40 MHz channel now won't do us |
| 401 | * any good -- we couldn't use it with the AP. |
| 402 | */ |
| 403 | if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ && |
| 404 | chandef.width == NL80211_CHAN_WIDTH_80P80) |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 405 | flags |= ieee80211_chandef_downgrade(&chandef); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 406 | if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ && |
| 407 | chandef.width == NL80211_CHAN_WIDTH_160) |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 408 | flags |= ieee80211_chandef_downgrade(&chandef); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 409 | if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ && |
| 410 | chandef.width > NL80211_CHAN_WIDTH_20) |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 411 | flags |= ieee80211_chandef_downgrade(&chandef); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 412 | |
| 413 | if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef)) |
| 414 | return 0; |
| 415 | |
| 416 | sdata_info(sdata, |
Thomas Pedersen | b6011960 | 2020-04-01 18:18:04 -0700 | [diff] [blame] | 417 | "AP %pM changed bandwidth, new config is %d.%03d MHz, " |
| 418 | "width %d (%d.%03d/%d MHz)\n", |
| 419 | ifmgd->bssid, chandef.chan->center_freq, |
| 420 | chandef.chan->freq_offset, chandef.width, |
| 421 | chandef.center_freq1, chandef.freq1_offset, |
| 422 | chandef.center_freq2); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 423 | |
| 424 | if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT | |
| 425 | IEEE80211_STA_DISABLE_VHT | |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 426 | IEEE80211_STA_DISABLE_HE | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 427 | IEEE80211_STA_DISABLE_40MHZ | |
| 428 | IEEE80211_STA_DISABLE_80P80MHZ | |
| 429 | IEEE80211_STA_DISABLE_160MHZ)) || |
| 430 | !cfg80211_chandef_valid(&chandef)) { |
| 431 | sdata_info(sdata, |
| 432 | "AP %pM changed bandwidth in a way we can't support - disconnect\n", |
| 433 | ifmgd->bssid); |
| 434 | return -EINVAL; |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 435 | } |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 436 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 437 | switch (chandef.width) { |
| 438 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 439 | case NL80211_CHAN_WIDTH_20: |
| 440 | new_sta_bw = IEEE80211_STA_RX_BW_20; |
| 441 | break; |
| 442 | case NL80211_CHAN_WIDTH_40: |
| 443 | new_sta_bw = IEEE80211_STA_RX_BW_40; |
| 444 | break; |
| 445 | case NL80211_CHAN_WIDTH_80: |
| 446 | new_sta_bw = IEEE80211_STA_RX_BW_80; |
| 447 | break; |
| 448 | case NL80211_CHAN_WIDTH_80P80: |
| 449 | case NL80211_CHAN_WIDTH_160: |
| 450 | new_sta_bw = IEEE80211_STA_RX_BW_160; |
| 451 | break; |
| 452 | default: |
| 453 | return -EINVAL; |
| 454 | } |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 455 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 456 | if (new_sta_bw > sta->cur_max_bandwidth) |
| 457 | new_sta_bw = sta->cur_max_bandwidth; |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 458 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 459 | if (new_sta_bw < sta->sta.bandwidth) { |
| 460 | sta->sta.bandwidth = new_sta_bw; |
| 461 | rate_control_rate_update(local, sband, sta, |
| 462 | IEEE80211_RC_BW_CHANGED); |
| 463 | } |
Rajkumar Manoharan | 7cc44ed | 2011-09-16 15:32:34 +0530 | [diff] [blame] | 464 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 465 | ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed); |
| 466 | if (ret) { |
| 467 | sdata_info(sdata, |
| 468 | "AP %pM changed bandwidth to incompatible one - disconnect\n", |
| 469 | ifmgd->bssid); |
| 470 | return ret; |
| 471 | } |
| 472 | |
| 473 | if (new_sta_bw > sta->sta.bandwidth) { |
| 474 | sta->sta.bandwidth = new_sta_bw; |
| 475 | rate_control_rate_update(local, sband, sta, |
| 476 | IEEE80211_RC_BW_CHANGED); |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 477 | } |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 478 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 479 | return 0; |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 480 | } |
| 481 | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 482 | /* frame sending functions */ |
| 483 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 484 | static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 485 | struct sk_buff *skb, u8 ap_ht_param, |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 486 | struct ieee80211_supported_band *sband, |
| 487 | struct ieee80211_channel *channel, |
| 488 | enum ieee80211_smps_mode smps) |
| 489 | { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 490 | u8 *pos; |
| 491 | u32 flags = channel->flags; |
| 492 | u16 cap; |
| 493 | struct ieee80211_sta_ht_cap ht_cap; |
| 494 | |
| 495 | BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap)); |
| 496 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 497 | memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap)); |
| 498 | ieee80211_apply_htcap_overrides(sdata, &ht_cap); |
| 499 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 500 | /* determine capability flags */ |
| 501 | cap = ht_cap.cap; |
| 502 | |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 503 | switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 504 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: |
| 505 | if (flags & IEEE80211_CHAN_NO_HT40PLUS) { |
| 506 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 507 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 508 | } |
| 509 | break; |
| 510 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: |
| 511 | if (flags & IEEE80211_CHAN_NO_HT40MINUS) { |
| 512 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 513 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 514 | } |
| 515 | break; |
| 516 | } |
| 517 | |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 518 | /* |
| 519 | * If 40 MHz was disabled associate as though we weren't |
| 520 | * capable of 40 MHz -- some broken APs will never fall |
| 521 | * back to trying to transmit in 20 MHz. |
| 522 | */ |
| 523 | if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) { |
| 524 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 525 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 526 | } |
| 527 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 528 | /* set SM PS mode properly */ |
| 529 | cap &= ~IEEE80211_HT_CAP_SM_PS; |
| 530 | switch (smps) { |
| 531 | case IEEE80211_SMPS_AUTOMATIC: |
| 532 | case IEEE80211_SMPS_NUM_MODES: |
| 533 | WARN_ON(1); |
Gustavo A. R. Silva | 02049ce | 2017-10-17 18:14:50 -0500 | [diff] [blame] | 534 | /* fall through */ |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 535 | case IEEE80211_SMPS_OFF: |
| 536 | cap |= WLAN_HT_CAP_SM_PS_DISABLED << |
| 537 | IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 538 | break; |
| 539 | case IEEE80211_SMPS_STATIC: |
| 540 | cap |= WLAN_HT_CAP_SM_PS_STATIC << |
| 541 | IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 542 | break; |
| 543 | case IEEE80211_SMPS_DYNAMIC: |
| 544 | cap |= WLAN_HT_CAP_SM_PS_DYNAMIC << |
| 545 | IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 546 | break; |
| 547 | } |
| 548 | |
| 549 | /* reserve and fill IE */ |
| 550 | pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2); |
| 551 | ieee80211_ie_build_ht_cap(pos, &ht_cap, cap); |
| 552 | } |
| 553 | |
Sara Sharon | 322cd40 | 2015-07-08 15:41:43 +0300 | [diff] [blame] | 554 | /* This function determines vht capability flags for the association |
| 555 | * and builds the IE. |
| 556 | * Note - the function may set the owner of the MU-MIMO capability |
| 557 | */ |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 558 | static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata, |
| 559 | struct sk_buff *skb, |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 560 | struct ieee80211_supported_band *sband, |
| 561 | struct ieee80211_vht_cap *ap_vht_cap) |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 562 | { |
Sara Sharon | 322cd40 | 2015-07-08 15:41:43 +0300 | [diff] [blame] | 563 | struct ieee80211_local *local = sdata->local; |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 564 | u8 *pos; |
| 565 | u32 cap; |
| 566 | struct ieee80211_sta_vht_cap vht_cap; |
Eyal Shapira | c1cf6d4 | 2014-01-08 15:49:08 +0200 | [diff] [blame] | 567 | u32 mask, ap_bf_sts, our_bf_sts; |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 568 | |
| 569 | BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap)); |
| 570 | |
| 571 | memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap)); |
Johannes Berg | dd5ecfe | 2013-02-21 17:40:19 +0100 | [diff] [blame] | 572 | ieee80211_apply_vhtcap_overrides(sdata, &vht_cap); |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 573 | |
| 574 | /* determine capability flags */ |
| 575 | cap = vht_cap.cap; |
| 576 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 577 | if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) { |
Johannes Berg | 575f053 | 2014-11-24 16:51:33 +0100 | [diff] [blame] | 578 | u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; |
| 579 | |
| 580 | cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; |
| 581 | if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ || |
| 582 | bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ) |
| 583 | cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) { |
| 587 | cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160; |
Johannes Berg | 575f053 | 2014-11-24 16:51:33 +0100 | [diff] [blame] | 588 | cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 589 | } |
| 590 | |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 591 | /* |
| 592 | * Some APs apparently get confused if our capabilities are better |
| 593 | * than theirs, so restrict what we advertise in the assoc request. |
| 594 | */ |
| 595 | if (!(ap_vht_cap->vht_cap_info & |
| 596 | cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE))) |
Sara Sharon | 322cd40 | 2015-07-08 15:41:43 +0300 | [diff] [blame] | 597 | cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
| 598 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE); |
| 599 | else if (!(ap_vht_cap->vht_cap_info & |
| 600 | cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))) |
| 601 | cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE; |
| 602 | |
| 603 | /* |
| 604 | * If some other vif is using the MU-MIMO capablity we cannot associate |
| 605 | * using MU-MIMO - this will lead to contradictions in the group-id |
| 606 | * mechanism. |
| 607 | * Ownership is defined since association request, in order to avoid |
| 608 | * simultaneous associations with MU-MIMO. |
| 609 | */ |
| 610 | if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) { |
| 611 | bool disable_mu_mimo = false; |
| 612 | struct ieee80211_sub_if_data *other; |
| 613 | |
| 614 | list_for_each_entry_rcu(other, &local->interfaces, list) { |
Sara Sharon | b5a33d5 | 2016-02-16 12:48:18 +0200 | [diff] [blame] | 615 | if (other->vif.mu_mimo_owner) { |
Sara Sharon | 322cd40 | 2015-07-08 15:41:43 +0300 | [diff] [blame] | 616 | disable_mu_mimo = true; |
| 617 | break; |
| 618 | } |
| 619 | } |
| 620 | if (disable_mu_mimo) |
| 621 | cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE; |
| 622 | else |
Sara Sharon | b5a33d5 | 2016-02-16 12:48:18 +0200 | [diff] [blame] | 623 | sdata->vif.mu_mimo_owner = true; |
Sara Sharon | 322cd40 | 2015-07-08 15:41:43 +0300 | [diff] [blame] | 624 | } |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 625 | |
Eyal Shapira | c1cf6d4 | 2014-01-08 15:49:08 +0200 | [diff] [blame] | 626 | mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK; |
| 627 | |
| 628 | ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask; |
| 629 | our_bf_sts = cap & mask; |
| 630 | |
| 631 | if (ap_bf_sts < our_bf_sts) { |
| 632 | cap &= ~mask; |
| 633 | cap |= ap_bf_sts; |
| 634 | } |
| 635 | |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 636 | /* reserve and fill IE */ |
Mahesh Palivela | d495028 | 2012-10-10 11:25:40 +0000 | [diff] [blame] | 637 | pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2); |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 638 | ieee80211_ie_build_vht_cap(pos, &vht_cap, cap); |
| 639 | } |
| 640 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 641 | /* This function determines HE capability flags for the association |
| 642 | * and builds the IE. |
| 643 | */ |
| 644 | static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata, |
| 645 | struct sk_buff *skb, |
| 646 | struct ieee80211_supported_band *sband) |
| 647 | { |
| 648 | u8 *pos; |
| 649 | const struct ieee80211_sta_he_cap *he_cap = NULL; |
Haim Dreyfuss | b5db1ac | 2020-01-31 13:12:44 +0200 | [diff] [blame] | 650 | struct ieee80211_chanctx_conf *chanctx_conf; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 651 | u8 he_cap_size; |
Haim Dreyfuss | b5db1ac | 2020-01-31 13:12:44 +0200 | [diff] [blame] | 652 | bool reg_cap = false; |
| 653 | |
| 654 | rcu_read_lock(); |
| 655 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 656 | if (!WARN_ON_ONCE(!chanctx_conf)) |
| 657 | reg_cap = cfg80211_chandef_usable(sdata->wdev.wiphy, |
| 658 | &chanctx_conf->def, |
| 659 | IEEE80211_CHAN_NO_HE); |
| 660 | |
| 661 | rcu_read_unlock(); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 662 | |
| 663 | he_cap = ieee80211_get_he_sta_cap(sband); |
Haim Dreyfuss | b5db1ac | 2020-01-31 13:12:44 +0200 | [diff] [blame] | 664 | if (!he_cap || !reg_cap) |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 665 | return; |
| 666 | |
| 667 | /* |
| 668 | * TODO: the 1 added is because this temporarily is under the EXTENSION |
| 669 | * IE. Get rid of it when it moves. |
| 670 | */ |
| 671 | he_cap_size = |
| 672 | 2 + 1 + sizeof(he_cap->he_cap_elem) + |
| 673 | ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) + |
| 674 | ieee80211_he_ppe_size(he_cap->ppe_thres[0], |
| 675 | he_cap->he_cap_elem.phy_cap_info); |
| 676 | pos = skb_put(skb, he_cap_size); |
| 677 | ieee80211_ie_build_he_cap(pos, he_cap, pos + he_cap_size); |
Rajkumar Manoharan | 24a2042 | 2020-05-28 21:34:32 +0200 | [diff] [blame] | 678 | |
| 679 | ieee80211_ie_build_he_6ghz_cap(sdata, skb); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 680 | } |
| 681 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 682 | static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata) |
| 683 | { |
| 684 | struct ieee80211_local *local = sdata->local; |
| 685 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 686 | struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; |
| 687 | struct sk_buff *skb; |
| 688 | struct ieee80211_mgmt *mgmt; |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 689 | u8 *pos, qos_info, *ie_start; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 690 | size_t offset = 0, noffset; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 691 | int i, count, rates_len, supp_rates_len, shift; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 692 | u16 capab; |
| 693 | struct ieee80211_supported_band *sband; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 694 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 695 | struct ieee80211_channel *chan; |
Johannes Berg | 44f6d42 | 2017-06-10 13:52:44 +0300 | [diff] [blame] | 696 | u32 rates = 0; |
Johannes Berg | 2ff69b0 | 2020-01-31 13:31:11 +0200 | [diff] [blame] | 697 | struct element *ext_capa = NULL; |
| 698 | |
| 699 | /* we know it's writable, cast away the const */ |
| 700 | if (assoc_data->ie_len) |
| 701 | ext_capa = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, |
| 702 | assoc_data->ie, |
| 703 | assoc_data->ie_len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 704 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 705 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 706 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 707 | rcu_read_lock(); |
| 708 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 709 | if (WARN_ON(!chanctx_conf)) { |
| 710 | rcu_read_unlock(); |
| 711 | return; |
| 712 | } |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 713 | chan = chanctx_conf->def.chan; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 714 | rcu_read_unlock(); |
| 715 | sband = local->hw.wiphy->bands[chan->band]; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 716 | shift = ieee80211_vif_get_shift(&sdata->vif); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 717 | |
| 718 | if (assoc_data->supp_rates_len) { |
| 719 | /* |
| 720 | * Get all rates supported by the device and the AP as |
| 721 | * some APs don't like getting a superset of their rates |
| 722 | * in the association request (e.g. D-Link DAP 1353 in |
| 723 | * b-only mode)... |
| 724 | */ |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 725 | rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband, |
| 726 | assoc_data->supp_rates, |
| 727 | assoc_data->supp_rates_len, |
| 728 | &rates); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 729 | } else { |
| 730 | /* |
| 731 | * In case AP not provide any supported rates information |
| 732 | * before association, we send information element(s) with |
| 733 | * all rates that we support. |
| 734 | */ |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 735 | rates_len = 0; |
| 736 | for (i = 0; i < sband->n_bitrates; i++) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 737 | rates |= BIT(i); |
| 738 | rates_len++; |
| 739 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | skb = alloc_skb(local->hw.extra_tx_headroom + |
| 743 | sizeof(*mgmt) + /* bit too much but doesn't matter */ |
| 744 | 2 + assoc_data->ssid_len + /* SSID */ |
| 745 | 4 + rates_len + /* (extended) rates */ |
| 746 | 4 + /* power capability */ |
| 747 | 2 + 2 * sband->n_channels + /* supported channels */ |
| 748 | 2 + sizeof(struct ieee80211_ht_cap) + /* HT */ |
Mahesh Palivela | d495028 | 2012-10-10 11:25:40 +0000 | [diff] [blame] | 749 | 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */ |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 750 | 2 + 1 + sizeof(struct ieee80211_he_cap_elem) + /* HE */ |
| 751 | sizeof(struct ieee80211_he_mcs_nss_supp) + |
| 752 | IEEE80211_HE_PPE_THRES_MAX_LEN + |
Rajkumar Manoharan | 24a2042 | 2020-05-28 21:34:32 +0200 | [diff] [blame] | 753 | 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa) + |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 754 | assoc_data->ie_len + /* extra IEs */ |
Jouni Malinen | 39404fe | 2016-10-27 00:42:05 +0300 | [diff] [blame] | 755 | (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) + |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 756 | 9, /* WMM */ |
| 757 | GFP_KERNEL); |
| 758 | if (!skb) |
| 759 | return; |
| 760 | |
| 761 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 762 | |
| 763 | capab = WLAN_CAPABILITY_ESS; |
| 764 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 765 | if (sband->band == NL80211_BAND_2GHZ) { |
Johannes Berg | ea1b2b45 | 2015-06-02 20:15:49 +0200 | [diff] [blame] | 766 | capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME; |
| 767 | capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY) |
| 771 | capab |= WLAN_CAPABILITY_PRIVACY; |
| 772 | |
| 773 | if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) && |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 774 | ieee80211_hw_check(&local->hw, SPECTRUM_MGMT)) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 775 | capab |= WLAN_CAPABILITY_SPECTRUM_MGMT; |
| 776 | |
Assaf Krauss | cd2f5dd | 2014-09-03 15:25:02 +0300 | [diff] [blame] | 777 | if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM) |
| 778 | capab |= WLAN_CAPABILITY_RADIO_MEASURE; |
| 779 | |
Johannes Berg | b080db5 | 2017-06-16 14:29:19 +0200 | [diff] [blame] | 780 | mgmt = skb_put_zero(skb, 24); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 781 | memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN); |
| 782 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
| 783 | memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN); |
| 784 | |
| 785 | if (!is_zero_ether_addr(assoc_data->prev_bssid)) { |
| 786 | skb_put(skb, 10); |
| 787 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 788 | IEEE80211_STYPE_REASSOC_REQ); |
| 789 | mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab); |
| 790 | mgmt->u.reassoc_req.listen_interval = |
| 791 | cpu_to_le16(local->hw.conf.listen_interval); |
| 792 | memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid, |
| 793 | ETH_ALEN); |
| 794 | } else { |
| 795 | skb_put(skb, 4); |
| 796 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 797 | IEEE80211_STYPE_ASSOC_REQ); |
| 798 | mgmt->u.assoc_req.capab_info = cpu_to_le16(capab); |
| 799 | mgmt->u.assoc_req.listen_interval = |
| 800 | cpu_to_le16(local->hw.conf.listen_interval); |
| 801 | } |
| 802 | |
| 803 | /* SSID */ |
| 804 | pos = skb_put(skb, 2 + assoc_data->ssid_len); |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 805 | ie_start = pos; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 806 | *pos++ = WLAN_EID_SSID; |
| 807 | *pos++ = assoc_data->ssid_len; |
| 808 | memcpy(pos, assoc_data->ssid, assoc_data->ssid_len); |
| 809 | |
| 810 | /* add all rates which were marked to be used above */ |
| 811 | supp_rates_len = rates_len; |
| 812 | if (supp_rates_len > 8) |
| 813 | supp_rates_len = 8; |
| 814 | |
| 815 | pos = skb_put(skb, supp_rates_len + 2); |
| 816 | *pos++ = WLAN_EID_SUPP_RATES; |
| 817 | *pos++ = supp_rates_len; |
| 818 | |
| 819 | count = 0; |
| 820 | for (i = 0; i < sband->n_bitrates; i++) { |
| 821 | if (BIT(i) & rates) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 822 | int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate, |
| 823 | 5 * (1 << shift)); |
| 824 | *pos++ = (u8) rate; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 825 | if (++count == 8) |
| 826 | break; |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | if (rates_len > count) { |
| 831 | pos = skb_put(skb, rates_len - count + 2); |
| 832 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 833 | *pos++ = rates_len - count; |
| 834 | |
| 835 | for (i++; i < sband->n_bitrates; i++) { |
| 836 | if (BIT(i) & rates) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 837 | int rate; |
| 838 | rate = DIV_ROUND_UP(sband->bitrates[i].bitrate, |
| 839 | 5 * (1 << shift)); |
| 840 | *pos++ = (u8) rate; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 841 | } |
| 842 | } |
| 843 | } |
| 844 | |
Assaf Krauss | cd2f5dd | 2014-09-03 15:25:02 +0300 | [diff] [blame] | 845 | if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT || |
| 846 | capab & WLAN_CAPABILITY_RADIO_MEASURE) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 847 | pos = skb_put(skb, 4); |
| 848 | *pos++ = WLAN_EID_PWR_CAPABILITY; |
| 849 | *pos++ = 2; |
| 850 | *pos++ = 0; /* min tx power */ |
Simon Wunderlich | 0430c88 | 2013-07-08 16:55:55 +0200 | [diff] [blame] | 851 | /* max tx power */ |
| 852 | *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def); |
Assaf Krauss | cd2f5dd | 2014-09-03 15:25:02 +0300 | [diff] [blame] | 853 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 854 | |
Johannes Berg | 2ff69b0 | 2020-01-31 13:31:11 +0200 | [diff] [blame] | 855 | /* |
| 856 | * Per spec, we shouldn't include the list of channels if we advertise |
| 857 | * support for extended channel switching, but we've always done that; |
| 858 | * (for now?) apply this restriction only on the (new) 6 GHz band. |
| 859 | */ |
| 860 | if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT && |
| 861 | (sband->band != NL80211_BAND_6GHZ || |
| 862 | !ext_capa || ext_capa->datalen < 1 || |
| 863 | !(ext_capa->data[0] & WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING))) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 864 | /* TODO: get this in reg domain format */ |
| 865 | pos = skb_put(skb, 2 * sband->n_channels + 2); |
| 866 | *pos++ = WLAN_EID_SUPPORTED_CHANNELS; |
| 867 | *pos++ = 2 * sband->n_channels; |
| 868 | for (i = 0; i < sband->n_channels; i++) { |
| 869 | *pos++ = ieee80211_frequency_to_channel( |
| 870 | sband->channels[i].center_freq); |
| 871 | *pos++ = 1; /* one channel in the subband*/ |
| 872 | } |
| 873 | } |
| 874 | |
Sara Sharon | caf5633 | 2019-01-16 23:03:25 +0200 | [diff] [blame] | 875 | /* Set MBSSID support for HE AP if needed */ |
| 876 | if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) && |
Johannes Berg | 2ff69b0 | 2020-01-31 13:31:11 +0200 | [diff] [blame] | 877 | !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && assoc_data->ie_len && |
| 878 | ext_capa && ext_capa->datalen >= 3) |
| 879 | ext_capa->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT; |
Sara Sharon | caf5633 | 2019-01-16 23:03:25 +0200 | [diff] [blame] | 880 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 881 | /* if present, add any custom IEs that go before HT */ |
Johannes Berg | b3f51e9 | 2013-10-25 11:31:42 +0200 | [diff] [blame] | 882 | if (assoc_data->ie_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 883 | static const u8 before_ht[] = { |
| 884 | WLAN_EID_SSID, |
| 885 | WLAN_EID_SUPP_RATES, |
| 886 | WLAN_EID_EXT_SUPP_RATES, |
| 887 | WLAN_EID_PWR_CAPABILITY, |
| 888 | WLAN_EID_SUPPORTED_CHANNELS, |
| 889 | WLAN_EID_RSN, |
| 890 | WLAN_EID_QOS_CAPA, |
| 891 | WLAN_EID_RRM_ENABLED_CAPABILITIES, |
| 892 | WLAN_EID_MOBILITY_DOMAIN, |
Johannes Berg | 8ed2874 | 2014-10-27 12:03:19 +0100 | [diff] [blame] | 893 | WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */ |
| 894 | WLAN_EID_RIC_DATA, /* reassoc only */ |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 895 | WLAN_EID_SUPPORTED_REGULATORY_CLASSES, |
| 896 | }; |
Johannes Berg | 8ed2874 | 2014-10-27 12:03:19 +0100 | [diff] [blame] | 897 | static const u8 after_ric[] = { |
| 898 | WLAN_EID_SUPPORTED_REGULATORY_CLASSES, |
| 899 | WLAN_EID_HT_CAPABILITY, |
| 900 | WLAN_EID_BSS_COEX_2040, |
Johannes Berg | a7f26d8 | 2017-08-05 11:44:32 +0300 | [diff] [blame] | 901 | /* luckily this is almost always there */ |
Johannes Berg | 8ed2874 | 2014-10-27 12:03:19 +0100 | [diff] [blame] | 902 | WLAN_EID_EXT_CAPABILITY, |
| 903 | WLAN_EID_QOS_TRAFFIC_CAPA, |
| 904 | WLAN_EID_TIM_BCAST_REQ, |
| 905 | WLAN_EID_INTERWORKING, |
Johannes Berg | a7f26d8 | 2017-08-05 11:44:32 +0300 | [diff] [blame] | 906 | /* 60 GHz (Multi-band, DMG, MMS) can't happen */ |
Johannes Berg | 8ed2874 | 2014-10-27 12:03:19 +0100 | [diff] [blame] | 907 | WLAN_EID_VHT_CAPABILITY, |
| 908 | WLAN_EID_OPMODE_NOTIF, |
| 909 | }; |
| 910 | |
| 911 | noffset = ieee80211_ie_split_ric(assoc_data->ie, |
| 912 | assoc_data->ie_len, |
| 913 | before_ht, |
| 914 | ARRAY_SIZE(before_ht), |
| 915 | after_ric, |
| 916 | ARRAY_SIZE(after_ric), |
| 917 | offset); |
yuan linyu | b952f4d | 2017-06-18 22:52:04 +0800 | [diff] [blame] | 918 | skb_put_data(skb, assoc_data->ie + offset, noffset - offset); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 919 | offset = noffset; |
| 920 | } |
| 921 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 922 | if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) && |
| 923 | !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))) |
| 924 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
| 925 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 926 | if (sband->band != NL80211_BAND_6GHZ && |
| 927 | !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 928 | ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param, |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 929 | sband, chan, sdata->smps_mode); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 930 | |
Johannes Berg | 3de3802 | 2014-02-04 09:54:07 +0100 | [diff] [blame] | 931 | /* if present, add any custom IEs that go before VHT */ |
| 932 | if (assoc_data->ie_len) { |
| 933 | static const u8 before_vht[] = { |
Johannes Berg | a7f26d8 | 2017-08-05 11:44:32 +0300 | [diff] [blame] | 934 | /* |
| 935 | * no need to list the ones split off before HT |
| 936 | * or generated here |
| 937 | */ |
Johannes Berg | 3de3802 | 2014-02-04 09:54:07 +0100 | [diff] [blame] | 938 | WLAN_EID_BSS_COEX_2040, |
| 939 | WLAN_EID_EXT_CAPABILITY, |
| 940 | WLAN_EID_QOS_TRAFFIC_CAPA, |
| 941 | WLAN_EID_TIM_BCAST_REQ, |
| 942 | WLAN_EID_INTERWORKING, |
Johannes Berg | a7f26d8 | 2017-08-05 11:44:32 +0300 | [diff] [blame] | 943 | /* 60 GHz (Multi-band, DMG, MMS) can't happen */ |
Johannes Berg | 3de3802 | 2014-02-04 09:54:07 +0100 | [diff] [blame] | 944 | }; |
Johannes Berg | 8ed2874 | 2014-10-27 12:03:19 +0100 | [diff] [blame] | 945 | |
| 946 | /* RIC already taken above, so no need to handle here anymore */ |
Johannes Berg | 3de3802 | 2014-02-04 09:54:07 +0100 | [diff] [blame] | 947 | noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len, |
| 948 | before_vht, ARRAY_SIZE(before_vht), |
| 949 | offset); |
yuan linyu | b952f4d | 2017-06-18 22:52:04 +0800 | [diff] [blame] | 950 | skb_put_data(skb, assoc_data->ie + offset, noffset - offset); |
Johannes Berg | 3de3802 | 2014-02-04 09:54:07 +0100 | [diff] [blame] | 951 | offset = noffset; |
| 952 | } |
| 953 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 954 | /* if present, add any custom IEs that go before HE */ |
| 955 | if (assoc_data->ie_len) { |
| 956 | static const u8 before_he[] = { |
| 957 | /* |
| 958 | * no need to list the ones split off before VHT |
| 959 | * or generated here |
| 960 | */ |
| 961 | WLAN_EID_OPMODE_NOTIF, |
| 962 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE, |
| 963 | /* 11ai elements */ |
| 964 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION, |
| 965 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY, |
| 966 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM, |
| 967 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER, |
| 968 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN, |
| 969 | /* TODO: add 11ah/11aj/11ak elements */ |
| 970 | }; |
| 971 | |
| 972 | /* RIC already taken above, so no need to handle here anymore */ |
| 973 | noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len, |
| 974 | before_he, ARRAY_SIZE(before_he), |
| 975 | offset); |
| 976 | pos = skb_put(skb, noffset - offset); |
| 977 | memcpy(pos, assoc_data->ie + offset, noffset - offset); |
| 978 | offset = noffset; |
| 979 | } |
| 980 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 981 | if (sband->band != NL80211_BAND_6GHZ && |
| 982 | !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 983 | ieee80211_add_vht_ie(sdata, skb, sband, |
| 984 | &assoc_data->ap_vht_cap); |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 985 | |
Shaul Triebitz | dc7eb0f | 2018-12-15 11:03:20 +0200 | [diff] [blame] | 986 | /* |
| 987 | * If AP doesn't support HT, mark HE as disabled. |
| 988 | * If on the 5GHz band, make sure it supports VHT. |
| 989 | */ |
| 990 | if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || |
| 991 | (sband->band == NL80211_BAND_5GHZ && |
| 992 | ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
| 993 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
| 994 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 995 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) |
| 996 | ieee80211_add_he_ie(sdata, skb, sband); |
| 997 | |
| 998 | /* if present, add any custom non-vendor IEs that go after HE */ |
Johannes Berg | b3f51e9 | 2013-10-25 11:31:42 +0200 | [diff] [blame] | 999 | if (assoc_data->ie_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1000 | noffset = ieee80211_ie_split_vendor(assoc_data->ie, |
| 1001 | assoc_data->ie_len, |
| 1002 | offset); |
yuan linyu | b952f4d | 2017-06-18 22:52:04 +0800 | [diff] [blame] | 1003 | skb_put_data(skb, assoc_data->ie + offset, noffset - offset); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1004 | offset = noffset; |
| 1005 | } |
| 1006 | |
Johannes Berg | 76f0303 | 2012-03-08 15:02:05 +0100 | [diff] [blame] | 1007 | if (assoc_data->wmm) { |
| 1008 | if (assoc_data->uapsd) { |
Eliad Peller | dc41e4d | 2012-03-14 16:15:03 +0200 | [diff] [blame] | 1009 | qos_info = ifmgd->uapsd_queues; |
| 1010 | qos_info |= (ifmgd->uapsd_max_sp_len << |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1011 | IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT); |
| 1012 | } else { |
| 1013 | qos_info = 0; |
| 1014 | } |
| 1015 | |
Arik Nemtsov | 40b861a | 2014-07-17 17:14:23 +0300 | [diff] [blame] | 1016 | pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | /* add any remaining custom (i.e. vendor specific here) IEs */ |
Johannes Berg | b3f51e9 | 2013-10-25 11:31:42 +0200 | [diff] [blame] | 1020 | if (assoc_data->ie_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1021 | noffset = assoc_data->ie_len; |
yuan linyu | b952f4d | 2017-06-18 22:52:04 +0800 | [diff] [blame] | 1022 | skb_put_data(skb, assoc_data->ie + offset, noffset - offset); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1023 | } |
| 1024 | |
Jouni Malinen | 39404fe | 2016-10-27 00:42:05 +0300 | [diff] [blame] | 1025 | if (assoc_data->fils_kek_len && |
| 1026 | fils_encrypt_assoc_req(skb, assoc_data) < 0) { |
| 1027 | dev_kfree_skb(skb); |
| 1028 | return; |
| 1029 | } |
| 1030 | |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 1031 | pos = skb_tail_pointer(skb); |
| 1032 | kfree(ifmgd->assoc_req_ies); |
| 1033 | ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC); |
| 1034 | ifmgd->assoc_req_ies_len = pos - ie_start; |
| 1035 | |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 1036 | drv_mgd_prepare_tx(local, sdata, 0); |
Johannes Berg | a1845fc | 2012-06-27 13:18:36 +0200 | [diff] [blame] | 1037 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1038 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1039 | if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 1040 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS | |
| 1041 | IEEE80211_TX_INTFL_MLME_CONN_TX; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1042 | ieee80211_tx_skb(sdata, skb); |
| 1043 | } |
| 1044 | |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1045 | void ieee80211_send_pspoll(struct ieee80211_local *local, |
| 1046 | struct ieee80211_sub_if_data *sdata) |
| 1047 | { |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1048 | struct ieee80211_pspoll *pspoll; |
| 1049 | struct sk_buff *skb; |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1050 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1051 | skb = ieee80211_pspoll_get(&local->hw, &sdata->vif); |
| 1052 | if (!skb) |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1053 | return; |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1054 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1055 | pspoll = (struct ieee80211_pspoll *) skb->data; |
| 1056 | pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1057 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 1058 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 1059 | ieee80211_tx_skb(sdata, skb); |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1060 | } |
| 1061 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1062 | void ieee80211_send_nullfunc(struct ieee80211_local *local, |
| 1063 | struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 076cdcb | 2015-09-24 16:14:55 +0200 | [diff] [blame] | 1064 | bool powersave) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1065 | { |
| 1066 | struct sk_buff *skb; |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1067 | struct ieee80211_hdr_3addr *nullfunc; |
Rajkumar Manoharan | b6f3530 | 2011-09-29 20:34:04 +0530 | [diff] [blame] | 1068 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1069 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 1070 | /* Don't send NDPs when STA is connected HE */ |
| 1071 | if (sdata->vif.type == NL80211_IFTYPE_STATION && |
| 1072 | !(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) |
| 1073 | return; |
| 1074 | |
Ben Caradoc-Davies | 7c181f4 | 2018-03-19 12:57:44 +1300 | [diff] [blame] | 1075 | skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif, |
| 1076 | !ieee80211_hw_check(&local->hw, DOESNT_SUPPORT_QOS_NDP)); |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1077 | if (!skb) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1078 | return; |
| 1079 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1080 | nullfunc = (struct ieee80211_hdr_3addr *) skb->data; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1081 | if (powersave) |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1082 | nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1083 | |
Seth Forshee | 6c17b77 | 2013-02-11 11:21:07 -0600 | [diff] [blame] | 1084 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT | |
| 1085 | IEEE80211_TX_INTFL_OFFCHAN_TX_OK; |
Pontus Fuchs | ff40b42 | 2013-06-04 12:44:52 +0200 | [diff] [blame] | 1086 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1087 | if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
Pontus Fuchs | ff40b42 | 2013-06-04 12:44:52 +0200 | [diff] [blame] | 1088 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; |
| 1089 | |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 1090 | if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) |
Rajkumar Manoharan | b6f3530 | 2011-09-29 20:34:04 +0530 | [diff] [blame] | 1091 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE; |
| 1092 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 1093 | ieee80211_tx_skb(sdata, skb); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1094 | } |
| 1095 | |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 1096 | static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local, |
| 1097 | struct ieee80211_sub_if_data *sdata) |
| 1098 | { |
| 1099 | struct sk_buff *skb; |
| 1100 | struct ieee80211_hdr *nullfunc; |
| 1101 | __le16 fc; |
| 1102 | |
| 1103 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) |
| 1104 | return; |
| 1105 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 1106 | /* Don't send NDPs when connected HE */ |
| 1107 | if (!(sdata->u.mgd.flags & IEEE80211_STA_DISABLE_HE)) |
| 1108 | return; |
| 1109 | |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 1110 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30); |
Joe Perches | d15b845 | 2011-08-29 14:17:31 -0700 | [diff] [blame] | 1111 | if (!skb) |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 1112 | return; |
Joe Perches | d15b845 | 2011-08-29 14:17:31 -0700 | [diff] [blame] | 1113 | |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 1114 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 1115 | |
Johannes Berg | b080db5 | 2017-06-16 14:29:19 +0200 | [diff] [blame] | 1116 | nullfunc = skb_put_zero(skb, 30); |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 1117 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | |
| 1118 | IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); |
| 1119 | nullfunc->frame_control = fc; |
| 1120 | memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN); |
| 1121 | memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); |
| 1122 | memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN); |
| 1123 | memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN); |
| 1124 | |
| 1125 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 1126 | ieee80211_tx_skb(sdata, skb); |
| 1127 | } |
| 1128 | |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1129 | /* spectrum management related things */ |
| 1130 | static void ieee80211_chswitch_work(struct work_struct *work) |
| 1131 | { |
| 1132 | struct ieee80211_sub_if_data *sdata = |
| 1133 | container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work); |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 1134 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1135 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Arik Nemtsov | 7578d57 | 2013-09-01 17:15:51 +0300 | [diff] [blame] | 1136 | int ret; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1137 | |
Johannes Berg | 9607e6b66 | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 1138 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1139 | return; |
| 1140 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 1141 | sdata_lock(sdata); |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1142 | mutex_lock(&local->mtx); |
| 1143 | mutex_lock(&local->chanctx_mtx); |
| 1144 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1145 | if (!ifmgd->associated) |
| 1146 | goto out; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1147 | |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1148 | if (!sdata->vif.csa_active) |
| 1149 | goto out; |
| 1150 | |
| 1151 | /* |
| 1152 | * using reservation isn't immediate as it may be deferred until later |
| 1153 | * with multi-vif. once reservation is complete it will re-schedule the |
| 1154 | * work with no reserved_chanctx so verify chandef to check if it |
| 1155 | * completed successfully |
| 1156 | */ |
| 1157 | |
| 1158 | if (sdata->reserved_chanctx) { |
Ilan Peer | 0007e94 | 2018-08-31 11:31:10 +0300 | [diff] [blame] | 1159 | struct ieee80211_supported_band *sband = NULL; |
| 1160 | struct sta_info *mgd_sta = NULL; |
| 1161 | enum ieee80211_sta_rx_bandwidth bw = IEEE80211_STA_RX_BW_20; |
| 1162 | |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1163 | /* |
| 1164 | * with multi-vif csa driver may call ieee80211_csa_finish() |
| 1165 | * many times while waiting for other interfaces to use their |
| 1166 | * reservations |
| 1167 | */ |
| 1168 | if (sdata->reserved_ready) |
| 1169 | goto out; |
| 1170 | |
Ilan Peer | 0007e94 | 2018-08-31 11:31:10 +0300 | [diff] [blame] | 1171 | if (sdata->vif.bss_conf.chandef.width != |
| 1172 | sdata->csa_chandef.width) { |
| 1173 | /* |
| 1174 | * For managed interface, we need to also update the AP |
| 1175 | * station bandwidth and align the rate scale algorithm |
| 1176 | * on the bandwidth change. Here we only consider the |
| 1177 | * bandwidth of the new channel definition (as channel |
| 1178 | * switch flow does not have the full HT/VHT/HE |
| 1179 | * information), assuming that if additional changes are |
| 1180 | * required they would be done as part of the processing |
| 1181 | * of the next beacon from the AP. |
| 1182 | */ |
| 1183 | switch (sdata->csa_chandef.width) { |
| 1184 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 1185 | case NL80211_CHAN_WIDTH_20: |
| 1186 | default: |
| 1187 | bw = IEEE80211_STA_RX_BW_20; |
| 1188 | break; |
| 1189 | case NL80211_CHAN_WIDTH_40: |
| 1190 | bw = IEEE80211_STA_RX_BW_40; |
| 1191 | break; |
| 1192 | case NL80211_CHAN_WIDTH_80: |
| 1193 | bw = IEEE80211_STA_RX_BW_80; |
| 1194 | break; |
| 1195 | case NL80211_CHAN_WIDTH_80P80: |
| 1196 | case NL80211_CHAN_WIDTH_160: |
| 1197 | bw = IEEE80211_STA_RX_BW_160; |
| 1198 | break; |
| 1199 | } |
| 1200 | |
| 1201 | mgd_sta = sta_info_get(sdata, ifmgd->bssid); |
| 1202 | sband = |
| 1203 | local->hw.wiphy->bands[sdata->csa_chandef.chan->band]; |
| 1204 | } |
| 1205 | |
| 1206 | if (sdata->vif.bss_conf.chandef.width > |
| 1207 | sdata->csa_chandef.width) { |
| 1208 | mgd_sta->sta.bandwidth = bw; |
| 1209 | rate_control_rate_update(local, sband, mgd_sta, |
| 1210 | IEEE80211_RC_BW_CHANGED); |
| 1211 | } |
| 1212 | |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1213 | ret = ieee80211_vif_use_reserved_context(sdata); |
| 1214 | if (ret) { |
| 1215 | sdata_info(sdata, |
| 1216 | "failed to use reserved channel context, disconnecting (err=%d)\n", |
| 1217 | ret); |
| 1218 | ieee80211_queue_work(&sdata->local->hw, |
| 1219 | &ifmgd->csa_connection_drop_work); |
| 1220 | goto out; |
| 1221 | } |
| 1222 | |
Ilan Peer | 0007e94 | 2018-08-31 11:31:10 +0300 | [diff] [blame] | 1223 | if (sdata->vif.bss_conf.chandef.width < |
| 1224 | sdata->csa_chandef.width) { |
| 1225 | mgd_sta->sta.bandwidth = bw; |
| 1226 | rate_control_rate_update(local, sband, mgd_sta, |
| 1227 | IEEE80211_RC_BW_CHANGED); |
| 1228 | } |
| 1229 | |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1230 | goto out; |
| 1231 | } |
| 1232 | |
| 1233 | if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef, |
| 1234 | &sdata->csa_chandef)) { |
Arik Nemtsov | 7578d57 | 2013-09-01 17:15:51 +0300 | [diff] [blame] | 1235 | sdata_info(sdata, |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1236 | "failed to finalize channel switch, disconnecting\n"); |
Arik Nemtsov | 7578d57 | 2013-09-01 17:15:51 +0300 | [diff] [blame] | 1237 | ieee80211_queue_work(&sdata->local->hw, |
| 1238 | &ifmgd->csa_connection_drop_work); |
| 1239 | goto out; |
| 1240 | } |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 1241 | |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 1242 | ifmgd->csa_waiting_bcn = true; |
Luciano Coelho | f1d6558 | 2014-10-08 09:48:38 +0300 | [diff] [blame] | 1243 | |
Michal Kazior | e5593f5 | 2014-04-09 15:45:36 +0200 | [diff] [blame] | 1244 | ieee80211_sta_reset_beacon_monitor(sdata); |
| 1245 | ieee80211_sta_reset_conn_monitor(sdata); |
| 1246 | |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 1247 | out: |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1248 | mutex_unlock(&local->chanctx_mtx); |
| 1249 | mutex_unlock(&local->mtx); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 1250 | sdata_unlock(sdata); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1251 | } |
| 1252 | |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 1253 | static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data *sdata) |
| 1254 | { |
| 1255 | struct ieee80211_local *local = sdata->local; |
| 1256 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 1257 | int ret; |
| 1258 | |
| 1259 | sdata_assert_lock(sdata); |
| 1260 | |
| 1261 | WARN_ON(!sdata->vif.csa_active); |
| 1262 | |
| 1263 | if (sdata->csa_block_tx) { |
| 1264 | ieee80211_wake_vif_queues(local, sdata, |
| 1265 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 1266 | sdata->csa_block_tx = false; |
| 1267 | } |
| 1268 | |
| 1269 | sdata->vif.csa_active = false; |
| 1270 | ifmgd->csa_waiting_bcn = false; |
| 1271 | |
| 1272 | ret = drv_post_channel_switch(sdata); |
| 1273 | if (ret) { |
| 1274 | sdata_info(sdata, |
| 1275 | "driver post channel switch failed, disconnecting\n"); |
| 1276 | ieee80211_queue_work(&local->hw, |
| 1277 | &ifmgd->csa_connection_drop_work); |
| 1278 | return; |
| 1279 | } |
Luciano Coelho | 688b1ec | 2014-12-16 16:01:39 +0200 | [diff] [blame] | 1280 | |
| 1281 | cfg80211_ch_switch_notify(sdata->dev, &sdata->reserved_chandef); |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 1282 | } |
| 1283 | |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1284 | void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success) |
| 1285 | { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1286 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 1287 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1288 | |
| 1289 | trace_api_chswitch_done(sdata, success); |
| 1290 | if (!success) { |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 1291 | sdata_info(sdata, |
| 1292 | "driver channel switch failed, disconnecting\n"); |
| 1293 | ieee80211_queue_work(&sdata->local->hw, |
| 1294 | &ifmgd->csa_connection_drop_work); |
| 1295 | } else { |
| 1296 | ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1297 | } |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1298 | } |
| 1299 | EXPORT_SYMBOL(ieee80211_chswitch_done); |
| 1300 | |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 1301 | static void ieee80211_chswitch_timer(struct timer_list *t) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1302 | { |
| 1303 | struct ieee80211_sub_if_data *sdata = |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 1304 | from_timer(sdata, t, u.mgd.chswitch_timer); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1305 | |
Stanislaw Gruszka | 9b7d72c | 2013-02-28 10:55:27 +0100 | [diff] [blame] | 1306 | ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1307 | } |
| 1308 | |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 1309 | static void |
Sara Sharon | b9cc81d | 2019-02-06 13:17:10 +0200 | [diff] [blame] | 1310 | ieee80211_sta_abort_chanswitch(struct ieee80211_sub_if_data *sdata) |
| 1311 | { |
| 1312 | struct ieee80211_local *local = sdata->local; |
| 1313 | |
| 1314 | if (!local->ops->abort_channel_switch) |
| 1315 | return; |
| 1316 | |
| 1317 | mutex_lock(&local->mtx); |
| 1318 | |
| 1319 | mutex_lock(&local->chanctx_mtx); |
| 1320 | ieee80211_vif_unreserve_chanctx(sdata); |
| 1321 | mutex_unlock(&local->chanctx_mtx); |
| 1322 | |
| 1323 | if (sdata->csa_block_tx) |
| 1324 | ieee80211_wake_vif_queues(local, sdata, |
| 1325 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 1326 | |
| 1327 | sdata->csa_block_tx = false; |
| 1328 | sdata->vif.csa_active = false; |
| 1329 | |
| 1330 | mutex_unlock(&local->mtx); |
| 1331 | |
| 1332 | drv_abort_channel_switch(sdata); |
| 1333 | } |
| 1334 | |
| 1335 | static void |
Johannes Berg | 4a3cb70 | 2013-02-12 16:43:19 +0100 | [diff] [blame] | 1336 | ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata, |
Luciano Coelho | 2ba4538 | 2014-10-08 09:48:35 +0300 | [diff] [blame] | 1337 | u64 timestamp, u32 device_timestamp, |
| 1338 | struct ieee802_11_elems *elems, |
Johannes Berg | 04a161f | 2013-05-03 09:35:35 +0200 | [diff] [blame] | 1339 | bool beacon) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1340 | { |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1341 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1342 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 1343 | struct cfg80211_bss *cbss = ifmgd->associated; |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1344 | struct ieee80211_chanctx_conf *conf; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1345 | struct ieee80211_chanctx *chanctx; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1346 | enum nl80211_band current_band; |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1347 | struct ieee80211_csa_ie csa_ie; |
Luciano Coelho | 6d027bc | 2014-10-08 09:48:37 +0300 | [diff] [blame] | 1348 | struct ieee80211_channel_switch ch_switch; |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 1349 | struct ieee80211_bss *bss; |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 1350 | int res; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1351 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 1352 | sdata_assert_lock(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1353 | |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 1354 | if (!cbss) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1355 | return; |
| 1356 | |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1357 | if (local->scanning) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1358 | return; |
| 1359 | |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 1360 | current_band = cbss->channel->band; |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 1361 | bss = (void *)cbss->priv; |
Luciano Coelho | 84469a4 | 2014-10-28 13:33:04 +0200 | [diff] [blame] | 1362 | res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band, |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 1363 | bss->vht_cap_info, |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 1364 | ifmgd->flags, |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1365 | ifmgd->associated->bssid, &csa_ie); |
Sara Sharon | fafd2bc | 2019-02-06 13:17:15 +0200 | [diff] [blame] | 1366 | |
| 1367 | if (!res) { |
| 1368 | ch_switch.timestamp = timestamp; |
| 1369 | ch_switch.device_timestamp = device_timestamp; |
Sara Sharon | 2bf973f | 2020-01-31 13:12:51 +0200 | [diff] [blame] | 1370 | ch_switch.block_tx = csa_ie.mode; |
Sara Sharon | fafd2bc | 2019-02-06 13:17:15 +0200 | [diff] [blame] | 1371 | ch_switch.chandef = csa_ie.chandef; |
| 1372 | ch_switch.count = csa_ie.count; |
| 1373 | ch_switch.delay = csa_ie.max_switch_time; |
| 1374 | } |
| 1375 | |
Sara Sharon | b9cc81d | 2019-02-06 13:17:10 +0200 | [diff] [blame] | 1376 | if (res < 0) { |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1377 | ieee80211_queue_work(&local->hw, |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 1378 | &ifmgd->csa_connection_drop_work); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1379 | return; |
Sara Sharon | b9cc81d | 2019-02-06 13:17:10 +0200 | [diff] [blame] | 1380 | } |
| 1381 | |
Sara Sharon | fafd2bc | 2019-02-06 13:17:15 +0200 | [diff] [blame] | 1382 | if (beacon && sdata->vif.csa_active && !ifmgd->csa_waiting_bcn) { |
| 1383 | if (res) |
| 1384 | ieee80211_sta_abort_chanswitch(sdata); |
| 1385 | else |
| 1386 | drv_channel_switch_rx_beacon(sdata, &ch_switch); |
Sara Sharon | b9cc81d | 2019-02-06 13:17:10 +0200 | [diff] [blame] | 1387 | return; |
| 1388 | } else if (sdata->vif.csa_active || res) { |
| 1389 | /* disregard subsequent announcements if already processing */ |
| 1390 | return; |
| 1391 | } |
Johannes Berg | cd64f2a | 2013-03-28 10:44:18 +0100 | [diff] [blame] | 1392 | |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1393 | if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef, |
Johannes Berg | 85220d7 | 2013-03-25 18:29:27 +0100 | [diff] [blame] | 1394 | IEEE80211_CHAN_DISABLED)) { |
| 1395 | sdata_info(sdata, |
Thomas Pedersen | b6011960 | 2020-04-01 18:18:04 -0700 | [diff] [blame] | 1396 | "AP %pM switches to unsupported channel " |
| 1397 | "(%d.%03d MHz, width:%d, CF1/2: %d.%03d/%d MHz), " |
| 1398 | "disconnecting\n", |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 1399 | ifmgd->associated->bssid, |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1400 | csa_ie.chandef.chan->center_freq, |
Thomas Pedersen | b6011960 | 2020-04-01 18:18:04 -0700 | [diff] [blame] | 1401 | csa_ie.chandef.chan->freq_offset, |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1402 | csa_ie.chandef.width, csa_ie.chandef.center_freq1, |
Thomas Pedersen | b6011960 | 2020-04-01 18:18:04 -0700 | [diff] [blame] | 1403 | csa_ie.chandef.freq1_offset, |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1404 | csa_ie.chandef.center_freq2); |
Johannes Berg | 85220d7 | 2013-03-25 18:29:27 +0100 | [diff] [blame] | 1405 | ieee80211_queue_work(&local->hw, |
| 1406 | &ifmgd->csa_connection_drop_work); |
| 1407 | return; |
| 1408 | } |
| 1409 | |
Johannes Berg | f84eaa1 | 2015-03-12 08:53:26 +0200 | [diff] [blame] | 1410 | if (cfg80211_chandef_identical(&csa_ie.chandef, |
Sara Sharon | 9792875 | 2019-02-06 13:17:16 +0200 | [diff] [blame] | 1411 | &sdata->vif.bss_conf.chandef) && |
| 1412 | (!csa_ie.mode || !beacon)) { |
Johannes Berg | f84eaa1 | 2015-03-12 08:53:26 +0200 | [diff] [blame] | 1413 | if (ifmgd->csa_ignored_same_chan) |
| 1414 | return; |
| 1415 | sdata_info(sdata, |
| 1416 | "AP %pM tries to chanswitch to same channel, ignore\n", |
| 1417 | ifmgd->associated->bssid); |
| 1418 | ifmgd->csa_ignored_same_chan = true; |
| 1419 | return; |
| 1420 | } |
| 1421 | |
Arik Nemtsov | c5a7168 | 2015-05-19 14:36:48 +0300 | [diff] [blame] | 1422 | /* |
| 1423 | * Drop all TDLS peers - either we disconnect or move to a different |
| 1424 | * channel from this point on. There's no telling what our peer will do. |
| 1425 | * The TDLS WIDER_BW scenario is also problematic, as peers might now |
| 1426 | * have an incompatible wider chandef. |
| 1427 | */ |
| 1428 | ieee80211_teardown_tdls_peers(sdata); |
| 1429 | |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1430 | mutex_lock(&local->mtx); |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1431 | mutex_lock(&local->chanctx_mtx); |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1432 | conf = rcu_dereference_protected(sdata->vif.chanctx_conf, |
| 1433 | lockdep_is_held(&local->chanctx_mtx)); |
| 1434 | if (!conf) { |
| 1435 | sdata_info(sdata, |
| 1436 | "no channel context assigned to vif?, disconnecting\n"); |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1437 | goto drop_connection; |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | chanctx = container_of(conf, struct ieee80211_chanctx, conf); |
| 1441 | |
Luciano Coelho | 0f791eb4 | 2014-10-08 09:48:40 +0300 | [diff] [blame] | 1442 | if (local->use_chanctx && |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1443 | !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) { |
Luciano Coelho | 0f791eb4 | 2014-10-08 09:48:40 +0300 | [diff] [blame] | 1444 | sdata_info(sdata, |
| 1445 | "driver doesn't support chan-switch with channel contexts\n"); |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1446 | goto drop_connection; |
Arik Nemtsov | 7578d57 | 2013-09-01 17:15:51 +0300 | [diff] [blame] | 1447 | } |
| 1448 | |
Luciano Coelho | 6d027bc | 2014-10-08 09:48:37 +0300 | [diff] [blame] | 1449 | if (drv_pre_channel_switch(sdata, &ch_switch)) { |
| 1450 | sdata_info(sdata, |
| 1451 | "preparing for channel switch failed, disconnecting\n"); |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1452 | goto drop_connection; |
Luciano Coelho | 6d027bc | 2014-10-08 09:48:37 +0300 | [diff] [blame] | 1453 | } |
| 1454 | |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1455 | res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef, |
| 1456 | chanctx->mode, false); |
| 1457 | if (res) { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1458 | sdata_info(sdata, |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1459 | "failed to reserve channel context for channel switch, disconnecting (err=%d)\n", |
| 1460 | res); |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1461 | goto drop_connection; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1462 | } |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1463 | mutex_unlock(&local->chanctx_mtx); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1464 | |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 1465 | sdata->vif.csa_active = true; |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1466 | sdata->csa_chandef = csa_ie.chandef; |
Sara Sharon | 2bf973f | 2020-01-31 13:12:51 +0200 | [diff] [blame] | 1467 | sdata->csa_block_tx = csa_ie.mode; |
Johannes Berg | f84eaa1 | 2015-03-12 08:53:26 +0200 | [diff] [blame] | 1468 | ifmgd->csa_ignored_same_chan = false; |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 1469 | |
| 1470 | if (sdata->csa_block_tx) |
Luciano Coelho | a46992b | 2014-06-13 16:30:07 +0300 | [diff] [blame] | 1471 | ieee80211_stop_vif_queues(local, sdata, |
| 1472 | IEEE80211_QUEUE_STOP_REASON_CSA); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 1473 | mutex_unlock(&local->mtx); |
Johannes Berg | 57eebdf | 2012-08-01 15:50:46 +0200 | [diff] [blame] | 1474 | |
Luciano Coelho | 2f45729 | 2014-11-07 14:31:36 +0200 | [diff] [blame] | 1475 | cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef, |
| 1476 | csa_ie.count); |
| 1477 | |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1478 | if (local->ops->channel_switch) { |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1479 | /* use driver's channel switch callback */ |
Luciano Coelho | 0f791eb4 | 2014-10-08 09:48:40 +0300 | [diff] [blame] | 1480 | drv_channel_switch(local, sdata, &ch_switch); |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1481 | return; |
| 1482 | } |
| 1483 | |
| 1484 | /* channel switch handled in software */ |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1485 | if (csa_ie.count <= 1) |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1486 | ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work); |
Johannes Berg | 57eebdf | 2012-08-01 15:50:46 +0200 | [diff] [blame] | 1487 | else |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1488 | mod_timer(&ifmgd->chswitch_timer, |
Luciano Coelho | ff1e417 | 2014-10-28 13:33:05 +0200 | [diff] [blame] | 1489 | TU_TO_EXP_TIME((csa_ie.count - 1) * |
| 1490 | cbss->beacon_interval)); |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1491 | return; |
| 1492 | drop_connection: |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 1493 | /* |
| 1494 | * This is just so that the disconnect flow will know that |
| 1495 | * we were trying to switch channel and failed. In case the |
| 1496 | * mode is 1 (we are not allowed to Tx), we will know not to |
| 1497 | * send a deauthentication frame. Those two fields will be |
| 1498 | * reset when the disconnection worker runs. |
| 1499 | */ |
| 1500 | sdata->vif.csa_active = true; |
Sara Sharon | 2bf973f | 2020-01-31 13:12:51 +0200 | [diff] [blame] | 1501 | sdata->csa_block_tx = csa_ie.mode; |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 1502 | |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1503 | ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work); |
| 1504 | mutex_unlock(&local->chanctx_mtx); |
| 1505 | mutex_unlock(&local->mtx); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1506 | } |
| 1507 | |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1508 | static bool |
| 1509 | ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata, |
| 1510 | struct ieee80211_channel *channel, |
| 1511 | const u8 *country_ie, u8 country_ie_len, |
| 1512 | const u8 *pwr_constr_elem, |
| 1513 | int *chan_pwr, int *pwr_reduction) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1514 | { |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1515 | struct ieee80211_country_ie_triplet *triplet; |
| 1516 | int chan = ieee80211_frequency_to_channel(channel->center_freq); |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1517 | int i, chan_increment; |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1518 | bool have_chan_pwr = false; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1519 | |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1520 | /* Invalid IE */ |
| 1521 | 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] | 1522 | return false; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1523 | |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1524 | triplet = (void *)(country_ie + 3); |
| 1525 | country_ie_len -= 3; |
| 1526 | |
| 1527 | switch (channel->band) { |
| 1528 | default: |
| 1529 | WARN_ON_ONCE(1); |
| 1530 | /* fall through */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1531 | case NL80211_BAND_2GHZ: |
| 1532 | case NL80211_BAND_60GHZ: |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1533 | chan_increment = 1; |
| 1534 | break; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1535 | case NL80211_BAND_5GHZ: |
Ilan Peer | 6fcb56c | 2020-05-28 21:34:45 +0200 | [diff] [blame^] | 1536 | case NL80211_BAND_6GHZ: |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1537 | chan_increment = 4; |
| 1538 | break; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1539 | } |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1540 | |
| 1541 | /* find channel */ |
| 1542 | while (country_ie_len >= 3) { |
| 1543 | u8 first_channel = triplet->chans.first_channel; |
| 1544 | |
| 1545 | if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID) |
| 1546 | goto next; |
| 1547 | |
| 1548 | for (i = 0; i < triplet->chans.num_channels; i++) { |
| 1549 | if (first_channel + i * chan_increment == chan) { |
| 1550 | have_chan_pwr = true; |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1551 | *chan_pwr = triplet->chans.max_power; |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1552 | break; |
| 1553 | } |
| 1554 | } |
| 1555 | if (have_chan_pwr) |
| 1556 | break; |
| 1557 | |
| 1558 | next: |
| 1559 | triplet++; |
| 1560 | country_ie_len -= 3; |
| 1561 | } |
| 1562 | |
Moshe Benji | a5fee9c | 2014-12-14 11:05:50 +0200 | [diff] [blame] | 1563 | if (have_chan_pwr && pwr_constr_elem) |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1564 | *pwr_reduction = *pwr_constr_elem; |
Moshe Benji | a5fee9c | 2014-12-14 11:05:50 +0200 | [diff] [blame] | 1565 | else |
| 1566 | *pwr_reduction = 0; |
| 1567 | |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1568 | return have_chan_pwr; |
| 1569 | } |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1570 | |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1571 | static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata, |
| 1572 | struct ieee80211_channel *channel, |
| 1573 | const u8 *cisco_dtpc_ie, |
| 1574 | int *pwr_level) |
| 1575 | { |
| 1576 | /* From practical testing, the first data byte of the DTPC element |
| 1577 | * seems to contain the requested dBm level, and the CLI on Cisco |
| 1578 | * APs clearly state the range is -127 to 127 dBm, which indicates |
| 1579 | * a signed byte, although it seemingly never actually goes negative. |
| 1580 | * The other byte seems to always be zero. |
| 1581 | */ |
| 1582 | *pwr_level = (__s8)cisco_dtpc_ie[4]; |
| 1583 | } |
| 1584 | |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1585 | static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata, |
| 1586 | struct ieee80211_channel *channel, |
| 1587 | struct ieee80211_mgmt *mgmt, |
| 1588 | const u8 *country_ie, u8 country_ie_len, |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1589 | const u8 *pwr_constr_ie, |
| 1590 | const u8 *cisco_dtpc_ie) |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1591 | { |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1592 | bool has_80211h_pwr = false, has_cisco_pwr = false; |
| 1593 | int chan_pwr = 0, pwr_reduction_80211h = 0; |
| 1594 | int pwr_level_cisco, pwr_level_80211h; |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1595 | int new_ap_level; |
Moshe Benji | a5fee9c | 2014-12-14 11:05:50 +0200 | [diff] [blame] | 1596 | __le16 capab = mgmt->u.probe_resp.capab_info; |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1597 | |
Moshe Benji | a5fee9c | 2014-12-14 11:05:50 +0200 | [diff] [blame] | 1598 | if (country_ie && |
| 1599 | (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) || |
| 1600 | capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) { |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1601 | has_80211h_pwr = ieee80211_find_80211h_pwr_constr( |
| 1602 | sdata, channel, country_ie, country_ie_len, |
| 1603 | pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h); |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1604 | pwr_level_80211h = |
| 1605 | max_t(int, 0, chan_pwr - pwr_reduction_80211h); |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1606 | } |
| 1607 | |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1608 | if (cisco_dtpc_ie) { |
| 1609 | ieee80211_find_cisco_dtpc( |
| 1610 | sdata, channel, cisco_dtpc_ie, &pwr_level_cisco); |
| 1611 | has_cisco_pwr = true; |
| 1612 | } |
| 1613 | |
| 1614 | if (!has_80211h_pwr && !has_cisco_pwr) |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1615 | return 0; |
| 1616 | |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1617 | /* If we have both 802.11h and Cisco DTPC, apply both limits |
| 1618 | * by picking the smallest of the two power levels advertised. |
| 1619 | */ |
| 1620 | if (has_80211h_pwr && |
| 1621 | (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) { |
Johannes Berg | a87da0c | 2015-12-08 16:04:37 +0200 | [diff] [blame] | 1622 | new_ap_level = pwr_level_80211h; |
| 1623 | |
| 1624 | if (sdata->ap_power_level == new_ap_level) |
| 1625 | return 0; |
| 1626 | |
John Linville | cef2fc1 | 2015-03-31 10:49:14 -0400 | [diff] [blame] | 1627 | sdata_dbg(sdata, |
| 1628 | "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n", |
| 1629 | pwr_level_80211h, chan_pwr, pwr_reduction_80211h, |
| 1630 | sdata->u.mgd.bssid); |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1631 | } else { /* has_cisco_pwr is always true here. */ |
Johannes Berg | a87da0c | 2015-12-08 16:04:37 +0200 | [diff] [blame] | 1632 | new_ap_level = pwr_level_cisco; |
| 1633 | |
| 1634 | if (sdata->ap_power_level == new_ap_level) |
| 1635 | return 0; |
| 1636 | |
John Linville | cef2fc1 | 2015-03-31 10:49:14 -0400 | [diff] [blame] | 1637 | sdata_dbg(sdata, |
| 1638 | "Limiting TX power to %d dBm as advertised by %pM\n", |
| 1639 | pwr_level_cisco, sdata->u.mgd.bssid); |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1640 | } |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1641 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 1642 | sdata->ap_power_level = new_ap_level; |
| 1643 | if (__ieee80211_recalc_txpower(sdata)) |
| 1644 | return BSS_CHANGED_TXPOWER; |
| 1645 | return 0; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1646 | } |
| 1647 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1648 | /* powersave */ |
| 1649 | static void ieee80211_enable_ps(struct ieee80211_local *local, |
| 1650 | struct ieee80211_sub_if_data *sdata) |
| 1651 | { |
| 1652 | struct ieee80211_conf *conf = &local->hw.conf; |
| 1653 | |
Johannes Berg | d5edaed | 2009-04-22 23:02:51 +0200 | [diff] [blame] | 1654 | /* |
| 1655 | * If we are scanning right now then the parameters will |
| 1656 | * take effect when scan finishes. |
| 1657 | */ |
Helmut Schaa | fbe9c429 | 2009-07-23 12:14:04 +0200 | [diff] [blame] | 1658 | if (local->scanning) |
Johannes Berg | d5edaed | 2009-04-22 23:02:51 +0200 | [diff] [blame] | 1659 | return; |
| 1660 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1661 | if (conf->dynamic_ps_timeout > 0 && |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1662 | !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1663 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 1664 | msecs_to_jiffies(conf->dynamic_ps_timeout)); |
| 1665 | } else { |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1666 | if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) |
Johannes Berg | 076cdcb | 2015-09-24 16:14:55 +0200 | [diff] [blame] | 1667 | ieee80211_send_nullfunc(local, sdata, true); |
Vivek Natarajan | 375177b | 2010-02-09 14:50:28 +0530 | [diff] [blame] | 1668 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1669 | if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) && |
| 1670 | ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
Juuso Oikarinen | 2a13052 | 2010-03-09 14:25:02 +0200 | [diff] [blame] | 1671 | return; |
| 1672 | |
| 1673 | conf->flags |= IEEE80211_CONF_PS; |
| 1674 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1675 | } |
| 1676 | } |
| 1677 | |
| 1678 | static void ieee80211_change_ps(struct ieee80211_local *local) |
| 1679 | { |
| 1680 | struct ieee80211_conf *conf = &local->hw.conf; |
| 1681 | |
| 1682 | if (local->ps_sdata) { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1683 | ieee80211_enable_ps(local, local->ps_sdata); |
| 1684 | } else if (conf->flags & IEEE80211_CONF_PS) { |
| 1685 | conf->flags &= ~IEEE80211_CONF_PS; |
| 1686 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 1687 | del_timer_sync(&local->dynamic_ps_timer); |
| 1688 | cancel_work_sync(&local->dynamic_ps_enable_work); |
| 1689 | } |
| 1690 | } |
| 1691 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1692 | static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata) |
| 1693 | { |
| 1694 | struct ieee80211_if_managed *mgd = &sdata->u.mgd; |
| 1695 | struct sta_info *sta = NULL; |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1696 | bool authorized = false; |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1697 | |
| 1698 | if (!mgd->powersave) |
| 1699 | return false; |
| 1700 | |
Johannes Berg | 05cb910 | 2011-10-28 11:59:47 +0200 | [diff] [blame] | 1701 | if (mgd->broken_ap) |
| 1702 | return false; |
| 1703 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1704 | if (!mgd->associated) |
| 1705 | return false; |
| 1706 | |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 1707 | if (mgd->flags & IEEE80211_STA_CONNECTION_POLL) |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1708 | return false; |
| 1709 | |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 1710 | if (!mgd->have_beacon) |
Alexander Bondar | ce85788 | 2013-05-06 17:17:04 +0300 | [diff] [blame] | 1711 | return false; |
| 1712 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1713 | rcu_read_lock(); |
| 1714 | sta = sta_info_get(sdata, mgd->bssid); |
| 1715 | if (sta) |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1716 | authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED); |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1717 | rcu_read_unlock(); |
| 1718 | |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1719 | return authorized; |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1720 | } |
| 1721 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1722 | /* need to hold RTNL or interface lock */ |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 1723 | void ieee80211_recalc_ps(struct ieee80211_local *local) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1724 | { |
| 1725 | struct ieee80211_sub_if_data *sdata, *found = NULL; |
| 1726 | int count = 0; |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 1727 | int timeout; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1728 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1729 | if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1730 | local->ps_sdata = NULL; |
| 1731 | return; |
| 1732 | } |
| 1733 | |
| 1734 | list_for_each_entry(sdata, &local->interfaces, list) { |
Johannes Berg | 9607e6b66 | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 1735 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1736 | continue; |
Rajkumar Manoharan | 8c7914d | 2011-02-01 00:28:59 +0530 | [diff] [blame] | 1737 | if (sdata->vif.type == NL80211_IFTYPE_AP) { |
| 1738 | /* If an AP vif is found, then disable PS |
| 1739 | * by setting the count to zero thereby setting |
| 1740 | * ps_sdata to NULL. |
| 1741 | */ |
| 1742 | count = 0; |
| 1743 | break; |
| 1744 | } |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1745 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 1746 | continue; |
| 1747 | found = sdata; |
| 1748 | count++; |
| 1749 | } |
| 1750 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1751 | if (count == 1 && ieee80211_powersave_allowed(found)) { |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 1752 | u8 dtimper = found->u.mgd.dtim_period; |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1753 | |
Juuso Oikarinen | ff61638 | 2010-06-09 09:51:52 +0300 | [diff] [blame] | 1754 | timeout = local->dynamic_ps_forced_timeout; |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 1755 | if (timeout < 0) |
| 1756 | timeout = 100; |
Johannes Berg | 09b8556 | 2013-02-06 23:07:41 +0100 | [diff] [blame] | 1757 | local->hw.conf.dynamic_ps_timeout = timeout; |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 1758 | |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 1759 | /* If the TIM IE is invalid, pretend the value is 1 */ |
| 1760 | if (!dtimper) |
| 1761 | dtimper = 1; |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 1762 | |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 1763 | local->hw.conf.ps_dtim_period = dtimper; |
| 1764 | local->ps_sdata = found; |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1765 | } else { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1766 | local->ps_sdata = NULL; |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1767 | } |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1768 | |
| 1769 | ieee80211_change_ps(local); |
| 1770 | } |
| 1771 | |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 1772 | void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata) |
| 1773 | { |
| 1774 | bool ps_allowed = ieee80211_powersave_allowed(sdata); |
| 1775 | |
| 1776 | if (sdata->vif.bss_conf.ps != ps_allowed) { |
| 1777 | sdata->vif.bss_conf.ps = ps_allowed; |
| 1778 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS); |
| 1779 | } |
| 1780 | } |
| 1781 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1782 | void ieee80211_dynamic_ps_disable_work(struct work_struct *work) |
| 1783 | { |
| 1784 | struct ieee80211_local *local = |
| 1785 | container_of(work, struct ieee80211_local, |
| 1786 | dynamic_ps_disable_work); |
| 1787 | |
| 1788 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 1789 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 1790 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 1791 | } |
| 1792 | |
| 1793 | ieee80211_wake_queues_by_reason(&local->hw, |
Johannes Berg | 445ea4e | 2013-02-13 12:25:28 +0100 | [diff] [blame] | 1794 | IEEE80211_MAX_QUEUE_MAP, |
Luciano Coelho | cca07b0 | 2014-06-13 16:30:05 +0300 | [diff] [blame] | 1795 | IEEE80211_QUEUE_STOP_REASON_PS, |
| 1796 | false); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | void ieee80211_dynamic_ps_enable_work(struct work_struct *work) |
| 1800 | { |
| 1801 | struct ieee80211_local *local = |
| 1802 | container_of(work, struct ieee80211_local, |
| 1803 | dynamic_ps_enable_work); |
| 1804 | struct ieee80211_sub_if_data *sdata = local->ps_sdata; |
Christian Lamparter | 5e34069 | 2011-06-30 21:08:43 +0200 | [diff] [blame] | 1805 | struct ieee80211_if_managed *ifmgd; |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1806 | unsigned long flags; |
| 1807 | int q; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1808 | |
| 1809 | /* can only happen when PS was just disabled anyway */ |
| 1810 | if (!sdata) |
| 1811 | return; |
| 1812 | |
Christian Lamparter | 5e34069 | 2011-06-30 21:08:43 +0200 | [diff] [blame] | 1813 | ifmgd = &sdata->u.mgd; |
| 1814 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1815 | if (local->hw.conf.flags & IEEE80211_CONF_PS) |
| 1816 | return; |
| 1817 | |
Johannes Berg | 09b8556 | 2013-02-06 23:07:41 +0100 | [diff] [blame] | 1818 | if (local->hw.conf.dynamic_ps_timeout > 0) { |
Arik Nemtsov | 77b7023 | 2011-06-26 12:06:54 +0300 | [diff] [blame] | 1819 | /* don't enter PS if TX frames are pending */ |
| 1820 | if (drv_tx_frames_pending(local)) { |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1821 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 1822 | msecs_to_jiffies( |
| 1823 | local->hw.conf.dynamic_ps_timeout)); |
| 1824 | return; |
| 1825 | } |
Arik Nemtsov | 77b7023 | 2011-06-26 12:06:54 +0300 | [diff] [blame] | 1826 | |
| 1827 | /* |
| 1828 | * transmission can be stopped by others which leads to |
| 1829 | * dynamic_ps_timer expiry. Postpone the ps timer if it |
| 1830 | * is not the actual idle state. |
| 1831 | */ |
| 1832 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 1833 | for (q = 0; q < local->hw.queues; q++) { |
| 1834 | if (local->queue_stop_reasons[q]) { |
| 1835 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, |
| 1836 | flags); |
| 1837 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 1838 | msecs_to_jiffies( |
| 1839 | local->hw.conf.dynamic_ps_timeout)); |
| 1840 | return; |
| 1841 | } |
| 1842 | } |
| 1843 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1844 | } |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1845 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1846 | if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) && |
Mohammed Shafi Shajakhan | 9c38a8b | 2011-12-14 19:46:07 +0530 | [diff] [blame] | 1847 | !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) { |
Johannes Berg | a159838 | 2013-03-26 22:02:42 +0100 | [diff] [blame] | 1848 | if (drv_tx_frames_pending(local)) { |
Vivek Natarajan | e8306f9 | 2011-04-06 11:41:10 +0530 | [diff] [blame] | 1849 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 1850 | msecs_to_jiffies( |
| 1851 | local->hw.conf.dynamic_ps_timeout)); |
Johannes Berg | a159838 | 2013-03-26 22:02:42 +0100 | [diff] [blame] | 1852 | } else { |
Johannes Berg | 076cdcb | 2015-09-24 16:14:55 +0200 | [diff] [blame] | 1853 | ieee80211_send_nullfunc(local, sdata, true); |
Vivek Natarajan | e8306f9 | 2011-04-06 11:41:10 +0530 | [diff] [blame] | 1854 | /* Flush to get the tx status of nullfunc frame */ |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 1855 | ieee80211_flush_queues(local, sdata, false); |
Vivek Natarajan | e8306f9 | 2011-04-06 11:41:10 +0530 | [diff] [blame] | 1856 | } |
Vivek Natarajan | f3e85b9 | 2011-02-23 13:04:32 +0530 | [diff] [blame] | 1857 | } |
| 1858 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1859 | if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) && |
| 1860 | ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) || |
Vivek Natarajan | 375177b | 2010-02-09 14:50:28 +0530 | [diff] [blame] | 1861 | (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) { |
| 1862 | ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED; |
| 1863 | local->hw.conf.flags |= IEEE80211_CONF_PS; |
| 1864 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 1865 | } |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1866 | } |
| 1867 | |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 1868 | void ieee80211_dynamic_ps_timer(struct timer_list *t) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1869 | { |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 1870 | struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1871 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 1872 | ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1873 | } |
| 1874 | |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 1875 | void ieee80211_dfs_cac_timer_work(struct work_struct *work) |
| 1876 | { |
Geliang Tang | a85a7e2 | 2016-01-01 23:48:52 +0800 | [diff] [blame] | 1877 | struct delayed_work *delayed_work = to_delayed_work(work); |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 1878 | struct ieee80211_sub_if_data *sdata = |
| 1879 | container_of(delayed_work, struct ieee80211_sub_if_data, |
| 1880 | dfs_cac_timer_work); |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 1881 | struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef; |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 1882 | |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 1883 | mutex_lock(&sdata->local->mtx); |
| 1884 | if (sdata->wdev.cac_started) { |
| 1885 | ieee80211_vif_release_channel(sdata); |
| 1886 | cfg80211_cac_event(sdata->dev, &chandef, |
| 1887 | NL80211_RADAR_CAC_FINISHED, |
| 1888 | GFP_KERNEL); |
| 1889 | } |
| 1890 | mutex_unlock(&sdata->local->mtx); |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 1891 | } |
| 1892 | |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 1893 | static bool |
| 1894 | __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata) |
| 1895 | { |
| 1896 | struct ieee80211_local *local = sdata->local; |
| 1897 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
John Linville | cc72f6e | 2015-01-06 14:39:33 -0500 | [diff] [blame] | 1898 | bool ret = false; |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 1899 | int ac; |
| 1900 | |
| 1901 | if (local->hw.queues < IEEE80211_NUM_ACS) |
| 1902 | return false; |
| 1903 | |
| 1904 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 1905 | struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac]; |
| 1906 | int non_acm_ac; |
| 1907 | unsigned long now = jiffies; |
| 1908 | |
| 1909 | if (tx_tspec->action == TX_TSPEC_ACTION_NONE && |
| 1910 | tx_tspec->admitted_time && |
| 1911 | time_after(now, tx_tspec->time_slice_start + HZ)) { |
| 1912 | tx_tspec->consumed_tx_time = 0; |
| 1913 | tx_tspec->time_slice_start = now; |
| 1914 | |
| 1915 | if (tx_tspec->downgraded) |
| 1916 | tx_tspec->action = |
| 1917 | TX_TSPEC_ACTION_STOP_DOWNGRADE; |
| 1918 | } |
| 1919 | |
| 1920 | switch (tx_tspec->action) { |
| 1921 | case TX_TSPEC_ACTION_STOP_DOWNGRADE: |
| 1922 | /* take the original parameters */ |
| 1923 | if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac])) |
| 1924 | sdata_err(sdata, |
| 1925 | "failed to set TX queue parameters for queue %d\n", |
| 1926 | ac); |
| 1927 | tx_tspec->action = TX_TSPEC_ACTION_NONE; |
| 1928 | tx_tspec->downgraded = false; |
| 1929 | ret = true; |
| 1930 | break; |
| 1931 | case TX_TSPEC_ACTION_DOWNGRADE: |
| 1932 | if (time_after(now, tx_tspec->time_slice_start + HZ)) { |
| 1933 | tx_tspec->action = TX_TSPEC_ACTION_NONE; |
| 1934 | ret = true; |
| 1935 | break; |
| 1936 | } |
| 1937 | /* downgrade next lower non-ACM AC */ |
| 1938 | for (non_acm_ac = ac + 1; |
| 1939 | non_acm_ac < IEEE80211_NUM_ACS; |
| 1940 | non_acm_ac++) |
| 1941 | if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac))) |
| 1942 | break; |
Johannes Berg | 93db1d9 | 2016-09-14 09:23:51 +0200 | [diff] [blame] | 1943 | /* Usually the loop will result in using BK even if it |
| 1944 | * requires admission control, but such a configuration |
| 1945 | * makes no sense and we have to transmit somehow - the |
| 1946 | * AC selection does the same thing. |
| 1947 | * If we started out trying to downgrade from BK, then |
| 1948 | * the extra condition here might be needed. |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 1949 | */ |
Johannes Berg | 93db1d9 | 2016-09-14 09:23:51 +0200 | [diff] [blame] | 1950 | if (non_acm_ac >= IEEE80211_NUM_ACS) |
| 1951 | non_acm_ac = IEEE80211_AC_BK; |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 1952 | if (drv_conf_tx(local, sdata, ac, |
| 1953 | &sdata->tx_conf[non_acm_ac])) |
| 1954 | sdata_err(sdata, |
| 1955 | "failed to set TX queue parameters for queue %d\n", |
| 1956 | ac); |
| 1957 | tx_tspec->action = TX_TSPEC_ACTION_NONE; |
| 1958 | ret = true; |
| 1959 | schedule_delayed_work(&ifmgd->tx_tspec_wk, |
| 1960 | tx_tspec->time_slice_start + HZ - now + 1); |
| 1961 | break; |
| 1962 | case TX_TSPEC_ACTION_NONE: |
| 1963 | /* nothing now */ |
| 1964 | break; |
| 1965 | } |
| 1966 | } |
| 1967 | |
| 1968 | return ret; |
| 1969 | } |
| 1970 | |
| 1971 | void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata) |
| 1972 | { |
| 1973 | if (__ieee80211_sta_handle_tspec_ac_params(sdata)) |
| 1974 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS); |
| 1975 | } |
| 1976 | |
| 1977 | static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work) |
| 1978 | { |
| 1979 | struct ieee80211_sub_if_data *sdata; |
| 1980 | |
| 1981 | sdata = container_of(work, struct ieee80211_sub_if_data, |
| 1982 | u.mgd.tx_tspec_wk.work); |
| 1983 | ieee80211_sta_handle_tspec_ac_params(sdata); |
| 1984 | } |
| 1985 | |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1986 | /* MLME */ |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 1987 | static bool |
| 1988 | ieee80211_sta_wmm_params(struct ieee80211_local *local, |
| 1989 | struct ieee80211_sub_if_data *sdata, |
| 1990 | const u8 *wmm_param, size_t wmm_param_len, |
| 1991 | const struct ieee80211_mu_edca_param_set *mu_edca) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1992 | { |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 1993 | struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS]; |
Johannes Berg | 4ced3f7 | 2010-07-19 16:39:04 +0200 | [diff] [blame] | 1994 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1995 | size_t left; |
Shaul Triebitz | 2e249fc | 2018-12-15 11:03:15 +0200 | [diff] [blame] | 1996 | int count, mu_edca_count, ac; |
Johannes Berg | 4a3cb70 | 2013-02-12 16:43:19 +0100 | [diff] [blame] | 1997 | const u8 *pos; |
| 1998 | u8 uapsd_queues = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1999 | |
Stanislaw Gruszka | e1b3ec1 | 2010-03-29 12:18:34 +0200 | [diff] [blame] | 2000 | if (!local->ops->conf_tx) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 2001 | return false; |
Stanislaw Gruszka | e1b3ec1 | 2010-03-29 12:18:34 +0200 | [diff] [blame] | 2002 | |
Johannes Berg | 32c5057 | 2012-03-28 11:04:29 +0200 | [diff] [blame] | 2003 | if (local->hw.queues < IEEE80211_NUM_ACS) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 2004 | return false; |
Johannes Berg | 3434fbd | 2008-05-03 00:59:37 +0200 | [diff] [blame] | 2005 | |
| 2006 | if (!wmm_param) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 2007 | return false; |
Johannes Berg | 3434fbd | 2008-05-03 00:59:37 +0200 | [diff] [blame] | 2008 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2009 | if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 2010 | return false; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2011 | |
| 2012 | if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED) |
Eliad Peller | dc41e4d | 2012-03-14 16:15:03 +0200 | [diff] [blame] | 2013 | uapsd_queues = ifmgd->uapsd_queues; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2014 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2015 | count = wmm_param[6] & 0x0f; |
Shaul Triebitz | 2e249fc | 2018-12-15 11:03:15 +0200 | [diff] [blame] | 2016 | /* -1 is the initial value of ifmgd->mu_edca_last_param_set. |
| 2017 | * if mu_edca was preset before and now it disappeared tell |
| 2018 | * the driver about it. |
| 2019 | */ |
| 2020 | mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1; |
| 2021 | if (count == ifmgd->wmm_last_param_set && |
| 2022 | mu_edca_count == ifmgd->mu_edca_last_param_set) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 2023 | return false; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2024 | ifmgd->wmm_last_param_set = count; |
Shaul Triebitz | 2e249fc | 2018-12-15 11:03:15 +0200 | [diff] [blame] | 2025 | ifmgd->mu_edca_last_param_set = mu_edca_count; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2026 | |
| 2027 | pos = wmm_param + 8; |
| 2028 | left = wmm_param_len - 8; |
| 2029 | |
| 2030 | memset(¶ms, 0, sizeof(params)); |
| 2031 | |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 2032 | sdata->wmm_acm = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2033 | for (; left >= 4; left -= 4, pos += 4) { |
| 2034 | int aci = (pos[0] >> 5) & 0x03; |
| 2035 | int acm = (pos[0] >> 4) & 0x01; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2036 | bool uapsd = false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2037 | |
| 2038 | switch (aci) { |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 2039 | case 1: /* AC_BK */ |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2040 | ac = IEEE80211_AC_BK; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 2041 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 2042 | sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2043 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) |
| 2044 | uapsd = true; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 2045 | params[ac].mu_edca = !!mu_edca; |
| 2046 | if (mu_edca) |
| 2047 | params[ac].mu_edca_param_rec = mu_edca->ac_bk; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2048 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 2049 | case 2: /* AC_VI */ |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2050 | ac = IEEE80211_AC_VI; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 2051 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 2052 | sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2053 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) |
| 2054 | uapsd = true; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 2055 | params[ac].mu_edca = !!mu_edca; |
| 2056 | if (mu_edca) |
| 2057 | params[ac].mu_edca_param_rec = mu_edca->ac_vi; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2058 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 2059 | case 3: /* AC_VO */ |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2060 | ac = IEEE80211_AC_VO; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 2061 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 2062 | sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2063 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) |
| 2064 | uapsd = true; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 2065 | params[ac].mu_edca = !!mu_edca; |
| 2066 | if (mu_edca) |
| 2067 | params[ac].mu_edca_param_rec = mu_edca->ac_vo; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2068 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 2069 | case 0: /* AC_BE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2070 | default: |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2071 | ac = IEEE80211_AC_BE; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 2072 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 2073 | sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2074 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) |
| 2075 | uapsd = true; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 2076 | params[ac].mu_edca = !!mu_edca; |
| 2077 | if (mu_edca) |
| 2078 | params[ac].mu_edca_param_rec = mu_edca->ac_be; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2079 | break; |
| 2080 | } |
| 2081 | |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2082 | params[ac].aifs = pos[0] & 0x0f; |
Emmanuel Grumbach | 730a7550 | 2015-10-22 17:46:05 +0200 | [diff] [blame] | 2083 | |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2084 | if (params[ac].aifs < 2) { |
Emmanuel Grumbach | 730a7550 | 2015-10-22 17:46:05 +0200 | [diff] [blame] | 2085 | sdata_info(sdata, |
| 2086 | "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] | 2087 | params[ac].aifs, aci); |
| 2088 | params[ac].aifs = 2; |
Emmanuel Grumbach | 730a7550 | 2015-10-22 17:46:05 +0200 | [diff] [blame] | 2089 | } |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2090 | params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4); |
| 2091 | params[ac].cw_min = ecw2cw(pos[1] & 0x0f); |
| 2092 | params[ac].txop = get_unaligned_le16(pos + 2); |
| 2093 | params[ac].acm = acm; |
| 2094 | params[ac].uapsd = uapsd; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2095 | |
Ilan Peer | 911a264 | 2018-04-03 11:35:22 +0300 | [diff] [blame] | 2096 | if (params[ac].cw_min == 0 || |
Emmanuel Grumbach | c470bdc | 2018-03-26 16:21:04 +0300 | [diff] [blame] | 2097 | params[ac].cw_min > params[ac].cw_max) { |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2098 | sdata_info(sdata, |
| 2099 | "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n", |
| 2100 | params[ac].cw_min, params[ac].cw_max, aci); |
| 2101 | return false; |
| 2102 | } |
Haim Dreyfuss | e552af0 | 2018-03-28 13:24:10 +0300 | [diff] [blame] | 2103 | ieee80211_regulatory_limit_wmm_params(sdata, ¶ms[ac], ac); |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2104 | } |
| 2105 | |
Brian Norris | 05aaa5c | 2019-07-26 15:47:58 -0700 | [diff] [blame] | 2106 | /* WMM specification requires all 4 ACIs. */ |
| 2107 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 2108 | if (params[ac].cw_min == 0) { |
| 2109 | sdata_info(sdata, |
| 2110 | "AP has invalid WMM params (missing AC %d), using defaults\n", |
| 2111 | ac); |
| 2112 | return false; |
| 2113 | } |
| 2114 | } |
| 2115 | |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2116 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2117 | mlme_dbg(sdata, |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2118 | "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n", |
| 2119 | ac, params[ac].acm, |
| 2120 | params[ac].aifs, params[ac].cw_min, params[ac].cw_max, |
| 2121 | params[ac].txop, params[ac].uapsd, |
| 2122 | ifmgd->tx_tspec[ac].downgraded); |
| 2123 | sdata->tx_conf[ac] = params[ac]; |
| 2124 | if (!ifmgd->tx_tspec[ac].downgraded && |
| 2125 | drv_conf_tx(local, sdata, ac, ¶ms[ac])) |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2126 | sdata_err(sdata, |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2127 | "failed to set TX queue parameters for AC %d\n", |
| 2128 | ac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2129 | } |
Stanislaw Gruszka | e1b3ec1 | 2010-03-29 12:18:34 +0200 | [diff] [blame] | 2130 | |
| 2131 | /* enable WMM or activate new settings */ |
Johannes Berg | 4ced3f7 | 2010-07-19 16:39:04 +0200 | [diff] [blame] | 2132 | sdata->vif.bss_conf.qos = true; |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 2133 | return true; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2134 | } |
| 2135 | |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 2136 | static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata) |
| 2137 | { |
| 2138 | lockdep_assert_held(&sdata->local->mtx); |
| 2139 | |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 2140 | sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL; |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 2141 | ieee80211_run_deferred_scan(sdata->local); |
| 2142 | } |
| 2143 | |
| 2144 | static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata) |
| 2145 | { |
| 2146 | mutex_lock(&sdata->local->mtx); |
| 2147 | __ieee80211_stop_poll(sdata); |
| 2148 | mutex_unlock(&sdata->local->mtx); |
| 2149 | } |
| 2150 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2151 | static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata, |
| 2152 | u16 capab, bool erp_valid, u8 erp) |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 2153 | { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 2154 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 2155 | struct ieee80211_supported_band *sband; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2156 | u32 changed = 0; |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2157 | bool use_protection; |
| 2158 | bool use_short_preamble; |
| 2159 | bool use_short_slot; |
| 2160 | |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 2161 | sband = ieee80211_get_sband(sdata); |
| 2162 | if (!sband) |
| 2163 | return changed; |
| 2164 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2165 | if (erp_valid) { |
| 2166 | use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0; |
| 2167 | use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0; |
| 2168 | } else { |
| 2169 | use_protection = false; |
| 2170 | use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE); |
| 2171 | } |
| 2172 | |
| 2173 | use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME); |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 2174 | if (sband->band == NL80211_BAND_5GHZ) |
Felix Fietkau | 43d3534 | 2010-01-15 03:00:48 +0100 | [diff] [blame] | 2175 | use_short_slot = true; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 2176 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2177 | if (use_protection != bss_conf->use_cts_prot) { |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2178 | bss_conf->use_cts_prot = use_protection; |
| 2179 | changed |= BSS_CHANGED_ERP_CTS_PROT; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 2180 | } |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 2181 | |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 2182 | if (use_short_preamble != bss_conf->use_short_preamble) { |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 2183 | bss_conf->use_short_preamble = use_short_preamble; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2184 | changed |= BSS_CHANGED_ERP_PREAMBLE; |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 2185 | } |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 2186 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2187 | if (use_short_slot != bss_conf->use_short_slot) { |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2188 | bss_conf->use_short_slot = use_short_slot; |
| 2189 | changed |= BSS_CHANGED_ERP_SLOT; |
John W. Linville | 50c4afb | 2008-04-15 14:09:27 -0400 | [diff] [blame] | 2190 | } |
| 2191 | |
| 2192 | return changed; |
| 2193 | } |
| 2194 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2195 | static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2196 | struct cfg80211_bss *cbss, |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2197 | u32 bss_info_changed) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2198 | { |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2199 | struct ieee80211_bss *bss = (void *)cbss->priv; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2200 | struct ieee80211_local *local = sdata->local; |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2201 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2202 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2203 | bss_info_changed |= BSS_CHANGED_ASSOC; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2204 | bss_info_changed |= ieee80211_handle_bss_capability(sdata, |
Luciano Coelho | 50ae34a | 2012-06-20 17:23:24 +0300 | [diff] [blame] | 2205 | bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value); |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 2206 | |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 2207 | sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec( |
Ben Greear | 59c1ec2 | 2013-03-19 14:19:56 -0700 | [diff] [blame] | 2208 | beacon_loss_count * bss_conf->beacon_int)); |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 2209 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2210 | sdata->u.mgd.associated = cbss; |
| 2211 | memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2212 | |
Johannes Berg | e8e4f52 | 2017-03-08 11:12:10 +0100 | [diff] [blame] | 2213 | ieee80211_check_rate_mask(sdata); |
| 2214 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 2215 | sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE; |
| 2216 | |
Janusz.Dziedzic@tieto.com | b115b97 | 2015-10-27 08:38:40 +0100 | [diff] [blame] | 2217 | if (sdata->vif.p2p || |
| 2218 | sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2219 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 2220 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2221 | rcu_read_lock(); |
| 2222 | ies = rcu_dereference(cbss->ies); |
| 2223 | if (ies) { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2224 | int ret; |
| 2225 | |
| 2226 | ret = cfg80211_get_p2p_attr( |
| 2227 | ies->data, ies->len, |
| 2228 | IEEE80211_P2P_ATTR_ABSENCE_NOTICE, |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 2229 | (u8 *) &bss_conf->p2p_noa_attr, |
| 2230 | sizeof(bss_conf->p2p_noa_attr)); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2231 | if (ret >= 2) { |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 2232 | sdata->u.mgd.p2p_noa_index = |
| 2233 | bss_conf->p2p_noa_attr.index; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2234 | bss_info_changed |= BSS_CHANGED_P2P_PS; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2235 | } |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 2236 | } |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2237 | rcu_read_unlock(); |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 2238 | } |
| 2239 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2240 | /* just to be sure */ |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 2241 | ieee80211_stop_poll(sdata); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2242 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 2243 | ieee80211_led_assoc(local, 1); |
| 2244 | |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 2245 | if (sdata->u.mgd.have_beacon) { |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 2246 | /* |
| 2247 | * If the AP is buggy we may get here with no DTIM period |
| 2248 | * known, so assume it's 1 which is the only safe assumption |
| 2249 | * in that case, although if the TIM IE is broken powersave |
| 2250 | * probably just won't work at all. |
| 2251 | */ |
| 2252 | bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1; |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 2253 | bss_conf->beacon_rate = bss->beacon_rate; |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 2254 | bss_info_changed |= BSS_CHANGED_BEACON_INFO; |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 2255 | } else { |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 2256 | bss_conf->beacon_rate = NULL; |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 2257 | bss_conf->dtim_period = 0; |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 2258 | } |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 2259 | |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2260 | bss_conf->assoc = 1; |
Johannes Berg | 9cef873 | 2009-05-14 13:10:14 +0200 | [diff] [blame] | 2261 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 2262 | /* Tell the driver to monitor connection quality (if supported) */ |
Johannes Berg | ea08635 | 2012-01-19 09:29:58 +0100 | [diff] [blame] | 2263 | if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI && |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2264 | bss_conf->cqm_rssi_thold) |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 2265 | bss_info_changed |= BSS_CHANGED_CQM; |
| 2266 | |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2267 | /* Enable ARP filtering */ |
Johannes Berg | 0f19b41 | 2013-01-14 16:39:07 +0100 | [diff] [blame] | 2268 | if (bss_conf->arp_addr_cnt) |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2269 | bss_info_changed |= BSS_CHANGED_ARP_FILTER; |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2270 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2271 | ieee80211_bss_info_change_notify(sdata, bss_info_changed); |
Guy Cohen | 8db9369 | 2008-07-03 19:56:13 +0300 | [diff] [blame] | 2272 | |
Johannes Berg | 056508d | 2009-07-30 21:43:55 +0200 | [diff] [blame] | 2273 | mutex_lock(&local->iflist_mtx); |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 2274 | ieee80211_recalc_ps(local); |
Johannes Berg | 056508d | 2009-07-30 21:43:55 +0200 | [diff] [blame] | 2275 | mutex_unlock(&local->iflist_mtx); |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 2276 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 2277 | ieee80211_recalc_smps(sdata); |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 2278 | ieee80211_recalc_ps_vif(sdata); |
| 2279 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 2280 | netif_carrier_on(sdata->dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2281 | } |
| 2282 | |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 2283 | static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2284 | u16 stype, u16 reason, bool tx, |
| 2285 | u8 *frame_buf) |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2286 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2287 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2288 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 3cc5240 | 2012-03-09 13:12:35 +0100 | [diff] [blame] | 2289 | u32 changed = 0; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2290 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2291 | sdata_assert_lock(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2292 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2293 | if (WARN_ON_ONCE(tx && !frame_buf)) |
| 2294 | return; |
| 2295 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2296 | if (WARN_ON(!ifmgd->associated)) |
| 2297 | return; |
| 2298 | |
David Spinadel | 79543d8 | 2012-06-12 09:59:45 +0300 | [diff] [blame] | 2299 | ieee80211_stop_poll(sdata); |
| 2300 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2301 | ifmgd->associated = NULL; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2302 | netif_carrier_off(sdata->dev); |
| 2303 | |
Eliad Peller | 88bc40e | 2012-07-12 17:35:33 +0300 | [diff] [blame] | 2304 | /* |
| 2305 | * if we want to get out of ps before disassoc (why?) we have |
| 2306 | * to do it before sending disassoc, as otherwise the null-packet |
| 2307 | * won't be valid. |
| 2308 | */ |
| 2309 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 2310 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 2311 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 2312 | } |
| 2313 | local->ps_sdata = NULL; |
| 2314 | |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 2315 | /* disable per-vif ps */ |
| 2316 | ieee80211_recalc_ps_vif(sdata); |
| 2317 | |
Emmanuel Grumbach | 14f2ae8 | 2015-01-22 23:30:19 +0200 | [diff] [blame] | 2318 | /* make sure ongoing transmission finishes */ |
| 2319 | synchronize_net(); |
| 2320 | |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 2321 | /* |
| 2322 | * drop any frame before deauth/disassoc, this can be data or |
| 2323 | * management frame. Since we are disconnecting, we should not |
| 2324 | * insist sending these frames which can take time and delay |
| 2325 | * the disconnection and possible the roaming. |
| 2326 | */ |
Eliad Peller | f823981 | 2012-06-27 14:18:22 +0300 | [diff] [blame] | 2327 | if (tx) |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 2328 | ieee80211_flush_queues(local, sdata, true); |
Eliad Peller | f823981 | 2012-06-27 14:18:22 +0300 | [diff] [blame] | 2329 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2330 | /* deauthenticate/disassociate now */ |
Ilan Peer | 94ba927 | 2018-02-19 14:48:41 +0200 | [diff] [blame] | 2331 | if (tx || frame_buf) { |
Ilan Peer | 94ba927 | 2018-02-19 14:48:41 +0200 | [diff] [blame] | 2332 | /* |
| 2333 | * In multi channel scenarios guarantee that the virtual |
| 2334 | * interface is granted immediate airtime to transmit the |
| 2335 | * deauthentication frame by calling mgd_prepare_tx, if the |
| 2336 | * driver requested so. |
| 2337 | */ |
| 2338 | if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) && |
| 2339 | !ifmgd->have_beacon) |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 2340 | drv_mgd_prepare_tx(sdata->local, sdata, 0); |
Ilan Peer | 94ba927 | 2018-02-19 14:48:41 +0200 | [diff] [blame] | 2341 | |
Johannes Berg | 4b08d1b | 2019-08-30 14:24:51 +0300 | [diff] [blame] | 2342 | ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, |
| 2343 | ifmgd->bssid, stype, reason, |
| 2344 | tx, frame_buf); |
Ilan Peer | 94ba927 | 2018-02-19 14:48:41 +0200 | [diff] [blame] | 2345 | } |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2346 | |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 2347 | /* flush out frame - make sure the deauth was actually sent */ |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2348 | if (tx) |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 2349 | ieee80211_flush_queues(local, sdata, false); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2350 | |
Eliad Peller | 88a9e31 | 2012-06-01 11:14:03 +0300 | [diff] [blame] | 2351 | /* clear bssid only after building the needed mgmt frames */ |
Joe Perches | c84a67a | 2015-03-02 19:54:57 -0800 | [diff] [blame] | 2352 | eth_zero_addr(ifmgd->bssid); |
Eliad Peller | 88a9e31 | 2012-06-01 11:14:03 +0300 | [diff] [blame] | 2353 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2354 | /* remove AP and TDLS peers */ |
Johannes Berg | d34ba21 | 2013-12-04 22:46:11 +0100 | [diff] [blame] | 2355 | sta_info_flush(sdata); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2356 | |
| 2357 | /* finally reset all BSS / config parameters */ |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 2358 | changed |= ieee80211_reset_erp_info(sdata); |
| 2359 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 2360 | ieee80211_led_assoc(local, 0); |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2361 | changed |= BSS_CHANGED_ASSOC; |
| 2362 | sdata->vif.bss_conf.assoc = false; |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 2363 | |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 2364 | ifmgd->p2p_noa_index = -1; |
| 2365 | memset(&sdata->vif.bss_conf.p2p_noa_attr, 0, |
| 2366 | sizeof(sdata->vif.bss_conf.p2p_noa_attr)); |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 2367 | |
Johannes Berg | dd5ecfe | 2013-02-21 17:40:19 +0100 | [diff] [blame] | 2368 | /* on the next assoc, re-program HT/VHT parameters */ |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 2369 | memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa)); |
| 2370 | memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask)); |
Johannes Berg | dd5ecfe | 2013-02-21 17:40:19 +0100 | [diff] [blame] | 2371 | memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa)); |
| 2372 | memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask)); |
Sara Sharon | 23a1f8d | 2015-12-08 16:04:31 +0200 | [diff] [blame] | 2373 | |
| 2374 | /* reset MU-MIMO ownership and group data */ |
| 2375 | memset(sdata->vif.bss_conf.mu_group.membership, 0, |
| 2376 | sizeof(sdata->vif.bss_conf.mu_group.membership)); |
| 2377 | memset(sdata->vif.bss_conf.mu_group.position, 0, |
| 2378 | sizeof(sdata->vif.bss_conf.mu_group.position)); |
| 2379 | changed |= BSS_CHANGED_MU_GROUPS; |
Sara Sharon | b5a33d5 | 2016-02-16 12:48:18 +0200 | [diff] [blame] | 2380 | sdata->vif.mu_mimo_owner = false; |
Johannes Berg | 413ad50 | 2009-05-08 21:21:06 +0200 | [diff] [blame] | 2381 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2382 | sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL; |
Vasanthakumar Thiagarajan | a8302de | 2009-01-09 18:14:15 +0530 | [diff] [blame] | 2383 | |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 2384 | del_timer_sync(&local->dynamic_ps_timer); |
| 2385 | cancel_work_sync(&local->dynamic_ps_enable_work); |
| 2386 | |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2387 | /* Disable ARP filtering */ |
Johannes Berg | 0f19b41 | 2013-01-14 16:39:07 +0100 | [diff] [blame] | 2388 | if (sdata->vif.bss_conf.arp_addr_cnt) |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2389 | changed |= BSS_CHANGED_ARP_FILTER; |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2390 | |
Johannes Berg | 3abead5 | 2012-03-02 15:56:59 +0100 | [diff] [blame] | 2391 | sdata->vif.bss_conf.qos = false; |
| 2392 | changed |= BSS_CHANGED_QOS; |
| 2393 | |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 2394 | /* The BSSID (not really interesting) and HT changed */ |
| 2395 | changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT; |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2396 | ieee80211_bss_info_change_notify(sdata, changed); |
Tomas Winkler | 8e268e4 | 2008-11-25 13:05:44 +0200 | [diff] [blame] | 2397 | |
Johannes Berg | 3abead5 | 2012-03-02 15:56:59 +0100 | [diff] [blame] | 2398 | /* disassociated - set to defaults now */ |
Johannes Berg | cec6628 | 2015-10-22 17:46:04 +0200 | [diff] [blame] | 2399 | ieee80211_set_wmm_default(sdata, false, false); |
Johannes Berg | 3abead5 | 2012-03-02 15:56:59 +0100 | [diff] [blame] | 2400 | |
Johannes Berg | b9dcf71 | 2010-08-27 12:35:54 +0200 | [diff] [blame] | 2401 | del_timer_sync(&sdata->u.mgd.conn_mon_timer); |
| 2402 | del_timer_sync(&sdata->u.mgd.bcn_mon_timer); |
| 2403 | del_timer_sync(&sdata->u.mgd.timer); |
| 2404 | del_timer_sync(&sdata->u.mgd.chswitch_timer); |
Johannes Berg | 2d9957c | 2012-08-01 20:54:52 +0200 | [diff] [blame] | 2405 | |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 2406 | sdata->vif.bss_conf.dtim_period = 0; |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 2407 | sdata->vif.bss_conf.beacon_rate = NULL; |
| 2408 | |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 2409 | ifmgd->have_beacon = false; |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 2410 | |
Johannes Berg | 028e8da0 | 2012-11-26 11:57:41 +0100 | [diff] [blame] | 2411 | ifmgd->flags = 0; |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2412 | mutex_lock(&local->mtx); |
Johannes Berg | 028e8da0 | 2012-11-26 11:57:41 +0100 | [diff] [blame] | 2413 | ieee80211_vif_release_channel(sdata); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 2414 | |
| 2415 | sdata->vif.csa_active = false; |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 2416 | ifmgd->csa_waiting_bcn = false; |
Johannes Berg | f84eaa1 | 2015-03-12 08:53:26 +0200 | [diff] [blame] | 2417 | ifmgd->csa_ignored_same_chan = false; |
Luciano Coelho | a46992b | 2014-06-13 16:30:07 +0300 | [diff] [blame] | 2418 | if (sdata->csa_block_tx) { |
| 2419 | ieee80211_wake_vif_queues(local, sdata, |
| 2420 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 2421 | sdata->csa_block_tx = false; |
| 2422 | } |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2423 | mutex_unlock(&local->mtx); |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 2424 | |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 2425 | /* existing TX TSPEC sessions no longer exist */ |
| 2426 | memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec)); |
| 2427 | cancel_delayed_work_sync(&ifmgd->tx_tspec_wk); |
| 2428 | |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 2429 | sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2430 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2431 | |
Kalle Valo | 3cf335d5 | 2009-03-22 21:57:06 +0200 | [diff] [blame] | 2432 | void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata, |
| 2433 | struct ieee80211_hdr *hdr) |
| 2434 | { |
| 2435 | /* |
| 2436 | * We can postpone the mgd.timer whenever receiving unicast frames |
| 2437 | * from AP because we know that the connection is working both ways |
| 2438 | * at that time. But multicast frames (and hence also beacons) must |
| 2439 | * be ignored here, because we need to trigger the timer during |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2440 | * data idle periods for sending the periodic probe request to the |
| 2441 | * AP we're connected to. |
Kalle Valo | 3cf335d5 | 2009-03-22 21:57:06 +0200 | [diff] [blame] | 2442 | */ |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2443 | if (is_multicast_ether_addr(hdr->addr1)) |
| 2444 | return; |
| 2445 | |
Luis R. Rodriguez | be099e8 | 2010-09-16 15:12:29 -0400 | [diff] [blame] | 2446 | ieee80211_sta_reset_conn_monitor(sdata); |
Kalle Valo | 3cf335d5 | 2009-03-22 21:57:06 +0200 | [diff] [blame] | 2447 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2448 | |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2449 | static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata) |
| 2450 | { |
| 2451 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2452 | struct ieee80211_local *local = sdata->local; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2453 | |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2454 | mutex_lock(&local->mtx); |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 2455 | if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)) |
| 2456 | goto out; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2457 | |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 2458 | __ieee80211_stop_poll(sdata); |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2459 | |
| 2460 | mutex_lock(&local->iflist_mtx); |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 2461 | ieee80211_recalc_ps(local); |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2462 | mutex_unlock(&local->iflist_mtx); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2463 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2464 | if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR)) |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2465 | goto out; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2466 | |
| 2467 | /* |
| 2468 | * We've received a probe response, but are not sure whether |
| 2469 | * we have or will be receiving any beacons or data, so let's |
| 2470 | * schedule the timers again, just in case. |
| 2471 | */ |
| 2472 | ieee80211_sta_reset_beacon_monitor(sdata); |
| 2473 | |
| 2474 | mod_timer(&ifmgd->conn_mon_timer, |
| 2475 | round_jiffies_up(jiffies + |
| 2476 | IEEE80211_CONNECTION_IDLE_TIME)); |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2477 | out: |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2478 | mutex_unlock(&local->mtx); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2479 | } |
| 2480 | |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 2481 | static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata, |
| 2482 | struct ieee80211_hdr *hdr, |
| 2483 | u16 tx_time) |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2484 | { |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 2485 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Sara Sharon | a1f2ba04c | 2018-02-19 14:48:40 +0200 | [diff] [blame] | 2486 | u16 tid = ieee80211_get_tid(hdr); |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 2487 | int ac = ieee80211_ac_from_tid(tid); |
| 2488 | struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac]; |
| 2489 | unsigned long now = jiffies; |
| 2490 | |
| 2491 | if (likely(!tx_tspec->admitted_time)) |
| 2492 | return; |
| 2493 | |
| 2494 | if (time_after(now, tx_tspec->time_slice_start + HZ)) { |
| 2495 | tx_tspec->consumed_tx_time = 0; |
| 2496 | tx_tspec->time_slice_start = now; |
| 2497 | |
| 2498 | if (tx_tspec->downgraded) { |
| 2499 | tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE; |
| 2500 | schedule_delayed_work(&ifmgd->tx_tspec_wk, 0); |
| 2501 | } |
| 2502 | } |
| 2503 | |
| 2504 | if (tx_tspec->downgraded) |
| 2505 | return; |
| 2506 | |
| 2507 | tx_tspec->consumed_tx_time += tx_time; |
| 2508 | |
| 2509 | if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) { |
| 2510 | tx_tspec->downgraded = true; |
| 2511 | tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE; |
| 2512 | schedule_delayed_work(&ifmgd->tx_tspec_wk, 0); |
| 2513 | } |
| 2514 | } |
| 2515 | |
| 2516 | void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata, |
| 2517 | struct ieee80211_hdr *hdr, bool ack, u16 tx_time) |
| 2518 | { |
| 2519 | ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time); |
| 2520 | |
Felix Fietkau | 75706d0 | 2010-12-02 21:01:07 +0100 | [diff] [blame] | 2521 | if (!ieee80211_is_data(hdr->frame_control)) |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2522 | return; |
| 2523 | |
Thomas Pedersen | 30b2f0b | 2020-01-13 21:59:40 -0800 | [diff] [blame] | 2524 | if (ieee80211_is_any_nullfunc(hdr->frame_control) && |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2525 | sdata->u.mgd.probe_send_count > 0) { |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2526 | if (ack) |
Wojciech Dubowik | cab1c7f | 2013-02-14 14:08:37 +0100 | [diff] [blame] | 2527 | ieee80211_sta_reset_conn_monitor(sdata); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2528 | else |
| 2529 | sdata->u.mgd.nullfunc_failed = true; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2530 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
Wojciech Dubowik | cab1c7f | 2013-02-14 14:08:37 +0100 | [diff] [blame] | 2531 | return; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2532 | } |
Wojciech Dubowik | cab1c7f | 2013-02-14 14:08:37 +0100 | [diff] [blame] | 2533 | |
| 2534 | if (ack) |
| 2535 | ieee80211_sta_reset_conn_monitor(sdata); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2536 | } |
| 2537 | |
Johannes Berg | 45ad683 | 2018-05-28 15:47:39 +0200 | [diff] [blame] | 2538 | static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata, |
| 2539 | const u8 *src, const u8 *dst, |
| 2540 | const u8 *ssid, size_t ssid_len, |
| 2541 | struct ieee80211_channel *channel) |
| 2542 | { |
| 2543 | struct sk_buff *skb; |
| 2544 | |
| 2545 | skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel, |
| 2546 | ssid, ssid_len, NULL, 0, |
| 2547 | IEEE80211_PROBE_FLAG_DIRECTED); |
| 2548 | if (skb) |
| 2549 | ieee80211_tx_skb(sdata, skb); |
| 2550 | } |
| 2551 | |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2552 | static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata) |
| 2553 | { |
| 2554 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 2555 | const u8 *ssid; |
Luis R. Rodriguez | f01a067 | 2010-09-16 15:12:34 -0400 | [diff] [blame] | 2556 | u8 *dst = ifmgd->associated->bssid; |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 2557 | u8 unicast_limit = max(1, max_probe_tries - 3); |
Johannes Berg | 49ddf8e | 2016-03-31 20:02:10 +0300 | [diff] [blame] | 2558 | struct sta_info *sta; |
Luis R. Rodriguez | f01a067 | 2010-09-16 15:12:34 -0400 | [diff] [blame] | 2559 | |
| 2560 | /* |
| 2561 | * Try sending broadcast probe requests for the last three |
| 2562 | * probe requests after the first ones failed since some |
| 2563 | * buggy APs only support broadcast probe requests. |
| 2564 | */ |
| 2565 | if (ifmgd->probe_send_count >= unicast_limit) |
| 2566 | dst = NULL; |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2567 | |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2568 | /* |
| 2569 | * When the hardware reports an accurate Tx ACK status, it's |
| 2570 | * better to send a nullfunc frame instead of a probe request, |
| 2571 | * as it will kick us off the AP quickly if we aren't associated |
| 2572 | * anymore. The timeout will be reset if the frame is ACKed by |
| 2573 | * the AP. |
| 2574 | */ |
Soumik Das | 992e68b | 2012-05-20 15:31:13 +0530 | [diff] [blame] | 2575 | ifmgd->probe_send_count++; |
| 2576 | |
Johannes Berg | 49ddf8e | 2016-03-31 20:02:10 +0300 | [diff] [blame] | 2577 | if (dst) { |
| 2578 | mutex_lock(&sdata->local->sta_mtx); |
| 2579 | sta = sta_info_get(sdata, dst); |
| 2580 | if (!WARN_ON(!sta)) |
| 2581 | ieee80211_check_fast_rx(sta); |
| 2582 | mutex_unlock(&sdata->local->sta_mtx); |
| 2583 | } |
| 2584 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2585 | if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) { |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2586 | ifmgd->nullfunc_failed = false; |
Shay Bar | f39b07f | 2019-07-03 16:18:48 +0300 | [diff] [blame] | 2587 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) |
| 2588 | ifmgd->probe_send_count--; |
| 2589 | else |
| 2590 | ieee80211_send_nullfunc(sdata->local, sdata, false); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2591 | } else { |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 2592 | int ssid_len; |
| 2593 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2594 | rcu_read_lock(); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2595 | ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID); |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 2596 | if (WARN_ON_ONCE(ssid == NULL)) |
| 2597 | ssid_len = 0; |
| 2598 | else |
| 2599 | ssid_len = ssid[1]; |
| 2600 | |
Johannes Berg | 45ad683 | 2018-05-28 15:47:39 +0200 | [diff] [blame] | 2601 | ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst, |
| 2602 | ssid + 2, ssid_len, |
| 2603 | ifmgd->associated->channel); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2604 | rcu_read_unlock(); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2605 | } |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2606 | |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 2607 | ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2608 | run_again(sdata, ifmgd->probe_timeout); |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2609 | } |
| 2610 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2611 | static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata, |
| 2612 | bool beacon) |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2613 | { |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2614 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2615 | bool already = false; |
Johannes Berg | 34bfc41 | 2009-05-12 19:58:12 +0200 | [diff] [blame] | 2616 | |
Johannes Berg | 9607e6b66 | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 2617 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | 0e2b628 | 2009-07-13 13:23:39 +0200 | [diff] [blame] | 2618 | return; |
| 2619 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2620 | sdata_lock(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2621 | |
| 2622 | if (!ifmgd->associated) |
| 2623 | goto out; |
| 2624 | |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2625 | mutex_lock(&sdata->local->mtx); |
| 2626 | |
| 2627 | if (sdata->local->tmp_channel || sdata->local->scanning) { |
| 2628 | mutex_unlock(&sdata->local->mtx); |
| 2629 | goto out; |
| 2630 | } |
| 2631 | |
Ben Greear | a13fbe5 | 2013-03-25 11:19:35 -0700 | [diff] [blame] | 2632 | if (beacon) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2633 | mlme_dbg_ratelimited(sdata, |
Ben Greear | 59c1ec2 | 2013-03-19 14:19:56 -0700 | [diff] [blame] | 2634 | "detected beacon loss from AP (missed %d beacons) - probing\n", |
| 2635 | beacon_loss_count); |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2636 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 2637 | ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL); |
Ben Greear | a13fbe5 | 2013-03-25 11:19:35 -0700 | [diff] [blame] | 2638 | } |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2639 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2640 | /* |
| 2641 | * The driver/our work has already reported this event or the |
| 2642 | * connection monitoring has kicked in and we have already sent |
| 2643 | * a probe request. Or maybe the AP died and the driver keeps |
| 2644 | * reporting until we disassociate... |
| 2645 | * |
| 2646 | * In either case we have to ignore the current call to this |
| 2647 | * function (except for setting the correct probe reason bit) |
| 2648 | * because otherwise we would reset the timer every time and |
| 2649 | * never check whether we received a probe response! |
| 2650 | */ |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 2651 | if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2652 | already = true; |
| 2653 | |
Eliad Peller | 12b5f34 | 2013-11-18 19:06:46 +0200 | [diff] [blame] | 2654 | ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL; |
| 2655 | |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2656 | mutex_unlock(&sdata->local->mtx); |
| 2657 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2658 | if (already) |
| 2659 | goto out; |
| 2660 | |
Johannes Berg | 4e75184 | 2009-06-10 15:16:52 +0200 | [diff] [blame] | 2661 | mutex_lock(&sdata->local->iflist_mtx); |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 2662 | ieee80211_recalc_ps(sdata->local); |
Johannes Berg | 4e75184 | 2009-06-10 15:16:52 +0200 | [diff] [blame] | 2663 | mutex_unlock(&sdata->local->iflist_mtx); |
| 2664 | |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2665 | ifmgd->probe_send_count = 0; |
| 2666 | ieee80211_mgd_probe_ap_send(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2667 | out: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2668 | sdata_unlock(sdata); |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2669 | } |
| 2670 | |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2671 | struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw, |
| 2672 | struct ieee80211_vif *vif) |
| 2673 | { |
| 2674 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 2675 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Eliad Peller | d9b3b28 | 2012-06-28 15:03:13 +0300 | [diff] [blame] | 2676 | struct cfg80211_bss *cbss; |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2677 | struct sk_buff *skb; |
| 2678 | const u8 *ssid; |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 2679 | int ssid_len; |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2680 | |
| 2681 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) |
| 2682 | return NULL; |
| 2683 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2684 | sdata_assert_lock(sdata); |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2685 | |
Eliad Peller | d9b3b28 | 2012-06-28 15:03:13 +0300 | [diff] [blame] | 2686 | if (ifmgd->associated) |
| 2687 | cbss = ifmgd->associated; |
| 2688 | else if (ifmgd->auth_data) |
| 2689 | cbss = ifmgd->auth_data->bss; |
| 2690 | else if (ifmgd->assoc_data) |
| 2691 | cbss = ifmgd->assoc_data->bss; |
| 2692 | else |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2693 | return NULL; |
| 2694 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2695 | rcu_read_lock(); |
Eliad Peller | d9b3b28 | 2012-06-28 15:03:13 +0300 | [diff] [blame] | 2696 | ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID); |
Will Deacon | 4152561 | 2019-10-04 10:51:31 +0100 | [diff] [blame] | 2697 | if (WARN_ONCE(!ssid || ssid[1] > IEEE80211_MAX_SSID_LEN, |
| 2698 | "invalid SSID element (len=%d)", ssid ? ssid[1] : -1)) |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 2699 | ssid_len = 0; |
| 2700 | else |
| 2701 | ssid_len = ssid[1]; |
| 2702 | |
Johannes Berg | a344d67 | 2014-06-12 22:24:31 +0200 | [diff] [blame] | 2703 | skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid, |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2704 | (u32) -1, cbss->channel, |
Johannes Berg | 6b77863 | 2012-07-23 14:53:27 +0200 | [diff] [blame] | 2705 | ssid + 2, ssid_len, |
Johannes Berg | 00387f3 | 2018-05-28 15:47:38 +0200 | [diff] [blame] | 2706 | NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2707 | rcu_read_unlock(); |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2708 | |
| 2709 | return skb; |
| 2710 | } |
| 2711 | EXPORT_SYMBOL(ieee80211_ap_probereq_get); |
| 2712 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 2713 | static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata, |
| 2714 | const u8 *buf, size_t len, bool tx, |
| 2715 | u16 reason) |
| 2716 | { |
| 2717 | struct ieee80211_event event = { |
| 2718 | .type = MLME_EVENT, |
| 2719 | .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT, |
| 2720 | .u.mlme.reason = reason, |
| 2721 | }; |
| 2722 | |
| 2723 | if (tx) |
| 2724 | cfg80211_tx_mlme_mgmt(sdata->dev, buf, len); |
| 2725 | else |
| 2726 | cfg80211_rx_mlme_mgmt(sdata->dev, buf, len); |
| 2727 | |
| 2728 | drv_event_callback(sdata->local, sdata, &event); |
| 2729 | } |
| 2730 | |
Johannes Berg | eef9e54 | 2013-01-29 13:09:34 +0100 | [diff] [blame] | 2731 | static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata) |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2732 | { |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 2733 | struct ieee80211_local *local = sdata->local; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2734 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 2735 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 2736 | bool tx; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2737 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2738 | sdata_lock(sdata); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2739 | if (!ifmgd->associated) { |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2740 | sdata_unlock(sdata); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2741 | return; |
| 2742 | } |
| 2743 | |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 2744 | tx = !sdata->csa_block_tx; |
| 2745 | |
David Spinadel | 20eb7ea | 2016-05-03 16:05:02 +0300 | [diff] [blame] | 2746 | /* AP is probably out of range (or not reachable for another reason) so |
| 2747 | * remove the bss struct for that AP. |
| 2748 | */ |
| 2749 | cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated); |
| 2750 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2751 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
| 2752 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 2753 | tx, frame_buf); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 2754 | mutex_lock(&local->mtx); |
Arik Nemtsov | 7578d57 | 2013-09-01 17:15:51 +0300 | [diff] [blame] | 2755 | sdata->vif.csa_active = false; |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 2756 | ifmgd->csa_waiting_bcn = false; |
Luciano Coelho | a46992b | 2014-06-13 16:30:07 +0300 | [diff] [blame] | 2757 | if (sdata->csa_block_tx) { |
| 2758 | ieee80211_wake_vif_queues(local, sdata, |
| 2759 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 2760 | sdata->csa_block_tx = false; |
| 2761 | } |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 2762 | mutex_unlock(&local->mtx); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 2763 | |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 2764 | ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx, |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 2765 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY); |
| 2766 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2767 | sdata_unlock(sdata); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2768 | } |
| 2769 | |
Johannes Berg | cc74c0c | 2012-08-01 16:49:34 +0200 | [diff] [blame] | 2770 | static void ieee80211_beacon_connection_loss_work(struct work_struct *work) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2771 | { |
| 2772 | struct ieee80211_sub_if_data *sdata = |
| 2773 | container_of(work, struct ieee80211_sub_if_data, |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2774 | u.mgd.beacon_connection_loss_work); |
Paul Stewart | a85e1d5 | 2011-12-09 11:01:49 -0800 | [diff] [blame] | 2775 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Paul Stewart | a85e1d5 | 2011-12-09 11:01:49 -0800 | [diff] [blame] | 2776 | |
Johannes Berg | 976bd9e | 2015-10-16 17:18:11 +0200 | [diff] [blame] | 2777 | if (ifmgd->associated) |
| 2778 | ifmgd->beacon_loss_count++; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2779 | |
Johannes Berg | 682bd38 | 2013-01-29 13:13:50 +0100 | [diff] [blame] | 2780 | if (ifmgd->connection_loss) { |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 2781 | sdata_info(sdata, "Connection to AP %pM lost\n", |
| 2782 | ifmgd->bssid); |
Johannes Berg | eef9e54 | 2013-01-29 13:09:34 +0100 | [diff] [blame] | 2783 | __ieee80211_disconnect(sdata); |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 2784 | } else { |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2785 | ieee80211_mgd_probe_ap(sdata, true); |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 2786 | } |
| 2787 | } |
| 2788 | |
| 2789 | static void ieee80211_csa_connection_drop_work(struct work_struct *work) |
| 2790 | { |
| 2791 | struct ieee80211_sub_if_data *sdata = |
| 2792 | container_of(work, struct ieee80211_sub_if_data, |
| 2793 | u.mgd.csa_connection_drop_work); |
| 2794 | |
Johannes Berg | eef9e54 | 2013-01-29 13:09:34 +0100 | [diff] [blame] | 2795 | __ieee80211_disconnect(sdata); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2796 | } |
| 2797 | |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2798 | void ieee80211_beacon_loss(struct ieee80211_vif *vif) |
| 2799 | { |
| 2800 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2801 | struct ieee80211_hw *hw = &sdata->local->hw; |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2802 | |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 2803 | trace_api_beacon_loss(sdata); |
| 2804 | |
Johannes Berg | 682bd38 | 2013-01-29 13:13:50 +0100 | [diff] [blame] | 2805 | sdata->u.mgd.connection_loss = false; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2806 | ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work); |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2807 | } |
| 2808 | EXPORT_SYMBOL(ieee80211_beacon_loss); |
| 2809 | |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2810 | void ieee80211_connection_loss(struct ieee80211_vif *vif) |
| 2811 | { |
| 2812 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 2813 | struct ieee80211_hw *hw = &sdata->local->hw; |
| 2814 | |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 2815 | trace_api_connection_loss(sdata); |
| 2816 | |
Johannes Berg | 682bd38 | 2013-01-29 13:13:50 +0100 | [diff] [blame] | 2817 | sdata->u.mgd.connection_loss = true; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2818 | ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work); |
| 2819 | } |
| 2820 | EXPORT_SYMBOL(ieee80211_connection_loss); |
| 2821 | |
| 2822 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2823 | static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata, |
| 2824 | bool assoc) |
| 2825 | { |
| 2826 | struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data; |
| 2827 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2828 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2829 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2830 | if (!assoc) { |
Emmanuel Grumbach | c1e140b | 2015-01-19 16:53:06 +0200 | [diff] [blame] | 2831 | /* |
| 2832 | * we are not authenticated yet, the only timer that could be |
| 2833 | * running is the timeout for the authentication response which |
| 2834 | * which is not relevant anymore. |
| 2835 | */ |
| 2836 | del_timer_sync(&sdata->u.mgd.timer); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2837 | sta_info_destroy_addr(sdata, auth_data->bss->bssid); |
| 2838 | |
Joe Perches | c84a67a | 2015-03-02 19:54:57 -0800 | [diff] [blame] | 2839 | eth_zero_addr(sdata->u.mgd.bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2840 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
Johannes Berg | 028e8da0 | 2012-11-26 11:57:41 +0100 | [diff] [blame] | 2841 | sdata->u.mgd.flags = 0; |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2842 | mutex_lock(&sdata->local->mtx); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2843 | ieee80211_vif_release_channel(sdata); |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2844 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2845 | } |
| 2846 | |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 2847 | cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2848 | kfree(auth_data); |
| 2849 | sdata->u.mgd.auth_data = NULL; |
| 2850 | } |
| 2851 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 2852 | static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 2853 | bool assoc, bool abandon) |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 2854 | { |
| 2855 | struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data; |
| 2856 | |
| 2857 | sdata_assert_lock(sdata); |
| 2858 | |
| 2859 | if (!assoc) { |
| 2860 | /* |
| 2861 | * we are not associated yet, the only timer that could be |
| 2862 | * running is the timeout for the association response which |
| 2863 | * which is not relevant anymore. |
| 2864 | */ |
| 2865 | del_timer_sync(&sdata->u.mgd.timer); |
| 2866 | sta_info_destroy_addr(sdata, assoc_data->bss->bssid); |
| 2867 | |
| 2868 | eth_zero_addr(sdata->u.mgd.bssid); |
| 2869 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
| 2870 | sdata->u.mgd.flags = 0; |
Sara Sharon | b5a33d5 | 2016-02-16 12:48:18 +0200 | [diff] [blame] | 2871 | sdata->vif.mu_mimo_owner = false; |
| 2872 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 2873 | mutex_lock(&sdata->local->mtx); |
| 2874 | ieee80211_vif_release_channel(sdata); |
| 2875 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 2876 | |
| 2877 | if (abandon) |
| 2878 | cfg80211_abandon_assoc(sdata->dev, assoc_data->bss); |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 2879 | } |
| 2880 | |
| 2881 | kfree(assoc_data); |
| 2882 | sdata->u.mgd.assoc_data = NULL; |
| 2883 | } |
| 2884 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2885 | static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata, |
| 2886 | struct ieee80211_mgmt *mgmt, size_t len) |
| 2887 | { |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 2888 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2889 | struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data; |
| 2890 | u8 *pos; |
| 2891 | struct ieee802_11_elems elems; |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 2892 | u32 tx_flags = 0; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2893 | |
| 2894 | pos = mgmt->u.auth.variable; |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 2895 | ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems, |
| 2896 | mgmt->bssid, auth_data->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2897 | if (!elems.challenge) |
| 2898 | return; |
| 2899 | auth_data->expected_transaction = 4; |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 2900 | drv_mgd_prepare_tx(sdata->local, sdata, 0); |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2901 | if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 2902 | tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS | |
| 2903 | IEEE80211_TX_INTFL_MLME_CONN_TX; |
Jouni Malinen | 700e8ea | 2012-09-30 19:29:37 +0300 | [diff] [blame] | 2904 | ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0, |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2905 | elems.challenge - 2, elems.challenge_len + 2, |
| 2906 | auth_data->bss->bssid, auth_data->bss->bssid, |
| 2907 | auth_data->key, auth_data->key_len, |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 2908 | auth_data->key_idx, tx_flags); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2909 | } |
| 2910 | |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2911 | static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata, |
| 2912 | const u8 *bssid) |
| 2913 | { |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 2914 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2915 | struct sta_info *sta; |
Wei Yongjun | 33483a6 | 2018-10-16 02:35:30 +0000 | [diff] [blame] | 2916 | bool result = true; |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2917 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 2918 | sdata_info(sdata, "authenticated\n"); |
| 2919 | ifmgd->auth_data->done = true; |
| 2920 | ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC; |
| 2921 | ifmgd->auth_data->timeout_started = true; |
| 2922 | run_again(sdata, ifmgd->auth_data->timeout); |
| 2923 | |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2924 | /* move station state to auth */ |
| 2925 | mutex_lock(&sdata->local->sta_mtx); |
| 2926 | sta = sta_info_get(sdata, bssid); |
| 2927 | if (!sta) { |
| 2928 | WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid); |
Wei Yongjun | 33483a6 | 2018-10-16 02:35:30 +0000 | [diff] [blame] | 2929 | result = false; |
| 2930 | goto out; |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2931 | } |
| 2932 | if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) { |
| 2933 | sdata_info(sdata, "failed moving %pM to auth\n", bssid); |
Wei Yongjun | 33483a6 | 2018-10-16 02:35:30 +0000 | [diff] [blame] | 2934 | result = false; |
| 2935 | goto out; |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2936 | } |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2937 | |
Wei Yongjun | 33483a6 | 2018-10-16 02:35:30 +0000 | [diff] [blame] | 2938 | out: |
| 2939 | mutex_unlock(&sdata->local->sta_mtx); |
| 2940 | return result; |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2941 | } |
| 2942 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2943 | static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata, |
| 2944 | struct ieee80211_mgmt *mgmt, size_t len) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2945 | { |
| 2946 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 2947 | u8 bssid[ETH_ALEN]; |
| 2948 | u16 auth_alg, auth_transaction, status_code; |
Emmanuel Grumbach | a940909 | 2015-03-16 23:23:35 +0200 | [diff] [blame] | 2949 | struct ieee80211_event event = { |
| 2950 | .type = MLME_EVENT, |
| 2951 | .u.mlme.data = AUTH_EVENT, |
| 2952 | }; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2953 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2954 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2955 | |
| 2956 | if (len < 24 + 6) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2957 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2958 | |
| 2959 | if (!ifmgd->auth_data || ifmgd->auth_data->done) |
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 | memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN); |
| 2963 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2964 | if (!ether_addr_equal(bssid, mgmt->bssid)) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2965 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2966 | |
| 2967 | auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); |
| 2968 | auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); |
| 2969 | status_code = le16_to_cpu(mgmt->u.auth.status_code); |
| 2970 | |
| 2971 | if (auth_alg != ifmgd->auth_data->algorithm || |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 2972 | (auth_alg != WLAN_AUTH_SAE && |
| 2973 | auth_transaction != ifmgd->auth_data->expected_transaction) || |
| 2974 | (auth_alg == WLAN_AUTH_SAE && |
| 2975 | (auth_transaction < ifmgd->auth_data->expected_transaction || |
| 2976 | auth_transaction > 2))) { |
Jouni Malinen | 0f4126e | 2012-09-30 19:29:38 +0300 | [diff] [blame] | 2977 | sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n", |
| 2978 | mgmt->sa, auth_alg, ifmgd->auth_data->algorithm, |
| 2979 | auth_transaction, |
| 2980 | ifmgd->auth_data->expected_transaction); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2981 | return; |
Jouni Malinen | 0f4126e | 2012-09-30 19:29:38 +0300 | [diff] [blame] | 2982 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2983 | |
| 2984 | if (status_code != WLAN_STATUS_SUCCESS) { |
Andrei Otcheretianski | a4055e7 | 2020-03-26 15:09:34 +0200 | [diff] [blame] | 2985 | cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len); |
| 2986 | |
| 2987 | if (auth_alg == WLAN_AUTH_SAE && |
| 2988 | status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED) |
| 2989 | return; |
| 2990 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2991 | sdata_info(sdata, "%pM denied authentication (status %d)\n", |
| 2992 | mgmt->sa, status_code); |
Eliad Peller | dac211e | 2012-05-13 18:07:04 +0300 | [diff] [blame] | 2993 | ieee80211_destroy_auth_data(sdata, false); |
Emmanuel Grumbach | a940909 | 2015-03-16 23:23:35 +0200 | [diff] [blame] | 2994 | event.u.mlme.status = MLME_DENIED; |
| 2995 | event.u.mlme.reason = status_code; |
| 2996 | drv_event_callback(sdata->local, sdata, &event); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2997 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2998 | } |
| 2999 | |
| 3000 | switch (ifmgd->auth_data->algorithm) { |
| 3001 | case WLAN_AUTH_OPEN: |
| 3002 | case WLAN_AUTH_LEAP: |
| 3003 | case WLAN_AUTH_FT: |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 3004 | case WLAN_AUTH_SAE: |
Jouni Malinen | dbc0c2c | 2016-10-27 00:42:04 +0300 | [diff] [blame] | 3005 | case WLAN_AUTH_FILS_SK: |
| 3006 | case WLAN_AUTH_FILS_SK_PFS: |
| 3007 | case WLAN_AUTH_FILS_PK: |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3008 | break; |
| 3009 | case WLAN_AUTH_SHARED_KEY: |
| 3010 | if (ifmgd->auth_data->expected_transaction != 4) { |
| 3011 | ieee80211_auth_challenge(sdata, mgmt, len); |
| 3012 | /* need another frame */ |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3013 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3014 | } |
| 3015 | break; |
| 3016 | default: |
| 3017 | WARN_ONCE(1, "invalid auth alg %d", |
| 3018 | ifmgd->auth_data->algorithm); |
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 | |
Emmanuel Grumbach | a940909 | 2015-03-16 23:23:35 +0200 | [diff] [blame] | 3022 | event.u.mlme.status = MLME_SUCCESS; |
| 3023 | drv_event_callback(sdata->local, sdata, &event); |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 3024 | if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE || |
| 3025 | (auth_transaction == 2 && |
| 3026 | ifmgd->auth_data->expected_transaction == 2)) { |
| 3027 | if (!ieee80211_mark_sta_auth(sdata, bssid)) |
Andrei Otcheretianski | 0daa63e | 2020-02-21 10:47:20 +0100 | [diff] [blame] | 3028 | return; /* ignore frame -- wait for timeout */ |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 3029 | } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE && |
| 3030 | auth_transaction == 2) { |
| 3031 | sdata_info(sdata, "SAE peer confirmed\n"); |
| 3032 | ifmgd->auth_data->peer_confirmed = true; |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 3033 | } |
| 3034 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 3035 | cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3036 | } |
| 3037 | |
Calvin Owens | dfa1ad2 | 2014-02-11 12:36:24 -0600 | [diff] [blame] | 3038 | #define case_WLAN(type) \ |
| 3039 | case WLAN_REASON_##type: return #type |
| 3040 | |
Yu Wang | 79c92ca | 2019-05-10 17:04:52 +0800 | [diff] [blame] | 3041 | const char *ieee80211_get_reason_code_string(u16 reason_code) |
Calvin Owens | dfa1ad2 | 2014-02-11 12:36:24 -0600 | [diff] [blame] | 3042 | { |
| 3043 | switch (reason_code) { |
| 3044 | case_WLAN(UNSPECIFIED); |
| 3045 | case_WLAN(PREV_AUTH_NOT_VALID); |
| 3046 | case_WLAN(DEAUTH_LEAVING); |
| 3047 | case_WLAN(DISASSOC_DUE_TO_INACTIVITY); |
| 3048 | case_WLAN(DISASSOC_AP_BUSY); |
| 3049 | case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA); |
| 3050 | case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA); |
| 3051 | case_WLAN(DISASSOC_STA_HAS_LEFT); |
| 3052 | case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH); |
| 3053 | case_WLAN(DISASSOC_BAD_POWER); |
| 3054 | case_WLAN(DISASSOC_BAD_SUPP_CHAN); |
| 3055 | case_WLAN(INVALID_IE); |
| 3056 | case_WLAN(MIC_FAILURE); |
| 3057 | case_WLAN(4WAY_HANDSHAKE_TIMEOUT); |
| 3058 | case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT); |
| 3059 | case_WLAN(IE_DIFFERENT); |
| 3060 | case_WLAN(INVALID_GROUP_CIPHER); |
| 3061 | case_WLAN(INVALID_PAIRWISE_CIPHER); |
| 3062 | case_WLAN(INVALID_AKMP); |
| 3063 | case_WLAN(UNSUPP_RSN_VERSION); |
| 3064 | case_WLAN(INVALID_RSN_IE_CAP); |
| 3065 | case_WLAN(IEEE8021X_FAILED); |
| 3066 | case_WLAN(CIPHER_SUITE_REJECTED); |
| 3067 | case_WLAN(DISASSOC_UNSPECIFIED_QOS); |
| 3068 | case_WLAN(DISASSOC_QAP_NO_BANDWIDTH); |
| 3069 | case_WLAN(DISASSOC_LOW_ACK); |
| 3070 | case_WLAN(DISASSOC_QAP_EXCEED_TXOP); |
| 3071 | case_WLAN(QSTA_LEAVE_QBSS); |
| 3072 | case_WLAN(QSTA_NOT_USE); |
| 3073 | case_WLAN(QSTA_REQUIRE_SETUP); |
| 3074 | case_WLAN(QSTA_TIMEOUT); |
| 3075 | case_WLAN(QSTA_CIPHER_NOT_SUPP); |
| 3076 | case_WLAN(MESH_PEER_CANCELED); |
| 3077 | case_WLAN(MESH_MAX_PEERS); |
| 3078 | case_WLAN(MESH_CONFIG); |
| 3079 | case_WLAN(MESH_CLOSE); |
| 3080 | case_WLAN(MESH_MAX_RETRIES); |
| 3081 | case_WLAN(MESH_CONFIRM_TIMEOUT); |
| 3082 | case_WLAN(MESH_INVALID_GTK); |
| 3083 | case_WLAN(MESH_INCONSISTENT_PARAM); |
| 3084 | case_WLAN(MESH_INVALID_SECURITY); |
| 3085 | case_WLAN(MESH_PATH_ERROR); |
| 3086 | case_WLAN(MESH_PATH_NOFORWARD); |
| 3087 | case_WLAN(MESH_PATH_DEST_UNREACHABLE); |
| 3088 | case_WLAN(MAC_EXISTS_IN_MBSS); |
| 3089 | case_WLAN(MESH_CHAN_REGULATORY); |
| 3090 | case_WLAN(MESH_CHAN); |
| 3091 | default: return "<unknown>"; |
| 3092 | } |
| 3093 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3094 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3095 | static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata, |
| 3096 | struct ieee80211_mgmt *mgmt, size_t len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3097 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3098 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3099 | u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3100 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3101 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3102 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 3103 | if (len < 24 + 2) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3104 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3105 | |
Yu Wang | 79c92ca | 2019-05-10 17:04:52 +0800 | [diff] [blame] | 3106 | if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) { |
| 3107 | ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code); |
| 3108 | return; |
| 3109 | } |
| 3110 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3111 | if (ifmgd->associated && |
| 3112 | ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) { |
| 3113 | const u8 *bssid = ifmgd->associated->bssid; |
| 3114 | |
| 3115 | sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n", |
| 3116 | bssid, reason_code, |
| 3117 | ieee80211_get_reason_code_string(reason_code)); |
| 3118 | |
| 3119 | ieee80211_set_disassoc(sdata, 0, 0, false, NULL); |
| 3120 | |
| 3121 | ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, |
| 3122 | reason_code); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3123 | return; |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3124 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3125 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3126 | if (ifmgd->assoc_data && |
| 3127 | ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) { |
| 3128 | const u8 *bssid = ifmgd->assoc_data->bss->bssid; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3129 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3130 | sdata_info(sdata, |
| 3131 | "deauthenticated from %pM while associating (Reason: %u=%s)\n", |
| 3132 | bssid, reason_code, |
| 3133 | ieee80211_get_reason_code_string(reason_code)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3134 | |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 3135 | ieee80211_destroy_assoc_data(sdata, false, true); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3136 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3137 | cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len); |
| 3138 | return; |
| 3139 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3140 | } |
| 3141 | |
| 3142 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3143 | static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata, |
| 3144 | struct ieee80211_mgmt *mgmt, size_t len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3145 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3146 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3147 | u16 reason_code; |
| 3148 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3149 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3150 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 3151 | if (len < 24 + 2) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3152 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3153 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3154 | if (!ifmgd->associated || |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 3155 | !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3156 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3157 | |
| 3158 | reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); |
| 3159 | |
Yu Wang | 79c92ca | 2019-05-10 17:04:52 +0800 | [diff] [blame] | 3160 | if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) { |
| 3161 | ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code); |
| 3162 | return; |
| 3163 | } |
| 3164 | |
Arkadiusz Miskiewicz | 68506e9 | 2017-02-15 14:21:27 +0100 | [diff] [blame] | 3165 | sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n", |
| 3166 | mgmt->sa, reason_code, |
| 3167 | ieee80211_get_reason_code_string(reason_code)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3168 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 3169 | ieee80211_set_disassoc(sdata, 0, 0, false, NULL); |
| 3170 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 3171 | ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3172 | } |
| 3173 | |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3174 | static void ieee80211_get_rates(struct ieee80211_supported_band *sband, |
| 3175 | u8 *supp_rates, unsigned int supp_rates_len, |
| 3176 | u32 *rates, u32 *basic_rates, |
| 3177 | bool *have_higher_than_11mbit, |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3178 | int *min_rate, int *min_rate_index, |
Johannes Berg | 44f6d42 | 2017-06-10 13:52:44 +0300 | [diff] [blame] | 3179 | int shift) |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3180 | { |
| 3181 | int i, j; |
| 3182 | |
| 3183 | for (i = 0; i < supp_rates_len; i++) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3184 | int rate = supp_rates[i] & 0x7f; |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3185 | bool is_basic = !!(supp_rates[i] & 0x80); |
| 3186 | |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3187 | if ((rate * 5 * (1 << shift)) > 110) |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3188 | *have_higher_than_11mbit = true; |
| 3189 | |
| 3190 | /* |
Ilan Peer | 4826e72 | 2020-03-26 15:09:36 +0200 | [diff] [blame] | 3191 | * Skip HT, VHT and HE BSS membership selectors since they're |
| 3192 | * not rates. |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3193 | * |
Johannes Berg | a6289d3 | 2017-03-06 22:59:04 +0100 | [diff] [blame] | 3194 | * Note: Even though the membership selector and the basic |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3195 | * rate flag share the same bit, they are not exactly |
| 3196 | * the same. |
| 3197 | */ |
Johannes Berg | a6289d3 | 2017-03-06 22:59:04 +0100 | [diff] [blame] | 3198 | if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) || |
Ilan Peer | 4826e72 | 2020-03-26 15:09:36 +0200 | [diff] [blame] | 3199 | supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY) || |
| 3200 | supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY)) |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3201 | continue; |
| 3202 | |
| 3203 | for (j = 0; j < sband->n_bitrates; j++) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3204 | struct ieee80211_rate *br; |
| 3205 | int brate; |
| 3206 | |
| 3207 | br = &sband->bitrates[j]; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3208 | |
| 3209 | brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5); |
| 3210 | if (brate == rate) { |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3211 | *rates |= BIT(j); |
| 3212 | if (is_basic) |
| 3213 | *basic_rates |= BIT(j); |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3214 | if ((rate * 5) < *min_rate) { |
| 3215 | *min_rate = rate * 5; |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3216 | *min_rate_index = j; |
| 3217 | } |
| 3218 | break; |
| 3219 | } |
| 3220 | } |
| 3221 | } |
| 3222 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3223 | |
Emmanuel Grumbach | 55ebd6e | 2018-12-15 11:03:04 +0200 | [diff] [blame] | 3224 | static bool ieee80211_twt_req_supported(const struct sta_info *sta, |
| 3225 | const struct ieee802_11_elems *elems) |
| 3226 | { |
| 3227 | if (elems->ext_capab_len < 10) |
| 3228 | return false; |
| 3229 | |
| 3230 | if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT)) |
| 3231 | return false; |
| 3232 | |
| 3233 | return sta->sta.he_cap.he_cap_elem.mac_cap_info[0] & |
| 3234 | IEEE80211_HE_MAC_CAP0_TWT_RES; |
| 3235 | } |
| 3236 | |
John Crispin | c9d3245 | 2019-05-28 13:49:47 +0200 | [diff] [blame] | 3237 | static int ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata, |
| 3238 | struct sta_info *sta, |
| 3239 | struct ieee802_11_elems *elems) |
| 3240 | { |
| 3241 | bool twt = ieee80211_twt_req_supported(sta, elems); |
| 3242 | |
| 3243 | if (sdata->vif.bss_conf.twt_requester != twt) { |
| 3244 | sdata->vif.bss_conf.twt_requester = twt; |
| 3245 | return BSS_CHANGED_TWT; |
| 3246 | } |
| 3247 | return 0; |
| 3248 | } |
| 3249 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3250 | static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata, |
| 3251 | struct cfg80211_bss *cbss, |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3252 | struct ieee80211_mgmt *mgmt, size_t len, |
| 3253 | struct ieee802_11_elems *elems) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3254 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3255 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 3256 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3257 | struct ieee80211_supported_band *sband; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3258 | struct sta_info *sta; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3259 | u16 capab_info, aid; |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 3260 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3261 | const struct cfg80211_bss_ies *bss_ies = NULL; |
| 3262 | struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 3263 | bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ; |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 3264 | u32 changed = 0; |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3265 | int err; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3266 | bool ret; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3267 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3268 | /* AssocResp and ReassocResp have identical structure */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3269 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3270 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3271 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3272 | |
Johannes Berg | c7c477b | 2017-12-01 13:50:51 +0200 | [diff] [blame] | 3273 | /* |
| 3274 | * The 5 MSB of the AID field are reserved |
| 3275 | * (802.11-2016 9.4.1.8 AID field) |
| 3276 | */ |
| 3277 | aid &= 0x7ff; |
Johannes Berg | 1dd84aa | 2007-10-10 12:03:41 +0200 | [diff] [blame] | 3278 | |
Johannes Berg | 05cb910 | 2011-10-28 11:59:47 +0200 | [diff] [blame] | 3279 | ifmgd->broken_ap = false; |
| 3280 | |
| 3281 | if (aid == 0 || aid > IEEE80211_MAX_AID) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3282 | sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n", |
| 3283 | aid); |
Johannes Berg | 05cb910 | 2011-10-28 11:59:47 +0200 | [diff] [blame] | 3284 | aid = 0; |
| 3285 | ifmgd->broken_ap = true; |
| 3286 | } |
| 3287 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3288 | if (!elems->supp_rates) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3289 | sdata_info(sdata, "no SuppRates element in AssocResp\n"); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3290 | return false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3291 | } |
| 3292 | |
Johannes Berg | 1db364c | 2020-04-17 12:38:04 +0200 | [diff] [blame] | 3293 | sdata->vif.bss_conf.aid = aid; |
Arik Nemtsov | 9041c1f | 2014-11-09 18:50:15 +0200 | [diff] [blame] | 3294 | ifmgd->tdls_chan_switch_prohibited = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3295 | elems->ext_capab && elems->ext_capab_len >= 5 && |
| 3296 | (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3297 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3298 | /* |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3299 | * Some APs are erroneously not including some information in their |
| 3300 | * (re)association response frames. Try to recover by using the data |
| 3301 | * from the beacon or probe response. This seems to afflict mobile |
| 3302 | * 2G/3G/4G wifi routers, reported models include the "Onda PN51T", |
| 3303 | * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device. |
| 3304 | */ |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 3305 | if (!is_6ghz && |
| 3306 | ((assoc_data->wmm && !elems->wmm_param) || |
| 3307 | (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) && |
| 3308 | (!elems->ht_cap_elem || !elems->ht_operation)) || |
| 3309 | (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && |
| 3310 | (!elems->vht_cap_elem || !elems->vht_operation)))) { |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3311 | const struct cfg80211_bss_ies *ies; |
| 3312 | struct ieee802_11_elems bss_elems; |
| 3313 | |
| 3314 | rcu_read_lock(); |
| 3315 | ies = rcu_dereference(cbss->ies); |
| 3316 | if (ies) |
| 3317 | bss_ies = kmemdup(ies, sizeof(*ies) + ies->len, |
| 3318 | GFP_ATOMIC); |
| 3319 | rcu_read_unlock(); |
| 3320 | if (!bss_ies) |
| 3321 | return false; |
| 3322 | |
| 3323 | ieee802_11_parse_elems(bss_ies->data, bss_ies->len, |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3324 | false, &bss_elems, |
| 3325 | mgmt->bssid, |
| 3326 | assoc_data->bss->bssid); |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3327 | if (assoc_data->wmm && |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3328 | !elems->wmm_param && bss_elems.wmm_param) { |
| 3329 | elems->wmm_param = bss_elems.wmm_param; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3330 | sdata_info(sdata, |
| 3331 | "AP bug: WMM param missing from AssocResp\n"); |
| 3332 | } |
| 3333 | |
| 3334 | /* |
| 3335 | * Also check if we requested HT/VHT, otherwise the AP doesn't |
| 3336 | * have to include the IEs in the (re)association response. |
| 3337 | */ |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3338 | if (!elems->ht_cap_elem && bss_elems.ht_cap_elem && |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3339 | !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) { |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3340 | elems->ht_cap_elem = bss_elems.ht_cap_elem; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3341 | sdata_info(sdata, |
| 3342 | "AP bug: HT capability missing from AssocResp\n"); |
| 3343 | } |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3344 | if (!elems->ht_operation && bss_elems.ht_operation && |
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_operation = bss_elems.ht_operation; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3347 | sdata_info(sdata, |
| 3348 | "AP bug: HT operation missing from AssocResp\n"); |
| 3349 | } |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3350 | if (!elems->vht_cap_elem && bss_elems.vht_cap_elem && |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3351 | !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) { |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3352 | elems->vht_cap_elem = bss_elems.vht_cap_elem; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3353 | sdata_info(sdata, |
| 3354 | "AP bug: VHT capa missing from AssocResp\n"); |
| 3355 | } |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3356 | if (!elems->vht_operation && bss_elems.vht_operation && |
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_operation = bss_elems.vht_operation; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3359 | sdata_info(sdata, |
| 3360 | "AP bug: VHT operation missing from AssocResp\n"); |
| 3361 | } |
| 3362 | } |
| 3363 | |
| 3364 | /* |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3365 | * We previously checked these in the beacon/probe response, so |
| 3366 | * they should be present here. This is just a safety net. |
| 3367 | */ |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 3368 | if (!is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT) && |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3369 | (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) { |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3370 | sdata_info(sdata, |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3371 | "HT AP is missing WMM params or HT capability/operation\n"); |
| 3372 | ret = false; |
| 3373 | goto out; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3374 | } |
| 3375 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 3376 | if (!is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3377 | (!elems->vht_cap_elem || !elems->vht_operation)) { |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3378 | sdata_info(sdata, |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3379 | "VHT AP is missing VHT capability/operation\n"); |
| 3380 | ret = false; |
| 3381 | goto out; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3382 | } |
| 3383 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 3384 | if (is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && |
| 3385 | !elems->he_6ghz_capa) { |
| 3386 | sdata_info(sdata, |
| 3387 | "HE 6 GHz AP is missing HE 6 GHz band capability\n"); |
| 3388 | ret = false; |
| 3389 | goto out; |
| 3390 | } |
| 3391 | |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 3392 | mutex_lock(&sdata->local->sta_mtx); |
| 3393 | /* |
| 3394 | * station info was already allocated and inserted before |
| 3395 | * the association and should be available to us |
| 3396 | */ |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 3397 | sta = sta_info_get(sdata, cbss->bssid); |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 3398 | if (WARN_ON(!sta)) { |
| 3399 | mutex_unlock(&sdata->local->sta_mtx); |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3400 | ret = false; |
| 3401 | goto out; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3402 | } |
| 3403 | |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 3404 | sband = ieee80211_get_sband(sdata); |
| 3405 | if (!sband) { |
| 3406 | mutex_unlock(&sdata->local->sta_mtx); |
| 3407 | ret = false; |
| 3408 | goto out; |
| 3409 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3410 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3411 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3412 | (!elems->he_cap || !elems->he_operation)) { |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3413 | mutex_unlock(&sdata->local->sta_mtx); |
| 3414 | sdata_info(sdata, |
| 3415 | "HE AP is missing HE capability/operation\n"); |
| 3416 | ret = false; |
| 3417 | goto out; |
| 3418 | } |
| 3419 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3420 | /* Set up internal HT/VHT capabilities */ |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3421 | if (elems->ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 3422 | ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband, |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3423 | elems->ht_cap_elem, sta); |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 3424 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3425 | if (elems->vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
Mahesh Palivela | 818255e | 2012-10-10 11:33:04 +0000 | [diff] [blame] | 3426 | ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband, |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3427 | elems->vht_cap_elem, sta); |
Mahesh Palivela | 818255e | 2012-10-10 11:33:04 +0000 | [diff] [blame] | 3428 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3429 | if (elems->he_operation && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && |
| 3430 | elems->he_cap) { |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3431 | ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband, |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3432 | elems->he_cap, |
| 3433 | elems->he_cap_len, |
Johannes Berg | 1bb9a8a | 2020-05-28 21:34:38 +0200 | [diff] [blame] | 3434 | elems->he_6ghz_capa, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3435 | sta); |
| 3436 | |
| 3437 | bss_conf->he_support = sta->sta.he_cap.has_he; |
Shaul Triebitz | d46b4ab8 | 2020-03-26 15:09:33 +0200 | [diff] [blame] | 3438 | if (elems->rsnx && elems->rsnx_len && |
| 3439 | (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) && |
| 3440 | wiphy_ext_feature_isset(local->hw.wiphy, |
| 3441 | NL80211_EXT_FEATURE_PROTECTED_TWT)) |
| 3442 | bss_conf->twt_protected = true; |
| 3443 | else |
| 3444 | bss_conf->twt_protected = false; |
| 3445 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3446 | changed |= ieee80211_recalc_twt_req(sdata, sta, elems); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3447 | } else { |
| 3448 | bss_conf->he_support = false; |
Emmanuel Grumbach | 55ebd6e | 2018-12-15 11:03:04 +0200 | [diff] [blame] | 3449 | bss_conf->twt_requester = false; |
Shaul Triebitz | d46b4ab8 | 2020-03-26 15:09:33 +0200 | [diff] [blame] | 3450 | bss_conf->twt_protected = false; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3451 | } |
| 3452 | |
| 3453 | if (bss_conf->he_support) { |
John Crispin | dd56e90 | 2019-12-17 15:19:19 +0100 | [diff] [blame] | 3454 | bss_conf->he_bss_color.color = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3455 | le32_get_bits(elems->he_operation->he_oper_params, |
Naftali Goldstein | 77cbbc3 | 2018-09-05 08:06:07 +0300 | [diff] [blame] | 3456 | IEEE80211_HE_OPERATION_BSS_COLOR_MASK); |
John Crispin | dd56e90 | 2019-12-17 15:19:19 +0100 | [diff] [blame] | 3457 | bss_conf->he_bss_color.partial = |
| 3458 | le32_get_bits(elems->he_operation->he_oper_params, |
| 3459 | IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR); |
| 3460 | bss_conf->he_bss_color.disabled = |
| 3461 | le32_get_bits(elems->he_operation->he_oper_params, |
| 3462 | IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED); |
| 3463 | changed |= BSS_CHANGED_HE_BSS_COLOR; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3464 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3465 | bss_conf->htc_trig_based_pkt_ext = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3466 | le32_get_bits(elems->he_operation->he_oper_params, |
Naftali Goldstein | 77cbbc3 | 2018-09-05 08:06:07 +0300 | [diff] [blame] | 3467 | IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3468 | bss_conf->frame_time_rts_th = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3469 | le32_get_bits(elems->he_operation->he_oper_params, |
Naftali Goldstein | 77cbbc3 | 2018-09-05 08:06:07 +0300 | [diff] [blame] | 3470 | IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3471 | |
| 3472 | bss_conf->multi_sta_back_32bit = |
| 3473 | sta->sta.he_cap.he_cap_elem.mac_cap_info[2] & |
| 3474 | IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP; |
| 3475 | |
| 3476 | bss_conf->ack_enabled = |
| 3477 | sta->sta.he_cap.he_cap_elem.mac_cap_info[2] & |
| 3478 | IEEE80211_HE_MAC_CAP2_ACK_EN; |
| 3479 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3480 | bss_conf->uora_exists = !!elems->uora_element; |
| 3481 | if (elems->uora_element) |
| 3482 | bss_conf->uora_ocw_range = elems->uora_element[0]; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3483 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3484 | ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation); |
| 3485 | ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3486 | /* TODO: OPEN: what happens if BSS color disable is set? */ |
| 3487 | } |
| 3488 | |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3489 | if (cbss->transmitted_bss) { |
| 3490 | bss_conf->nontransmitted = true; |
| 3491 | ether_addr_copy(bss_conf->transmitter_bssid, |
| 3492 | cbss->transmitted_bss->bssid); |
| 3493 | bss_conf->bssid_indicator = cbss->max_bssid_indicator; |
| 3494 | bss_conf->bssid_index = cbss->bssid_index; |
| 3495 | } |
| 3496 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3497 | /* |
| 3498 | * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data |
| 3499 | * in their association response, so ignore that data for our own |
| 3500 | * configuration. If it changed since the last beacon, we'll get the |
| 3501 | * next beacon and update then. |
| 3502 | */ |
Johannes Berg | 1128958 | 2013-02-07 17:36:12 +0100 | [diff] [blame] | 3503 | |
Johannes Berg | bee7f586 | 2013-02-07 22:24:55 +0100 | [diff] [blame] | 3504 | /* |
| 3505 | * If an operating mode notification IE is present, override the |
| 3506 | * NSS calculation (that would be done in rate_control_rate_init()) |
| 3507 | * and use the # of streams from that element. |
| 3508 | */ |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3509 | if (elems->opmode_notif && |
| 3510 | !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) { |
Johannes Berg | bee7f586 | 2013-02-07 22:24:55 +0100 | [diff] [blame] | 3511 | u8 nss; |
| 3512 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3513 | nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK; |
Johannes Berg | bee7f586 | 2013-02-07 22:24:55 +0100 | [diff] [blame] | 3514 | nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT; |
| 3515 | nss += 1; |
| 3516 | sta->sta.rx_nss = nss; |
| 3517 | } |
| 3518 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 3519 | rate_control_rate_init(sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3520 | |
Tamizh chelvam | 93f0490 | 2015-10-07 10:40:04 +0530 | [diff] [blame] | 3521 | if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) { |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 3522 | set_sta_flag(sta, WLAN_STA_MFP); |
Tamizh chelvam | 93f0490 | 2015-10-07 10:40:04 +0530 | [diff] [blame] | 3523 | sta->sta.mfp = true; |
| 3524 | } else { |
| 3525 | sta->sta.mfp = false; |
| 3526 | } |
Jouni Malinen | 5394af4 | 2009-01-08 13:31:59 +0200 | [diff] [blame] | 3527 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3528 | sta->sta.wme = elems->wmm_param && local->hw.queues >= IEEE80211_NUM_ACS; |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 3529 | |
Johannes Berg | 3e4d40f | 2013-02-07 17:19:08 +0100 | [diff] [blame] | 3530 | err = sta_info_move_state(sta, IEEE80211_STA_ASSOC); |
Johannes Berg | c898787 | 2012-01-20 13:55:17 +0100 | [diff] [blame] | 3531 | if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT)) |
| 3532 | err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED); |
| 3533 | if (err) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3534 | sdata_info(sdata, |
| 3535 | "failed to move station %pM to desired state\n", |
| 3536 | sta->sta.addr); |
Johannes Berg | c898787 | 2012-01-20 13:55:17 +0100 | [diff] [blame] | 3537 | WARN_ON(__sta_info_destroy(sta)); |
| 3538 | mutex_unlock(&sdata->local->sta_mtx); |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3539 | ret = false; |
| 3540 | goto out; |
Johannes Berg | c898787 | 2012-01-20 13:55:17 +0100 | [diff] [blame] | 3541 | } |
| 3542 | |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 3543 | mutex_unlock(&sdata->local->sta_mtx); |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 3544 | |
Juuso Oikarinen | f2176d7 | 2010-09-28 14:39:32 +0300 | [diff] [blame] | 3545 | /* |
| 3546 | * Always handle WMM once after association regardless |
| 3547 | * of the first value the AP uses. Setting -1 here has |
| 3548 | * that effect because the AP values is an unsigned |
| 3549 | * 4-bit value. |
| 3550 | */ |
| 3551 | ifmgd->wmm_last_param_set = -1; |
Shaul Triebitz | 2e249fc | 2018-12-15 11:03:15 +0200 | [diff] [blame] | 3552 | ifmgd->mu_edca_last_param_set = -1; |
Juuso Oikarinen | f2176d7 | 2010-09-28 14:39:32 +0300 | [diff] [blame] | 3553 | |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 3554 | if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) { |
Johannes Berg | cec6628 | 2015-10-22 17:46:04 +0200 | [diff] [blame] | 3555 | ieee80211_set_wmm_default(sdata, false, false); |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3556 | } else if (!ieee80211_sta_wmm_params(local, sdata, elems->wmm_param, |
| 3557 | elems->wmm_param_len, |
| 3558 | elems->mu_edca_param_set)) { |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 3559 | /* still enable QoS since we might have HT/VHT */ |
| 3560 | ieee80211_set_wmm_default(sdata, false, true); |
| 3561 | /* set the disable-WMM flag in this case to disable |
| 3562 | * tracking WMM parameter changes in the beacon if |
| 3563 | * the parameters weren't actually valid. Doing so |
| 3564 | * avoids changing parameters very strangely when |
| 3565 | * the AP is going back and forth between valid and |
| 3566 | * invalid parameters. |
| 3567 | */ |
| 3568 | ifmgd->flags |= IEEE80211_STA_DISABLE_WMM; |
| 3569 | } |
Johannes Berg | 3abead5 | 2012-03-02 15:56:59 +0100 | [diff] [blame] | 3570 | changed |= BSS_CHANGED_QOS; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3571 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3572 | if (elems->max_idle_period_ie) { |
Avraham Stern | e38a017 | 2017-04-26 10:58:47 +0300 | [diff] [blame] | 3573 | bss_conf->max_idle_period = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3574 | le16_to_cpu(elems->max_idle_period_ie->max_idle_period); |
Avraham Stern | e38a017 | 2017-04-26 10:58:47 +0300 | [diff] [blame] | 3575 | bss_conf->protected_keep_alive = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3576 | !!(elems->max_idle_period_ie->idle_options & |
Avraham Stern | e38a017 | 2017-04-26 10:58:47 +0300 | [diff] [blame] | 3577 | WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE); |
| 3578 | changed |= BSS_CHANGED_KEEP_ALIVE; |
| 3579 | } else { |
| 3580 | bss_conf->max_idle_period = 0; |
| 3581 | bss_conf->protected_keep_alive = false; |
| 3582 | } |
| 3583 | |
Johannes Berg | 1db364c | 2020-04-17 12:38:04 +0200 | [diff] [blame] | 3584 | /* set assoc capability (AID was already set earlier), |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 3585 | * ieee80211_set_associated() will tell the driver */ |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 3586 | bss_conf->assoc_capability = capab_info; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 3587 | ieee80211_set_associated(sdata, cbss, changed); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3588 | |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 3589 | /* |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 3590 | * If we're using 4-addr mode, let the AP know that we're |
| 3591 | * doing so, so that it can create the STA VLAN on its side |
| 3592 | */ |
| 3593 | if (ifmgd->use_4addr) |
| 3594 | ieee80211_send_4addr_nullfunc(local, sdata); |
| 3595 | |
| 3596 | /* |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3597 | * Start timer to probe the connection to the AP now. |
| 3598 | * Also start the timer that will detect beacon loss. |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 3599 | */ |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3600 | ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt); |
Luis R. Rodriguez | d3a910a | 2010-09-16 15:12:32 -0400 | [diff] [blame] | 3601 | ieee80211_sta_reset_beacon_monitor(sdata); |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 3602 | |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3603 | ret = true; |
| 3604 | out: |
| 3605 | kfree(bss_ies); |
| 3606 | return ret; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3607 | } |
| 3608 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3609 | static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata, |
| 3610 | struct ieee80211_mgmt *mgmt, |
| 3611 | size_t len) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3612 | { |
| 3613 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3614 | struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; |
| 3615 | u16 capab_info, status_code, aid; |
| 3616 | struct ieee802_11_elems elems; |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 3617 | int ac, uapsd_queues = -1; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3618 | u8 *pos; |
| 3619 | bool reassoc; |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3620 | struct cfg80211_bss *bss; |
Emmanuel Grumbach | d0d1a12 | 2015-03-16 23:23:36 +0200 | [diff] [blame] | 3621 | struct ieee80211_event event = { |
| 3622 | .type = MLME_EVENT, |
| 3623 | .u.mlme.data = ASSOC_EVENT, |
| 3624 | }; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3625 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3626 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3627 | |
| 3628 | if (!assoc_data) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3629 | return; |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 3630 | if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid)) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3631 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3632 | |
| 3633 | /* |
| 3634 | * AssocResp and ReassocResp have identical structure, so process both |
| 3635 | * of them in this function. |
| 3636 | */ |
| 3637 | |
| 3638 | if (len < 24 + 6) |
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 | |
Simon Dinkin | 7a7d3e4 | 2017-08-31 13:09:36 +0300 | [diff] [blame] | 3641 | reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3642 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); |
| 3643 | status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); |
| 3644 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); |
| 3645 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3646 | sdata_info(sdata, |
| 3647 | "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n", |
| 3648 | reassoc ? "Rea" : "A", mgmt->sa, |
| 3649 | capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14)))); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3650 | |
Jouni Malinen | 39404fe | 2016-10-27 00:42:05 +0300 | [diff] [blame] | 3651 | if (assoc_data->fils_kek_len && |
| 3652 | fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0) |
| 3653 | return; |
| 3654 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3655 | pos = mgmt->u.assoc_resp.variable; |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3656 | ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems, |
| 3657 | mgmt->bssid, assoc_data->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3658 | |
| 3659 | if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY && |
Johannes Berg | 79ba1d8 | 2013-03-27 14:38:07 +0100 | [diff] [blame] | 3660 | elems.timeout_int && |
| 3661 | elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3662 | u32 tu, ms; |
Johannes Berg | 79ba1d8 | 2013-03-27 14:38:07 +0100 | [diff] [blame] | 3663 | tu = le32_to_cpu(elems.timeout_int->value); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3664 | ms = tu * 1024 / 1000; |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3665 | sdata_info(sdata, |
| 3666 | "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n", |
| 3667 | mgmt->sa, tu, ms); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3668 | assoc_data->timeout = jiffies + msecs_to_jiffies(ms); |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 3669 | assoc_data->timeout_started = true; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3670 | if (ms > IEEE80211_ASSOC_TIMEOUT) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3671 | run_again(sdata, assoc_data->timeout); |
| 3672 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3673 | } |
| 3674 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3675 | bss = assoc_data->bss; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3676 | |
| 3677 | if (status_code != WLAN_STATUS_SUCCESS) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3678 | sdata_info(sdata, "%pM denied association (code=%d)\n", |
| 3679 | mgmt->sa, status_code); |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 3680 | ieee80211_destroy_assoc_data(sdata, false, false); |
Emmanuel Grumbach | d0d1a12 | 2015-03-16 23:23:36 +0200 | [diff] [blame] | 3681 | event.u.mlme.status = MLME_DENIED; |
| 3682 | event.u.mlme.reason = status_code; |
| 3683 | drv_event_callback(sdata->local, sdata, &event); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3684 | } else { |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3685 | if (!ieee80211_assoc_success(sdata, bss, mgmt, len, &elems)) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3686 | /* oops -- internal error -- send timeout for now */ |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 3687 | ieee80211_destroy_assoc_data(sdata, false, false); |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 3688 | cfg80211_assoc_timeout(sdata->dev, bss); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3689 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3690 | } |
Emmanuel Grumbach | d0d1a12 | 2015-03-16 23:23:36 +0200 | [diff] [blame] | 3691 | event.u.mlme.status = MLME_SUCCESS; |
| 3692 | drv_event_callback(sdata->local, sdata, &event); |
John W. Linville | 635d999 | 2012-07-09 16:34:34 -0400 | [diff] [blame] | 3693 | sdata_info(sdata, "associated\n"); |
Johannes Berg | 79ebfb8 | 2012-02-20 14:19:58 +0100 | [diff] [blame] | 3694 | |
| 3695 | /* |
| 3696 | * destroy assoc_data afterwards, as otherwise an idle |
| 3697 | * recalc after assoc_data is NULL but before associated |
| 3698 | * is set can cause the interface to go idle |
| 3699 | */ |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 3700 | ieee80211_destroy_assoc_data(sdata, true, false); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 3701 | |
| 3702 | /* get uapsd queues configuration */ |
| 3703 | uapsd_queues = 0; |
| 3704 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) |
| 3705 | if (sdata->tx_conf[ac].uapsd) |
Emmanuel Grumbach | f438ceb | 2016-10-18 23:12:12 +0300 | [diff] [blame] | 3706 | uapsd_queues |= ieee80211_ac_to_qos_mask[ac]; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3707 | } |
| 3708 | |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 3709 | cfg80211_rx_assoc_resp(sdata->dev, bss, (u8 *)mgmt, len, uapsd_queues, |
| 3710 | ifmgd->assoc_req_ies, ifmgd->assoc_req_ies_len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3711 | } |
Johannes Berg | 8e3c1b7 | 2012-12-10 13:44:19 +0100 | [diff] [blame] | 3712 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3713 | static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 8e3c1b7 | 2012-12-10 13:44:19 +0100 | [diff] [blame] | 3714 | struct ieee80211_mgmt *mgmt, size_t len, |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3715 | struct ieee80211_rx_status *rx_status) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3716 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3717 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 3718 | struct ieee80211_bss *bss; |
Johannes Berg | fab7d4a | 2008-03-16 18:42:44 +0100 | [diff] [blame] | 3719 | struct ieee80211_channel *channel; |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 3720 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3721 | sdata_assert_lock(sdata); |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 3722 | |
Thomas Pedersen | 3b23c184 | 2020-04-01 18:18:05 -0700 | [diff] [blame] | 3723 | channel = ieee80211_get_channel_khz(local->hw.wiphy, |
| 3724 | ieee80211_rx_status_to_khz(rx_status)); |
Emmanuel Grumbach | 3afc216 | 2014-03-04 16:50:13 +0200 | [diff] [blame] | 3725 | if (!channel) |
Johannes Berg | 5bda617 | 2008-09-08 11:05:10 +0200 | [diff] [blame] | 3726 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3727 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3728 | bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel); |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 3729 | if (bss) { |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 3730 | sdata->vif.bss_conf.beacon_rate = bss->beacon_rate; |
Johannes Berg | d2722f8 | 2014-03-04 11:43:28 +0100 | [diff] [blame] | 3731 | ieee80211_rx_bss_put(local, bss); |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 3732 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3733 | } |
| 3734 | |
| 3735 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3736 | 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] | 3737 | struct sk_buff *skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3738 | { |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3739 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 3740 | struct ieee80211_if_managed *ifmgd; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3741 | struct ieee80211_rx_status *rx_status = (void *) skb->cb; |
Andrei Otcheretianski | 85b27ef | 2020-01-31 13:12:50 +0200 | [diff] [blame] | 3742 | struct ieee80211_channel *channel; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3743 | size_t baselen, len = skb->len; |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 3744 | |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 3745 | ifmgd = &sdata->u.mgd; |
| 3746 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3747 | sdata_assert_lock(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3748 | |
Andrei Otcheretianski | 85b27ef | 2020-01-31 13:12:50 +0200 | [diff] [blame] | 3749 | /* |
| 3750 | * According to Draft P802.11ax D6.0 clause 26.17.2.3.2: |
| 3751 | * "If a 6 GHz AP receives a Probe Request frame and responds with |
| 3752 | * a Probe Response frame [..], the Address 1 field of the Probe |
| 3753 | * Response frame shall be set to the broadcast address [..]" |
| 3754 | * So, on 6GHz band we should also accept broadcast responses. |
| 3755 | */ |
| 3756 | channel = ieee80211_get_channel(sdata->local->hw.wiphy, |
| 3757 | rx_status->freq); |
| 3758 | if (!channel) |
| 3759 | return; |
| 3760 | |
| 3761 | if (!ether_addr_equal(mgmt->da, sdata->vif.addr) && |
| 3762 | (channel->band != NL80211_BAND_6GHZ || |
| 3763 | !is_broadcast_ether_addr(mgmt->da))) |
Tomas Winkler | 8e7cdbb | 2008-08-03 14:32:01 +0300 | [diff] [blame] | 3764 | return; /* ignore ProbeResp to foreign address */ |
| 3765 | |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 3766 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; |
| 3767 | if (baselen > len) |
| 3768 | return; |
| 3769 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3770 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status); |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 3771 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3772 | if (ifmgd->associated && |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 3773 | ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 3774 | ieee80211_reset_ap_probe(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3775 | } |
| 3776 | |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 3777 | /* |
| 3778 | * This is the canonical list of information elements we care about, |
| 3779 | * 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] | 3780 | * (00:50:F2) vendor IE which is used for WMM which we need to track, |
| 3781 | * as well as the DTPC IE (part of the Cisco OUI) used for signaling |
| 3782 | * changes to requested client power. |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 3783 | * |
| 3784 | * We implement beacon filtering in software since that means we can |
| 3785 | * avoid processing the frame here and in cfg80211, and userspace |
| 3786 | * will not be able to tell whether the hardware supports it or not. |
| 3787 | * |
| 3788 | * XXX: This list needs to be dynamic -- userspace needs to be able to |
| 3789 | * add items it requires. It also needs to be able to tell us to |
| 3790 | * look out for other vendor IEs. |
| 3791 | */ |
| 3792 | static const u64 care_about_ies = |
Johannes Berg | 1d4df3a | 2009-04-22 11:25:43 +0200 | [diff] [blame] | 3793 | (1ULL << WLAN_EID_COUNTRY) | |
| 3794 | (1ULL << WLAN_EID_ERP_INFO) | |
| 3795 | (1ULL << WLAN_EID_CHANNEL_SWITCH) | |
| 3796 | (1ULL << WLAN_EID_PWR_CONSTRAINT) | |
| 3797 | (1ULL << WLAN_EID_HT_CAPABILITY) | |
Johannes Berg | 70a3fd6 | 2015-03-12 08:53:29 +0200 | [diff] [blame] | 3798 | (1ULL << WLAN_EID_HT_OPERATION) | |
| 3799 | (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN); |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 3800 | |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3801 | static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data *sdata, |
| 3802 | struct ieee80211_if_managed *ifmgd, |
| 3803 | struct ieee80211_bss_conf *bss_conf, |
| 3804 | struct ieee80211_local *local, |
| 3805 | struct ieee80211_rx_status *rx_status) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3806 | { |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3807 | /* Track average RSSI from the Beacon frames of the current AP */ |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3808 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3809 | if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) { |
| 3810 | ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE; |
Johannes Berg | 338c17a | 2015-08-28 10:52:54 +0200 | [diff] [blame] | 3811 | ewma_beacon_signal_init(&ifmgd->ave_beacon_signal); |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3812 | ifmgd->last_cqm_event_signal = 0; |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 3813 | ifmgd->count_beacon_signal = 1; |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3814 | ifmgd->last_ave_beacon_signal = 0; |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3815 | } else { |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 3816 | ifmgd->count_beacon_signal++; |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3817 | } |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3818 | |
Johannes Berg | 338c17a | 2015-08-28 10:52:54 +0200 | [diff] [blame] | 3819 | ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal); |
| 3820 | |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3821 | if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold && |
| 3822 | ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) { |
Johannes Berg | 338c17a | 2015-08-28 10:52:54 +0200 | [diff] [blame] | 3823 | int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal); |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3824 | int last_sig = ifmgd->last_ave_beacon_signal; |
Emmanuel Grumbach | a818292 | 2015-03-16 23:23:34 +0200 | [diff] [blame] | 3825 | struct ieee80211_event event = { |
| 3826 | .type = RSSI_EVENT, |
| 3827 | }; |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3828 | |
| 3829 | /* |
| 3830 | * if signal crosses either of the boundaries, invoke callback |
| 3831 | * with appropriate parameters |
| 3832 | */ |
| 3833 | if (sig > ifmgd->rssi_max_thold && |
| 3834 | (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) { |
| 3835 | ifmgd->last_ave_beacon_signal = sig; |
Emmanuel Grumbach | a818292 | 2015-03-16 23:23:34 +0200 | [diff] [blame] | 3836 | event.u.rssi.data = RSSI_EVENT_HIGH; |
| 3837 | drv_event_callback(local, sdata, &event); |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3838 | } else if (sig < ifmgd->rssi_min_thold && |
| 3839 | (last_sig >= ifmgd->rssi_max_thold || |
| 3840 | last_sig == 0)) { |
| 3841 | ifmgd->last_ave_beacon_signal = sig; |
Emmanuel Grumbach | a818292 | 2015-03-16 23:23:34 +0200 | [diff] [blame] | 3842 | event.u.rssi.data = RSSI_EVENT_LOW; |
| 3843 | drv_event_callback(local, sdata, &event); |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3844 | } |
| 3845 | } |
| 3846 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3847 | if (bss_conf->cqm_rssi_thold && |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 3848 | ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT && |
Johannes Berg | ea08635 | 2012-01-19 09:29:58 +0100 | [diff] [blame] | 3849 | !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) { |
Johannes Berg | 338c17a | 2015-08-28 10:52:54 +0200 | [diff] [blame] | 3850 | int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal); |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3851 | int last_event = ifmgd->last_cqm_event_signal; |
| 3852 | int thold = bss_conf->cqm_rssi_thold; |
| 3853 | int hyst = bss_conf->cqm_rssi_hyst; |
Johannes Berg | 338c17a | 2015-08-28 10:52:54 +0200 | [diff] [blame] | 3854 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3855 | if (sig < thold && |
| 3856 | (last_event == 0 || sig < last_event - hyst)) { |
| 3857 | ifmgd->last_cqm_event_signal = sig; |
| 3858 | ieee80211_cqm_rssi_notify( |
| 3859 | &sdata->vif, |
| 3860 | NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW, |
Andrzej Zaborowski | 769f07d | 2017-01-25 12:43:40 +0100 | [diff] [blame] | 3861 | sig, GFP_KERNEL); |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3862 | } else if (sig > thold && |
| 3863 | (last_event == 0 || sig > last_event + hyst)) { |
| 3864 | ifmgd->last_cqm_event_signal = sig; |
| 3865 | ieee80211_cqm_rssi_notify( |
| 3866 | &sdata->vif, |
| 3867 | NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, |
Andrzej Zaborowski | 769f07d | 2017-01-25 12:43:40 +0100 | [diff] [blame] | 3868 | sig, GFP_KERNEL); |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3869 | } |
| 3870 | } |
| 3871 | |
Andrew Zaborowski | 2c3c5f8c | 2017-02-10 04:50:22 +0100 | [diff] [blame] | 3872 | if (bss_conf->cqm_rssi_low && |
| 3873 | ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) { |
| 3874 | int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal); |
| 3875 | int last_event = ifmgd->last_cqm_event_signal; |
| 3876 | int low = bss_conf->cqm_rssi_low; |
| 3877 | int high = bss_conf->cqm_rssi_high; |
| 3878 | |
| 3879 | if (sig < low && |
| 3880 | (last_event == 0 || last_event >= low)) { |
| 3881 | ifmgd->last_cqm_event_signal = sig; |
| 3882 | ieee80211_cqm_rssi_notify( |
| 3883 | &sdata->vif, |
| 3884 | NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW, |
| 3885 | sig, GFP_KERNEL); |
| 3886 | } else if (sig > high && |
| 3887 | (last_event == 0 || last_event <= high)) { |
| 3888 | ifmgd->last_cqm_event_signal = sig; |
| 3889 | ieee80211_cqm_rssi_notify( |
| 3890 | &sdata->vif, |
| 3891 | NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, |
| 3892 | sig, GFP_KERNEL); |
| 3893 | } |
| 3894 | } |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3895 | } |
| 3896 | |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3897 | static bool ieee80211_rx_our_beacon(const u8 *tx_bssid, |
| 3898 | struct cfg80211_bss *bss) |
| 3899 | { |
| 3900 | if (ether_addr_equal(tx_bssid, bss->bssid)) |
| 3901 | return true; |
| 3902 | if (!bss->transmitted_bss) |
| 3903 | return false; |
| 3904 | return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid); |
| 3905 | } |
| 3906 | |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3907 | static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata, |
| 3908 | struct ieee80211_mgmt *mgmt, size_t len, |
| 3909 | struct ieee80211_rx_status *rx_status) |
| 3910 | { |
| 3911 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3912 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
| 3913 | size_t baselen; |
| 3914 | struct ieee802_11_elems elems; |
| 3915 | struct ieee80211_local *local = sdata->local; |
| 3916 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 3917 | struct ieee80211_channel *chan; |
| 3918 | struct sta_info *sta; |
| 3919 | u32 changed = 0; |
| 3920 | bool erp_valid; |
| 3921 | u8 erp_value = 0; |
| 3922 | u32 ncrc; |
| 3923 | u8 *bssid; |
| 3924 | u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
| 3925 | |
| 3926 | sdata_assert_lock(sdata); |
| 3927 | |
| 3928 | /* Process beacon from the current BSS */ |
| 3929 | baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; |
| 3930 | if (baselen > len) |
| 3931 | return; |
| 3932 | |
| 3933 | rcu_read_lock(); |
| 3934 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 3935 | if (!chanctx_conf) { |
| 3936 | rcu_read_unlock(); |
| 3937 | return; |
| 3938 | } |
| 3939 | |
Thomas Pedersen | 3b23c184 | 2020-04-01 18:18:05 -0700 | [diff] [blame] | 3940 | if (ieee80211_rx_status_to_khz(rx_status) != |
| 3941 | ieee80211_channel_to_khz(chanctx_conf->def.chan)) { |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3942 | rcu_read_unlock(); |
| 3943 | return; |
| 3944 | } |
| 3945 | chan = chanctx_conf->def.chan; |
| 3946 | rcu_read_unlock(); |
| 3947 | |
| 3948 | if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon && |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3949 | ieee80211_rx_our_beacon(mgmt->bssid, ifmgd->assoc_data->bss)) { |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3950 | ieee802_11_parse_elems(mgmt->u.beacon.variable, |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3951 | len - baselen, false, &elems, |
| 3952 | mgmt->bssid, |
| 3953 | ifmgd->assoc_data->bss->bssid); |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3954 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3955 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status); |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3956 | |
| 3957 | if (elems.dtim_period) |
| 3958 | ifmgd->dtim_period = elems.dtim_period; |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3959 | ifmgd->have_beacon = true; |
| 3960 | ifmgd->assoc_data->need_beacon = false; |
| 3961 | if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) { |
| 3962 | sdata->vif.bss_conf.sync_tsf = |
| 3963 | le64_to_cpu(mgmt->u.beacon.timestamp); |
| 3964 | sdata->vif.bss_conf.sync_device_ts = |
| 3965 | rx_status->device_timestamp; |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3966 | sdata->vif.bss_conf.sync_dtim_count = elems.dtim_count; |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3967 | } |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3968 | |
| 3969 | if (elems.mbssid_config_ie) |
| 3970 | bss_conf->profile_periodicity = |
| 3971 | elems.mbssid_config_ie->profile_periodicity; |
| 3972 | |
| 3973 | if (elems.ext_capab_len >= 11 && |
| 3974 | (elems.ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT)) |
| 3975 | bss_conf->ema_ap = true; |
| 3976 | |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3977 | /* continue assoc process */ |
| 3978 | ifmgd->assoc_data->timeout = jiffies; |
| 3979 | ifmgd->assoc_data->timeout_started = true; |
| 3980 | run_again(sdata, ifmgd->assoc_data->timeout); |
| 3981 | return; |
| 3982 | } |
| 3983 | |
| 3984 | if (!ifmgd->associated || |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3985 | !ieee80211_rx_our_beacon(mgmt->bssid, ifmgd->associated)) |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3986 | return; |
| 3987 | bssid = ifmgd->associated->bssid; |
| 3988 | |
| 3989 | if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL)) |
| 3990 | ieee80211_handle_beacon_sig(sdata, ifmgd, bss_conf, |
| 3991 | local, rx_status); |
Andrew Zaborowski | 2c3c5f8c | 2017-02-10 04:50:22 +0100 | [diff] [blame] | 3992 | |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 3993 | if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3994 | mlme_dbg_ratelimited(sdata, |
Johannes Berg | 112c31f | 2013-02-08 22:59:00 +0100 | [diff] [blame] | 3995 | "cancelling AP probe due to a received beacon\n"); |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 3996 | ieee80211_reset_ap_probe(sdata); |
Jouni Malinen | 9277818 | 2009-05-14 21:15:36 +0300 | [diff] [blame] | 3997 | } |
| 3998 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3999 | /* |
| 4000 | * Push the beacon loss detection into the future since |
| 4001 | * we are processing a beacon from the AP just now. |
| 4002 | */ |
Luis R. Rodriguez | d3a910a | 2010-09-16 15:12:32 -0400 | [diff] [blame] | 4003 | ieee80211_sta_reset_beacon_monitor(sdata); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4004 | |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 4005 | ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4); |
| 4006 | ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable, |
Johannes Berg | b2e506b | 2013-03-26 14:54:16 +0100 | [diff] [blame] | 4007 | len - baselen, false, &elems, |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 4008 | care_about_ies, ncrc, |
| 4009 | mgmt->bssid, bssid); |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 4010 | |
Johannes Berg | 90d13e8 | 2015-09-24 16:13:07 +0200 | [diff] [blame] | 4011 | if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) && |
Johannes Berg | 1db364c | 2020-04-17 12:38:04 +0200 | [diff] [blame] | 4012 | ieee80211_check_tim(elems.tim, elems.tim_len, bss_conf->aid)) { |
Johannes Berg | 90d13e8 | 2015-09-24 16:13:07 +0200 | [diff] [blame] | 4013 | if (local->hw.conf.dynamic_ps_timeout > 0) { |
| 4014 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 4015 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 4016 | ieee80211_hw_config(local, |
| 4017 | IEEE80211_CONF_CHANGE_PS); |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 4018 | } |
Johannes Berg | 076cdcb | 2015-09-24 16:14:55 +0200 | [diff] [blame] | 4019 | ieee80211_send_nullfunc(local, sdata, false); |
Johannes Berg | 90d13e8 | 2015-09-24 16:13:07 +0200 | [diff] [blame] | 4020 | } else if (!local->pspolling && sdata->u.mgd.powersave) { |
| 4021 | local->pspolling = true; |
| 4022 | |
| 4023 | /* |
| 4024 | * Here is assumed that the driver will be |
| 4025 | * able to send ps-poll frame and receive a |
| 4026 | * response even though power save mode is |
| 4027 | * enabled, but some drivers might require |
| 4028 | * to disable power save here. This needs |
| 4029 | * to be investigated. |
| 4030 | */ |
| 4031 | ieee80211_send_pspoll(local, sdata); |
Vivek Natarajan | a97b77b | 2008-12-23 18:39:02 -0800 | [diff] [blame] | 4032 | } |
| 4033 | } |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 4034 | |
Janusz.Dziedzic@tieto.com | b115b97 | 2015-10-27 08:38:40 +0100 | [diff] [blame] | 4035 | if (sdata->vif.p2p || |
| 4036 | sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) { |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 4037 | struct ieee80211_p2p_noa_attr noa = {}; |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 4038 | int ret; |
| 4039 | |
| 4040 | ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable, |
| 4041 | len - baselen, |
| 4042 | IEEE80211_P2P_ATTR_ABSENCE_NOTICE, |
Janusz Dziedzic | 934457e | 2013-03-21 15:47:55 +0100 | [diff] [blame] | 4043 | (u8 *) &noa, sizeof(noa)); |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 4044 | if (ret >= 2) { |
| 4045 | if (sdata->u.mgd.p2p_noa_index != noa.index) { |
| 4046 | /* valid noa_attr and index changed */ |
| 4047 | sdata->u.mgd.p2p_noa_index = noa.index; |
| 4048 | memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa)); |
| 4049 | changed |= BSS_CHANGED_P2P_PS; |
| 4050 | /* |
| 4051 | * make sure we update all information, the CRC |
| 4052 | * mechanism doesn't look at P2P attributes. |
| 4053 | */ |
| 4054 | ifmgd->beacon_crc_valid = false; |
| 4055 | } |
| 4056 | } else if (sdata->u.mgd.p2p_noa_index != -1) { |
| 4057 | /* noa_attr not found and we had valid noa_attr before */ |
| 4058 | sdata->u.mgd.p2p_noa_index = -1; |
| 4059 | 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] | 4060 | changed |= BSS_CHANGED_P2P_PS; |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 4061 | ifmgd->beacon_crc_valid = false; |
| 4062 | } |
| 4063 | } |
| 4064 | |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 4065 | if (ifmgd->csa_waiting_bcn) |
| 4066 | ieee80211_chswitch_post_beacon(sdata); |
| 4067 | |
Alexander Bondar | 2ecc390 | 2015-03-01 09:10:00 +0200 | [diff] [blame] | 4068 | /* |
| 4069 | * Update beacon timing and dtim count on every beacon appearance. This |
| 4070 | * will allow the driver to use the most updated values. Do it before |
| 4071 | * comparing this one with last received beacon. |
| 4072 | * IMPORTANT: These parameters would possibly be out of sync by the time |
| 4073 | * the driver will use them. The synchronized view is currently |
| 4074 | * guaranteed only in certain callbacks. |
| 4075 | */ |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 4076 | if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) { |
Alexander Bondar | 2ecc390 | 2015-03-01 09:10:00 +0200 | [diff] [blame] | 4077 | sdata->vif.bss_conf.sync_tsf = |
| 4078 | le64_to_cpu(mgmt->u.beacon.timestamp); |
| 4079 | sdata->vif.bss_conf.sync_device_ts = |
| 4080 | rx_status->device_timestamp; |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 4081 | sdata->vif.bss_conf.sync_dtim_count = elems.dtim_count; |
Alexander Bondar | 2ecc390 | 2015-03-01 09:10:00 +0200 | [diff] [blame] | 4082 | } |
| 4083 | |
Juuso Oikarinen | d8ec443 | 2010-10-01 16:02:31 +0300 | [diff] [blame] | 4084 | if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4085 | return; |
Jouni Malinen | 3019667 | 2009-05-19 17:01:43 +0300 | [diff] [blame] | 4086 | ifmgd->beacon_crc = ncrc; |
Juuso Oikarinen | d8ec443 | 2010-10-01 16:02:31 +0300 | [diff] [blame] | 4087 | ifmgd->beacon_crc_valid = true; |
Jouni Malinen | 3019667 | 2009-05-19 17:01:43 +0300 | [diff] [blame] | 4088 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 4089 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status); |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 4090 | |
Johannes Berg | d70b761 | 2013-08-23 15:48:48 +0200 | [diff] [blame] | 4091 | ieee80211_sta_process_chanswitch(sdata, rx_status->mactime, |
Luciano Coelho | 2ba4538 | 2014-10-08 09:48:35 +0300 | [diff] [blame] | 4092 | rx_status->device_timestamp, |
Johannes Berg | d70b761 | 2013-08-23 15:48:48 +0200 | [diff] [blame] | 4093 | &elems, true); |
| 4094 | |
Johannes Berg | 095d81c | 2013-10-15 12:25:07 +0200 | [diff] [blame] | 4095 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) && |
| 4096 | ieee80211_sta_wmm_params(local, sdata, elems.wmm_param, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4097 | elems.wmm_param_len, |
| 4098 | elems.mu_edca_param_set)) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 4099 | changed |= BSS_CHANGED_QOS; |
| 4100 | |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 4101 | /* |
| 4102 | * 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] | 4103 | * DTIM period (and beacon timing if desired) now. |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 4104 | */ |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 4105 | if (!ifmgd->have_beacon) { |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 4106 | /* a few bogus AP send dtim_period = 0 or no TIM IE */ |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 4107 | bss_conf->dtim_period = elems.dtim_period ?: 1; |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 4108 | |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 4109 | changed |= BSS_CHANGED_BEACON_INFO; |
| 4110 | ifmgd->have_beacon = true; |
Alexander Bondar | 482a9c7 | 2013-06-03 17:29:33 +0300 | [diff] [blame] | 4111 | |
| 4112 | mutex_lock(&local->iflist_mtx); |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 4113 | ieee80211_recalc_ps(local); |
Alexander Bondar | 482a9c7 | 2013-06-03 17:29:33 +0300 | [diff] [blame] | 4114 | mutex_unlock(&local->iflist_mtx); |
| 4115 | |
Alexander Bondar | ce85788 | 2013-05-06 17:17:04 +0300 | [diff] [blame] | 4116 | ieee80211_recalc_ps_vif(sdata); |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 4117 | } |
| 4118 | |
Johannes Berg | 1946bed | 2013-03-27 14:31:53 +0100 | [diff] [blame] | 4119 | if (elems.erp_info) { |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 4120 | erp_valid = true; |
| 4121 | erp_value = elems.erp_info[0]; |
| 4122 | } else { |
| 4123 | erp_valid = false; |
John W. Linville | 50c4afb | 2008-04-15 14:09:27 -0400 | [diff] [blame] | 4124 | } |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 4125 | changed |= ieee80211_handle_bss_capability(sdata, |
| 4126 | le16_to_cpu(mgmt->u.beacon.capab_info), |
| 4127 | erp_valid, erp_value); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4128 | |
Johannes Berg | 1128958 | 2013-02-07 17:36:12 +0100 | [diff] [blame] | 4129 | mutex_lock(&local->sta_mtx); |
Johannes Berg | bee7f586 | 2013-02-07 22:24:55 +0100 | [diff] [blame] | 4130 | sta = sta_info_get(sdata, bssid); |
| 4131 | |
John Crispin | c9d3245 | 2019-05-28 13:49:47 +0200 | [diff] [blame] | 4132 | changed |= ieee80211_recalc_twt_req(sdata, sta, &elems); |
| 4133 | |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 4134 | if (ieee80211_config_bw(sdata, sta, elems.ht_cap_elem, |
| 4135 | elems.vht_cap_elem, elems.ht_operation, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4136 | elems.vht_operation, elems.he_operation, |
| 4137 | bssid, &changed)) { |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 4138 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | 89f774e | 2016-01-25 15:46:36 +0200 | [diff] [blame] | 4139 | sdata_info(sdata, |
| 4140 | "failed to follow AP %pM bandwidth change, disconnect\n", |
| 4141 | bssid); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 4142 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
| 4143 | WLAN_REASON_DEAUTH_LEAVING, |
| 4144 | true, deauth_buf); |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 4145 | ieee80211_report_disconnect(sdata, deauth_buf, |
| 4146 | sizeof(deauth_buf), true, |
| 4147 | WLAN_REASON_DEAUTH_LEAVING); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4148 | return; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 4149 | } |
Johannes Berg | bee7f586 | 2013-02-07 22:24:55 +0100 | [diff] [blame] | 4150 | |
| 4151 | if (sta && elems.opmode_notif) |
| 4152 | ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif, |
Eyal Shapira | cf1e05c | 2015-12-08 16:04:36 +0200 | [diff] [blame] | 4153 | rx_status->band); |
Johannes Berg | 1128958 | 2013-02-07 17:36:12 +0100 | [diff] [blame] | 4154 | mutex_unlock(&local->sta_mtx); |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 4155 | |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 4156 | changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt, |
| 4157 | elems.country_elem, |
| 4158 | elems.country_elem_len, |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 4159 | elems.pwr_constr_elem, |
| 4160 | elems.cisco_dtpc_elem); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 4161 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4162 | ieee80211_bss_info_change_notify(sdata, changed); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4163 | } |
| 4164 | |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 4165 | void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, |
| 4166 | struct sk_buff *skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4167 | { |
| 4168 | struct ieee80211_rx_status *rx_status; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4169 | struct ieee80211_mgmt *mgmt; |
| 4170 | u16 fc; |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 4171 | struct ieee802_11_elems elems; |
| 4172 | int ies_len; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4173 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4174 | rx_status = (struct ieee80211_rx_status *) skb->cb; |
| 4175 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 4176 | fc = le16_to_cpu(mgmt->frame_control); |
| 4177 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4178 | sdata_lock(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 4179 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4180 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 4181 | case IEEE80211_STYPE_BEACON: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4182 | ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4183 | break; |
| 4184 | case IEEE80211_STYPE_PROBE_RESP: |
| 4185 | ieee80211_rx_mgmt_probe_resp(sdata, skb); |
| 4186 | break; |
| 4187 | case IEEE80211_STYPE_AUTH: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4188 | ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4189 | break; |
| 4190 | case IEEE80211_STYPE_DEAUTH: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4191 | ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4192 | break; |
| 4193 | case IEEE80211_STYPE_DISASSOC: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4194 | ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4195 | break; |
| 4196 | case IEEE80211_STYPE_ASSOC_RESP: |
| 4197 | case IEEE80211_STYPE_REASSOC_RESP: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4198 | ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4199 | break; |
| 4200 | case IEEE80211_STYPE_ACTION: |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 4201 | if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) { |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 4202 | ies_len = skb->len - |
| 4203 | offsetof(struct ieee80211_mgmt, |
| 4204 | u.action.u.chan_switch.variable); |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 4205 | |
| 4206 | if (ies_len < 0) |
| 4207 | break; |
| 4208 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 4209 | /* CSA IE cannot be overridden, no need for BSSID */ |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 4210 | ieee802_11_parse_elems( |
| 4211 | mgmt->u.action.u.chan_switch.variable, |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 4212 | ies_len, true, &elems, mgmt->bssid, NULL); |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 4213 | |
| 4214 | if (elems.parse_error) |
| 4215 | break; |
| 4216 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4217 | ieee80211_sta_process_chanswitch(sdata, |
Luciano Coelho | 2ba4538 | 2014-10-08 09:48:35 +0300 | [diff] [blame] | 4218 | rx_status->mactime, |
| 4219 | rx_status->device_timestamp, |
| 4220 | &elems, false); |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 4221 | } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) { |
| 4222 | ies_len = skb->len - |
| 4223 | offsetof(struct ieee80211_mgmt, |
| 4224 | u.action.u.ext_chan_switch.variable); |
| 4225 | |
| 4226 | if (ies_len < 0) |
| 4227 | break; |
| 4228 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 4229 | /* |
| 4230 | * extended CSA IE can't be overridden, no need for |
| 4231 | * BSSID |
| 4232 | */ |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 4233 | ieee802_11_parse_elems( |
| 4234 | mgmt->u.action.u.ext_chan_switch.variable, |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 4235 | ies_len, true, &elems, mgmt->bssid, NULL); |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 4236 | |
| 4237 | if (elems.parse_error) |
| 4238 | break; |
| 4239 | |
| 4240 | /* for the handling code pretend this was also an IE */ |
| 4241 | elems.ext_chansw_ie = |
| 4242 | &mgmt->u.action.u.ext_chan_switch.data; |
| 4243 | |
| 4244 | ieee80211_sta_process_chanswitch(sdata, |
Luciano Coelho | 2ba4538 | 2014-10-08 09:48:35 +0300 | [diff] [blame] | 4245 | rx_status->mactime, |
| 4246 | rx_status->device_timestamp, |
| 4247 | &elems, false); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 4248 | } |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 4249 | break; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 4250 | } |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4251 | sdata_unlock(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4252 | } |
| 4253 | |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4254 | static void ieee80211_sta_timer(struct timer_list *t) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4255 | { |
| 4256 | struct ieee80211_sub_if_data *sdata = |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4257 | from_timer(sdata, t, u.mgd.timer); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4258 | |
Stanislaw Gruszka | 9b7d72c | 2013-02-28 10:55:27 +0100 | [diff] [blame] | 4259 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4260 | } |
| 4261 | |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4262 | static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 6b684db | 2013-01-29 11:35:29 +0100 | [diff] [blame] | 4263 | u8 *bssid, u8 reason, bool tx) |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4264 | { |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 4265 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4266 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 4267 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason, |
Johannes Berg | 6b684db | 2013-01-29 11:35:29 +0100 | [diff] [blame] | 4268 | tx, frame_buf); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 4269 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 4270 | ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true, |
| 4271 | reason); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4272 | } |
| 4273 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4274 | static int ieee80211_auth(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4275 | { |
| 4276 | struct ieee80211_local *local = sdata->local; |
| 4277 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 4278 | struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data; |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4279 | u32 tx_flags = 0; |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4280 | u16 trans = 1; |
| 4281 | u16 status = 0; |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 4282 | u16 prepare_tx_duration = 0; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4283 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4284 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4285 | |
| 4286 | if (WARN_ON_ONCE(!auth_data)) |
| 4287 | return -EINVAL; |
| 4288 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4289 | auth_data->tries++; |
| 4290 | |
| 4291 | if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4292 | sdata_info(sdata, "authentication with %pM timed out\n", |
| 4293 | auth_data->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4294 | |
| 4295 | /* |
| 4296 | * Most likely AP is not in the range so remove the |
| 4297 | * bss struct for that AP. |
| 4298 | */ |
| 4299 | cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss); |
| 4300 | |
| 4301 | return -ETIMEDOUT; |
| 4302 | } |
| 4303 | |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 4304 | if (auth_data->algorithm == WLAN_AUTH_SAE) |
| 4305 | prepare_tx_duration = |
| 4306 | jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE); |
| 4307 | |
| 4308 | drv_mgd_prepare_tx(local, sdata, prepare_tx_duration); |
Johannes Berg | a1845fc | 2012-06-27 13:18:36 +0200 | [diff] [blame] | 4309 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4310 | sdata_info(sdata, "send auth to %pM (try %d/%d)\n", |
| 4311 | auth_data->bss->bssid, auth_data->tries, |
| 4312 | IEEE80211_AUTH_MAX_TRIES); |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 4313 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4314 | auth_data->expected_transaction = 2; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4315 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4316 | if (auth_data->algorithm == WLAN_AUTH_SAE) { |
| 4317 | trans = auth_data->sae_trans; |
| 4318 | status = auth_data->sae_status; |
| 4319 | auth_data->expected_transaction = trans; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4320 | } |
| 4321 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4322 | if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
| 4323 | tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS | |
| 4324 | IEEE80211_TX_INTFL_MLME_CONN_TX; |
| 4325 | |
| 4326 | ieee80211_send_auth(sdata, trans, auth_data->algorithm, status, |
| 4327 | auth_data->data, auth_data->data_len, |
| 4328 | auth_data->bss->bssid, |
| 4329 | auth_data->bss->bssid, NULL, 0, 0, |
| 4330 | tx_flags); |
| 4331 | |
Stanislaw Gruszka | 6211dd1 | 2013-05-17 13:43:04 +0200 | [diff] [blame] | 4332 | if (tx_flags == 0) { |
Ilan Peer | 407879b | 2018-04-20 13:49:20 +0300 | [diff] [blame] | 4333 | if (auth_data->algorithm == WLAN_AUTH_SAE) |
| 4334 | auth_data->timeout = jiffies + |
| 4335 | IEEE80211_AUTH_TIMEOUT_SAE; |
| 4336 | else |
| 4337 | auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT; |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4338 | } else { |
Johannes Berg | cb236d2 | 2013-07-29 23:07:43 +0200 | [diff] [blame] | 4339 | auth_data->timeout = |
| 4340 | round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG); |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4341 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4342 | |
Ilan Peer | 407879b | 2018-04-20 13:49:20 +0300 | [diff] [blame] | 4343 | auth_data->timeout_started = true; |
| 4344 | run_again(sdata, auth_data->timeout); |
| 4345 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4346 | return 0; |
| 4347 | } |
| 4348 | |
| 4349 | static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata) |
| 4350 | { |
| 4351 | struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data; |
| 4352 | struct ieee80211_local *local = sdata->local; |
| 4353 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4354 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4355 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4356 | assoc_data->tries++; |
| 4357 | if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4358 | sdata_info(sdata, "association with %pM timed out\n", |
| 4359 | assoc_data->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4360 | |
| 4361 | /* |
| 4362 | * Most likely AP is not in the range so remove the |
| 4363 | * bss struct for that AP. |
| 4364 | */ |
| 4365 | cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss); |
| 4366 | |
| 4367 | return -ETIMEDOUT; |
| 4368 | } |
| 4369 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4370 | sdata_info(sdata, "associate with %pM (try %d/%d)\n", |
| 4371 | assoc_data->bss->bssid, assoc_data->tries, |
| 4372 | IEEE80211_ASSOC_MAX_TRIES); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4373 | ieee80211_send_assoc(sdata); |
| 4374 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 4375 | if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) { |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4376 | assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT; |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4377 | assoc_data->timeout_started = true; |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4378 | run_again(sdata, assoc_data->timeout); |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4379 | } else { |
Johannes Berg | cb236d2 | 2013-07-29 23:07:43 +0200 | [diff] [blame] | 4380 | assoc_data->timeout = |
| 4381 | round_jiffies_up(jiffies + |
| 4382 | IEEE80211_ASSOC_TIMEOUT_LONG); |
| 4383 | assoc_data->timeout_started = true; |
| 4384 | run_again(sdata, assoc_data->timeout); |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4385 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4386 | |
| 4387 | return 0; |
| 4388 | } |
| 4389 | |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4390 | void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata, |
| 4391 | __le16 fc, bool acked) |
| 4392 | { |
| 4393 | struct ieee80211_local *local = sdata->local; |
| 4394 | |
| 4395 | sdata->u.mgd.status_fc = fc; |
| 4396 | sdata->u.mgd.status_acked = acked; |
| 4397 | sdata->u.mgd.status_received = true; |
| 4398 | |
| 4399 | ieee80211_queue_work(&local->hw, &sdata->work); |
| 4400 | } |
| 4401 | |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 4402 | void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 4403 | { |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 4404 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 4405 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 4406 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4407 | sdata_lock(sdata); |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 4408 | |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4409 | if (ifmgd->status_received) { |
| 4410 | __le16 fc = ifmgd->status_fc; |
| 4411 | bool status_acked = ifmgd->status_acked; |
| 4412 | |
| 4413 | ifmgd->status_received = false; |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4414 | if (ifmgd->auth_data && ieee80211_is_auth(fc)) { |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4415 | if (status_acked) { |
Ilan Peer | 407879b | 2018-04-20 13:49:20 +0300 | [diff] [blame] | 4416 | if (ifmgd->auth_data->algorithm == |
| 4417 | WLAN_AUTH_SAE) |
| 4418 | ifmgd->auth_data->timeout = |
| 4419 | jiffies + |
| 4420 | IEEE80211_AUTH_TIMEOUT_SAE; |
| 4421 | else |
| 4422 | ifmgd->auth_data->timeout = |
| 4423 | jiffies + |
| 4424 | IEEE80211_AUTH_TIMEOUT_SHORT; |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4425 | run_again(sdata, ifmgd->auth_data->timeout); |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4426 | } else { |
| 4427 | ifmgd->auth_data->timeout = jiffies - 1; |
| 4428 | } |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4429 | ifmgd->auth_data->timeout_started = true; |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4430 | } else if (ifmgd->assoc_data && |
| 4431 | (ieee80211_is_assoc_req(fc) || |
| 4432 | ieee80211_is_reassoc_req(fc))) { |
| 4433 | if (status_acked) { |
| 4434 | ifmgd->assoc_data->timeout = |
| 4435 | jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT; |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4436 | run_again(sdata, ifmgd->assoc_data->timeout); |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4437 | } else { |
| 4438 | ifmgd->assoc_data->timeout = jiffies - 1; |
| 4439 | } |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4440 | ifmgd->assoc_data->timeout_started = true; |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4441 | } |
| 4442 | } |
| 4443 | |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4444 | if (ifmgd->auth_data && ifmgd->auth_data->timeout_started && |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4445 | time_after(jiffies, ifmgd->auth_data->timeout)) { |
| 4446 | if (ifmgd->auth_data->done) { |
| 4447 | /* |
| 4448 | * ok ... we waited for assoc but userspace didn't, |
| 4449 | * so let's just kill the auth data |
| 4450 | */ |
| 4451 | ieee80211_destroy_auth_data(sdata, false); |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4452 | } else if (ieee80211_auth(sdata)) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4453 | u8 bssid[ETH_ALEN]; |
Emmanuel Grumbach | a940909 | 2015-03-16 23:23:35 +0200 | [diff] [blame] | 4454 | struct ieee80211_event event = { |
| 4455 | .type = MLME_EVENT, |
| 4456 | .u.mlme.data = AUTH_EVENT, |
| 4457 | .u.mlme.status = MLME_TIMEOUT, |
| 4458 | }; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4459 | |
| 4460 | memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN); |
| 4461 | |
| 4462 | ieee80211_destroy_auth_data(sdata, false); |
| 4463 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 4464 | cfg80211_auth_timeout(sdata->dev, bssid); |
Emmanuel Grumbach | a940909 | 2015-03-16 23:23:35 +0200 | [diff] [blame] | 4465 | drv_event_callback(sdata->local, sdata, &event); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4466 | } |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4467 | } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4468 | run_again(sdata, ifmgd->auth_data->timeout); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4469 | |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4470 | if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started && |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4471 | time_after(jiffies, ifmgd->assoc_data->timeout)) { |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 4472 | if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) || |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4473 | ieee80211_do_assoc(sdata)) { |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 4474 | struct cfg80211_bss *bss = ifmgd->assoc_data->bss; |
Emmanuel Grumbach | d0d1a12 | 2015-03-16 23:23:36 +0200 | [diff] [blame] | 4475 | struct ieee80211_event event = { |
| 4476 | .type = MLME_EVENT, |
| 4477 | .u.mlme.data = ASSOC_EVENT, |
| 4478 | .u.mlme.status = MLME_TIMEOUT, |
| 4479 | }; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4480 | |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 4481 | ieee80211_destroy_assoc_data(sdata, false, false); |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 4482 | cfg80211_assoc_timeout(sdata->dev, bss); |
Emmanuel Grumbach | d0d1a12 | 2015-03-16 23:23:36 +0200 | [diff] [blame] | 4483 | drv_event_callback(sdata->local, sdata, &event); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4484 | } |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4485 | } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4486 | run_again(sdata, ifmgd->assoc_data->timeout); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4487 | |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 4488 | if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL && |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4489 | ifmgd->associated) { |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 4490 | u8 bssid[ETH_ALEN]; |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 4491 | int max_tries; |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 4492 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 4493 | memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 4494 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 4495 | if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 4496 | max_tries = max_nullfunc_tries; |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 4497 | else |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 4498 | max_tries = max_probe_tries; |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 4499 | |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 4500 | /* ACK received for nullfunc probing frame */ |
| 4501 | if (!ifmgd->probe_send_count) |
| 4502 | ieee80211_reset_ap_probe(sdata); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4503 | else if (ifmgd->nullfunc_failed) { |
| 4504 | if (ifmgd->probe_send_count < max_tries) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4505 | mlme_dbg(sdata, |
| 4506 | "No ack for nullfunc frame to AP %pM, try %d/%i\n", |
| 4507 | bssid, ifmgd->probe_send_count, |
| 4508 | max_tries); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4509 | ieee80211_mgd_probe_ap_send(sdata); |
| 4510 | } else { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4511 | mlme_dbg(sdata, |
| 4512 | "No ack for nullfunc frame to AP %pM, disconnecting.\n", |
| 4513 | bssid); |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 4514 | ieee80211_sta_connection_lost(sdata, bssid, |
Johannes Berg | 6b684db | 2013-01-29 11:35:29 +0100 | [diff] [blame] | 4515 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, |
| 4516 | false); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4517 | } |
| 4518 | } else if (time_is_after_jiffies(ifmgd->probe_timeout)) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4519 | run_again(sdata, ifmgd->probe_timeout); |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 4520 | else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4521 | mlme_dbg(sdata, |
| 4522 | "Failed to send nullfunc to AP %pM after %dms, disconnecting\n", |
| 4523 | bssid, probe_wait_ms); |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 4524 | ieee80211_sta_connection_lost(sdata, bssid, |
Johannes Berg | 6b684db | 2013-01-29 11:35:29 +0100 | [diff] [blame] | 4525 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4526 | } else if (ifmgd->probe_send_count < max_tries) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4527 | mlme_dbg(sdata, |
| 4528 | "No probe response from AP %pM after %dms, try %d/%i\n", |
| 4529 | bssid, probe_wait_ms, |
| 4530 | ifmgd->probe_send_count, max_tries); |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 4531 | ieee80211_mgd_probe_ap_send(sdata); |
| 4532 | } else { |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4533 | /* |
| 4534 | * We actually lost the connection ... or did we? |
| 4535 | * Let's make sure! |
| 4536 | */ |
Johannes Berg | 89f774e | 2016-01-25 15:46:36 +0200 | [diff] [blame] | 4537 | mlme_dbg(sdata, |
| 4538 | "No probe response from AP %pM after %dms, disconnecting.\n", |
| 4539 | bssid, probe_wait_ms); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4540 | |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 4541 | ieee80211_sta_connection_lost(sdata, bssid, |
Johannes Berg | 6b684db | 2013-01-29 11:35:29 +0100 | [diff] [blame] | 4542 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4543 | } |
| 4544 | } |
| 4545 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4546 | sdata_unlock(sdata); |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 4547 | } |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 4548 | |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4549 | static void ieee80211_sta_bcn_mon_timer(struct timer_list *t) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4550 | { |
| 4551 | struct ieee80211_sub_if_data *sdata = |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4552 | from_timer(sdata, t, u.mgd.bcn_mon_timer); |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 4553 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4554 | |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 4555 | if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn) |
Michal Kazior | e5593f5 | 2014-04-09 15:45:36 +0200 | [diff] [blame] | 4556 | return; |
| 4557 | |
Johannes Berg | 682bd38 | 2013-01-29 13:13:50 +0100 | [diff] [blame] | 4558 | sdata->u.mgd.connection_loss = false; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 4559 | ieee80211_queue_work(&sdata->local->hw, |
| 4560 | &sdata->u.mgd.beacon_connection_loss_work); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4561 | } |
| 4562 | |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4563 | static void ieee80211_sta_conn_mon_timer(struct timer_list *t) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4564 | { |
| 4565 | struct ieee80211_sub_if_data *sdata = |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4566 | from_timer(sdata, t, u.mgd.conn_mon_timer); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4567 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 4568 | struct ieee80211_local *local = sdata->local; |
| 4569 | |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 4570 | if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn) |
Michal Kazior | e5593f5 | 2014-04-09 15:45:36 +0200 | [diff] [blame] | 4571 | return; |
| 4572 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 4573 | ieee80211_queue_work(&local->hw, &ifmgd->monitor_work); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4574 | } |
| 4575 | |
| 4576 | static void ieee80211_sta_monitor_work(struct work_struct *work) |
| 4577 | { |
| 4578 | struct ieee80211_sub_if_data *sdata = |
| 4579 | container_of(work, struct ieee80211_sub_if_data, |
| 4580 | u.mgd.monitor_work); |
| 4581 | |
| 4582 | ieee80211_mgd_probe_ap(sdata, false); |
| 4583 | } |
| 4584 | |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 4585 | static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata) |
| 4586 | { |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 4587 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 4588 | __ieee80211_stop_poll(sdata); |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 4589 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4590 | /* let's probe the connection once */ |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 4591 | if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR)) |
Eliad Peller | 494f1fe | 2012-02-19 15:26:09 +0200 | [diff] [blame] | 4592 | ieee80211_queue_work(&sdata->local->hw, |
| 4593 | &sdata->u.mgd.monitor_work); |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 4594 | } |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 4595 | } |
| 4596 | |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4597 | #ifdef CONFIG_PM |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4598 | void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata) |
| 4599 | { |
| 4600 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 4601 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
| 4602 | |
| 4603 | sdata_lock(sdata); |
| 4604 | |
Emmanuel Grumbach | c52666a | 2014-05-13 12:54:09 +0300 | [diff] [blame] | 4605 | if (ifmgd->auth_data || ifmgd->assoc_data) { |
| 4606 | const u8 *bssid = ifmgd->auth_data ? |
| 4607 | ifmgd->auth_data->bss->bssid : |
| 4608 | ifmgd->assoc_data->bss->bssid; |
| 4609 | |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4610 | /* |
Emmanuel Grumbach | c52666a | 2014-05-13 12:54:09 +0300 | [diff] [blame] | 4611 | * If we are trying to authenticate / associate while suspending, |
| 4612 | * cfg80211 won't know and won't actually abort those attempts, |
| 4613 | * thus we need to do that ourselves. |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4614 | */ |
Johannes Berg | 4b08d1b | 2019-08-30 14:24:51 +0300 | [diff] [blame] | 4615 | ieee80211_send_deauth_disassoc(sdata, bssid, bssid, |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4616 | IEEE80211_STYPE_DEAUTH, |
| 4617 | WLAN_REASON_DEAUTH_LEAVING, |
| 4618 | false, frame_buf); |
Emmanuel Grumbach | c52666a | 2014-05-13 12:54:09 +0300 | [diff] [blame] | 4619 | if (ifmgd->assoc_data) |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 4620 | ieee80211_destroy_assoc_data(sdata, false, true); |
Emmanuel Grumbach | c52666a | 2014-05-13 12:54:09 +0300 | [diff] [blame] | 4621 | if (ifmgd->auth_data) |
| 4622 | ieee80211_destroy_auth_data(sdata, false); |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4623 | cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf, |
| 4624 | IEEE80211_DEAUTH_FRAME_LEN); |
| 4625 | } |
| 4626 | |
Johannes Berg | be72afe | 2015-03-01 09:10:03 +0200 | [diff] [blame] | 4627 | /* This is a bit of a hack - we should find a better and more generic |
| 4628 | * solution to this. Normally when suspending, cfg80211 will in fact |
| 4629 | * deauthenticate. However, it doesn't (and cannot) stop an ongoing |
| 4630 | * auth (not so important) or assoc (this is the problem) process. |
| 4631 | * |
| 4632 | * As a consequence, it can happen that we are in the process of both |
| 4633 | * associating and suspending, and receive an association response |
| 4634 | * after cfg80211 has checked if it needs to disconnect, but before |
| 4635 | * we actually set the flag to drop incoming frames. This will then |
| 4636 | * cause the workqueue flush to process the association response in |
| 4637 | * the suspend, resulting in a successful association just before it |
| 4638 | * tries to remove the interface from the driver, which now though |
| 4639 | * has a channel context assigned ... this results in issues. |
| 4640 | * |
| 4641 | * To work around this (for now) simply deauth here again if we're |
| 4642 | * now connected. |
| 4643 | */ |
| 4644 | if (ifmgd->associated && !sdata->local->wowlan) { |
| 4645 | u8 bssid[ETH_ALEN]; |
| 4646 | struct cfg80211_deauth_request req = { |
| 4647 | .reason_code = WLAN_REASON_DEAUTH_LEAVING, |
| 4648 | .bssid = bssid, |
| 4649 | }; |
| 4650 | |
| 4651 | memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN); |
| 4652 | ieee80211_mgd_deauth(sdata, &req); |
| 4653 | } |
| 4654 | |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4655 | sdata_unlock(sdata); |
| 4656 | } |
| 4657 | |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4658 | void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata) |
| 4659 | { |
| 4660 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 4661 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4662 | sdata_lock(sdata); |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4663 | if (!ifmgd->associated) { |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4664 | sdata_unlock(sdata); |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4665 | return; |
| 4666 | } |
| 4667 | |
| 4668 | if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) { |
| 4669 | sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME; |
| 4670 | mlme_dbg(sdata, "driver requested disconnect after resume\n"); |
| 4671 | ieee80211_sta_connection_lost(sdata, |
| 4672 | ifmgd->associated->bssid, |
| 4673 | WLAN_REASON_UNSPECIFIED, |
| 4674 | true); |
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 | } |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4678 | sdata_unlock(sdata); |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4679 | } |
| 4680 | #endif |
| 4681 | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 4682 | /* interface setup */ |
| 4683 | void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata) |
| 4684 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 4685 | struct ieee80211_if_managed *ifmgd; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 4686 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 4687 | ifmgd = &sdata->u.mgd; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4688 | INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 4689 | INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 4690 | INIT_WORK(&ifmgd->beacon_connection_loss_work, |
| 4691 | ieee80211_beacon_connection_loss_work); |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 4692 | INIT_WORK(&ifmgd->csa_connection_drop_work, |
| 4693 | ieee80211_csa_connection_drop_work); |
Emmanuel Grumbach | 687da13 | 2013-10-01 16:45:43 +0300 | [diff] [blame] | 4694 | INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work); |
Arik Nemtsov | 81dd2b8 | 2014-07-17 17:14:25 +0300 | [diff] [blame] | 4695 | INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work, |
| 4696 | ieee80211_tdls_peer_del_work); |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4697 | timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0); |
| 4698 | timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0); |
| 4699 | timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0); |
| 4700 | timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0); |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 4701 | INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk, |
| 4702 | ieee80211_sta_handle_tspec_ac_params_wk); |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 4703 | |
Johannes Berg | ab1faea | 2009-07-01 21:41:17 +0200 | [diff] [blame] | 4704 | ifmgd->flags = 0; |
Mohammed Shafi Shajakhan | 1478acb | 2011-12-14 19:46:08 +0530 | [diff] [blame] | 4705 | ifmgd->powersave = sdata->wdev.ps; |
Alexander Bondar | 219c386 | 2013-01-22 16:52:23 +0200 | [diff] [blame] | 4706 | ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues; |
| 4707 | ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len; |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 4708 | ifmgd->p2p_noa_index = -1; |
Johannes Berg | bbbdff9 | 2009-04-16 13:27:42 +0200 | [diff] [blame] | 4709 | |
Eliad Peller | 0d8614b | 2014-09-10 14:07:36 +0300 | [diff] [blame] | 4710 | if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS) |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 4711 | ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC; |
| 4712 | else |
| 4713 | ifmgd->req_smps = IEEE80211_SMPS_OFF; |
Liad Kaufman | 1277b4a | 2014-11-09 18:50:08 +0200 | [diff] [blame] | 4714 | |
| 4715 | /* Setup TDLS data */ |
| 4716 | spin_lock_init(&ifmgd->teardown_lock); |
| 4717 | ifmgd->teardown_skb = NULL; |
| 4718 | ifmgd->orig_teardown_skb = NULL; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 4719 | } |
| 4720 | |
| 4721 | /* scan finished notification */ |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 4722 | void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local) |
| 4723 | { |
Johannes Berg | 31ee67a | 2012-07-06 21:18:24 +0200 | [diff] [blame] | 4724 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 4725 | |
| 4726 | /* Restart STA timers */ |
| 4727 | rcu_read_lock(); |
Ben Greear | 370bd00 | 2013-03-19 17:50:50 -0700 | [diff] [blame] | 4728 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
| 4729 | if (ieee80211_sdata_running(sdata)) |
| 4730 | ieee80211_restart_sta_timer(sdata); |
| 4731 | } |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 4732 | rcu_read_unlock(); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 4733 | } |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 4734 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4735 | static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata, |
| 4736 | struct cfg80211_bss *cbss) |
| 4737 | { |
| 4738 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 4739 | const u8 *ht_cap_ie, *vht_cap_ie; |
| 4740 | const struct ieee80211_ht_cap *ht_cap; |
| 4741 | const struct ieee80211_vht_cap *vht_cap; |
| 4742 | u8 chains = 1; |
| 4743 | |
| 4744 | if (ifmgd->flags & IEEE80211_STA_DISABLE_HT) |
| 4745 | return chains; |
| 4746 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 4747 | ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY); |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4748 | if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) { |
| 4749 | ht_cap = (void *)(ht_cap_ie + 2); |
| 4750 | chains = ieee80211_mcs_to_chains(&ht_cap->mcs); |
| 4751 | /* |
| 4752 | * TODO: use "Tx Maximum Number Spatial Streams Supported" and |
| 4753 | * "Tx Unequal Modulation Supported" fields. |
| 4754 | */ |
| 4755 | } |
| 4756 | |
| 4757 | if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT) |
| 4758 | return chains; |
| 4759 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 4760 | vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY); |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4761 | if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) { |
| 4762 | u8 nss; |
| 4763 | u16 tx_mcs_map; |
| 4764 | |
| 4765 | vht_cap = (void *)(vht_cap_ie + 2); |
| 4766 | tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map); |
| 4767 | for (nss = 8; nss > 0; nss--) { |
| 4768 | if (((tx_mcs_map >> (2 * (nss - 1))) & 3) != |
| 4769 | IEEE80211_VHT_MCS_NOT_SUPPORTED) |
| 4770 | break; |
| 4771 | } |
| 4772 | /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */ |
| 4773 | chains = max(chains, nss); |
| 4774 | } |
| 4775 | |
| 4776 | return chains; |
| 4777 | } |
| 4778 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4779 | static bool |
| 4780 | ieee80211_verify_sta_he_mcs_support(struct ieee80211_supported_band *sband, |
| 4781 | const struct ieee80211_he_operation *he_op) |
| 4782 | { |
| 4783 | const struct ieee80211_sta_he_cap *sta_he_cap = |
| 4784 | ieee80211_get_he_sta_cap(sband); |
Gustavo A. R. Silva | 47aa786 | 2018-06-18 07:41:34 -0500 | [diff] [blame] | 4785 | u16 ap_min_req_set; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4786 | int i; |
| 4787 | |
| 4788 | if (!sta_he_cap || !he_op) |
| 4789 | return false; |
| 4790 | |
Gustavo A. R. Silva | 47aa786 | 2018-06-18 07:41:34 -0500 | [diff] [blame] | 4791 | ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set); |
| 4792 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4793 | /* Need to go over for 80MHz, 160MHz and for 80+80 */ |
| 4794 | for (i = 0; i < 3; i++) { |
| 4795 | const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp = |
| 4796 | &sta_he_cap->he_mcs_nss_supp; |
| 4797 | u16 sta_mcs_map_rx = |
| 4798 | le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]); |
| 4799 | u16 sta_mcs_map_tx = |
| 4800 | le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]); |
| 4801 | u8 nss; |
| 4802 | bool verified = true; |
| 4803 | |
| 4804 | /* |
| 4805 | * For each band there is a maximum of 8 spatial streams |
| 4806 | * possible. Each of the sta_mcs_map_* is a 16-bit struct built |
| 4807 | * of 2 bits per NSS (1-8), with the values defined in enum |
| 4808 | * ieee80211_he_mcs_support. Need to make sure STA TX and RX |
| 4809 | * capabilities aren't less than the AP's minimum requirements |
| 4810 | * for this HE BSS per SS. |
| 4811 | * It is enough to find one such band that meets the reqs. |
| 4812 | */ |
| 4813 | for (nss = 8; nss > 0; nss--) { |
| 4814 | u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3; |
| 4815 | u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3; |
| 4816 | u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3; |
| 4817 | |
| 4818 | if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED) |
| 4819 | continue; |
| 4820 | |
| 4821 | /* |
| 4822 | * Make sure the HE AP doesn't require MCSs that aren't |
| 4823 | * supported by the client |
| 4824 | */ |
| 4825 | if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED || |
| 4826 | sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED || |
| 4827 | (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) { |
| 4828 | verified = false; |
| 4829 | break; |
| 4830 | } |
| 4831 | } |
| 4832 | |
| 4833 | if (verified) |
| 4834 | return true; |
| 4835 | } |
| 4836 | |
| 4837 | /* If here, STA doesn't meet AP's HE min requirements */ |
| 4838 | return false; |
| 4839 | } |
| 4840 | |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 4841 | static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata, |
| 4842 | struct cfg80211_bss *cbss) |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 4843 | { |
| 4844 | struct ieee80211_local *local = sdata->local; |
| 4845 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Eliad Peller | 53b954e | 2014-07-24 11:20:05 +0300 | [diff] [blame] | 4846 | const struct ieee80211_ht_cap *ht_cap = NULL; |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4847 | const struct ieee80211_ht_operation *ht_oper = NULL; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4848 | const struct ieee80211_vht_operation *vht_oper = NULL; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4849 | const struct ieee80211_he_operation *he_oper = NULL; |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4850 | struct ieee80211_supported_band *sband; |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 4851 | struct cfg80211_chan_def chandef; |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 4852 | bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ; |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 4853 | struct ieee80211_bss *bss = (void *)cbss->priv; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4854 | int ret; |
Arik Nemtsov | 52a45f3 | 2015-08-15 22:39:53 +0300 | [diff] [blame] | 4855 | u32 i; |
| 4856 | bool have_80mhz; |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 4857 | |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4858 | sband = local->hw.wiphy->bands[cbss->channel->band]; |
| 4859 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4860 | ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ | |
| 4861 | IEEE80211_STA_DISABLE_80P80MHZ | |
| 4862 | IEEE80211_STA_DISABLE_160MHZ); |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4863 | |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 4864 | /* disable HT/VHT/HE if we don't support them */ |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 4865 | if (!sband->ht_cap.ht_supported && !is_6ghz) { |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 4866 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
| 4867 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
| 4868 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
| 4869 | } |
| 4870 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 4871 | if (!sband->vht_cap.vht_supported && !is_6ghz) { |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 4872 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 4873 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
| 4874 | } |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 4875 | |
| 4876 | if (!ieee80211_get_he_sta_cap(sband)) |
| 4877 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
| 4878 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 4879 | rcu_read_lock(); |
| 4880 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 4881 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) && !is_6ghz) { |
Eliad Peller | 53b954e | 2014-07-24 11:20:05 +0300 | [diff] [blame] | 4882 | const u8 *ht_oper_ie, *ht_cap_ie; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4883 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 4884 | ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION); |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4885 | if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper)) |
| 4886 | ht_oper = (void *)(ht_oper_ie + 2); |
Johannes Berg | 08e6effa | 2013-02-07 23:33:32 +0100 | [diff] [blame] | 4887 | |
Eliad Peller | 53b954e | 2014-07-24 11:20:05 +0300 | [diff] [blame] | 4888 | ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY); |
| 4889 | if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) |
| 4890 | ht_cap = (void *)(ht_cap_ie + 2); |
| 4891 | |
| 4892 | if (!ht_cap) { |
Johannes Berg | 08e6effa | 2013-02-07 23:33:32 +0100 | [diff] [blame] | 4893 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
| 4894 | ht_oper = NULL; |
| 4895 | } |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4896 | } |
| 4897 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 4898 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && !is_6ghz) { |
Johannes Berg | 08e6effa | 2013-02-07 23:33:32 +0100 | [diff] [blame] | 4899 | const u8 *vht_oper_ie, *vht_cap; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4900 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 4901 | vht_oper_ie = ieee80211_bss_get_ie(cbss, |
| 4902 | WLAN_EID_VHT_OPERATION); |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4903 | if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper)) |
| 4904 | vht_oper = (void *)(vht_oper_ie + 2); |
| 4905 | if (vht_oper && !ht_oper) { |
| 4906 | vht_oper = NULL; |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4907 | sdata_info(sdata, |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 4908 | "AP advertised VHT without HT, disabling HT/VHT/HE\n"); |
Johannes Berg | cb14502 | 2013-02-07 20:41:50 +0100 | [diff] [blame] | 4909 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
| 4910 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 4911 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4912 | } |
Johannes Berg | 08e6effa | 2013-02-07 23:33:32 +0100 | [diff] [blame] | 4913 | |
| 4914 | vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY); |
| 4915 | if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) { |
| 4916 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
| 4917 | vht_oper = NULL; |
| 4918 | } |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4919 | } |
| 4920 | |
Shaul Triebitz | 002245e | 2018-12-15 11:03:19 +0200 | [diff] [blame] | 4921 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) { |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4922 | const struct cfg80211_bss_ies *ies; |
| 4923 | const u8 *he_oper_ie; |
| 4924 | |
| 4925 | ies = rcu_dereference(cbss->ies); |
| 4926 | he_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION, |
| 4927 | ies->data, ies->len); |
| 4928 | if (he_oper_ie && |
| 4929 | he_oper_ie[1] == ieee80211_he_oper_size(&he_oper_ie[3])) |
| 4930 | he_oper = (void *)(he_oper_ie + 3); |
| 4931 | else |
| 4932 | he_oper = NULL; |
| 4933 | |
Johannes Berg | f0c0407 | 2018-06-29 09:51:39 +0200 | [diff] [blame] | 4934 | if (!ieee80211_verify_sta_he_mcs_support(sband, he_oper)) |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4935 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
| 4936 | } |
| 4937 | |
Arik Nemtsov | 52a45f3 | 2015-08-15 22:39:53 +0300 | [diff] [blame] | 4938 | /* Allow VHT if at least one channel on the sband supports 80 MHz */ |
| 4939 | have_80mhz = false; |
| 4940 | for (i = 0; i < sband->n_channels; i++) { |
| 4941 | if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED | |
| 4942 | IEEE80211_CHAN_NO_80MHZ)) |
| 4943 | continue; |
| 4944 | |
| 4945 | have_80mhz = true; |
| 4946 | break; |
| 4947 | } |
| 4948 | |
| 4949 | if (!have_80mhz) |
| 4950 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
| 4951 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4952 | ifmgd->flags |= ieee80211_determine_chantype(sdata, sband, |
| 4953 | cbss->channel, |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 4954 | bss->vht_cap_info, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4955 | ht_oper, vht_oper, he_oper, |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 4956 | &chandef, false); |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 4957 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4958 | sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss), |
| 4959 | local->rx_chains); |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4960 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 4961 | rcu_read_unlock(); |
| 4962 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 4963 | if (ifmgd->flags & IEEE80211_STA_DISABLE_HE && is_6ghz) { |
| 4964 | sdata_info(sdata, "Rejecting non-HE 6/7 GHz connection"); |
| 4965 | return -EINVAL; |
| 4966 | } |
| 4967 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 4968 | /* will change later if needed */ |
| 4969 | sdata->smps_mode = IEEE80211_SMPS_OFF; |
| 4970 | |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 4971 | mutex_lock(&local->mtx); |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4972 | /* |
| 4973 | * If this fails (possibly due to channel context sharing |
| 4974 | * on incompatible channels, e.g. 80+80 and 160 sharing the |
| 4975 | * same control channel) try to use a smaller bandwidth. |
| 4976 | */ |
| 4977 | ret = ieee80211_vif_use_channel(sdata, &chandef, |
| 4978 | IEEE80211_CHANCTX_SHARED); |
Simon Wunderlich | 0418a44 | 2013-05-16 13:00:31 +0200 | [diff] [blame] | 4979 | |
| 4980 | /* don't downgrade for 5 and 10 MHz channels, though. */ |
| 4981 | if (chandef.width == NL80211_CHAN_WIDTH_5 || |
| 4982 | chandef.width == NL80211_CHAN_WIDTH_10) |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 4983 | goto out; |
Simon Wunderlich | 0418a44 | 2013-05-16 13:00:31 +0200 | [diff] [blame] | 4984 | |
Johannes Berg | d601cd8 | 2013-02-07 20:54:51 +0100 | [diff] [blame] | 4985 | while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) { |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 4986 | ifmgd->flags |= ieee80211_chandef_downgrade(&chandef); |
Johannes Berg | d601cd8 | 2013-02-07 20:54:51 +0100 | [diff] [blame] | 4987 | ret = ieee80211_vif_use_channel(sdata, &chandef, |
| 4988 | IEEE80211_CHANCTX_SHARED); |
| 4989 | } |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 4990 | out: |
| 4991 | mutex_unlock(&local->mtx); |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4992 | return ret; |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 4993 | } |
| 4994 | |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 4995 | static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies, |
| 4996 | u8 *dtim_count, u8 *dtim_period) |
| 4997 | { |
| 4998 | const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len); |
| 4999 | const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data, |
| 5000 | ies->len); |
| 5001 | const struct ieee80211_tim_ie *tim = NULL; |
| 5002 | const struct ieee80211_bssid_index *idx; |
| 5003 | bool valid = tim_ie && tim_ie[1] >= 2; |
| 5004 | |
| 5005 | if (valid) |
| 5006 | tim = (void *)(tim_ie + 2); |
| 5007 | |
| 5008 | if (dtim_count) |
| 5009 | *dtim_count = valid ? tim->dtim_count : 0; |
| 5010 | |
| 5011 | if (dtim_period) |
| 5012 | *dtim_period = valid ? tim->dtim_period : 0; |
| 5013 | |
| 5014 | /* Check if value is overridden by non-transmitted profile */ |
| 5015 | if (!idx_ie || idx_ie[1] < 3) |
| 5016 | return valid; |
| 5017 | |
| 5018 | idx = (void *)(idx_ie + 2); |
| 5019 | |
| 5020 | if (dtim_count) |
| 5021 | *dtim_count = idx->dtim_count; |
| 5022 | |
| 5023 | if (dtim_period) |
| 5024 | *dtim_period = idx->dtim_period; |
| 5025 | |
| 5026 | return true; |
| 5027 | } |
| 5028 | |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 5029 | static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata, |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 5030 | struct cfg80211_bss *cbss, bool assoc, |
| 5031 | bool override) |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 5032 | { |
| 5033 | struct ieee80211_local *local = sdata->local; |
| 5034 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 5035 | struct ieee80211_bss *bss = (void *)cbss->priv; |
| 5036 | struct sta_info *new_sta = NULL; |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 5037 | struct ieee80211_supported_band *sband; |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 5038 | bool have_sta = false; |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 5039 | int err; |
| 5040 | |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 5041 | sband = local->hw.wiphy->bands[cbss->channel->band]; |
| 5042 | |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 5043 | if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data)) |
| 5044 | return -EINVAL; |
| 5045 | |
Luca Coelho | f8860ce | 2017-05-02 17:56:21 +0300 | [diff] [blame] | 5046 | /* If a reconfig is happening, bail out */ |
| 5047 | if (local->in_reconfig) |
| 5048 | return -EBUSY; |
| 5049 | |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 5050 | if (assoc) { |
| 5051 | rcu_read_lock(); |
| 5052 | have_sta = sta_info_get(sdata, cbss->bssid); |
| 5053 | rcu_read_unlock(); |
| 5054 | } |
| 5055 | |
| 5056 | if (!have_sta) { |
| 5057 | new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL); |
| 5058 | if (!new_sta) |
| 5059 | return -ENOMEM; |
| 5060 | } |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 5061 | |
Johannes Berg | c87905b | 2017-06-10 13:52:43 +0300 | [diff] [blame] | 5062 | /* |
| 5063 | * Set up the information for the new channel before setting the |
| 5064 | * new channel. We can't - completely race-free - change the basic |
| 5065 | * rates bitmap and the channel (sband) that it refers to, but if |
| 5066 | * we set it up before we at least avoid calling into the driver's |
| 5067 | * bss_info_changed() method with invalid information (since we do |
| 5068 | * call that from changing the channel - only for IDLE and perhaps |
| 5069 | * some others, but ...). |
| 5070 | * |
| 5071 | * So to avoid that, just set up all the new information before the |
| 5072 | * channel, but tell the driver to apply it only afterwards, since |
| 5073 | * it might need the new channel for that. |
| 5074 | */ |
Johannes Berg | 13e0c8e | 2012-07-27 10:43:16 +0200 | [diff] [blame] | 5075 | if (new_sta) { |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5076 | u32 rates = 0, basic_rates = 0; |
| 5077 | bool have_higher_than_11mbit; |
| 5078 | int min_rate = INT_MAX, min_rate_index = -1; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5079 | const struct cfg80211_bss_ies *ies; |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 5080 | int shift = ieee80211_vif_get_shift(&sdata->vif); |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5081 | |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5082 | ieee80211_get_rates(sband, bss->supp_rates, |
| 5083 | bss->supp_rates_len, |
| 5084 | &rates, &basic_rates, |
| 5085 | &have_higher_than_11mbit, |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 5086 | &min_rate, &min_rate_index, |
Johannes Berg | 44f6d42 | 2017-06-10 13:52:44 +0300 | [diff] [blame] | 5087 | shift); |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5088 | |
| 5089 | /* |
| 5090 | * This used to be a workaround for basic rates missing |
| 5091 | * in the association response frame. Now that we no |
| 5092 | * longer use the basic rates from there, it probably |
| 5093 | * doesn't happen any more, but keep the workaround so |
| 5094 | * in case some *other* APs are buggy in different ways |
| 5095 | * we can connect -- with a warning. |
Ilan Peer | 302ff8b | 2020-03-26 15:09:39 +0200 | [diff] [blame] | 5096 | * Allow this workaround only in case the AP provided at least |
| 5097 | * one rate. |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5098 | */ |
Ilan Peer | 302ff8b | 2020-03-26 15:09:39 +0200 | [diff] [blame] | 5099 | if (min_rate_index < 0) { |
| 5100 | sdata_info(sdata, |
| 5101 | "No legacy rates in association response\n"); |
| 5102 | |
| 5103 | sta_info_free(local, new_sta); |
| 5104 | return -EINVAL; |
| 5105 | } else if (!basic_rates) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 5106 | sdata_info(sdata, |
| 5107 | "No basic rates, using min rate instead\n"); |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5108 | basic_rates = BIT(min_rate_index); |
| 5109 | } |
| 5110 | |
Johannes Berg | bd718fc | 2019-05-29 15:25:35 +0300 | [diff] [blame] | 5111 | if (rates) |
| 5112 | new_sta->sta.supp_rates[cbss->channel->band] = rates; |
| 5113 | else |
| 5114 | sdata_info(sdata, |
| 5115 | "No rates found, keeping mandatory only\n"); |
| 5116 | |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5117 | sdata->vif.bss_conf.basic_rates = basic_rates; |
| 5118 | |
| 5119 | /* cf. IEEE 802.11 9.2.12 */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5120 | if (cbss->channel->band == NL80211_BAND_2GHZ && |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5121 | have_higher_than_11mbit) |
| 5122 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; |
| 5123 | else |
| 5124 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; |
| 5125 | |
| 5126 | memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN); |
| 5127 | |
Johannes Berg | 8c358bc | 2012-05-22 22:13:05 +0200 | [diff] [blame] | 5128 | /* set timing information */ |
| 5129 | sdata->vif.bss_conf.beacon_int = cbss->beacon_interval; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5130 | rcu_read_lock(); |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5131 | ies = rcu_dereference(cbss->beacon_ies); |
| 5132 | if (ies) { |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5133 | sdata->vif.bss_conf.sync_tsf = ies->tsf; |
| 5134 | sdata->vif.bss_conf.sync_device_ts = |
| 5135 | bss->device_ts_beacon; |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 5136 | |
| 5137 | ieee80211_get_dtim(ies, |
| 5138 | &sdata->vif.bss_conf.sync_dtim_count, |
| 5139 | NULL); |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 5140 | } else if (!ieee80211_hw_check(&sdata->local->hw, |
| 5141 | TIMING_BEACON_ONLY)) { |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5142 | ies = rcu_dereference(cbss->proberesp_ies); |
| 5143 | /* must be non-NULL since beacon IEs were NULL */ |
| 5144 | sdata->vif.bss_conf.sync_tsf = ies->tsf; |
| 5145 | sdata->vif.bss_conf.sync_device_ts = |
| 5146 | bss->device_ts_presp; |
| 5147 | sdata->vif.bss_conf.sync_dtim_count = 0; |
| 5148 | } else { |
| 5149 | sdata->vif.bss_conf.sync_tsf = 0; |
| 5150 | sdata->vif.bss_conf.sync_device_ts = 0; |
| 5151 | sdata->vif.bss_conf.sync_dtim_count = 0; |
| 5152 | } |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5153 | rcu_read_unlock(); |
Johannes Berg | c87905b | 2017-06-10 13:52:43 +0300 | [diff] [blame] | 5154 | } |
Johannes Berg | 8c358bc | 2012-05-22 22:13:05 +0200 | [diff] [blame] | 5155 | |
Johannes Berg | c87905b | 2017-06-10 13:52:43 +0300 | [diff] [blame] | 5156 | if (new_sta || override) { |
| 5157 | err = ieee80211_prep_channel(sdata, cbss); |
| 5158 | if (err) { |
| 5159 | if (new_sta) |
| 5160 | sta_info_free(local, new_sta); |
| 5161 | return -EINVAL; |
| 5162 | } |
| 5163 | } |
| 5164 | |
| 5165 | if (new_sta) { |
| 5166 | /* |
| 5167 | * tell driver about BSSID, basic rates and timing |
| 5168 | * this was set up above, before setting the channel |
| 5169 | */ |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5170 | ieee80211_bss_info_change_notify(sdata, |
Johannes Berg | 8c358bc | 2012-05-22 22:13:05 +0200 | [diff] [blame] | 5171 | BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES | |
| 5172 | BSS_CHANGED_BEACON_INT); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5173 | |
| 5174 | if (assoc) |
Johannes Berg | 13e0c8e | 2012-07-27 10:43:16 +0200 | [diff] [blame] | 5175 | sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5176 | |
Johannes Berg | 13e0c8e | 2012-07-27 10:43:16 +0200 | [diff] [blame] | 5177 | err = sta_info_insert(new_sta); |
| 5178 | new_sta = NULL; |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5179 | if (err) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 5180 | sdata_info(sdata, |
| 5181 | "failed to insert STA entry for the AP (error %d)\n", |
| 5182 | err); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5183 | return err; |
| 5184 | } |
| 5185 | } else |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 5186 | WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid)); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5187 | |
David Spinadel | 7d830a1 | 2015-03-17 19:58:38 +0200 | [diff] [blame] | 5188 | /* Cancel scan to ensure that nothing interferes with connection */ |
| 5189 | if (local->scanning) |
| 5190 | ieee80211_scan_cancel(local); |
| 5191 | |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5192 | return 0; |
| 5193 | } |
| 5194 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5195 | /* config hooks */ |
| 5196 | int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata, |
| 5197 | struct cfg80211_auth_request *req) |
| 5198 | { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5199 | struct ieee80211_local *local = sdata->local; |
| 5200 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 5201 | struct ieee80211_mgd_auth_data *auth_data; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5202 | u16 auth_alg; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5203 | int err; |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5204 | bool cont_auth; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5205 | |
| 5206 | /* prepare auth data structure */ |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5207 | |
| 5208 | switch (req->auth_type) { |
| 5209 | case NL80211_AUTHTYPE_OPEN_SYSTEM: |
| 5210 | auth_alg = WLAN_AUTH_OPEN; |
| 5211 | break; |
| 5212 | case NL80211_AUTHTYPE_SHARED_KEY: |
Ard Biesheuvel | 5fdb373 | 2019-06-12 18:19:54 +0200 | [diff] [blame] | 5213 | if (fips_enabled) |
Johannes Berg | 9dca9c4 | 2010-07-21 10:09:25 +0200 | [diff] [blame] | 5214 | return -EOPNOTSUPP; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5215 | auth_alg = WLAN_AUTH_SHARED_KEY; |
| 5216 | break; |
| 5217 | case NL80211_AUTHTYPE_FT: |
| 5218 | auth_alg = WLAN_AUTH_FT; |
| 5219 | break; |
| 5220 | case NL80211_AUTHTYPE_NETWORK_EAP: |
| 5221 | auth_alg = WLAN_AUTH_LEAP; |
| 5222 | break; |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 5223 | case NL80211_AUTHTYPE_SAE: |
| 5224 | auth_alg = WLAN_AUTH_SAE; |
| 5225 | break; |
Jouni Malinen | dbc0c2c | 2016-10-27 00:42:04 +0300 | [diff] [blame] | 5226 | case NL80211_AUTHTYPE_FILS_SK: |
| 5227 | auth_alg = WLAN_AUTH_FILS_SK; |
| 5228 | break; |
| 5229 | case NL80211_AUTHTYPE_FILS_SK_PFS: |
| 5230 | auth_alg = WLAN_AUTH_FILS_SK_PFS; |
| 5231 | break; |
| 5232 | case NL80211_AUTHTYPE_FILS_PK: |
| 5233 | auth_alg = WLAN_AUTH_FILS_PK; |
| 5234 | break; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5235 | default: |
| 5236 | return -EOPNOTSUPP; |
| 5237 | } |
| 5238 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5239 | if (ifmgd->assoc_data) |
Jouni Malinen | 8d7432a | 2018-10-11 00:21:20 +0300 | [diff] [blame] | 5240 | return -EBUSY; |
| 5241 | |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 5242 | auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len + |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 5243 | req->ie_len, GFP_KERNEL); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5244 | if (!auth_data) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5245 | return -ENOMEM; |
| 5246 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5247 | auth_data->bss = req->bss; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5248 | |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 5249 | if (req->auth_data_len >= 4) { |
Jouni Malinen | 6ec6361 | 2016-10-27 00:41:59 +0300 | [diff] [blame] | 5250 | if (req->auth_type == NL80211_AUTHTYPE_SAE) { |
| 5251 | __le16 *pos = (__le16 *) req->auth_data; |
| 5252 | |
| 5253 | auth_data->sae_trans = le16_to_cpu(pos[0]); |
| 5254 | auth_data->sae_status = le16_to_cpu(pos[1]); |
| 5255 | } |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 5256 | memcpy(auth_data->data, req->auth_data + 4, |
| 5257 | req->auth_data_len - 4); |
| 5258 | auth_data->data_len += req->auth_data_len - 4; |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 5259 | } |
| 5260 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5261 | /* Check if continuing authentication or trying to authenticate with the |
| 5262 | * same BSS that we were in the process of authenticating with and avoid |
| 5263 | * removal and re-addition of the STA entry in |
| 5264 | * ieee80211_prep_connection(). |
| 5265 | */ |
| 5266 | cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss; |
| 5267 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5268 | if (req->ie && req->ie_len) { |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 5269 | memcpy(&auth_data->data[auth_data->data_len], |
| 5270 | req->ie, req->ie_len); |
| 5271 | auth_data->data_len += req->ie_len; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5272 | } |
| 5273 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5274 | if (req->key && req->key_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5275 | auth_data->key_len = req->key_len; |
| 5276 | auth_data->key_idx = req->key_idx; |
| 5277 | memcpy(auth_data->key, req->key, req->key_len); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5278 | } |
| 5279 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5280 | auth_data->algorithm = auth_alg; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5281 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5282 | /* try to authenticate/probe */ |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 5283 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5284 | if (ifmgd->auth_data) { |
| 5285 | if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) { |
| 5286 | auth_data->peer_confirmed = |
| 5287 | ifmgd->auth_data->peer_confirmed; |
| 5288 | } |
| 5289 | ieee80211_destroy_auth_data(sdata, cont_auth); |
| 5290 | } |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 5291 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5292 | /* prep auth_data so we don't go into idle on disassoc */ |
| 5293 | ifmgd->auth_data = auth_data; |
| 5294 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5295 | /* If this is continuation of an ongoing SAE authentication exchange |
| 5296 | * (i.e., request to send SAE Confirm) and the peer has already |
| 5297 | * confirmed, mark authentication completed since we are about to send |
| 5298 | * out SAE Confirm. |
| 5299 | */ |
| 5300 | if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE && |
| 5301 | auth_data->peer_confirmed && auth_data->sae_trans == 2) |
| 5302 | ieee80211_mark_sta_auth(sdata, req->bss->bssid); |
| 5303 | |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5304 | if (ifmgd->associated) { |
| 5305 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
| 5306 | |
Johannes Berg | 89f774e | 2016-01-25 15:46:36 +0200 | [diff] [blame] | 5307 | sdata_info(sdata, |
| 5308 | "disconnect from AP %pM for new auth to %pM\n", |
| 5309 | ifmgd->associated->bssid, req->bss->bssid); |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5310 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
| 5311 | WLAN_REASON_UNSPECIFIED, |
| 5312 | false, frame_buf); |
| 5313 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 5314 | ieee80211_report_disconnect(sdata, frame_buf, |
| 5315 | sizeof(frame_buf), true, |
| 5316 | WLAN_REASON_UNSPECIFIED); |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5317 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5318 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 5319 | sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5320 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5321 | err = ieee80211_prep_connection(sdata, req->bss, cont_auth, false); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5322 | if (err) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5323 | goto err_clear; |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 5324 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 5325 | err = ieee80211_auth(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5326 | if (err) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5327 | sta_info_destroy_addr(sdata, req->bss->bssid); |
| 5328 | goto err_clear; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5329 | } |
| 5330 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5331 | /* hold our own reference */ |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 5332 | cfg80211_ref_bss(local->hw.wiphy, auth_data->bss); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 5333 | return 0; |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 5334 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5335 | err_clear: |
Joe Perches | c84a67a | 2015-03-02 19:54:57 -0800 | [diff] [blame] | 5336 | eth_zero_addr(ifmgd->bssid); |
Eliad Peller | 3d2abdf | 2012-09-04 17:44:45 +0300 | [diff] [blame] | 5337 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5338 | ifmgd->auth_data = NULL; |
Michal Kazior | d01f858 | 2015-06-03 08:36:13 +0200 | [diff] [blame] | 5339 | mutex_lock(&sdata->local->mtx); |
| 5340 | ieee80211_vif_release_channel(sdata); |
| 5341 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5342 | kfree(auth_data); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5343 | return err; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5344 | } |
| 5345 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5346 | int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, |
| 5347 | struct cfg80211_assoc_request *req) |
| 5348 | { |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 5349 | bool is_6ghz = req->bss->channel->band == NL80211_BAND_6GHZ; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5350 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5351 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 5352 | struct ieee80211_bss *bss = (void *)req->bss->priv; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5353 | struct ieee80211_mgd_assoc_data *assoc_data; |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5354 | const struct cfg80211_bss_ies *beacon_ies; |
Johannes Berg | 4e74bfd | 2012-03-08 15:02:04 +0100 | [diff] [blame] | 5355 | struct ieee80211_supported_band *sband; |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 5356 | const u8 *ssidie, *ht_ie, *vht_ie; |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 5357 | int i, err; |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 5358 | bool override = false; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5359 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5360 | assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL); |
| 5361 | if (!assoc_data) |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5362 | return -ENOMEM; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5363 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5364 | rcu_read_lock(); |
| 5365 | ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID); |
Will Deacon | 4152561 | 2019-10-04 10:51:31 +0100 | [diff] [blame] | 5366 | if (!ssidie || ssidie[1] > sizeof(assoc_data->ssid)) { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5367 | rcu_read_unlock(); |
| 5368 | kfree(assoc_data); |
| 5369 | return -EINVAL; |
| 5370 | } |
| 5371 | memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]); |
| 5372 | assoc_data->ssid_len = ssidie[1]; |
| 5373 | rcu_read_unlock(); |
| 5374 | |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5375 | if (ifmgd->associated) { |
| 5376 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
| 5377 | |
Johannes Berg | 89f774e | 2016-01-25 15:46:36 +0200 | [diff] [blame] | 5378 | sdata_info(sdata, |
| 5379 | "disconnect from AP %pM for new assoc to %pM\n", |
| 5380 | ifmgd->associated->bssid, req->bss->bssid); |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5381 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
| 5382 | WLAN_REASON_UNSPECIFIED, |
| 5383 | false, frame_buf); |
| 5384 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 5385 | ieee80211_report_disconnect(sdata, frame_buf, |
| 5386 | sizeof(frame_buf), true, |
| 5387 | WLAN_REASON_UNSPECIFIED); |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5388 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5389 | |
| 5390 | if (ifmgd->auth_data && !ifmgd->auth_data->done) { |
| 5391 | err = -EBUSY; |
| 5392 | goto err_free; |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 5393 | } |
| 5394 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5395 | if (ifmgd->assoc_data) { |
| 5396 | err = -EBUSY; |
| 5397 | goto err_free; |
| 5398 | } |
| 5399 | |
| 5400 | if (ifmgd->auth_data) { |
| 5401 | bool match; |
| 5402 | |
| 5403 | /* keep sta info, bssid if matching */ |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 5404 | match = ether_addr_equal(ifmgd->bssid, req->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5405 | ieee80211_destroy_auth_data(sdata, match); |
| 5406 | } |
| 5407 | |
| 5408 | /* prepare assoc data */ |
Johannes Berg | 095d81c | 2013-10-15 12:25:07 +0200 | [diff] [blame] | 5409 | |
Juuso Oikarinen | d8ec443 | 2010-10-01 16:02:31 +0300 | [diff] [blame] | 5410 | ifmgd->beacon_crc_valid = false; |
| 5411 | |
Johannes Berg | 095d81c | 2013-10-15 12:25:07 +0200 | [diff] [blame] | 5412 | assoc_data->wmm = bss->wmm_used && |
| 5413 | (local->hw.queues >= IEEE80211_NUM_ACS); |
Johannes Berg | 095d81c | 2013-10-15 12:25:07 +0200 | [diff] [blame] | 5414 | |
Johannes Berg | de5036a | 2012-03-08 15:02:03 +0100 | [diff] [blame] | 5415 | /* |
| 5416 | * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode. |
| 5417 | * We still associate in non-HT mode (11a/b/g) if any one of these |
| 5418 | * ciphers is configured as pairwise. |
| 5419 | * We can set this to true for non-11n hardware, that'll be checked |
| 5420 | * separately along with the peer capabilities. |
| 5421 | */ |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 5422 | for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) { |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5423 | if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 || |
| 5424 | req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP || |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 5425 | req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) { |
Johannes Berg | a8243b7 | 2012-11-22 14:32:09 +0100 | [diff] [blame] | 5426 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 5427 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 5428 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 5429 | netdev_info(sdata->dev, |
Johannes Berg | 5462632 | 2019-08-30 14:24:46 +0300 | [diff] [blame] | 5430 | "disabling HT/VHT/HE due to WEP/TKIP use\n"); |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 5431 | } |
| 5432 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5433 | |
Johannes Berg | 4e74bfd | 2012-03-08 15:02:04 +0100 | [diff] [blame] | 5434 | sband = local->hw.wiphy->bands[req->bss->channel->band]; |
Johannes Berg | 4e74bfd | 2012-03-08 15:02:04 +0100 | [diff] [blame] | 5435 | |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 5436 | /* also disable HT/VHT/HE if the AP doesn't use WMM */ |
| 5437 | if (!bss->wmm_used) { |
| 5438 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 5439 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 5440 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
| 5441 | netdev_info(sdata->dev, |
| 5442 | "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] | 5443 | } |
| 5444 | |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 5445 | memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa)); |
| 5446 | memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask, |
| 5447 | sizeof(ifmgd->ht_capa_mask)); |
| 5448 | |
Johannes Berg | dd5ecfe | 2013-02-21 17:40:19 +0100 | [diff] [blame] | 5449 | memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa)); |
| 5450 | memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask, |
| 5451 | sizeof(ifmgd->vht_capa_mask)); |
| 5452 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5453 | if (req->ie && req->ie_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5454 | memcpy(assoc_data->ie, req->ie, req->ie_len); |
| 5455 | assoc_data->ie_len = req->ie_len; |
| 5456 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5457 | |
Jouni Malinen | 39404fe | 2016-10-27 00:42:05 +0300 | [diff] [blame] | 5458 | if (req->fils_kek) { |
| 5459 | /* should already be checked in cfg80211 - so warn */ |
| 5460 | if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) { |
| 5461 | err = -EINVAL; |
| 5462 | goto err_free; |
| 5463 | } |
| 5464 | memcpy(assoc_data->fils_kek, req->fils_kek, |
| 5465 | req->fils_kek_len); |
| 5466 | assoc_data->fils_kek_len = req->fils_kek_len; |
| 5467 | } |
| 5468 | |
| 5469 | if (req->fils_nonces) |
| 5470 | memcpy(assoc_data->fils_nonces, req->fils_nonces, |
| 5471 | 2 * FILS_NONCE_LEN); |
| 5472 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5473 | assoc_data->bss = req->bss; |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 5474 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5475 | if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) { |
| 5476 | if (ifmgd->powersave) |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 5477 | sdata->smps_mode = IEEE80211_SMPS_DYNAMIC; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5478 | else |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 5479 | sdata->smps_mode = IEEE80211_SMPS_OFF; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5480 | } else |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 5481 | sdata->smps_mode = ifmgd->req_smps; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5482 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5483 | assoc_data->capability = req->bss->capability; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5484 | assoc_data->supp_rates = bss->supp_rates; |
| 5485 | assoc_data->supp_rates_len = bss->supp_rates_len; |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 5486 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5487 | rcu_read_lock(); |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 5488 | ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION); |
| 5489 | if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation)) |
| 5490 | assoc_data->ap_ht_param = |
| 5491 | ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param; |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 5492 | else if (!is_6ghz) |
Johannes Berg | a8243b7 | 2012-11-22 14:32:09 +0100 | [diff] [blame] | 5493 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 5494 | vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY); |
| 5495 | if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap)) |
| 5496 | memcpy(&assoc_data->ap_vht_cap, vht_ie + 2, |
| 5497 | sizeof(struct ieee80211_vht_cap)); |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 5498 | else if (!is_6ghz) |
| 5499 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT | |
| 5500 | IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5501 | rcu_read_unlock(); |
Johannes Berg | 63f170e | 2009-12-23 13:15:33 +0100 | [diff] [blame] | 5502 | |
Johannes Berg | 848955c | 2014-11-11 12:48:42 +0100 | [diff] [blame] | 5503 | if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) && |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 5504 | ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK), |
Johannes Berg | 848955c | 2014-11-11 12:48:42 +0100 | [diff] [blame] | 5505 | "U-APSD not supported with HW_PS_NULLFUNC_STACK\n")) |
| 5506 | sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; |
| 5507 | |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 5508 | if (bss->wmm_used && bss->uapsd_supported && |
Johannes Berg | 848955c | 2014-11-11 12:48:42 +0100 | [diff] [blame] | 5509 | (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) { |
Johannes Berg | 76f0303 | 2012-03-08 15:02:05 +0100 | [diff] [blame] | 5510 | assoc_data->uapsd = true; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 5511 | ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED; |
| 5512 | } else { |
Johannes Berg | 76f0303 | 2012-03-08 15:02:05 +0100 | [diff] [blame] | 5513 | assoc_data->uapsd = false; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 5514 | ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED; |
| 5515 | } |
| 5516 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5517 | if (req->prev_bssid) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5518 | memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5519 | |
| 5520 | if (req->use_mfp) { |
| 5521 | ifmgd->mfp = IEEE80211_MFP_REQUIRED; |
| 5522 | ifmgd->flags |= IEEE80211_STA_MFP_ENABLED; |
| 5523 | } else { |
| 5524 | ifmgd->mfp = IEEE80211_MFP_DISABLED; |
| 5525 | ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED; |
| 5526 | } |
| 5527 | |
Assaf Krauss | cd2f5dd | 2014-09-03 15:25:02 +0300 | [diff] [blame] | 5528 | if (req->flags & ASSOC_REQ_USE_RRM) |
| 5529 | ifmgd->flags |= IEEE80211_STA_ENABLE_RRM; |
| 5530 | else |
| 5531 | ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM; |
| 5532 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5533 | if (req->crypto.control_port) |
| 5534 | ifmgd->flags |= IEEE80211_STA_CONTROL_PORT; |
| 5535 | else |
| 5536 | ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT; |
| 5537 | |
Johannes Berg | a621fa4 | 2010-08-27 14:26:54 +0300 | [diff] [blame] | 5538 | sdata->control_port_protocol = req->crypto.control_port_ethertype; |
| 5539 | sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt; |
Denis Kenzior | 018f6fb | 2018-03-26 12:52:51 -0500 | [diff] [blame] | 5540 | sdata->control_port_over_nl80211 = |
| 5541 | req->crypto.control_port_over_nl80211; |
Markus Theil | 7f3f96c | 2020-03-12 10:10:54 +0100 | [diff] [blame] | 5542 | sdata->control_port_no_preauth = req->crypto.control_port_no_preauth; |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 5543 | sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto, |
| 5544 | sdata->vif.type); |
Johannes Berg | a621fa4 | 2010-08-27 14:26:54 +0300 | [diff] [blame] | 5545 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5546 | /* kick off associate process */ |
| 5547 | |
| 5548 | ifmgd->assoc_data = assoc_data; |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 5549 | ifmgd->dtim_period = 0; |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 5550 | ifmgd->have_beacon = false; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5551 | |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 5552 | /* override HT/VHT configuration only if the AP and we support it */ |
| 5553 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) { |
| 5554 | struct ieee80211_sta_ht_cap sta_ht_cap; |
| 5555 | |
| 5556 | if (req->flags & ASSOC_REQ_DISABLE_HT) |
| 5557 | override = true; |
| 5558 | |
| 5559 | memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap)); |
| 5560 | ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap); |
| 5561 | |
| 5562 | /* check for 40 MHz disable override */ |
| 5563 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) && |
| 5564 | sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 && |
| 5565 | !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) |
| 5566 | override = true; |
| 5567 | |
| 5568 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && |
| 5569 | req->flags & ASSOC_REQ_DISABLE_VHT) |
| 5570 | override = true; |
| 5571 | } |
| 5572 | |
| 5573 | if (req->flags & ASSOC_REQ_DISABLE_HT) { |
| 5574 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
| 5575 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 5576 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 5577 | } |
| 5578 | |
| 5579 | if (req->flags & ASSOC_REQ_DISABLE_VHT) |
| 5580 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
| 5581 | |
| 5582 | err = ieee80211_prep_connection(sdata, req->bss, true, override); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5583 | if (err) |
| 5584 | goto err_clear; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5585 | |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5586 | rcu_read_lock(); |
| 5587 | beacon_ies = rcu_dereference(req->bss->beacon_ies); |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 5588 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 5589 | if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) && |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5590 | !beacon_ies) { |
| 5591 | /* |
| 5592 | * Wait up to one beacon interval ... |
| 5593 | * should this be more if we miss one? |
| 5594 | */ |
| 5595 | sdata_info(sdata, "waiting for beacon from %pM\n", |
| 5596 | ifmgd->bssid); |
| 5597 | assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval); |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 5598 | assoc_data->timeout_started = true; |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5599 | assoc_data->need_beacon = true; |
| 5600 | } else if (beacon_ies) { |
Shaul Triebitz | 3b3ec3d | 2020-05-28 21:34:37 +0200 | [diff] [blame] | 5601 | const struct element *elem; |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5602 | u8 dtim_count = 0; |
| 5603 | |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 5604 | ieee80211_get_dtim(beacon_ies, &dtim_count, |
| 5605 | &ifmgd->dtim_period); |
| 5606 | |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 5607 | ifmgd->have_beacon = true; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5608 | assoc_data->timeout = jiffies; |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 5609 | assoc_data->timeout_started = true; |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5610 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 5611 | if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) { |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5612 | sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf; |
| 5613 | sdata->vif.bss_conf.sync_device_ts = |
| 5614 | bss->device_ts_beacon; |
| 5615 | sdata->vif.bss_conf.sync_dtim_count = dtim_count; |
| 5616 | } |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 5617 | |
Shaul Triebitz | 3b3ec3d | 2020-05-28 21:34:37 +0200 | [diff] [blame] | 5618 | elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION, |
| 5619 | beacon_ies->data, beacon_ies->len); |
| 5620 | if (elem && elem->datalen >= 3) |
| 5621 | sdata->vif.bss_conf.profile_periodicity = elem->data[2]; |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 5622 | |
Shaul Triebitz | 3b3ec3d | 2020-05-28 21:34:37 +0200 | [diff] [blame] | 5623 | elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, |
| 5624 | beacon_ies->data, beacon_ies->len); |
| 5625 | if (elem && elem->datalen >= 11 && |
| 5626 | (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT)) |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 5627 | sdata->vif.bss_conf.ema_ap = true; |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5628 | } else { |
| 5629 | assoc_data->timeout = jiffies; |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 5630 | assoc_data->timeout_started = true; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5631 | } |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5632 | rcu_read_unlock(); |
| 5633 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 5634 | run_again(sdata, assoc_data->timeout); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5635 | |
Paul Stewart | fcff4f1 | 2012-02-23 17:59:53 -0800 | [diff] [blame] | 5636 | if (bss->corrupt_data) { |
| 5637 | char *corrupt_type = "data"; |
| 5638 | if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) { |
| 5639 | if (bss->corrupt_data & |
| 5640 | IEEE80211_BSS_CORRUPT_PROBE_RESP) |
| 5641 | corrupt_type = "beacon and probe response"; |
| 5642 | else |
| 5643 | corrupt_type = "beacon"; |
| 5644 | } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP) |
| 5645 | corrupt_type = "probe response"; |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 5646 | sdata_info(sdata, "associating with AP with corrupt %s\n", |
| 5647 | corrupt_type); |
Paul Stewart | fcff4f1 | 2012-02-23 17:59:53 -0800 | [diff] [blame] | 5648 | } |
| 5649 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 5650 | return 0; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5651 | err_clear: |
Joe Perches | c84a67a | 2015-03-02 19:54:57 -0800 | [diff] [blame] | 5652 | eth_zero_addr(ifmgd->bssid); |
Eliad Peller | 3d2abdf | 2012-09-04 17:44:45 +0300 | [diff] [blame] | 5653 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5654 | ifmgd->assoc_data = NULL; |
| 5655 | err_free: |
| 5656 | kfree(assoc_data); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5657 | return err; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5658 | } |
| 5659 | |
| 5660 | int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 63c9c5e | 2012-02-24 13:50:51 +0100 | [diff] [blame] | 5661 | struct cfg80211_deauth_request *req) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5662 | { |
| 5663 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 5664 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Stanislaw Gruszka | 6863255 | 2012-10-15 14:52:41 +0200 | [diff] [blame] | 5665 | bool tx = !req->local_state_change; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5666 | |
Johannes Berg | c9c3a06 | 2014-03-19 09:11:19 +0100 | [diff] [blame] | 5667 | if (ifmgd->auth_data && |
| 5668 | ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) { |
| 5669 | sdata_info(sdata, |
| 5670 | "aborting authentication with %pM by local choice (Reason: %u=%s)\n", |
| 5671 | req->bssid, req->reason_code, |
| 5672 | ieee80211_get_reason_code_string(req->reason_code)); |
Johannes Berg | 0ff7161 | 2009-09-26 14:45:41 +0200 | [diff] [blame] | 5673 | |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 5674 | drv_mgd_prepare_tx(sdata->local, sdata, 0); |
Johannes Berg | 4b08d1b | 2019-08-30 14:24:51 +0300 | [diff] [blame] | 5675 | ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid, |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 5676 | IEEE80211_STYPE_DEAUTH, |
Stanislaw Gruszka | 6863255 | 2012-10-15 14:52:41 +0200 | [diff] [blame] | 5677 | req->reason_code, tx, |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 5678 | frame_buf); |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 5679 | ieee80211_destroy_auth_data(sdata, false); |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 5680 | ieee80211_report_disconnect(sdata, frame_buf, |
| 5681 | sizeof(frame_buf), true, |
| 5682 | req->reason_code); |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 5683 | |
Johannes Berg | c9c3a06 | 2014-03-19 09:11:19 +0100 | [diff] [blame] | 5684 | return 0; |
Emmanuel Grumbach | 8c7d857 | 2012-07-25 01:42:36 +0300 | [diff] [blame] | 5685 | } |
| 5686 | |
Andrei Otcheretianski | a64cba3 | 2015-10-25 10:59:38 +0200 | [diff] [blame] | 5687 | if (ifmgd->assoc_data && |
| 5688 | ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) { |
| 5689 | sdata_info(sdata, |
| 5690 | "aborting association with %pM by local choice (Reason: %u=%s)\n", |
| 5691 | req->bssid, req->reason_code, |
| 5692 | ieee80211_get_reason_code_string(req->reason_code)); |
| 5693 | |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 5694 | drv_mgd_prepare_tx(sdata->local, sdata, 0); |
Johannes Berg | 4b08d1b | 2019-08-30 14:24:51 +0300 | [diff] [blame] | 5695 | ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid, |
Andrei Otcheretianski | a64cba3 | 2015-10-25 10:59:38 +0200 | [diff] [blame] | 5696 | IEEE80211_STYPE_DEAUTH, |
| 5697 | req->reason_code, tx, |
| 5698 | frame_buf); |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 5699 | ieee80211_destroy_assoc_data(sdata, false, true); |
Andrei Otcheretianski | a64cba3 | 2015-10-25 10:59:38 +0200 | [diff] [blame] | 5700 | ieee80211_report_disconnect(sdata, frame_buf, |
| 5701 | sizeof(frame_buf), true, |
| 5702 | req->reason_code); |
| 5703 | return 0; |
| 5704 | } |
| 5705 | |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 5706 | if (ifmgd->associated && |
| 5707 | ether_addr_equal(ifmgd->associated->bssid, req->bssid)) { |
Johannes Berg | c9c3a06 | 2014-03-19 09:11:19 +0100 | [diff] [blame] | 5708 | sdata_info(sdata, |
| 5709 | "deauthenticating from %pM by local choice (Reason: %u=%s)\n", |
| 5710 | req->bssid, req->reason_code, |
| 5711 | ieee80211_get_reason_code_string(req->reason_code)); |
| 5712 | |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 5713 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
| 5714 | req->reason_code, tx, frame_buf); |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 5715 | ieee80211_report_disconnect(sdata, frame_buf, |
| 5716 | sizeof(frame_buf), true, |
| 5717 | req->reason_code); |
Johannes Berg | c9c3a06 | 2014-03-19 09:11:19 +0100 | [diff] [blame] | 5718 | return 0; |
| 5719 | } |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 5720 | |
Johannes Berg | c9c3a06 | 2014-03-19 09:11:19 +0100 | [diff] [blame] | 5721 | return -ENOTCONN; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5722 | } |
| 5723 | |
| 5724 | int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 63c9c5e | 2012-02-24 13:50:51 +0100 | [diff] [blame] | 5725 | struct cfg80211_disassoc_request *req) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5726 | { |
| 5727 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 5728 | u8 bssid[ETH_ALEN]; |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 5729 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5730 | |
Johannes Berg | 8d8b261 | 2009-07-25 11:58:36 +0200 | [diff] [blame] | 5731 | /* |
| 5732 | * cfg80211 should catch this ... but it's racy since |
| 5733 | * we can receive a disassoc frame, process it, hand it |
| 5734 | * to cfg80211 while that's in a locked section already |
| 5735 | * trying to tell us that the user wants to disconnect. |
| 5736 | */ |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 5737 | if (ifmgd->associated != req->bss) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5738 | return -ENOLINK; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5739 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 5740 | sdata_info(sdata, |
Calvin Owens | dfa1ad2 | 2014-02-11 12:36:24 -0600 | [diff] [blame] | 5741 | "disassociating from %pM by local choice (Reason: %u=%s)\n", |
| 5742 | 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] | 5743 | |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 5744 | memcpy(bssid, req->bss->bssid, ETH_ALEN); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 5745 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC, |
| 5746 | req->reason_code, !req->local_state_change, |
| 5747 | frame_buf); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5748 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 5749 | ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true, |
| 5750 | req->reason_code); |
Johannes Berg | bc83b68 | 2009-11-29 12:19:06 +0100 | [diff] [blame] | 5751 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5752 | return 0; |
| 5753 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5754 | |
Eliad Peller | afa762f | 2012-04-23 14:45:15 +0300 | [diff] [blame] | 5755 | void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 54e4ffb | 2012-02-25 21:48:08 +0100 | [diff] [blame] | 5756 | { |
| 5757 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 5758 | |
Ben Greear | 4992185 | 2013-02-20 09:41:09 -0800 | [diff] [blame] | 5759 | /* |
| 5760 | * Make sure some work items will not run after this, |
| 5761 | * they will not do anything but might not have been |
| 5762 | * cancelled when disconnecting. |
| 5763 | */ |
| 5764 | cancel_work_sync(&ifmgd->monitor_work); |
| 5765 | cancel_work_sync(&ifmgd->beacon_connection_loss_work); |
| 5766 | cancel_work_sync(&ifmgd->request_smps_work); |
| 5767 | cancel_work_sync(&ifmgd->csa_connection_drop_work); |
| 5768 | cancel_work_sync(&ifmgd->chswitch_work); |
Arik Nemtsov | 81dd2b8 | 2014-07-17 17:14:25 +0300 | [diff] [blame] | 5769 | cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work); |
Ben Greear | 4992185 | 2013-02-20 09:41:09 -0800 | [diff] [blame] | 5770 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 5771 | sdata_lock(sdata); |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 5772 | if (ifmgd->assoc_data) { |
| 5773 | struct cfg80211_bss *bss = ifmgd->assoc_data->bss; |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 5774 | ieee80211_destroy_assoc_data(sdata, false, false); |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 5775 | cfg80211_assoc_timeout(sdata->dev, bss); |
| 5776 | } |
Johannes Berg | 54e4ffb | 2012-02-25 21:48:08 +0100 | [diff] [blame] | 5777 | if (ifmgd->auth_data) |
| 5778 | ieee80211_destroy_auth_data(sdata, false); |
Liad Kaufman | 1277b4a | 2014-11-09 18:50:08 +0200 | [diff] [blame] | 5779 | spin_lock_bh(&ifmgd->teardown_lock); |
| 5780 | if (ifmgd->teardown_skb) { |
| 5781 | kfree_skb(ifmgd->teardown_skb); |
| 5782 | ifmgd->teardown_skb = NULL; |
| 5783 | ifmgd->orig_teardown_skb = NULL; |
| 5784 | } |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 5785 | kfree(ifmgd->assoc_req_ies); |
| 5786 | ifmgd->assoc_req_ies = NULL; |
| 5787 | ifmgd->assoc_req_ies_len = 0; |
Liad Kaufman | 1277b4a | 2014-11-09 18:50:08 +0200 | [diff] [blame] | 5788 | spin_unlock_bh(&ifmgd->teardown_lock); |
Johannes Berg | 54e4ffb | 2012-02-25 21:48:08 +0100 | [diff] [blame] | 5789 | del_timer_sync(&ifmgd->timer); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 5790 | sdata_unlock(sdata); |
Johannes Berg | 54e4ffb | 2012-02-25 21:48:08 +0100 | [diff] [blame] | 5791 | } |
| 5792 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 5793 | void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif, |
| 5794 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
Andrzej Zaborowski | 769f07d | 2017-01-25 12:43:40 +0100 | [diff] [blame] | 5795 | s32 rssi_level, |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 5796 | gfp_t gfp) |
| 5797 | { |
| 5798 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 5799 | |
Andrzej Zaborowski | 769f07d | 2017-01-25 12:43:40 +0100 | [diff] [blame] | 5800 | trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level); |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 5801 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 5802 | cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp); |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 5803 | } |
| 5804 | EXPORT_SYMBOL(ieee80211_cqm_rssi_notify); |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 5805 | |
| 5806 | void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp) |
| 5807 | { |
| 5808 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 5809 | |
| 5810 | trace_api_cqm_beacon_loss_notify(sdata->local, sdata); |
| 5811 | |
| 5812 | cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp); |
| 5813 | } |
| 5814 | EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify); |