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 |
Johannes Berg | 9bd6a83e | 2021-06-18 13:41:53 +0300 | [diff] [blame] | 11 | * Copyright (C) 2018 - 2021 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, |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 152 | const struct ieee80211_s1g_oper_ie *s1g_oper, |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 153 | struct cfg80211_chan_def *chandef, bool tracking) |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 154 | { |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 155 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 156 | struct cfg80211_chan_def vht_chandef; |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 157 | struct ieee80211_sta_ht_cap sta_ht_cap; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 158 | u32 ht_cfreq, ret; |
| 159 | |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 160 | memset(chandef, 0, sizeof(struct cfg80211_chan_def)); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 161 | chandef->chan = channel; |
| 162 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 163 | chandef->center_freq1 = channel->center_freq; |
Thomas Pedersen | b6011960 | 2020-04-01 18:18:04 -0700 | [diff] [blame] | 164 | chandef->freq1_offset = channel->freq_offset; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 165 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 166 | if (channel->band == NL80211_BAND_6GHZ) { |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 167 | if (!ieee80211_chandef_he_6ghz_oper(sdata, he_oper, chandef)) { |
| 168 | mlme_dbg(sdata, |
| 169 | "bad 6 GHz operation, disabling HT/VHT/HE\n"); |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 170 | ret = IEEE80211_STA_DISABLE_HT | |
| 171 | IEEE80211_STA_DISABLE_VHT | |
| 172 | IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 173 | } else { |
Johannes Berg | 523f3ec | 2020-06-03 11:15:03 +0200 | [diff] [blame] | 174 | ret = 0; |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 175 | } |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 176 | vht_chandef = *chandef; |
| 177 | goto out; |
Thomas Pedersen | 75f87ea | 2020-10-01 10:47:48 -0700 | [diff] [blame] | 178 | } else if (sband->band == NL80211_BAND_S1GHZ) { |
| 179 | if (!ieee80211_chandef_s1g_oper(s1g_oper, chandef)) { |
| 180 | sdata_info(sdata, |
| 181 | "Missing S1G Operation Element? Trying operating == primary\n"); |
| 182 | chandef->width = ieee80211_s1g_channel_width(channel); |
| 183 | } |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 184 | |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 185 | ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_40MHZ | |
| 186 | IEEE80211_STA_DISABLE_VHT | |
| 187 | IEEE80211_STA_DISABLE_80P80MHZ | |
| 188 | IEEE80211_STA_DISABLE_160MHZ; |
| 189 | goto out; |
| 190 | } |
| 191 | |
Thomas Pedersen | 75f87ea | 2020-10-01 10:47:48 -0700 | [diff] [blame] | 192 | memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap)); |
| 193 | ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap); |
| 194 | |
Johannes Berg | b1b1ae2 | 2017-10-13 15:26:01 +0300 | [diff] [blame] | 195 | if (!ht_oper || !sta_ht_cap.ht_supported) { |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 196 | mlme_dbg(sdata, "HT operation missing / HT not supported\n"); |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 197 | ret = IEEE80211_STA_DISABLE_HT | |
| 198 | IEEE80211_STA_DISABLE_VHT | |
| 199 | IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 200 | goto out; |
| 201 | } |
| 202 | |
| 203 | chandef->width = NL80211_CHAN_WIDTH_20; |
| 204 | |
| 205 | ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan, |
| 206 | channel->band); |
| 207 | /* check that channel matches the right operating channel */ |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 208 | if (!tracking && channel->center_freq != ht_cfreq) { |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 209 | /* |
| 210 | * It's possible that some APs are confused here; |
| 211 | * Netgear WNDR3700 sometimes reports 4 higher than |
| 212 | * the actual channel in association responses, but |
| 213 | * since we look at probe response/beacon data here |
| 214 | * it should be OK. |
| 215 | */ |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 216 | sdata_info(sdata, |
| 217 | "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n", |
| 218 | channel->center_freq, ht_cfreq, |
| 219 | ht_oper->primary_chan, channel->band); |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 220 | ret = IEEE80211_STA_DISABLE_HT | |
| 221 | IEEE80211_STA_DISABLE_VHT | |
| 222 | IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 223 | goto out; |
| 224 | } |
| 225 | |
| 226 | /* check 40 MHz support, if we have it */ |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 227 | if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) { |
Johannes Berg | 8ac3c704 | 2015-12-18 15:08:34 +0100 | [diff] [blame] | 228 | ieee80211_chandef_ht_oper(ht_oper, chandef); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 229 | } else { |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 230 | mlme_dbg(sdata, "40 MHz not supported\n"); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 231 | /* 40 MHz (and 80 MHz) must be supported for VHT */ |
| 232 | ret = IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 85220d7 | 2013-03-25 18:29:27 +0100 | [diff] [blame] | 233 | /* also mark 40 MHz disabled */ |
| 234 | ret |= IEEE80211_STA_DISABLE_40MHZ; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 235 | goto out; |
| 236 | } |
| 237 | |
| 238 | if (!vht_oper || !sband->vht_cap.vht_supported) { |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 239 | mlme_dbg(sdata, "VHT operation missing / VHT not supported\n"); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 240 | ret = IEEE80211_STA_DISABLE_VHT; |
| 241 | goto out; |
| 242 | } |
| 243 | |
Johannes Berg | 8ac3c704 | 2015-12-18 15:08:34 +0100 | [diff] [blame] | 244 | vht_chandef = *chandef; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 245 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && he_oper && |
| 246 | (le32_to_cpu(he_oper->he_oper_params) & |
| 247 | IEEE80211_HE_OPERATION_VHT_OPER_INFO)) { |
| 248 | struct ieee80211_vht_operation he_oper_vht_cap; |
| 249 | |
| 250 | /* |
| 251 | * Set only first 3 bytes (other 2 aren't used in |
| 252 | * ieee80211_chandef_vht_oper() anyway) |
| 253 | */ |
| 254 | memcpy(&he_oper_vht_cap, he_oper->optional, 3); |
| 255 | he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0); |
| 256 | |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 257 | if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_cap_info, |
Johannes Berg | 7eb26df | 2018-08-31 11:31:18 +0300 | [diff] [blame] | 258 | &he_oper_vht_cap, ht_oper, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 259 | &vht_chandef)) { |
| 260 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) |
| 261 | sdata_info(sdata, |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 262 | "HE AP VHT information is invalid, disabling HE\n"); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 263 | ret = IEEE80211_STA_DISABLE_HE; |
| 264 | goto out; |
| 265 | } |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 266 | } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw, |
| 267 | vht_cap_info, |
| 268 | vht_oper, ht_oper, |
| 269 | &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, |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 272 | "AP VHT information is invalid, disabling 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 | if (!cfg80211_chandef_valid(&vht_chandef)) { |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 278 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 279 | sdata_info(sdata, |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 280 | "AP VHT information is invalid, disabling VHT\n"); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 281 | ret = IEEE80211_STA_DISABLE_VHT; |
| 282 | goto out; |
| 283 | } |
| 284 | |
| 285 | if (cfg80211_chandef_identical(chandef, &vht_chandef)) { |
| 286 | ret = 0; |
| 287 | goto out; |
| 288 | } |
| 289 | |
| 290 | if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) { |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 291 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 292 | sdata_info(sdata, |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 293 | "AP VHT information doesn't match HT, disabling VHT\n"); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 294 | ret = IEEE80211_STA_DISABLE_VHT; |
| 295 | goto out; |
| 296 | } |
| 297 | |
| 298 | *chandef = vht_chandef; |
| 299 | |
| 300 | ret = 0; |
| 301 | |
| 302 | out: |
Johannes Berg | 963a1852 | 2014-02-21 20:34:34 +0100 | [diff] [blame] | 303 | /* |
| 304 | * When tracking the current AP, don't do any further checks if the |
| 305 | * new chandef is identical to the one we're currently using for the |
| 306 | * connection. This keeps us from playing ping-pong with regulatory, |
| 307 | * without it the following can happen (for example): |
| 308 | * - connect to an AP with 80 MHz, world regdom allows 80 MHz |
| 309 | * - AP advertises regdom US |
| 310 | * - CRDA loads regdom US with 80 MHz prohibited (old database) |
| 311 | * - the code below detects an unsupported channel, downgrades, and |
| 312 | * we disconnect from the AP in the caller |
| 313 | * - disconnect causes CRDA to reload world regdomain and the game |
| 314 | * starts anew. |
| 315 | * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881) |
| 316 | * |
| 317 | * It seems possible that there are still scenarios with CSA or real |
| 318 | * bandwidth changes where a this could happen, but those cases are |
| 319 | * less common and wouldn't completely prevent using the AP. |
| 320 | */ |
| 321 | if (tracking && |
| 322 | cfg80211_chandef_identical(chandef, &sdata->vif.bss_conf.chandef)) |
| 323 | return ret; |
| 324 | |
Johannes Berg | 586e01e | 2013-02-14 12:13:53 +0100 | [diff] [blame] | 325 | /* don't print the message below for VHT mismatch if VHT is disabled */ |
| 326 | if (ret & IEEE80211_STA_DISABLE_VHT) |
| 327 | vht_chandef = *chandef; |
| 328 | |
Johannes Berg | ddfe49b | 2013-07-31 20:52:03 +0200 | [diff] [blame] | 329 | /* |
| 330 | * Ignore the DISABLED flag when we're already connected and only |
| 331 | * tracking the APs beacon for bandwidth changes - otherwise we |
| 332 | * might get disconnected here if we connect to an AP, update our |
| 333 | * regulatory information based on the AP's country IE and the |
| 334 | * information we have is wrong/outdated and disables the channel |
| 335 | * that we're actually using for the connection to the AP. |
| 336 | */ |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 337 | while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef, |
Johannes Berg | ddfe49b | 2013-07-31 20:52:03 +0200 | [diff] [blame] | 338 | tracking ? 0 : |
| 339 | IEEE80211_CHAN_DISABLED)) { |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 340 | if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) { |
| 341 | ret = IEEE80211_STA_DISABLE_HT | |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 342 | IEEE80211_STA_DISABLE_VHT | |
| 343 | IEEE80211_STA_DISABLE_HE; |
Chris Wright | b56e4b8 | 2013-07-31 12:12:24 -0700 | [diff] [blame] | 344 | break; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 345 | } |
| 346 | |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 347 | ret |= ieee80211_chandef_downgrade(chandef); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 348 | } |
| 349 | |
Daniel Gabay | 8cadb20 | 2020-01-31 13:12:52 +0200 | [diff] [blame] | 350 | if (!he_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef, |
| 351 | IEEE80211_CHAN_NO_HE)) |
Haim Dreyfuss | b5db1ac | 2020-01-31 13:12:44 +0200 | [diff] [blame] | 352 | ret |= IEEE80211_STA_DISABLE_HE; |
| 353 | |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 354 | if (chandef->width != vht_chandef.width && !tracking) |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 355 | sdata_info(sdata, |
| 356 | "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n"); |
| 357 | |
| 358 | WARN_ON_ONCE(!cfg80211_chandef_valid(chandef)); |
| 359 | return ret; |
| 360 | } |
| 361 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 362 | static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata, |
| 363 | struct sta_info *sta, |
Eliad Peller | 53b954e | 2014-07-24 11:20:05 +0300 | [diff] [blame] | 364 | const struct ieee80211_ht_cap *ht_cap, |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 365 | const struct ieee80211_vht_cap *vht_cap, |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 366 | const struct ieee80211_ht_operation *ht_oper, |
| 367 | const struct ieee80211_vht_operation *vht_oper, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 368 | const struct ieee80211_he_operation *he_oper, |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 369 | const struct ieee80211_s1g_oper_ie *s1g_oper, |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 370 | const u8 *bssid, u32 *changed) |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 371 | { |
| 372 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 373 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 374 | struct ieee80211_channel *chan = sdata->vif.bss_conf.chandef.chan; |
| 375 | struct ieee80211_supported_band *sband = |
| 376 | local->hw.wiphy->bands[chan->band]; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 377 | struct cfg80211_chan_def chandef; |
Johannes Berg | 9ed6bcc | 2009-05-08 20:47:39 +0200 | [diff] [blame] | 378 | u16 ht_opmode; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 379 | u32 flags; |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 380 | u32 vht_cap_info = 0; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 381 | int ret; |
| 382 | |
| 383 | /* if HT was/is disabled, don't track any bandwidth changes */ |
| 384 | if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper) |
| 385 | return 0; |
| 386 | |
| 387 | /* don't check VHT if we associated as non-VHT station */ |
| 388 | if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT) |
| 389 | vht_oper = NULL; |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 390 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 391 | /* don't check HE if we associated as non-HE station */ |
| 392 | if (ifmgd->flags & IEEE80211_STA_DISABLE_HE || |
Johannes Berg | bac2fd3 | 2021-06-18 13:41:50 +0300 | [diff] [blame] | 393 | !ieee80211_get_he_iftype_cap(sband, |
| 394 | ieee80211_vif_type_p2p(&sdata->vif))) |
| 395 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 396 | he_oper = NULL; |
| 397 | |
Johannes Berg | 1128958 | 2013-02-07 17:36:12 +0100 | [diff] [blame] | 398 | if (WARN_ON_ONCE(!sta)) |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 399 | return -EINVAL; |
Johannes Berg | 1128958 | 2013-02-07 17:36:12 +0100 | [diff] [blame] | 400 | |
Avri Altman | 017b45b | 2013-11-18 19:06:48 +0200 | [diff] [blame] | 401 | /* |
| 402 | * if bss configuration changed store the new one - |
| 403 | * this may be applicable even if channel is identical |
| 404 | */ |
| 405 | ht_opmode = le16_to_cpu(ht_oper->operation_mode); |
| 406 | if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) { |
| 407 | *changed |= BSS_CHANGED_HT; |
| 408 | sdata->vif.bss_conf.ht_operation_mode = ht_opmode; |
| 409 | } |
| 410 | |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 411 | if (vht_cap) |
| 412 | vht_cap_info = le32_to_cpu(vht_cap->vht_cap_info); |
| 413 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 414 | /* calculate new channel (type) based on HT/VHT/HE operation IEs */ |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 415 | flags = ieee80211_determine_chantype(sdata, sband, chan, vht_cap_info, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 416 | ht_oper, vht_oper, he_oper, |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 417 | s1g_oper, &chandef, true); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 418 | |
| 419 | /* |
| 420 | * Downgrade the new channel if we associated with restricted |
| 421 | * capabilities. For example, if we associated as a 20 MHz STA |
| 422 | * to a 40 MHz AP (due to regulatory, capabilities or config |
| 423 | * reasons) then switching to a 40 MHz channel now won't do us |
| 424 | * any good -- we couldn't use it with the AP. |
| 425 | */ |
| 426 | if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ && |
| 427 | chandef.width == NL80211_CHAN_WIDTH_80P80) |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 428 | flags |= ieee80211_chandef_downgrade(&chandef); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 429 | if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ && |
| 430 | chandef.width == NL80211_CHAN_WIDTH_160) |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 431 | flags |= ieee80211_chandef_downgrade(&chandef); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 432 | if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ && |
| 433 | chandef.width > NL80211_CHAN_WIDTH_20) |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 434 | flags |= ieee80211_chandef_downgrade(&chandef); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 435 | |
| 436 | if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef)) |
| 437 | return 0; |
| 438 | |
| 439 | sdata_info(sdata, |
Thomas Pedersen | b6011960 | 2020-04-01 18:18:04 -0700 | [diff] [blame] | 440 | "AP %pM changed bandwidth, new config is %d.%03d MHz, " |
| 441 | "width %d (%d.%03d/%d MHz)\n", |
| 442 | ifmgd->bssid, chandef.chan->center_freq, |
| 443 | chandef.chan->freq_offset, chandef.width, |
| 444 | chandef.center_freq1, chandef.freq1_offset, |
| 445 | chandef.center_freq2); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 446 | |
| 447 | if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT | |
| 448 | IEEE80211_STA_DISABLE_VHT | |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 449 | IEEE80211_STA_DISABLE_HE | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 450 | IEEE80211_STA_DISABLE_40MHZ | |
| 451 | IEEE80211_STA_DISABLE_80P80MHZ | |
| 452 | IEEE80211_STA_DISABLE_160MHZ)) || |
| 453 | !cfg80211_chandef_valid(&chandef)) { |
| 454 | sdata_info(sdata, |
Johannes Berg | 6516ee2 | 2021-06-18 13:41:47 +0300 | [diff] [blame] | 455 | "AP %pM changed caps/bw in a way we can't support (0x%x/0x%x) - disconnect\n", |
| 456 | ifmgd->bssid, flags, ifmgd->flags); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 457 | return -EINVAL; |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 458 | } |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 459 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 460 | ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed); |
Mordechay Goodstein | d6c3750 | 2021-06-18 13:41:30 +0300 | [diff] [blame] | 461 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 462 | if (ret) { |
| 463 | sdata_info(sdata, |
| 464 | "AP %pM changed bandwidth to incompatible one - disconnect\n", |
| 465 | ifmgd->bssid); |
| 466 | return ret; |
| 467 | } |
| 468 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 469 | return 0; |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 470 | } |
| 471 | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 472 | /* frame sending functions */ |
| 473 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 474 | static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 475 | struct sk_buff *skb, u8 ap_ht_param, |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 476 | struct ieee80211_supported_band *sband, |
| 477 | struct ieee80211_channel *channel, |
| 478 | enum ieee80211_smps_mode smps) |
| 479 | { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 480 | u8 *pos; |
| 481 | u32 flags = channel->flags; |
| 482 | u16 cap; |
| 483 | struct ieee80211_sta_ht_cap ht_cap; |
| 484 | |
| 485 | BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap)); |
| 486 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 487 | memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap)); |
| 488 | ieee80211_apply_htcap_overrides(sdata, &ht_cap); |
| 489 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 490 | /* determine capability flags */ |
| 491 | cap = ht_cap.cap; |
| 492 | |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 493 | switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 494 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: |
| 495 | if (flags & IEEE80211_CHAN_NO_HT40PLUS) { |
| 496 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 497 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 498 | } |
| 499 | break; |
| 500 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: |
| 501 | if (flags & IEEE80211_CHAN_NO_HT40MINUS) { |
| 502 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 503 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 504 | } |
| 505 | break; |
| 506 | } |
| 507 | |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 508 | /* |
| 509 | * If 40 MHz was disabled associate as though we weren't |
| 510 | * capable of 40 MHz -- some broken APs will never fall |
| 511 | * back to trying to transmit in 20 MHz. |
| 512 | */ |
| 513 | if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) { |
| 514 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 515 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 516 | } |
| 517 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 518 | /* set SM PS mode properly */ |
| 519 | cap &= ~IEEE80211_HT_CAP_SM_PS; |
| 520 | switch (smps) { |
| 521 | case IEEE80211_SMPS_AUTOMATIC: |
| 522 | case IEEE80211_SMPS_NUM_MODES: |
| 523 | WARN_ON(1); |
Gustavo A. R. Silva | fc0561d | 2020-07-07 15:45:48 -0500 | [diff] [blame] | 524 | fallthrough; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 525 | case IEEE80211_SMPS_OFF: |
| 526 | cap |= WLAN_HT_CAP_SM_PS_DISABLED << |
| 527 | IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 528 | break; |
| 529 | case IEEE80211_SMPS_STATIC: |
| 530 | cap |= WLAN_HT_CAP_SM_PS_STATIC << |
| 531 | IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 532 | break; |
| 533 | case IEEE80211_SMPS_DYNAMIC: |
| 534 | cap |= WLAN_HT_CAP_SM_PS_DYNAMIC << |
| 535 | IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 536 | break; |
| 537 | } |
| 538 | |
| 539 | /* reserve and fill IE */ |
| 540 | pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2); |
| 541 | ieee80211_ie_build_ht_cap(pos, &ht_cap, cap); |
| 542 | } |
| 543 | |
Sara Sharon | 322cd40 | 2015-07-08 15:41:43 +0300 | [diff] [blame] | 544 | /* This function determines vht capability flags for the association |
| 545 | * and builds the IE. |
| 546 | * Note - the function may set the owner of the MU-MIMO capability |
| 547 | */ |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 548 | static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata, |
| 549 | struct sk_buff *skb, |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 550 | struct ieee80211_supported_band *sband, |
| 551 | struct ieee80211_vht_cap *ap_vht_cap) |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 552 | { |
Sara Sharon | 322cd40 | 2015-07-08 15:41:43 +0300 | [diff] [blame] | 553 | struct ieee80211_local *local = sdata->local; |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 554 | u8 *pos; |
| 555 | u32 cap; |
| 556 | struct ieee80211_sta_vht_cap vht_cap; |
Eyal Shapira | c1cf6d4 | 2014-01-08 15:49:08 +0200 | [diff] [blame] | 557 | u32 mask, ap_bf_sts, our_bf_sts; |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 558 | |
| 559 | BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap)); |
| 560 | |
| 561 | memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap)); |
Johannes Berg | dd5ecfe | 2013-02-21 17:40:19 +0100 | [diff] [blame] | 562 | ieee80211_apply_vhtcap_overrides(sdata, &vht_cap); |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 563 | |
| 564 | /* determine capability flags */ |
| 565 | cap = vht_cap.cap; |
| 566 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 567 | if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) { |
Johannes Berg | 575f053 | 2014-11-24 16:51:33 +0100 | [diff] [blame] | 568 | u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; |
| 569 | |
| 570 | cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; |
| 571 | if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ || |
| 572 | bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ) |
| 573 | cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) { |
| 577 | cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160; |
Johannes Berg | 575f053 | 2014-11-24 16:51:33 +0100 | [diff] [blame] | 578 | cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 579 | } |
| 580 | |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 581 | /* |
| 582 | * Some APs apparently get confused if our capabilities are better |
| 583 | * than theirs, so restrict what we advertise in the assoc request. |
| 584 | */ |
| 585 | if (!(ap_vht_cap->vht_cap_info & |
| 586 | cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE))) |
Sara Sharon | 322cd40 | 2015-07-08 15:41:43 +0300 | [diff] [blame] | 587 | cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
| 588 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE); |
| 589 | else if (!(ap_vht_cap->vht_cap_info & |
| 590 | cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))) |
| 591 | cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE; |
| 592 | |
| 593 | /* |
Zheng Yongjun | ab4040d | 2021-06-07 23:00:47 +0800 | [diff] [blame] | 594 | * If some other vif is using the MU-MIMO capability we cannot associate |
Sara Sharon | 322cd40 | 2015-07-08 15:41:43 +0300 | [diff] [blame] | 595 | * using MU-MIMO - this will lead to contradictions in the group-id |
| 596 | * mechanism. |
| 597 | * Ownership is defined since association request, in order to avoid |
| 598 | * simultaneous associations with MU-MIMO. |
| 599 | */ |
| 600 | if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) { |
| 601 | bool disable_mu_mimo = false; |
| 602 | struct ieee80211_sub_if_data *other; |
| 603 | |
| 604 | list_for_each_entry_rcu(other, &local->interfaces, list) { |
Sara Sharon | b5a33d5 | 2016-02-16 12:48:18 +0200 | [diff] [blame] | 605 | if (other->vif.mu_mimo_owner) { |
Sara Sharon | 322cd40 | 2015-07-08 15:41:43 +0300 | [diff] [blame] | 606 | disable_mu_mimo = true; |
| 607 | break; |
| 608 | } |
| 609 | } |
| 610 | if (disable_mu_mimo) |
| 611 | cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE; |
| 612 | else |
Sara Sharon | b5a33d5 | 2016-02-16 12:48:18 +0200 | [diff] [blame] | 613 | sdata->vif.mu_mimo_owner = true; |
Sara Sharon | 322cd40 | 2015-07-08 15:41:43 +0300 | [diff] [blame] | 614 | } |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 615 | |
Eyal Shapira | c1cf6d4 | 2014-01-08 15:49:08 +0200 | [diff] [blame] | 616 | mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK; |
| 617 | |
| 618 | ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask; |
| 619 | our_bf_sts = cap & mask; |
| 620 | |
| 621 | if (ap_bf_sts < our_bf_sts) { |
| 622 | cap &= ~mask; |
| 623 | cap |= ap_bf_sts; |
| 624 | } |
| 625 | |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 626 | /* reserve and fill IE */ |
Mahesh Palivela | d495028 | 2012-10-10 11:25:40 +0000 | [diff] [blame] | 627 | pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2); |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 628 | ieee80211_ie_build_vht_cap(pos, &vht_cap, cap); |
| 629 | } |
| 630 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 631 | /* This function determines HE capability flags for the association |
| 632 | * and builds the IE. |
| 633 | */ |
| 634 | static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata, |
| 635 | struct sk_buff *skb, |
| 636 | struct ieee80211_supported_band *sband) |
| 637 | { |
| 638 | u8 *pos; |
| 639 | const struct ieee80211_sta_he_cap *he_cap = NULL; |
Haim Dreyfuss | b5db1ac | 2020-01-31 13:12:44 +0200 | [diff] [blame] | 640 | struct ieee80211_chanctx_conf *chanctx_conf; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 641 | u8 he_cap_size; |
Haim Dreyfuss | b5db1ac | 2020-01-31 13:12:44 +0200 | [diff] [blame] | 642 | bool reg_cap = false; |
| 643 | |
| 644 | rcu_read_lock(); |
| 645 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 646 | if (!WARN_ON_ONCE(!chanctx_conf)) |
| 647 | reg_cap = cfg80211_chandef_usable(sdata->wdev.wiphy, |
| 648 | &chanctx_conf->def, |
| 649 | IEEE80211_CHAN_NO_HE); |
| 650 | |
| 651 | rcu_read_unlock(); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 652 | |
Johannes Berg | bac2fd3 | 2021-06-18 13:41:50 +0300 | [diff] [blame] | 653 | he_cap = ieee80211_get_he_iftype_cap(sband, |
| 654 | ieee80211_vif_type_p2p(&sdata->vif)); |
Haim Dreyfuss | b5db1ac | 2020-01-31 13:12:44 +0200 | [diff] [blame] | 655 | if (!he_cap || !reg_cap) |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 656 | return; |
| 657 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 658 | he_cap_size = |
| 659 | 2 + 1 + sizeof(he_cap->he_cap_elem) + |
| 660 | ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) + |
| 661 | ieee80211_he_ppe_size(he_cap->ppe_thres[0], |
| 662 | he_cap->he_cap_elem.phy_cap_info); |
| 663 | pos = skb_put(skb, he_cap_size); |
| 664 | ieee80211_ie_build_he_cap(pos, he_cap, pos + he_cap_size); |
Rajkumar Manoharan | 24a2042 | 2020-05-28 21:34:32 +0200 | [diff] [blame] | 665 | |
| 666 | ieee80211_ie_build_he_6ghz_cap(sdata, skb); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 667 | } |
| 668 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 669 | static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata) |
| 670 | { |
| 671 | struct ieee80211_local *local = sdata->local; |
| 672 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 673 | struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; |
| 674 | struct sk_buff *skb; |
| 675 | struct ieee80211_mgmt *mgmt; |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 676 | u8 *pos, qos_info, *ie_start; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 677 | size_t offset = 0, noffset; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 678 | int i, count, rates_len, supp_rates_len, shift; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 679 | u16 capab; |
| 680 | struct ieee80211_supported_band *sband; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 681 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 682 | struct ieee80211_channel *chan; |
Johannes Berg | 44f6d42 | 2017-06-10 13:52:44 +0300 | [diff] [blame] | 683 | u32 rates = 0; |
Thomas Pedersen | 05d1095 | 2020-09-21 19:28:10 -0700 | [diff] [blame] | 684 | __le16 listen_int; |
Johannes Berg | 2ff69b0 | 2020-01-31 13:31:11 +0200 | [diff] [blame] | 685 | struct element *ext_capa = NULL; |
Johannes Berg | 9bd6a83e | 2021-06-18 13:41:53 +0300 | [diff] [blame] | 686 | enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif); |
| 687 | const struct ieee80211_sband_iftype_data *iftd; |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 688 | struct ieee80211_prep_tx_info info = {}; |
Johannes Berg | 2ff69b0 | 2020-01-31 13:31:11 +0200 | [diff] [blame] | 689 | |
| 690 | /* we know it's writable, cast away the const */ |
| 691 | if (assoc_data->ie_len) |
| 692 | ext_capa = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, |
| 693 | assoc_data->ie, |
| 694 | assoc_data->ie_len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 695 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 696 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 697 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 698 | rcu_read_lock(); |
| 699 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 700 | if (WARN_ON(!chanctx_conf)) { |
| 701 | rcu_read_unlock(); |
| 702 | return; |
| 703 | } |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 704 | chan = chanctx_conf->def.chan; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 705 | rcu_read_unlock(); |
| 706 | sband = local->hw.wiphy->bands[chan->band]; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 707 | shift = ieee80211_vif_get_shift(&sdata->vif); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 708 | |
| 709 | if (assoc_data->supp_rates_len) { |
| 710 | /* |
| 711 | * Get all rates supported by the device and the AP as |
| 712 | * some APs don't like getting a superset of their rates |
| 713 | * in the association request (e.g. D-Link DAP 1353 in |
| 714 | * b-only mode)... |
| 715 | */ |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 716 | rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband, |
| 717 | assoc_data->supp_rates, |
| 718 | assoc_data->supp_rates_len, |
| 719 | &rates); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 720 | } else { |
| 721 | /* |
| 722 | * In case AP not provide any supported rates information |
| 723 | * before association, we send information element(s) with |
| 724 | * all rates that we support. |
| 725 | */ |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 726 | rates_len = 0; |
| 727 | for (i = 0; i < sband->n_bitrates; i++) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 728 | rates |= BIT(i); |
| 729 | rates_len++; |
| 730 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 731 | } |
| 732 | |
Johannes Berg | 9bd6a83e | 2021-06-18 13:41:53 +0300 | [diff] [blame] | 733 | iftd = ieee80211_get_sband_iftype_data(sband, iftype); |
| 734 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 735 | skb = alloc_skb(local->hw.extra_tx_headroom + |
| 736 | sizeof(*mgmt) + /* bit too much but doesn't matter */ |
| 737 | 2 + assoc_data->ssid_len + /* SSID */ |
| 738 | 4 + rates_len + /* (extended) rates */ |
| 739 | 4 + /* power capability */ |
| 740 | 2 + 2 * sband->n_channels + /* supported channels */ |
| 741 | 2 + sizeof(struct ieee80211_ht_cap) + /* HT */ |
Mahesh Palivela | d495028 | 2012-10-10 11:25:40 +0000 | [diff] [blame] | 742 | 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */ |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 743 | 2 + 1 + sizeof(struct ieee80211_he_cap_elem) + /* HE */ |
| 744 | sizeof(struct ieee80211_he_mcs_nss_supp) + |
| 745 | IEEE80211_HE_PPE_THRES_MAX_LEN + |
Rajkumar Manoharan | 24a2042 | 2020-05-28 21:34:32 +0200 | [diff] [blame] | 746 | 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa) + |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 747 | assoc_data->ie_len + /* extra IEs */ |
Jouni Malinen | 39404fe | 2016-10-27 00:42:05 +0300 | [diff] [blame] | 748 | (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) + |
Johannes Berg | 9bd6a83e | 2021-06-18 13:41:53 +0300 | [diff] [blame] | 749 | 9 + /* WMM */ |
| 750 | (iftd ? iftd->vendor_elems.len : 0), |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 751 | GFP_KERNEL); |
| 752 | if (!skb) |
| 753 | return; |
| 754 | |
| 755 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 756 | |
| 757 | capab = WLAN_CAPABILITY_ESS; |
| 758 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 759 | if (sband->band == NL80211_BAND_2GHZ) { |
Johannes Berg | ea1b2b45 | 2015-06-02 20:15:49 +0200 | [diff] [blame] | 760 | capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME; |
| 761 | capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY) |
| 765 | capab |= WLAN_CAPABILITY_PRIVACY; |
| 766 | |
| 767 | if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) && |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 768 | ieee80211_hw_check(&local->hw, SPECTRUM_MGMT)) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 769 | capab |= WLAN_CAPABILITY_SPECTRUM_MGMT; |
| 770 | |
Assaf Krauss | cd2f5dd | 2014-09-03 15:25:02 +0300 | [diff] [blame] | 771 | if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM) |
| 772 | capab |= WLAN_CAPABILITY_RADIO_MEASURE; |
| 773 | |
Johannes Berg | b080db5 | 2017-06-16 14:29:19 +0200 | [diff] [blame] | 774 | mgmt = skb_put_zero(skb, 24); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 775 | memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN); |
| 776 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
| 777 | memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN); |
| 778 | |
Thomas Pedersen | 05d1095 | 2020-09-21 19:28:10 -0700 | [diff] [blame] | 779 | listen_int = cpu_to_le16(sband->band == NL80211_BAND_S1GHZ ? |
| 780 | ieee80211_encode_usf(local->hw.conf.listen_interval) : |
| 781 | local->hw.conf.listen_interval); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 782 | if (!is_zero_ether_addr(assoc_data->prev_bssid)) { |
| 783 | skb_put(skb, 10); |
| 784 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 785 | IEEE80211_STYPE_REASSOC_REQ); |
| 786 | mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab); |
Thomas Pedersen | 05d1095 | 2020-09-21 19:28:10 -0700 | [diff] [blame] | 787 | mgmt->u.reassoc_req.listen_interval = listen_int; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 788 | memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid, |
| 789 | ETH_ALEN); |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 790 | info.subtype = IEEE80211_STYPE_REASSOC_REQ; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 791 | } else { |
| 792 | skb_put(skb, 4); |
| 793 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 794 | IEEE80211_STYPE_ASSOC_REQ); |
| 795 | mgmt->u.assoc_req.capab_info = cpu_to_le16(capab); |
Thomas Pedersen | 05d1095 | 2020-09-21 19:28:10 -0700 | [diff] [blame] | 796 | mgmt->u.assoc_req.listen_interval = listen_int; |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 797 | info.subtype = IEEE80211_STYPE_ASSOC_REQ; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | /* SSID */ |
| 801 | pos = skb_put(skb, 2 + assoc_data->ssid_len); |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 802 | ie_start = pos; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 803 | *pos++ = WLAN_EID_SSID; |
| 804 | *pos++ = assoc_data->ssid_len; |
| 805 | memcpy(pos, assoc_data->ssid, assoc_data->ssid_len); |
| 806 | |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 807 | if (sband->band == NL80211_BAND_S1GHZ) |
| 808 | goto skip_rates; |
| 809 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 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 | |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 845 | skip_rates: |
Assaf Krauss | cd2f5dd | 2014-09-03 15:25:02 +0300 | [diff] [blame] | 846 | if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT || |
| 847 | capab & WLAN_CAPABILITY_RADIO_MEASURE) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 848 | pos = skb_put(skb, 4); |
| 849 | *pos++ = WLAN_EID_PWR_CAPABILITY; |
| 850 | *pos++ = 2; |
| 851 | *pos++ = 0; /* min tx power */ |
Simon Wunderlich | 0430c88 | 2013-07-08 16:55:55 +0200 | [diff] [blame] | 852 | /* max tx power */ |
| 853 | *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def); |
Assaf Krauss | cd2f5dd | 2014-09-03 15:25:02 +0300 | [diff] [blame] | 854 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 855 | |
Johannes Berg | 2ff69b0 | 2020-01-31 13:31:11 +0200 | [diff] [blame] | 856 | /* |
| 857 | * Per spec, we shouldn't include the list of channels if we advertise |
| 858 | * support for extended channel switching, but we've always done that; |
| 859 | * (for now?) apply this restriction only on the (new) 6 GHz band. |
| 860 | */ |
| 861 | if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT && |
| 862 | (sband->band != NL80211_BAND_6GHZ || |
| 863 | !ext_capa || ext_capa->datalen < 1 || |
| 864 | !(ext_capa->data[0] & WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING))) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 865 | /* TODO: get this in reg domain format */ |
| 866 | pos = skb_put(skb, 2 * sband->n_channels + 2); |
| 867 | *pos++ = WLAN_EID_SUPPORTED_CHANNELS; |
| 868 | *pos++ = 2 * sband->n_channels; |
| 869 | for (i = 0; i < sband->n_channels; i++) { |
| 870 | *pos++ = ieee80211_frequency_to_channel( |
| 871 | sband->channels[i].center_freq); |
| 872 | *pos++ = 1; /* one channel in the subband*/ |
| 873 | } |
| 874 | } |
| 875 | |
Sara Sharon | caf5633 | 2019-01-16 23:03:25 +0200 | [diff] [blame] | 876 | /* Set MBSSID support for HE AP if needed */ |
| 877 | if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) && |
Johannes Berg | 2ff69b0 | 2020-01-31 13:31:11 +0200 | [diff] [blame] | 878 | !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && assoc_data->ie_len && |
| 879 | ext_capa && ext_capa->datalen >= 3) |
| 880 | ext_capa->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT; |
Sara Sharon | caf5633 | 2019-01-16 23:03:25 +0200 | [diff] [blame] | 881 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 882 | /* if present, add any custom IEs that go before HT */ |
Johannes Berg | b3f51e9 | 2013-10-25 11:31:42 +0200 | [diff] [blame] | 883 | if (assoc_data->ie_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 884 | static const u8 before_ht[] = { |
| 885 | WLAN_EID_SSID, |
| 886 | WLAN_EID_SUPP_RATES, |
| 887 | WLAN_EID_EXT_SUPP_RATES, |
| 888 | WLAN_EID_PWR_CAPABILITY, |
| 889 | WLAN_EID_SUPPORTED_CHANNELS, |
| 890 | WLAN_EID_RSN, |
| 891 | WLAN_EID_QOS_CAPA, |
| 892 | WLAN_EID_RRM_ENABLED_CAPABILITIES, |
| 893 | WLAN_EID_MOBILITY_DOMAIN, |
Johannes Berg | 8ed2874 | 2014-10-27 12:03:19 +0100 | [diff] [blame] | 894 | WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */ |
| 895 | WLAN_EID_RIC_DATA, /* reassoc only */ |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 896 | WLAN_EID_SUPPORTED_REGULATORY_CLASSES, |
| 897 | }; |
Johannes Berg | 8ed2874 | 2014-10-27 12:03:19 +0100 | [diff] [blame] | 898 | static const u8 after_ric[] = { |
| 899 | WLAN_EID_SUPPORTED_REGULATORY_CLASSES, |
| 900 | WLAN_EID_HT_CAPABILITY, |
| 901 | WLAN_EID_BSS_COEX_2040, |
Johannes Berg | a7f26d8 | 2017-08-05 11:44:32 +0300 | [diff] [blame] | 902 | /* luckily this is almost always there */ |
Johannes Berg | 8ed2874 | 2014-10-27 12:03:19 +0100 | [diff] [blame] | 903 | WLAN_EID_EXT_CAPABILITY, |
| 904 | WLAN_EID_QOS_TRAFFIC_CAPA, |
| 905 | WLAN_EID_TIM_BCAST_REQ, |
| 906 | WLAN_EID_INTERWORKING, |
Johannes Berg | a7f26d8 | 2017-08-05 11:44:32 +0300 | [diff] [blame] | 907 | /* 60 GHz (Multi-band, DMG, MMS) can't happen */ |
Johannes Berg | 8ed2874 | 2014-10-27 12:03:19 +0100 | [diff] [blame] | 908 | WLAN_EID_VHT_CAPABILITY, |
| 909 | WLAN_EID_OPMODE_NOTIF, |
| 910 | }; |
| 911 | |
| 912 | noffset = ieee80211_ie_split_ric(assoc_data->ie, |
| 913 | assoc_data->ie_len, |
| 914 | before_ht, |
| 915 | ARRAY_SIZE(before_ht), |
| 916 | after_ric, |
| 917 | ARRAY_SIZE(after_ric), |
| 918 | offset); |
yuan linyu | b952f4d | 2017-06-18 22:52:04 +0800 | [diff] [blame] | 919 | skb_put_data(skb, assoc_data->ie + offset, noffset - offset); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 920 | offset = noffset; |
| 921 | } |
| 922 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 923 | if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) && |
| 924 | !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))) |
| 925 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
| 926 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 927 | if (sband->band != NL80211_BAND_6GHZ && |
| 928 | !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 929 | ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param, |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 930 | sband, chan, sdata->smps_mode); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 931 | |
Johannes Berg | 3de3802 | 2014-02-04 09:54:07 +0100 | [diff] [blame] | 932 | /* if present, add any custom IEs that go before VHT */ |
| 933 | if (assoc_data->ie_len) { |
| 934 | static const u8 before_vht[] = { |
Johannes Berg | a7f26d8 | 2017-08-05 11:44:32 +0300 | [diff] [blame] | 935 | /* |
| 936 | * no need to list the ones split off before HT |
| 937 | * or generated here |
| 938 | */ |
Johannes Berg | 3de3802 | 2014-02-04 09:54:07 +0100 | [diff] [blame] | 939 | WLAN_EID_BSS_COEX_2040, |
| 940 | WLAN_EID_EXT_CAPABILITY, |
| 941 | WLAN_EID_QOS_TRAFFIC_CAPA, |
| 942 | WLAN_EID_TIM_BCAST_REQ, |
| 943 | WLAN_EID_INTERWORKING, |
Johannes Berg | a7f26d8 | 2017-08-05 11:44:32 +0300 | [diff] [blame] | 944 | /* 60 GHz (Multi-band, DMG, MMS) can't happen */ |
Johannes Berg | 3de3802 | 2014-02-04 09:54:07 +0100 | [diff] [blame] | 945 | }; |
Johannes Berg | 8ed2874 | 2014-10-27 12:03:19 +0100 | [diff] [blame] | 946 | |
| 947 | /* RIC already taken above, so no need to handle here anymore */ |
Johannes Berg | 3de3802 | 2014-02-04 09:54:07 +0100 | [diff] [blame] | 948 | noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len, |
| 949 | before_vht, ARRAY_SIZE(before_vht), |
| 950 | offset); |
yuan linyu | b952f4d | 2017-06-18 22:52:04 +0800 | [diff] [blame] | 951 | skb_put_data(skb, assoc_data->ie + offset, noffset - offset); |
Johannes Berg | 3de3802 | 2014-02-04 09:54:07 +0100 | [diff] [blame] | 952 | offset = noffset; |
| 953 | } |
| 954 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 955 | /* if present, add any custom IEs that go before HE */ |
| 956 | if (assoc_data->ie_len) { |
| 957 | static const u8 before_he[] = { |
| 958 | /* |
| 959 | * no need to list the ones split off before VHT |
| 960 | * or generated here |
| 961 | */ |
| 962 | WLAN_EID_OPMODE_NOTIF, |
| 963 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE, |
| 964 | /* 11ai elements */ |
| 965 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION, |
| 966 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY, |
| 967 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM, |
| 968 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER, |
| 969 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN, |
| 970 | /* TODO: add 11ah/11aj/11ak elements */ |
| 971 | }; |
| 972 | |
| 973 | /* RIC already taken above, so no need to handle here anymore */ |
| 974 | noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len, |
| 975 | before_he, ARRAY_SIZE(before_he), |
| 976 | offset); |
| 977 | pos = skb_put(skb, noffset - offset); |
| 978 | memcpy(pos, assoc_data->ie + offset, noffset - offset); |
| 979 | offset = noffset; |
| 980 | } |
| 981 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 982 | if (sband->band != NL80211_BAND_6GHZ && |
| 983 | !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 984 | ieee80211_add_vht_ie(sdata, skb, sband, |
| 985 | &assoc_data->ap_vht_cap); |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 986 | |
Shaul Triebitz | dc7eb0f | 2018-12-15 11:03:20 +0200 | [diff] [blame] | 987 | /* |
| 988 | * If AP doesn't support HT, mark HE as disabled. |
| 989 | * If on the 5GHz band, make sure it supports VHT. |
| 990 | */ |
| 991 | if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || |
| 992 | (sband->band == NL80211_BAND_5GHZ && |
| 993 | ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
| 994 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
| 995 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 996 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) |
| 997 | ieee80211_add_he_ie(sdata, skb, sband); |
| 998 | |
| 999 | /* if present, add any custom non-vendor IEs that go after HE */ |
Johannes Berg | b3f51e9 | 2013-10-25 11:31:42 +0200 | [diff] [blame] | 1000 | if (assoc_data->ie_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1001 | noffset = ieee80211_ie_split_vendor(assoc_data->ie, |
| 1002 | assoc_data->ie_len, |
| 1003 | offset); |
yuan linyu | b952f4d | 2017-06-18 22:52:04 +0800 | [diff] [blame] | 1004 | skb_put_data(skb, assoc_data->ie + offset, noffset - offset); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1005 | offset = noffset; |
| 1006 | } |
| 1007 | |
Johannes Berg | 76f0303 | 2012-03-08 15:02:05 +0100 | [diff] [blame] | 1008 | if (assoc_data->wmm) { |
| 1009 | if (assoc_data->uapsd) { |
Eliad Peller | dc41e4d | 2012-03-14 16:15:03 +0200 | [diff] [blame] | 1010 | qos_info = ifmgd->uapsd_queues; |
| 1011 | qos_info |= (ifmgd->uapsd_max_sp_len << |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1012 | IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT); |
| 1013 | } else { |
| 1014 | qos_info = 0; |
| 1015 | } |
| 1016 | |
Arik Nemtsov | 40b861a | 2014-07-17 17:14:23 +0300 | [diff] [blame] | 1017 | pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1018 | } |
| 1019 | |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 1020 | if (sband->band == NL80211_BAND_S1GHZ) { |
| 1021 | ieee80211_add_aid_request_ie(sdata, skb); |
Thomas Pedersen | 7957c6c | 2020-09-21 19:28:05 -0700 | [diff] [blame] | 1022 | ieee80211_add_s1g_capab_ie(sdata, &sband->s1g_cap, skb); |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 1023 | } |
Thomas Pedersen | 7957c6c | 2020-09-21 19:28:05 -0700 | [diff] [blame] | 1024 | |
Johannes Berg | 9bd6a83e | 2021-06-18 13:41:53 +0300 | [diff] [blame] | 1025 | if (iftd && iftd->vendor_elems.data && iftd->vendor_elems.len) |
| 1026 | skb_put_data(skb, iftd->vendor_elems.data, iftd->vendor_elems.len); |
| 1027 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1028 | /* add any remaining custom (i.e. vendor specific here) IEs */ |
Johannes Berg | b3f51e9 | 2013-10-25 11:31:42 +0200 | [diff] [blame] | 1029 | if (assoc_data->ie_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1030 | noffset = assoc_data->ie_len; |
yuan linyu | b952f4d | 2017-06-18 22:52:04 +0800 | [diff] [blame] | 1031 | skb_put_data(skb, assoc_data->ie + offset, noffset - offset); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1032 | } |
| 1033 | |
Jouni Malinen | 39404fe | 2016-10-27 00:42:05 +0300 | [diff] [blame] | 1034 | if (assoc_data->fils_kek_len && |
| 1035 | fils_encrypt_assoc_req(skb, assoc_data) < 0) { |
| 1036 | dev_kfree_skb(skb); |
| 1037 | return; |
| 1038 | } |
| 1039 | |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 1040 | pos = skb_tail_pointer(skb); |
| 1041 | kfree(ifmgd->assoc_req_ies); |
| 1042 | ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC); |
| 1043 | ifmgd->assoc_req_ies_len = pos - ie_start; |
| 1044 | |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 1045 | drv_mgd_prepare_tx(local, sdata, &info); |
Johannes Berg | a1845fc | 2012-06-27 13:18:36 +0200 | [diff] [blame] | 1046 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1047 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1048 | if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 1049 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS | |
| 1050 | IEEE80211_TX_INTFL_MLME_CONN_TX; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1051 | ieee80211_tx_skb(sdata, skb); |
| 1052 | } |
| 1053 | |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1054 | void ieee80211_send_pspoll(struct ieee80211_local *local, |
| 1055 | struct ieee80211_sub_if_data *sdata) |
| 1056 | { |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1057 | struct ieee80211_pspoll *pspoll; |
| 1058 | struct sk_buff *skb; |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1059 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1060 | skb = ieee80211_pspoll_get(&local->hw, &sdata->vif); |
| 1061 | if (!skb) |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1062 | return; |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1063 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1064 | pspoll = (struct ieee80211_pspoll *) skb->data; |
| 1065 | pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1066 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 1067 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 1068 | ieee80211_tx_skb(sdata, skb); |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1069 | } |
| 1070 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1071 | void ieee80211_send_nullfunc(struct ieee80211_local *local, |
| 1072 | struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 076cdcb | 2015-09-24 16:14:55 +0200 | [diff] [blame] | 1073 | bool powersave) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1074 | { |
| 1075 | struct sk_buff *skb; |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1076 | struct ieee80211_hdr_3addr *nullfunc; |
Rajkumar Manoharan | b6f3530 | 2011-09-29 20:34:04 +0530 | [diff] [blame] | 1077 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1078 | |
Ben Caradoc-Davies | 7c181f4 | 2018-03-19 12:57:44 +1300 | [diff] [blame] | 1079 | skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif, |
| 1080 | !ieee80211_hw_check(&local->hw, DOESNT_SUPPORT_QOS_NDP)); |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1081 | if (!skb) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1082 | return; |
| 1083 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1084 | nullfunc = (struct ieee80211_hdr_3addr *) skb->data; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1085 | if (powersave) |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1086 | nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1087 | |
Seth Forshee | 6c17b77 | 2013-02-11 11:21:07 -0600 | [diff] [blame] | 1088 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT | |
| 1089 | IEEE80211_TX_INTFL_OFFCHAN_TX_OK; |
Pontus Fuchs | ff40b42 | 2013-06-04 12:44:52 +0200 | [diff] [blame] | 1090 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1091 | if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
Pontus Fuchs | ff40b42 | 2013-06-04 12:44:52 +0200 | [diff] [blame] | 1092 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; |
| 1093 | |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 1094 | if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) |
Rajkumar Manoharan | b6f3530 | 2011-09-29 20:34:04 +0530 | [diff] [blame] | 1095 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE; |
| 1096 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 1097 | ieee80211_tx_skb(sdata, skb); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1098 | } |
| 1099 | |
Felix Fietkau | a5d3cbd | 2021-07-02 07:01:11 +0200 | [diff] [blame] | 1100 | void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local, |
| 1101 | struct ieee80211_sub_if_data *sdata) |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 1102 | { |
| 1103 | struct sk_buff *skb; |
| 1104 | struct ieee80211_hdr *nullfunc; |
| 1105 | __le16 fc; |
| 1106 | |
| 1107 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) |
| 1108 | return; |
| 1109 | |
| 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) { |
| 1159 | /* |
| 1160 | * with multi-vif csa driver may call ieee80211_csa_finish() |
| 1161 | * many times while waiting for other interfaces to use their |
| 1162 | * reservations |
| 1163 | */ |
| 1164 | if (sdata->reserved_ready) |
| 1165 | goto out; |
| 1166 | |
| 1167 | ret = ieee80211_vif_use_reserved_context(sdata); |
| 1168 | if (ret) { |
| 1169 | sdata_info(sdata, |
| 1170 | "failed to use reserved channel context, disconnecting (err=%d)\n", |
| 1171 | ret); |
| 1172 | ieee80211_queue_work(&sdata->local->hw, |
| 1173 | &ifmgd->csa_connection_drop_work); |
| 1174 | goto out; |
| 1175 | } |
| 1176 | |
| 1177 | goto out; |
| 1178 | } |
| 1179 | |
| 1180 | if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef, |
| 1181 | &sdata->csa_chandef)) { |
Arik Nemtsov | 7578d57 | 2013-09-01 17:15:51 +0300 | [diff] [blame] | 1182 | sdata_info(sdata, |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1183 | "failed to finalize channel switch, disconnecting\n"); |
Arik Nemtsov | 7578d57 | 2013-09-01 17:15:51 +0300 | [diff] [blame] | 1184 | ieee80211_queue_work(&sdata->local->hw, |
| 1185 | &ifmgd->csa_connection_drop_work); |
| 1186 | goto out; |
| 1187 | } |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 1188 | |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 1189 | ifmgd->csa_waiting_bcn = true; |
Luciano Coelho | f1d6558 | 2014-10-08 09:48:38 +0300 | [diff] [blame] | 1190 | |
Michal Kazior | e5593f5 | 2014-04-09 15:45:36 +0200 | [diff] [blame] | 1191 | ieee80211_sta_reset_beacon_monitor(sdata); |
| 1192 | ieee80211_sta_reset_conn_monitor(sdata); |
| 1193 | |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 1194 | out: |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1195 | mutex_unlock(&local->chanctx_mtx); |
| 1196 | mutex_unlock(&local->mtx); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 1197 | sdata_unlock(sdata); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1198 | } |
| 1199 | |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 1200 | static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data *sdata) |
| 1201 | { |
| 1202 | struct ieee80211_local *local = sdata->local; |
| 1203 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 1204 | int ret; |
| 1205 | |
| 1206 | sdata_assert_lock(sdata); |
| 1207 | |
| 1208 | WARN_ON(!sdata->vif.csa_active); |
| 1209 | |
| 1210 | if (sdata->csa_block_tx) { |
| 1211 | ieee80211_wake_vif_queues(local, sdata, |
| 1212 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 1213 | sdata->csa_block_tx = false; |
| 1214 | } |
| 1215 | |
| 1216 | sdata->vif.csa_active = false; |
| 1217 | ifmgd->csa_waiting_bcn = false; |
Emmanuel Grumbach | d6843d1 | 2021-04-08 14:31:25 +0200 | [diff] [blame] | 1218 | /* |
| 1219 | * If the CSA IE is still present on the beacon after the switch, |
| 1220 | * we need to consider it as a new CSA (possibly to self). |
| 1221 | */ |
| 1222 | ifmgd->beacon_crc_valid = false; |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 1223 | |
| 1224 | ret = drv_post_channel_switch(sdata); |
| 1225 | if (ret) { |
| 1226 | sdata_info(sdata, |
| 1227 | "driver post channel switch failed, disconnecting\n"); |
| 1228 | ieee80211_queue_work(&local->hw, |
| 1229 | &ifmgd->csa_connection_drop_work); |
| 1230 | return; |
| 1231 | } |
Luciano Coelho | 688b1ec | 2014-12-16 16:01:39 +0200 | [diff] [blame] | 1232 | |
| 1233 | cfg80211_ch_switch_notify(sdata->dev, &sdata->reserved_chandef); |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 1234 | } |
| 1235 | |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1236 | void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success) |
| 1237 | { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1238 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 1239 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1240 | |
| 1241 | trace_api_chswitch_done(sdata, success); |
| 1242 | if (!success) { |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 1243 | sdata_info(sdata, |
| 1244 | "driver channel switch failed, disconnecting\n"); |
| 1245 | ieee80211_queue_work(&sdata->local->hw, |
| 1246 | &ifmgd->csa_connection_drop_work); |
| 1247 | } else { |
| 1248 | ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1249 | } |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1250 | } |
| 1251 | EXPORT_SYMBOL(ieee80211_chswitch_done); |
| 1252 | |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 1253 | static void ieee80211_chswitch_timer(struct timer_list *t) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1254 | { |
| 1255 | struct ieee80211_sub_if_data *sdata = |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 1256 | from_timer(sdata, t, u.mgd.chswitch_timer); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1257 | |
Stanislaw Gruszka | 9b7d72c | 2013-02-28 10:55:27 +0100 | [diff] [blame] | 1258 | ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1259 | } |
| 1260 | |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 1261 | static void |
Sara Sharon | b9cc81d | 2019-02-06 13:17:10 +0200 | [diff] [blame] | 1262 | ieee80211_sta_abort_chanswitch(struct ieee80211_sub_if_data *sdata) |
| 1263 | { |
| 1264 | struct ieee80211_local *local = sdata->local; |
| 1265 | |
| 1266 | if (!local->ops->abort_channel_switch) |
| 1267 | return; |
| 1268 | |
| 1269 | mutex_lock(&local->mtx); |
| 1270 | |
| 1271 | mutex_lock(&local->chanctx_mtx); |
| 1272 | ieee80211_vif_unreserve_chanctx(sdata); |
| 1273 | mutex_unlock(&local->chanctx_mtx); |
| 1274 | |
| 1275 | if (sdata->csa_block_tx) |
| 1276 | ieee80211_wake_vif_queues(local, sdata, |
| 1277 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 1278 | |
| 1279 | sdata->csa_block_tx = false; |
| 1280 | sdata->vif.csa_active = false; |
| 1281 | |
| 1282 | mutex_unlock(&local->mtx); |
| 1283 | |
| 1284 | drv_abort_channel_switch(sdata); |
| 1285 | } |
| 1286 | |
| 1287 | static void |
Johannes Berg | 4a3cb70 | 2013-02-12 16:43:19 +0100 | [diff] [blame] | 1288 | ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata, |
Luciano Coelho | 2ba4538 | 2014-10-08 09:48:35 +0300 | [diff] [blame] | 1289 | u64 timestamp, u32 device_timestamp, |
| 1290 | struct ieee802_11_elems *elems, |
Johannes Berg | 04a161f | 2013-05-03 09:35:35 +0200 | [diff] [blame] | 1291 | bool beacon) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1292 | { |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1293 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1294 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 1295 | struct cfg80211_bss *cbss = ifmgd->associated; |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1296 | struct ieee80211_chanctx_conf *conf; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1297 | struct ieee80211_chanctx *chanctx; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1298 | enum nl80211_band current_band; |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1299 | struct ieee80211_csa_ie csa_ie; |
Luciano Coelho | 6d027bc | 2014-10-08 09:48:37 +0300 | [diff] [blame] | 1300 | struct ieee80211_channel_switch ch_switch; |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 1301 | struct ieee80211_bss *bss; |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 1302 | int res; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1303 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 1304 | sdata_assert_lock(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1305 | |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 1306 | if (!cbss) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1307 | return; |
| 1308 | |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1309 | if (local->scanning) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1310 | return; |
| 1311 | |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 1312 | current_band = cbss->channel->band; |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 1313 | bss = (void *)cbss->priv; |
Luciano Coelho | 84469a4 | 2014-10-28 13:33:04 +0200 | [diff] [blame] | 1314 | res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band, |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 1315 | bss->vht_cap_info, |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 1316 | ifmgd->flags, |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1317 | ifmgd->associated->bssid, &csa_ie); |
Sara Sharon | fafd2bc | 2019-02-06 13:17:15 +0200 | [diff] [blame] | 1318 | |
| 1319 | if (!res) { |
| 1320 | ch_switch.timestamp = timestamp; |
| 1321 | ch_switch.device_timestamp = device_timestamp; |
Sara Sharon | 2bf973f | 2020-01-31 13:12:51 +0200 | [diff] [blame] | 1322 | ch_switch.block_tx = csa_ie.mode; |
Sara Sharon | fafd2bc | 2019-02-06 13:17:15 +0200 | [diff] [blame] | 1323 | ch_switch.chandef = csa_ie.chandef; |
| 1324 | ch_switch.count = csa_ie.count; |
| 1325 | ch_switch.delay = csa_ie.max_switch_time; |
| 1326 | } |
| 1327 | |
Emmanuel Grumbach | 253907a | 2021-04-09 12:40:16 +0300 | [diff] [blame] | 1328 | if (res < 0) |
| 1329 | goto lock_and_drop_connection; |
Sara Sharon | b9cc81d | 2019-02-06 13:17:10 +0200 | [diff] [blame] | 1330 | |
Sara Sharon | fafd2bc | 2019-02-06 13:17:15 +0200 | [diff] [blame] | 1331 | if (beacon && sdata->vif.csa_active && !ifmgd->csa_waiting_bcn) { |
| 1332 | if (res) |
| 1333 | ieee80211_sta_abort_chanswitch(sdata); |
| 1334 | else |
| 1335 | drv_channel_switch_rx_beacon(sdata, &ch_switch); |
Sara Sharon | b9cc81d | 2019-02-06 13:17:10 +0200 | [diff] [blame] | 1336 | return; |
| 1337 | } else if (sdata->vif.csa_active || res) { |
| 1338 | /* disregard subsequent announcements if already processing */ |
| 1339 | return; |
| 1340 | } |
Johannes Berg | cd64f2a | 2013-03-28 10:44:18 +0100 | [diff] [blame] | 1341 | |
Johannes Berg | 3660944 | 2020-11-29 17:30:54 +0200 | [diff] [blame] | 1342 | if (sdata->vif.bss_conf.chandef.chan->band != |
| 1343 | csa_ie.chandef.chan->band) { |
| 1344 | sdata_info(sdata, |
| 1345 | "AP %pM switches to different band (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n", |
| 1346 | ifmgd->associated->bssid, |
| 1347 | csa_ie.chandef.chan->center_freq, |
| 1348 | csa_ie.chandef.width, csa_ie.chandef.center_freq1, |
| 1349 | csa_ie.chandef.center_freq2); |
| 1350 | goto lock_and_drop_connection; |
| 1351 | } |
| 1352 | |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1353 | if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef, |
Johannes Berg | 85220d7 | 2013-03-25 18:29:27 +0100 | [diff] [blame] | 1354 | IEEE80211_CHAN_DISABLED)) { |
| 1355 | sdata_info(sdata, |
Thomas Pedersen | b6011960 | 2020-04-01 18:18:04 -0700 | [diff] [blame] | 1356 | "AP %pM switches to unsupported channel " |
| 1357 | "(%d.%03d MHz, width:%d, CF1/2: %d.%03d/%d MHz), " |
| 1358 | "disconnecting\n", |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 1359 | ifmgd->associated->bssid, |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1360 | csa_ie.chandef.chan->center_freq, |
Thomas Pedersen | b6011960 | 2020-04-01 18:18:04 -0700 | [diff] [blame] | 1361 | csa_ie.chandef.chan->freq_offset, |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1362 | csa_ie.chandef.width, csa_ie.chandef.center_freq1, |
Thomas Pedersen | b6011960 | 2020-04-01 18:18:04 -0700 | [diff] [blame] | 1363 | csa_ie.chandef.freq1_offset, |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1364 | csa_ie.chandef.center_freq2); |
Johannes Berg | 3660944 | 2020-11-29 17:30:54 +0200 | [diff] [blame] | 1365 | goto lock_and_drop_connection; |
Johannes Berg | 85220d7 | 2013-03-25 18:29:27 +0100 | [diff] [blame] | 1366 | } |
| 1367 | |
Johannes Berg | f84eaa1 | 2015-03-12 08:53:26 +0200 | [diff] [blame] | 1368 | if (cfg80211_chandef_identical(&csa_ie.chandef, |
Sara Sharon | 9792875 | 2019-02-06 13:17:16 +0200 | [diff] [blame] | 1369 | &sdata->vif.bss_conf.chandef) && |
| 1370 | (!csa_ie.mode || !beacon)) { |
Johannes Berg | f84eaa1 | 2015-03-12 08:53:26 +0200 | [diff] [blame] | 1371 | if (ifmgd->csa_ignored_same_chan) |
| 1372 | return; |
| 1373 | sdata_info(sdata, |
| 1374 | "AP %pM tries to chanswitch to same channel, ignore\n", |
| 1375 | ifmgd->associated->bssid); |
| 1376 | ifmgd->csa_ignored_same_chan = true; |
| 1377 | return; |
| 1378 | } |
| 1379 | |
Arik Nemtsov | c5a7168 | 2015-05-19 14:36:48 +0300 | [diff] [blame] | 1380 | /* |
| 1381 | * Drop all TDLS peers - either we disconnect or move to a different |
| 1382 | * channel from this point on. There's no telling what our peer will do. |
| 1383 | * The TDLS WIDER_BW scenario is also problematic, as peers might now |
| 1384 | * have an incompatible wider chandef. |
| 1385 | */ |
| 1386 | ieee80211_teardown_tdls_peers(sdata); |
| 1387 | |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1388 | mutex_lock(&local->mtx); |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1389 | mutex_lock(&local->chanctx_mtx); |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1390 | conf = rcu_dereference_protected(sdata->vif.chanctx_conf, |
| 1391 | lockdep_is_held(&local->chanctx_mtx)); |
| 1392 | if (!conf) { |
| 1393 | sdata_info(sdata, |
| 1394 | "no channel context assigned to vif?, disconnecting\n"); |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1395 | goto drop_connection; |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | chanctx = container_of(conf, struct ieee80211_chanctx, conf); |
| 1399 | |
Luciano Coelho | 0f791eb4 | 2014-10-08 09:48:40 +0300 | [diff] [blame] | 1400 | if (local->use_chanctx && |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1401 | !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) { |
Luciano Coelho | 0f791eb4 | 2014-10-08 09:48:40 +0300 | [diff] [blame] | 1402 | sdata_info(sdata, |
| 1403 | "driver doesn't support chan-switch with channel contexts\n"); |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1404 | goto drop_connection; |
Arik Nemtsov | 7578d57 | 2013-09-01 17:15:51 +0300 | [diff] [blame] | 1405 | } |
| 1406 | |
Luciano Coelho | 6d027bc | 2014-10-08 09:48:37 +0300 | [diff] [blame] | 1407 | if (drv_pre_channel_switch(sdata, &ch_switch)) { |
| 1408 | sdata_info(sdata, |
| 1409 | "preparing for channel switch failed, disconnecting\n"); |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1410 | goto drop_connection; |
Luciano Coelho | 6d027bc | 2014-10-08 09:48:37 +0300 | [diff] [blame] | 1411 | } |
| 1412 | |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1413 | res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef, |
| 1414 | chanctx->mode, false); |
| 1415 | if (res) { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1416 | sdata_info(sdata, |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1417 | "failed to reserve channel context for channel switch, disconnecting (err=%d)\n", |
| 1418 | res); |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1419 | goto drop_connection; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1420 | } |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1421 | mutex_unlock(&local->chanctx_mtx); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1422 | |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 1423 | sdata->vif.csa_active = true; |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1424 | sdata->csa_chandef = csa_ie.chandef; |
Sara Sharon | 2bf973f | 2020-01-31 13:12:51 +0200 | [diff] [blame] | 1425 | sdata->csa_block_tx = csa_ie.mode; |
Johannes Berg | f84eaa1 | 2015-03-12 08:53:26 +0200 | [diff] [blame] | 1426 | ifmgd->csa_ignored_same_chan = false; |
Emmanuel Grumbach | 189a164 | 2020-12-06 14:54:49 +0200 | [diff] [blame] | 1427 | ifmgd->beacon_crc_valid = false; |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 1428 | |
| 1429 | if (sdata->csa_block_tx) |
Luciano Coelho | a46992b | 2014-06-13 16:30:07 +0300 | [diff] [blame] | 1430 | ieee80211_stop_vif_queues(local, sdata, |
| 1431 | IEEE80211_QUEUE_STOP_REASON_CSA); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 1432 | mutex_unlock(&local->mtx); |
Johannes Berg | 57eebdf | 2012-08-01 15:50:46 +0200 | [diff] [blame] | 1433 | |
Luciano Coelho | 2f45729 | 2014-11-07 14:31:36 +0200 | [diff] [blame] | 1434 | cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef, |
Johannes Berg | 669b841 | 2020-11-29 17:30:55 +0200 | [diff] [blame] | 1435 | csa_ie.count, csa_ie.mode); |
Luciano Coelho | 2f45729 | 2014-11-07 14:31:36 +0200 | [diff] [blame] | 1436 | |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1437 | if (local->ops->channel_switch) { |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1438 | /* use driver's channel switch callback */ |
Luciano Coelho | 0f791eb4 | 2014-10-08 09:48:40 +0300 | [diff] [blame] | 1439 | drv_channel_switch(local, sdata, &ch_switch); |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1440 | return; |
| 1441 | } |
| 1442 | |
| 1443 | /* channel switch handled in software */ |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1444 | if (csa_ie.count <= 1) |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1445 | ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work); |
Johannes Berg | 57eebdf | 2012-08-01 15:50:46 +0200 | [diff] [blame] | 1446 | else |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1447 | mod_timer(&ifmgd->chswitch_timer, |
Luciano Coelho | ff1e417 | 2014-10-28 13:33:05 +0200 | [diff] [blame] | 1448 | TU_TO_EXP_TIME((csa_ie.count - 1) * |
| 1449 | cbss->beacon_interval)); |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1450 | return; |
Johannes Berg | 3660944 | 2020-11-29 17:30:54 +0200 | [diff] [blame] | 1451 | lock_and_drop_connection: |
| 1452 | mutex_lock(&local->mtx); |
| 1453 | mutex_lock(&local->chanctx_mtx); |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1454 | drop_connection: |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 1455 | /* |
| 1456 | * This is just so that the disconnect flow will know that |
| 1457 | * we were trying to switch channel and failed. In case the |
| 1458 | * mode is 1 (we are not allowed to Tx), we will know not to |
| 1459 | * send a deauthentication frame. Those two fields will be |
| 1460 | * reset when the disconnection worker runs. |
| 1461 | */ |
| 1462 | sdata->vif.csa_active = true; |
Sara Sharon | 2bf973f | 2020-01-31 13:12:51 +0200 | [diff] [blame] | 1463 | sdata->csa_block_tx = csa_ie.mode; |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 1464 | |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1465 | ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work); |
| 1466 | mutex_unlock(&local->chanctx_mtx); |
| 1467 | mutex_unlock(&local->mtx); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1468 | } |
| 1469 | |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1470 | static bool |
| 1471 | ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata, |
| 1472 | struct ieee80211_channel *channel, |
| 1473 | const u8 *country_ie, u8 country_ie_len, |
| 1474 | const u8 *pwr_constr_elem, |
| 1475 | int *chan_pwr, int *pwr_reduction) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1476 | { |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1477 | struct ieee80211_country_ie_triplet *triplet; |
| 1478 | int chan = ieee80211_frequency_to_channel(channel->center_freq); |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1479 | int i, chan_increment; |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1480 | bool have_chan_pwr = false; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1481 | |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1482 | /* Invalid IE */ |
| 1483 | 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] | 1484 | return false; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1485 | |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1486 | triplet = (void *)(country_ie + 3); |
| 1487 | country_ie_len -= 3; |
| 1488 | |
| 1489 | switch (channel->band) { |
| 1490 | default: |
| 1491 | WARN_ON_ONCE(1); |
Gustavo A. R. Silva | fc0561d | 2020-07-07 15:45:48 -0500 | [diff] [blame] | 1492 | fallthrough; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1493 | case NL80211_BAND_2GHZ: |
| 1494 | case NL80211_BAND_60GHZ: |
Srinivasan Raju | 63fa042 | 2021-10-18 11:00:54 +0100 | [diff] [blame] | 1495 | case NL80211_BAND_LC: |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1496 | chan_increment = 1; |
| 1497 | break; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1498 | case NL80211_BAND_5GHZ: |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1499 | chan_increment = 4; |
| 1500 | break; |
Johannes Berg | 2dedfe1 | 2020-12-06 14:54:47 +0200 | [diff] [blame] | 1501 | case NL80211_BAND_6GHZ: |
| 1502 | /* |
| 1503 | * In the 6 GHz band, the "maximum transmit power level" |
| 1504 | * field in the triplets is reserved, and thus will be |
| 1505 | * zero and we shouldn't use it to control TX power. |
| 1506 | * The actual TX power will be given in the transmit |
| 1507 | * power envelope element instead. |
| 1508 | */ |
| 1509 | return false; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1510 | } |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1511 | |
| 1512 | /* find channel */ |
| 1513 | while (country_ie_len >= 3) { |
| 1514 | u8 first_channel = triplet->chans.first_channel; |
| 1515 | |
| 1516 | if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID) |
| 1517 | goto next; |
| 1518 | |
| 1519 | for (i = 0; i < triplet->chans.num_channels; i++) { |
| 1520 | if (first_channel + i * chan_increment == chan) { |
| 1521 | have_chan_pwr = true; |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1522 | *chan_pwr = triplet->chans.max_power; |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1523 | break; |
| 1524 | } |
| 1525 | } |
| 1526 | if (have_chan_pwr) |
| 1527 | break; |
| 1528 | |
| 1529 | next: |
| 1530 | triplet++; |
| 1531 | country_ie_len -= 3; |
| 1532 | } |
| 1533 | |
Moshe Benji | a5fee9c | 2014-12-14 11:05:50 +0200 | [diff] [blame] | 1534 | if (have_chan_pwr && pwr_constr_elem) |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1535 | *pwr_reduction = *pwr_constr_elem; |
Moshe Benji | a5fee9c | 2014-12-14 11:05:50 +0200 | [diff] [blame] | 1536 | else |
| 1537 | *pwr_reduction = 0; |
| 1538 | |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1539 | return have_chan_pwr; |
| 1540 | } |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1541 | |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1542 | static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata, |
| 1543 | struct ieee80211_channel *channel, |
| 1544 | const u8 *cisco_dtpc_ie, |
| 1545 | int *pwr_level) |
| 1546 | { |
| 1547 | /* From practical testing, the first data byte of the DTPC element |
| 1548 | * seems to contain the requested dBm level, and the CLI on Cisco |
| 1549 | * APs clearly state the range is -127 to 127 dBm, which indicates |
| 1550 | * a signed byte, although it seemingly never actually goes negative. |
| 1551 | * The other byte seems to always be zero. |
| 1552 | */ |
| 1553 | *pwr_level = (__s8)cisco_dtpc_ie[4]; |
| 1554 | } |
| 1555 | |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1556 | static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata, |
| 1557 | struct ieee80211_channel *channel, |
| 1558 | struct ieee80211_mgmt *mgmt, |
| 1559 | const u8 *country_ie, u8 country_ie_len, |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1560 | const u8 *pwr_constr_ie, |
| 1561 | const u8 *cisco_dtpc_ie) |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1562 | { |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1563 | bool has_80211h_pwr = false, has_cisco_pwr = false; |
| 1564 | int chan_pwr = 0, pwr_reduction_80211h = 0; |
| 1565 | int pwr_level_cisco, pwr_level_80211h; |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1566 | int new_ap_level; |
Moshe Benji | a5fee9c | 2014-12-14 11:05:50 +0200 | [diff] [blame] | 1567 | __le16 capab = mgmt->u.probe_resp.capab_info; |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1568 | |
Thomas Pedersen | 09a740c | 2020-09-21 19:28:14 -0700 | [diff] [blame] | 1569 | if (ieee80211_is_s1g_beacon(mgmt->frame_control)) |
| 1570 | return 0; /* TODO */ |
| 1571 | |
Moshe Benji | a5fee9c | 2014-12-14 11:05:50 +0200 | [diff] [blame] | 1572 | if (country_ie && |
| 1573 | (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) || |
| 1574 | capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) { |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1575 | has_80211h_pwr = ieee80211_find_80211h_pwr_constr( |
| 1576 | sdata, channel, country_ie, country_ie_len, |
| 1577 | pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h); |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1578 | pwr_level_80211h = |
| 1579 | max_t(int, 0, chan_pwr - pwr_reduction_80211h); |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1580 | } |
| 1581 | |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1582 | if (cisco_dtpc_ie) { |
| 1583 | ieee80211_find_cisco_dtpc( |
| 1584 | sdata, channel, cisco_dtpc_ie, &pwr_level_cisco); |
| 1585 | has_cisco_pwr = true; |
| 1586 | } |
| 1587 | |
| 1588 | if (!has_80211h_pwr && !has_cisco_pwr) |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1589 | return 0; |
| 1590 | |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1591 | /* If we have both 802.11h and Cisco DTPC, apply both limits |
| 1592 | * by picking the smallest of the two power levels advertised. |
| 1593 | */ |
| 1594 | if (has_80211h_pwr && |
| 1595 | (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) { |
Johannes Berg | a87da0c | 2015-12-08 16:04:37 +0200 | [diff] [blame] | 1596 | new_ap_level = pwr_level_80211h; |
| 1597 | |
| 1598 | if (sdata->ap_power_level == new_ap_level) |
| 1599 | return 0; |
| 1600 | |
John Linville | cef2fc1 | 2015-03-31 10:49:14 -0400 | [diff] [blame] | 1601 | sdata_dbg(sdata, |
| 1602 | "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n", |
| 1603 | pwr_level_80211h, chan_pwr, pwr_reduction_80211h, |
| 1604 | sdata->u.mgd.bssid); |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1605 | } else { /* has_cisco_pwr is always true here. */ |
Johannes Berg | a87da0c | 2015-12-08 16:04:37 +0200 | [diff] [blame] | 1606 | new_ap_level = pwr_level_cisco; |
| 1607 | |
| 1608 | if (sdata->ap_power_level == new_ap_level) |
| 1609 | return 0; |
| 1610 | |
John Linville | cef2fc1 | 2015-03-31 10:49:14 -0400 | [diff] [blame] | 1611 | sdata_dbg(sdata, |
| 1612 | "Limiting TX power to %d dBm as advertised by %pM\n", |
| 1613 | pwr_level_cisco, sdata->u.mgd.bssid); |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1614 | } |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1615 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 1616 | sdata->ap_power_level = new_ap_level; |
| 1617 | if (__ieee80211_recalc_txpower(sdata)) |
| 1618 | return BSS_CHANGED_TXPOWER; |
| 1619 | return 0; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1620 | } |
| 1621 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1622 | /* powersave */ |
| 1623 | static void ieee80211_enable_ps(struct ieee80211_local *local, |
| 1624 | struct ieee80211_sub_if_data *sdata) |
| 1625 | { |
| 1626 | struct ieee80211_conf *conf = &local->hw.conf; |
| 1627 | |
Johannes Berg | d5edaed | 2009-04-22 23:02:51 +0200 | [diff] [blame] | 1628 | /* |
| 1629 | * If we are scanning right now then the parameters will |
| 1630 | * take effect when scan finishes. |
| 1631 | */ |
Helmut Schaa | fbe9c429 | 2009-07-23 12:14:04 +0200 | [diff] [blame] | 1632 | if (local->scanning) |
Johannes Berg | d5edaed | 2009-04-22 23:02:51 +0200 | [diff] [blame] | 1633 | return; |
| 1634 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1635 | if (conf->dynamic_ps_timeout > 0 && |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1636 | !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1637 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 1638 | msecs_to_jiffies(conf->dynamic_ps_timeout)); |
| 1639 | } else { |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1640 | if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) |
Johannes Berg | 076cdcb | 2015-09-24 16:14:55 +0200 | [diff] [blame] | 1641 | ieee80211_send_nullfunc(local, sdata, true); |
Vivek Natarajan | 375177b | 2010-02-09 14:50:28 +0530 | [diff] [blame] | 1642 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1643 | if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) && |
| 1644 | ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
Juuso Oikarinen | 2a13052 | 2010-03-09 14:25:02 +0200 | [diff] [blame] | 1645 | return; |
| 1646 | |
| 1647 | conf->flags |= IEEE80211_CONF_PS; |
| 1648 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | static void ieee80211_change_ps(struct ieee80211_local *local) |
| 1653 | { |
| 1654 | struct ieee80211_conf *conf = &local->hw.conf; |
| 1655 | |
| 1656 | if (local->ps_sdata) { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1657 | ieee80211_enable_ps(local, local->ps_sdata); |
| 1658 | } else if (conf->flags & IEEE80211_CONF_PS) { |
| 1659 | conf->flags &= ~IEEE80211_CONF_PS; |
| 1660 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 1661 | del_timer_sync(&local->dynamic_ps_timer); |
| 1662 | cancel_work_sync(&local->dynamic_ps_enable_work); |
| 1663 | } |
| 1664 | } |
| 1665 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1666 | static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata) |
| 1667 | { |
| 1668 | struct ieee80211_if_managed *mgd = &sdata->u.mgd; |
| 1669 | struct sta_info *sta = NULL; |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1670 | bool authorized = false; |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1671 | |
| 1672 | if (!mgd->powersave) |
| 1673 | return false; |
| 1674 | |
Johannes Berg | 05cb910 | 2011-10-28 11:59:47 +0200 | [diff] [blame] | 1675 | if (mgd->broken_ap) |
| 1676 | return false; |
| 1677 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1678 | if (!mgd->associated) |
| 1679 | return false; |
| 1680 | |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 1681 | if (mgd->flags & IEEE80211_STA_CONNECTION_POLL) |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1682 | return false; |
| 1683 | |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 1684 | if (!mgd->have_beacon) |
Alexander Bondar | ce85788 | 2013-05-06 17:17:04 +0300 | [diff] [blame] | 1685 | return false; |
| 1686 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1687 | rcu_read_lock(); |
| 1688 | sta = sta_info_get(sdata, mgd->bssid); |
| 1689 | if (sta) |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1690 | authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED); |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1691 | rcu_read_unlock(); |
| 1692 | |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1693 | return authorized; |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1694 | } |
| 1695 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1696 | /* need to hold RTNL or interface lock */ |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 1697 | void ieee80211_recalc_ps(struct ieee80211_local *local) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1698 | { |
| 1699 | struct ieee80211_sub_if_data *sdata, *found = NULL; |
| 1700 | int count = 0; |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 1701 | int timeout; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1702 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1703 | if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1704 | local->ps_sdata = NULL; |
| 1705 | return; |
| 1706 | } |
| 1707 | |
| 1708 | list_for_each_entry(sdata, &local->interfaces, list) { |
Johannes Berg | 9607e6b66 | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 1709 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1710 | continue; |
Rajkumar Manoharan | 8c7914d | 2011-02-01 00:28:59 +0530 | [diff] [blame] | 1711 | if (sdata->vif.type == NL80211_IFTYPE_AP) { |
| 1712 | /* If an AP vif is found, then disable PS |
| 1713 | * by setting the count to zero thereby setting |
| 1714 | * ps_sdata to NULL. |
| 1715 | */ |
| 1716 | count = 0; |
| 1717 | break; |
| 1718 | } |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1719 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 1720 | continue; |
| 1721 | found = sdata; |
| 1722 | count++; |
| 1723 | } |
| 1724 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1725 | if (count == 1 && ieee80211_powersave_allowed(found)) { |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 1726 | u8 dtimper = found->u.mgd.dtim_period; |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1727 | |
Juuso Oikarinen | ff61638 | 2010-06-09 09:51:52 +0300 | [diff] [blame] | 1728 | timeout = local->dynamic_ps_forced_timeout; |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 1729 | if (timeout < 0) |
| 1730 | timeout = 100; |
Johannes Berg | 09b8556 | 2013-02-06 23:07:41 +0100 | [diff] [blame] | 1731 | local->hw.conf.dynamic_ps_timeout = timeout; |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 1732 | |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 1733 | /* If the TIM IE is invalid, pretend the value is 1 */ |
| 1734 | if (!dtimper) |
| 1735 | dtimper = 1; |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 1736 | |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 1737 | local->hw.conf.ps_dtim_period = dtimper; |
| 1738 | local->ps_sdata = found; |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1739 | } else { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1740 | local->ps_sdata = NULL; |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1741 | } |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1742 | |
| 1743 | ieee80211_change_ps(local); |
| 1744 | } |
| 1745 | |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 1746 | void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata) |
| 1747 | { |
| 1748 | bool ps_allowed = ieee80211_powersave_allowed(sdata); |
| 1749 | |
| 1750 | if (sdata->vif.bss_conf.ps != ps_allowed) { |
| 1751 | sdata->vif.bss_conf.ps = ps_allowed; |
| 1752 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS); |
| 1753 | } |
| 1754 | } |
| 1755 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1756 | void ieee80211_dynamic_ps_disable_work(struct work_struct *work) |
| 1757 | { |
| 1758 | struct ieee80211_local *local = |
| 1759 | container_of(work, struct ieee80211_local, |
| 1760 | dynamic_ps_disable_work); |
| 1761 | |
| 1762 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 1763 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 1764 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 1765 | } |
| 1766 | |
| 1767 | ieee80211_wake_queues_by_reason(&local->hw, |
Johannes Berg | 445ea4e | 2013-02-13 12:25:28 +0100 | [diff] [blame] | 1768 | IEEE80211_MAX_QUEUE_MAP, |
Luciano Coelho | cca07b0 | 2014-06-13 16:30:05 +0300 | [diff] [blame] | 1769 | IEEE80211_QUEUE_STOP_REASON_PS, |
| 1770 | false); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | void ieee80211_dynamic_ps_enable_work(struct work_struct *work) |
| 1774 | { |
| 1775 | struct ieee80211_local *local = |
| 1776 | container_of(work, struct ieee80211_local, |
| 1777 | dynamic_ps_enable_work); |
| 1778 | struct ieee80211_sub_if_data *sdata = local->ps_sdata; |
Christian Lamparter | 5e34069 | 2011-06-30 21:08:43 +0200 | [diff] [blame] | 1779 | struct ieee80211_if_managed *ifmgd; |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1780 | unsigned long flags; |
| 1781 | int q; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1782 | |
| 1783 | /* can only happen when PS was just disabled anyway */ |
| 1784 | if (!sdata) |
| 1785 | return; |
| 1786 | |
Christian Lamparter | 5e34069 | 2011-06-30 21:08:43 +0200 | [diff] [blame] | 1787 | ifmgd = &sdata->u.mgd; |
| 1788 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1789 | if (local->hw.conf.flags & IEEE80211_CONF_PS) |
| 1790 | return; |
| 1791 | |
Johannes Berg | 09b8556 | 2013-02-06 23:07:41 +0100 | [diff] [blame] | 1792 | if (local->hw.conf.dynamic_ps_timeout > 0) { |
Arik Nemtsov | 77b7023 | 2011-06-26 12:06:54 +0300 | [diff] [blame] | 1793 | /* don't enter PS if TX frames are pending */ |
| 1794 | if (drv_tx_frames_pending(local)) { |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1795 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 1796 | msecs_to_jiffies( |
| 1797 | local->hw.conf.dynamic_ps_timeout)); |
| 1798 | return; |
| 1799 | } |
Arik Nemtsov | 77b7023 | 2011-06-26 12:06:54 +0300 | [diff] [blame] | 1800 | |
| 1801 | /* |
| 1802 | * transmission can be stopped by others which leads to |
| 1803 | * dynamic_ps_timer expiry. Postpone the ps timer if it |
| 1804 | * is not the actual idle state. |
| 1805 | */ |
| 1806 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 1807 | for (q = 0; q < local->hw.queues; q++) { |
| 1808 | if (local->queue_stop_reasons[q]) { |
| 1809 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, |
| 1810 | flags); |
| 1811 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 1812 | msecs_to_jiffies( |
| 1813 | local->hw.conf.dynamic_ps_timeout)); |
| 1814 | return; |
| 1815 | } |
| 1816 | } |
| 1817 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1818 | } |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1819 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1820 | if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) && |
Mohammed Shafi Shajakhan | 9c38a8b | 2011-12-14 19:46:07 +0530 | [diff] [blame] | 1821 | !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) { |
Johannes Berg | a159838 | 2013-03-26 22:02:42 +0100 | [diff] [blame] | 1822 | if (drv_tx_frames_pending(local)) { |
Vivek Natarajan | e8306f9 | 2011-04-06 11:41:10 +0530 | [diff] [blame] | 1823 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 1824 | msecs_to_jiffies( |
| 1825 | local->hw.conf.dynamic_ps_timeout)); |
Johannes Berg | a159838 | 2013-03-26 22:02:42 +0100 | [diff] [blame] | 1826 | } else { |
Johannes Berg | 076cdcb | 2015-09-24 16:14:55 +0200 | [diff] [blame] | 1827 | ieee80211_send_nullfunc(local, sdata, true); |
Vivek Natarajan | e8306f9 | 2011-04-06 11:41:10 +0530 | [diff] [blame] | 1828 | /* Flush to get the tx status of nullfunc frame */ |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 1829 | ieee80211_flush_queues(local, sdata, false); |
Vivek Natarajan | e8306f9 | 2011-04-06 11:41:10 +0530 | [diff] [blame] | 1830 | } |
Vivek Natarajan | f3e85b9 | 2011-02-23 13:04:32 +0530 | [diff] [blame] | 1831 | } |
| 1832 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1833 | if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) && |
| 1834 | ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) || |
Vivek Natarajan | 375177b | 2010-02-09 14:50:28 +0530 | [diff] [blame] | 1835 | (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) { |
| 1836 | ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED; |
| 1837 | local->hw.conf.flags |= IEEE80211_CONF_PS; |
| 1838 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 1839 | } |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1840 | } |
| 1841 | |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 1842 | void ieee80211_dynamic_ps_timer(struct timer_list *t) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1843 | { |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 1844 | struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1845 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 1846 | ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1847 | } |
| 1848 | |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 1849 | void ieee80211_dfs_cac_timer_work(struct work_struct *work) |
| 1850 | { |
Geliang Tang | a85a7e2 | 2016-01-01 23:48:52 +0800 | [diff] [blame] | 1851 | struct delayed_work *delayed_work = to_delayed_work(work); |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 1852 | struct ieee80211_sub_if_data *sdata = |
| 1853 | container_of(delayed_work, struct ieee80211_sub_if_data, |
| 1854 | dfs_cac_timer_work); |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 1855 | struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef; |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 1856 | |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 1857 | mutex_lock(&sdata->local->mtx); |
| 1858 | if (sdata->wdev.cac_started) { |
| 1859 | ieee80211_vif_release_channel(sdata); |
| 1860 | cfg80211_cac_event(sdata->dev, &chandef, |
| 1861 | NL80211_RADAR_CAC_FINISHED, |
| 1862 | GFP_KERNEL); |
| 1863 | } |
| 1864 | mutex_unlock(&sdata->local->mtx); |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 1865 | } |
| 1866 | |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 1867 | static bool |
| 1868 | __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata) |
| 1869 | { |
| 1870 | struct ieee80211_local *local = sdata->local; |
| 1871 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
John Linville | cc72f6e | 2015-01-06 14:39:33 -0500 | [diff] [blame] | 1872 | bool ret = false; |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 1873 | int ac; |
| 1874 | |
| 1875 | if (local->hw.queues < IEEE80211_NUM_ACS) |
| 1876 | return false; |
| 1877 | |
| 1878 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 1879 | struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac]; |
| 1880 | int non_acm_ac; |
| 1881 | unsigned long now = jiffies; |
| 1882 | |
| 1883 | if (tx_tspec->action == TX_TSPEC_ACTION_NONE && |
| 1884 | tx_tspec->admitted_time && |
| 1885 | time_after(now, tx_tspec->time_slice_start + HZ)) { |
| 1886 | tx_tspec->consumed_tx_time = 0; |
| 1887 | tx_tspec->time_slice_start = now; |
| 1888 | |
| 1889 | if (tx_tspec->downgraded) |
| 1890 | tx_tspec->action = |
| 1891 | TX_TSPEC_ACTION_STOP_DOWNGRADE; |
| 1892 | } |
| 1893 | |
| 1894 | switch (tx_tspec->action) { |
| 1895 | case TX_TSPEC_ACTION_STOP_DOWNGRADE: |
| 1896 | /* take the original parameters */ |
| 1897 | if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac])) |
| 1898 | sdata_err(sdata, |
| 1899 | "failed to set TX queue parameters for queue %d\n", |
| 1900 | ac); |
| 1901 | tx_tspec->action = TX_TSPEC_ACTION_NONE; |
| 1902 | tx_tspec->downgraded = false; |
| 1903 | ret = true; |
| 1904 | break; |
| 1905 | case TX_TSPEC_ACTION_DOWNGRADE: |
| 1906 | if (time_after(now, tx_tspec->time_slice_start + HZ)) { |
| 1907 | tx_tspec->action = TX_TSPEC_ACTION_NONE; |
| 1908 | ret = true; |
| 1909 | break; |
| 1910 | } |
| 1911 | /* downgrade next lower non-ACM AC */ |
| 1912 | for (non_acm_ac = ac + 1; |
| 1913 | non_acm_ac < IEEE80211_NUM_ACS; |
| 1914 | non_acm_ac++) |
| 1915 | if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac))) |
| 1916 | break; |
Johannes Berg | 93db1d9 | 2016-09-14 09:23:51 +0200 | [diff] [blame] | 1917 | /* Usually the loop will result in using BK even if it |
| 1918 | * requires admission control, but such a configuration |
| 1919 | * makes no sense and we have to transmit somehow - the |
| 1920 | * AC selection does the same thing. |
| 1921 | * If we started out trying to downgrade from BK, then |
| 1922 | * the extra condition here might be needed. |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 1923 | */ |
Johannes Berg | 93db1d9 | 2016-09-14 09:23:51 +0200 | [diff] [blame] | 1924 | if (non_acm_ac >= IEEE80211_NUM_ACS) |
| 1925 | non_acm_ac = IEEE80211_AC_BK; |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 1926 | if (drv_conf_tx(local, sdata, ac, |
| 1927 | &sdata->tx_conf[non_acm_ac])) |
| 1928 | sdata_err(sdata, |
| 1929 | "failed to set TX queue parameters for queue %d\n", |
| 1930 | ac); |
| 1931 | tx_tspec->action = TX_TSPEC_ACTION_NONE; |
| 1932 | ret = true; |
| 1933 | schedule_delayed_work(&ifmgd->tx_tspec_wk, |
| 1934 | tx_tspec->time_slice_start + HZ - now + 1); |
| 1935 | break; |
| 1936 | case TX_TSPEC_ACTION_NONE: |
| 1937 | /* nothing now */ |
| 1938 | break; |
| 1939 | } |
| 1940 | } |
| 1941 | |
| 1942 | return ret; |
| 1943 | } |
| 1944 | |
| 1945 | void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata) |
| 1946 | { |
| 1947 | if (__ieee80211_sta_handle_tspec_ac_params(sdata)) |
| 1948 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS); |
| 1949 | } |
| 1950 | |
| 1951 | static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work) |
| 1952 | { |
| 1953 | struct ieee80211_sub_if_data *sdata; |
| 1954 | |
| 1955 | sdata = container_of(work, struct ieee80211_sub_if_data, |
| 1956 | u.mgd.tx_tspec_wk.work); |
| 1957 | ieee80211_sta_handle_tspec_ac_params(sdata); |
| 1958 | } |
| 1959 | |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1960 | /* MLME */ |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 1961 | static bool |
| 1962 | ieee80211_sta_wmm_params(struct ieee80211_local *local, |
| 1963 | struct ieee80211_sub_if_data *sdata, |
| 1964 | const u8 *wmm_param, size_t wmm_param_len, |
| 1965 | const struct ieee80211_mu_edca_param_set *mu_edca) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1966 | { |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 1967 | struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS]; |
Johannes Berg | 4ced3f7 | 2010-07-19 16:39:04 +0200 | [diff] [blame] | 1968 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1969 | size_t left; |
Shaul Triebitz | 2e249fc | 2018-12-15 11:03:15 +0200 | [diff] [blame] | 1970 | int count, mu_edca_count, ac; |
Johannes Berg | 4a3cb70 | 2013-02-12 16:43:19 +0100 | [diff] [blame] | 1971 | const u8 *pos; |
| 1972 | u8 uapsd_queues = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1973 | |
Stanislaw Gruszka | e1b3ec1 | 2010-03-29 12:18:34 +0200 | [diff] [blame] | 1974 | if (!local->ops->conf_tx) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1975 | return false; |
Stanislaw Gruszka | e1b3ec1 | 2010-03-29 12:18:34 +0200 | [diff] [blame] | 1976 | |
Johannes Berg | 32c5057 | 2012-03-28 11:04:29 +0200 | [diff] [blame] | 1977 | if (local->hw.queues < IEEE80211_NUM_ACS) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1978 | return false; |
Johannes Berg | 3434fbd | 2008-05-03 00:59:37 +0200 | [diff] [blame] | 1979 | |
| 1980 | if (!wmm_param) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1981 | return false; |
Johannes Berg | 3434fbd | 2008-05-03 00:59:37 +0200 | [diff] [blame] | 1982 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1983 | if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1984 | return false; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1985 | |
| 1986 | if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED) |
Eliad Peller | dc41e4d | 2012-03-14 16:15:03 +0200 | [diff] [blame] | 1987 | uapsd_queues = ifmgd->uapsd_queues; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1988 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1989 | count = wmm_param[6] & 0x0f; |
Shaul Triebitz | 2e249fc | 2018-12-15 11:03:15 +0200 | [diff] [blame] | 1990 | /* -1 is the initial value of ifmgd->mu_edca_last_param_set. |
| 1991 | * if mu_edca was preset before and now it disappeared tell |
| 1992 | * the driver about it. |
| 1993 | */ |
| 1994 | mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1; |
| 1995 | if (count == ifmgd->wmm_last_param_set && |
| 1996 | mu_edca_count == ifmgd->mu_edca_last_param_set) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1997 | return false; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1998 | ifmgd->wmm_last_param_set = count; |
Shaul Triebitz | 2e249fc | 2018-12-15 11:03:15 +0200 | [diff] [blame] | 1999 | ifmgd->mu_edca_last_param_set = mu_edca_count; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2000 | |
| 2001 | pos = wmm_param + 8; |
| 2002 | left = wmm_param_len - 8; |
| 2003 | |
| 2004 | memset(¶ms, 0, sizeof(params)); |
| 2005 | |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 2006 | sdata->wmm_acm = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2007 | for (; left >= 4; left -= 4, pos += 4) { |
| 2008 | int aci = (pos[0] >> 5) & 0x03; |
| 2009 | int acm = (pos[0] >> 4) & 0x01; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2010 | bool uapsd = false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2011 | |
| 2012 | switch (aci) { |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 2013 | case 1: /* AC_BK */ |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2014 | ac = IEEE80211_AC_BK; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 2015 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 2016 | sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2017 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) |
| 2018 | uapsd = true; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 2019 | params[ac].mu_edca = !!mu_edca; |
| 2020 | if (mu_edca) |
| 2021 | params[ac].mu_edca_param_rec = mu_edca->ac_bk; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2022 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 2023 | case 2: /* AC_VI */ |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2024 | ac = IEEE80211_AC_VI; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 2025 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 2026 | sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2027 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) |
| 2028 | uapsd = true; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 2029 | params[ac].mu_edca = !!mu_edca; |
| 2030 | if (mu_edca) |
| 2031 | params[ac].mu_edca_param_rec = mu_edca->ac_vi; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2032 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 2033 | case 3: /* AC_VO */ |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2034 | ac = IEEE80211_AC_VO; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 2035 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 2036 | sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2037 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) |
| 2038 | uapsd = true; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 2039 | params[ac].mu_edca = !!mu_edca; |
| 2040 | if (mu_edca) |
| 2041 | params[ac].mu_edca_param_rec = mu_edca->ac_vo; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2042 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 2043 | case 0: /* AC_BE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2044 | default: |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2045 | ac = IEEE80211_AC_BE; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 2046 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 2047 | sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2048 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) |
| 2049 | uapsd = true; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 2050 | params[ac].mu_edca = !!mu_edca; |
| 2051 | if (mu_edca) |
| 2052 | params[ac].mu_edca_param_rec = mu_edca->ac_be; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2053 | break; |
| 2054 | } |
| 2055 | |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2056 | params[ac].aifs = pos[0] & 0x0f; |
Emmanuel Grumbach | 730a7550 | 2015-10-22 17:46:05 +0200 | [diff] [blame] | 2057 | |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2058 | if (params[ac].aifs < 2) { |
Emmanuel Grumbach | 730a7550 | 2015-10-22 17:46:05 +0200 | [diff] [blame] | 2059 | sdata_info(sdata, |
| 2060 | "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] | 2061 | params[ac].aifs, aci); |
| 2062 | params[ac].aifs = 2; |
Emmanuel Grumbach | 730a7550 | 2015-10-22 17:46:05 +0200 | [diff] [blame] | 2063 | } |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2064 | params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4); |
| 2065 | params[ac].cw_min = ecw2cw(pos[1] & 0x0f); |
| 2066 | params[ac].txop = get_unaligned_le16(pos + 2); |
| 2067 | params[ac].acm = acm; |
| 2068 | params[ac].uapsd = uapsd; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2069 | |
Ilan Peer | 911a264 | 2018-04-03 11:35:22 +0300 | [diff] [blame] | 2070 | if (params[ac].cw_min == 0 || |
Emmanuel Grumbach | c470bdc | 2018-03-26 16:21:04 +0300 | [diff] [blame] | 2071 | params[ac].cw_min > params[ac].cw_max) { |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2072 | sdata_info(sdata, |
| 2073 | "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n", |
| 2074 | params[ac].cw_min, params[ac].cw_max, aci); |
| 2075 | return false; |
| 2076 | } |
Haim Dreyfuss | e552af0 | 2018-03-28 13:24:10 +0300 | [diff] [blame] | 2077 | ieee80211_regulatory_limit_wmm_params(sdata, ¶ms[ac], ac); |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2078 | } |
| 2079 | |
Brian Norris | 05aaa5c | 2019-07-26 15:47:58 -0700 | [diff] [blame] | 2080 | /* WMM specification requires all 4 ACIs. */ |
| 2081 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 2082 | if (params[ac].cw_min == 0) { |
| 2083 | sdata_info(sdata, |
| 2084 | "AP has invalid WMM params (missing AC %d), using defaults\n", |
| 2085 | ac); |
| 2086 | return false; |
| 2087 | } |
| 2088 | } |
| 2089 | |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2090 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2091 | mlme_dbg(sdata, |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2092 | "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n", |
| 2093 | ac, params[ac].acm, |
| 2094 | params[ac].aifs, params[ac].cw_min, params[ac].cw_max, |
| 2095 | params[ac].txop, params[ac].uapsd, |
| 2096 | ifmgd->tx_tspec[ac].downgraded); |
| 2097 | sdata->tx_conf[ac] = params[ac]; |
| 2098 | if (!ifmgd->tx_tspec[ac].downgraded && |
| 2099 | drv_conf_tx(local, sdata, ac, ¶ms[ac])) |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2100 | sdata_err(sdata, |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2101 | "failed to set TX queue parameters for AC %d\n", |
| 2102 | ac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2103 | } |
Stanislaw Gruszka | e1b3ec1 | 2010-03-29 12:18:34 +0200 | [diff] [blame] | 2104 | |
| 2105 | /* enable WMM or activate new settings */ |
Johannes Berg | 4ced3f7 | 2010-07-19 16:39:04 +0200 | [diff] [blame] | 2106 | sdata->vif.bss_conf.qos = true; |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 2107 | return true; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2108 | } |
| 2109 | |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 2110 | static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata) |
| 2111 | { |
| 2112 | lockdep_assert_held(&sdata->local->mtx); |
| 2113 | |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 2114 | sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL; |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 2115 | ieee80211_run_deferred_scan(sdata->local); |
| 2116 | } |
| 2117 | |
| 2118 | static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata) |
| 2119 | { |
| 2120 | mutex_lock(&sdata->local->mtx); |
| 2121 | __ieee80211_stop_poll(sdata); |
| 2122 | mutex_unlock(&sdata->local->mtx); |
| 2123 | } |
| 2124 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2125 | static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata, |
| 2126 | u16 capab, bool erp_valid, u8 erp) |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 2127 | { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 2128 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 2129 | struct ieee80211_supported_band *sband; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2130 | u32 changed = 0; |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2131 | bool use_protection; |
| 2132 | bool use_short_preamble; |
| 2133 | bool use_short_slot; |
| 2134 | |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 2135 | sband = ieee80211_get_sband(sdata); |
| 2136 | if (!sband) |
| 2137 | return changed; |
| 2138 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2139 | if (erp_valid) { |
| 2140 | use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0; |
| 2141 | use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0; |
| 2142 | } else { |
| 2143 | use_protection = false; |
| 2144 | use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE); |
| 2145 | } |
| 2146 | |
| 2147 | use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME); |
Tova Mussai | 07c12d6 | 2020-05-28 21:34:46 +0200 | [diff] [blame] | 2148 | if (sband->band == NL80211_BAND_5GHZ || |
| 2149 | sband->band == NL80211_BAND_6GHZ) |
Felix Fietkau | 43d3534 | 2010-01-15 03:00:48 +0100 | [diff] [blame] | 2150 | use_short_slot = true; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 2151 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2152 | if (use_protection != bss_conf->use_cts_prot) { |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2153 | bss_conf->use_cts_prot = use_protection; |
| 2154 | changed |= BSS_CHANGED_ERP_CTS_PROT; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 2155 | } |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 2156 | |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 2157 | if (use_short_preamble != bss_conf->use_short_preamble) { |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 2158 | bss_conf->use_short_preamble = use_short_preamble; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2159 | changed |= BSS_CHANGED_ERP_PREAMBLE; |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 2160 | } |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 2161 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2162 | if (use_short_slot != bss_conf->use_short_slot) { |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2163 | bss_conf->use_short_slot = use_short_slot; |
| 2164 | changed |= BSS_CHANGED_ERP_SLOT; |
John W. Linville | 50c4afb | 2008-04-15 14:09:27 -0400 | [diff] [blame] | 2165 | } |
| 2166 | |
| 2167 | return changed; |
| 2168 | } |
| 2169 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2170 | static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2171 | struct cfg80211_bss *cbss, |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2172 | u32 bss_info_changed) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2173 | { |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2174 | struct ieee80211_bss *bss = (void *)cbss->priv; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2175 | struct ieee80211_local *local = sdata->local; |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2176 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2177 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2178 | bss_info_changed |= BSS_CHANGED_ASSOC; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2179 | bss_info_changed |= ieee80211_handle_bss_capability(sdata, |
Luciano Coelho | 50ae34a | 2012-06-20 17:23:24 +0300 | [diff] [blame] | 2180 | bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value); |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 2181 | |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 2182 | sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec( |
Ben Greear | 59c1ec2 | 2013-03-19 14:19:56 -0700 | [diff] [blame] | 2183 | beacon_loss_count * bss_conf->beacon_int)); |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 2184 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2185 | sdata->u.mgd.associated = cbss; |
| 2186 | memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2187 | |
Johannes Berg | e8e4f52 | 2017-03-08 11:12:10 +0100 | [diff] [blame] | 2188 | ieee80211_check_rate_mask(sdata); |
| 2189 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 2190 | sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE; |
| 2191 | |
Janusz.Dziedzic@tieto.com | b115b97 | 2015-10-27 08:38:40 +0100 | [diff] [blame] | 2192 | if (sdata->vif.p2p || |
| 2193 | sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2194 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 2195 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2196 | rcu_read_lock(); |
| 2197 | ies = rcu_dereference(cbss->ies); |
| 2198 | if (ies) { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2199 | int ret; |
| 2200 | |
| 2201 | ret = cfg80211_get_p2p_attr( |
| 2202 | ies->data, ies->len, |
| 2203 | IEEE80211_P2P_ATTR_ABSENCE_NOTICE, |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 2204 | (u8 *) &bss_conf->p2p_noa_attr, |
| 2205 | sizeof(bss_conf->p2p_noa_attr)); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2206 | if (ret >= 2) { |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 2207 | sdata->u.mgd.p2p_noa_index = |
| 2208 | bss_conf->p2p_noa_attr.index; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2209 | bss_info_changed |= BSS_CHANGED_P2P_PS; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2210 | } |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 2211 | } |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2212 | rcu_read_unlock(); |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 2213 | } |
| 2214 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2215 | /* just to be sure */ |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 2216 | ieee80211_stop_poll(sdata); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2217 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 2218 | ieee80211_led_assoc(local, 1); |
| 2219 | |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 2220 | if (sdata->u.mgd.have_beacon) { |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 2221 | /* |
| 2222 | * If the AP is buggy we may get here with no DTIM period |
| 2223 | * known, so assume it's 1 which is the only safe assumption |
| 2224 | * in that case, although if the TIM IE is broken powersave |
| 2225 | * probably just won't work at all. |
| 2226 | */ |
| 2227 | bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1; |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 2228 | bss_conf->beacon_rate = bss->beacon_rate; |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 2229 | bss_info_changed |= BSS_CHANGED_BEACON_INFO; |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 2230 | } else { |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 2231 | bss_conf->beacon_rate = NULL; |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 2232 | bss_conf->dtim_period = 0; |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 2233 | } |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 2234 | |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2235 | bss_conf->assoc = 1; |
Johannes Berg | 9cef873 | 2009-05-14 13:10:14 +0200 | [diff] [blame] | 2236 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 2237 | /* Tell the driver to monitor connection quality (if supported) */ |
Johannes Berg | ea08635 | 2012-01-19 09:29:58 +0100 | [diff] [blame] | 2238 | if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI && |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2239 | bss_conf->cqm_rssi_thold) |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 2240 | bss_info_changed |= BSS_CHANGED_CQM; |
| 2241 | |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2242 | /* Enable ARP filtering */ |
Johannes Berg | 0f19b41 | 2013-01-14 16:39:07 +0100 | [diff] [blame] | 2243 | if (bss_conf->arp_addr_cnt) |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2244 | bss_info_changed |= BSS_CHANGED_ARP_FILTER; |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2245 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2246 | ieee80211_bss_info_change_notify(sdata, bss_info_changed); |
Guy Cohen | 8db9369 | 2008-07-03 19:56:13 +0300 | [diff] [blame] | 2247 | |
Johannes Berg | 056508d | 2009-07-30 21:43:55 +0200 | [diff] [blame] | 2248 | mutex_lock(&local->iflist_mtx); |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 2249 | ieee80211_recalc_ps(local); |
Johannes Berg | 056508d | 2009-07-30 21:43:55 +0200 | [diff] [blame] | 2250 | mutex_unlock(&local->iflist_mtx); |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 2251 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 2252 | ieee80211_recalc_smps(sdata); |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 2253 | ieee80211_recalc_ps_vif(sdata); |
| 2254 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 2255 | netif_carrier_on(sdata->dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2256 | } |
| 2257 | |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 2258 | static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2259 | u16 stype, u16 reason, bool tx, |
| 2260 | u8 *frame_buf) |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2261 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2262 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2263 | struct ieee80211_local *local = sdata->local; |
Wen Gong | 63214f0 | 2021-09-24 06:00:52 -0400 | [diff] [blame] | 2264 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Johannes Berg | 3cc5240 | 2012-03-09 13:12:35 +0100 | [diff] [blame] | 2265 | u32 changed = 0; |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 2266 | struct ieee80211_prep_tx_info info = { |
| 2267 | .subtype = stype, |
| 2268 | }; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2269 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2270 | sdata_assert_lock(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2271 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2272 | if (WARN_ON_ONCE(tx && !frame_buf)) |
| 2273 | return; |
| 2274 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2275 | if (WARN_ON(!ifmgd->associated)) |
| 2276 | return; |
| 2277 | |
David Spinadel | 79543d8 | 2012-06-12 09:59:45 +0300 | [diff] [blame] | 2278 | ieee80211_stop_poll(sdata); |
| 2279 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2280 | ifmgd->associated = NULL; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2281 | netif_carrier_off(sdata->dev); |
| 2282 | |
Eliad Peller | 88bc40e | 2012-07-12 17:35:33 +0300 | [diff] [blame] | 2283 | /* |
| 2284 | * if we want to get out of ps before disassoc (why?) we have |
| 2285 | * to do it before sending disassoc, as otherwise the null-packet |
| 2286 | * won't be valid. |
| 2287 | */ |
| 2288 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 2289 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 2290 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 2291 | } |
| 2292 | local->ps_sdata = NULL; |
| 2293 | |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 2294 | /* disable per-vif ps */ |
| 2295 | ieee80211_recalc_ps_vif(sdata); |
| 2296 | |
Emmanuel Grumbach | 14f2ae8 | 2015-01-22 23:30:19 +0200 | [diff] [blame] | 2297 | /* make sure ongoing transmission finishes */ |
| 2298 | synchronize_net(); |
| 2299 | |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 2300 | /* |
| 2301 | * drop any frame before deauth/disassoc, this can be data or |
| 2302 | * management frame. Since we are disconnecting, we should not |
| 2303 | * insist sending these frames which can take time and delay |
| 2304 | * the disconnection and possible the roaming. |
| 2305 | */ |
Eliad Peller | f823981 | 2012-06-27 14:18:22 +0300 | [diff] [blame] | 2306 | if (tx) |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 2307 | ieee80211_flush_queues(local, sdata, true); |
Eliad Peller | f823981 | 2012-06-27 14:18:22 +0300 | [diff] [blame] | 2308 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2309 | /* deauthenticate/disassociate now */ |
Ilan Peer | 94ba927 | 2018-02-19 14:48:41 +0200 | [diff] [blame] | 2310 | if (tx || frame_buf) { |
Ilan Peer | 94ba927 | 2018-02-19 14:48:41 +0200 | [diff] [blame] | 2311 | /* |
| 2312 | * In multi channel scenarios guarantee that the virtual |
| 2313 | * interface is granted immediate airtime to transmit the |
| 2314 | * deauthentication frame by calling mgd_prepare_tx, if the |
| 2315 | * driver requested so. |
| 2316 | */ |
| 2317 | if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) && |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 2318 | !ifmgd->have_beacon) { |
| 2319 | drv_mgd_prepare_tx(sdata->local, sdata, &info); |
| 2320 | } |
Ilan Peer | 94ba927 | 2018-02-19 14:48:41 +0200 | [diff] [blame] | 2321 | |
Johannes Berg | 4b08d1b | 2019-08-30 14:24:51 +0300 | [diff] [blame] | 2322 | ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, |
| 2323 | ifmgd->bssid, stype, reason, |
| 2324 | tx, frame_buf); |
Ilan Peer | 94ba927 | 2018-02-19 14:48:41 +0200 | [diff] [blame] | 2325 | } |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2326 | |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 2327 | /* flush out frame - make sure the deauth was actually sent */ |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2328 | if (tx) |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 2329 | ieee80211_flush_queues(local, sdata, false); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2330 | |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 2331 | drv_mgd_complete_tx(sdata->local, sdata, &info); |
| 2332 | |
Eliad Peller | 88a9e31 | 2012-06-01 11:14:03 +0300 | [diff] [blame] | 2333 | /* clear bssid only after building the needed mgmt frames */ |
Joe Perches | c84a67a | 2015-03-02 19:54:57 -0800 | [diff] [blame] | 2334 | eth_zero_addr(ifmgd->bssid); |
Eliad Peller | 88a9e31 | 2012-06-01 11:14:03 +0300 | [diff] [blame] | 2335 | |
Wen Gong | b0140fd | 2020-12-07 11:36:34 +0800 | [diff] [blame] | 2336 | sdata->vif.bss_conf.ssid_len = 0; |
| 2337 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2338 | /* remove AP and TDLS peers */ |
Johannes Berg | d34ba21 | 2013-12-04 22:46:11 +0100 | [diff] [blame] | 2339 | sta_info_flush(sdata); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2340 | |
| 2341 | /* finally reset all BSS / config parameters */ |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 2342 | changed |= ieee80211_reset_erp_info(sdata); |
| 2343 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 2344 | ieee80211_led_assoc(local, 0); |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2345 | changed |= BSS_CHANGED_ASSOC; |
| 2346 | sdata->vif.bss_conf.assoc = false; |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 2347 | |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 2348 | ifmgd->p2p_noa_index = -1; |
| 2349 | memset(&sdata->vif.bss_conf.p2p_noa_attr, 0, |
| 2350 | sizeof(sdata->vif.bss_conf.p2p_noa_attr)); |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 2351 | |
Johannes Berg | dd5ecfe | 2013-02-21 17:40:19 +0100 | [diff] [blame] | 2352 | /* on the next assoc, re-program HT/VHT parameters */ |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 2353 | memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa)); |
| 2354 | memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask)); |
Johannes Berg | dd5ecfe | 2013-02-21 17:40:19 +0100 | [diff] [blame] | 2355 | memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa)); |
| 2356 | memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask)); |
Sara Sharon | 23a1f8d | 2015-12-08 16:04:31 +0200 | [diff] [blame] | 2357 | |
| 2358 | /* reset MU-MIMO ownership and group data */ |
| 2359 | memset(sdata->vif.bss_conf.mu_group.membership, 0, |
| 2360 | sizeof(sdata->vif.bss_conf.mu_group.membership)); |
| 2361 | memset(sdata->vif.bss_conf.mu_group.position, 0, |
| 2362 | sizeof(sdata->vif.bss_conf.mu_group.position)); |
| 2363 | changed |= BSS_CHANGED_MU_GROUPS; |
Sara Sharon | b5a33d5 | 2016-02-16 12:48:18 +0200 | [diff] [blame] | 2364 | sdata->vif.mu_mimo_owner = false; |
Johannes Berg | 413ad50 | 2009-05-08 21:21:06 +0200 | [diff] [blame] | 2365 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2366 | sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL; |
Vasanthakumar Thiagarajan | a8302de | 2009-01-09 18:14:15 +0530 | [diff] [blame] | 2367 | |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 2368 | del_timer_sync(&local->dynamic_ps_timer); |
| 2369 | cancel_work_sync(&local->dynamic_ps_enable_work); |
| 2370 | |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2371 | /* Disable ARP filtering */ |
Johannes Berg | 0f19b41 | 2013-01-14 16:39:07 +0100 | [diff] [blame] | 2372 | if (sdata->vif.bss_conf.arp_addr_cnt) |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2373 | changed |= BSS_CHANGED_ARP_FILTER; |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2374 | |
Johannes Berg | 3abead5 | 2012-03-02 15:56:59 +0100 | [diff] [blame] | 2375 | sdata->vif.bss_conf.qos = false; |
| 2376 | changed |= BSS_CHANGED_QOS; |
| 2377 | |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 2378 | /* The BSSID (not really interesting) and HT changed */ |
| 2379 | changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT; |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2380 | ieee80211_bss_info_change_notify(sdata, changed); |
Tomas Winkler | 8e268e4 | 2008-11-25 13:05:44 +0200 | [diff] [blame] | 2381 | |
Johannes Berg | 3abead5 | 2012-03-02 15:56:59 +0100 | [diff] [blame] | 2382 | /* disassociated - set to defaults now */ |
Johannes Berg | cec6628 | 2015-10-22 17:46:04 +0200 | [diff] [blame] | 2383 | ieee80211_set_wmm_default(sdata, false, false); |
Johannes Berg | 3abead5 | 2012-03-02 15:56:59 +0100 | [diff] [blame] | 2384 | |
Johannes Berg | b9dcf71 | 2010-08-27 12:35:54 +0200 | [diff] [blame] | 2385 | del_timer_sync(&sdata->u.mgd.conn_mon_timer); |
| 2386 | del_timer_sync(&sdata->u.mgd.bcn_mon_timer); |
| 2387 | del_timer_sync(&sdata->u.mgd.timer); |
| 2388 | del_timer_sync(&sdata->u.mgd.chswitch_timer); |
Johannes Berg | 2d9957c | 2012-08-01 20:54:52 +0200 | [diff] [blame] | 2389 | |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 2390 | sdata->vif.bss_conf.dtim_period = 0; |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 2391 | sdata->vif.bss_conf.beacon_rate = NULL; |
| 2392 | |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 2393 | ifmgd->have_beacon = false; |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 2394 | |
Johannes Berg | 028e8da0 | 2012-11-26 11:57:41 +0100 | [diff] [blame] | 2395 | ifmgd->flags = 0; |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2396 | mutex_lock(&local->mtx); |
Johannes Berg | 028e8da0 | 2012-11-26 11:57:41 +0100 | [diff] [blame] | 2397 | ieee80211_vif_release_channel(sdata); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 2398 | |
| 2399 | sdata->vif.csa_active = false; |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 2400 | ifmgd->csa_waiting_bcn = false; |
Johannes Berg | f84eaa1 | 2015-03-12 08:53:26 +0200 | [diff] [blame] | 2401 | ifmgd->csa_ignored_same_chan = false; |
Luciano Coelho | a46992b | 2014-06-13 16:30:07 +0300 | [diff] [blame] | 2402 | if (sdata->csa_block_tx) { |
| 2403 | ieee80211_wake_vif_queues(local, sdata, |
| 2404 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 2405 | sdata->csa_block_tx = false; |
| 2406 | } |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2407 | mutex_unlock(&local->mtx); |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 2408 | |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 2409 | /* existing TX TSPEC sessions no longer exist */ |
| 2410 | memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec)); |
| 2411 | cancel_delayed_work_sync(&ifmgd->tx_tspec_wk); |
| 2412 | |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 2413 | sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM; |
Wen Gong | 63214f0 | 2021-09-24 06:00:52 -0400 | [diff] [blame] | 2414 | |
| 2415 | bss_conf->pwr_reduction = 0; |
| 2416 | bss_conf->tx_pwr_env_num = 0; |
| 2417 | memset(bss_conf->tx_pwr_env, 0, sizeof(bss_conf->tx_pwr_env)); |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2418 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2419 | |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2420 | static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata) |
| 2421 | { |
| 2422 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2423 | struct ieee80211_local *local = sdata->local; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2424 | |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2425 | mutex_lock(&local->mtx); |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 2426 | if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)) |
| 2427 | goto out; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2428 | |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 2429 | __ieee80211_stop_poll(sdata); |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2430 | |
| 2431 | mutex_lock(&local->iflist_mtx); |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 2432 | ieee80211_recalc_ps(local); |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2433 | mutex_unlock(&local->iflist_mtx); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2434 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2435 | if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR)) |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2436 | goto out; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2437 | |
| 2438 | /* |
| 2439 | * We've received a probe response, but are not sure whether |
| 2440 | * we have or will be receiving any beacons or data, so let's |
| 2441 | * schedule the timers again, just in case. |
| 2442 | */ |
| 2443 | ieee80211_sta_reset_beacon_monitor(sdata); |
| 2444 | |
| 2445 | mod_timer(&ifmgd->conn_mon_timer, |
| 2446 | round_jiffies_up(jiffies + |
| 2447 | IEEE80211_CONNECTION_IDLE_TIME)); |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2448 | out: |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2449 | mutex_unlock(&local->mtx); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2450 | } |
| 2451 | |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 2452 | static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata, |
| 2453 | struct ieee80211_hdr *hdr, |
| 2454 | u16 tx_time) |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2455 | { |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 2456 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | d5e568c | 2021-11-22 12:47:40 +0100 | [diff] [blame] | 2457 | u16 tid; |
| 2458 | int ac; |
| 2459 | struct ieee80211_sta_tx_tspec *tx_tspec; |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 2460 | unsigned long now = jiffies; |
| 2461 | |
Johannes Berg | d5e568c | 2021-11-22 12:47:40 +0100 | [diff] [blame] | 2462 | if (!ieee80211_is_data_qos(hdr->frame_control)) |
| 2463 | return; |
| 2464 | |
| 2465 | tid = ieee80211_get_tid(hdr); |
| 2466 | ac = ieee80211_ac_from_tid(tid); |
| 2467 | tx_tspec = &ifmgd->tx_tspec[ac]; |
| 2468 | |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 2469 | if (likely(!tx_tspec->admitted_time)) |
| 2470 | return; |
| 2471 | |
| 2472 | if (time_after(now, tx_tspec->time_slice_start + HZ)) { |
| 2473 | tx_tspec->consumed_tx_time = 0; |
| 2474 | tx_tspec->time_slice_start = now; |
| 2475 | |
| 2476 | if (tx_tspec->downgraded) { |
| 2477 | tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE; |
| 2478 | schedule_delayed_work(&ifmgd->tx_tspec_wk, 0); |
| 2479 | } |
| 2480 | } |
| 2481 | |
| 2482 | if (tx_tspec->downgraded) |
| 2483 | return; |
| 2484 | |
| 2485 | tx_tspec->consumed_tx_time += tx_time; |
| 2486 | |
| 2487 | if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) { |
| 2488 | tx_tspec->downgraded = true; |
| 2489 | tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE; |
| 2490 | schedule_delayed_work(&ifmgd->tx_tspec_wk, 0); |
| 2491 | } |
| 2492 | } |
| 2493 | |
| 2494 | void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata, |
| 2495 | struct ieee80211_hdr *hdr, bool ack, u16 tx_time) |
| 2496 | { |
| 2497 | ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time); |
| 2498 | |
Felix Fietkau | 9abf4e4 | 2020-09-08 14:36:56 +0200 | [diff] [blame] | 2499 | if (!ieee80211_is_any_nullfunc(hdr->frame_control) || |
| 2500 | !sdata->u.mgd.probe_send_count) |
Wojciech Dubowik | cab1c7f | 2013-02-14 14:08:37 +0100 | [diff] [blame] | 2501 | return; |
Wojciech Dubowik | cab1c7f | 2013-02-14 14:08:37 +0100 | [diff] [blame] | 2502 | |
Felix Fietkau | e3f2590 | 2020-09-27 12:56:05 +0200 | [diff] [blame] | 2503 | if (ack) |
| 2504 | sdata->u.mgd.probe_send_count = 0; |
| 2505 | else |
Felix Fietkau | 9abf4e4 | 2020-09-08 14:36:56 +0200 | [diff] [blame] | 2506 | sdata->u.mgd.nullfunc_failed = true; |
| 2507 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2508 | } |
| 2509 | |
Johannes Berg | 45ad683 | 2018-05-28 15:47:39 +0200 | [diff] [blame] | 2510 | static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata, |
| 2511 | const u8 *src, const u8 *dst, |
| 2512 | const u8 *ssid, size_t ssid_len, |
| 2513 | struct ieee80211_channel *channel) |
| 2514 | { |
| 2515 | struct sk_buff *skb; |
| 2516 | |
| 2517 | skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel, |
| 2518 | ssid, ssid_len, NULL, 0, |
| 2519 | IEEE80211_PROBE_FLAG_DIRECTED); |
| 2520 | if (skb) |
| 2521 | ieee80211_tx_skb(sdata, skb); |
| 2522 | } |
| 2523 | |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2524 | static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata) |
| 2525 | { |
| 2526 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | f262213 | 2021-09-30 13:11:31 +0200 | [diff] [blame] | 2527 | const struct element *ssid; |
Luis R. Rodriguez | f01a067 | 2010-09-16 15:12:34 -0400 | [diff] [blame] | 2528 | u8 *dst = ifmgd->associated->bssid; |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 2529 | u8 unicast_limit = max(1, max_probe_tries - 3); |
Johannes Berg | 49ddf8e | 2016-03-31 20:02:10 +0300 | [diff] [blame] | 2530 | struct sta_info *sta; |
Luis R. Rodriguez | f01a067 | 2010-09-16 15:12:34 -0400 | [diff] [blame] | 2531 | |
| 2532 | /* |
| 2533 | * Try sending broadcast probe requests for the last three |
| 2534 | * probe requests after the first ones failed since some |
| 2535 | * buggy APs only support broadcast probe requests. |
| 2536 | */ |
| 2537 | if (ifmgd->probe_send_count >= unicast_limit) |
| 2538 | dst = NULL; |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2539 | |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2540 | /* |
| 2541 | * When the hardware reports an accurate Tx ACK status, it's |
| 2542 | * better to send a nullfunc frame instead of a probe request, |
| 2543 | * as it will kick us off the AP quickly if we aren't associated |
| 2544 | * anymore. The timeout will be reset if the frame is ACKed by |
| 2545 | * the AP. |
| 2546 | */ |
Soumik Das | 992e68b | 2012-05-20 15:31:13 +0530 | [diff] [blame] | 2547 | ifmgd->probe_send_count++; |
| 2548 | |
Johannes Berg | 49ddf8e | 2016-03-31 20:02:10 +0300 | [diff] [blame] | 2549 | if (dst) { |
| 2550 | mutex_lock(&sdata->local->sta_mtx); |
| 2551 | sta = sta_info_get(sdata, dst); |
| 2552 | if (!WARN_ON(!sta)) |
| 2553 | ieee80211_check_fast_rx(sta); |
| 2554 | mutex_unlock(&sdata->local->sta_mtx); |
| 2555 | } |
| 2556 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2557 | if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) { |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2558 | ifmgd->nullfunc_failed = false; |
Ping-Ke Shih | 2832943 | 2021-06-23 21:48:26 +0800 | [diff] [blame] | 2559 | ieee80211_send_nullfunc(sdata->local, sdata, false); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2560 | } else { |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 2561 | int ssid_len; |
| 2562 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2563 | rcu_read_lock(); |
Johannes Berg | f262213 | 2021-09-30 13:11:31 +0200 | [diff] [blame] | 2564 | ssid = ieee80211_bss_get_elem(ifmgd->associated, WLAN_EID_SSID); |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 2565 | if (WARN_ON_ONCE(ssid == NULL)) |
| 2566 | ssid_len = 0; |
| 2567 | else |
Johannes Berg | f262213 | 2021-09-30 13:11:31 +0200 | [diff] [blame] | 2568 | ssid_len = ssid->datalen; |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 2569 | |
Johannes Berg | 45ad683 | 2018-05-28 15:47:39 +0200 | [diff] [blame] | 2570 | ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst, |
Johannes Berg | f262213 | 2021-09-30 13:11:31 +0200 | [diff] [blame] | 2571 | ssid->data, ssid_len, |
Johannes Berg | 45ad683 | 2018-05-28 15:47:39 +0200 | [diff] [blame] | 2572 | ifmgd->associated->channel); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2573 | rcu_read_unlock(); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2574 | } |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2575 | |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 2576 | ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2577 | run_again(sdata, ifmgd->probe_timeout); |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2578 | } |
| 2579 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2580 | static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata, |
| 2581 | bool beacon) |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2582 | { |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2583 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2584 | bool already = false; |
Johannes Berg | 34bfc41 | 2009-05-12 19:58:12 +0200 | [diff] [blame] | 2585 | |
Johannes Berg | 9607e6b66 | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 2586 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | 0e2b628 | 2009-07-13 13:23:39 +0200 | [diff] [blame] | 2587 | return; |
| 2588 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2589 | sdata_lock(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2590 | |
| 2591 | if (!ifmgd->associated) |
| 2592 | goto out; |
| 2593 | |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2594 | mutex_lock(&sdata->local->mtx); |
| 2595 | |
| 2596 | if (sdata->local->tmp_channel || sdata->local->scanning) { |
| 2597 | mutex_unlock(&sdata->local->mtx); |
| 2598 | goto out; |
| 2599 | } |
| 2600 | |
Loic Poulain | b33fb28 | 2021-10-21 10:45:27 +0200 | [diff] [blame] | 2601 | if (sdata->local->suspending) { |
| 2602 | /* reschedule after resume */ |
| 2603 | mutex_unlock(&sdata->local->mtx); |
| 2604 | ieee80211_reset_ap_probe(sdata); |
| 2605 | goto out; |
| 2606 | } |
| 2607 | |
Ben Greear | a13fbe5 | 2013-03-25 11:19:35 -0700 | [diff] [blame] | 2608 | if (beacon) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2609 | mlme_dbg_ratelimited(sdata, |
Ben Greear | 59c1ec2 | 2013-03-19 14:19:56 -0700 | [diff] [blame] | 2610 | "detected beacon loss from AP (missed %d beacons) - probing\n", |
| 2611 | beacon_loss_count); |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2612 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 2613 | ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL); |
Ben Greear | a13fbe5 | 2013-03-25 11:19:35 -0700 | [diff] [blame] | 2614 | } |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2615 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2616 | /* |
| 2617 | * The driver/our work has already reported this event or the |
| 2618 | * connection monitoring has kicked in and we have already sent |
| 2619 | * a probe request. Or maybe the AP died and the driver keeps |
| 2620 | * reporting until we disassociate... |
| 2621 | * |
| 2622 | * In either case we have to ignore the current call to this |
| 2623 | * function (except for setting the correct probe reason bit) |
| 2624 | * because otherwise we would reset the timer every time and |
| 2625 | * never check whether we received a probe response! |
| 2626 | */ |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 2627 | if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2628 | already = true; |
| 2629 | |
Eliad Peller | 12b5f34 | 2013-11-18 19:06:46 +0200 | [diff] [blame] | 2630 | ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL; |
| 2631 | |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2632 | mutex_unlock(&sdata->local->mtx); |
| 2633 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2634 | if (already) |
| 2635 | goto out; |
| 2636 | |
Johannes Berg | 4e75184 | 2009-06-10 15:16:52 +0200 | [diff] [blame] | 2637 | mutex_lock(&sdata->local->iflist_mtx); |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 2638 | ieee80211_recalc_ps(sdata->local); |
Johannes Berg | 4e75184 | 2009-06-10 15:16:52 +0200 | [diff] [blame] | 2639 | mutex_unlock(&sdata->local->iflist_mtx); |
| 2640 | |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2641 | ifmgd->probe_send_count = 0; |
| 2642 | ieee80211_mgd_probe_ap_send(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2643 | out: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2644 | sdata_unlock(sdata); |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2645 | } |
| 2646 | |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2647 | struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw, |
| 2648 | struct ieee80211_vif *vif) |
| 2649 | { |
| 2650 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 2651 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Eliad Peller | d9b3b28 | 2012-06-28 15:03:13 +0300 | [diff] [blame] | 2652 | struct cfg80211_bss *cbss; |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2653 | struct sk_buff *skb; |
Johannes Berg | f262213 | 2021-09-30 13:11:31 +0200 | [diff] [blame] | 2654 | const struct element *ssid; |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 2655 | int ssid_len; |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2656 | |
| 2657 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) |
| 2658 | return NULL; |
| 2659 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2660 | sdata_assert_lock(sdata); |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2661 | |
Eliad Peller | d9b3b28 | 2012-06-28 15:03:13 +0300 | [diff] [blame] | 2662 | if (ifmgd->associated) |
| 2663 | cbss = ifmgd->associated; |
| 2664 | else if (ifmgd->auth_data) |
| 2665 | cbss = ifmgd->auth_data->bss; |
| 2666 | else if (ifmgd->assoc_data) |
| 2667 | cbss = ifmgd->assoc_data->bss; |
| 2668 | else |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2669 | return NULL; |
| 2670 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2671 | rcu_read_lock(); |
Johannes Berg | f262213 | 2021-09-30 13:11:31 +0200 | [diff] [blame] | 2672 | ssid = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID); |
| 2673 | if (WARN_ONCE(!ssid || ssid->datalen > IEEE80211_MAX_SSID_LEN, |
| 2674 | "invalid SSID element (len=%d)", |
| 2675 | ssid ? ssid->datalen : -1)) |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 2676 | ssid_len = 0; |
| 2677 | else |
Johannes Berg | f262213 | 2021-09-30 13:11:31 +0200 | [diff] [blame] | 2678 | ssid_len = ssid->datalen; |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 2679 | |
Johannes Berg | a344d67 | 2014-06-12 22:24:31 +0200 | [diff] [blame] | 2680 | skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid, |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2681 | (u32) -1, cbss->channel, |
Johannes Berg | f262213 | 2021-09-30 13:11:31 +0200 | [diff] [blame] | 2682 | ssid->data, ssid_len, |
Johannes Berg | 00387f3 | 2018-05-28 15:47:38 +0200 | [diff] [blame] | 2683 | NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2684 | rcu_read_unlock(); |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2685 | |
| 2686 | return skb; |
| 2687 | } |
| 2688 | EXPORT_SYMBOL(ieee80211_ap_probereq_get); |
| 2689 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 2690 | static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata, |
| 2691 | const u8 *buf, size_t len, bool tx, |
Johannes Berg | 3f8a39f | 2020-12-06 14:54:43 +0200 | [diff] [blame] | 2692 | u16 reason, bool reconnect) |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 2693 | { |
| 2694 | struct ieee80211_event event = { |
| 2695 | .type = MLME_EVENT, |
| 2696 | .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT, |
| 2697 | .u.mlme.reason = reason, |
| 2698 | }; |
| 2699 | |
| 2700 | if (tx) |
Johannes Berg | 3f8a39f | 2020-12-06 14:54:43 +0200 | [diff] [blame] | 2701 | cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect); |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 2702 | else |
| 2703 | cfg80211_rx_mlme_mgmt(sdata->dev, buf, len); |
| 2704 | |
| 2705 | drv_event_callback(sdata->local, sdata, &event); |
| 2706 | } |
| 2707 | |
Johannes Berg | eef9e54 | 2013-01-29 13:09:34 +0100 | [diff] [blame] | 2708 | static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata) |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2709 | { |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 2710 | struct ieee80211_local *local = sdata->local; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2711 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 2712 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 2713 | bool tx; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2714 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2715 | sdata_lock(sdata); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2716 | if (!ifmgd->associated) { |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2717 | sdata_unlock(sdata); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2718 | return; |
| 2719 | } |
| 2720 | |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 2721 | tx = !sdata->csa_block_tx; |
| 2722 | |
Johannes Berg | 3f8a39f | 2020-12-06 14:54:43 +0200 | [diff] [blame] | 2723 | if (!ifmgd->driver_disconnect) { |
| 2724 | /* |
| 2725 | * AP is probably out of range (or not reachable for another |
| 2726 | * reason) so remove the bss struct for that AP. |
| 2727 | */ |
| 2728 | cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated); |
| 2729 | } |
David Spinadel | 20eb7ea | 2016-05-03 16:05:02 +0300 | [diff] [blame] | 2730 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2731 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
Johannes Berg | 3f8a39f | 2020-12-06 14:54:43 +0200 | [diff] [blame] | 2732 | ifmgd->driver_disconnect ? |
| 2733 | WLAN_REASON_DEAUTH_LEAVING : |
| 2734 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 2735 | tx, frame_buf); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 2736 | mutex_lock(&local->mtx); |
Arik Nemtsov | 7578d57 | 2013-09-01 17:15:51 +0300 | [diff] [blame] | 2737 | sdata->vif.csa_active = false; |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 2738 | ifmgd->csa_waiting_bcn = false; |
Luciano Coelho | a46992b | 2014-06-13 16:30:07 +0300 | [diff] [blame] | 2739 | if (sdata->csa_block_tx) { |
| 2740 | ieee80211_wake_vif_queues(local, sdata, |
| 2741 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 2742 | sdata->csa_block_tx = false; |
| 2743 | } |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 2744 | mutex_unlock(&local->mtx); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 2745 | |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 2746 | ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx, |
Johannes Berg | 3f8a39f | 2020-12-06 14:54:43 +0200 | [diff] [blame] | 2747 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, |
| 2748 | ifmgd->reconnect); |
| 2749 | ifmgd->reconnect = false; |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 2750 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2751 | sdata_unlock(sdata); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2752 | } |
| 2753 | |
Johannes Berg | cc74c0c | 2012-08-01 16:49:34 +0200 | [diff] [blame] | 2754 | static void ieee80211_beacon_connection_loss_work(struct work_struct *work) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2755 | { |
| 2756 | struct ieee80211_sub_if_data *sdata = |
| 2757 | container_of(work, struct ieee80211_sub_if_data, |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2758 | u.mgd.beacon_connection_loss_work); |
Paul Stewart | a85e1d5 | 2011-12-09 11:01:49 -0800 | [diff] [blame] | 2759 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Paul Stewart | a85e1d5 | 2011-12-09 11:01:49 -0800 | [diff] [blame] | 2760 | |
Johannes Berg | 976bd9e | 2015-10-16 17:18:11 +0200 | [diff] [blame] | 2761 | if (ifmgd->associated) |
| 2762 | ifmgd->beacon_loss_count++; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2763 | |
Johannes Berg | 682bd38 | 2013-01-29 13:13:50 +0100 | [diff] [blame] | 2764 | if (ifmgd->connection_loss) { |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 2765 | sdata_info(sdata, "Connection to AP %pM lost\n", |
| 2766 | ifmgd->bssid); |
Johannes Berg | eef9e54 | 2013-01-29 13:09:34 +0100 | [diff] [blame] | 2767 | __ieee80211_disconnect(sdata); |
Johannes Berg | 3f8a39f | 2020-12-06 14:54:43 +0200 | [diff] [blame] | 2768 | ifmgd->connection_loss = false; |
| 2769 | } else if (ifmgd->driver_disconnect) { |
| 2770 | sdata_info(sdata, |
| 2771 | "Driver requested disconnection from AP %pM\n", |
| 2772 | ifmgd->bssid); |
| 2773 | __ieee80211_disconnect(sdata); |
| 2774 | ifmgd->driver_disconnect = false; |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 2775 | } else { |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2776 | ieee80211_mgd_probe_ap(sdata, true); |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 2777 | } |
| 2778 | } |
| 2779 | |
| 2780 | static void ieee80211_csa_connection_drop_work(struct work_struct *work) |
| 2781 | { |
| 2782 | struct ieee80211_sub_if_data *sdata = |
| 2783 | container_of(work, struct ieee80211_sub_if_data, |
| 2784 | u.mgd.csa_connection_drop_work); |
| 2785 | |
Johannes Berg | eef9e54 | 2013-01-29 13:09:34 +0100 | [diff] [blame] | 2786 | __ieee80211_disconnect(sdata); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2787 | } |
| 2788 | |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2789 | void ieee80211_beacon_loss(struct ieee80211_vif *vif) |
| 2790 | { |
| 2791 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2792 | struct ieee80211_hw *hw = &sdata->local->hw; |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2793 | |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 2794 | trace_api_beacon_loss(sdata); |
| 2795 | |
Johannes Berg | 682bd38 | 2013-01-29 13:13:50 +0100 | [diff] [blame] | 2796 | sdata->u.mgd.connection_loss = false; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2797 | ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work); |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2798 | } |
| 2799 | EXPORT_SYMBOL(ieee80211_beacon_loss); |
| 2800 | |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2801 | void ieee80211_connection_loss(struct ieee80211_vif *vif) |
| 2802 | { |
| 2803 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 2804 | struct ieee80211_hw *hw = &sdata->local->hw; |
| 2805 | |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 2806 | trace_api_connection_loss(sdata); |
| 2807 | |
Johannes Berg | 682bd38 | 2013-01-29 13:13:50 +0100 | [diff] [blame] | 2808 | sdata->u.mgd.connection_loss = true; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2809 | ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work); |
| 2810 | } |
| 2811 | EXPORT_SYMBOL(ieee80211_connection_loss); |
| 2812 | |
Johannes Berg | 3f8a39f | 2020-12-06 14:54:43 +0200 | [diff] [blame] | 2813 | void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect) |
| 2814 | { |
| 2815 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 2816 | struct ieee80211_hw *hw = &sdata->local->hw; |
| 2817 | |
| 2818 | trace_api_disconnect(sdata, reconnect); |
| 2819 | |
| 2820 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) |
| 2821 | return; |
| 2822 | |
| 2823 | sdata->u.mgd.driver_disconnect = true; |
| 2824 | sdata->u.mgd.reconnect = reconnect; |
| 2825 | ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work); |
| 2826 | } |
| 2827 | EXPORT_SYMBOL(ieee80211_disconnect); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2828 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2829 | static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata, |
| 2830 | bool assoc) |
| 2831 | { |
| 2832 | struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data; |
| 2833 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2834 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2835 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2836 | if (!assoc) { |
Emmanuel Grumbach | c1e140b | 2015-01-19 16:53:06 +0200 | [diff] [blame] | 2837 | /* |
| 2838 | * we are not authenticated yet, the only timer that could be |
| 2839 | * running is the timeout for the authentication response which |
| 2840 | * which is not relevant anymore. |
| 2841 | */ |
| 2842 | del_timer_sync(&sdata->u.mgd.timer); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2843 | sta_info_destroy_addr(sdata, auth_data->bss->bssid); |
| 2844 | |
Joe Perches | c84a67a | 2015-03-02 19:54:57 -0800 | [diff] [blame] | 2845 | eth_zero_addr(sdata->u.mgd.bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2846 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
Johannes Berg | 028e8da0 | 2012-11-26 11:57:41 +0100 | [diff] [blame] | 2847 | sdata->u.mgd.flags = 0; |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2848 | mutex_lock(&sdata->local->mtx); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2849 | ieee80211_vif_release_channel(sdata); |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2850 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2851 | } |
| 2852 | |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 2853 | cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2854 | kfree(auth_data); |
| 2855 | sdata->u.mgd.auth_data = NULL; |
| 2856 | } |
| 2857 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 2858 | static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 2859 | bool assoc, bool abandon) |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 2860 | { |
| 2861 | struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data; |
| 2862 | |
| 2863 | sdata_assert_lock(sdata); |
| 2864 | |
| 2865 | if (!assoc) { |
| 2866 | /* |
| 2867 | * we are not associated yet, the only timer that could be |
| 2868 | * running is the timeout for the association response which |
| 2869 | * which is not relevant anymore. |
| 2870 | */ |
| 2871 | del_timer_sync(&sdata->u.mgd.timer); |
| 2872 | sta_info_destroy_addr(sdata, assoc_data->bss->bssid); |
| 2873 | |
| 2874 | eth_zero_addr(sdata->u.mgd.bssid); |
| 2875 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
| 2876 | sdata->u.mgd.flags = 0; |
Sara Sharon | b5a33d5 | 2016-02-16 12:48:18 +0200 | [diff] [blame] | 2877 | sdata->vif.mu_mimo_owner = false; |
| 2878 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 2879 | mutex_lock(&sdata->local->mtx); |
| 2880 | ieee80211_vif_release_channel(sdata); |
| 2881 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 2882 | |
| 2883 | if (abandon) |
| 2884 | cfg80211_abandon_assoc(sdata->dev, assoc_data->bss); |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 2885 | } |
| 2886 | |
| 2887 | kfree(assoc_data); |
| 2888 | sdata->u.mgd.assoc_data = NULL; |
| 2889 | } |
| 2890 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2891 | static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata, |
| 2892 | struct ieee80211_mgmt *mgmt, size_t len) |
| 2893 | { |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 2894 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2895 | struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data; |
Johannes Berg | 49a765d | 2021-09-20 15:40:09 +0200 | [diff] [blame] | 2896 | const struct element *challenge; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2897 | u8 *pos; |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 2898 | u32 tx_flags = 0; |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 2899 | struct ieee80211_prep_tx_info info = { |
| 2900 | .subtype = IEEE80211_STYPE_AUTH, |
| 2901 | }; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2902 | |
| 2903 | pos = mgmt->u.auth.variable; |
Johannes Berg | 49a765d | 2021-09-20 15:40:09 +0200 | [diff] [blame] | 2904 | challenge = cfg80211_find_elem(WLAN_EID_CHALLENGE, pos, |
| 2905 | len - (pos - (u8 *)mgmt)); |
| 2906 | if (!challenge) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2907 | return; |
| 2908 | auth_data->expected_transaction = 4; |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 2909 | drv_mgd_prepare_tx(sdata->local, sdata, &info); |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2910 | if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 2911 | tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS | |
| 2912 | IEEE80211_TX_INTFL_MLME_CONN_TX; |
Jouni Malinen | 700e8ea | 2012-09-30 19:29:37 +0300 | [diff] [blame] | 2913 | ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0, |
Johannes Berg | 49a765d | 2021-09-20 15:40:09 +0200 | [diff] [blame] | 2914 | (void *)challenge, |
| 2915 | challenge->datalen + sizeof(*challenge), |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2916 | auth_data->bss->bssid, auth_data->bss->bssid, |
| 2917 | auth_data->key, auth_data->key_len, |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 2918 | auth_data->key_idx, tx_flags); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2919 | } |
| 2920 | |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2921 | static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata, |
| 2922 | const u8 *bssid) |
| 2923 | { |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 2924 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2925 | struct sta_info *sta; |
Wei Yongjun | 33483a6 | 2018-10-16 02:35:30 +0000 | [diff] [blame] | 2926 | bool result = true; |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2927 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 2928 | sdata_info(sdata, "authenticated\n"); |
| 2929 | ifmgd->auth_data->done = true; |
| 2930 | ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC; |
| 2931 | ifmgd->auth_data->timeout_started = true; |
| 2932 | run_again(sdata, ifmgd->auth_data->timeout); |
| 2933 | |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2934 | /* move station state to auth */ |
| 2935 | mutex_lock(&sdata->local->sta_mtx); |
| 2936 | sta = sta_info_get(sdata, bssid); |
| 2937 | if (!sta) { |
| 2938 | WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid); |
Wei Yongjun | 33483a6 | 2018-10-16 02:35:30 +0000 | [diff] [blame] | 2939 | result = false; |
| 2940 | goto out; |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2941 | } |
| 2942 | if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) { |
| 2943 | sdata_info(sdata, "failed moving %pM to auth\n", bssid); |
Wei Yongjun | 33483a6 | 2018-10-16 02:35:30 +0000 | [diff] [blame] | 2944 | result = false; |
| 2945 | goto out; |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2946 | } |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2947 | |
Wei Yongjun | 33483a6 | 2018-10-16 02:35:30 +0000 | [diff] [blame] | 2948 | out: |
| 2949 | mutex_unlock(&sdata->local->sta_mtx); |
| 2950 | return result; |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2951 | } |
| 2952 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2953 | static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata, |
| 2954 | struct ieee80211_mgmt *mgmt, size_t len) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2955 | { |
| 2956 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 2957 | u8 bssid[ETH_ALEN]; |
| 2958 | u16 auth_alg, auth_transaction, status_code; |
Emmanuel Grumbach | a940909 | 2015-03-16 23:23:35 +0200 | [diff] [blame] | 2959 | struct ieee80211_event event = { |
| 2960 | .type = MLME_EVENT, |
| 2961 | .u.mlme.data = AUTH_EVENT, |
| 2962 | }; |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 2963 | struct ieee80211_prep_tx_info info = { |
| 2964 | .subtype = IEEE80211_STYPE_AUTH, |
| 2965 | }; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2966 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2967 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2968 | |
| 2969 | if (len < 24 + 6) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2970 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2971 | |
| 2972 | if (!ifmgd->auth_data || ifmgd->auth_data->done) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2973 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2974 | |
| 2975 | memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN); |
| 2976 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2977 | if (!ether_addr_equal(bssid, mgmt->bssid)) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2978 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2979 | |
| 2980 | auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); |
| 2981 | auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); |
| 2982 | status_code = le16_to_cpu(mgmt->u.auth.status_code); |
| 2983 | |
| 2984 | if (auth_alg != ifmgd->auth_data->algorithm || |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 2985 | (auth_alg != WLAN_AUTH_SAE && |
| 2986 | auth_transaction != ifmgd->auth_data->expected_transaction) || |
| 2987 | (auth_alg == WLAN_AUTH_SAE && |
| 2988 | (auth_transaction < ifmgd->auth_data->expected_transaction || |
| 2989 | auth_transaction > 2))) { |
Jouni Malinen | 0f4126e | 2012-09-30 19:29:38 +0300 | [diff] [blame] | 2990 | sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n", |
| 2991 | mgmt->sa, auth_alg, ifmgd->auth_data->algorithm, |
| 2992 | auth_transaction, |
| 2993 | ifmgd->auth_data->expected_transaction); |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 2994 | goto notify_driver; |
Jouni Malinen | 0f4126e | 2012-09-30 19:29:38 +0300 | [diff] [blame] | 2995 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2996 | |
| 2997 | if (status_code != WLAN_STATUS_SUCCESS) { |
Andrei Otcheretianski | a4055e7 | 2020-03-26 15:09:34 +0200 | [diff] [blame] | 2998 | cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len); |
| 2999 | |
| 3000 | if (auth_alg == WLAN_AUTH_SAE && |
Jouni Malinen | 4e56cde | 2020-07-31 21:38:30 +0300 | [diff] [blame] | 3001 | (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED || |
| 3002 | (auth_transaction == 1 && |
| 3003 | (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT || |
| 3004 | status_code == WLAN_STATUS_SAE_PK)))) |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 3005 | goto notify_driver; |
Andrei Otcheretianski | a4055e7 | 2020-03-26 15:09:34 +0200 | [diff] [blame] | 3006 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3007 | sdata_info(sdata, "%pM denied authentication (status %d)\n", |
| 3008 | mgmt->sa, status_code); |
Eliad Peller | dac211e | 2012-05-13 18:07:04 +0300 | [diff] [blame] | 3009 | ieee80211_destroy_auth_data(sdata, false); |
Emmanuel Grumbach | a940909 | 2015-03-16 23:23:35 +0200 | [diff] [blame] | 3010 | event.u.mlme.status = MLME_DENIED; |
| 3011 | event.u.mlme.reason = status_code; |
| 3012 | drv_event_callback(sdata->local, sdata, &event); |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 3013 | goto notify_driver; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3014 | } |
| 3015 | |
| 3016 | switch (ifmgd->auth_data->algorithm) { |
| 3017 | case WLAN_AUTH_OPEN: |
| 3018 | case WLAN_AUTH_LEAP: |
| 3019 | case WLAN_AUTH_FT: |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 3020 | case WLAN_AUTH_SAE: |
Jouni Malinen | dbc0c2c | 2016-10-27 00:42:04 +0300 | [diff] [blame] | 3021 | case WLAN_AUTH_FILS_SK: |
| 3022 | case WLAN_AUTH_FILS_SK_PFS: |
| 3023 | case WLAN_AUTH_FILS_PK: |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3024 | break; |
| 3025 | case WLAN_AUTH_SHARED_KEY: |
| 3026 | if (ifmgd->auth_data->expected_transaction != 4) { |
| 3027 | ieee80211_auth_challenge(sdata, mgmt, len); |
| 3028 | /* need another frame */ |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3029 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3030 | } |
| 3031 | break; |
| 3032 | default: |
| 3033 | WARN_ONCE(1, "invalid auth alg %d", |
| 3034 | ifmgd->auth_data->algorithm); |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 3035 | goto notify_driver; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3036 | } |
| 3037 | |
Emmanuel Grumbach | a940909 | 2015-03-16 23:23:35 +0200 | [diff] [blame] | 3038 | event.u.mlme.status = MLME_SUCCESS; |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 3039 | info.success = 1; |
Emmanuel Grumbach | a940909 | 2015-03-16 23:23:35 +0200 | [diff] [blame] | 3040 | drv_event_callback(sdata->local, sdata, &event); |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 3041 | if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE || |
| 3042 | (auth_transaction == 2 && |
| 3043 | ifmgd->auth_data->expected_transaction == 2)) { |
| 3044 | if (!ieee80211_mark_sta_auth(sdata, bssid)) |
Andrei Otcheretianski | 0daa63e | 2020-02-21 10:47:20 +0100 | [diff] [blame] | 3045 | return; /* ignore frame -- wait for timeout */ |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 3046 | } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE && |
| 3047 | auth_transaction == 2) { |
| 3048 | sdata_info(sdata, "SAE peer confirmed\n"); |
| 3049 | ifmgd->auth_data->peer_confirmed = true; |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 3050 | } |
| 3051 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 3052 | cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len); |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 3053 | notify_driver: |
| 3054 | drv_mgd_complete_tx(sdata->local, sdata, &info); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3055 | } |
| 3056 | |
Calvin Owens | dfa1ad2 | 2014-02-11 12:36:24 -0600 | [diff] [blame] | 3057 | #define case_WLAN(type) \ |
| 3058 | case WLAN_REASON_##type: return #type |
| 3059 | |
Yu Wang | 79c92ca | 2019-05-10 17:04:52 +0800 | [diff] [blame] | 3060 | const char *ieee80211_get_reason_code_string(u16 reason_code) |
Calvin Owens | dfa1ad2 | 2014-02-11 12:36:24 -0600 | [diff] [blame] | 3061 | { |
| 3062 | switch (reason_code) { |
| 3063 | case_WLAN(UNSPECIFIED); |
| 3064 | case_WLAN(PREV_AUTH_NOT_VALID); |
| 3065 | case_WLAN(DEAUTH_LEAVING); |
| 3066 | case_WLAN(DISASSOC_DUE_TO_INACTIVITY); |
| 3067 | case_WLAN(DISASSOC_AP_BUSY); |
| 3068 | case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA); |
| 3069 | case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA); |
| 3070 | case_WLAN(DISASSOC_STA_HAS_LEFT); |
| 3071 | case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH); |
| 3072 | case_WLAN(DISASSOC_BAD_POWER); |
| 3073 | case_WLAN(DISASSOC_BAD_SUPP_CHAN); |
| 3074 | case_WLAN(INVALID_IE); |
| 3075 | case_WLAN(MIC_FAILURE); |
| 3076 | case_WLAN(4WAY_HANDSHAKE_TIMEOUT); |
| 3077 | case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT); |
| 3078 | case_WLAN(IE_DIFFERENT); |
| 3079 | case_WLAN(INVALID_GROUP_CIPHER); |
| 3080 | case_WLAN(INVALID_PAIRWISE_CIPHER); |
| 3081 | case_WLAN(INVALID_AKMP); |
| 3082 | case_WLAN(UNSUPP_RSN_VERSION); |
| 3083 | case_WLAN(INVALID_RSN_IE_CAP); |
| 3084 | case_WLAN(IEEE8021X_FAILED); |
| 3085 | case_WLAN(CIPHER_SUITE_REJECTED); |
| 3086 | case_WLAN(DISASSOC_UNSPECIFIED_QOS); |
| 3087 | case_WLAN(DISASSOC_QAP_NO_BANDWIDTH); |
| 3088 | case_WLAN(DISASSOC_LOW_ACK); |
| 3089 | case_WLAN(DISASSOC_QAP_EXCEED_TXOP); |
| 3090 | case_WLAN(QSTA_LEAVE_QBSS); |
| 3091 | case_WLAN(QSTA_NOT_USE); |
| 3092 | case_WLAN(QSTA_REQUIRE_SETUP); |
| 3093 | case_WLAN(QSTA_TIMEOUT); |
| 3094 | case_WLAN(QSTA_CIPHER_NOT_SUPP); |
| 3095 | case_WLAN(MESH_PEER_CANCELED); |
| 3096 | case_WLAN(MESH_MAX_PEERS); |
| 3097 | case_WLAN(MESH_CONFIG); |
| 3098 | case_WLAN(MESH_CLOSE); |
| 3099 | case_WLAN(MESH_MAX_RETRIES); |
| 3100 | case_WLAN(MESH_CONFIRM_TIMEOUT); |
| 3101 | case_WLAN(MESH_INVALID_GTK); |
| 3102 | case_WLAN(MESH_INCONSISTENT_PARAM); |
| 3103 | case_WLAN(MESH_INVALID_SECURITY); |
| 3104 | case_WLAN(MESH_PATH_ERROR); |
| 3105 | case_WLAN(MESH_PATH_NOFORWARD); |
| 3106 | case_WLAN(MESH_PATH_DEST_UNREACHABLE); |
| 3107 | case_WLAN(MAC_EXISTS_IN_MBSS); |
| 3108 | case_WLAN(MESH_CHAN_REGULATORY); |
| 3109 | case_WLAN(MESH_CHAN); |
| 3110 | default: return "<unknown>"; |
| 3111 | } |
| 3112 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3113 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3114 | static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata, |
| 3115 | struct ieee80211_mgmt *mgmt, size_t len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3116 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3117 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3118 | u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3119 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3120 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3121 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 3122 | if (len < 24 + 2) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3123 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3124 | |
Yu Wang | 79c92ca | 2019-05-10 17:04:52 +0800 | [diff] [blame] | 3125 | if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) { |
| 3126 | ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code); |
| 3127 | return; |
| 3128 | } |
| 3129 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3130 | if (ifmgd->associated && |
| 3131 | ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) { |
| 3132 | const u8 *bssid = ifmgd->associated->bssid; |
| 3133 | |
| 3134 | sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n", |
| 3135 | bssid, reason_code, |
| 3136 | ieee80211_get_reason_code_string(reason_code)); |
| 3137 | |
| 3138 | ieee80211_set_disassoc(sdata, 0, 0, false, NULL); |
| 3139 | |
| 3140 | ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, |
Johannes Berg | 3f8a39f | 2020-12-06 14:54:43 +0200 | [diff] [blame] | 3141 | reason_code, false); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3142 | return; |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3143 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3144 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3145 | if (ifmgd->assoc_data && |
| 3146 | ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) { |
| 3147 | const u8 *bssid = ifmgd->assoc_data->bss->bssid; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3148 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3149 | sdata_info(sdata, |
| 3150 | "deauthenticated from %pM while associating (Reason: %u=%s)\n", |
| 3151 | bssid, reason_code, |
| 3152 | ieee80211_get_reason_code_string(reason_code)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3153 | |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 3154 | ieee80211_destroy_assoc_data(sdata, false, true); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3155 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3156 | cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len); |
| 3157 | return; |
| 3158 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3159 | } |
| 3160 | |
| 3161 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3162 | static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata, |
| 3163 | struct ieee80211_mgmt *mgmt, size_t len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3164 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3165 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3166 | u16 reason_code; |
| 3167 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3168 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3169 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 3170 | if (len < 24 + 2) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3171 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3172 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3173 | if (!ifmgd->associated || |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 3174 | !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3175 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3176 | |
| 3177 | reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); |
| 3178 | |
Yu Wang | 79c92ca | 2019-05-10 17:04:52 +0800 | [diff] [blame] | 3179 | if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) { |
| 3180 | ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code); |
| 3181 | return; |
| 3182 | } |
| 3183 | |
Arkadiusz Miskiewicz | 68506e9 | 2017-02-15 14:21:27 +0100 | [diff] [blame] | 3184 | sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n", |
| 3185 | mgmt->sa, reason_code, |
| 3186 | ieee80211_get_reason_code_string(reason_code)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3187 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 3188 | ieee80211_set_disassoc(sdata, 0, 0, false, NULL); |
| 3189 | |
Johannes Berg | 3f8a39f | 2020-12-06 14:54:43 +0200 | [diff] [blame] | 3190 | ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code, |
| 3191 | false); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3192 | } |
| 3193 | |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3194 | static void ieee80211_get_rates(struct ieee80211_supported_band *sband, |
| 3195 | u8 *supp_rates, unsigned int supp_rates_len, |
| 3196 | u32 *rates, u32 *basic_rates, |
| 3197 | bool *have_higher_than_11mbit, |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3198 | int *min_rate, int *min_rate_index, |
Johannes Berg | 44f6d42 | 2017-06-10 13:52:44 +0300 | [diff] [blame] | 3199 | int shift) |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3200 | { |
| 3201 | int i, j; |
| 3202 | |
| 3203 | for (i = 0; i < supp_rates_len; i++) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3204 | int rate = supp_rates[i] & 0x7f; |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3205 | bool is_basic = !!(supp_rates[i] & 0x80); |
| 3206 | |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3207 | if ((rate * 5 * (1 << shift)) > 110) |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3208 | *have_higher_than_11mbit = true; |
| 3209 | |
| 3210 | /* |
Ilan Peer | 3598ae8 | 2020-11-29 17:30:47 +0200 | [diff] [blame] | 3211 | * Skip HT, VHT, HE and SAE H2E only BSS membership selectors |
| 3212 | * since they're not rates. |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3213 | * |
Johannes Berg | a6289d3 | 2017-03-06 22:59:04 +0100 | [diff] [blame] | 3214 | * Note: Even though the membership selector and the basic |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3215 | * rate flag share the same bit, they are not exactly |
| 3216 | * the same. |
| 3217 | */ |
Johannes Berg | a6289d3 | 2017-03-06 22:59:04 +0100 | [diff] [blame] | 3218 | if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) || |
Ilan Peer | 4826e72 | 2020-03-26 15:09:36 +0200 | [diff] [blame] | 3219 | supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY) || |
Ilan Peer | 3598ae8 | 2020-11-29 17:30:47 +0200 | [diff] [blame] | 3220 | supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY) || |
| 3221 | supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E)) |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3222 | continue; |
| 3223 | |
| 3224 | for (j = 0; j < sband->n_bitrates; j++) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3225 | struct ieee80211_rate *br; |
| 3226 | int brate; |
| 3227 | |
| 3228 | br = &sband->bitrates[j]; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3229 | |
| 3230 | brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5); |
| 3231 | if (brate == rate) { |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3232 | *rates |= BIT(j); |
| 3233 | if (is_basic) |
| 3234 | *basic_rates |= BIT(j); |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3235 | if ((rate * 5) < *min_rate) { |
| 3236 | *min_rate = rate * 5; |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3237 | *min_rate_index = j; |
| 3238 | } |
| 3239 | break; |
| 3240 | } |
| 3241 | } |
| 3242 | } |
| 3243 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3244 | |
Emmanuel Grumbach | 55ebd6e | 2018-12-15 11:03:04 +0200 | [diff] [blame] | 3245 | static bool ieee80211_twt_req_supported(const struct sta_info *sta, |
| 3246 | const struct ieee802_11_elems *elems) |
| 3247 | { |
| 3248 | if (elems->ext_capab_len < 10) |
| 3249 | return false; |
| 3250 | |
| 3251 | if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT)) |
| 3252 | return false; |
| 3253 | |
| 3254 | return sta->sta.he_cap.he_cap_elem.mac_cap_info[0] & |
| 3255 | IEEE80211_HE_MAC_CAP0_TWT_RES; |
| 3256 | } |
| 3257 | |
John Crispin | c9d3245 | 2019-05-28 13:49:47 +0200 | [diff] [blame] | 3258 | static int ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata, |
| 3259 | struct sta_info *sta, |
| 3260 | struct ieee802_11_elems *elems) |
| 3261 | { |
| 3262 | bool twt = ieee80211_twt_req_supported(sta, elems); |
| 3263 | |
| 3264 | if (sdata->vif.bss_conf.twt_requester != twt) { |
| 3265 | sdata->vif.bss_conf.twt_requester = twt; |
| 3266 | return BSS_CHANGED_TWT; |
| 3267 | } |
| 3268 | return 0; |
| 3269 | } |
| 3270 | |
Johannes Berg | bac2fd3 | 2021-06-18 13:41:50 +0300 | [diff] [blame] | 3271 | static bool ieee80211_twt_bcast_support(struct ieee80211_sub_if_data *sdata, |
| 3272 | struct ieee80211_bss_conf *bss_conf, |
Shaul Triebitz | d8b2615 | 2021-06-18 13:41:35 +0300 | [diff] [blame] | 3273 | struct ieee80211_supported_band *sband, |
| 3274 | struct sta_info *sta) |
| 3275 | { |
| 3276 | const struct ieee80211_sta_he_cap *own_he_cap = |
Johannes Berg | bac2fd3 | 2021-06-18 13:41:50 +0300 | [diff] [blame] | 3277 | ieee80211_get_he_iftype_cap(sband, |
| 3278 | ieee80211_vif_type_p2p(&sdata->vif)); |
Shaul Triebitz | d8b2615 | 2021-06-18 13:41:35 +0300 | [diff] [blame] | 3279 | |
| 3280 | return bss_conf->he_support && |
| 3281 | (sta->sta.he_cap.he_cap_elem.mac_cap_info[2] & |
| 3282 | IEEE80211_HE_MAC_CAP2_BCAST_TWT) && |
| 3283 | own_he_cap && |
| 3284 | (own_he_cap->he_cap_elem.mac_cap_info[2] & |
| 3285 | IEEE80211_HE_MAC_CAP2_BCAST_TWT); |
| 3286 | } |
| 3287 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3288 | static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata, |
| 3289 | struct cfg80211_bss *cbss, |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3290 | struct ieee80211_mgmt *mgmt, size_t len, |
| 3291 | struct ieee802_11_elems *elems) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3292 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3293 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 3294 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3295 | struct ieee80211_supported_band *sband; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3296 | struct sta_info *sta; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3297 | u16 capab_info, aid; |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 3298 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3299 | const struct cfg80211_bss_ies *bss_ies = NULL; |
| 3300 | struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 3301 | bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ; |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 3302 | bool is_s1g = cbss->channel->band == NL80211_BAND_S1GHZ; |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 3303 | u32 changed = 0; |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 3304 | u8 *pos; |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3305 | int err; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3306 | bool ret; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3307 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3308 | /* AssocResp and ReassocResp have identical structure */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3309 | |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 3310 | pos = mgmt->u.assoc_resp.variable; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3311 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 3312 | if (is_s1g) { |
| 3313 | pos = (u8 *) mgmt->u.s1g_assoc_resp.variable; |
| 3314 | aid = 0; /* TODO */ |
| 3315 | } |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3316 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 3317 | elems = ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, |
| 3318 | mgmt->bssid, assoc_data->bss->bssid); |
| 3319 | |
| 3320 | if (!elems) |
| 3321 | return false; |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 3322 | |
| 3323 | if (elems->aid_resp) |
| 3324 | aid = le16_to_cpu(elems->aid_resp->aid); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3325 | |
Johannes Berg | c7c477b | 2017-12-01 13:50:51 +0200 | [diff] [blame] | 3326 | /* |
| 3327 | * The 5 MSB of the AID field are reserved |
| 3328 | * (802.11-2016 9.4.1.8 AID field) |
| 3329 | */ |
| 3330 | aid &= 0x7ff; |
Johannes Berg | 1dd84aa | 2007-10-10 12:03:41 +0200 | [diff] [blame] | 3331 | |
Johannes Berg | 05cb910 | 2011-10-28 11:59:47 +0200 | [diff] [blame] | 3332 | ifmgd->broken_ap = false; |
| 3333 | |
| 3334 | if (aid == 0 || aid > IEEE80211_MAX_AID) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3335 | sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n", |
| 3336 | aid); |
Johannes Berg | 05cb910 | 2011-10-28 11:59:47 +0200 | [diff] [blame] | 3337 | aid = 0; |
| 3338 | ifmgd->broken_ap = true; |
| 3339 | } |
| 3340 | |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 3341 | if (!is_s1g && !elems->supp_rates) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3342 | sdata_info(sdata, "no SuppRates element in AssocResp\n"); |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 3343 | ret = false; |
| 3344 | goto out; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3345 | } |
| 3346 | |
Johannes Berg | 1db364c | 2020-04-17 12:38:04 +0200 | [diff] [blame] | 3347 | sdata->vif.bss_conf.aid = aid; |
Arik Nemtsov | 9041c1f | 2014-11-09 18:50:15 +0200 | [diff] [blame] | 3348 | ifmgd->tdls_chan_switch_prohibited = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3349 | elems->ext_capab && elems->ext_capab_len >= 5 && |
| 3350 | (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3351 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3352 | /* |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3353 | * Some APs are erroneously not including some information in their |
| 3354 | * (re)association response frames. Try to recover by using the data |
| 3355 | * from the beacon or probe response. This seems to afflict mobile |
| 3356 | * 2G/3G/4G wifi routers, reported models include the "Onda PN51T", |
| 3357 | * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device. |
| 3358 | */ |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 3359 | if (!is_6ghz && |
| 3360 | ((assoc_data->wmm && !elems->wmm_param) || |
| 3361 | (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) && |
| 3362 | (!elems->ht_cap_elem || !elems->ht_operation)) || |
| 3363 | (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && |
| 3364 | (!elems->vht_cap_elem || !elems->vht_operation)))) { |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3365 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 3366 | struct ieee802_11_elems *bss_elems; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3367 | |
| 3368 | rcu_read_lock(); |
| 3369 | ies = rcu_dereference(cbss->ies); |
| 3370 | if (ies) |
| 3371 | bss_ies = kmemdup(ies, sizeof(*ies) + ies->len, |
| 3372 | GFP_ATOMIC); |
| 3373 | rcu_read_unlock(); |
Johannes Berg | 8223ac1 | 2021-10-01 21:11:08 +0200 | [diff] [blame] | 3374 | if (!bss_ies) { |
| 3375 | ret = false; |
| 3376 | goto out; |
| 3377 | } |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3378 | |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 3379 | bss_elems = ieee802_11_parse_elems(bss_ies->data, bss_ies->len, |
| 3380 | false, mgmt->bssid, |
| 3381 | assoc_data->bss->bssid); |
| 3382 | if (!bss_elems) { |
| 3383 | ret = false; |
| 3384 | goto out; |
| 3385 | } |
| 3386 | |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3387 | if (assoc_data->wmm && |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 3388 | !elems->wmm_param && bss_elems->wmm_param) { |
| 3389 | elems->wmm_param = bss_elems->wmm_param; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3390 | sdata_info(sdata, |
| 3391 | "AP bug: WMM param missing from AssocResp\n"); |
| 3392 | } |
| 3393 | |
| 3394 | /* |
| 3395 | * Also check if we requested HT/VHT, otherwise the AP doesn't |
| 3396 | * have to include the IEs in the (re)association response. |
| 3397 | */ |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 3398 | if (!elems->ht_cap_elem && bss_elems->ht_cap_elem && |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3399 | !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) { |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 3400 | elems->ht_cap_elem = bss_elems->ht_cap_elem; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3401 | sdata_info(sdata, |
| 3402 | "AP bug: HT capability missing from AssocResp\n"); |
| 3403 | } |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 3404 | if (!elems->ht_operation && bss_elems->ht_operation && |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3405 | !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) { |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 3406 | elems->ht_operation = bss_elems->ht_operation; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3407 | sdata_info(sdata, |
| 3408 | "AP bug: HT operation missing from AssocResp\n"); |
| 3409 | } |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 3410 | if (!elems->vht_cap_elem && bss_elems->vht_cap_elem && |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3411 | !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) { |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 3412 | elems->vht_cap_elem = bss_elems->vht_cap_elem; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3413 | sdata_info(sdata, |
| 3414 | "AP bug: VHT capa missing from AssocResp\n"); |
| 3415 | } |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 3416 | if (!elems->vht_operation && bss_elems->vht_operation && |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3417 | !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) { |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 3418 | elems->vht_operation = bss_elems->vht_operation; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3419 | sdata_info(sdata, |
| 3420 | "AP bug: VHT operation missing from AssocResp\n"); |
| 3421 | } |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 3422 | |
| 3423 | kfree(bss_elems); |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3424 | } |
| 3425 | |
| 3426 | /* |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3427 | * We previously checked these in the beacon/probe response, so |
| 3428 | * they should be present here. This is just a safety net. |
| 3429 | */ |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 3430 | if (!is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT) && |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3431 | (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) { |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3432 | sdata_info(sdata, |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3433 | "HT AP is missing WMM params or HT capability/operation\n"); |
| 3434 | ret = false; |
| 3435 | goto out; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3436 | } |
| 3437 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 3438 | if (!is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3439 | (!elems->vht_cap_elem || !elems->vht_operation)) { |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3440 | sdata_info(sdata, |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3441 | "VHT AP is missing VHT capability/operation\n"); |
| 3442 | ret = false; |
| 3443 | goto out; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3444 | } |
| 3445 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 3446 | if (is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && |
| 3447 | !elems->he_6ghz_capa) { |
| 3448 | sdata_info(sdata, |
| 3449 | "HE 6 GHz AP is missing HE 6 GHz band capability\n"); |
| 3450 | ret = false; |
| 3451 | goto out; |
| 3452 | } |
| 3453 | |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 3454 | mutex_lock(&sdata->local->sta_mtx); |
| 3455 | /* |
| 3456 | * station info was already allocated and inserted before |
| 3457 | * the association and should be available to us |
| 3458 | */ |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 3459 | sta = sta_info_get(sdata, cbss->bssid); |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 3460 | if (WARN_ON(!sta)) { |
| 3461 | mutex_unlock(&sdata->local->sta_mtx); |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3462 | ret = false; |
| 3463 | goto out; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3464 | } |
| 3465 | |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 3466 | sband = ieee80211_get_sband(sdata); |
| 3467 | if (!sband) { |
| 3468 | mutex_unlock(&sdata->local->sta_mtx); |
| 3469 | ret = false; |
| 3470 | goto out; |
| 3471 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3472 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3473 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3474 | (!elems->he_cap || !elems->he_operation)) { |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3475 | mutex_unlock(&sdata->local->sta_mtx); |
| 3476 | sdata_info(sdata, |
| 3477 | "HE AP is missing HE capability/operation\n"); |
| 3478 | ret = false; |
| 3479 | goto out; |
| 3480 | } |
| 3481 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3482 | /* Set up internal HT/VHT capabilities */ |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3483 | if (elems->ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 3484 | ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband, |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3485 | elems->ht_cap_elem, sta); |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 3486 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3487 | if (elems->vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
Mahesh Palivela | 818255e | 2012-10-10 11:33:04 +0000 | [diff] [blame] | 3488 | ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband, |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3489 | elems->vht_cap_elem, sta); |
Mahesh Palivela | 818255e | 2012-10-10 11:33:04 +0000 | [diff] [blame] | 3490 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3491 | if (elems->he_operation && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && |
| 3492 | elems->he_cap) { |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3493 | ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband, |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3494 | elems->he_cap, |
| 3495 | elems->he_cap_len, |
Johannes Berg | 1bb9a8a | 2020-05-28 21:34:38 +0200 | [diff] [blame] | 3496 | elems->he_6ghz_capa, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3497 | sta); |
| 3498 | |
| 3499 | bss_conf->he_support = sta->sta.he_cap.has_he; |
Shaul Triebitz | d46b4ab8 | 2020-03-26 15:09:33 +0200 | [diff] [blame] | 3500 | if (elems->rsnx && elems->rsnx_len && |
| 3501 | (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) && |
| 3502 | wiphy_ext_feature_isset(local->hw.wiphy, |
| 3503 | NL80211_EXT_FEATURE_PROTECTED_TWT)) |
| 3504 | bss_conf->twt_protected = true; |
| 3505 | else |
| 3506 | bss_conf->twt_protected = false; |
| 3507 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3508 | changed |= ieee80211_recalc_twt_req(sdata, sta, elems); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3509 | } else { |
| 3510 | bss_conf->he_support = false; |
Emmanuel Grumbach | 55ebd6e | 2018-12-15 11:03:04 +0200 | [diff] [blame] | 3511 | bss_conf->twt_requester = false; |
Shaul Triebitz | d46b4ab8 | 2020-03-26 15:09:33 +0200 | [diff] [blame] | 3512 | bss_conf->twt_protected = false; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3513 | } |
| 3514 | |
Shaul Triebitz | d8b2615 | 2021-06-18 13:41:35 +0300 | [diff] [blame] | 3515 | bss_conf->twt_broadcast = |
Johannes Berg | bac2fd3 | 2021-06-18 13:41:50 +0300 | [diff] [blame] | 3516 | ieee80211_twt_bcast_support(sdata, bss_conf, sband, sta); |
Shaul Triebitz | d8b2615 | 2021-06-18 13:41:35 +0300 | [diff] [blame] | 3517 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3518 | if (bss_conf->he_support) { |
John Crispin | dd56e90 | 2019-12-17 15:19:19 +0100 | [diff] [blame] | 3519 | bss_conf->he_bss_color.color = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3520 | le32_get_bits(elems->he_operation->he_oper_params, |
Naftali Goldstein | 77cbbc3 | 2018-09-05 08:06:07 +0300 | [diff] [blame] | 3521 | IEEE80211_HE_OPERATION_BSS_COLOR_MASK); |
John Crispin | dd56e90 | 2019-12-17 15:19:19 +0100 | [diff] [blame] | 3522 | bss_conf->he_bss_color.partial = |
| 3523 | le32_get_bits(elems->he_operation->he_oper_params, |
| 3524 | IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR); |
Johannes Berg | 75e6b59 | 2020-07-30 13:00:52 +0200 | [diff] [blame] | 3525 | bss_conf->he_bss_color.enabled = |
| 3526 | !le32_get_bits(elems->he_operation->he_oper_params, |
| 3527 | IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED); |
P Praneesh | 322cd27 | 2020-07-09 08:16:21 +0530 | [diff] [blame] | 3528 | |
Johannes Berg | 75e6b59 | 2020-07-30 13:00:52 +0200 | [diff] [blame] | 3529 | if (bss_conf->he_bss_color.enabled) |
P Praneesh | 322cd27 | 2020-07-09 08:16:21 +0530 | [diff] [blame] | 3530 | changed |= BSS_CHANGED_HE_BSS_COLOR; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3531 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3532 | bss_conf->htc_trig_based_pkt_ext = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3533 | le32_get_bits(elems->he_operation->he_oper_params, |
Naftali Goldstein | 77cbbc3 | 2018-09-05 08:06:07 +0300 | [diff] [blame] | 3534 | IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3535 | bss_conf->frame_time_rts_th = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3536 | le32_get_bits(elems->he_operation->he_oper_params, |
Naftali Goldstein | 77cbbc3 | 2018-09-05 08:06:07 +0300 | [diff] [blame] | 3537 | IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3538 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3539 | bss_conf->uora_exists = !!elems->uora_element; |
| 3540 | if (elems->uora_element) |
| 3541 | bss_conf->uora_ocw_range = elems->uora_element[0]; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3542 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3543 | ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation); |
| 3544 | ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3545 | /* TODO: OPEN: what happens if BSS color disable is set? */ |
| 3546 | } |
| 3547 | |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3548 | if (cbss->transmitted_bss) { |
| 3549 | bss_conf->nontransmitted = true; |
| 3550 | ether_addr_copy(bss_conf->transmitter_bssid, |
| 3551 | cbss->transmitted_bss->bssid); |
| 3552 | bss_conf->bssid_indicator = cbss->max_bssid_indicator; |
| 3553 | bss_conf->bssid_index = cbss->bssid_index; |
| 3554 | } |
| 3555 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3556 | /* |
| 3557 | * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data |
| 3558 | * in their association response, so ignore that data for our own |
| 3559 | * configuration. If it changed since the last beacon, we'll get the |
| 3560 | * next beacon and update then. |
| 3561 | */ |
Johannes Berg | 1128958 | 2013-02-07 17:36:12 +0100 | [diff] [blame] | 3562 | |
Johannes Berg | bee7f586 | 2013-02-07 22:24:55 +0100 | [diff] [blame] | 3563 | /* |
| 3564 | * If an operating mode notification IE is present, override the |
| 3565 | * NSS calculation (that would be done in rate_control_rate_init()) |
| 3566 | * and use the # of streams from that element. |
| 3567 | */ |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3568 | if (elems->opmode_notif && |
| 3569 | !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) { |
Johannes Berg | bee7f586 | 2013-02-07 22:24:55 +0100 | [diff] [blame] | 3570 | u8 nss; |
| 3571 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3572 | nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK; |
Johannes Berg | bee7f586 | 2013-02-07 22:24:55 +0100 | [diff] [blame] | 3573 | nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT; |
| 3574 | nss += 1; |
| 3575 | sta->sta.rx_nss = nss; |
| 3576 | } |
| 3577 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 3578 | rate_control_rate_init(sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3579 | |
Tamizh chelvam | 93f0490 | 2015-10-07 10:40:04 +0530 | [diff] [blame] | 3580 | if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) { |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 3581 | set_sta_flag(sta, WLAN_STA_MFP); |
Tamizh chelvam | 93f0490 | 2015-10-07 10:40:04 +0530 | [diff] [blame] | 3582 | sta->sta.mfp = true; |
| 3583 | } else { |
| 3584 | sta->sta.mfp = false; |
| 3585 | } |
Jouni Malinen | 5394af4 | 2009-01-08 13:31:59 +0200 | [diff] [blame] | 3586 | |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 3587 | sta->sta.wme = (elems->wmm_param || elems->s1g_capab) && |
| 3588 | local->hw.queues >= IEEE80211_NUM_ACS; |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 3589 | |
Johannes Berg | 3e4d40f | 2013-02-07 17:19:08 +0100 | [diff] [blame] | 3590 | err = sta_info_move_state(sta, IEEE80211_STA_ASSOC); |
Johannes Berg | c898787 | 2012-01-20 13:55:17 +0100 | [diff] [blame] | 3591 | if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT)) |
| 3592 | err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED); |
| 3593 | if (err) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3594 | sdata_info(sdata, |
| 3595 | "failed to move station %pM to desired state\n", |
| 3596 | sta->sta.addr); |
Johannes Berg | c898787 | 2012-01-20 13:55:17 +0100 | [diff] [blame] | 3597 | WARN_ON(__sta_info_destroy(sta)); |
| 3598 | mutex_unlock(&sdata->local->sta_mtx); |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3599 | ret = false; |
| 3600 | goto out; |
Johannes Berg | c898787 | 2012-01-20 13:55:17 +0100 | [diff] [blame] | 3601 | } |
| 3602 | |
Felix Fietkau | 1ff4e8f | 2020-09-08 14:37:01 +0200 | [diff] [blame] | 3603 | if (sdata->wdev.use_4addr) |
| 3604 | drv_sta_set_4addr(local, sdata, &sta->sta, true); |
| 3605 | |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 3606 | mutex_unlock(&sdata->local->sta_mtx); |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 3607 | |
Juuso Oikarinen | f2176d7 | 2010-09-28 14:39:32 +0300 | [diff] [blame] | 3608 | /* |
| 3609 | * Always handle WMM once after association regardless |
| 3610 | * of the first value the AP uses. Setting -1 here has |
| 3611 | * that effect because the AP values is an unsigned |
| 3612 | * 4-bit value. |
| 3613 | */ |
| 3614 | ifmgd->wmm_last_param_set = -1; |
Shaul Triebitz | 2e249fc | 2018-12-15 11:03:15 +0200 | [diff] [blame] | 3615 | ifmgd->mu_edca_last_param_set = -1; |
Juuso Oikarinen | f2176d7 | 2010-09-28 14:39:32 +0300 | [diff] [blame] | 3616 | |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 3617 | if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) { |
Johannes Berg | cec6628 | 2015-10-22 17:46:04 +0200 | [diff] [blame] | 3618 | ieee80211_set_wmm_default(sdata, false, false); |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3619 | } else if (!ieee80211_sta_wmm_params(local, sdata, elems->wmm_param, |
| 3620 | elems->wmm_param_len, |
| 3621 | elems->mu_edca_param_set)) { |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 3622 | /* still enable QoS since we might have HT/VHT */ |
| 3623 | ieee80211_set_wmm_default(sdata, false, true); |
| 3624 | /* set the disable-WMM flag in this case to disable |
| 3625 | * tracking WMM parameter changes in the beacon if |
| 3626 | * the parameters weren't actually valid. Doing so |
| 3627 | * avoids changing parameters very strangely when |
| 3628 | * the AP is going back and forth between valid and |
| 3629 | * invalid parameters. |
| 3630 | */ |
| 3631 | ifmgd->flags |= IEEE80211_STA_DISABLE_WMM; |
| 3632 | } |
Johannes Berg | 3abead5 | 2012-03-02 15:56:59 +0100 | [diff] [blame] | 3633 | changed |= BSS_CHANGED_QOS; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3634 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3635 | if (elems->max_idle_period_ie) { |
Avraham Stern | e38a017 | 2017-04-26 10:58:47 +0300 | [diff] [blame] | 3636 | bss_conf->max_idle_period = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3637 | le16_to_cpu(elems->max_idle_period_ie->max_idle_period); |
Avraham Stern | e38a017 | 2017-04-26 10:58:47 +0300 | [diff] [blame] | 3638 | bss_conf->protected_keep_alive = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3639 | !!(elems->max_idle_period_ie->idle_options & |
Avraham Stern | e38a017 | 2017-04-26 10:58:47 +0300 | [diff] [blame] | 3640 | WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE); |
| 3641 | changed |= BSS_CHANGED_KEEP_ALIVE; |
| 3642 | } else { |
| 3643 | bss_conf->max_idle_period = 0; |
| 3644 | bss_conf->protected_keep_alive = false; |
| 3645 | } |
| 3646 | |
Johannes Berg | 1db364c | 2020-04-17 12:38:04 +0200 | [diff] [blame] | 3647 | /* set assoc capability (AID was already set earlier), |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 3648 | * ieee80211_set_associated() will tell the driver */ |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 3649 | bss_conf->assoc_capability = capab_info; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 3650 | ieee80211_set_associated(sdata, cbss, changed); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3651 | |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 3652 | /* |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 3653 | * If we're using 4-addr mode, let the AP know that we're |
| 3654 | * doing so, so that it can create the STA VLAN on its side |
| 3655 | */ |
| 3656 | if (ifmgd->use_4addr) |
| 3657 | ieee80211_send_4addr_nullfunc(local, sdata); |
| 3658 | |
| 3659 | /* |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3660 | * Start timer to probe the connection to the AP now. |
| 3661 | * Also start the timer that will detect beacon loss. |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 3662 | */ |
Luis R. Rodriguez | d3a910a | 2010-09-16 15:12:32 -0400 | [diff] [blame] | 3663 | ieee80211_sta_reset_beacon_monitor(sdata); |
Felix Fietkau | 9abf4e4 | 2020-09-08 14:36:56 +0200 | [diff] [blame] | 3664 | ieee80211_sta_reset_conn_monitor(sdata); |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 3665 | |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3666 | ret = true; |
| 3667 | out: |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 3668 | kfree(elems); |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3669 | kfree(bss_ies); |
| 3670 | return ret; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3671 | } |
| 3672 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3673 | static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata, |
| 3674 | struct ieee80211_mgmt *mgmt, |
| 3675 | size_t len) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3676 | { |
| 3677 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3678 | struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; |
| 3679 | u16 capab_info, status_code, aid; |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 3680 | struct ieee802_11_elems *elems; |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 3681 | int ac, uapsd_queues = -1; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3682 | u8 *pos; |
| 3683 | bool reassoc; |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 3684 | struct cfg80211_bss *cbss; |
Emmanuel Grumbach | d0d1a12 | 2015-03-16 23:23:36 +0200 | [diff] [blame] | 3685 | struct ieee80211_event event = { |
| 3686 | .type = MLME_EVENT, |
| 3687 | .u.mlme.data = ASSOC_EVENT, |
| 3688 | }; |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 3689 | struct ieee80211_prep_tx_info info = {}; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3690 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3691 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3692 | |
| 3693 | if (!assoc_data) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3694 | return; |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 3695 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 3696 | if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid)) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3697 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3698 | |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 3699 | cbss = assoc_data->bss; |
| 3700 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3701 | /* |
| 3702 | * AssocResp and ReassocResp have identical structure, so process both |
| 3703 | * of them in this function. |
| 3704 | */ |
| 3705 | |
| 3706 | if (len < 24 + 6) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3707 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3708 | |
Simon Dinkin | 7a7d3e4 | 2017-08-31 13:09:36 +0300 | [diff] [blame] | 3709 | reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3710 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); |
| 3711 | status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 3712 | pos = mgmt->u.assoc_resp.variable; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3713 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 3714 | if (cbss->channel->band == NL80211_BAND_S1GHZ) { |
| 3715 | pos = (u8 *) mgmt->u.s1g_assoc_resp.variable; |
| 3716 | aid = 0; /* TODO */ |
| 3717 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3718 | |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 3719 | /* |
| 3720 | * Note: this may not be perfect, AP might misbehave - if |
| 3721 | * anyone needs to rely on perfect complete notification |
| 3722 | * with the exact right subtype, then we need to track what |
| 3723 | * we actually transmitted. |
| 3724 | */ |
| 3725 | info.subtype = reassoc ? IEEE80211_STYPE_REASSOC_REQ : |
| 3726 | IEEE80211_STYPE_ASSOC_REQ; |
| 3727 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3728 | sdata_info(sdata, |
| 3729 | "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n", |
| 3730 | reassoc ? "Rea" : "A", mgmt->sa, |
| 3731 | capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14)))); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3732 | |
Jouni Malinen | 39404fe | 2016-10-27 00:42:05 +0300 | [diff] [blame] | 3733 | if (assoc_data->fils_kek_len && |
| 3734 | fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0) |
| 3735 | return; |
| 3736 | |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 3737 | elems = ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, |
| 3738 | mgmt->bssid, assoc_data->bss->bssid); |
| 3739 | if (!elems) |
| 3740 | goto notify_driver; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3741 | |
| 3742 | if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY && |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 3743 | elems->timeout_int && |
| 3744 | elems->timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3745 | u32 tu, ms; |
Ilan Peer | 852a07c | 2021-11-29 15:32:35 +0200 | [diff] [blame] | 3746 | |
| 3747 | cfg80211_assoc_comeback(sdata->dev, assoc_data->bss, |
| 3748 | le32_to_cpu(elems->timeout_int->value)); |
| 3749 | |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 3750 | tu = le32_to_cpu(elems->timeout_int->value); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3751 | ms = tu * 1024 / 1000; |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3752 | sdata_info(sdata, |
| 3753 | "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n", |
| 3754 | mgmt->sa, tu, ms); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3755 | assoc_data->timeout = jiffies + msecs_to_jiffies(ms); |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 3756 | assoc_data->timeout_started = true; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3757 | if (ms > IEEE80211_ASSOC_TIMEOUT) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3758 | run_again(sdata, assoc_data->timeout); |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 3759 | goto notify_driver; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3760 | } |
| 3761 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3762 | if (status_code != WLAN_STATUS_SUCCESS) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3763 | sdata_info(sdata, "%pM denied association (code=%d)\n", |
| 3764 | mgmt->sa, status_code); |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 3765 | ieee80211_destroy_assoc_data(sdata, false, false); |
Emmanuel Grumbach | d0d1a12 | 2015-03-16 23:23:36 +0200 | [diff] [blame] | 3766 | event.u.mlme.status = MLME_DENIED; |
| 3767 | event.u.mlme.reason = status_code; |
| 3768 | drv_event_callback(sdata->local, sdata, &event); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3769 | } else { |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 3770 | if (!ieee80211_assoc_success(sdata, cbss, mgmt, len, elems)) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3771 | /* oops -- internal error -- send timeout for now */ |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 3772 | ieee80211_destroy_assoc_data(sdata, false, false); |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 3773 | cfg80211_assoc_timeout(sdata->dev, cbss); |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 3774 | goto notify_driver; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3775 | } |
Emmanuel Grumbach | d0d1a12 | 2015-03-16 23:23:36 +0200 | [diff] [blame] | 3776 | event.u.mlme.status = MLME_SUCCESS; |
| 3777 | drv_event_callback(sdata->local, sdata, &event); |
John W. Linville | 635d999 | 2012-07-09 16:34:34 -0400 | [diff] [blame] | 3778 | sdata_info(sdata, "associated\n"); |
Johannes Berg | 79ebfb8 | 2012-02-20 14:19:58 +0100 | [diff] [blame] | 3779 | |
| 3780 | /* |
| 3781 | * destroy assoc_data afterwards, as otherwise an idle |
| 3782 | * recalc after assoc_data is NULL but before associated |
| 3783 | * is set can cause the interface to go idle |
| 3784 | */ |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 3785 | ieee80211_destroy_assoc_data(sdata, true, false); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 3786 | |
| 3787 | /* get uapsd queues configuration */ |
| 3788 | uapsd_queues = 0; |
| 3789 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) |
| 3790 | if (sdata->tx_conf[ac].uapsd) |
Emmanuel Grumbach | f438ceb | 2016-10-18 23:12:12 +0300 | [diff] [blame] | 3791 | uapsd_queues |= ieee80211_ac_to_qos_mask[ac]; |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 3792 | |
| 3793 | info.success = 1; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3794 | } |
| 3795 | |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 3796 | cfg80211_rx_assoc_resp(sdata->dev, cbss, (u8 *)mgmt, len, uapsd_queues, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 3797 | ifmgd->assoc_req_ies, ifmgd->assoc_req_ies_len); |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 3798 | notify_driver: |
| 3799 | drv_mgd_complete_tx(sdata->local, sdata, &info); |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 3800 | kfree(elems); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3801 | } |
Johannes Berg | 8e3c1b7 | 2012-12-10 13:44:19 +0100 | [diff] [blame] | 3802 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3803 | static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 8e3c1b7 | 2012-12-10 13:44:19 +0100 | [diff] [blame] | 3804 | struct ieee80211_mgmt *mgmt, size_t len, |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3805 | struct ieee80211_rx_status *rx_status) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3806 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3807 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 3808 | struct ieee80211_bss *bss; |
Johannes Berg | fab7d4a | 2008-03-16 18:42:44 +0100 | [diff] [blame] | 3809 | struct ieee80211_channel *channel; |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 3810 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3811 | sdata_assert_lock(sdata); |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 3812 | |
Thomas Pedersen | 3b23c184 | 2020-04-01 18:18:05 -0700 | [diff] [blame] | 3813 | channel = ieee80211_get_channel_khz(local->hw.wiphy, |
| 3814 | ieee80211_rx_status_to_khz(rx_status)); |
Emmanuel Grumbach | 3afc216 | 2014-03-04 16:50:13 +0200 | [diff] [blame] | 3815 | if (!channel) |
Johannes Berg | 5bda617 | 2008-09-08 11:05:10 +0200 | [diff] [blame] | 3816 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3817 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3818 | bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel); |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 3819 | if (bss) { |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 3820 | sdata->vif.bss_conf.beacon_rate = bss->beacon_rate; |
Johannes Berg | d2722f8 | 2014-03-04 11:43:28 +0100 | [diff] [blame] | 3821 | ieee80211_rx_bss_put(local, bss); |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 3822 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3823 | } |
| 3824 | |
| 3825 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3826 | 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] | 3827 | struct sk_buff *skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3828 | { |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3829 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 3830 | struct ieee80211_if_managed *ifmgd; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3831 | struct ieee80211_rx_status *rx_status = (void *) skb->cb; |
Andrei Otcheretianski | 85b27ef | 2020-01-31 13:12:50 +0200 | [diff] [blame] | 3832 | struct ieee80211_channel *channel; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3833 | size_t baselen, len = skb->len; |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 3834 | |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 3835 | ifmgd = &sdata->u.mgd; |
| 3836 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3837 | sdata_assert_lock(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3838 | |
Andrei Otcheretianski | 85b27ef | 2020-01-31 13:12:50 +0200 | [diff] [blame] | 3839 | /* |
| 3840 | * According to Draft P802.11ax D6.0 clause 26.17.2.3.2: |
| 3841 | * "If a 6 GHz AP receives a Probe Request frame and responds with |
| 3842 | * a Probe Response frame [..], the Address 1 field of the Probe |
| 3843 | * Response frame shall be set to the broadcast address [..]" |
| 3844 | * So, on 6GHz band we should also accept broadcast responses. |
| 3845 | */ |
| 3846 | channel = ieee80211_get_channel(sdata->local->hw.wiphy, |
| 3847 | rx_status->freq); |
| 3848 | if (!channel) |
| 3849 | return; |
| 3850 | |
| 3851 | if (!ether_addr_equal(mgmt->da, sdata->vif.addr) && |
| 3852 | (channel->band != NL80211_BAND_6GHZ || |
| 3853 | !is_broadcast_ether_addr(mgmt->da))) |
Tomas Winkler | 8e7cdbb | 2008-08-03 14:32:01 +0300 | [diff] [blame] | 3854 | return; /* ignore ProbeResp to foreign address */ |
| 3855 | |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 3856 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; |
| 3857 | if (baselen > len) |
| 3858 | return; |
| 3859 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3860 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status); |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 3861 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3862 | if (ifmgd->associated && |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 3863 | ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 3864 | ieee80211_reset_ap_probe(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3865 | } |
| 3866 | |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 3867 | /* |
| 3868 | * This is the canonical list of information elements we care about, |
| 3869 | * 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] | 3870 | * (00:50:F2) vendor IE which is used for WMM which we need to track, |
| 3871 | * as well as the DTPC IE (part of the Cisco OUI) used for signaling |
| 3872 | * changes to requested client power. |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 3873 | * |
| 3874 | * We implement beacon filtering in software since that means we can |
| 3875 | * avoid processing the frame here and in cfg80211, and userspace |
| 3876 | * will not be able to tell whether the hardware supports it or not. |
| 3877 | * |
| 3878 | * XXX: This list needs to be dynamic -- userspace needs to be able to |
| 3879 | * add items it requires. It also needs to be able to tell us to |
| 3880 | * look out for other vendor IEs. |
| 3881 | */ |
| 3882 | static const u64 care_about_ies = |
Johannes Berg | 1d4df3a | 2009-04-22 11:25:43 +0200 | [diff] [blame] | 3883 | (1ULL << WLAN_EID_COUNTRY) | |
| 3884 | (1ULL << WLAN_EID_ERP_INFO) | |
| 3885 | (1ULL << WLAN_EID_CHANNEL_SWITCH) | |
| 3886 | (1ULL << WLAN_EID_PWR_CONSTRAINT) | |
| 3887 | (1ULL << WLAN_EID_HT_CAPABILITY) | |
Johannes Berg | 70a3fd6 | 2015-03-12 08:53:29 +0200 | [diff] [blame] | 3888 | (1ULL << WLAN_EID_HT_OPERATION) | |
| 3889 | (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN); |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 3890 | |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3891 | static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data *sdata, |
| 3892 | struct ieee80211_if_managed *ifmgd, |
| 3893 | struct ieee80211_bss_conf *bss_conf, |
| 3894 | struct ieee80211_local *local, |
| 3895 | struct ieee80211_rx_status *rx_status) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3896 | { |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3897 | /* Track average RSSI from the Beacon frames of the current AP */ |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3898 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3899 | if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) { |
| 3900 | ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE; |
Johannes Berg | 338c17a | 2015-08-28 10:52:54 +0200 | [diff] [blame] | 3901 | ewma_beacon_signal_init(&ifmgd->ave_beacon_signal); |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3902 | ifmgd->last_cqm_event_signal = 0; |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 3903 | ifmgd->count_beacon_signal = 1; |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3904 | ifmgd->last_ave_beacon_signal = 0; |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3905 | } else { |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 3906 | ifmgd->count_beacon_signal++; |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3907 | } |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3908 | |
Johannes Berg | 338c17a | 2015-08-28 10:52:54 +0200 | [diff] [blame] | 3909 | ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal); |
| 3910 | |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3911 | if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold && |
| 3912 | ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) { |
Johannes Berg | 338c17a | 2015-08-28 10:52:54 +0200 | [diff] [blame] | 3913 | int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal); |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3914 | int last_sig = ifmgd->last_ave_beacon_signal; |
Emmanuel Grumbach | a818292 | 2015-03-16 23:23:34 +0200 | [diff] [blame] | 3915 | struct ieee80211_event event = { |
| 3916 | .type = RSSI_EVENT, |
| 3917 | }; |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3918 | |
| 3919 | /* |
| 3920 | * if signal crosses either of the boundaries, invoke callback |
| 3921 | * with appropriate parameters |
| 3922 | */ |
| 3923 | if (sig > ifmgd->rssi_max_thold && |
| 3924 | (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) { |
| 3925 | ifmgd->last_ave_beacon_signal = sig; |
Emmanuel Grumbach | a818292 | 2015-03-16 23:23:34 +0200 | [diff] [blame] | 3926 | event.u.rssi.data = RSSI_EVENT_HIGH; |
| 3927 | drv_event_callback(local, sdata, &event); |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3928 | } else if (sig < ifmgd->rssi_min_thold && |
| 3929 | (last_sig >= ifmgd->rssi_max_thold || |
| 3930 | last_sig == 0)) { |
| 3931 | ifmgd->last_ave_beacon_signal = sig; |
Emmanuel Grumbach | a818292 | 2015-03-16 23:23:34 +0200 | [diff] [blame] | 3932 | event.u.rssi.data = RSSI_EVENT_LOW; |
| 3933 | drv_event_callback(local, sdata, &event); |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3934 | } |
| 3935 | } |
| 3936 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3937 | if (bss_conf->cqm_rssi_thold && |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 3938 | ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT && |
Johannes Berg | ea08635 | 2012-01-19 09:29:58 +0100 | [diff] [blame] | 3939 | !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) { |
Johannes Berg | 338c17a | 2015-08-28 10:52:54 +0200 | [diff] [blame] | 3940 | int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal); |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3941 | int last_event = ifmgd->last_cqm_event_signal; |
| 3942 | int thold = bss_conf->cqm_rssi_thold; |
| 3943 | int hyst = bss_conf->cqm_rssi_hyst; |
Johannes Berg | 338c17a | 2015-08-28 10:52:54 +0200 | [diff] [blame] | 3944 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3945 | if (sig < thold && |
| 3946 | (last_event == 0 || sig < last_event - hyst)) { |
| 3947 | ifmgd->last_cqm_event_signal = sig; |
| 3948 | ieee80211_cqm_rssi_notify( |
| 3949 | &sdata->vif, |
| 3950 | NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW, |
Andrzej Zaborowski | 769f07d | 2017-01-25 12:43:40 +0100 | [diff] [blame] | 3951 | sig, GFP_KERNEL); |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3952 | } else if (sig > thold && |
| 3953 | (last_event == 0 || sig > last_event + hyst)) { |
| 3954 | ifmgd->last_cqm_event_signal = sig; |
| 3955 | ieee80211_cqm_rssi_notify( |
| 3956 | &sdata->vif, |
| 3957 | NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, |
Andrzej Zaborowski | 769f07d | 2017-01-25 12:43:40 +0100 | [diff] [blame] | 3958 | sig, GFP_KERNEL); |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3959 | } |
| 3960 | } |
| 3961 | |
Andrew Zaborowski | 2c3c5f8c | 2017-02-10 04:50:22 +0100 | [diff] [blame] | 3962 | if (bss_conf->cqm_rssi_low && |
| 3963 | ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) { |
| 3964 | int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal); |
| 3965 | int last_event = ifmgd->last_cqm_event_signal; |
| 3966 | int low = bss_conf->cqm_rssi_low; |
| 3967 | int high = bss_conf->cqm_rssi_high; |
| 3968 | |
| 3969 | if (sig < low && |
| 3970 | (last_event == 0 || last_event >= low)) { |
| 3971 | ifmgd->last_cqm_event_signal = sig; |
| 3972 | ieee80211_cqm_rssi_notify( |
| 3973 | &sdata->vif, |
| 3974 | NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW, |
| 3975 | sig, GFP_KERNEL); |
| 3976 | } else if (sig > high && |
| 3977 | (last_event == 0 || last_event <= high)) { |
| 3978 | ifmgd->last_cqm_event_signal = sig; |
| 3979 | ieee80211_cqm_rssi_notify( |
| 3980 | &sdata->vif, |
| 3981 | NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, |
| 3982 | sig, GFP_KERNEL); |
| 3983 | } |
| 3984 | } |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3985 | } |
| 3986 | |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3987 | static bool ieee80211_rx_our_beacon(const u8 *tx_bssid, |
| 3988 | struct cfg80211_bss *bss) |
| 3989 | { |
| 3990 | if (ether_addr_equal(tx_bssid, bss->bssid)) |
| 3991 | return true; |
| 3992 | if (!bss->transmitted_bss) |
| 3993 | return false; |
| 3994 | return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid); |
| 3995 | } |
| 3996 | |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3997 | static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata, |
Thomas Pedersen | 09a740c | 2020-09-21 19:28:14 -0700 | [diff] [blame] | 3998 | struct ieee80211_hdr *hdr, size_t len, |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3999 | struct ieee80211_rx_status *rx_status) |
| 4000 | { |
| 4001 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 4002 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Thomas Pedersen | 09a740c | 2020-09-21 19:28:14 -0700 | [diff] [blame] | 4003 | struct ieee80211_mgmt *mgmt = (void *) hdr; |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 4004 | size_t baselen; |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4005 | struct ieee802_11_elems *elems; |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 4006 | struct ieee80211_local *local = sdata->local; |
| 4007 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 4008 | struct ieee80211_channel *chan; |
| 4009 | struct sta_info *sta; |
| 4010 | u32 changed = 0; |
| 4011 | bool erp_valid; |
| 4012 | u8 erp_value = 0; |
Thomas Pedersen | 09a740c | 2020-09-21 19:28:14 -0700 | [diff] [blame] | 4013 | u32 ncrc = 0; |
| 4014 | u8 *bssid, *variable = mgmt->u.beacon.variable; |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 4015 | u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
| 4016 | |
| 4017 | sdata_assert_lock(sdata); |
| 4018 | |
| 4019 | /* Process beacon from the current BSS */ |
Thomas Pedersen | 09a740c | 2020-09-21 19:28:14 -0700 | [diff] [blame] | 4020 | bssid = ieee80211_get_bssid(hdr, len, sdata->vif.type); |
| 4021 | if (ieee80211_is_s1g_beacon(mgmt->frame_control)) { |
| 4022 | struct ieee80211_ext *ext = (void *) mgmt; |
| 4023 | |
| 4024 | if (ieee80211_is_s1g_short_beacon(ext->frame_control)) |
| 4025 | variable = ext->u.s1g_short_beacon.variable; |
| 4026 | else |
| 4027 | variable = ext->u.s1g_beacon.variable; |
| 4028 | } |
| 4029 | |
| 4030 | baselen = (u8 *) variable - (u8 *) mgmt; |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 4031 | if (baselen > len) |
| 4032 | return; |
| 4033 | |
| 4034 | rcu_read_lock(); |
| 4035 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 4036 | if (!chanctx_conf) { |
| 4037 | rcu_read_unlock(); |
| 4038 | return; |
| 4039 | } |
| 4040 | |
Thomas Pedersen | 3b23c184 | 2020-04-01 18:18:05 -0700 | [diff] [blame] | 4041 | if (ieee80211_rx_status_to_khz(rx_status) != |
| 4042 | ieee80211_channel_to_khz(chanctx_conf->def.chan)) { |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 4043 | rcu_read_unlock(); |
| 4044 | return; |
| 4045 | } |
| 4046 | chan = chanctx_conf->def.chan; |
| 4047 | rcu_read_unlock(); |
| 4048 | |
| 4049 | if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon && |
Thomas Pedersen | 09a740c | 2020-09-21 19:28:14 -0700 | [diff] [blame] | 4050 | ieee80211_rx_our_beacon(bssid, ifmgd->assoc_data->bss)) { |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4051 | elems = ieee802_11_parse_elems(variable, len - baselen, false, |
| 4052 | bssid, |
| 4053 | ifmgd->assoc_data->bss->bssid); |
| 4054 | if (!elems) |
| 4055 | return; |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 4056 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 4057 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status); |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 4058 | |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4059 | if (elems->dtim_period) |
| 4060 | ifmgd->dtim_period = elems->dtim_period; |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 4061 | ifmgd->have_beacon = true; |
| 4062 | ifmgd->assoc_data->need_beacon = false; |
| 4063 | if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) { |
| 4064 | sdata->vif.bss_conf.sync_tsf = |
| 4065 | le64_to_cpu(mgmt->u.beacon.timestamp); |
| 4066 | sdata->vif.bss_conf.sync_device_ts = |
| 4067 | rx_status->device_timestamp; |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4068 | sdata->vif.bss_conf.sync_dtim_count = elems->dtim_count; |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 4069 | } |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 4070 | |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4071 | if (elems->mbssid_config_ie) |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 4072 | bss_conf->profile_periodicity = |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4073 | elems->mbssid_config_ie->profile_periodicity; |
Johannes Berg | bbc6f03 | 2021-06-18 13:41:49 +0300 | [diff] [blame] | 4074 | else |
| 4075 | bss_conf->profile_periodicity = 0; |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 4076 | |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4077 | if (elems->ext_capab_len >= 11 && |
| 4078 | (elems->ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT)) |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 4079 | bss_conf->ema_ap = true; |
Johannes Berg | bbc6f03 | 2021-06-18 13:41:49 +0300 | [diff] [blame] | 4080 | else |
| 4081 | bss_conf->ema_ap = false; |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 4082 | |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 4083 | /* continue assoc process */ |
| 4084 | ifmgd->assoc_data->timeout = jiffies; |
| 4085 | ifmgd->assoc_data->timeout_started = true; |
| 4086 | run_again(sdata, ifmgd->assoc_data->timeout); |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4087 | kfree(elems); |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 4088 | return; |
| 4089 | } |
| 4090 | |
| 4091 | if (!ifmgd->associated || |
Thomas Pedersen | 09a740c | 2020-09-21 19:28:14 -0700 | [diff] [blame] | 4092 | !ieee80211_rx_our_beacon(bssid, ifmgd->associated)) |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 4093 | return; |
| 4094 | bssid = ifmgd->associated->bssid; |
| 4095 | |
| 4096 | if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL)) |
| 4097 | ieee80211_handle_beacon_sig(sdata, ifmgd, bss_conf, |
| 4098 | local, rx_status); |
Andrew Zaborowski | 2c3c5f8c | 2017-02-10 04:50:22 +0100 | [diff] [blame] | 4099 | |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 4100 | if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4101 | mlme_dbg_ratelimited(sdata, |
Johannes Berg | 112c31f | 2013-02-08 22:59:00 +0100 | [diff] [blame] | 4102 | "cancelling AP probe due to a received beacon\n"); |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 4103 | ieee80211_reset_ap_probe(sdata); |
Jouni Malinen | 9277818 | 2009-05-14 21:15:36 +0300 | [diff] [blame] | 4104 | } |
| 4105 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4106 | /* |
| 4107 | * Push the beacon loss detection into the future since |
| 4108 | * we are processing a beacon from the AP just now. |
| 4109 | */ |
Luis R. Rodriguez | d3a910a | 2010-09-16 15:12:32 -0400 | [diff] [blame] | 4110 | ieee80211_sta_reset_beacon_monitor(sdata); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4111 | |
Thomas Pedersen | 09a740c | 2020-09-21 19:28:14 -0700 | [diff] [blame] | 4112 | /* TODO: CRC urrently not calculated on S1G Beacon Compatibility |
| 4113 | * element (which carries the beacon interval). Don't forget to add a |
| 4114 | * bit to care_about_ies[] above if mac80211 is interested in a |
| 4115 | * changing S1G element. |
| 4116 | */ |
| 4117 | if (!ieee80211_is_s1g_beacon(hdr->frame_control)) |
| 4118 | ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4); |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4119 | elems = ieee802_11_parse_elems_crc(variable, len - baselen, |
| 4120 | false, care_about_ies, ncrc, |
| 4121 | mgmt->bssid, bssid); |
| 4122 | if (!elems) |
| 4123 | return; |
| 4124 | ncrc = elems->crc; |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 4125 | |
Johannes Berg | 90d13e8 | 2015-09-24 16:13:07 +0200 | [diff] [blame] | 4126 | if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) && |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4127 | ieee80211_check_tim(elems->tim, elems->tim_len, bss_conf->aid)) { |
Johannes Berg | 90d13e8 | 2015-09-24 16:13:07 +0200 | [diff] [blame] | 4128 | if (local->hw.conf.dynamic_ps_timeout > 0) { |
| 4129 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 4130 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 4131 | ieee80211_hw_config(local, |
| 4132 | IEEE80211_CONF_CHANGE_PS); |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 4133 | } |
Johannes Berg | 076cdcb | 2015-09-24 16:14:55 +0200 | [diff] [blame] | 4134 | ieee80211_send_nullfunc(local, sdata, false); |
Johannes Berg | 90d13e8 | 2015-09-24 16:13:07 +0200 | [diff] [blame] | 4135 | } else if (!local->pspolling && sdata->u.mgd.powersave) { |
| 4136 | local->pspolling = true; |
| 4137 | |
| 4138 | /* |
| 4139 | * Here is assumed that the driver will be |
| 4140 | * able to send ps-poll frame and receive a |
| 4141 | * response even though power save mode is |
| 4142 | * enabled, but some drivers might require |
| 4143 | * to disable power save here. This needs |
| 4144 | * to be investigated. |
| 4145 | */ |
| 4146 | ieee80211_send_pspoll(local, sdata); |
Vivek Natarajan | a97b77b | 2008-12-23 18:39:02 -0800 | [diff] [blame] | 4147 | } |
| 4148 | } |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 4149 | |
Janusz.Dziedzic@tieto.com | b115b97 | 2015-10-27 08:38:40 +0100 | [diff] [blame] | 4150 | if (sdata->vif.p2p || |
| 4151 | sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) { |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 4152 | struct ieee80211_p2p_noa_attr noa = {}; |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 4153 | int ret; |
| 4154 | |
Thomas Pedersen | 09a740c | 2020-09-21 19:28:14 -0700 | [diff] [blame] | 4155 | ret = cfg80211_get_p2p_attr(variable, |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 4156 | len - baselen, |
| 4157 | IEEE80211_P2P_ATTR_ABSENCE_NOTICE, |
Janusz Dziedzic | 934457e | 2013-03-21 15:47:55 +0100 | [diff] [blame] | 4158 | (u8 *) &noa, sizeof(noa)); |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 4159 | if (ret >= 2) { |
| 4160 | if (sdata->u.mgd.p2p_noa_index != noa.index) { |
| 4161 | /* valid noa_attr and index changed */ |
| 4162 | sdata->u.mgd.p2p_noa_index = noa.index; |
| 4163 | memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa)); |
| 4164 | changed |= BSS_CHANGED_P2P_PS; |
| 4165 | /* |
| 4166 | * make sure we update all information, the CRC |
| 4167 | * mechanism doesn't look at P2P attributes. |
| 4168 | */ |
| 4169 | ifmgd->beacon_crc_valid = false; |
| 4170 | } |
| 4171 | } else if (sdata->u.mgd.p2p_noa_index != -1) { |
| 4172 | /* noa_attr not found and we had valid noa_attr before */ |
| 4173 | sdata->u.mgd.p2p_noa_index = -1; |
| 4174 | 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] | 4175 | changed |= BSS_CHANGED_P2P_PS; |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 4176 | ifmgd->beacon_crc_valid = false; |
| 4177 | } |
| 4178 | } |
| 4179 | |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 4180 | if (ifmgd->csa_waiting_bcn) |
| 4181 | ieee80211_chswitch_post_beacon(sdata); |
| 4182 | |
Alexander Bondar | 2ecc390 | 2015-03-01 09:10:00 +0200 | [diff] [blame] | 4183 | /* |
| 4184 | * Update beacon timing and dtim count on every beacon appearance. This |
| 4185 | * will allow the driver to use the most updated values. Do it before |
| 4186 | * comparing this one with last received beacon. |
| 4187 | * IMPORTANT: These parameters would possibly be out of sync by the time |
| 4188 | * the driver will use them. The synchronized view is currently |
| 4189 | * guaranteed only in certain callbacks. |
| 4190 | */ |
Thomas Pedersen | 09a740c | 2020-09-21 19:28:14 -0700 | [diff] [blame] | 4191 | if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) && |
| 4192 | !ieee80211_is_s1g_beacon(hdr->frame_control)) { |
Alexander Bondar | 2ecc390 | 2015-03-01 09:10:00 +0200 | [diff] [blame] | 4193 | sdata->vif.bss_conf.sync_tsf = |
| 4194 | le64_to_cpu(mgmt->u.beacon.timestamp); |
| 4195 | sdata->vif.bss_conf.sync_device_ts = |
| 4196 | rx_status->device_timestamp; |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4197 | sdata->vif.bss_conf.sync_dtim_count = elems->dtim_count; |
Alexander Bondar | 2ecc390 | 2015-03-01 09:10:00 +0200 | [diff] [blame] | 4198 | } |
| 4199 | |
Thomas Pedersen | 09a740c | 2020-09-21 19:28:14 -0700 | [diff] [blame] | 4200 | if ((ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid) || |
| 4201 | ieee80211_is_s1g_short_beacon(mgmt->frame_control)) |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4202 | goto free; |
Jouni Malinen | 3019667 | 2009-05-19 17:01:43 +0300 | [diff] [blame] | 4203 | ifmgd->beacon_crc = ncrc; |
Juuso Oikarinen | d8ec443 | 2010-10-01 16:02:31 +0300 | [diff] [blame] | 4204 | ifmgd->beacon_crc_valid = true; |
Jouni Malinen | 3019667 | 2009-05-19 17:01:43 +0300 | [diff] [blame] | 4205 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 4206 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status); |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 4207 | |
Johannes Berg | d70b761 | 2013-08-23 15:48:48 +0200 | [diff] [blame] | 4208 | ieee80211_sta_process_chanswitch(sdata, rx_status->mactime, |
Luciano Coelho | 2ba4538 | 2014-10-08 09:48:35 +0300 | [diff] [blame] | 4209 | rx_status->device_timestamp, |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4210 | elems, true); |
Johannes Berg | d70b761 | 2013-08-23 15:48:48 +0200 | [diff] [blame] | 4211 | |
Johannes Berg | 095d81c | 2013-10-15 12:25:07 +0200 | [diff] [blame] | 4212 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) && |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4213 | ieee80211_sta_wmm_params(local, sdata, elems->wmm_param, |
| 4214 | elems->wmm_param_len, |
| 4215 | elems->mu_edca_param_set)) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 4216 | changed |= BSS_CHANGED_QOS; |
| 4217 | |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 4218 | /* |
| 4219 | * 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] | 4220 | * DTIM period (and beacon timing if desired) now. |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 4221 | */ |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 4222 | if (!ifmgd->have_beacon) { |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 4223 | /* a few bogus AP send dtim_period = 0 or no TIM IE */ |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4224 | bss_conf->dtim_period = elems->dtim_period ?: 1; |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 4225 | |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 4226 | changed |= BSS_CHANGED_BEACON_INFO; |
| 4227 | ifmgd->have_beacon = true; |
Alexander Bondar | 482a9c7 | 2013-06-03 17:29:33 +0300 | [diff] [blame] | 4228 | |
| 4229 | mutex_lock(&local->iflist_mtx); |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 4230 | ieee80211_recalc_ps(local); |
Alexander Bondar | 482a9c7 | 2013-06-03 17:29:33 +0300 | [diff] [blame] | 4231 | mutex_unlock(&local->iflist_mtx); |
| 4232 | |
Alexander Bondar | ce85788 | 2013-05-06 17:17:04 +0300 | [diff] [blame] | 4233 | ieee80211_recalc_ps_vif(sdata); |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 4234 | } |
| 4235 | |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4236 | if (elems->erp_info) { |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 4237 | erp_valid = true; |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4238 | erp_value = elems->erp_info[0]; |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 4239 | } else { |
| 4240 | erp_valid = false; |
John W. Linville | 50c4afb | 2008-04-15 14:09:27 -0400 | [diff] [blame] | 4241 | } |
Thomas Pedersen | 09a740c | 2020-09-21 19:28:14 -0700 | [diff] [blame] | 4242 | |
| 4243 | if (!ieee80211_is_s1g_beacon(hdr->frame_control)) |
| 4244 | changed |= ieee80211_handle_bss_capability(sdata, |
| 4245 | le16_to_cpu(mgmt->u.beacon.capab_info), |
| 4246 | erp_valid, erp_value); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4247 | |
Johannes Berg | 1128958 | 2013-02-07 17:36:12 +0100 | [diff] [blame] | 4248 | mutex_lock(&local->sta_mtx); |
Johannes Berg | bee7f586 | 2013-02-07 22:24:55 +0100 | [diff] [blame] | 4249 | sta = sta_info_get(sdata, bssid); |
| 4250 | |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4251 | changed |= ieee80211_recalc_twt_req(sdata, sta, elems); |
John Crispin | c9d3245 | 2019-05-28 13:49:47 +0200 | [diff] [blame] | 4252 | |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4253 | if (ieee80211_config_bw(sdata, sta, elems->ht_cap_elem, |
| 4254 | elems->vht_cap_elem, elems->ht_operation, |
| 4255 | elems->vht_operation, elems->he_operation, |
| 4256 | elems->s1g_oper, bssid, &changed)) { |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 4257 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | 89f774e | 2016-01-25 15:46:36 +0200 | [diff] [blame] | 4258 | sdata_info(sdata, |
| 4259 | "failed to follow AP %pM bandwidth change, disconnect\n", |
| 4260 | bssid); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 4261 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
| 4262 | WLAN_REASON_DEAUTH_LEAVING, |
| 4263 | true, deauth_buf); |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 4264 | ieee80211_report_disconnect(sdata, deauth_buf, |
| 4265 | sizeof(deauth_buf), true, |
Johannes Berg | 3f8a39f | 2020-12-06 14:54:43 +0200 | [diff] [blame] | 4266 | WLAN_REASON_DEAUTH_LEAVING, |
| 4267 | false); |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4268 | goto free; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 4269 | } |
Johannes Berg | bee7f586 | 2013-02-07 22:24:55 +0100 | [diff] [blame] | 4270 | |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4271 | if (sta && elems->opmode_notif) |
| 4272 | ieee80211_vht_handle_opmode(sdata, sta, *elems->opmode_notif, |
Eyal Shapira | cf1e05c | 2015-12-08 16:04:36 +0200 | [diff] [blame] | 4273 | rx_status->band); |
Johannes Berg | 1128958 | 2013-02-07 17:36:12 +0100 | [diff] [blame] | 4274 | mutex_unlock(&local->sta_mtx); |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 4275 | |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 4276 | changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt, |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4277 | elems->country_elem, |
| 4278 | elems->country_elem_len, |
| 4279 | elems->pwr_constr_elem, |
| 4280 | elems->cisco_dtpc_elem); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 4281 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4282 | ieee80211_bss_info_change_notify(sdata, changed); |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4283 | free: |
| 4284 | kfree(elems); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4285 | } |
| 4286 | |
Thomas Pedersen | 09a740c | 2020-09-21 19:28:14 -0700 | [diff] [blame] | 4287 | void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data *sdata, |
| 4288 | struct sk_buff *skb) |
| 4289 | { |
| 4290 | struct ieee80211_rx_status *rx_status; |
| 4291 | struct ieee80211_hdr *hdr; |
| 4292 | u16 fc; |
| 4293 | |
| 4294 | rx_status = (struct ieee80211_rx_status *) skb->cb; |
| 4295 | hdr = (struct ieee80211_hdr *) skb->data; |
| 4296 | fc = le16_to_cpu(hdr->frame_control); |
| 4297 | |
| 4298 | sdata_lock(sdata); |
| 4299 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 4300 | case IEEE80211_STYPE_S1G_BEACON: |
| 4301 | ieee80211_rx_mgmt_beacon(sdata, hdr, skb->len, rx_status); |
| 4302 | break; |
| 4303 | } |
| 4304 | sdata_unlock(sdata); |
| 4305 | } |
| 4306 | |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 4307 | void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, |
| 4308 | struct sk_buff *skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4309 | { |
| 4310 | struct ieee80211_rx_status *rx_status; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4311 | struct ieee80211_mgmt *mgmt; |
| 4312 | u16 fc; |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 4313 | int ies_len; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4314 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4315 | rx_status = (struct ieee80211_rx_status *) skb->cb; |
| 4316 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 4317 | fc = le16_to_cpu(mgmt->frame_control); |
| 4318 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4319 | sdata_lock(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 4320 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4321 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 4322 | case IEEE80211_STYPE_BEACON: |
Thomas Pedersen | 09a740c | 2020-09-21 19:28:14 -0700 | [diff] [blame] | 4323 | ieee80211_rx_mgmt_beacon(sdata, (void *)mgmt, |
| 4324 | skb->len, rx_status); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4325 | break; |
| 4326 | case IEEE80211_STYPE_PROBE_RESP: |
| 4327 | ieee80211_rx_mgmt_probe_resp(sdata, skb); |
| 4328 | break; |
| 4329 | case IEEE80211_STYPE_AUTH: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4330 | ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4331 | break; |
| 4332 | case IEEE80211_STYPE_DEAUTH: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4333 | ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4334 | break; |
| 4335 | case IEEE80211_STYPE_DISASSOC: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4336 | ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4337 | break; |
| 4338 | case IEEE80211_STYPE_ASSOC_RESP: |
| 4339 | case IEEE80211_STYPE_REASSOC_RESP: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4340 | ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4341 | break; |
| 4342 | case IEEE80211_STYPE_ACTION: |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 4343 | if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) { |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4344 | struct ieee802_11_elems *elems; |
| 4345 | |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 4346 | ies_len = skb->len - |
| 4347 | offsetof(struct ieee80211_mgmt, |
| 4348 | u.action.u.chan_switch.variable); |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 4349 | |
| 4350 | if (ies_len < 0) |
| 4351 | break; |
| 4352 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 4353 | /* CSA IE cannot be overridden, no need for BSSID */ |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4354 | elems = ieee802_11_parse_elems( |
| 4355 | mgmt->u.action.u.chan_switch.variable, |
| 4356 | ies_len, true, mgmt->bssid, NULL); |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 4357 | |
Johannes Berg | 8223ac1 | 2021-10-01 21:11:08 +0200 | [diff] [blame] | 4358 | if (elems && !elems->parse_error) |
| 4359 | ieee80211_sta_process_chanswitch(sdata, |
| 4360 | rx_status->mactime, |
| 4361 | rx_status->device_timestamp, |
| 4362 | elems, false); |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4363 | kfree(elems); |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 4364 | } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) { |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4365 | struct ieee802_11_elems *elems; |
| 4366 | |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 4367 | ies_len = skb->len - |
| 4368 | offsetof(struct ieee80211_mgmt, |
| 4369 | u.action.u.ext_chan_switch.variable); |
| 4370 | |
| 4371 | if (ies_len < 0) |
| 4372 | break; |
| 4373 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 4374 | /* |
| 4375 | * extended CSA IE can't be overridden, no need for |
| 4376 | * BSSID |
| 4377 | */ |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4378 | elems = ieee802_11_parse_elems( |
| 4379 | mgmt->u.action.u.ext_chan_switch.variable, |
| 4380 | ies_len, true, mgmt->bssid, NULL); |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 4381 | |
Johannes Berg | 8223ac1 | 2021-10-01 21:11:08 +0200 | [diff] [blame] | 4382 | if (elems && !elems->parse_error) { |
| 4383 | /* for the handling code pretend it was an IE */ |
| 4384 | elems->ext_chansw_ie = |
| 4385 | &mgmt->u.action.u.ext_chan_switch.data; |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 4386 | |
Johannes Berg | 8223ac1 | 2021-10-01 21:11:08 +0200 | [diff] [blame] | 4387 | ieee80211_sta_process_chanswitch(sdata, |
| 4388 | rx_status->mactime, |
| 4389 | rx_status->device_timestamp, |
| 4390 | elems, false); |
| 4391 | } |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 4392 | |
Johannes Berg | 5d24828 | 2021-09-20 15:40:10 +0200 | [diff] [blame] | 4393 | kfree(elems); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 4394 | } |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 4395 | break; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 4396 | } |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4397 | sdata_unlock(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4398 | } |
| 4399 | |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4400 | static void ieee80211_sta_timer(struct timer_list *t) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4401 | { |
| 4402 | struct ieee80211_sub_if_data *sdata = |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4403 | from_timer(sdata, t, u.mgd.timer); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4404 | |
Stanislaw Gruszka | 9b7d72c | 2013-02-28 10:55:27 +0100 | [diff] [blame] | 4405 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4406 | } |
| 4407 | |
Naftali Goldstein | 7dd231e | 2021-04-09 12:40:14 +0300 | [diff] [blame] | 4408 | void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata, |
| 4409 | u8 *bssid, u8 reason, bool tx) |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4410 | { |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 4411 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4412 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 4413 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason, |
Johannes Berg | 6b684db | 2013-01-29 11:35:29 +0100 | [diff] [blame] | 4414 | tx, frame_buf); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 4415 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 4416 | ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true, |
Johannes Berg | 3f8a39f | 2020-12-06 14:54:43 +0200 | [diff] [blame] | 4417 | reason, false); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4418 | } |
| 4419 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4420 | static int ieee80211_auth(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4421 | { |
| 4422 | struct ieee80211_local *local = sdata->local; |
| 4423 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 4424 | struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data; |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4425 | u32 tx_flags = 0; |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4426 | u16 trans = 1; |
| 4427 | u16 status = 0; |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 4428 | struct ieee80211_prep_tx_info info = { |
| 4429 | .subtype = IEEE80211_STYPE_AUTH, |
| 4430 | }; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4431 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4432 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4433 | |
| 4434 | if (WARN_ON_ONCE(!auth_data)) |
| 4435 | return -EINVAL; |
| 4436 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4437 | auth_data->tries++; |
| 4438 | |
| 4439 | if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4440 | sdata_info(sdata, "authentication with %pM timed out\n", |
| 4441 | auth_data->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4442 | |
| 4443 | /* |
| 4444 | * Most likely AP is not in the range so remove the |
| 4445 | * bss struct for that AP. |
| 4446 | */ |
| 4447 | cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss); |
| 4448 | |
| 4449 | return -ETIMEDOUT; |
| 4450 | } |
| 4451 | |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 4452 | if (auth_data->algorithm == WLAN_AUTH_SAE) |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 4453 | info.duration = jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE); |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 4454 | |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 4455 | drv_mgd_prepare_tx(local, sdata, &info); |
Johannes Berg | a1845fc | 2012-06-27 13:18:36 +0200 | [diff] [blame] | 4456 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4457 | sdata_info(sdata, "send auth to %pM (try %d/%d)\n", |
| 4458 | auth_data->bss->bssid, auth_data->tries, |
| 4459 | IEEE80211_AUTH_MAX_TRIES); |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 4460 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4461 | auth_data->expected_transaction = 2; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4462 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4463 | if (auth_data->algorithm == WLAN_AUTH_SAE) { |
| 4464 | trans = auth_data->sae_trans; |
| 4465 | status = auth_data->sae_status; |
| 4466 | auth_data->expected_transaction = trans; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4467 | } |
| 4468 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4469 | if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
| 4470 | tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS | |
| 4471 | IEEE80211_TX_INTFL_MLME_CONN_TX; |
| 4472 | |
| 4473 | ieee80211_send_auth(sdata, trans, auth_data->algorithm, status, |
| 4474 | auth_data->data, auth_data->data_len, |
| 4475 | auth_data->bss->bssid, |
| 4476 | auth_data->bss->bssid, NULL, 0, 0, |
| 4477 | tx_flags); |
| 4478 | |
Stanislaw Gruszka | 6211dd1 | 2013-05-17 13:43:04 +0200 | [diff] [blame] | 4479 | if (tx_flags == 0) { |
Ilan Peer | 407879b | 2018-04-20 13:49:20 +0300 | [diff] [blame] | 4480 | if (auth_data->algorithm == WLAN_AUTH_SAE) |
| 4481 | auth_data->timeout = jiffies + |
| 4482 | IEEE80211_AUTH_TIMEOUT_SAE; |
| 4483 | else |
| 4484 | auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT; |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4485 | } else { |
Johannes Berg | cb236d2 | 2013-07-29 23:07:43 +0200 | [diff] [blame] | 4486 | auth_data->timeout = |
| 4487 | round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG); |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4488 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4489 | |
Ilan Peer | 407879b | 2018-04-20 13:49:20 +0300 | [diff] [blame] | 4490 | auth_data->timeout_started = true; |
| 4491 | run_again(sdata, auth_data->timeout); |
| 4492 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4493 | return 0; |
| 4494 | } |
| 4495 | |
| 4496 | static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata) |
| 4497 | { |
| 4498 | struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data; |
| 4499 | struct ieee80211_local *local = sdata->local; |
| 4500 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4501 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4502 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4503 | assoc_data->tries++; |
| 4504 | if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4505 | sdata_info(sdata, "association with %pM timed out\n", |
| 4506 | assoc_data->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4507 | |
| 4508 | /* |
| 4509 | * Most likely AP is not in the range so remove the |
| 4510 | * bss struct for that AP. |
| 4511 | */ |
| 4512 | cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss); |
| 4513 | |
| 4514 | return -ETIMEDOUT; |
| 4515 | } |
| 4516 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4517 | sdata_info(sdata, "associate with %pM (try %d/%d)\n", |
| 4518 | assoc_data->bss->bssid, assoc_data->tries, |
| 4519 | IEEE80211_ASSOC_MAX_TRIES); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4520 | ieee80211_send_assoc(sdata); |
| 4521 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 4522 | if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) { |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4523 | assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT; |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4524 | assoc_data->timeout_started = true; |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4525 | run_again(sdata, assoc_data->timeout); |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4526 | } else { |
Johannes Berg | cb236d2 | 2013-07-29 23:07:43 +0200 | [diff] [blame] | 4527 | assoc_data->timeout = |
| 4528 | round_jiffies_up(jiffies + |
| 4529 | IEEE80211_ASSOC_TIMEOUT_LONG); |
| 4530 | assoc_data->timeout_started = true; |
| 4531 | run_again(sdata, assoc_data->timeout); |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4532 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4533 | |
| 4534 | return 0; |
| 4535 | } |
| 4536 | |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4537 | void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata, |
| 4538 | __le16 fc, bool acked) |
| 4539 | { |
| 4540 | struct ieee80211_local *local = sdata->local; |
| 4541 | |
| 4542 | sdata->u.mgd.status_fc = fc; |
| 4543 | sdata->u.mgd.status_acked = acked; |
| 4544 | sdata->u.mgd.status_received = true; |
| 4545 | |
| 4546 | ieee80211_queue_work(&local->hw, &sdata->work); |
| 4547 | } |
| 4548 | |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 4549 | void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 4550 | { |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 4551 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 4552 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 4553 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4554 | sdata_lock(sdata); |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 4555 | |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4556 | if (ifmgd->status_received) { |
| 4557 | __le16 fc = ifmgd->status_fc; |
| 4558 | bool status_acked = ifmgd->status_acked; |
| 4559 | |
| 4560 | ifmgd->status_received = false; |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4561 | if (ifmgd->auth_data && ieee80211_is_auth(fc)) { |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4562 | if (status_acked) { |
Ilan Peer | 407879b | 2018-04-20 13:49:20 +0300 | [diff] [blame] | 4563 | if (ifmgd->auth_data->algorithm == |
| 4564 | WLAN_AUTH_SAE) |
| 4565 | ifmgd->auth_data->timeout = |
| 4566 | jiffies + |
| 4567 | IEEE80211_AUTH_TIMEOUT_SAE; |
| 4568 | else |
| 4569 | ifmgd->auth_data->timeout = |
| 4570 | jiffies + |
| 4571 | IEEE80211_AUTH_TIMEOUT_SHORT; |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4572 | run_again(sdata, ifmgd->auth_data->timeout); |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4573 | } else { |
| 4574 | ifmgd->auth_data->timeout = jiffies - 1; |
| 4575 | } |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4576 | ifmgd->auth_data->timeout_started = true; |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4577 | } else if (ifmgd->assoc_data && |
| 4578 | (ieee80211_is_assoc_req(fc) || |
| 4579 | ieee80211_is_reassoc_req(fc))) { |
| 4580 | if (status_acked) { |
| 4581 | ifmgd->assoc_data->timeout = |
| 4582 | jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT; |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4583 | run_again(sdata, ifmgd->assoc_data->timeout); |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4584 | } else { |
| 4585 | ifmgd->assoc_data->timeout = jiffies - 1; |
| 4586 | } |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4587 | ifmgd->assoc_data->timeout_started = true; |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4588 | } |
| 4589 | } |
| 4590 | |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4591 | if (ifmgd->auth_data && ifmgd->auth_data->timeout_started && |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4592 | time_after(jiffies, ifmgd->auth_data->timeout)) { |
| 4593 | if (ifmgd->auth_data->done) { |
| 4594 | /* |
| 4595 | * ok ... we waited for assoc but userspace didn't, |
| 4596 | * so let's just kill the auth data |
| 4597 | */ |
| 4598 | ieee80211_destroy_auth_data(sdata, false); |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4599 | } else if (ieee80211_auth(sdata)) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4600 | u8 bssid[ETH_ALEN]; |
Emmanuel Grumbach | a940909 | 2015-03-16 23:23:35 +0200 | [diff] [blame] | 4601 | struct ieee80211_event event = { |
| 4602 | .type = MLME_EVENT, |
| 4603 | .u.mlme.data = AUTH_EVENT, |
| 4604 | .u.mlme.status = MLME_TIMEOUT, |
| 4605 | }; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4606 | |
| 4607 | memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN); |
| 4608 | |
| 4609 | ieee80211_destroy_auth_data(sdata, false); |
| 4610 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 4611 | cfg80211_auth_timeout(sdata->dev, bssid); |
Emmanuel Grumbach | a940909 | 2015-03-16 23:23:35 +0200 | [diff] [blame] | 4612 | drv_event_callback(sdata->local, sdata, &event); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4613 | } |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4614 | } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4615 | run_again(sdata, ifmgd->auth_data->timeout); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4616 | |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4617 | if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started && |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4618 | time_after(jiffies, ifmgd->assoc_data->timeout)) { |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 4619 | if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) || |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4620 | ieee80211_do_assoc(sdata)) { |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 4621 | struct cfg80211_bss *bss = ifmgd->assoc_data->bss; |
Emmanuel Grumbach | d0d1a12 | 2015-03-16 23:23:36 +0200 | [diff] [blame] | 4622 | struct ieee80211_event event = { |
| 4623 | .type = MLME_EVENT, |
| 4624 | .u.mlme.data = ASSOC_EVENT, |
| 4625 | .u.mlme.status = MLME_TIMEOUT, |
| 4626 | }; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4627 | |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 4628 | ieee80211_destroy_assoc_data(sdata, false, false); |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 4629 | cfg80211_assoc_timeout(sdata->dev, bss); |
Emmanuel Grumbach | d0d1a12 | 2015-03-16 23:23:36 +0200 | [diff] [blame] | 4630 | drv_event_callback(sdata->local, sdata, &event); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4631 | } |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4632 | } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4633 | run_again(sdata, ifmgd->assoc_data->timeout); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4634 | |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 4635 | if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL && |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4636 | ifmgd->associated) { |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 4637 | u8 bssid[ETH_ALEN]; |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 4638 | int max_tries; |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 4639 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 4640 | memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 4641 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 4642 | if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 4643 | max_tries = max_nullfunc_tries; |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 4644 | else |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 4645 | max_tries = max_probe_tries; |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 4646 | |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 4647 | /* ACK received for nullfunc probing frame */ |
| 4648 | if (!ifmgd->probe_send_count) |
| 4649 | ieee80211_reset_ap_probe(sdata); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4650 | else if (ifmgd->nullfunc_failed) { |
| 4651 | if (ifmgd->probe_send_count < max_tries) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4652 | mlme_dbg(sdata, |
| 4653 | "No ack for nullfunc frame to AP %pM, try %d/%i\n", |
| 4654 | bssid, ifmgd->probe_send_count, |
| 4655 | max_tries); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4656 | ieee80211_mgd_probe_ap_send(sdata); |
| 4657 | } else { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4658 | mlme_dbg(sdata, |
| 4659 | "No ack for nullfunc frame to AP %pM, disconnecting.\n", |
| 4660 | bssid); |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 4661 | ieee80211_sta_connection_lost(sdata, bssid, |
Johannes Berg | 6b684db | 2013-01-29 11:35:29 +0100 | [diff] [blame] | 4662 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, |
| 4663 | false); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4664 | } |
| 4665 | } else if (time_is_after_jiffies(ifmgd->probe_timeout)) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4666 | run_again(sdata, ifmgd->probe_timeout); |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 4667 | else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4668 | mlme_dbg(sdata, |
| 4669 | "Failed to send nullfunc to AP %pM after %dms, disconnecting\n", |
| 4670 | bssid, probe_wait_ms); |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 4671 | ieee80211_sta_connection_lost(sdata, bssid, |
Johannes Berg | 6b684db | 2013-01-29 11:35:29 +0100 | [diff] [blame] | 4672 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4673 | } else if (ifmgd->probe_send_count < max_tries) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4674 | mlme_dbg(sdata, |
| 4675 | "No probe response from AP %pM after %dms, try %d/%i\n", |
| 4676 | bssid, probe_wait_ms, |
| 4677 | ifmgd->probe_send_count, max_tries); |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 4678 | ieee80211_mgd_probe_ap_send(sdata); |
| 4679 | } else { |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4680 | /* |
| 4681 | * We actually lost the connection ... or did we? |
| 4682 | * Let's make sure! |
| 4683 | */ |
Johannes Berg | 89f774e | 2016-01-25 15:46:36 +0200 | [diff] [blame] | 4684 | mlme_dbg(sdata, |
| 4685 | "No probe response from AP %pM after %dms, disconnecting.\n", |
| 4686 | bssid, probe_wait_ms); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4687 | |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 4688 | ieee80211_sta_connection_lost(sdata, bssid, |
Johannes Berg | 6b684db | 2013-01-29 11:35:29 +0100 | [diff] [blame] | 4689 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4690 | } |
| 4691 | } |
| 4692 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4693 | sdata_unlock(sdata); |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 4694 | } |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 4695 | |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4696 | static void ieee80211_sta_bcn_mon_timer(struct timer_list *t) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4697 | { |
| 4698 | struct ieee80211_sub_if_data *sdata = |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4699 | from_timer(sdata, t, u.mgd.bcn_mon_timer); |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 4700 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4701 | |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 4702 | if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn) |
Michal Kazior | e5593f5 | 2014-04-09 15:45:36 +0200 | [diff] [blame] | 4703 | return; |
| 4704 | |
Loic Poulain | 0b91111 | 2020-06-18 11:17:42 +0200 | [diff] [blame] | 4705 | if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER) |
| 4706 | return; |
| 4707 | |
Johannes Berg | 682bd38 | 2013-01-29 13:13:50 +0100 | [diff] [blame] | 4708 | sdata->u.mgd.connection_loss = false; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 4709 | ieee80211_queue_work(&sdata->local->hw, |
| 4710 | &sdata->u.mgd.beacon_connection_loss_work); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4711 | } |
| 4712 | |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4713 | static void ieee80211_sta_conn_mon_timer(struct timer_list *t) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4714 | { |
| 4715 | struct ieee80211_sub_if_data *sdata = |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4716 | from_timer(sdata, t, u.mgd.conn_mon_timer); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4717 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 4718 | struct ieee80211_local *local = sdata->local; |
Felix Fietkau | 9abf4e4 | 2020-09-08 14:36:56 +0200 | [diff] [blame] | 4719 | struct sta_info *sta; |
| 4720 | unsigned long timeout; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4721 | |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 4722 | if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn) |
Michal Kazior | e5593f5 | 2014-04-09 15:45:36 +0200 | [diff] [blame] | 4723 | return; |
| 4724 | |
Felix Fietkau | 9abf4e4 | 2020-09-08 14:36:56 +0200 | [diff] [blame] | 4725 | sta = sta_info_get(sdata, ifmgd->bssid); |
| 4726 | if (!sta) |
| 4727 | return; |
| 4728 | |
| 4729 | timeout = sta->status_stats.last_ack; |
| 4730 | if (time_before(sta->status_stats.last_ack, sta->rx_stats.last_rx)) |
| 4731 | timeout = sta->rx_stats.last_rx; |
| 4732 | timeout += IEEE80211_CONNECTION_IDLE_TIME; |
| 4733 | |
Ben Greear | 7d73cd9 | 2021-03-30 16:07:49 -0700 | [diff] [blame] | 4734 | /* If timeout is after now, then update timer to fire at |
| 4735 | * the later date, but do not actually probe at this time. |
| 4736 | */ |
| 4737 | if (time_is_after_jiffies(timeout)) { |
Felix Fietkau | 9abf4e4 | 2020-09-08 14:36:56 +0200 | [diff] [blame] | 4738 | mod_timer(&ifmgd->conn_mon_timer, round_jiffies_up(timeout)); |
| 4739 | return; |
| 4740 | } |
| 4741 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 4742 | ieee80211_queue_work(&local->hw, &ifmgd->monitor_work); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4743 | } |
| 4744 | |
| 4745 | static void ieee80211_sta_monitor_work(struct work_struct *work) |
| 4746 | { |
| 4747 | struct ieee80211_sub_if_data *sdata = |
| 4748 | container_of(work, struct ieee80211_sub_if_data, |
| 4749 | u.mgd.monitor_work); |
| 4750 | |
| 4751 | ieee80211_mgd_probe_ap(sdata, false); |
| 4752 | } |
| 4753 | |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 4754 | static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata) |
| 4755 | { |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 4756 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 4757 | __ieee80211_stop_poll(sdata); |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 4758 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4759 | /* let's probe the connection once */ |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 4760 | if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR)) |
Eliad Peller | 494f1fe | 2012-02-19 15:26:09 +0200 | [diff] [blame] | 4761 | ieee80211_queue_work(&sdata->local->hw, |
| 4762 | &sdata->u.mgd.monitor_work); |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 4763 | } |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 4764 | } |
| 4765 | |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4766 | #ifdef CONFIG_PM |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4767 | void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata) |
| 4768 | { |
| 4769 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 4770 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
| 4771 | |
| 4772 | sdata_lock(sdata); |
| 4773 | |
Emmanuel Grumbach | c52666a | 2014-05-13 12:54:09 +0300 | [diff] [blame] | 4774 | if (ifmgd->auth_data || ifmgd->assoc_data) { |
| 4775 | const u8 *bssid = ifmgd->auth_data ? |
| 4776 | ifmgd->auth_data->bss->bssid : |
| 4777 | ifmgd->assoc_data->bss->bssid; |
| 4778 | |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4779 | /* |
Emmanuel Grumbach | c52666a | 2014-05-13 12:54:09 +0300 | [diff] [blame] | 4780 | * If we are trying to authenticate / associate while suspending, |
| 4781 | * cfg80211 won't know and won't actually abort those attempts, |
| 4782 | * thus we need to do that ourselves. |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4783 | */ |
Johannes Berg | 4b08d1b | 2019-08-30 14:24:51 +0300 | [diff] [blame] | 4784 | ieee80211_send_deauth_disassoc(sdata, bssid, bssid, |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4785 | IEEE80211_STYPE_DEAUTH, |
| 4786 | WLAN_REASON_DEAUTH_LEAVING, |
| 4787 | false, frame_buf); |
Emmanuel Grumbach | c52666a | 2014-05-13 12:54:09 +0300 | [diff] [blame] | 4788 | if (ifmgd->assoc_data) |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 4789 | ieee80211_destroy_assoc_data(sdata, false, true); |
Emmanuel Grumbach | c52666a | 2014-05-13 12:54:09 +0300 | [diff] [blame] | 4790 | if (ifmgd->auth_data) |
| 4791 | ieee80211_destroy_auth_data(sdata, false); |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4792 | cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf, |
Johannes Berg | 3bb0214 | 2020-12-06 14:54:42 +0200 | [diff] [blame] | 4793 | IEEE80211_DEAUTH_FRAME_LEN, |
| 4794 | false); |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4795 | } |
| 4796 | |
Johannes Berg | be72afe | 2015-03-01 09:10:03 +0200 | [diff] [blame] | 4797 | /* This is a bit of a hack - we should find a better and more generic |
| 4798 | * solution to this. Normally when suspending, cfg80211 will in fact |
| 4799 | * deauthenticate. However, it doesn't (and cannot) stop an ongoing |
| 4800 | * auth (not so important) or assoc (this is the problem) process. |
| 4801 | * |
| 4802 | * As a consequence, it can happen that we are in the process of both |
| 4803 | * associating and suspending, and receive an association response |
| 4804 | * after cfg80211 has checked if it needs to disconnect, but before |
| 4805 | * we actually set the flag to drop incoming frames. This will then |
| 4806 | * cause the workqueue flush to process the association response in |
| 4807 | * the suspend, resulting in a successful association just before it |
| 4808 | * tries to remove the interface from the driver, which now though |
| 4809 | * has a channel context assigned ... this results in issues. |
| 4810 | * |
| 4811 | * To work around this (for now) simply deauth here again if we're |
| 4812 | * now connected. |
| 4813 | */ |
| 4814 | if (ifmgd->associated && !sdata->local->wowlan) { |
| 4815 | u8 bssid[ETH_ALEN]; |
| 4816 | struct cfg80211_deauth_request req = { |
| 4817 | .reason_code = WLAN_REASON_DEAUTH_LEAVING, |
| 4818 | .bssid = bssid, |
| 4819 | }; |
| 4820 | |
| 4821 | memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN); |
| 4822 | ieee80211_mgd_deauth(sdata, &req); |
| 4823 | } |
| 4824 | |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4825 | sdata_unlock(sdata); |
| 4826 | } |
| 4827 | |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4828 | void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata) |
| 4829 | { |
| 4830 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 4831 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4832 | sdata_lock(sdata); |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4833 | if (!ifmgd->associated) { |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4834 | sdata_unlock(sdata); |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4835 | return; |
| 4836 | } |
| 4837 | |
| 4838 | if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) { |
| 4839 | sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME; |
| 4840 | mlme_dbg(sdata, "driver requested disconnect after resume\n"); |
| 4841 | ieee80211_sta_connection_lost(sdata, |
| 4842 | ifmgd->associated->bssid, |
| 4843 | WLAN_REASON_UNSPECIFIED, |
| 4844 | true); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4845 | sdata_unlock(sdata); |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4846 | return; |
| 4847 | } |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4848 | sdata_unlock(sdata); |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4849 | } |
| 4850 | #endif |
| 4851 | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 4852 | /* interface setup */ |
| 4853 | void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata) |
| 4854 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 4855 | struct ieee80211_if_managed *ifmgd; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 4856 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 4857 | ifmgd = &sdata->u.mgd; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4858 | INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 4859 | INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 4860 | INIT_WORK(&ifmgd->beacon_connection_loss_work, |
| 4861 | ieee80211_beacon_connection_loss_work); |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 4862 | INIT_WORK(&ifmgd->csa_connection_drop_work, |
| 4863 | ieee80211_csa_connection_drop_work); |
Emmanuel Grumbach | 687da13 | 2013-10-01 16:45:43 +0300 | [diff] [blame] | 4864 | INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work); |
Arik Nemtsov | 81dd2b8 | 2014-07-17 17:14:25 +0300 | [diff] [blame] | 4865 | INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work, |
| 4866 | ieee80211_tdls_peer_del_work); |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4867 | timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0); |
| 4868 | timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0); |
| 4869 | timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0); |
| 4870 | timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0); |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 4871 | INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk, |
| 4872 | ieee80211_sta_handle_tspec_ac_params_wk); |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 4873 | |
Johannes Berg | ab1faea | 2009-07-01 21:41:17 +0200 | [diff] [blame] | 4874 | ifmgd->flags = 0; |
Mohammed Shafi Shajakhan | 1478acb | 2011-12-14 19:46:08 +0530 | [diff] [blame] | 4875 | ifmgd->powersave = sdata->wdev.ps; |
Alexander Bondar | 219c386 | 2013-01-22 16:52:23 +0200 | [diff] [blame] | 4876 | ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues; |
| 4877 | ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len; |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 4878 | ifmgd->p2p_noa_index = -1; |
Johannes Berg | bbbdff9 | 2009-04-16 13:27:42 +0200 | [diff] [blame] | 4879 | |
Eliad Peller | 0d8614b | 2014-09-10 14:07:36 +0300 | [diff] [blame] | 4880 | if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS) |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 4881 | ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC; |
| 4882 | else |
| 4883 | ifmgd->req_smps = IEEE80211_SMPS_OFF; |
Liad Kaufman | 1277b4a | 2014-11-09 18:50:08 +0200 | [diff] [blame] | 4884 | |
| 4885 | /* Setup TDLS data */ |
| 4886 | spin_lock_init(&ifmgd->teardown_lock); |
| 4887 | ifmgd->teardown_skb = NULL; |
| 4888 | ifmgd->orig_teardown_skb = NULL; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 4889 | } |
| 4890 | |
| 4891 | /* scan finished notification */ |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 4892 | void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local) |
| 4893 | { |
Johannes Berg | 31ee67a | 2012-07-06 21:18:24 +0200 | [diff] [blame] | 4894 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 4895 | |
| 4896 | /* Restart STA timers */ |
| 4897 | rcu_read_lock(); |
Ben Greear | 370bd00 | 2013-03-19 17:50:50 -0700 | [diff] [blame] | 4898 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
| 4899 | if (ieee80211_sdata_running(sdata)) |
| 4900 | ieee80211_restart_sta_timer(sdata); |
| 4901 | } |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 4902 | rcu_read_unlock(); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 4903 | } |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 4904 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4905 | static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata, |
| 4906 | struct cfg80211_bss *cbss) |
| 4907 | { |
| 4908 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | b3c1906 | 2021-12-20 11:36:10 +0100 | [diff] [blame] | 4909 | const struct element *ht_cap_elem, *vht_cap_elem; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4910 | const struct ieee80211_ht_cap *ht_cap; |
| 4911 | const struct ieee80211_vht_cap *vht_cap; |
| 4912 | u8 chains = 1; |
| 4913 | |
| 4914 | if (ifmgd->flags & IEEE80211_STA_DISABLE_HT) |
| 4915 | return chains; |
| 4916 | |
Johannes Berg | b3c1906 | 2021-12-20 11:36:10 +0100 | [diff] [blame] | 4917 | ht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_CAPABILITY); |
| 4918 | if (ht_cap_elem && ht_cap_elem->datalen >= sizeof(*ht_cap)) { |
| 4919 | ht_cap = (void *)ht_cap_elem->data; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4920 | chains = ieee80211_mcs_to_chains(&ht_cap->mcs); |
| 4921 | /* |
| 4922 | * TODO: use "Tx Maximum Number Spatial Streams Supported" and |
| 4923 | * "Tx Unequal Modulation Supported" fields. |
| 4924 | */ |
| 4925 | } |
| 4926 | |
| 4927 | if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT) |
| 4928 | return chains; |
| 4929 | |
Johannes Berg | b3c1906 | 2021-12-20 11:36:10 +0100 | [diff] [blame] | 4930 | vht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY); |
| 4931 | if (vht_cap_elem && vht_cap_elem->datalen >= sizeof(*vht_cap)) { |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4932 | u8 nss; |
| 4933 | u16 tx_mcs_map; |
| 4934 | |
Johannes Berg | b3c1906 | 2021-12-20 11:36:10 +0100 | [diff] [blame] | 4935 | vht_cap = (void *)vht_cap_elem->data; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4936 | tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map); |
| 4937 | for (nss = 8; nss > 0; nss--) { |
| 4938 | if (((tx_mcs_map >> (2 * (nss - 1))) & 3) != |
| 4939 | IEEE80211_VHT_MCS_NOT_SUPPORTED) |
| 4940 | break; |
| 4941 | } |
| 4942 | /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */ |
| 4943 | chains = max(chains, nss); |
| 4944 | } |
| 4945 | |
| 4946 | return chains; |
| 4947 | } |
| 4948 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4949 | static bool |
Johannes Berg | bac2fd3 | 2021-06-18 13:41:50 +0300 | [diff] [blame] | 4950 | ieee80211_verify_sta_he_mcs_support(struct ieee80211_sub_if_data *sdata, |
| 4951 | struct ieee80211_supported_band *sband, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4952 | const struct ieee80211_he_operation *he_op) |
| 4953 | { |
| 4954 | const struct ieee80211_sta_he_cap *sta_he_cap = |
Johannes Berg | bac2fd3 | 2021-06-18 13:41:50 +0300 | [diff] [blame] | 4955 | ieee80211_get_he_iftype_cap(sband, |
| 4956 | ieee80211_vif_type_p2p(&sdata->vif)); |
Gustavo A. R. Silva | 47aa786 | 2018-06-18 07:41:34 -0500 | [diff] [blame] | 4957 | u16 ap_min_req_set; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4958 | int i; |
| 4959 | |
| 4960 | if (!sta_he_cap || !he_op) |
| 4961 | return false; |
| 4962 | |
Gustavo A. R. Silva | 47aa786 | 2018-06-18 07:41:34 -0500 | [diff] [blame] | 4963 | ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set); |
| 4964 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4965 | /* Need to go over for 80MHz, 160MHz and for 80+80 */ |
| 4966 | for (i = 0; i < 3; i++) { |
| 4967 | const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp = |
| 4968 | &sta_he_cap->he_mcs_nss_supp; |
| 4969 | u16 sta_mcs_map_rx = |
| 4970 | le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]); |
| 4971 | u16 sta_mcs_map_tx = |
| 4972 | le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]); |
| 4973 | u8 nss; |
| 4974 | bool verified = true; |
| 4975 | |
| 4976 | /* |
| 4977 | * For each band there is a maximum of 8 spatial streams |
| 4978 | * possible. Each of the sta_mcs_map_* is a 16-bit struct built |
| 4979 | * of 2 bits per NSS (1-8), with the values defined in enum |
| 4980 | * ieee80211_he_mcs_support. Need to make sure STA TX and RX |
| 4981 | * capabilities aren't less than the AP's minimum requirements |
| 4982 | * for this HE BSS per SS. |
| 4983 | * It is enough to find one such band that meets the reqs. |
| 4984 | */ |
| 4985 | for (nss = 8; nss > 0; nss--) { |
| 4986 | u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3; |
| 4987 | u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3; |
| 4988 | u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3; |
| 4989 | |
| 4990 | if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED) |
| 4991 | continue; |
| 4992 | |
| 4993 | /* |
| 4994 | * Make sure the HE AP doesn't require MCSs that aren't |
| 4995 | * supported by the client |
| 4996 | */ |
| 4997 | if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED || |
| 4998 | sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED || |
| 4999 | (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) { |
| 5000 | verified = false; |
| 5001 | break; |
| 5002 | } |
| 5003 | } |
| 5004 | |
| 5005 | if (verified) |
| 5006 | return true; |
| 5007 | } |
| 5008 | |
| 5009 | /* If here, STA doesn't meet AP's HE min requirements */ |
| 5010 | return false; |
| 5011 | } |
| 5012 | |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 5013 | static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata, |
| 5014 | struct cfg80211_bss *cbss) |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5015 | { |
| 5016 | struct ieee80211_local *local = sdata->local; |
| 5017 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Eliad Peller | 53b954e | 2014-07-24 11:20:05 +0300 | [diff] [blame] | 5018 | const struct ieee80211_ht_cap *ht_cap = NULL; |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 5019 | const struct ieee80211_ht_operation *ht_oper = NULL; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 5020 | const struct ieee80211_vht_operation *vht_oper = NULL; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 5021 | const struct ieee80211_he_operation *he_oper = NULL; |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 5022 | const struct ieee80211_s1g_oper_ie *s1g_oper = NULL; |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 5023 | struct ieee80211_supported_band *sband; |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 5024 | struct cfg80211_chan_def chandef; |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 5025 | bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ; |
Wen Gong | 780a8c9 | 2020-09-11 10:29:02 +0000 | [diff] [blame] | 5026 | bool is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ; |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 5027 | struct ieee80211_bss *bss = (void *)cbss->priv; |
Wen Gong | 37123c3 | 2021-09-24 06:00:51 -0400 | [diff] [blame] | 5028 | struct ieee802_11_elems *elems; |
| 5029 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 5030 | int ret; |
Arik Nemtsov | 52a45f3 | 2015-08-15 22:39:53 +0300 | [diff] [blame] | 5031 | u32 i; |
| 5032 | bool have_80mhz; |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5033 | |
Wen Gong | 37123c3 | 2021-09-24 06:00:51 -0400 | [diff] [blame] | 5034 | rcu_read_lock(); |
| 5035 | |
| 5036 | ies = rcu_dereference(cbss->ies); |
| 5037 | elems = ieee802_11_parse_elems(ies->data, ies->len, false, |
| 5038 | NULL, NULL); |
| 5039 | if (!elems) { |
| 5040 | rcu_read_unlock(); |
| 5041 | return -ENOMEM; |
| 5042 | } |
| 5043 | |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 5044 | sband = local->hw.wiphy->bands[cbss->channel->band]; |
| 5045 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 5046 | ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ | |
| 5047 | IEEE80211_STA_DISABLE_80P80MHZ | |
| 5048 | IEEE80211_STA_DISABLE_160MHZ); |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 5049 | |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 5050 | /* disable HT/VHT/HE if we don't support them */ |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 5051 | if (!sband->ht_cap.ht_supported && !is_6ghz) { |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 5052 | mlme_dbg(sdata, "HT not supported, disabling HT/VHT/HE\n"); |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 5053 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
| 5054 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
| 5055 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
| 5056 | } |
| 5057 | |
Wen Gong | 780a8c9 | 2020-09-11 10:29:02 +0000 | [diff] [blame] | 5058 | if (!sband->vht_cap.vht_supported && is_5ghz) { |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 5059 | mlme_dbg(sdata, "VHT not supported, disabling VHT/HE\n"); |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 5060 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 5061 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
| 5062 | } |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 5063 | |
Johannes Berg | bac2fd3 | 2021-06-18 13:41:50 +0300 | [diff] [blame] | 5064 | if (!ieee80211_get_he_iftype_cap(sband, |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 5065 | ieee80211_vif_type_p2p(&sdata->vif))) { |
| 5066 | mlme_dbg(sdata, "HE not supported, disabling it\n"); |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 5067 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 5068 | } |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 5069 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 5070 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) && !is_6ghz) { |
Wen Gong | 37123c3 | 2021-09-24 06:00:51 -0400 | [diff] [blame] | 5071 | ht_oper = elems->ht_operation; |
| 5072 | ht_cap = elems->ht_cap_elem; |
Eliad Peller | 53b954e | 2014-07-24 11:20:05 +0300 | [diff] [blame] | 5073 | |
| 5074 | if (!ht_cap) { |
Johannes Berg | 08e6effa | 2013-02-07 23:33:32 +0100 | [diff] [blame] | 5075 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
| 5076 | ht_oper = NULL; |
| 5077 | } |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 5078 | } |
| 5079 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 5080 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && !is_6ghz) { |
Wen Gong | 37123c3 | 2021-09-24 06:00:51 -0400 | [diff] [blame] | 5081 | vht_oper = elems->vht_operation; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 5082 | if (vht_oper && !ht_oper) { |
| 5083 | vht_oper = NULL; |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 5084 | sdata_info(sdata, |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 5085 | "AP advertised VHT without HT, disabling HT/VHT/HE\n"); |
Johannes Berg | cb14502 | 2013-02-07 20:41:50 +0100 | [diff] [blame] | 5086 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
| 5087 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 5088 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 5089 | } |
Johannes Berg | 08e6effa | 2013-02-07 23:33:32 +0100 | [diff] [blame] | 5090 | |
Wen Gong | 37123c3 | 2021-09-24 06:00:51 -0400 | [diff] [blame] | 5091 | if (!elems->vht_cap_elem) { |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 5092 | sdata_info(sdata, |
| 5093 | "bad VHT capabilities, disabling VHT\n"); |
Johannes Berg | 08e6effa | 2013-02-07 23:33:32 +0100 | [diff] [blame] | 5094 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
| 5095 | vht_oper = NULL; |
| 5096 | } |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 5097 | } |
| 5098 | |
Shaul Triebitz | 002245e | 2018-12-15 11:03:19 +0200 | [diff] [blame] | 5099 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) { |
Wen Gong | 37123c3 | 2021-09-24 06:00:51 -0400 | [diff] [blame] | 5100 | he_oper = elems->he_operation; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 5101 | |
Wen Gong | 63214f0 | 2021-09-24 06:00:52 -0400 | [diff] [blame] | 5102 | if (is_6ghz) { |
| 5103 | struct ieee80211_bss_conf *bss_conf; |
| 5104 | u8 i, j = 0; |
| 5105 | |
| 5106 | bss_conf = &sdata->vif.bss_conf; |
| 5107 | |
| 5108 | if (elems->pwr_constr_elem) |
| 5109 | bss_conf->pwr_reduction = *elems->pwr_constr_elem; |
| 5110 | |
| 5111 | BUILD_BUG_ON(ARRAY_SIZE(bss_conf->tx_pwr_env) != |
| 5112 | ARRAY_SIZE(elems->tx_pwr_env)); |
| 5113 | |
| 5114 | for (i = 0; i < elems->tx_pwr_env_num; i++) { |
| 5115 | if (elems->tx_pwr_env_len[i] > |
| 5116 | sizeof(bss_conf->tx_pwr_env[j])) |
| 5117 | continue; |
| 5118 | |
| 5119 | bss_conf->tx_pwr_env_num++; |
| 5120 | memcpy(&bss_conf->tx_pwr_env[j], elems->tx_pwr_env[i], |
| 5121 | elems->tx_pwr_env_len[i]); |
| 5122 | j++; |
| 5123 | } |
| 5124 | } |
| 5125 | |
Johannes Berg | bac2fd3 | 2021-06-18 13:41:50 +0300 | [diff] [blame] | 5126 | if (!ieee80211_verify_sta_he_mcs_support(sdata, sband, he_oper)) |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 5127 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
| 5128 | } |
| 5129 | |
Arik Nemtsov | 52a45f3 | 2015-08-15 22:39:53 +0300 | [diff] [blame] | 5130 | /* Allow VHT if at least one channel on the sband supports 80 MHz */ |
| 5131 | have_80mhz = false; |
| 5132 | for (i = 0; i < sband->n_channels; i++) { |
| 5133 | if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED | |
| 5134 | IEEE80211_CHAN_NO_80MHZ)) |
| 5135 | continue; |
| 5136 | |
| 5137 | have_80mhz = true; |
| 5138 | break; |
| 5139 | } |
| 5140 | |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 5141 | if (!have_80mhz) { |
| 5142 | sdata_info(sdata, "80 MHz not supported, disabling VHT\n"); |
Arik Nemtsov | 52a45f3 | 2015-08-15 22:39:53 +0300 | [diff] [blame] | 5143 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 5144 | } |
Arik Nemtsov | 52a45f3 | 2015-08-15 22:39:53 +0300 | [diff] [blame] | 5145 | |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 5146 | if (sband->band == NL80211_BAND_S1GHZ) { |
Wen Gong | 37123c3 | 2021-09-24 06:00:51 -0400 | [diff] [blame] | 5147 | s1g_oper = elems->s1g_oper; |
| 5148 | if (!s1g_oper) |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 5149 | sdata_info(sdata, |
| 5150 | "AP missing S1G operation element?\n"); |
| 5151 | } |
| 5152 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 5153 | ifmgd->flags |= ieee80211_determine_chantype(sdata, sband, |
| 5154 | cbss->channel, |
Johannes Berg | 2a333a0 | 2020-05-28 21:34:35 +0200 | [diff] [blame] | 5155 | bss->vht_cap_info, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 5156 | ht_oper, vht_oper, he_oper, |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 5157 | s1g_oper, |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 5158 | &chandef, false); |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 5159 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 5160 | sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss), |
| 5161 | local->rx_chains); |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 5162 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5163 | rcu_read_unlock(); |
Wen Gong | 37123c3 | 2021-09-24 06:00:51 -0400 | [diff] [blame] | 5164 | /* the element data was RCU protected so no longer valid anyway */ |
| 5165 | kfree(elems); |
| 5166 | elems = NULL; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5167 | |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 5168 | if (ifmgd->flags & IEEE80211_STA_DISABLE_HE && is_6ghz) { |
| 5169 | sdata_info(sdata, "Rejecting non-HE 6/7 GHz connection"); |
| 5170 | return -EINVAL; |
| 5171 | } |
| 5172 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 5173 | /* will change later if needed */ |
| 5174 | sdata->smps_mode = IEEE80211_SMPS_OFF; |
| 5175 | |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 5176 | mutex_lock(&local->mtx); |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 5177 | /* |
| 5178 | * If this fails (possibly due to channel context sharing |
| 5179 | * on incompatible channels, e.g. 80+80 and 160 sharing the |
| 5180 | * same control channel) try to use a smaller bandwidth. |
| 5181 | */ |
| 5182 | ret = ieee80211_vif_use_channel(sdata, &chandef, |
| 5183 | IEEE80211_CHANCTX_SHARED); |
Simon Wunderlich | 0418a44 | 2013-05-16 13:00:31 +0200 | [diff] [blame] | 5184 | |
| 5185 | /* don't downgrade for 5 and 10 MHz channels, though. */ |
| 5186 | if (chandef.width == NL80211_CHAN_WIDTH_5 || |
| 5187 | chandef.width == NL80211_CHAN_WIDTH_10) |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 5188 | goto out; |
Simon Wunderlich | 0418a44 | 2013-05-16 13:00:31 +0200 | [diff] [blame] | 5189 | |
Johannes Berg | d601cd8 | 2013-02-07 20:54:51 +0100 | [diff] [blame] | 5190 | while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) { |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 5191 | ifmgd->flags |= ieee80211_chandef_downgrade(&chandef); |
Johannes Berg | d601cd8 | 2013-02-07 20:54:51 +0100 | [diff] [blame] | 5192 | ret = ieee80211_vif_use_channel(sdata, &chandef, |
| 5193 | IEEE80211_CHANCTX_SHARED); |
| 5194 | } |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 5195 | out: |
| 5196 | mutex_unlock(&local->mtx); |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 5197 | return ret; |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 5198 | } |
| 5199 | |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 5200 | static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies, |
| 5201 | u8 *dtim_count, u8 *dtim_period) |
| 5202 | { |
| 5203 | const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len); |
| 5204 | const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data, |
| 5205 | ies->len); |
| 5206 | const struct ieee80211_tim_ie *tim = NULL; |
| 5207 | const struct ieee80211_bssid_index *idx; |
| 5208 | bool valid = tim_ie && tim_ie[1] >= 2; |
| 5209 | |
| 5210 | if (valid) |
| 5211 | tim = (void *)(tim_ie + 2); |
| 5212 | |
| 5213 | if (dtim_count) |
| 5214 | *dtim_count = valid ? tim->dtim_count : 0; |
| 5215 | |
| 5216 | if (dtim_period) |
| 5217 | *dtim_period = valid ? tim->dtim_period : 0; |
| 5218 | |
| 5219 | /* Check if value is overridden by non-transmitted profile */ |
| 5220 | if (!idx_ie || idx_ie[1] < 3) |
| 5221 | return valid; |
| 5222 | |
| 5223 | idx = (void *)(idx_ie + 2); |
| 5224 | |
| 5225 | if (dtim_count) |
| 5226 | *dtim_count = idx->dtim_count; |
| 5227 | |
| 5228 | if (dtim_period) |
| 5229 | *dtim_period = idx->dtim_period; |
| 5230 | |
| 5231 | return true; |
| 5232 | } |
| 5233 | |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 5234 | static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata, |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 5235 | struct cfg80211_bss *cbss, bool assoc, |
| 5236 | bool override) |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 5237 | { |
| 5238 | struct ieee80211_local *local = sdata->local; |
| 5239 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 5240 | struct ieee80211_bss *bss = (void *)cbss->priv; |
| 5241 | struct sta_info *new_sta = NULL; |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 5242 | struct ieee80211_supported_band *sband; |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 5243 | bool have_sta = false; |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 5244 | int err; |
| 5245 | |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 5246 | sband = local->hw.wiphy->bands[cbss->channel->band]; |
| 5247 | |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 5248 | if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data)) |
| 5249 | return -EINVAL; |
| 5250 | |
Luca Coelho | f8860ce | 2017-05-02 17:56:21 +0300 | [diff] [blame] | 5251 | /* If a reconfig is happening, bail out */ |
| 5252 | if (local->in_reconfig) |
| 5253 | return -EBUSY; |
| 5254 | |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 5255 | if (assoc) { |
| 5256 | rcu_read_lock(); |
| 5257 | have_sta = sta_info_get(sdata, cbss->bssid); |
| 5258 | rcu_read_unlock(); |
| 5259 | } |
| 5260 | |
| 5261 | if (!have_sta) { |
| 5262 | new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL); |
| 5263 | if (!new_sta) |
| 5264 | return -ENOMEM; |
| 5265 | } |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 5266 | |
Johannes Berg | c87905b | 2017-06-10 13:52:43 +0300 | [diff] [blame] | 5267 | /* |
| 5268 | * Set up the information for the new channel before setting the |
| 5269 | * new channel. We can't - completely race-free - change the basic |
| 5270 | * rates bitmap and the channel (sband) that it refers to, but if |
| 5271 | * we set it up before we at least avoid calling into the driver's |
| 5272 | * bss_info_changed() method with invalid information (since we do |
| 5273 | * call that from changing the channel - only for IDLE and perhaps |
| 5274 | * some others, but ...). |
| 5275 | * |
| 5276 | * So to avoid that, just set up all the new information before the |
| 5277 | * channel, but tell the driver to apply it only afterwards, since |
| 5278 | * it might need the new channel for that. |
| 5279 | */ |
Johannes Berg | 13e0c8e | 2012-07-27 10:43:16 +0200 | [diff] [blame] | 5280 | if (new_sta) { |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5281 | u32 rates = 0, basic_rates = 0; |
Tom Rix | 68a18ad | 2021-12-23 08:28:48 -0800 | [diff] [blame] | 5282 | bool have_higher_than_11mbit = false; |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5283 | int min_rate = INT_MAX, min_rate_index = -1; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5284 | const struct cfg80211_bss_ies *ies; |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 5285 | int shift = ieee80211_vif_get_shift(&sdata->vif); |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5286 | |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 5287 | /* TODO: S1G Basic Rate Set is expressed elsewhere */ |
Thomas Pedersen | 12bf8fa | 2020-10-05 09:45:22 -0700 | [diff] [blame] | 5288 | if (cbss->channel->band == NL80211_BAND_S1GHZ) { |
| 5289 | ieee80211_s1g_sta_rate_init(new_sta); |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 5290 | goto skip_rates; |
Thomas Pedersen | 12bf8fa | 2020-10-05 09:45:22 -0700 | [diff] [blame] | 5291 | } |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 5292 | |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5293 | ieee80211_get_rates(sband, bss->supp_rates, |
| 5294 | bss->supp_rates_len, |
| 5295 | &rates, &basic_rates, |
| 5296 | &have_higher_than_11mbit, |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 5297 | &min_rate, &min_rate_index, |
Johannes Berg | 44f6d42 | 2017-06-10 13:52:44 +0300 | [diff] [blame] | 5298 | shift); |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5299 | |
| 5300 | /* |
| 5301 | * This used to be a workaround for basic rates missing |
| 5302 | * in the association response frame. Now that we no |
| 5303 | * longer use the basic rates from there, it probably |
| 5304 | * doesn't happen any more, but keep the workaround so |
| 5305 | * in case some *other* APs are buggy in different ways |
| 5306 | * we can connect -- with a warning. |
Ilan Peer | 302ff8b | 2020-03-26 15:09:39 +0200 | [diff] [blame] | 5307 | * Allow this workaround only in case the AP provided at least |
| 5308 | * one rate. |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5309 | */ |
Ilan Peer | 302ff8b | 2020-03-26 15:09:39 +0200 | [diff] [blame] | 5310 | if (min_rate_index < 0) { |
| 5311 | sdata_info(sdata, |
| 5312 | "No legacy rates in association response\n"); |
| 5313 | |
| 5314 | sta_info_free(local, new_sta); |
| 5315 | return -EINVAL; |
| 5316 | } else if (!basic_rates) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 5317 | sdata_info(sdata, |
| 5318 | "No basic rates, using min rate instead\n"); |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5319 | basic_rates = BIT(min_rate_index); |
| 5320 | } |
| 5321 | |
Johannes Berg | bd718fc | 2019-05-29 15:25:35 +0300 | [diff] [blame] | 5322 | if (rates) |
| 5323 | new_sta->sta.supp_rates[cbss->channel->band] = rates; |
| 5324 | else |
| 5325 | sdata_info(sdata, |
| 5326 | "No rates found, keeping mandatory only\n"); |
| 5327 | |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5328 | sdata->vif.bss_conf.basic_rates = basic_rates; |
| 5329 | |
| 5330 | /* cf. IEEE 802.11 9.2.12 */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5331 | if (cbss->channel->band == NL80211_BAND_2GHZ && |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5332 | have_higher_than_11mbit) |
| 5333 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; |
| 5334 | else |
| 5335 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; |
| 5336 | |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 5337 | skip_rates: |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5338 | memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN); |
| 5339 | |
Johannes Berg | 8c358bc | 2012-05-22 22:13:05 +0200 | [diff] [blame] | 5340 | /* set timing information */ |
| 5341 | sdata->vif.bss_conf.beacon_int = cbss->beacon_interval; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5342 | rcu_read_lock(); |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5343 | ies = rcu_dereference(cbss->beacon_ies); |
| 5344 | if (ies) { |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5345 | sdata->vif.bss_conf.sync_tsf = ies->tsf; |
| 5346 | sdata->vif.bss_conf.sync_device_ts = |
| 5347 | bss->device_ts_beacon; |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 5348 | |
| 5349 | ieee80211_get_dtim(ies, |
| 5350 | &sdata->vif.bss_conf.sync_dtim_count, |
| 5351 | NULL); |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 5352 | } else if (!ieee80211_hw_check(&sdata->local->hw, |
| 5353 | TIMING_BEACON_ONLY)) { |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5354 | ies = rcu_dereference(cbss->proberesp_ies); |
| 5355 | /* must be non-NULL since beacon IEs were NULL */ |
| 5356 | sdata->vif.bss_conf.sync_tsf = ies->tsf; |
| 5357 | sdata->vif.bss_conf.sync_device_ts = |
| 5358 | bss->device_ts_presp; |
| 5359 | sdata->vif.bss_conf.sync_dtim_count = 0; |
| 5360 | } else { |
| 5361 | sdata->vif.bss_conf.sync_tsf = 0; |
| 5362 | sdata->vif.bss_conf.sync_device_ts = 0; |
| 5363 | sdata->vif.bss_conf.sync_dtim_count = 0; |
| 5364 | } |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5365 | rcu_read_unlock(); |
Johannes Berg | c87905b | 2017-06-10 13:52:43 +0300 | [diff] [blame] | 5366 | } |
Johannes Berg | 8c358bc | 2012-05-22 22:13:05 +0200 | [diff] [blame] | 5367 | |
Johannes Berg | c87905b | 2017-06-10 13:52:43 +0300 | [diff] [blame] | 5368 | if (new_sta || override) { |
| 5369 | err = ieee80211_prep_channel(sdata, cbss); |
| 5370 | if (err) { |
| 5371 | if (new_sta) |
| 5372 | sta_info_free(local, new_sta); |
| 5373 | return -EINVAL; |
| 5374 | } |
| 5375 | } |
| 5376 | |
| 5377 | if (new_sta) { |
| 5378 | /* |
| 5379 | * tell driver about BSSID, basic rates and timing |
| 5380 | * this was set up above, before setting the channel |
| 5381 | */ |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5382 | ieee80211_bss_info_change_notify(sdata, |
Johannes Berg | 8c358bc | 2012-05-22 22:13:05 +0200 | [diff] [blame] | 5383 | BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES | |
| 5384 | BSS_CHANGED_BEACON_INT); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5385 | |
| 5386 | if (assoc) |
Johannes Berg | 13e0c8e | 2012-07-27 10:43:16 +0200 | [diff] [blame] | 5387 | sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5388 | |
Johannes Berg | 13e0c8e | 2012-07-27 10:43:16 +0200 | [diff] [blame] | 5389 | err = sta_info_insert(new_sta); |
| 5390 | new_sta = NULL; |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5391 | if (err) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 5392 | sdata_info(sdata, |
| 5393 | "failed to insert STA entry for the AP (error %d)\n", |
| 5394 | err); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5395 | return err; |
| 5396 | } |
| 5397 | } else |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 5398 | WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid)); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5399 | |
David Spinadel | 7d830a1 | 2015-03-17 19:58:38 +0200 | [diff] [blame] | 5400 | /* Cancel scan to ensure that nothing interferes with connection */ |
| 5401 | if (local->scanning) |
| 5402 | ieee80211_scan_cancel(local); |
| 5403 | |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5404 | return 0; |
| 5405 | } |
| 5406 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5407 | /* config hooks */ |
| 5408 | int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata, |
| 5409 | struct cfg80211_auth_request *req) |
| 5410 | { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5411 | struct ieee80211_local *local = sdata->local; |
| 5412 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 5413 | struct ieee80211_mgd_auth_data *auth_data; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5414 | u16 auth_alg; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5415 | int err; |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5416 | bool cont_auth; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5417 | |
| 5418 | /* prepare auth data structure */ |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5419 | |
| 5420 | switch (req->auth_type) { |
| 5421 | case NL80211_AUTHTYPE_OPEN_SYSTEM: |
| 5422 | auth_alg = WLAN_AUTH_OPEN; |
| 5423 | break; |
| 5424 | case NL80211_AUTHTYPE_SHARED_KEY: |
Ard Biesheuvel | 5fdb373 | 2019-06-12 18:19:54 +0200 | [diff] [blame] | 5425 | if (fips_enabled) |
Johannes Berg | 9dca9c4 | 2010-07-21 10:09:25 +0200 | [diff] [blame] | 5426 | return -EOPNOTSUPP; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5427 | auth_alg = WLAN_AUTH_SHARED_KEY; |
| 5428 | break; |
| 5429 | case NL80211_AUTHTYPE_FT: |
| 5430 | auth_alg = WLAN_AUTH_FT; |
| 5431 | break; |
| 5432 | case NL80211_AUTHTYPE_NETWORK_EAP: |
| 5433 | auth_alg = WLAN_AUTH_LEAP; |
| 5434 | break; |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 5435 | case NL80211_AUTHTYPE_SAE: |
| 5436 | auth_alg = WLAN_AUTH_SAE; |
| 5437 | break; |
Jouni Malinen | dbc0c2c | 2016-10-27 00:42:04 +0300 | [diff] [blame] | 5438 | case NL80211_AUTHTYPE_FILS_SK: |
| 5439 | auth_alg = WLAN_AUTH_FILS_SK; |
| 5440 | break; |
| 5441 | case NL80211_AUTHTYPE_FILS_SK_PFS: |
| 5442 | auth_alg = WLAN_AUTH_FILS_SK_PFS; |
| 5443 | break; |
| 5444 | case NL80211_AUTHTYPE_FILS_PK: |
| 5445 | auth_alg = WLAN_AUTH_FILS_PK; |
| 5446 | break; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5447 | default: |
| 5448 | return -EOPNOTSUPP; |
| 5449 | } |
| 5450 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5451 | if (ifmgd->assoc_data) |
Jouni Malinen | 8d7432a | 2018-10-11 00:21:20 +0300 | [diff] [blame] | 5452 | return -EBUSY; |
| 5453 | |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 5454 | auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len + |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 5455 | req->ie_len, GFP_KERNEL); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5456 | if (!auth_data) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5457 | return -ENOMEM; |
| 5458 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5459 | auth_data->bss = req->bss; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5460 | |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 5461 | if (req->auth_data_len >= 4) { |
Jouni Malinen | 6ec6361 | 2016-10-27 00:41:59 +0300 | [diff] [blame] | 5462 | if (req->auth_type == NL80211_AUTHTYPE_SAE) { |
| 5463 | __le16 *pos = (__le16 *) req->auth_data; |
| 5464 | |
| 5465 | auth_data->sae_trans = le16_to_cpu(pos[0]); |
| 5466 | auth_data->sae_status = le16_to_cpu(pos[1]); |
| 5467 | } |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 5468 | memcpy(auth_data->data, req->auth_data + 4, |
| 5469 | req->auth_data_len - 4); |
| 5470 | auth_data->data_len += req->auth_data_len - 4; |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 5471 | } |
| 5472 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5473 | /* Check if continuing authentication or trying to authenticate with the |
| 5474 | * same BSS that we were in the process of authenticating with and avoid |
| 5475 | * removal and re-addition of the STA entry in |
| 5476 | * ieee80211_prep_connection(). |
| 5477 | */ |
| 5478 | cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss; |
| 5479 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5480 | if (req->ie && req->ie_len) { |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 5481 | memcpy(&auth_data->data[auth_data->data_len], |
| 5482 | req->ie, req->ie_len); |
| 5483 | auth_data->data_len += req->ie_len; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5484 | } |
| 5485 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5486 | if (req->key && req->key_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5487 | auth_data->key_len = req->key_len; |
| 5488 | auth_data->key_idx = req->key_idx; |
| 5489 | memcpy(auth_data->key, req->key, req->key_len); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5490 | } |
| 5491 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5492 | auth_data->algorithm = auth_alg; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5493 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5494 | /* try to authenticate/probe */ |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 5495 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5496 | if (ifmgd->auth_data) { |
| 5497 | if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) { |
| 5498 | auth_data->peer_confirmed = |
| 5499 | ifmgd->auth_data->peer_confirmed; |
| 5500 | } |
| 5501 | ieee80211_destroy_auth_data(sdata, cont_auth); |
| 5502 | } |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 5503 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5504 | /* prep auth_data so we don't go into idle on disassoc */ |
| 5505 | ifmgd->auth_data = auth_data; |
| 5506 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5507 | /* If this is continuation of an ongoing SAE authentication exchange |
| 5508 | * (i.e., request to send SAE Confirm) and the peer has already |
| 5509 | * confirmed, mark authentication completed since we are about to send |
| 5510 | * out SAE Confirm. |
| 5511 | */ |
| 5512 | if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE && |
| 5513 | auth_data->peer_confirmed && auth_data->sae_trans == 2) |
| 5514 | ieee80211_mark_sta_auth(sdata, req->bss->bssid); |
| 5515 | |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5516 | if (ifmgd->associated) { |
| 5517 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
| 5518 | |
Johannes Berg | 89f774e | 2016-01-25 15:46:36 +0200 | [diff] [blame] | 5519 | sdata_info(sdata, |
| 5520 | "disconnect from AP %pM for new auth to %pM\n", |
| 5521 | ifmgd->associated->bssid, req->bss->bssid); |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5522 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
| 5523 | WLAN_REASON_UNSPECIFIED, |
| 5524 | false, frame_buf); |
| 5525 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 5526 | ieee80211_report_disconnect(sdata, frame_buf, |
| 5527 | sizeof(frame_buf), true, |
Johannes Berg | 3f8a39f | 2020-12-06 14:54:43 +0200 | [diff] [blame] | 5528 | WLAN_REASON_UNSPECIFIED, |
| 5529 | false); |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5530 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5531 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 5532 | sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5533 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5534 | err = ieee80211_prep_connection(sdata, req->bss, cont_auth, false); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5535 | if (err) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5536 | goto err_clear; |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 5537 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 5538 | err = ieee80211_auth(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5539 | if (err) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5540 | sta_info_destroy_addr(sdata, req->bss->bssid); |
| 5541 | goto err_clear; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5542 | } |
| 5543 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5544 | /* hold our own reference */ |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 5545 | cfg80211_ref_bss(local->hw.wiphy, auth_data->bss); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 5546 | return 0; |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 5547 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5548 | err_clear: |
Joe Perches | c84a67a | 2015-03-02 19:54:57 -0800 | [diff] [blame] | 5549 | eth_zero_addr(ifmgd->bssid); |
Eliad Peller | 3d2abdf | 2012-09-04 17:44:45 +0300 | [diff] [blame] | 5550 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5551 | ifmgd->auth_data = NULL; |
Michal Kazior | d01f858 | 2015-06-03 08:36:13 +0200 | [diff] [blame] | 5552 | mutex_lock(&sdata->local->mtx); |
| 5553 | ieee80211_vif_release_channel(sdata); |
| 5554 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5555 | kfree(auth_data); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5556 | return err; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5557 | } |
| 5558 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5559 | int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, |
| 5560 | struct cfg80211_assoc_request *req) |
| 5561 | { |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 5562 | bool is_6ghz = req->bss->channel->band == NL80211_BAND_6GHZ; |
Johannes Berg | c2f4681 | 2020-10-13 14:01:57 +0200 | [diff] [blame] | 5563 | bool is_5ghz = req->bss->channel->band == NL80211_BAND_5GHZ; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5564 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5565 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 5566 | struct ieee80211_bss *bss = (void *)req->bss->priv; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5567 | struct ieee80211_mgd_assoc_data *assoc_data; |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5568 | const struct cfg80211_bss_ies *beacon_ies; |
Johannes Berg | 4e74bfd | 2012-03-08 15:02:04 +0100 | [diff] [blame] | 5569 | struct ieee80211_supported_band *sband; |
Wen Gong | b0140fd | 2020-12-07 11:36:34 +0800 | [diff] [blame] | 5570 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Johannes Berg | f262213 | 2021-09-30 13:11:31 +0200 | [diff] [blame] | 5571 | const struct element *ssid_elem, *ht_elem, *vht_elem; |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 5572 | int i, err; |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 5573 | bool override = false; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5574 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5575 | assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL); |
| 5576 | if (!assoc_data) |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5577 | return -ENOMEM; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5578 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5579 | rcu_read_lock(); |
Johannes Berg | f262213 | 2021-09-30 13:11:31 +0200 | [diff] [blame] | 5580 | ssid_elem = ieee80211_bss_get_elem(req->bss, WLAN_EID_SSID); |
| 5581 | if (!ssid_elem || ssid_elem->datalen > sizeof(assoc_data->ssid)) { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5582 | rcu_read_unlock(); |
| 5583 | kfree(assoc_data); |
| 5584 | return -EINVAL; |
| 5585 | } |
Johannes Berg | f262213 | 2021-09-30 13:11:31 +0200 | [diff] [blame] | 5586 | memcpy(assoc_data->ssid, ssid_elem->data, ssid_elem->datalen); |
| 5587 | assoc_data->ssid_len = ssid_elem->datalen; |
Wen Gong | b0140fd | 2020-12-07 11:36:34 +0800 | [diff] [blame] | 5588 | memcpy(bss_conf->ssid, assoc_data->ssid, assoc_data->ssid_len); |
| 5589 | bss_conf->ssid_len = assoc_data->ssid_len; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5590 | rcu_read_unlock(); |
| 5591 | |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5592 | if (ifmgd->associated) { |
| 5593 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
| 5594 | |
Johannes Berg | 89f774e | 2016-01-25 15:46:36 +0200 | [diff] [blame] | 5595 | sdata_info(sdata, |
| 5596 | "disconnect from AP %pM for new assoc to %pM\n", |
| 5597 | ifmgd->associated->bssid, req->bss->bssid); |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5598 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
| 5599 | WLAN_REASON_UNSPECIFIED, |
| 5600 | false, frame_buf); |
| 5601 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 5602 | ieee80211_report_disconnect(sdata, frame_buf, |
| 5603 | sizeof(frame_buf), true, |
Johannes Berg | 3f8a39f | 2020-12-06 14:54:43 +0200 | [diff] [blame] | 5604 | WLAN_REASON_UNSPECIFIED, |
| 5605 | false); |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5606 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5607 | |
| 5608 | if (ifmgd->auth_data && !ifmgd->auth_data->done) { |
| 5609 | err = -EBUSY; |
| 5610 | goto err_free; |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 5611 | } |
| 5612 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5613 | if (ifmgd->assoc_data) { |
| 5614 | err = -EBUSY; |
| 5615 | goto err_free; |
| 5616 | } |
| 5617 | |
| 5618 | if (ifmgd->auth_data) { |
| 5619 | bool match; |
| 5620 | |
| 5621 | /* keep sta info, bssid if matching */ |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 5622 | match = ether_addr_equal(ifmgd->bssid, req->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5623 | ieee80211_destroy_auth_data(sdata, match); |
| 5624 | } |
| 5625 | |
| 5626 | /* prepare assoc data */ |
Johannes Berg | 095d81c | 2013-10-15 12:25:07 +0200 | [diff] [blame] | 5627 | |
Juuso Oikarinen | d8ec443 | 2010-10-01 16:02:31 +0300 | [diff] [blame] | 5628 | ifmgd->beacon_crc_valid = false; |
| 5629 | |
Johannes Berg | 095d81c | 2013-10-15 12:25:07 +0200 | [diff] [blame] | 5630 | assoc_data->wmm = bss->wmm_used && |
| 5631 | (local->hw.queues >= IEEE80211_NUM_ACS); |
Johannes Berg | 095d81c | 2013-10-15 12:25:07 +0200 | [diff] [blame] | 5632 | |
Johannes Berg | de5036a | 2012-03-08 15:02:03 +0100 | [diff] [blame] | 5633 | /* |
| 5634 | * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode. |
| 5635 | * We still associate in non-HT mode (11a/b/g) if any one of these |
| 5636 | * ciphers is configured as pairwise. |
| 5637 | * We can set this to true for non-11n hardware, that'll be checked |
| 5638 | * separately along with the peer capabilities. |
| 5639 | */ |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 5640 | for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) { |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5641 | if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 || |
| 5642 | req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP || |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 5643 | req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) { |
Johannes Berg | a8243b7 | 2012-11-22 14:32:09 +0100 | [diff] [blame] | 5644 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 5645 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 5646 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 5647 | netdev_info(sdata->dev, |
Johannes Berg | 5462632 | 2019-08-30 14:24:46 +0300 | [diff] [blame] | 5648 | "disabling HT/VHT/HE due to WEP/TKIP use\n"); |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 5649 | } |
| 5650 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5651 | |
Johannes Berg | 4e74bfd | 2012-03-08 15:02:04 +0100 | [diff] [blame] | 5652 | sband = local->hw.wiphy->bands[req->bss->channel->band]; |
Johannes Berg | 4e74bfd | 2012-03-08 15:02:04 +0100 | [diff] [blame] | 5653 | |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 5654 | /* also disable HT/VHT/HE if the AP doesn't use WMM */ |
| 5655 | if (!bss->wmm_used) { |
| 5656 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 5657 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 5658 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
| 5659 | netdev_info(sdata->dev, |
| 5660 | "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] | 5661 | } |
| 5662 | |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 5663 | memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa)); |
| 5664 | memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask, |
| 5665 | sizeof(ifmgd->ht_capa_mask)); |
| 5666 | |
Johannes Berg | dd5ecfe | 2013-02-21 17:40:19 +0100 | [diff] [blame] | 5667 | memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa)); |
| 5668 | memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask, |
| 5669 | sizeof(ifmgd->vht_capa_mask)); |
| 5670 | |
Thomas Pedersen | 7957c6c | 2020-09-21 19:28:05 -0700 | [diff] [blame] | 5671 | memcpy(&ifmgd->s1g_capa, &req->s1g_capa, sizeof(ifmgd->s1g_capa)); |
| 5672 | memcpy(&ifmgd->s1g_capa_mask, &req->s1g_capa_mask, |
| 5673 | sizeof(ifmgd->s1g_capa_mask)); |
| 5674 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5675 | if (req->ie && req->ie_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5676 | memcpy(assoc_data->ie, req->ie, req->ie_len); |
| 5677 | assoc_data->ie_len = req->ie_len; |
| 5678 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5679 | |
Jouni Malinen | 39404fe | 2016-10-27 00:42:05 +0300 | [diff] [blame] | 5680 | if (req->fils_kek) { |
| 5681 | /* should already be checked in cfg80211 - so warn */ |
| 5682 | if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) { |
| 5683 | err = -EINVAL; |
| 5684 | goto err_free; |
| 5685 | } |
| 5686 | memcpy(assoc_data->fils_kek, req->fils_kek, |
| 5687 | req->fils_kek_len); |
| 5688 | assoc_data->fils_kek_len = req->fils_kek_len; |
| 5689 | } |
| 5690 | |
| 5691 | if (req->fils_nonces) |
| 5692 | memcpy(assoc_data->fils_nonces, req->fils_nonces, |
| 5693 | 2 * FILS_NONCE_LEN); |
| 5694 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5695 | assoc_data->bss = req->bss; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5696 | assoc_data->capability = req->bss->capability; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5697 | assoc_data->supp_rates = bss->supp_rates; |
| 5698 | assoc_data->supp_rates_len = bss->supp_rates_len; |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 5699 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5700 | rcu_read_lock(); |
Johannes Berg | f262213 | 2021-09-30 13:11:31 +0200 | [diff] [blame] | 5701 | ht_elem = ieee80211_bss_get_elem(req->bss, WLAN_EID_HT_OPERATION); |
| 5702 | if (ht_elem && ht_elem->datalen >= sizeof(struct ieee80211_ht_operation)) |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 5703 | assoc_data->ap_ht_param = |
Johannes Berg | f262213 | 2021-09-30 13:11:31 +0200 | [diff] [blame] | 5704 | ((struct ieee80211_ht_operation *)(ht_elem->data))->ht_param; |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 5705 | else if (!is_6ghz) |
Johannes Berg | a8243b7 | 2012-11-22 14:32:09 +0100 | [diff] [blame] | 5706 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
Johannes Berg | f262213 | 2021-09-30 13:11:31 +0200 | [diff] [blame] | 5707 | vht_elem = ieee80211_bss_get_elem(req->bss, WLAN_EID_VHT_CAPABILITY); |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 5708 | if (vht_elem && vht_elem->datalen >= sizeof(struct ieee80211_vht_cap)) { |
Johannes Berg | f262213 | 2021-09-30 13:11:31 +0200 | [diff] [blame] | 5709 | memcpy(&assoc_data->ap_vht_cap, vht_elem->data, |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 5710 | sizeof(struct ieee80211_vht_cap)); |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 5711 | } else if (is_5ghz) { |
| 5712 | sdata_info(sdata, "VHT capa missing/short, disabling VHT/HE\n"); |
Johannes Berg | 57fa5e8 | 2020-05-28 21:34:36 +0200 | [diff] [blame] | 5713 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT | |
| 5714 | IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 5715 | } |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5716 | rcu_read_unlock(); |
Johannes Berg | 63f170e | 2009-12-23 13:15:33 +0100 | [diff] [blame] | 5717 | |
Johannes Berg | 848955c | 2014-11-11 12:48:42 +0100 | [diff] [blame] | 5718 | if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) && |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 5719 | ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK), |
Johannes Berg | 848955c | 2014-11-11 12:48:42 +0100 | [diff] [blame] | 5720 | "U-APSD not supported with HW_PS_NULLFUNC_STACK\n")) |
| 5721 | sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; |
| 5722 | |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 5723 | if (bss->wmm_used && bss->uapsd_supported && |
Johannes Berg | 848955c | 2014-11-11 12:48:42 +0100 | [diff] [blame] | 5724 | (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) { |
Johannes Berg | 76f0303 | 2012-03-08 15:02:05 +0100 | [diff] [blame] | 5725 | assoc_data->uapsd = true; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 5726 | ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED; |
| 5727 | } else { |
Johannes Berg | 76f0303 | 2012-03-08 15:02:05 +0100 | [diff] [blame] | 5728 | assoc_data->uapsd = false; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 5729 | ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED; |
| 5730 | } |
| 5731 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5732 | if (req->prev_bssid) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5733 | memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5734 | |
| 5735 | if (req->use_mfp) { |
| 5736 | ifmgd->mfp = IEEE80211_MFP_REQUIRED; |
| 5737 | ifmgd->flags |= IEEE80211_STA_MFP_ENABLED; |
| 5738 | } else { |
| 5739 | ifmgd->mfp = IEEE80211_MFP_DISABLED; |
| 5740 | ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED; |
| 5741 | } |
| 5742 | |
Assaf Krauss | cd2f5dd | 2014-09-03 15:25:02 +0300 | [diff] [blame] | 5743 | if (req->flags & ASSOC_REQ_USE_RRM) |
| 5744 | ifmgd->flags |= IEEE80211_STA_ENABLE_RRM; |
| 5745 | else |
| 5746 | ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM; |
| 5747 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5748 | if (req->crypto.control_port) |
| 5749 | ifmgd->flags |= IEEE80211_STA_CONTROL_PORT; |
| 5750 | else |
| 5751 | ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT; |
| 5752 | |
Johannes Berg | a621fa4 | 2010-08-27 14:26:54 +0300 | [diff] [blame] | 5753 | sdata->control_port_protocol = req->crypto.control_port_ethertype; |
| 5754 | sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt; |
Denis Kenzior | 018f6fb | 2018-03-26 12:52:51 -0500 | [diff] [blame] | 5755 | sdata->control_port_over_nl80211 = |
| 5756 | req->crypto.control_port_over_nl80211; |
Markus Theil | 7f3f96c | 2020-03-12 10:10:54 +0100 | [diff] [blame] | 5757 | sdata->control_port_no_preauth = req->crypto.control_port_no_preauth; |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 5758 | sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto, |
| 5759 | sdata->vif.type); |
Johannes Berg | a621fa4 | 2010-08-27 14:26:54 +0300 | [diff] [blame] | 5760 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5761 | /* kick off associate process */ |
| 5762 | |
| 5763 | ifmgd->assoc_data = assoc_data; |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 5764 | ifmgd->dtim_period = 0; |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 5765 | ifmgd->have_beacon = false; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5766 | |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 5767 | /* override HT/VHT configuration only if the AP and we support it */ |
| 5768 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) { |
| 5769 | struct ieee80211_sta_ht_cap sta_ht_cap; |
| 5770 | |
| 5771 | if (req->flags & ASSOC_REQ_DISABLE_HT) |
| 5772 | override = true; |
| 5773 | |
| 5774 | memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap)); |
| 5775 | ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap); |
| 5776 | |
| 5777 | /* check for 40 MHz disable override */ |
| 5778 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) && |
| 5779 | sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 && |
| 5780 | !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) |
| 5781 | override = true; |
| 5782 | |
| 5783 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && |
| 5784 | req->flags & ASSOC_REQ_DISABLE_VHT) |
| 5785 | override = true; |
| 5786 | } |
| 5787 | |
| 5788 | if (req->flags & ASSOC_REQ_DISABLE_HT) { |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 5789 | mlme_dbg(sdata, "HT disabled by flag, disabling HT/VHT/HE\n"); |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 5790 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
| 5791 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 5792 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 5793 | } |
| 5794 | |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 5795 | if (req->flags & ASSOC_REQ_DISABLE_VHT) { |
| 5796 | mlme_dbg(sdata, "VHT disabled by flag, disabling VHT\n"); |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 5797 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 5798 | } |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 5799 | |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 5800 | if (req->flags & ASSOC_REQ_DISABLE_HE) { |
| 5801 | mlme_dbg(sdata, "HE disabled by flag, disabling VHT\n"); |
Ben Greear | b6db0f8 | 2021-02-04 06:46:10 -0800 | [diff] [blame] | 5802 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 636ccda | 2021-11-30 13:16:59 +0200 | [diff] [blame] | 5803 | } |
Ben Greear | b6db0f8 | 2021-02-04 06:46:10 -0800 | [diff] [blame] | 5804 | |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 5805 | err = ieee80211_prep_connection(sdata, req->bss, true, override); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5806 | if (err) |
| 5807 | goto err_clear; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5808 | |
Shaul Triebitz | 79ea0a5 | 2021-06-18 13:41:34 +0300 | [diff] [blame] | 5809 | if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) { |
| 5810 | if (ifmgd->powersave) |
| 5811 | sdata->smps_mode = IEEE80211_SMPS_DYNAMIC; |
| 5812 | else |
| 5813 | sdata->smps_mode = IEEE80211_SMPS_OFF; |
| 5814 | } else { |
| 5815 | sdata->smps_mode = ifmgd->req_smps; |
| 5816 | } |
| 5817 | |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5818 | rcu_read_lock(); |
| 5819 | beacon_ies = rcu_dereference(req->bss->beacon_ies); |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 5820 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 5821 | if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) && |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5822 | !beacon_ies) { |
| 5823 | /* |
| 5824 | * Wait up to one beacon interval ... |
| 5825 | * should this be more if we miss one? |
| 5826 | */ |
| 5827 | sdata_info(sdata, "waiting for beacon from %pM\n", |
| 5828 | ifmgd->bssid); |
| 5829 | assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval); |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 5830 | assoc_data->timeout_started = true; |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5831 | assoc_data->need_beacon = true; |
| 5832 | } else if (beacon_ies) { |
Shaul Triebitz | 3b3ec3d | 2020-05-28 21:34:37 +0200 | [diff] [blame] | 5833 | const struct element *elem; |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5834 | u8 dtim_count = 0; |
| 5835 | |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 5836 | ieee80211_get_dtim(beacon_ies, &dtim_count, |
| 5837 | &ifmgd->dtim_period); |
| 5838 | |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 5839 | ifmgd->have_beacon = true; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5840 | assoc_data->timeout = jiffies; |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 5841 | assoc_data->timeout_started = true; |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5842 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 5843 | if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) { |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5844 | sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf; |
| 5845 | sdata->vif.bss_conf.sync_device_ts = |
| 5846 | bss->device_ts_beacon; |
| 5847 | sdata->vif.bss_conf.sync_dtim_count = dtim_count; |
| 5848 | } |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 5849 | |
Shaul Triebitz | 3b3ec3d | 2020-05-28 21:34:37 +0200 | [diff] [blame] | 5850 | elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION, |
| 5851 | beacon_ies->data, beacon_ies->len); |
| 5852 | if (elem && elem->datalen >= 3) |
| 5853 | sdata->vif.bss_conf.profile_periodicity = elem->data[2]; |
Johannes Berg | bbc6f03 | 2021-06-18 13:41:49 +0300 | [diff] [blame] | 5854 | else |
| 5855 | sdata->vif.bss_conf.profile_periodicity = 0; |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 5856 | |
Shaul Triebitz | 3b3ec3d | 2020-05-28 21:34:37 +0200 | [diff] [blame] | 5857 | elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, |
| 5858 | beacon_ies->data, beacon_ies->len); |
| 5859 | if (elem && elem->datalen >= 11 && |
| 5860 | (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT)) |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 5861 | sdata->vif.bss_conf.ema_ap = true; |
Johannes Berg | bbc6f03 | 2021-06-18 13:41:49 +0300 | [diff] [blame] | 5862 | else |
| 5863 | sdata->vif.bss_conf.ema_ap = false; |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5864 | } else { |
| 5865 | assoc_data->timeout = jiffies; |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 5866 | assoc_data->timeout_started = true; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5867 | } |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5868 | rcu_read_unlock(); |
| 5869 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 5870 | run_again(sdata, assoc_data->timeout); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5871 | |
Paul Stewart | fcff4f1 | 2012-02-23 17:59:53 -0800 | [diff] [blame] | 5872 | if (bss->corrupt_data) { |
| 5873 | char *corrupt_type = "data"; |
| 5874 | if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) { |
| 5875 | if (bss->corrupt_data & |
| 5876 | IEEE80211_BSS_CORRUPT_PROBE_RESP) |
| 5877 | corrupt_type = "beacon and probe response"; |
| 5878 | else |
| 5879 | corrupt_type = "beacon"; |
| 5880 | } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP) |
| 5881 | corrupt_type = "probe response"; |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 5882 | sdata_info(sdata, "associating with AP with corrupt %s\n", |
| 5883 | corrupt_type); |
Paul Stewart | fcff4f1 | 2012-02-23 17:59:53 -0800 | [diff] [blame] | 5884 | } |
| 5885 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 5886 | return 0; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5887 | err_clear: |
Joe Perches | c84a67a | 2015-03-02 19:54:57 -0800 | [diff] [blame] | 5888 | eth_zero_addr(ifmgd->bssid); |
Eliad Peller | 3d2abdf | 2012-09-04 17:44:45 +0300 | [diff] [blame] | 5889 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5890 | ifmgd->assoc_data = NULL; |
| 5891 | err_free: |
| 5892 | kfree(assoc_data); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5893 | return err; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5894 | } |
| 5895 | |
| 5896 | int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 63c9c5e | 2012-02-24 13:50:51 +0100 | [diff] [blame] | 5897 | struct cfg80211_deauth_request *req) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5898 | { |
| 5899 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 5900 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Stanislaw Gruszka | 6863255 | 2012-10-15 14:52:41 +0200 | [diff] [blame] | 5901 | bool tx = !req->local_state_change; |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 5902 | struct ieee80211_prep_tx_info info = { |
| 5903 | .subtype = IEEE80211_STYPE_DEAUTH, |
| 5904 | }; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5905 | |
Johannes Berg | c9c3a06 | 2014-03-19 09:11:19 +0100 | [diff] [blame] | 5906 | if (ifmgd->auth_data && |
| 5907 | ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) { |
| 5908 | sdata_info(sdata, |
| 5909 | "aborting authentication with %pM by local choice (Reason: %u=%s)\n", |
| 5910 | req->bssid, req->reason_code, |
| 5911 | ieee80211_get_reason_code_string(req->reason_code)); |
Johannes Berg | 0ff7161 | 2009-09-26 14:45:41 +0200 | [diff] [blame] | 5912 | |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 5913 | drv_mgd_prepare_tx(sdata->local, sdata, &info); |
Johannes Berg | 4b08d1b | 2019-08-30 14:24:51 +0300 | [diff] [blame] | 5914 | ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid, |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 5915 | IEEE80211_STYPE_DEAUTH, |
Stanislaw Gruszka | 6863255 | 2012-10-15 14:52:41 +0200 | [diff] [blame] | 5916 | req->reason_code, tx, |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 5917 | frame_buf); |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 5918 | ieee80211_destroy_auth_data(sdata, false); |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 5919 | ieee80211_report_disconnect(sdata, frame_buf, |
| 5920 | sizeof(frame_buf), true, |
Johannes Berg | 3f8a39f | 2020-12-06 14:54:43 +0200 | [diff] [blame] | 5921 | req->reason_code, false); |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 5922 | drv_mgd_complete_tx(sdata->local, sdata, &info); |
Johannes Berg | c9c3a06 | 2014-03-19 09:11:19 +0100 | [diff] [blame] | 5923 | return 0; |
Emmanuel Grumbach | 8c7d857 | 2012-07-25 01:42:36 +0300 | [diff] [blame] | 5924 | } |
| 5925 | |
Andrei Otcheretianski | a64cba3 | 2015-10-25 10:59:38 +0200 | [diff] [blame] | 5926 | if (ifmgd->assoc_data && |
| 5927 | ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) { |
| 5928 | sdata_info(sdata, |
| 5929 | "aborting association with %pM by local choice (Reason: %u=%s)\n", |
| 5930 | req->bssid, req->reason_code, |
| 5931 | ieee80211_get_reason_code_string(req->reason_code)); |
| 5932 | |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 5933 | drv_mgd_prepare_tx(sdata->local, sdata, &info); |
Johannes Berg | 4b08d1b | 2019-08-30 14:24:51 +0300 | [diff] [blame] | 5934 | ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid, |
Andrei Otcheretianski | a64cba3 | 2015-10-25 10:59:38 +0200 | [diff] [blame] | 5935 | IEEE80211_STYPE_DEAUTH, |
| 5936 | req->reason_code, tx, |
| 5937 | frame_buf); |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 5938 | ieee80211_destroy_assoc_data(sdata, false, true); |
Andrei Otcheretianski | a64cba3 | 2015-10-25 10:59:38 +0200 | [diff] [blame] | 5939 | ieee80211_report_disconnect(sdata, frame_buf, |
| 5940 | sizeof(frame_buf), true, |
Johannes Berg | 3f8a39f | 2020-12-06 14:54:43 +0200 | [diff] [blame] | 5941 | req->reason_code, false); |
Andrei Otcheretianski | a64cba3 | 2015-10-25 10:59:38 +0200 | [diff] [blame] | 5942 | return 0; |
| 5943 | } |
| 5944 | |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 5945 | if (ifmgd->associated && |
| 5946 | ether_addr_equal(ifmgd->associated->bssid, req->bssid)) { |
Johannes Berg | c9c3a06 | 2014-03-19 09:11:19 +0100 | [diff] [blame] | 5947 | sdata_info(sdata, |
| 5948 | "deauthenticating from %pM by local choice (Reason: %u=%s)\n", |
| 5949 | req->bssid, req->reason_code, |
| 5950 | ieee80211_get_reason_code_string(req->reason_code)); |
| 5951 | |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 5952 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
| 5953 | req->reason_code, tx, frame_buf); |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 5954 | ieee80211_report_disconnect(sdata, frame_buf, |
| 5955 | sizeof(frame_buf), true, |
Johannes Berg | 3f8a39f | 2020-12-06 14:54:43 +0200 | [diff] [blame] | 5956 | req->reason_code, false); |
Johannes Berg | 15fae34 | 2021-06-18 13:41:55 +0300 | [diff] [blame] | 5957 | drv_mgd_complete_tx(sdata->local, sdata, &info); |
Johannes Berg | c9c3a06 | 2014-03-19 09:11:19 +0100 | [diff] [blame] | 5958 | return 0; |
| 5959 | } |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 5960 | |
Johannes Berg | c9c3a06 | 2014-03-19 09:11:19 +0100 | [diff] [blame] | 5961 | return -ENOTCONN; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5962 | } |
| 5963 | |
| 5964 | int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 63c9c5e | 2012-02-24 13:50:51 +0100 | [diff] [blame] | 5965 | struct cfg80211_disassoc_request *req) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5966 | { |
| 5967 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 5968 | u8 bssid[ETH_ALEN]; |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 5969 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5970 | |
Johannes Berg | 8d8b261 | 2009-07-25 11:58:36 +0200 | [diff] [blame] | 5971 | /* |
| 5972 | * cfg80211 should catch this ... but it's racy since |
| 5973 | * we can receive a disassoc frame, process it, hand it |
| 5974 | * to cfg80211 while that's in a locked section already |
| 5975 | * trying to tell us that the user wants to disconnect. |
| 5976 | */ |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 5977 | if (ifmgd->associated != req->bss) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5978 | return -ENOLINK; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5979 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 5980 | sdata_info(sdata, |
Calvin Owens | dfa1ad2 | 2014-02-11 12:36:24 -0600 | [diff] [blame] | 5981 | "disassociating from %pM by local choice (Reason: %u=%s)\n", |
| 5982 | 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] | 5983 | |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 5984 | memcpy(bssid, req->bss->bssid, ETH_ALEN); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 5985 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC, |
| 5986 | req->reason_code, !req->local_state_change, |
| 5987 | frame_buf); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5988 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 5989 | ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true, |
Johannes Berg | 3f8a39f | 2020-12-06 14:54:43 +0200 | [diff] [blame] | 5990 | req->reason_code, false); |
Johannes Berg | bc83b68 | 2009-11-29 12:19:06 +0100 | [diff] [blame] | 5991 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5992 | return 0; |
| 5993 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5994 | |
Eliad Peller | afa762f | 2012-04-23 14:45:15 +0300 | [diff] [blame] | 5995 | void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 54e4ffb | 2012-02-25 21:48:08 +0100 | [diff] [blame] | 5996 | { |
| 5997 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 5998 | |
Ben Greear | 4992185 | 2013-02-20 09:41:09 -0800 | [diff] [blame] | 5999 | /* |
| 6000 | * Make sure some work items will not run after this, |
| 6001 | * they will not do anything but might not have been |
| 6002 | * cancelled when disconnecting. |
| 6003 | */ |
| 6004 | cancel_work_sync(&ifmgd->monitor_work); |
| 6005 | cancel_work_sync(&ifmgd->beacon_connection_loss_work); |
| 6006 | cancel_work_sync(&ifmgd->request_smps_work); |
| 6007 | cancel_work_sync(&ifmgd->csa_connection_drop_work); |
| 6008 | cancel_work_sync(&ifmgd->chswitch_work); |
Arik Nemtsov | 81dd2b8 | 2014-07-17 17:14:25 +0300 | [diff] [blame] | 6009 | cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work); |
Ben Greear | 4992185 | 2013-02-20 09:41:09 -0800 | [diff] [blame] | 6010 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 6011 | sdata_lock(sdata); |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 6012 | if (ifmgd->assoc_data) { |
| 6013 | struct cfg80211_bss *bss = ifmgd->assoc_data->bss; |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 6014 | ieee80211_destroy_assoc_data(sdata, false, false); |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 6015 | cfg80211_assoc_timeout(sdata->dev, bss); |
| 6016 | } |
Johannes Berg | 54e4ffb | 2012-02-25 21:48:08 +0100 | [diff] [blame] | 6017 | if (ifmgd->auth_data) |
| 6018 | ieee80211_destroy_auth_data(sdata, false); |
Liad Kaufman | 1277b4a | 2014-11-09 18:50:08 +0200 | [diff] [blame] | 6019 | spin_lock_bh(&ifmgd->teardown_lock); |
| 6020 | if (ifmgd->teardown_skb) { |
| 6021 | kfree_skb(ifmgd->teardown_skb); |
| 6022 | ifmgd->teardown_skb = NULL; |
| 6023 | ifmgd->orig_teardown_skb = NULL; |
| 6024 | } |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 6025 | kfree(ifmgd->assoc_req_ies); |
| 6026 | ifmgd->assoc_req_ies = NULL; |
| 6027 | ifmgd->assoc_req_ies_len = 0; |
Liad Kaufman | 1277b4a | 2014-11-09 18:50:08 +0200 | [diff] [blame] | 6028 | spin_unlock_bh(&ifmgd->teardown_lock); |
Johannes Berg | 54e4ffb | 2012-02-25 21:48:08 +0100 | [diff] [blame] | 6029 | del_timer_sync(&ifmgd->timer); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 6030 | sdata_unlock(sdata); |
Johannes Berg | 54e4ffb | 2012-02-25 21:48:08 +0100 | [diff] [blame] | 6031 | } |
| 6032 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 6033 | void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif, |
| 6034 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
Andrzej Zaborowski | 769f07d | 2017-01-25 12:43:40 +0100 | [diff] [blame] | 6035 | s32 rssi_level, |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 6036 | gfp_t gfp) |
| 6037 | { |
| 6038 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 6039 | |
Andrzej Zaborowski | 769f07d | 2017-01-25 12:43:40 +0100 | [diff] [blame] | 6040 | trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level); |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 6041 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 6042 | cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp); |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 6043 | } |
| 6044 | EXPORT_SYMBOL(ieee80211_cqm_rssi_notify); |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 6045 | |
| 6046 | void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp) |
| 6047 | { |
| 6048 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 6049 | |
| 6050 | trace_api_cqm_beacon_loss_notify(sdata->local, sdata); |
| 6051 | |
| 6052 | cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp); |
| 6053 | } |
| 6054 | EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify); |