Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2 | /* |
| 3 | * BSS client mode implementation |
Jouni Malinen | 5394af4 | 2009-01-08 13:31:59 +0200 | [diff] [blame] | 4 | * Copyright 2003-2008, Jouni Malinen <j@w1.fi> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 5 | * Copyright 2004, Instant802 Networks, Inc. |
| 6 | * Copyright 2005, Devicescape Software, Inc. |
| 7 | * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> |
| 8 | * Copyright 2007, Michael Wu <flamingice@sourmilk.net> |
Johannes Berg | d98ad83 | 2014-09-03 15:24:57 +0300 | [diff] [blame] | 9 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
Avraham Stern | e38a017 | 2017-04-26 10:58:47 +0300 | [diff] [blame] | 10 | * Copyright (C) 2015 - 2017 Intel Deutschland GmbH |
Sara Sharon | 2bf973f | 2020-01-31 13:12:51 +0200 | [diff] [blame] | 11 | * Copyright (C) 2018 - 2020 Intel Corporation |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 12 | */ |
| 13 | |
Geert Uytterhoeven | 5b323ed | 2007-05-08 18:40:27 -0700 | [diff] [blame] | 14 | #include <linux/delay.h> |
Ard Biesheuvel | 5fdb373 | 2019-06-12 18:19:54 +0200 | [diff] [blame] | 15 | #include <linux/fips.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 16 | #include <linux/if_ether.h> |
| 17 | #include <linux/skbuff.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 18 | #include <linux/if_arp.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 19 | #include <linux/etherdevice.h> |
Paul Gortmaker | d9b9384 | 2011-09-18 13:21:27 -0400 | [diff] [blame] | 20 | #include <linux/moduleparam.h> |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 21 | #include <linux/rtnetlink.h> |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 22 | #include <linux/crc32.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 24 | #include <linux/export.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 25 | #include <net/mac80211.h> |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 26 | #include <asm/unaligned.h> |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 27 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 28 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 29 | #include "driver-ops.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 30 | #include "rate.h" |
| 31 | #include "led.h" |
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 | 60f8b39 | 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 | 60f8b39 | 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, |
| 148 | const struct ieee80211_ht_operation *ht_oper, |
| 149 | const struct ieee80211_vht_operation *vht_oper, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 150 | const struct ieee80211_he_operation *he_oper, |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 151 | struct cfg80211_chan_def *chandef, bool tracking) |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 152 | { |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 153 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 154 | struct cfg80211_chan_def vht_chandef; |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 155 | struct ieee80211_sta_ht_cap sta_ht_cap; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 156 | u32 ht_cfreq, ret; |
| 157 | |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 158 | memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap)); |
| 159 | ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap); |
| 160 | |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 161 | memset(chandef, 0, sizeof(struct cfg80211_chan_def)); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 162 | chandef->chan = channel; |
| 163 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 164 | chandef->center_freq1 = channel->center_freq; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 165 | |
Johannes Berg | b1b1ae2 | 2017-10-13 15:26:01 +0300 | [diff] [blame] | 166 | if (!ht_oper || !sta_ht_cap.ht_supported) { |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 167 | ret = IEEE80211_STA_DISABLE_HT | |
| 168 | IEEE80211_STA_DISABLE_VHT | |
| 169 | IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 170 | goto out; |
| 171 | } |
| 172 | |
| 173 | chandef->width = NL80211_CHAN_WIDTH_20; |
| 174 | |
| 175 | ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan, |
| 176 | channel->band); |
| 177 | /* check that channel matches the right operating channel */ |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 178 | if (!tracking && channel->center_freq != ht_cfreq) { |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 179 | /* |
| 180 | * It's possible that some APs are confused here; |
| 181 | * Netgear WNDR3700 sometimes reports 4 higher than |
| 182 | * the actual channel in association responses, but |
| 183 | * since we look at probe response/beacon data here |
| 184 | * it should be OK. |
| 185 | */ |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 186 | sdata_info(sdata, |
| 187 | "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n", |
| 188 | channel->center_freq, ht_cfreq, |
| 189 | ht_oper->primary_chan, channel->band); |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 190 | ret = IEEE80211_STA_DISABLE_HT | |
| 191 | IEEE80211_STA_DISABLE_VHT | |
| 192 | IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 193 | goto out; |
| 194 | } |
| 195 | |
| 196 | /* check 40 MHz support, if we have it */ |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 197 | if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) { |
Johannes Berg | 8ac3c704 | 2015-12-18 15:08:34 +0100 | [diff] [blame] | 198 | ieee80211_chandef_ht_oper(ht_oper, chandef); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 199 | } else { |
| 200 | /* 40 MHz (and 80 MHz) must be supported for VHT */ |
| 201 | ret = IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 85220d7 | 2013-03-25 18:29:27 +0100 | [diff] [blame] | 202 | /* also mark 40 MHz disabled */ |
| 203 | ret |= IEEE80211_STA_DISABLE_40MHZ; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 204 | goto out; |
| 205 | } |
| 206 | |
| 207 | if (!vht_oper || !sband->vht_cap.vht_supported) { |
| 208 | ret = IEEE80211_STA_DISABLE_VHT; |
| 209 | goto out; |
| 210 | } |
| 211 | |
Johannes Berg | 8ac3c704 | 2015-12-18 15:08:34 +0100 | [diff] [blame] | 212 | vht_chandef = *chandef; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 213 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && he_oper && |
| 214 | (le32_to_cpu(he_oper->he_oper_params) & |
| 215 | IEEE80211_HE_OPERATION_VHT_OPER_INFO)) { |
| 216 | struct ieee80211_vht_operation he_oper_vht_cap; |
| 217 | |
| 218 | /* |
| 219 | * Set only first 3 bytes (other 2 aren't used in |
| 220 | * ieee80211_chandef_vht_oper() anyway) |
| 221 | */ |
| 222 | memcpy(&he_oper_vht_cap, he_oper->optional, 3); |
| 223 | he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0); |
| 224 | |
Johannes Berg | 7eb26df | 2018-08-31 11:31:18 +0300 | [diff] [blame] | 225 | if (!ieee80211_chandef_vht_oper(&sdata->local->hw, |
| 226 | &he_oper_vht_cap, ht_oper, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 227 | &vht_chandef)) { |
| 228 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) |
| 229 | sdata_info(sdata, |
| 230 | "HE AP VHT information is invalid, disable HE\n"); |
| 231 | ret = IEEE80211_STA_DISABLE_HE; |
| 232 | goto out; |
| 233 | } |
Johannes Berg | 7eb26df | 2018-08-31 11:31:18 +0300 | [diff] [blame] | 234 | } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_oper, |
| 235 | ht_oper, &vht_chandef)) { |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 236 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 237 | sdata_info(sdata, |
Johannes Berg | 8ac3c704 | 2015-12-18 15:08:34 +0100 | [diff] [blame] | 238 | "AP VHT information is invalid, disable VHT\n"); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 239 | ret = IEEE80211_STA_DISABLE_VHT; |
| 240 | goto out; |
| 241 | } |
| 242 | |
| 243 | if (!cfg80211_chandef_valid(&vht_chandef)) { |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 244 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 245 | sdata_info(sdata, |
| 246 | "AP VHT information is invalid, disable VHT\n"); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 247 | ret = IEEE80211_STA_DISABLE_VHT; |
| 248 | goto out; |
| 249 | } |
| 250 | |
| 251 | if (cfg80211_chandef_identical(chandef, &vht_chandef)) { |
| 252 | ret = 0; |
| 253 | goto out; |
| 254 | } |
| 255 | |
| 256 | if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) { |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 257 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 258 | sdata_info(sdata, |
| 259 | "AP VHT information doesn't match HT, disable VHT\n"); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 260 | ret = IEEE80211_STA_DISABLE_VHT; |
| 261 | goto out; |
| 262 | } |
| 263 | |
| 264 | *chandef = vht_chandef; |
| 265 | |
| 266 | ret = 0; |
| 267 | |
| 268 | out: |
Johannes Berg | 963a1852 | 2014-02-21 20:34:34 +0100 | [diff] [blame] | 269 | /* |
| 270 | * When tracking the current AP, don't do any further checks if the |
| 271 | * new chandef is identical to the one we're currently using for the |
| 272 | * connection. This keeps us from playing ping-pong with regulatory, |
| 273 | * without it the following can happen (for example): |
| 274 | * - connect to an AP with 80 MHz, world regdom allows 80 MHz |
| 275 | * - AP advertises regdom US |
| 276 | * - CRDA loads regdom US with 80 MHz prohibited (old database) |
| 277 | * - the code below detects an unsupported channel, downgrades, and |
| 278 | * we disconnect from the AP in the caller |
| 279 | * - disconnect causes CRDA to reload world regdomain and the game |
| 280 | * starts anew. |
| 281 | * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881) |
| 282 | * |
| 283 | * It seems possible that there are still scenarios with CSA or real |
| 284 | * bandwidth changes where a this could happen, but those cases are |
| 285 | * less common and wouldn't completely prevent using the AP. |
| 286 | */ |
| 287 | if (tracking && |
| 288 | cfg80211_chandef_identical(chandef, &sdata->vif.bss_conf.chandef)) |
| 289 | return ret; |
| 290 | |
Johannes Berg | 586e01e | 2013-02-14 12:13:53 +0100 | [diff] [blame] | 291 | /* don't print the message below for VHT mismatch if VHT is disabled */ |
| 292 | if (ret & IEEE80211_STA_DISABLE_VHT) |
| 293 | vht_chandef = *chandef; |
| 294 | |
Johannes Berg | ddfe49b | 2013-07-31 20:52:03 +0200 | [diff] [blame] | 295 | /* |
| 296 | * Ignore the DISABLED flag when we're already connected and only |
| 297 | * tracking the APs beacon for bandwidth changes - otherwise we |
| 298 | * might get disconnected here if we connect to an AP, update our |
| 299 | * regulatory information based on the AP's country IE and the |
| 300 | * information we have is wrong/outdated and disables the channel |
| 301 | * that we're actually using for the connection to the AP. |
| 302 | */ |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 303 | while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef, |
Johannes Berg | ddfe49b | 2013-07-31 20:52:03 +0200 | [diff] [blame] | 304 | tracking ? 0 : |
| 305 | IEEE80211_CHAN_DISABLED)) { |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 306 | if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) { |
| 307 | ret = IEEE80211_STA_DISABLE_HT | |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 308 | IEEE80211_STA_DISABLE_VHT | |
| 309 | IEEE80211_STA_DISABLE_HE; |
Chris Wright | b56e4b8 | 2013-07-31 12:12:24 -0700 | [diff] [blame] | 310 | break; |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 311 | } |
| 312 | |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 313 | ret |= ieee80211_chandef_downgrade(chandef); |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 314 | } |
| 315 | |
Daniel Gabay | 8cadb20 | 2020-01-31 13:12:52 +0200 | [diff] [blame] | 316 | if (!he_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef, |
| 317 | IEEE80211_CHAN_NO_HE)) |
Haim Dreyfuss | b5db1ac | 2020-01-31 13:12:44 +0200 | [diff] [blame] | 318 | ret |= IEEE80211_STA_DISABLE_HE; |
| 319 | |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 320 | if (chandef->width != vht_chandef.width && !tracking) |
Johannes Berg | 6565ec9 | 2013-02-08 14:52:32 +0100 | [diff] [blame] | 321 | sdata_info(sdata, |
| 322 | "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n"); |
| 323 | |
| 324 | WARN_ON_ONCE(!cfg80211_chandef_valid(chandef)); |
| 325 | return ret; |
| 326 | } |
| 327 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 328 | static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata, |
| 329 | struct sta_info *sta, |
Eliad Peller | 53b954e | 2014-07-24 11:20:05 +0300 | [diff] [blame] | 330 | const struct ieee80211_ht_cap *ht_cap, |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 331 | const struct ieee80211_ht_operation *ht_oper, |
| 332 | const struct ieee80211_vht_operation *vht_oper, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 333 | const struct ieee80211_he_operation *he_oper, |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 334 | const u8 *bssid, u32 *changed) |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 335 | { |
| 336 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 337 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 338 | struct ieee80211_channel *chan = sdata->vif.bss_conf.chandef.chan; |
| 339 | struct ieee80211_supported_band *sband = |
| 340 | local->hw.wiphy->bands[chan->band]; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 341 | struct cfg80211_chan_def chandef; |
Johannes Berg | 9ed6bcc | 2009-05-08 20:47:39 +0200 | [diff] [blame] | 342 | u16 ht_opmode; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 343 | u32 flags; |
| 344 | enum ieee80211_sta_rx_bandwidth new_sta_bw; |
| 345 | int ret; |
| 346 | |
| 347 | /* if HT was/is disabled, don't track any bandwidth changes */ |
| 348 | if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper) |
| 349 | return 0; |
| 350 | |
| 351 | /* don't check VHT if we associated as non-VHT station */ |
| 352 | if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT) |
| 353 | vht_oper = NULL; |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 354 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 355 | /* don't check HE if we associated as non-HE station */ |
| 356 | if (ifmgd->flags & IEEE80211_STA_DISABLE_HE || |
| 357 | !ieee80211_get_he_sta_cap(sband)) |
| 358 | he_oper = NULL; |
| 359 | |
Johannes Berg | 1128958 | 2013-02-07 17:36:12 +0100 | [diff] [blame] | 360 | if (WARN_ON_ONCE(!sta)) |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 361 | return -EINVAL; |
Johannes Berg | 1128958 | 2013-02-07 17:36:12 +0100 | [diff] [blame] | 362 | |
Avri Altman | 017b45b | 2013-11-18 19:06:48 +0200 | [diff] [blame] | 363 | /* |
| 364 | * if bss configuration changed store the new one - |
| 365 | * this may be applicable even if channel is identical |
| 366 | */ |
| 367 | ht_opmode = le16_to_cpu(ht_oper->operation_mode); |
| 368 | if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) { |
| 369 | *changed |= BSS_CHANGED_HT; |
| 370 | sdata->vif.bss_conf.ht_operation_mode = ht_opmode; |
| 371 | } |
| 372 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 373 | /* calculate new channel (type) based on HT/VHT/HE operation IEs */ |
Eliad Peller | 53b954e | 2014-07-24 11:20:05 +0300 | [diff] [blame] | 374 | flags = ieee80211_determine_chantype(sdata, sband, chan, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 375 | ht_oper, vht_oper, he_oper, |
Eliad Peller | 53b954e | 2014-07-24 11:20:05 +0300 | [diff] [blame] | 376 | &chandef, true); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 377 | |
| 378 | /* |
| 379 | * Downgrade the new channel if we associated with restricted |
| 380 | * capabilities. For example, if we associated as a 20 MHz STA |
| 381 | * to a 40 MHz AP (due to regulatory, capabilities or config |
| 382 | * reasons) then switching to a 40 MHz channel now won't do us |
| 383 | * any good -- we couldn't use it with the AP. |
| 384 | */ |
| 385 | if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ && |
| 386 | chandef.width == NL80211_CHAN_WIDTH_80P80) |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 387 | flags |= ieee80211_chandef_downgrade(&chandef); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 388 | if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ && |
| 389 | chandef.width == NL80211_CHAN_WIDTH_160) |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 390 | flags |= ieee80211_chandef_downgrade(&chandef); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 391 | if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ && |
| 392 | chandef.width > NL80211_CHAN_WIDTH_20) |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 393 | flags |= ieee80211_chandef_downgrade(&chandef); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 394 | |
| 395 | if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef)) |
| 396 | return 0; |
| 397 | |
| 398 | sdata_info(sdata, |
| 399 | "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n", |
| 400 | ifmgd->bssid, chandef.chan->center_freq, chandef.width, |
| 401 | chandef.center_freq1, chandef.center_freq2); |
| 402 | |
| 403 | if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT | |
| 404 | IEEE80211_STA_DISABLE_VHT | |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 405 | IEEE80211_STA_DISABLE_HE | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 406 | IEEE80211_STA_DISABLE_40MHZ | |
| 407 | IEEE80211_STA_DISABLE_80P80MHZ | |
| 408 | IEEE80211_STA_DISABLE_160MHZ)) || |
| 409 | !cfg80211_chandef_valid(&chandef)) { |
| 410 | sdata_info(sdata, |
| 411 | "AP %pM changed bandwidth in a way we can't support - disconnect\n", |
| 412 | ifmgd->bssid); |
| 413 | return -EINVAL; |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 414 | } |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 415 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 416 | switch (chandef.width) { |
| 417 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 418 | case NL80211_CHAN_WIDTH_20: |
| 419 | new_sta_bw = IEEE80211_STA_RX_BW_20; |
| 420 | break; |
| 421 | case NL80211_CHAN_WIDTH_40: |
| 422 | new_sta_bw = IEEE80211_STA_RX_BW_40; |
| 423 | break; |
| 424 | case NL80211_CHAN_WIDTH_80: |
| 425 | new_sta_bw = IEEE80211_STA_RX_BW_80; |
| 426 | break; |
| 427 | case NL80211_CHAN_WIDTH_80P80: |
| 428 | case NL80211_CHAN_WIDTH_160: |
| 429 | new_sta_bw = IEEE80211_STA_RX_BW_160; |
| 430 | break; |
| 431 | default: |
| 432 | return -EINVAL; |
| 433 | } |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 434 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 435 | if (new_sta_bw > sta->cur_max_bandwidth) |
| 436 | new_sta_bw = sta->cur_max_bandwidth; |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 437 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 438 | if (new_sta_bw < sta->sta.bandwidth) { |
| 439 | sta->sta.bandwidth = new_sta_bw; |
| 440 | rate_control_rate_update(local, sband, sta, |
| 441 | IEEE80211_RC_BW_CHANGED); |
| 442 | } |
Rajkumar Manoharan | 7cc44ed | 2011-09-16 15:32:34 +0530 | [diff] [blame] | 443 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 444 | ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed); |
| 445 | if (ret) { |
| 446 | sdata_info(sdata, |
| 447 | "AP %pM changed bandwidth to incompatible one - disconnect\n", |
| 448 | ifmgd->bssid); |
| 449 | return ret; |
| 450 | } |
| 451 | |
| 452 | if (new_sta_bw > sta->sta.bandwidth) { |
| 453 | sta->sta.bandwidth = new_sta_bw; |
| 454 | rate_control_rate_update(local, sband, sta, |
| 455 | IEEE80211_RC_BW_CHANGED); |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 456 | } |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 457 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 458 | return 0; |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 459 | } |
| 460 | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 461 | /* frame sending functions */ |
| 462 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 463 | static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 464 | struct sk_buff *skb, u8 ap_ht_param, |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 465 | struct ieee80211_supported_band *sband, |
| 466 | struct ieee80211_channel *channel, |
| 467 | enum ieee80211_smps_mode smps) |
| 468 | { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 469 | u8 *pos; |
| 470 | u32 flags = channel->flags; |
| 471 | u16 cap; |
| 472 | struct ieee80211_sta_ht_cap ht_cap; |
| 473 | |
| 474 | BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap)); |
| 475 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 476 | memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap)); |
| 477 | ieee80211_apply_htcap_overrides(sdata, &ht_cap); |
| 478 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 479 | /* determine capability flags */ |
| 480 | cap = ht_cap.cap; |
| 481 | |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 482 | switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 483 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: |
| 484 | if (flags & IEEE80211_CHAN_NO_HT40PLUS) { |
| 485 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 486 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 487 | } |
| 488 | break; |
| 489 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: |
| 490 | if (flags & IEEE80211_CHAN_NO_HT40MINUS) { |
| 491 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 492 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 493 | } |
| 494 | break; |
| 495 | } |
| 496 | |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 497 | /* |
| 498 | * If 40 MHz was disabled associate as though we weren't |
| 499 | * capable of 40 MHz -- some broken APs will never fall |
| 500 | * back to trying to transmit in 20 MHz. |
| 501 | */ |
| 502 | if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) { |
| 503 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 504 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 505 | } |
| 506 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 507 | /* set SM PS mode properly */ |
| 508 | cap &= ~IEEE80211_HT_CAP_SM_PS; |
| 509 | switch (smps) { |
| 510 | case IEEE80211_SMPS_AUTOMATIC: |
| 511 | case IEEE80211_SMPS_NUM_MODES: |
| 512 | WARN_ON(1); |
Gustavo A. R. Silva | 02049ce | 2017-10-17 18:14:50 -0500 | [diff] [blame] | 513 | /* fall through */ |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 514 | case IEEE80211_SMPS_OFF: |
| 515 | cap |= WLAN_HT_CAP_SM_PS_DISABLED << |
| 516 | IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 517 | break; |
| 518 | case IEEE80211_SMPS_STATIC: |
| 519 | cap |= WLAN_HT_CAP_SM_PS_STATIC << |
| 520 | IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 521 | break; |
| 522 | case IEEE80211_SMPS_DYNAMIC: |
| 523 | cap |= WLAN_HT_CAP_SM_PS_DYNAMIC << |
| 524 | IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 525 | break; |
| 526 | } |
| 527 | |
| 528 | /* reserve and fill IE */ |
| 529 | pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2); |
| 530 | ieee80211_ie_build_ht_cap(pos, &ht_cap, cap); |
| 531 | } |
| 532 | |
Sara Sharon | 322cd40 | 2015-07-08 15:41:43 +0300 | [diff] [blame] | 533 | /* This function determines vht capability flags for the association |
| 534 | * and builds the IE. |
| 535 | * Note - the function may set the owner of the MU-MIMO capability |
| 536 | */ |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 537 | static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata, |
| 538 | struct sk_buff *skb, |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 539 | struct ieee80211_supported_band *sband, |
| 540 | struct ieee80211_vht_cap *ap_vht_cap) |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 541 | { |
Sara Sharon | 322cd40 | 2015-07-08 15:41:43 +0300 | [diff] [blame] | 542 | struct ieee80211_local *local = sdata->local; |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 543 | u8 *pos; |
| 544 | u32 cap; |
| 545 | struct ieee80211_sta_vht_cap vht_cap; |
Eyal Shapira | c1cf6d4 | 2014-01-08 15:49:08 +0200 | [diff] [blame] | 546 | u32 mask, ap_bf_sts, our_bf_sts; |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 547 | |
| 548 | BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap)); |
| 549 | |
| 550 | memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap)); |
Johannes Berg | dd5ecfe | 2013-02-21 17:40:19 +0100 | [diff] [blame] | 551 | ieee80211_apply_vhtcap_overrides(sdata, &vht_cap); |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 552 | |
| 553 | /* determine capability flags */ |
| 554 | cap = vht_cap.cap; |
| 555 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 556 | if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) { |
Johannes Berg | 575f053 | 2014-11-24 16:51:33 +0100 | [diff] [blame] | 557 | u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; |
| 558 | |
| 559 | cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; |
| 560 | if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ || |
| 561 | bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ) |
| 562 | cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) { |
| 566 | cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160; |
Johannes Berg | 575f053 | 2014-11-24 16:51:33 +0100 | [diff] [blame] | 567 | cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 568 | } |
| 569 | |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 570 | /* |
| 571 | * Some APs apparently get confused if our capabilities are better |
| 572 | * than theirs, so restrict what we advertise in the assoc request. |
| 573 | */ |
| 574 | if (!(ap_vht_cap->vht_cap_info & |
| 575 | cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE))) |
Sara Sharon | 322cd40 | 2015-07-08 15:41:43 +0300 | [diff] [blame] | 576 | cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
| 577 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE); |
| 578 | else if (!(ap_vht_cap->vht_cap_info & |
| 579 | cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))) |
| 580 | cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE; |
| 581 | |
| 582 | /* |
| 583 | * If some other vif is using the MU-MIMO capablity we cannot associate |
| 584 | * using MU-MIMO - this will lead to contradictions in the group-id |
| 585 | * mechanism. |
| 586 | * Ownership is defined since association request, in order to avoid |
| 587 | * simultaneous associations with MU-MIMO. |
| 588 | */ |
| 589 | if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) { |
| 590 | bool disable_mu_mimo = false; |
| 591 | struct ieee80211_sub_if_data *other; |
| 592 | |
| 593 | list_for_each_entry_rcu(other, &local->interfaces, list) { |
Sara Sharon | b5a33d5 | 2016-02-16 12:48:18 +0200 | [diff] [blame] | 594 | if (other->vif.mu_mimo_owner) { |
Sara Sharon | 322cd40 | 2015-07-08 15:41:43 +0300 | [diff] [blame] | 595 | disable_mu_mimo = true; |
| 596 | break; |
| 597 | } |
| 598 | } |
| 599 | if (disable_mu_mimo) |
| 600 | cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE; |
| 601 | else |
Sara Sharon | b5a33d5 | 2016-02-16 12:48:18 +0200 | [diff] [blame] | 602 | sdata->vif.mu_mimo_owner = true; |
Sara Sharon | 322cd40 | 2015-07-08 15:41:43 +0300 | [diff] [blame] | 603 | } |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 604 | |
Eyal Shapira | c1cf6d4 | 2014-01-08 15:49:08 +0200 | [diff] [blame] | 605 | mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK; |
| 606 | |
| 607 | ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask; |
| 608 | our_bf_sts = cap & mask; |
| 609 | |
| 610 | if (ap_bf_sts < our_bf_sts) { |
| 611 | cap &= ~mask; |
| 612 | cap |= ap_bf_sts; |
| 613 | } |
| 614 | |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 615 | /* reserve and fill IE */ |
Mahesh Palivela | d495028 | 2012-10-10 11:25:40 +0000 | [diff] [blame] | 616 | pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2); |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 617 | ieee80211_ie_build_vht_cap(pos, &vht_cap, cap); |
| 618 | } |
| 619 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 620 | /* This function determines HE capability flags for the association |
| 621 | * and builds the IE. |
| 622 | */ |
| 623 | static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata, |
| 624 | struct sk_buff *skb, |
| 625 | struct ieee80211_supported_band *sband) |
| 626 | { |
| 627 | u8 *pos; |
| 628 | const struct ieee80211_sta_he_cap *he_cap = NULL; |
Haim Dreyfuss | b5db1ac | 2020-01-31 13:12:44 +0200 | [diff] [blame] | 629 | struct ieee80211_chanctx_conf *chanctx_conf; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 630 | u8 he_cap_size; |
Haim Dreyfuss | b5db1ac | 2020-01-31 13:12:44 +0200 | [diff] [blame] | 631 | bool reg_cap = false; |
| 632 | |
| 633 | rcu_read_lock(); |
| 634 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 635 | if (!WARN_ON_ONCE(!chanctx_conf)) |
| 636 | reg_cap = cfg80211_chandef_usable(sdata->wdev.wiphy, |
| 637 | &chanctx_conf->def, |
| 638 | IEEE80211_CHAN_NO_HE); |
| 639 | |
| 640 | rcu_read_unlock(); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 641 | |
| 642 | he_cap = ieee80211_get_he_sta_cap(sband); |
Haim Dreyfuss | b5db1ac | 2020-01-31 13:12:44 +0200 | [diff] [blame] | 643 | if (!he_cap || !reg_cap) |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 644 | return; |
| 645 | |
| 646 | /* |
| 647 | * TODO: the 1 added is because this temporarily is under the EXTENSION |
| 648 | * IE. Get rid of it when it moves. |
| 649 | */ |
| 650 | he_cap_size = |
| 651 | 2 + 1 + sizeof(he_cap->he_cap_elem) + |
| 652 | ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) + |
| 653 | ieee80211_he_ppe_size(he_cap->ppe_thres[0], |
| 654 | he_cap->he_cap_elem.phy_cap_info); |
| 655 | pos = skb_put(skb, he_cap_size); |
| 656 | ieee80211_ie_build_he_cap(pos, he_cap, pos + he_cap_size); |
| 657 | } |
| 658 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 659 | static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata) |
| 660 | { |
| 661 | struct ieee80211_local *local = sdata->local; |
| 662 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 663 | struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; |
| 664 | struct sk_buff *skb; |
| 665 | struct ieee80211_mgmt *mgmt; |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 666 | u8 *pos, qos_info, *ie_start; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 667 | size_t offset = 0, noffset; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 668 | int i, count, rates_len, supp_rates_len, shift; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 669 | u16 capab; |
| 670 | struct ieee80211_supported_band *sband; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 671 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 672 | struct ieee80211_channel *chan; |
Johannes Berg | 44f6d42 | 2017-06-10 13:52:44 +0300 | [diff] [blame] | 673 | u32 rates = 0; |
Johannes Berg | 2ff69b0 | 2020-01-31 13:31:11 +0200 | [diff] [blame] | 674 | struct element *ext_capa = NULL; |
| 675 | |
| 676 | /* we know it's writable, cast away the const */ |
| 677 | if (assoc_data->ie_len) |
| 678 | ext_capa = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, |
| 679 | assoc_data->ie, |
| 680 | assoc_data->ie_len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 681 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 682 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 683 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 684 | rcu_read_lock(); |
| 685 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 686 | if (WARN_ON(!chanctx_conf)) { |
| 687 | rcu_read_unlock(); |
| 688 | return; |
| 689 | } |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 690 | chan = chanctx_conf->def.chan; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 691 | rcu_read_unlock(); |
| 692 | sband = local->hw.wiphy->bands[chan->band]; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 693 | shift = ieee80211_vif_get_shift(&sdata->vif); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 694 | |
| 695 | if (assoc_data->supp_rates_len) { |
| 696 | /* |
| 697 | * Get all rates supported by the device and the AP as |
| 698 | * some APs don't like getting a superset of their rates |
| 699 | * in the association request (e.g. D-Link DAP 1353 in |
| 700 | * b-only mode)... |
| 701 | */ |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 702 | rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband, |
| 703 | assoc_data->supp_rates, |
| 704 | assoc_data->supp_rates_len, |
| 705 | &rates); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 706 | } else { |
| 707 | /* |
| 708 | * In case AP not provide any supported rates information |
| 709 | * before association, we send information element(s) with |
| 710 | * all rates that we support. |
| 711 | */ |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 712 | rates_len = 0; |
| 713 | for (i = 0; i < sband->n_bitrates; i++) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 714 | rates |= BIT(i); |
| 715 | rates_len++; |
| 716 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | skb = alloc_skb(local->hw.extra_tx_headroom + |
| 720 | sizeof(*mgmt) + /* bit too much but doesn't matter */ |
| 721 | 2 + assoc_data->ssid_len + /* SSID */ |
| 722 | 4 + rates_len + /* (extended) rates */ |
| 723 | 4 + /* power capability */ |
| 724 | 2 + 2 * sband->n_channels + /* supported channels */ |
| 725 | 2 + sizeof(struct ieee80211_ht_cap) + /* HT */ |
Mahesh Palivela | d495028 | 2012-10-10 11:25:40 +0000 | [diff] [blame] | 726 | 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */ |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 727 | 2 + 1 + sizeof(struct ieee80211_he_cap_elem) + /* HE */ |
| 728 | sizeof(struct ieee80211_he_mcs_nss_supp) + |
| 729 | IEEE80211_HE_PPE_THRES_MAX_LEN + |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 730 | assoc_data->ie_len + /* extra IEs */ |
Jouni Malinen | 39404fe | 2016-10-27 00:42:05 +0300 | [diff] [blame] | 731 | (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) + |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 732 | 9, /* WMM */ |
| 733 | GFP_KERNEL); |
| 734 | if (!skb) |
| 735 | return; |
| 736 | |
| 737 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 738 | |
| 739 | capab = WLAN_CAPABILITY_ESS; |
| 740 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 741 | if (sband->band == NL80211_BAND_2GHZ) { |
Johannes Berg | ea1b2b45 | 2015-06-02 20:15:49 +0200 | [diff] [blame] | 742 | capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME; |
| 743 | capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY) |
| 747 | capab |= WLAN_CAPABILITY_PRIVACY; |
| 748 | |
| 749 | if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) && |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 750 | ieee80211_hw_check(&local->hw, SPECTRUM_MGMT)) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 751 | capab |= WLAN_CAPABILITY_SPECTRUM_MGMT; |
| 752 | |
Assaf Krauss | cd2f5dd | 2014-09-03 15:25:02 +0300 | [diff] [blame] | 753 | if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM) |
| 754 | capab |= WLAN_CAPABILITY_RADIO_MEASURE; |
| 755 | |
Johannes Berg | b080db5 | 2017-06-16 14:29:19 +0200 | [diff] [blame] | 756 | mgmt = skb_put_zero(skb, 24); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 757 | memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN); |
| 758 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
| 759 | memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN); |
| 760 | |
| 761 | if (!is_zero_ether_addr(assoc_data->prev_bssid)) { |
| 762 | skb_put(skb, 10); |
| 763 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 764 | IEEE80211_STYPE_REASSOC_REQ); |
| 765 | mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab); |
| 766 | mgmt->u.reassoc_req.listen_interval = |
| 767 | cpu_to_le16(local->hw.conf.listen_interval); |
| 768 | memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid, |
| 769 | ETH_ALEN); |
| 770 | } else { |
| 771 | skb_put(skb, 4); |
| 772 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 773 | IEEE80211_STYPE_ASSOC_REQ); |
| 774 | mgmt->u.assoc_req.capab_info = cpu_to_le16(capab); |
| 775 | mgmt->u.assoc_req.listen_interval = |
| 776 | cpu_to_le16(local->hw.conf.listen_interval); |
| 777 | } |
| 778 | |
| 779 | /* SSID */ |
| 780 | pos = skb_put(skb, 2 + assoc_data->ssid_len); |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 781 | ie_start = pos; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 782 | *pos++ = WLAN_EID_SSID; |
| 783 | *pos++ = assoc_data->ssid_len; |
| 784 | memcpy(pos, assoc_data->ssid, assoc_data->ssid_len); |
| 785 | |
| 786 | /* add all rates which were marked to be used above */ |
| 787 | supp_rates_len = rates_len; |
| 788 | if (supp_rates_len > 8) |
| 789 | supp_rates_len = 8; |
| 790 | |
| 791 | pos = skb_put(skb, supp_rates_len + 2); |
| 792 | *pos++ = WLAN_EID_SUPP_RATES; |
| 793 | *pos++ = supp_rates_len; |
| 794 | |
| 795 | count = 0; |
| 796 | for (i = 0; i < sband->n_bitrates; i++) { |
| 797 | if (BIT(i) & rates) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 798 | int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate, |
| 799 | 5 * (1 << shift)); |
| 800 | *pos++ = (u8) rate; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 801 | if (++count == 8) |
| 802 | break; |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | if (rates_len > count) { |
| 807 | pos = skb_put(skb, rates_len - count + 2); |
| 808 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 809 | *pos++ = rates_len - count; |
| 810 | |
| 811 | for (i++; i < sband->n_bitrates; i++) { |
| 812 | if (BIT(i) & rates) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 813 | int rate; |
| 814 | rate = DIV_ROUND_UP(sband->bitrates[i].bitrate, |
| 815 | 5 * (1 << shift)); |
| 816 | *pos++ = (u8) rate; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 817 | } |
| 818 | } |
| 819 | } |
| 820 | |
Assaf Krauss | cd2f5dd | 2014-09-03 15:25:02 +0300 | [diff] [blame] | 821 | if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT || |
| 822 | capab & WLAN_CAPABILITY_RADIO_MEASURE) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 823 | pos = skb_put(skb, 4); |
| 824 | *pos++ = WLAN_EID_PWR_CAPABILITY; |
| 825 | *pos++ = 2; |
| 826 | *pos++ = 0; /* min tx power */ |
Simon Wunderlich | 0430c88 | 2013-07-08 16:55:55 +0200 | [diff] [blame] | 827 | /* max tx power */ |
| 828 | *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def); |
Assaf Krauss | cd2f5dd | 2014-09-03 15:25:02 +0300 | [diff] [blame] | 829 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 830 | |
Johannes Berg | 2ff69b0 | 2020-01-31 13:31:11 +0200 | [diff] [blame] | 831 | /* |
| 832 | * Per spec, we shouldn't include the list of channels if we advertise |
| 833 | * support for extended channel switching, but we've always done that; |
| 834 | * (for now?) apply this restriction only on the (new) 6 GHz band. |
| 835 | */ |
| 836 | if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT && |
| 837 | (sband->band != NL80211_BAND_6GHZ || |
| 838 | !ext_capa || ext_capa->datalen < 1 || |
| 839 | !(ext_capa->data[0] & WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING))) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 840 | /* TODO: get this in reg domain format */ |
| 841 | pos = skb_put(skb, 2 * sband->n_channels + 2); |
| 842 | *pos++ = WLAN_EID_SUPPORTED_CHANNELS; |
| 843 | *pos++ = 2 * sband->n_channels; |
| 844 | for (i = 0; i < sband->n_channels; i++) { |
| 845 | *pos++ = ieee80211_frequency_to_channel( |
| 846 | sband->channels[i].center_freq); |
| 847 | *pos++ = 1; /* one channel in the subband*/ |
| 848 | } |
| 849 | } |
| 850 | |
Sara Sharon | caf5633 | 2019-01-16 23:03:25 +0200 | [diff] [blame] | 851 | /* Set MBSSID support for HE AP if needed */ |
| 852 | if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) && |
Johannes Berg | 2ff69b0 | 2020-01-31 13:31:11 +0200 | [diff] [blame] | 853 | !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && assoc_data->ie_len && |
| 854 | ext_capa && ext_capa->datalen >= 3) |
| 855 | ext_capa->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT; |
Sara Sharon | caf5633 | 2019-01-16 23:03:25 +0200 | [diff] [blame] | 856 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 857 | /* if present, add any custom IEs that go before HT */ |
Johannes Berg | b3f51e9 | 2013-10-25 11:31:42 +0200 | [diff] [blame] | 858 | if (assoc_data->ie_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 859 | static const u8 before_ht[] = { |
| 860 | WLAN_EID_SSID, |
| 861 | WLAN_EID_SUPP_RATES, |
| 862 | WLAN_EID_EXT_SUPP_RATES, |
| 863 | WLAN_EID_PWR_CAPABILITY, |
| 864 | WLAN_EID_SUPPORTED_CHANNELS, |
| 865 | WLAN_EID_RSN, |
| 866 | WLAN_EID_QOS_CAPA, |
| 867 | WLAN_EID_RRM_ENABLED_CAPABILITIES, |
| 868 | WLAN_EID_MOBILITY_DOMAIN, |
Johannes Berg | 8ed2874 | 2014-10-27 12:03:19 +0100 | [diff] [blame] | 869 | WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */ |
| 870 | WLAN_EID_RIC_DATA, /* reassoc only */ |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 871 | WLAN_EID_SUPPORTED_REGULATORY_CLASSES, |
| 872 | }; |
Johannes Berg | 8ed2874 | 2014-10-27 12:03:19 +0100 | [diff] [blame] | 873 | static const u8 after_ric[] = { |
| 874 | WLAN_EID_SUPPORTED_REGULATORY_CLASSES, |
| 875 | WLAN_EID_HT_CAPABILITY, |
| 876 | WLAN_EID_BSS_COEX_2040, |
Johannes Berg | a7f26d8 | 2017-08-05 11:44:32 +0300 | [diff] [blame] | 877 | /* luckily this is almost always there */ |
Johannes Berg | 8ed2874 | 2014-10-27 12:03:19 +0100 | [diff] [blame] | 878 | WLAN_EID_EXT_CAPABILITY, |
| 879 | WLAN_EID_QOS_TRAFFIC_CAPA, |
| 880 | WLAN_EID_TIM_BCAST_REQ, |
| 881 | WLAN_EID_INTERWORKING, |
Johannes Berg | a7f26d8 | 2017-08-05 11:44:32 +0300 | [diff] [blame] | 882 | /* 60 GHz (Multi-band, DMG, MMS) can't happen */ |
Johannes Berg | 8ed2874 | 2014-10-27 12:03:19 +0100 | [diff] [blame] | 883 | WLAN_EID_VHT_CAPABILITY, |
| 884 | WLAN_EID_OPMODE_NOTIF, |
| 885 | }; |
| 886 | |
| 887 | noffset = ieee80211_ie_split_ric(assoc_data->ie, |
| 888 | assoc_data->ie_len, |
| 889 | before_ht, |
| 890 | ARRAY_SIZE(before_ht), |
| 891 | after_ric, |
| 892 | ARRAY_SIZE(after_ric), |
| 893 | offset); |
yuan linyu | b952f4d | 2017-06-18 22:52:04 +0800 | [diff] [blame] | 894 | skb_put_data(skb, assoc_data->ie + offset, noffset - offset); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 895 | offset = noffset; |
| 896 | } |
| 897 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 898 | if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) && |
| 899 | !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))) |
| 900 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
| 901 | |
Johannes Berg | a8243b7 | 2012-11-22 14:32:09 +0100 | [diff] [blame] | 902 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 903 | ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param, |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 904 | sband, chan, sdata->smps_mode); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 905 | |
Johannes Berg | 3de3802 | 2014-02-04 09:54:07 +0100 | [diff] [blame] | 906 | /* if present, add any custom IEs that go before VHT */ |
| 907 | if (assoc_data->ie_len) { |
| 908 | static const u8 before_vht[] = { |
Johannes Berg | a7f26d8 | 2017-08-05 11:44:32 +0300 | [diff] [blame] | 909 | /* |
| 910 | * no need to list the ones split off before HT |
| 911 | * or generated here |
| 912 | */ |
Johannes Berg | 3de3802 | 2014-02-04 09:54:07 +0100 | [diff] [blame] | 913 | WLAN_EID_BSS_COEX_2040, |
| 914 | WLAN_EID_EXT_CAPABILITY, |
| 915 | WLAN_EID_QOS_TRAFFIC_CAPA, |
| 916 | WLAN_EID_TIM_BCAST_REQ, |
| 917 | WLAN_EID_INTERWORKING, |
Johannes Berg | a7f26d8 | 2017-08-05 11:44:32 +0300 | [diff] [blame] | 918 | /* 60 GHz (Multi-band, DMG, MMS) can't happen */ |
Johannes Berg | 3de3802 | 2014-02-04 09:54:07 +0100 | [diff] [blame] | 919 | }; |
Johannes Berg | 8ed2874 | 2014-10-27 12:03:19 +0100 | [diff] [blame] | 920 | |
| 921 | /* RIC already taken above, so no need to handle here anymore */ |
Johannes Berg | 3de3802 | 2014-02-04 09:54:07 +0100 | [diff] [blame] | 922 | noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len, |
| 923 | before_vht, ARRAY_SIZE(before_vht), |
| 924 | offset); |
yuan linyu | b952f4d | 2017-06-18 22:52:04 +0800 | [diff] [blame] | 925 | skb_put_data(skb, assoc_data->ie + offset, noffset - offset); |
Johannes Berg | 3de3802 | 2014-02-04 09:54:07 +0100 | [diff] [blame] | 926 | offset = noffset; |
| 927 | } |
| 928 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 929 | /* if present, add any custom IEs that go before HE */ |
| 930 | if (assoc_data->ie_len) { |
| 931 | static const u8 before_he[] = { |
| 932 | /* |
| 933 | * no need to list the ones split off before VHT |
| 934 | * or generated here |
| 935 | */ |
| 936 | WLAN_EID_OPMODE_NOTIF, |
| 937 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE, |
| 938 | /* 11ai elements */ |
| 939 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION, |
| 940 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY, |
| 941 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM, |
| 942 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER, |
| 943 | WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN, |
| 944 | /* TODO: add 11ah/11aj/11ak elements */ |
| 945 | }; |
| 946 | |
| 947 | /* RIC already taken above, so no need to handle here anymore */ |
| 948 | noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len, |
| 949 | before_he, ARRAY_SIZE(before_he), |
| 950 | offset); |
| 951 | pos = skb_put(skb, noffset - offset); |
| 952 | memcpy(pos, assoc_data->ie + offset, noffset - offset); |
| 953 | offset = noffset; |
| 954 | } |
| 955 | |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 956 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 957 | ieee80211_add_vht_ie(sdata, skb, sband, |
| 958 | &assoc_data->ap_vht_cap); |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 959 | |
Shaul Triebitz | dc7eb0f | 2018-12-15 11:03:20 +0200 | [diff] [blame] | 960 | /* |
| 961 | * If AP doesn't support HT, mark HE as disabled. |
| 962 | * If on the 5GHz band, make sure it supports VHT. |
| 963 | */ |
| 964 | if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || |
| 965 | (sband->band == NL80211_BAND_5GHZ && |
| 966 | ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
| 967 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
| 968 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 969 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) |
| 970 | ieee80211_add_he_ie(sdata, skb, sband); |
| 971 | |
| 972 | /* if present, add any custom non-vendor IEs that go after HE */ |
Johannes Berg | b3f51e9 | 2013-10-25 11:31:42 +0200 | [diff] [blame] | 973 | if (assoc_data->ie_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 974 | noffset = ieee80211_ie_split_vendor(assoc_data->ie, |
| 975 | assoc_data->ie_len, |
| 976 | offset); |
yuan linyu | b952f4d | 2017-06-18 22:52:04 +0800 | [diff] [blame] | 977 | skb_put_data(skb, assoc_data->ie + offset, noffset - offset); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 978 | offset = noffset; |
| 979 | } |
| 980 | |
Johannes Berg | 76f0303 | 2012-03-08 15:02:05 +0100 | [diff] [blame] | 981 | if (assoc_data->wmm) { |
| 982 | if (assoc_data->uapsd) { |
Eliad Peller | dc41e4d | 2012-03-14 16:15:03 +0200 | [diff] [blame] | 983 | qos_info = ifmgd->uapsd_queues; |
| 984 | qos_info |= (ifmgd->uapsd_max_sp_len << |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 985 | IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT); |
| 986 | } else { |
| 987 | qos_info = 0; |
| 988 | } |
| 989 | |
Arik Nemtsov | 40b861a | 2014-07-17 17:14:23 +0300 | [diff] [blame] | 990 | pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | /* add any remaining custom (i.e. vendor specific here) IEs */ |
Johannes Berg | b3f51e9 | 2013-10-25 11:31:42 +0200 | [diff] [blame] | 994 | if (assoc_data->ie_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 995 | noffset = assoc_data->ie_len; |
yuan linyu | b952f4d | 2017-06-18 22:52:04 +0800 | [diff] [blame] | 996 | skb_put_data(skb, assoc_data->ie + offset, noffset - offset); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 997 | } |
| 998 | |
Jouni Malinen | 39404fe | 2016-10-27 00:42:05 +0300 | [diff] [blame] | 999 | if (assoc_data->fils_kek_len && |
| 1000 | fils_encrypt_assoc_req(skb, assoc_data) < 0) { |
| 1001 | dev_kfree_skb(skb); |
| 1002 | return; |
| 1003 | } |
| 1004 | |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 1005 | pos = skb_tail_pointer(skb); |
| 1006 | kfree(ifmgd->assoc_req_ies); |
| 1007 | ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC); |
| 1008 | ifmgd->assoc_req_ies_len = pos - ie_start; |
| 1009 | |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 1010 | drv_mgd_prepare_tx(local, sdata, 0); |
Johannes Berg | a1845fc | 2012-06-27 13:18:36 +0200 | [diff] [blame] | 1011 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1012 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1013 | if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 1014 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS | |
| 1015 | IEEE80211_TX_INTFL_MLME_CONN_TX; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1016 | ieee80211_tx_skb(sdata, skb); |
| 1017 | } |
| 1018 | |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1019 | void ieee80211_send_pspoll(struct ieee80211_local *local, |
| 1020 | struct ieee80211_sub_if_data *sdata) |
| 1021 | { |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1022 | struct ieee80211_pspoll *pspoll; |
| 1023 | struct sk_buff *skb; |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1024 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1025 | skb = ieee80211_pspoll_get(&local->hw, &sdata->vif); |
| 1026 | if (!skb) |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1027 | return; |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1028 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1029 | pspoll = (struct ieee80211_pspoll *) skb->data; |
| 1030 | pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1031 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 1032 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 1033 | ieee80211_tx_skb(sdata, skb); |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1034 | } |
| 1035 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1036 | void ieee80211_send_nullfunc(struct ieee80211_local *local, |
| 1037 | struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 076cdcb | 2015-09-24 16:14:55 +0200 | [diff] [blame] | 1038 | bool powersave) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1039 | { |
| 1040 | struct sk_buff *skb; |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1041 | struct ieee80211_hdr_3addr *nullfunc; |
Rajkumar Manoharan | b6f3530 | 2011-09-29 20:34:04 +0530 | [diff] [blame] | 1042 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1043 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 1044 | /* Don't send NDPs when STA is connected HE */ |
| 1045 | if (sdata->vif.type == NL80211_IFTYPE_STATION && |
| 1046 | !(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) |
| 1047 | return; |
| 1048 | |
Ben Caradoc-Davies | 7c181f4 | 2018-03-19 12:57:44 +1300 | [diff] [blame] | 1049 | skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif, |
| 1050 | !ieee80211_hw_check(&local->hw, DOESNT_SUPPORT_QOS_NDP)); |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1051 | if (!skb) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1052 | return; |
| 1053 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1054 | nullfunc = (struct ieee80211_hdr_3addr *) skb->data; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1055 | if (powersave) |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 1056 | nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1057 | |
Seth Forshee | 6c17b77 | 2013-02-11 11:21:07 -0600 | [diff] [blame] | 1058 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT | |
| 1059 | IEEE80211_TX_INTFL_OFFCHAN_TX_OK; |
Pontus Fuchs | ff40b42 | 2013-06-04 12:44:52 +0200 | [diff] [blame] | 1060 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1061 | if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
Pontus Fuchs | ff40b42 | 2013-06-04 12:44:52 +0200 | [diff] [blame] | 1062 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; |
| 1063 | |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 1064 | if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) |
Rajkumar Manoharan | b6f3530 | 2011-09-29 20:34:04 +0530 | [diff] [blame] | 1065 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE; |
| 1066 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 1067 | ieee80211_tx_skb(sdata, skb); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1068 | } |
| 1069 | |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 1070 | static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local, |
| 1071 | struct ieee80211_sub_if_data *sdata) |
| 1072 | { |
| 1073 | struct sk_buff *skb; |
| 1074 | struct ieee80211_hdr *nullfunc; |
| 1075 | __le16 fc; |
| 1076 | |
| 1077 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) |
| 1078 | return; |
| 1079 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 1080 | /* Don't send NDPs when connected HE */ |
| 1081 | if (!(sdata->u.mgd.flags & IEEE80211_STA_DISABLE_HE)) |
| 1082 | return; |
| 1083 | |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 1084 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30); |
Joe Perches | d15b845 | 2011-08-29 14:17:31 -0700 | [diff] [blame] | 1085 | if (!skb) |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 1086 | return; |
Joe Perches | d15b845 | 2011-08-29 14:17:31 -0700 | [diff] [blame] | 1087 | |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 1088 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 1089 | |
Johannes Berg | b080db5 | 2017-06-16 14:29:19 +0200 | [diff] [blame] | 1090 | nullfunc = skb_put_zero(skb, 30); |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 1091 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | |
| 1092 | IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); |
| 1093 | nullfunc->frame_control = fc; |
| 1094 | memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN); |
| 1095 | memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); |
| 1096 | memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN); |
| 1097 | memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN); |
| 1098 | |
| 1099 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 1100 | ieee80211_tx_skb(sdata, skb); |
| 1101 | } |
| 1102 | |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1103 | /* spectrum management related things */ |
| 1104 | static void ieee80211_chswitch_work(struct work_struct *work) |
| 1105 | { |
| 1106 | struct ieee80211_sub_if_data *sdata = |
| 1107 | container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work); |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 1108 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1109 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Arik Nemtsov | 7578d57 | 2013-09-01 17:15:51 +0300 | [diff] [blame] | 1110 | int ret; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1111 | |
Johannes Berg | 9607e6b66 | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 1112 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1113 | return; |
| 1114 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 1115 | sdata_lock(sdata); |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1116 | mutex_lock(&local->mtx); |
| 1117 | mutex_lock(&local->chanctx_mtx); |
| 1118 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1119 | if (!ifmgd->associated) |
| 1120 | goto out; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1121 | |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1122 | if (!sdata->vif.csa_active) |
| 1123 | goto out; |
| 1124 | |
| 1125 | /* |
| 1126 | * using reservation isn't immediate as it may be deferred until later |
| 1127 | * with multi-vif. once reservation is complete it will re-schedule the |
| 1128 | * work with no reserved_chanctx so verify chandef to check if it |
| 1129 | * completed successfully |
| 1130 | */ |
| 1131 | |
| 1132 | if (sdata->reserved_chanctx) { |
Ilan Peer | 0007e94 | 2018-08-31 11:31:10 +0300 | [diff] [blame] | 1133 | struct ieee80211_supported_band *sband = NULL; |
| 1134 | struct sta_info *mgd_sta = NULL; |
| 1135 | enum ieee80211_sta_rx_bandwidth bw = IEEE80211_STA_RX_BW_20; |
| 1136 | |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1137 | /* |
| 1138 | * with multi-vif csa driver may call ieee80211_csa_finish() |
| 1139 | * many times while waiting for other interfaces to use their |
| 1140 | * reservations |
| 1141 | */ |
| 1142 | if (sdata->reserved_ready) |
| 1143 | goto out; |
| 1144 | |
Ilan Peer | 0007e94 | 2018-08-31 11:31:10 +0300 | [diff] [blame] | 1145 | if (sdata->vif.bss_conf.chandef.width != |
| 1146 | sdata->csa_chandef.width) { |
| 1147 | /* |
| 1148 | * For managed interface, we need to also update the AP |
| 1149 | * station bandwidth and align the rate scale algorithm |
| 1150 | * on the bandwidth change. Here we only consider the |
| 1151 | * bandwidth of the new channel definition (as channel |
| 1152 | * switch flow does not have the full HT/VHT/HE |
| 1153 | * information), assuming that if additional changes are |
| 1154 | * required they would be done as part of the processing |
| 1155 | * of the next beacon from the AP. |
| 1156 | */ |
| 1157 | switch (sdata->csa_chandef.width) { |
| 1158 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 1159 | case NL80211_CHAN_WIDTH_20: |
| 1160 | default: |
| 1161 | bw = IEEE80211_STA_RX_BW_20; |
| 1162 | break; |
| 1163 | case NL80211_CHAN_WIDTH_40: |
| 1164 | bw = IEEE80211_STA_RX_BW_40; |
| 1165 | break; |
| 1166 | case NL80211_CHAN_WIDTH_80: |
| 1167 | bw = IEEE80211_STA_RX_BW_80; |
| 1168 | break; |
| 1169 | case NL80211_CHAN_WIDTH_80P80: |
| 1170 | case NL80211_CHAN_WIDTH_160: |
| 1171 | bw = IEEE80211_STA_RX_BW_160; |
| 1172 | break; |
| 1173 | } |
| 1174 | |
| 1175 | mgd_sta = sta_info_get(sdata, ifmgd->bssid); |
| 1176 | sband = |
| 1177 | local->hw.wiphy->bands[sdata->csa_chandef.chan->band]; |
| 1178 | } |
| 1179 | |
| 1180 | if (sdata->vif.bss_conf.chandef.width > |
| 1181 | sdata->csa_chandef.width) { |
| 1182 | mgd_sta->sta.bandwidth = bw; |
| 1183 | rate_control_rate_update(local, sband, mgd_sta, |
| 1184 | IEEE80211_RC_BW_CHANGED); |
| 1185 | } |
| 1186 | |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1187 | ret = ieee80211_vif_use_reserved_context(sdata); |
| 1188 | if (ret) { |
| 1189 | sdata_info(sdata, |
| 1190 | "failed to use reserved channel context, disconnecting (err=%d)\n", |
| 1191 | ret); |
| 1192 | ieee80211_queue_work(&sdata->local->hw, |
| 1193 | &ifmgd->csa_connection_drop_work); |
| 1194 | goto out; |
| 1195 | } |
| 1196 | |
Ilan Peer | 0007e94 | 2018-08-31 11:31:10 +0300 | [diff] [blame] | 1197 | if (sdata->vif.bss_conf.chandef.width < |
| 1198 | sdata->csa_chandef.width) { |
| 1199 | mgd_sta->sta.bandwidth = bw; |
| 1200 | rate_control_rate_update(local, sband, mgd_sta, |
| 1201 | IEEE80211_RC_BW_CHANGED); |
| 1202 | } |
| 1203 | |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1204 | goto out; |
| 1205 | } |
| 1206 | |
| 1207 | if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef, |
| 1208 | &sdata->csa_chandef)) { |
Arik Nemtsov | 7578d57 | 2013-09-01 17:15:51 +0300 | [diff] [blame] | 1209 | sdata_info(sdata, |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1210 | "failed to finalize channel switch, disconnecting\n"); |
Arik Nemtsov | 7578d57 | 2013-09-01 17:15:51 +0300 | [diff] [blame] | 1211 | ieee80211_queue_work(&sdata->local->hw, |
| 1212 | &ifmgd->csa_connection_drop_work); |
| 1213 | goto out; |
| 1214 | } |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 1215 | |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 1216 | ifmgd->csa_waiting_bcn = true; |
Luciano Coelho | f1d6558 | 2014-10-08 09:48:38 +0300 | [diff] [blame] | 1217 | |
Michal Kazior | e5593f5 | 2014-04-09 15:45:36 +0200 | [diff] [blame] | 1218 | ieee80211_sta_reset_beacon_monitor(sdata); |
| 1219 | ieee80211_sta_reset_conn_monitor(sdata); |
| 1220 | |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 1221 | out: |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1222 | mutex_unlock(&local->chanctx_mtx); |
| 1223 | mutex_unlock(&local->mtx); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 1224 | sdata_unlock(sdata); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1225 | } |
| 1226 | |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 1227 | static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data *sdata) |
| 1228 | { |
| 1229 | struct ieee80211_local *local = sdata->local; |
| 1230 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 1231 | int ret; |
| 1232 | |
| 1233 | sdata_assert_lock(sdata); |
| 1234 | |
| 1235 | WARN_ON(!sdata->vif.csa_active); |
| 1236 | |
| 1237 | if (sdata->csa_block_tx) { |
| 1238 | ieee80211_wake_vif_queues(local, sdata, |
| 1239 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 1240 | sdata->csa_block_tx = false; |
| 1241 | } |
| 1242 | |
| 1243 | sdata->vif.csa_active = false; |
| 1244 | ifmgd->csa_waiting_bcn = false; |
| 1245 | |
| 1246 | ret = drv_post_channel_switch(sdata); |
| 1247 | if (ret) { |
| 1248 | sdata_info(sdata, |
| 1249 | "driver post channel switch failed, disconnecting\n"); |
| 1250 | ieee80211_queue_work(&local->hw, |
| 1251 | &ifmgd->csa_connection_drop_work); |
| 1252 | return; |
| 1253 | } |
Luciano Coelho | 688b1ec | 2014-12-16 16:01:39 +0200 | [diff] [blame] | 1254 | |
| 1255 | cfg80211_ch_switch_notify(sdata->dev, &sdata->reserved_chandef); |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 1256 | } |
| 1257 | |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1258 | void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success) |
| 1259 | { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1260 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 1261 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1262 | |
| 1263 | trace_api_chswitch_done(sdata, success); |
| 1264 | if (!success) { |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 1265 | sdata_info(sdata, |
| 1266 | "driver channel switch failed, disconnecting\n"); |
| 1267 | ieee80211_queue_work(&sdata->local->hw, |
| 1268 | &ifmgd->csa_connection_drop_work); |
| 1269 | } else { |
| 1270 | ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1271 | } |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1272 | } |
| 1273 | EXPORT_SYMBOL(ieee80211_chswitch_done); |
| 1274 | |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 1275 | static void ieee80211_chswitch_timer(struct timer_list *t) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1276 | { |
| 1277 | struct ieee80211_sub_if_data *sdata = |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 1278 | from_timer(sdata, t, u.mgd.chswitch_timer); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1279 | |
Stanislaw Gruszka | 9b7d72c | 2013-02-28 10:55:27 +0100 | [diff] [blame] | 1280 | ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1281 | } |
| 1282 | |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 1283 | static void |
Sara Sharon | b9cc81d | 2019-02-06 13:17:10 +0200 | [diff] [blame] | 1284 | ieee80211_sta_abort_chanswitch(struct ieee80211_sub_if_data *sdata) |
| 1285 | { |
| 1286 | struct ieee80211_local *local = sdata->local; |
| 1287 | |
| 1288 | if (!local->ops->abort_channel_switch) |
| 1289 | return; |
| 1290 | |
| 1291 | mutex_lock(&local->mtx); |
| 1292 | |
| 1293 | mutex_lock(&local->chanctx_mtx); |
| 1294 | ieee80211_vif_unreserve_chanctx(sdata); |
| 1295 | mutex_unlock(&local->chanctx_mtx); |
| 1296 | |
| 1297 | if (sdata->csa_block_tx) |
| 1298 | ieee80211_wake_vif_queues(local, sdata, |
| 1299 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 1300 | |
| 1301 | sdata->csa_block_tx = false; |
| 1302 | sdata->vif.csa_active = false; |
| 1303 | |
| 1304 | mutex_unlock(&local->mtx); |
| 1305 | |
| 1306 | drv_abort_channel_switch(sdata); |
| 1307 | } |
| 1308 | |
| 1309 | static void |
Johannes Berg | 4a3cb70 | 2013-02-12 16:43:19 +0100 | [diff] [blame] | 1310 | ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata, |
Luciano Coelho | 2ba4538 | 2014-10-08 09:48:35 +0300 | [diff] [blame] | 1311 | u64 timestamp, u32 device_timestamp, |
| 1312 | struct ieee802_11_elems *elems, |
Johannes Berg | 04a161f | 2013-05-03 09:35:35 +0200 | [diff] [blame] | 1313 | bool beacon) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1314 | { |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1315 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1316 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 1317 | struct cfg80211_bss *cbss = ifmgd->associated; |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1318 | struct ieee80211_chanctx_conf *conf; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1319 | struct ieee80211_chanctx *chanctx; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1320 | enum nl80211_band current_band; |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1321 | struct ieee80211_csa_ie csa_ie; |
Luciano Coelho | 6d027bc | 2014-10-08 09:48:37 +0300 | [diff] [blame] | 1322 | struct ieee80211_channel_switch ch_switch; |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 1323 | int res; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1324 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 1325 | sdata_assert_lock(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1326 | |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 1327 | if (!cbss) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1328 | return; |
| 1329 | |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1330 | if (local->scanning) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1331 | return; |
| 1332 | |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 1333 | current_band = cbss->channel->band; |
Luciano Coelho | 84469a4 | 2014-10-28 13:33:04 +0200 | [diff] [blame] | 1334 | res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band, |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 1335 | ifmgd->flags, |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1336 | ifmgd->associated->bssid, &csa_ie); |
Sara Sharon | fafd2bc | 2019-02-06 13:17:15 +0200 | [diff] [blame] | 1337 | |
| 1338 | if (!res) { |
| 1339 | ch_switch.timestamp = timestamp; |
| 1340 | ch_switch.device_timestamp = device_timestamp; |
Sara Sharon | 2bf973f | 2020-01-31 13:12:51 +0200 | [diff] [blame] | 1341 | ch_switch.block_tx = csa_ie.mode; |
Sara Sharon | fafd2bc | 2019-02-06 13:17:15 +0200 | [diff] [blame] | 1342 | ch_switch.chandef = csa_ie.chandef; |
| 1343 | ch_switch.count = csa_ie.count; |
| 1344 | ch_switch.delay = csa_ie.max_switch_time; |
| 1345 | } |
| 1346 | |
Sara Sharon | b9cc81d | 2019-02-06 13:17:10 +0200 | [diff] [blame] | 1347 | if (res < 0) { |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1348 | ieee80211_queue_work(&local->hw, |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 1349 | &ifmgd->csa_connection_drop_work); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1350 | return; |
Sara Sharon | b9cc81d | 2019-02-06 13:17:10 +0200 | [diff] [blame] | 1351 | } |
| 1352 | |
Sara Sharon | fafd2bc | 2019-02-06 13:17:15 +0200 | [diff] [blame] | 1353 | if (beacon && sdata->vif.csa_active && !ifmgd->csa_waiting_bcn) { |
| 1354 | if (res) |
| 1355 | ieee80211_sta_abort_chanswitch(sdata); |
| 1356 | else |
| 1357 | drv_channel_switch_rx_beacon(sdata, &ch_switch); |
Sara Sharon | b9cc81d | 2019-02-06 13:17:10 +0200 | [diff] [blame] | 1358 | return; |
| 1359 | } else if (sdata->vif.csa_active || res) { |
| 1360 | /* disregard subsequent announcements if already processing */ |
| 1361 | return; |
| 1362 | } |
Johannes Berg | cd64f2a | 2013-03-28 10:44:18 +0100 | [diff] [blame] | 1363 | |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1364 | if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef, |
Johannes Berg | 85220d7 | 2013-03-25 18:29:27 +0100 | [diff] [blame] | 1365 | IEEE80211_CHAN_DISABLED)) { |
| 1366 | sdata_info(sdata, |
| 1367 | "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n", |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 1368 | ifmgd->associated->bssid, |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1369 | csa_ie.chandef.chan->center_freq, |
| 1370 | csa_ie.chandef.width, csa_ie.chandef.center_freq1, |
| 1371 | csa_ie.chandef.center_freq2); |
Johannes Berg | 85220d7 | 2013-03-25 18:29:27 +0100 | [diff] [blame] | 1372 | ieee80211_queue_work(&local->hw, |
| 1373 | &ifmgd->csa_connection_drop_work); |
| 1374 | return; |
| 1375 | } |
| 1376 | |
Johannes Berg | f84eaa1 | 2015-03-12 08:53:26 +0200 | [diff] [blame] | 1377 | if (cfg80211_chandef_identical(&csa_ie.chandef, |
Sara Sharon | 9792875 | 2019-02-06 13:17:16 +0200 | [diff] [blame] | 1378 | &sdata->vif.bss_conf.chandef) && |
| 1379 | (!csa_ie.mode || !beacon)) { |
Johannes Berg | f84eaa1 | 2015-03-12 08:53:26 +0200 | [diff] [blame] | 1380 | if (ifmgd->csa_ignored_same_chan) |
| 1381 | return; |
| 1382 | sdata_info(sdata, |
| 1383 | "AP %pM tries to chanswitch to same channel, ignore\n", |
| 1384 | ifmgd->associated->bssid); |
| 1385 | ifmgd->csa_ignored_same_chan = true; |
| 1386 | return; |
| 1387 | } |
| 1388 | |
Arik Nemtsov | c5a7168 | 2015-05-19 14:36:48 +0300 | [diff] [blame] | 1389 | /* |
| 1390 | * Drop all TDLS peers - either we disconnect or move to a different |
| 1391 | * channel from this point on. There's no telling what our peer will do. |
| 1392 | * The TDLS WIDER_BW scenario is also problematic, as peers might now |
| 1393 | * have an incompatible wider chandef. |
| 1394 | */ |
| 1395 | ieee80211_teardown_tdls_peers(sdata); |
| 1396 | |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1397 | mutex_lock(&local->mtx); |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1398 | mutex_lock(&local->chanctx_mtx); |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1399 | conf = rcu_dereference_protected(sdata->vif.chanctx_conf, |
| 1400 | lockdep_is_held(&local->chanctx_mtx)); |
| 1401 | if (!conf) { |
| 1402 | sdata_info(sdata, |
| 1403 | "no channel context assigned to vif?, disconnecting\n"); |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1404 | goto drop_connection; |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | chanctx = container_of(conf, struct ieee80211_chanctx, conf); |
| 1408 | |
Luciano Coelho | 0f791eb4 | 2014-10-08 09:48:40 +0300 | [diff] [blame] | 1409 | if (local->use_chanctx && |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1410 | !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) { |
Luciano Coelho | 0f791eb4 | 2014-10-08 09:48:40 +0300 | [diff] [blame] | 1411 | sdata_info(sdata, |
| 1412 | "driver doesn't support chan-switch with channel contexts\n"); |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1413 | goto drop_connection; |
Arik Nemtsov | 7578d57 | 2013-09-01 17:15:51 +0300 | [diff] [blame] | 1414 | } |
| 1415 | |
Luciano Coelho | 6d027bc | 2014-10-08 09:48:37 +0300 | [diff] [blame] | 1416 | if (drv_pre_channel_switch(sdata, &ch_switch)) { |
| 1417 | sdata_info(sdata, |
| 1418 | "preparing for channel switch failed, disconnecting\n"); |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1419 | goto drop_connection; |
Luciano Coelho | 6d027bc | 2014-10-08 09:48:37 +0300 | [diff] [blame] | 1420 | } |
| 1421 | |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1422 | res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef, |
| 1423 | chanctx->mode, false); |
| 1424 | if (res) { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1425 | sdata_info(sdata, |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1426 | "failed to reserve channel context for channel switch, disconnecting (err=%d)\n", |
| 1427 | res); |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1428 | goto drop_connection; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1429 | } |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1430 | mutex_unlock(&local->chanctx_mtx); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1431 | |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 1432 | sdata->vif.csa_active = true; |
Michal Kazior | 4c3ebc5 | 2014-06-25 12:35:09 +0200 | [diff] [blame] | 1433 | sdata->csa_chandef = csa_ie.chandef; |
Sara Sharon | 2bf973f | 2020-01-31 13:12:51 +0200 | [diff] [blame] | 1434 | sdata->csa_block_tx = csa_ie.mode; |
Johannes Berg | f84eaa1 | 2015-03-12 08:53:26 +0200 | [diff] [blame] | 1435 | ifmgd->csa_ignored_same_chan = false; |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 1436 | |
| 1437 | if (sdata->csa_block_tx) |
Luciano Coelho | a46992b | 2014-06-13 16:30:07 +0300 | [diff] [blame] | 1438 | ieee80211_stop_vif_queues(local, sdata, |
| 1439 | IEEE80211_QUEUE_STOP_REASON_CSA); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 1440 | mutex_unlock(&local->mtx); |
Johannes Berg | 57eebdf | 2012-08-01 15:50:46 +0200 | [diff] [blame] | 1441 | |
Luciano Coelho | 2f45729 | 2014-11-07 14:31:36 +0200 | [diff] [blame] | 1442 | cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef, |
| 1443 | csa_ie.count); |
| 1444 | |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1445 | if (local->ops->channel_switch) { |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1446 | /* use driver's channel switch callback */ |
Luciano Coelho | 0f791eb4 | 2014-10-08 09:48:40 +0300 | [diff] [blame] | 1447 | drv_channel_switch(local, sdata, &ch_switch); |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1448 | return; |
| 1449 | } |
| 1450 | |
| 1451 | /* channel switch handled in software */ |
Chun-Yeow Yeoh | c0f17eb | 2013-10-14 19:08:29 -0700 | [diff] [blame] | 1452 | if (csa_ie.count <= 1) |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 1453 | ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work); |
Johannes Berg | 57eebdf | 2012-08-01 15:50:46 +0200 | [diff] [blame] | 1454 | else |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1455 | mod_timer(&ifmgd->chswitch_timer, |
Luciano Coelho | ff1e417 | 2014-10-28 13:33:05 +0200 | [diff] [blame] | 1456 | TU_TO_EXP_TIME((csa_ie.count - 1) * |
| 1457 | cbss->beacon_interval)); |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1458 | return; |
| 1459 | drop_connection: |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 1460 | /* |
| 1461 | * This is just so that the disconnect flow will know that |
| 1462 | * we were trying to switch channel and failed. In case the |
| 1463 | * mode is 1 (we are not allowed to Tx), we will know not to |
| 1464 | * send a deauthentication frame. Those two fields will be |
| 1465 | * reset when the disconnection worker runs. |
| 1466 | */ |
| 1467 | sdata->vif.csa_active = true; |
Sara Sharon | 2bf973f | 2020-01-31 13:12:51 +0200 | [diff] [blame] | 1468 | sdata->csa_block_tx = csa_ie.mode; |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 1469 | |
Johannes Berg | f3b0bbb | 2015-03-12 08:53:25 +0200 | [diff] [blame] | 1470 | ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work); |
| 1471 | mutex_unlock(&local->chanctx_mtx); |
| 1472 | mutex_unlock(&local->mtx); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1473 | } |
| 1474 | |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1475 | static bool |
| 1476 | ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata, |
| 1477 | struct ieee80211_channel *channel, |
| 1478 | const u8 *country_ie, u8 country_ie_len, |
| 1479 | const u8 *pwr_constr_elem, |
| 1480 | int *chan_pwr, int *pwr_reduction) |
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 | struct ieee80211_country_ie_triplet *triplet; |
| 1483 | int chan = ieee80211_frequency_to_channel(channel->center_freq); |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1484 | int i, chan_increment; |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1485 | bool have_chan_pwr = false; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1486 | |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1487 | /* Invalid IE */ |
| 1488 | 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] | 1489 | return false; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1490 | |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1491 | triplet = (void *)(country_ie + 3); |
| 1492 | country_ie_len -= 3; |
| 1493 | |
| 1494 | switch (channel->band) { |
| 1495 | default: |
| 1496 | WARN_ON_ONCE(1); |
| 1497 | /* fall through */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1498 | case NL80211_BAND_2GHZ: |
| 1499 | case NL80211_BAND_60GHZ: |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1500 | chan_increment = 1; |
| 1501 | break; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1502 | case NL80211_BAND_5GHZ: |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1503 | chan_increment = 4; |
| 1504 | break; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1505 | } |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1506 | |
| 1507 | /* find channel */ |
| 1508 | while (country_ie_len >= 3) { |
| 1509 | u8 first_channel = triplet->chans.first_channel; |
| 1510 | |
| 1511 | if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID) |
| 1512 | goto next; |
| 1513 | |
| 1514 | for (i = 0; i < triplet->chans.num_channels; i++) { |
| 1515 | if (first_channel + i * chan_increment == chan) { |
| 1516 | have_chan_pwr = true; |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1517 | *chan_pwr = triplet->chans.max_power; |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1518 | break; |
| 1519 | } |
| 1520 | } |
| 1521 | if (have_chan_pwr) |
| 1522 | break; |
| 1523 | |
| 1524 | next: |
| 1525 | triplet++; |
| 1526 | country_ie_len -= 3; |
| 1527 | } |
| 1528 | |
Moshe Benji | a5fee9c | 2014-12-14 11:05:50 +0200 | [diff] [blame] | 1529 | if (have_chan_pwr && pwr_constr_elem) |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1530 | *pwr_reduction = *pwr_constr_elem; |
Moshe Benji | a5fee9c | 2014-12-14 11:05:50 +0200 | [diff] [blame] | 1531 | else |
| 1532 | *pwr_reduction = 0; |
| 1533 | |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1534 | return have_chan_pwr; |
| 1535 | } |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1536 | |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1537 | static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata, |
| 1538 | struct ieee80211_channel *channel, |
| 1539 | const u8 *cisco_dtpc_ie, |
| 1540 | int *pwr_level) |
| 1541 | { |
| 1542 | /* From practical testing, the first data byte of the DTPC element |
| 1543 | * seems to contain the requested dBm level, and the CLI on Cisco |
| 1544 | * APs clearly state the range is -127 to 127 dBm, which indicates |
| 1545 | * a signed byte, although it seemingly never actually goes negative. |
| 1546 | * The other byte seems to always be zero. |
| 1547 | */ |
| 1548 | *pwr_level = (__s8)cisco_dtpc_ie[4]; |
| 1549 | } |
| 1550 | |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1551 | static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata, |
| 1552 | struct ieee80211_channel *channel, |
| 1553 | struct ieee80211_mgmt *mgmt, |
| 1554 | const u8 *country_ie, u8 country_ie_len, |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1555 | const u8 *pwr_constr_ie, |
| 1556 | const u8 *cisco_dtpc_ie) |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1557 | { |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1558 | bool has_80211h_pwr = false, has_cisco_pwr = false; |
| 1559 | int chan_pwr = 0, pwr_reduction_80211h = 0; |
| 1560 | int pwr_level_cisco, pwr_level_80211h; |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1561 | int new_ap_level; |
Moshe Benji | a5fee9c | 2014-12-14 11:05:50 +0200 | [diff] [blame] | 1562 | __le16 capab = mgmt->u.probe_resp.capab_info; |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1563 | |
Moshe Benji | a5fee9c | 2014-12-14 11:05:50 +0200 | [diff] [blame] | 1564 | if (country_ie && |
| 1565 | (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) || |
| 1566 | capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) { |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1567 | has_80211h_pwr = ieee80211_find_80211h_pwr_constr( |
| 1568 | sdata, channel, country_ie, country_ie_len, |
| 1569 | pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h); |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1570 | pwr_level_80211h = |
| 1571 | max_t(int, 0, chan_pwr - pwr_reduction_80211h); |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 1572 | } |
| 1573 | |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1574 | if (cisco_dtpc_ie) { |
| 1575 | ieee80211_find_cisco_dtpc( |
| 1576 | sdata, channel, cisco_dtpc_ie, &pwr_level_cisco); |
| 1577 | has_cisco_pwr = true; |
| 1578 | } |
| 1579 | |
| 1580 | if (!has_80211h_pwr && !has_cisco_pwr) |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1581 | return 0; |
| 1582 | |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1583 | /* If we have both 802.11h and Cisco DTPC, apply both limits |
| 1584 | * by picking the smallest of the two power levels advertised. |
| 1585 | */ |
| 1586 | if (has_80211h_pwr && |
| 1587 | (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) { |
Johannes Berg | a87da0c | 2015-12-08 16:04:37 +0200 | [diff] [blame] | 1588 | new_ap_level = pwr_level_80211h; |
| 1589 | |
| 1590 | if (sdata->ap_power_level == new_ap_level) |
| 1591 | return 0; |
| 1592 | |
John Linville | cef2fc1 | 2015-03-31 10:49:14 -0400 | [diff] [blame] | 1593 | sdata_dbg(sdata, |
| 1594 | "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n", |
| 1595 | pwr_level_80211h, chan_pwr, pwr_reduction_80211h, |
| 1596 | sdata->u.mgd.bssid); |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1597 | } else { /* has_cisco_pwr is always true here. */ |
Johannes Berg | a87da0c | 2015-12-08 16:04:37 +0200 | [diff] [blame] | 1598 | new_ap_level = pwr_level_cisco; |
| 1599 | |
| 1600 | if (sdata->ap_power_level == new_ap_level) |
| 1601 | return 0; |
| 1602 | |
John Linville | cef2fc1 | 2015-03-31 10:49:14 -0400 | [diff] [blame] | 1603 | sdata_dbg(sdata, |
| 1604 | "Limiting TX power to %d dBm as advertised by %pM\n", |
| 1605 | pwr_level_cisco, sdata->u.mgd.bssid); |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 1606 | } |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 1607 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 1608 | sdata->ap_power_level = new_ap_level; |
| 1609 | if (__ieee80211_recalc_txpower(sdata)) |
| 1610 | return BSS_CHANGED_TXPOWER; |
| 1611 | return 0; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1612 | } |
| 1613 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1614 | /* powersave */ |
| 1615 | static void ieee80211_enable_ps(struct ieee80211_local *local, |
| 1616 | struct ieee80211_sub_if_data *sdata) |
| 1617 | { |
| 1618 | struct ieee80211_conf *conf = &local->hw.conf; |
| 1619 | |
Johannes Berg | d5edaed | 2009-04-22 23:02:51 +0200 | [diff] [blame] | 1620 | /* |
| 1621 | * If we are scanning right now then the parameters will |
| 1622 | * take effect when scan finishes. |
| 1623 | */ |
Helmut Schaa | fbe9c429 | 2009-07-23 12:14:04 +0200 | [diff] [blame] | 1624 | if (local->scanning) |
Johannes Berg | d5edaed | 2009-04-22 23:02:51 +0200 | [diff] [blame] | 1625 | return; |
| 1626 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1627 | if (conf->dynamic_ps_timeout > 0 && |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1628 | !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1629 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 1630 | msecs_to_jiffies(conf->dynamic_ps_timeout)); |
| 1631 | } else { |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1632 | if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) |
Johannes Berg | 076cdcb | 2015-09-24 16:14:55 +0200 | [diff] [blame] | 1633 | ieee80211_send_nullfunc(local, sdata, true); |
Vivek Natarajan | 375177b | 2010-02-09 14:50:28 +0530 | [diff] [blame] | 1634 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1635 | if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) && |
| 1636 | ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
Juuso Oikarinen | 2a13052 | 2010-03-09 14:25:02 +0200 | [diff] [blame] | 1637 | return; |
| 1638 | |
| 1639 | conf->flags |= IEEE80211_CONF_PS; |
| 1640 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1641 | } |
| 1642 | } |
| 1643 | |
| 1644 | static void ieee80211_change_ps(struct ieee80211_local *local) |
| 1645 | { |
| 1646 | struct ieee80211_conf *conf = &local->hw.conf; |
| 1647 | |
| 1648 | if (local->ps_sdata) { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1649 | ieee80211_enable_ps(local, local->ps_sdata); |
| 1650 | } else if (conf->flags & IEEE80211_CONF_PS) { |
| 1651 | conf->flags &= ~IEEE80211_CONF_PS; |
| 1652 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 1653 | del_timer_sync(&local->dynamic_ps_timer); |
| 1654 | cancel_work_sync(&local->dynamic_ps_enable_work); |
| 1655 | } |
| 1656 | } |
| 1657 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1658 | static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata) |
| 1659 | { |
| 1660 | struct ieee80211_if_managed *mgd = &sdata->u.mgd; |
| 1661 | struct sta_info *sta = NULL; |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1662 | bool authorized = false; |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1663 | |
| 1664 | if (!mgd->powersave) |
| 1665 | return false; |
| 1666 | |
Johannes Berg | 05cb910 | 2011-10-28 11:59:47 +0200 | [diff] [blame] | 1667 | if (mgd->broken_ap) |
| 1668 | return false; |
| 1669 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1670 | if (!mgd->associated) |
| 1671 | return false; |
| 1672 | |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 1673 | if (mgd->flags & IEEE80211_STA_CONNECTION_POLL) |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1674 | return false; |
| 1675 | |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 1676 | if (!mgd->have_beacon) |
Alexander Bondar | ce85788 | 2013-05-06 17:17:04 +0300 | [diff] [blame] | 1677 | return false; |
| 1678 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1679 | rcu_read_lock(); |
| 1680 | sta = sta_info_get(sdata, mgd->bssid); |
| 1681 | if (sta) |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1682 | authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED); |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1683 | rcu_read_unlock(); |
| 1684 | |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1685 | return authorized; |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1686 | } |
| 1687 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1688 | /* need to hold RTNL or interface lock */ |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 1689 | void ieee80211_recalc_ps(struct ieee80211_local *local) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1690 | { |
| 1691 | struct ieee80211_sub_if_data *sdata, *found = NULL; |
| 1692 | int count = 0; |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 1693 | int timeout; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1694 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1695 | if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1696 | local->ps_sdata = NULL; |
| 1697 | return; |
| 1698 | } |
| 1699 | |
| 1700 | list_for_each_entry(sdata, &local->interfaces, list) { |
Johannes Berg | 9607e6b66 | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 1701 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1702 | continue; |
Rajkumar Manoharan | 8c7914d | 2011-02-01 00:28:59 +0530 | [diff] [blame] | 1703 | if (sdata->vif.type == NL80211_IFTYPE_AP) { |
| 1704 | /* If an AP vif is found, then disable PS |
| 1705 | * by setting the count to zero thereby setting |
| 1706 | * ps_sdata to NULL. |
| 1707 | */ |
| 1708 | count = 0; |
| 1709 | break; |
| 1710 | } |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1711 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 1712 | continue; |
| 1713 | found = sdata; |
| 1714 | count++; |
| 1715 | } |
| 1716 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1717 | if (count == 1 && ieee80211_powersave_allowed(found)) { |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 1718 | u8 dtimper = found->u.mgd.dtim_period; |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1719 | |
Juuso Oikarinen | ff61638 | 2010-06-09 09:51:52 +0300 | [diff] [blame] | 1720 | timeout = local->dynamic_ps_forced_timeout; |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 1721 | if (timeout < 0) |
| 1722 | timeout = 100; |
Johannes Berg | 09b8556 | 2013-02-06 23:07:41 +0100 | [diff] [blame] | 1723 | local->hw.conf.dynamic_ps_timeout = timeout; |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 1724 | |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 1725 | /* If the TIM IE is invalid, pretend the value is 1 */ |
| 1726 | if (!dtimper) |
| 1727 | dtimper = 1; |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 1728 | |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 1729 | local->hw.conf.ps_dtim_period = dtimper; |
| 1730 | local->ps_sdata = found; |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1731 | } else { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1732 | local->ps_sdata = NULL; |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1733 | } |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1734 | |
| 1735 | ieee80211_change_ps(local); |
| 1736 | } |
| 1737 | |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 1738 | void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata) |
| 1739 | { |
| 1740 | bool ps_allowed = ieee80211_powersave_allowed(sdata); |
| 1741 | |
| 1742 | if (sdata->vif.bss_conf.ps != ps_allowed) { |
| 1743 | sdata->vif.bss_conf.ps = ps_allowed; |
| 1744 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS); |
| 1745 | } |
| 1746 | } |
| 1747 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1748 | void ieee80211_dynamic_ps_disable_work(struct work_struct *work) |
| 1749 | { |
| 1750 | struct ieee80211_local *local = |
| 1751 | container_of(work, struct ieee80211_local, |
| 1752 | dynamic_ps_disable_work); |
| 1753 | |
| 1754 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 1755 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 1756 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 1757 | } |
| 1758 | |
| 1759 | ieee80211_wake_queues_by_reason(&local->hw, |
Johannes Berg | 445ea4e | 2013-02-13 12:25:28 +0100 | [diff] [blame] | 1760 | IEEE80211_MAX_QUEUE_MAP, |
Luciano Coelho | cca07b0 | 2014-06-13 16:30:05 +0300 | [diff] [blame] | 1761 | IEEE80211_QUEUE_STOP_REASON_PS, |
| 1762 | false); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | void ieee80211_dynamic_ps_enable_work(struct work_struct *work) |
| 1766 | { |
| 1767 | struct ieee80211_local *local = |
| 1768 | container_of(work, struct ieee80211_local, |
| 1769 | dynamic_ps_enable_work); |
| 1770 | struct ieee80211_sub_if_data *sdata = local->ps_sdata; |
Christian Lamparter | 5e34069 | 2011-06-30 21:08:43 +0200 | [diff] [blame] | 1771 | struct ieee80211_if_managed *ifmgd; |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1772 | unsigned long flags; |
| 1773 | int q; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1774 | |
| 1775 | /* can only happen when PS was just disabled anyway */ |
| 1776 | if (!sdata) |
| 1777 | return; |
| 1778 | |
Christian Lamparter | 5e34069 | 2011-06-30 21:08:43 +0200 | [diff] [blame] | 1779 | ifmgd = &sdata->u.mgd; |
| 1780 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1781 | if (local->hw.conf.flags & IEEE80211_CONF_PS) |
| 1782 | return; |
| 1783 | |
Johannes Berg | 09b8556 | 2013-02-06 23:07:41 +0100 | [diff] [blame] | 1784 | if (local->hw.conf.dynamic_ps_timeout > 0) { |
Arik Nemtsov | 77b7023 | 2011-06-26 12:06:54 +0300 | [diff] [blame] | 1785 | /* don't enter PS if TX frames are pending */ |
| 1786 | if (drv_tx_frames_pending(local)) { |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1787 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 1788 | msecs_to_jiffies( |
| 1789 | local->hw.conf.dynamic_ps_timeout)); |
| 1790 | return; |
| 1791 | } |
Arik Nemtsov | 77b7023 | 2011-06-26 12:06:54 +0300 | [diff] [blame] | 1792 | |
| 1793 | /* |
| 1794 | * transmission can be stopped by others which leads to |
| 1795 | * dynamic_ps_timer expiry. Postpone the ps timer if it |
| 1796 | * is not the actual idle state. |
| 1797 | */ |
| 1798 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 1799 | for (q = 0; q < local->hw.queues; q++) { |
| 1800 | if (local->queue_stop_reasons[q]) { |
| 1801 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, |
| 1802 | flags); |
| 1803 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 1804 | msecs_to_jiffies( |
| 1805 | local->hw.conf.dynamic_ps_timeout)); |
| 1806 | return; |
| 1807 | } |
| 1808 | } |
| 1809 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1810 | } |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1811 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1812 | if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) && |
Mohammed Shafi Shajakhan | 9c38a8b | 2011-12-14 19:46:07 +0530 | [diff] [blame] | 1813 | !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) { |
Johannes Berg | a159838 | 2013-03-26 22:02:42 +0100 | [diff] [blame] | 1814 | if (drv_tx_frames_pending(local)) { |
Vivek Natarajan | e8306f9 | 2011-04-06 11:41:10 +0530 | [diff] [blame] | 1815 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 1816 | msecs_to_jiffies( |
| 1817 | local->hw.conf.dynamic_ps_timeout)); |
Johannes Berg | a159838 | 2013-03-26 22:02:42 +0100 | [diff] [blame] | 1818 | } else { |
Johannes Berg | 076cdcb | 2015-09-24 16:14:55 +0200 | [diff] [blame] | 1819 | ieee80211_send_nullfunc(local, sdata, true); |
Vivek Natarajan | e8306f9 | 2011-04-06 11:41:10 +0530 | [diff] [blame] | 1820 | /* Flush to get the tx status of nullfunc frame */ |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 1821 | ieee80211_flush_queues(local, sdata, false); |
Vivek Natarajan | e8306f9 | 2011-04-06 11:41:10 +0530 | [diff] [blame] | 1822 | } |
Vivek Natarajan | f3e85b9 | 2011-02-23 13:04:32 +0530 | [diff] [blame] | 1823 | } |
| 1824 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1825 | if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) && |
| 1826 | ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) || |
Vivek Natarajan | 375177b | 2010-02-09 14:50:28 +0530 | [diff] [blame] | 1827 | (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) { |
| 1828 | ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED; |
| 1829 | local->hw.conf.flags |= IEEE80211_CONF_PS; |
| 1830 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 1831 | } |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1832 | } |
| 1833 | |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 1834 | void ieee80211_dynamic_ps_timer(struct timer_list *t) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1835 | { |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 1836 | struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1837 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 1838 | ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1839 | } |
| 1840 | |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 1841 | void ieee80211_dfs_cac_timer_work(struct work_struct *work) |
| 1842 | { |
Geliang Tang | a85a7e2 | 2016-01-01 23:48:52 +0800 | [diff] [blame] | 1843 | struct delayed_work *delayed_work = to_delayed_work(work); |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 1844 | struct ieee80211_sub_if_data *sdata = |
| 1845 | container_of(delayed_work, struct ieee80211_sub_if_data, |
| 1846 | dfs_cac_timer_work); |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 1847 | struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef; |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 1848 | |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 1849 | mutex_lock(&sdata->local->mtx); |
| 1850 | if (sdata->wdev.cac_started) { |
| 1851 | ieee80211_vif_release_channel(sdata); |
| 1852 | cfg80211_cac_event(sdata->dev, &chandef, |
| 1853 | NL80211_RADAR_CAC_FINISHED, |
| 1854 | GFP_KERNEL); |
| 1855 | } |
| 1856 | mutex_unlock(&sdata->local->mtx); |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 1857 | } |
| 1858 | |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 1859 | static bool |
| 1860 | __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata) |
| 1861 | { |
| 1862 | struct ieee80211_local *local = sdata->local; |
| 1863 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
John Linville | cc72f6e | 2015-01-06 14:39:33 -0500 | [diff] [blame] | 1864 | bool ret = false; |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 1865 | int ac; |
| 1866 | |
| 1867 | if (local->hw.queues < IEEE80211_NUM_ACS) |
| 1868 | return false; |
| 1869 | |
| 1870 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 1871 | struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac]; |
| 1872 | int non_acm_ac; |
| 1873 | unsigned long now = jiffies; |
| 1874 | |
| 1875 | if (tx_tspec->action == TX_TSPEC_ACTION_NONE && |
| 1876 | tx_tspec->admitted_time && |
| 1877 | time_after(now, tx_tspec->time_slice_start + HZ)) { |
| 1878 | tx_tspec->consumed_tx_time = 0; |
| 1879 | tx_tspec->time_slice_start = now; |
| 1880 | |
| 1881 | if (tx_tspec->downgraded) |
| 1882 | tx_tspec->action = |
| 1883 | TX_TSPEC_ACTION_STOP_DOWNGRADE; |
| 1884 | } |
| 1885 | |
| 1886 | switch (tx_tspec->action) { |
| 1887 | case TX_TSPEC_ACTION_STOP_DOWNGRADE: |
| 1888 | /* take the original parameters */ |
| 1889 | if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac])) |
| 1890 | sdata_err(sdata, |
| 1891 | "failed to set TX queue parameters for queue %d\n", |
| 1892 | ac); |
| 1893 | tx_tspec->action = TX_TSPEC_ACTION_NONE; |
| 1894 | tx_tspec->downgraded = false; |
| 1895 | ret = true; |
| 1896 | break; |
| 1897 | case TX_TSPEC_ACTION_DOWNGRADE: |
| 1898 | if (time_after(now, tx_tspec->time_slice_start + HZ)) { |
| 1899 | tx_tspec->action = TX_TSPEC_ACTION_NONE; |
| 1900 | ret = true; |
| 1901 | break; |
| 1902 | } |
| 1903 | /* downgrade next lower non-ACM AC */ |
| 1904 | for (non_acm_ac = ac + 1; |
| 1905 | non_acm_ac < IEEE80211_NUM_ACS; |
| 1906 | non_acm_ac++) |
| 1907 | if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac))) |
| 1908 | break; |
Johannes Berg | 93db1d9 | 2016-09-14 09:23:51 +0200 | [diff] [blame] | 1909 | /* Usually the loop will result in using BK even if it |
| 1910 | * requires admission control, but such a configuration |
| 1911 | * makes no sense and we have to transmit somehow - the |
| 1912 | * AC selection does the same thing. |
| 1913 | * If we started out trying to downgrade from BK, then |
| 1914 | * the extra condition here might be needed. |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 1915 | */ |
Johannes Berg | 93db1d9 | 2016-09-14 09:23:51 +0200 | [diff] [blame] | 1916 | if (non_acm_ac >= IEEE80211_NUM_ACS) |
| 1917 | non_acm_ac = IEEE80211_AC_BK; |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 1918 | if (drv_conf_tx(local, sdata, ac, |
| 1919 | &sdata->tx_conf[non_acm_ac])) |
| 1920 | sdata_err(sdata, |
| 1921 | "failed to set TX queue parameters for queue %d\n", |
| 1922 | ac); |
| 1923 | tx_tspec->action = TX_TSPEC_ACTION_NONE; |
| 1924 | ret = true; |
| 1925 | schedule_delayed_work(&ifmgd->tx_tspec_wk, |
| 1926 | tx_tspec->time_slice_start + HZ - now + 1); |
| 1927 | break; |
| 1928 | case TX_TSPEC_ACTION_NONE: |
| 1929 | /* nothing now */ |
| 1930 | break; |
| 1931 | } |
| 1932 | } |
| 1933 | |
| 1934 | return ret; |
| 1935 | } |
| 1936 | |
| 1937 | void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata) |
| 1938 | { |
| 1939 | if (__ieee80211_sta_handle_tspec_ac_params(sdata)) |
| 1940 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS); |
| 1941 | } |
| 1942 | |
| 1943 | static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work) |
| 1944 | { |
| 1945 | struct ieee80211_sub_if_data *sdata; |
| 1946 | |
| 1947 | sdata = container_of(work, struct ieee80211_sub_if_data, |
| 1948 | u.mgd.tx_tspec_wk.work); |
| 1949 | ieee80211_sta_handle_tspec_ac_params(sdata); |
| 1950 | } |
| 1951 | |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1952 | /* MLME */ |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 1953 | static bool |
| 1954 | ieee80211_sta_wmm_params(struct ieee80211_local *local, |
| 1955 | struct ieee80211_sub_if_data *sdata, |
| 1956 | const u8 *wmm_param, size_t wmm_param_len, |
| 1957 | const struct ieee80211_mu_edca_param_set *mu_edca) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1958 | { |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 1959 | struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS]; |
Johannes Berg | 4ced3f7 | 2010-07-19 16:39:04 +0200 | [diff] [blame] | 1960 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1961 | size_t left; |
Shaul Triebitz | 2e249fc | 2018-12-15 11:03:15 +0200 | [diff] [blame] | 1962 | int count, mu_edca_count, ac; |
Johannes Berg | 4a3cb70 | 2013-02-12 16:43:19 +0100 | [diff] [blame] | 1963 | const u8 *pos; |
| 1964 | u8 uapsd_queues = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1965 | |
Stanislaw Gruszka | e1b3ec1 | 2010-03-29 12:18:34 +0200 | [diff] [blame] | 1966 | if (!local->ops->conf_tx) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1967 | return false; |
Stanislaw Gruszka | e1b3ec1 | 2010-03-29 12:18:34 +0200 | [diff] [blame] | 1968 | |
Johannes Berg | 32c5057 | 2012-03-28 11:04:29 +0200 | [diff] [blame] | 1969 | if (local->hw.queues < IEEE80211_NUM_ACS) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1970 | return false; |
Johannes Berg | 3434fbd | 2008-05-03 00:59:37 +0200 | [diff] [blame] | 1971 | |
| 1972 | if (!wmm_param) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1973 | return false; |
Johannes Berg | 3434fbd | 2008-05-03 00:59:37 +0200 | [diff] [blame] | 1974 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1975 | if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1976 | return false; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1977 | |
| 1978 | if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED) |
Eliad Peller | dc41e4d | 2012-03-14 16:15:03 +0200 | [diff] [blame] | 1979 | uapsd_queues = ifmgd->uapsd_queues; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1980 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1981 | count = wmm_param[6] & 0x0f; |
Shaul Triebitz | 2e249fc | 2018-12-15 11:03:15 +0200 | [diff] [blame] | 1982 | /* -1 is the initial value of ifmgd->mu_edca_last_param_set. |
| 1983 | * if mu_edca was preset before and now it disappeared tell |
| 1984 | * the driver about it. |
| 1985 | */ |
| 1986 | mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1; |
| 1987 | if (count == ifmgd->wmm_last_param_set && |
| 1988 | mu_edca_count == ifmgd->mu_edca_last_param_set) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1989 | return false; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1990 | ifmgd->wmm_last_param_set = count; |
Shaul Triebitz | 2e249fc | 2018-12-15 11:03:15 +0200 | [diff] [blame] | 1991 | ifmgd->mu_edca_last_param_set = mu_edca_count; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1992 | |
| 1993 | pos = wmm_param + 8; |
| 1994 | left = wmm_param_len - 8; |
| 1995 | |
| 1996 | memset(¶ms, 0, sizeof(params)); |
| 1997 | |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 1998 | sdata->wmm_acm = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1999 | for (; left >= 4; left -= 4, pos += 4) { |
| 2000 | int aci = (pos[0] >> 5) & 0x03; |
| 2001 | int acm = (pos[0] >> 4) & 0x01; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2002 | bool uapsd = false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2003 | |
| 2004 | switch (aci) { |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 2005 | case 1: /* AC_BK */ |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2006 | ac = IEEE80211_AC_BK; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 2007 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 2008 | sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2009 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) |
| 2010 | uapsd = true; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 2011 | params[ac].mu_edca = !!mu_edca; |
| 2012 | if (mu_edca) |
| 2013 | params[ac].mu_edca_param_rec = mu_edca->ac_bk; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2014 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 2015 | case 2: /* AC_VI */ |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2016 | ac = IEEE80211_AC_VI; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 2017 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 2018 | sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2019 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) |
| 2020 | uapsd = true; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 2021 | params[ac].mu_edca = !!mu_edca; |
| 2022 | if (mu_edca) |
| 2023 | params[ac].mu_edca_param_rec = mu_edca->ac_vi; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2024 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 2025 | case 3: /* AC_VO */ |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2026 | ac = IEEE80211_AC_VO; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 2027 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 2028 | sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2029 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) |
| 2030 | uapsd = true; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 2031 | params[ac].mu_edca = !!mu_edca; |
| 2032 | if (mu_edca) |
| 2033 | params[ac].mu_edca_param_rec = mu_edca->ac_vo; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2034 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 2035 | case 0: /* AC_BE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2036 | default: |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2037 | ac = IEEE80211_AC_BE; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 2038 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 2039 | sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2040 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) |
| 2041 | uapsd = true; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 2042 | params[ac].mu_edca = !!mu_edca; |
| 2043 | if (mu_edca) |
| 2044 | params[ac].mu_edca_param_rec = mu_edca->ac_be; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2045 | break; |
| 2046 | } |
| 2047 | |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2048 | params[ac].aifs = pos[0] & 0x0f; |
Emmanuel Grumbach | 730a7550 | 2015-10-22 17:46:05 +0200 | [diff] [blame] | 2049 | |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2050 | if (params[ac].aifs < 2) { |
Emmanuel Grumbach | 730a7550 | 2015-10-22 17:46:05 +0200 | [diff] [blame] | 2051 | sdata_info(sdata, |
| 2052 | "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] | 2053 | params[ac].aifs, aci); |
| 2054 | params[ac].aifs = 2; |
Emmanuel Grumbach | 730a7550 | 2015-10-22 17:46:05 +0200 | [diff] [blame] | 2055 | } |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2056 | params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4); |
| 2057 | params[ac].cw_min = ecw2cw(pos[1] & 0x0f); |
| 2058 | params[ac].txop = get_unaligned_le16(pos + 2); |
| 2059 | params[ac].acm = acm; |
| 2060 | params[ac].uapsd = uapsd; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2061 | |
Ilan Peer | 911a264 | 2018-04-03 11:35:22 +0300 | [diff] [blame] | 2062 | if (params[ac].cw_min == 0 || |
Emmanuel Grumbach | c470bdc | 2018-03-26 16:21:04 +0300 | [diff] [blame] | 2063 | params[ac].cw_min > params[ac].cw_max) { |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2064 | sdata_info(sdata, |
| 2065 | "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n", |
| 2066 | params[ac].cw_min, params[ac].cw_max, aci); |
| 2067 | return false; |
| 2068 | } |
Haim Dreyfuss | e552af0 | 2018-03-28 13:24:10 +0300 | [diff] [blame] | 2069 | ieee80211_regulatory_limit_wmm_params(sdata, ¶ms[ac], ac); |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2070 | } |
| 2071 | |
Brian Norris | 05aaa5c | 2019-07-26 15:47:58 -0700 | [diff] [blame] | 2072 | /* WMM specification requires all 4 ACIs. */ |
| 2073 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 2074 | if (params[ac].cw_min == 0) { |
| 2075 | sdata_info(sdata, |
| 2076 | "AP has invalid WMM params (missing AC %d), using defaults\n", |
| 2077 | ac); |
| 2078 | return false; |
| 2079 | } |
| 2080 | } |
| 2081 | |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2082 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2083 | mlme_dbg(sdata, |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2084 | "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n", |
| 2085 | ac, params[ac].acm, |
| 2086 | params[ac].aifs, params[ac].cw_min, params[ac].cw_max, |
| 2087 | params[ac].txop, params[ac].uapsd, |
| 2088 | ifmgd->tx_tspec[ac].downgraded); |
| 2089 | sdata->tx_conf[ac] = params[ac]; |
| 2090 | if (!ifmgd->tx_tspec[ac].downgraded && |
| 2091 | drv_conf_tx(local, sdata, ac, ¶ms[ac])) |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2092 | sdata_err(sdata, |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 2093 | "failed to set TX queue parameters for AC %d\n", |
| 2094 | ac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2095 | } |
Stanislaw Gruszka | e1b3ec1 | 2010-03-29 12:18:34 +0200 | [diff] [blame] | 2096 | |
| 2097 | /* enable WMM or activate new settings */ |
Johannes Berg | 4ced3f7 | 2010-07-19 16:39:04 +0200 | [diff] [blame] | 2098 | sdata->vif.bss_conf.qos = true; |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 2099 | return true; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2100 | } |
| 2101 | |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 2102 | static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata) |
| 2103 | { |
| 2104 | lockdep_assert_held(&sdata->local->mtx); |
| 2105 | |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 2106 | sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL; |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 2107 | ieee80211_run_deferred_scan(sdata->local); |
| 2108 | } |
| 2109 | |
| 2110 | static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata) |
| 2111 | { |
| 2112 | mutex_lock(&sdata->local->mtx); |
| 2113 | __ieee80211_stop_poll(sdata); |
| 2114 | mutex_unlock(&sdata->local->mtx); |
| 2115 | } |
| 2116 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2117 | static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata, |
| 2118 | u16 capab, bool erp_valid, u8 erp) |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 2119 | { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 2120 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 2121 | struct ieee80211_supported_band *sband; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2122 | u32 changed = 0; |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2123 | bool use_protection; |
| 2124 | bool use_short_preamble; |
| 2125 | bool use_short_slot; |
| 2126 | |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 2127 | sband = ieee80211_get_sband(sdata); |
| 2128 | if (!sband) |
| 2129 | return changed; |
| 2130 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2131 | if (erp_valid) { |
| 2132 | use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0; |
| 2133 | use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0; |
| 2134 | } else { |
| 2135 | use_protection = false; |
| 2136 | use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE); |
| 2137 | } |
| 2138 | |
| 2139 | use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME); |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 2140 | if (sband->band == NL80211_BAND_5GHZ) |
Felix Fietkau | 43d3534 | 2010-01-15 03:00:48 +0100 | [diff] [blame] | 2141 | use_short_slot = true; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 2142 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2143 | if (use_protection != bss_conf->use_cts_prot) { |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2144 | bss_conf->use_cts_prot = use_protection; |
| 2145 | changed |= BSS_CHANGED_ERP_CTS_PROT; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 2146 | } |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 2147 | |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 2148 | if (use_short_preamble != bss_conf->use_short_preamble) { |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 2149 | bss_conf->use_short_preamble = use_short_preamble; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2150 | changed |= BSS_CHANGED_ERP_PREAMBLE; |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 2151 | } |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 2152 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2153 | if (use_short_slot != bss_conf->use_short_slot) { |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2154 | bss_conf->use_short_slot = use_short_slot; |
| 2155 | changed |= BSS_CHANGED_ERP_SLOT; |
John W. Linville | 50c4afb | 2008-04-15 14:09:27 -0400 | [diff] [blame] | 2156 | } |
| 2157 | |
| 2158 | return changed; |
| 2159 | } |
| 2160 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2161 | static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2162 | struct cfg80211_bss *cbss, |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2163 | u32 bss_info_changed) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2164 | { |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2165 | struct ieee80211_bss *bss = (void *)cbss->priv; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2166 | struct ieee80211_local *local = sdata->local; |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2167 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2168 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2169 | bss_info_changed |= BSS_CHANGED_ASSOC; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2170 | bss_info_changed |= ieee80211_handle_bss_capability(sdata, |
Luciano Coelho | 50ae34a | 2012-06-20 17:23:24 +0300 | [diff] [blame] | 2171 | bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value); |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 2172 | |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 2173 | sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec( |
Ben Greear | 59c1ec2 | 2013-03-19 14:19:56 -0700 | [diff] [blame] | 2174 | beacon_loss_count * bss_conf->beacon_int)); |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 2175 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2176 | sdata->u.mgd.associated = cbss; |
| 2177 | memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2178 | |
Johannes Berg | e8e4f52 | 2017-03-08 11:12:10 +0100 | [diff] [blame] | 2179 | ieee80211_check_rate_mask(sdata); |
| 2180 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 2181 | sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE; |
| 2182 | |
Janusz.Dziedzic@tieto.com | b115b97 | 2015-10-27 08:38:40 +0100 | [diff] [blame] | 2183 | if (sdata->vif.p2p || |
| 2184 | sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2185 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 2186 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2187 | rcu_read_lock(); |
| 2188 | ies = rcu_dereference(cbss->ies); |
| 2189 | if (ies) { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2190 | int ret; |
| 2191 | |
| 2192 | ret = cfg80211_get_p2p_attr( |
| 2193 | ies->data, ies->len, |
| 2194 | IEEE80211_P2P_ATTR_ABSENCE_NOTICE, |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 2195 | (u8 *) &bss_conf->p2p_noa_attr, |
| 2196 | sizeof(bss_conf->p2p_noa_attr)); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2197 | if (ret >= 2) { |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 2198 | sdata->u.mgd.p2p_noa_index = |
| 2199 | bss_conf->p2p_noa_attr.index; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2200 | bss_info_changed |= BSS_CHANGED_P2P_PS; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2201 | } |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 2202 | } |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2203 | rcu_read_unlock(); |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 2204 | } |
| 2205 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2206 | /* just to be sure */ |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 2207 | ieee80211_stop_poll(sdata); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2208 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 2209 | ieee80211_led_assoc(local, 1); |
| 2210 | |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 2211 | if (sdata->u.mgd.have_beacon) { |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 2212 | /* |
| 2213 | * If the AP is buggy we may get here with no DTIM period |
| 2214 | * known, so assume it's 1 which is the only safe assumption |
| 2215 | * in that case, although if the TIM IE is broken powersave |
| 2216 | * probably just won't work at all. |
| 2217 | */ |
| 2218 | bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1; |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 2219 | bss_conf->beacon_rate = bss->beacon_rate; |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 2220 | bss_info_changed |= BSS_CHANGED_BEACON_INFO; |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 2221 | } else { |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 2222 | bss_conf->beacon_rate = NULL; |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 2223 | bss_conf->dtim_period = 0; |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 2224 | } |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 2225 | |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2226 | bss_conf->assoc = 1; |
Johannes Berg | 9cef873 | 2009-05-14 13:10:14 +0200 | [diff] [blame] | 2227 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 2228 | /* Tell the driver to monitor connection quality (if supported) */ |
Johannes Berg | ea08635 | 2012-01-19 09:29:58 +0100 | [diff] [blame] | 2229 | if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI && |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2230 | bss_conf->cqm_rssi_thold) |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 2231 | bss_info_changed |= BSS_CHANGED_CQM; |
| 2232 | |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2233 | /* Enable ARP filtering */ |
Johannes Berg | 0f19b41 | 2013-01-14 16:39:07 +0100 | [diff] [blame] | 2234 | if (bss_conf->arp_addr_cnt) |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2235 | bss_info_changed |= BSS_CHANGED_ARP_FILTER; |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2236 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2237 | ieee80211_bss_info_change_notify(sdata, bss_info_changed); |
Guy Cohen | 8db9369 | 2008-07-03 19:56:13 +0300 | [diff] [blame] | 2238 | |
Johannes Berg | 056508d | 2009-07-30 21:43:55 +0200 | [diff] [blame] | 2239 | mutex_lock(&local->iflist_mtx); |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 2240 | ieee80211_recalc_ps(local); |
Johannes Berg | 056508d | 2009-07-30 21:43:55 +0200 | [diff] [blame] | 2241 | mutex_unlock(&local->iflist_mtx); |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 2242 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 2243 | ieee80211_recalc_smps(sdata); |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 2244 | ieee80211_recalc_ps_vif(sdata); |
| 2245 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 2246 | netif_carrier_on(sdata->dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2247 | } |
| 2248 | |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 2249 | static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2250 | u16 stype, u16 reason, bool tx, |
| 2251 | u8 *frame_buf) |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2252 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2253 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2254 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 3cc5240 | 2012-03-09 13:12:35 +0100 | [diff] [blame] | 2255 | u32 changed = 0; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2256 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2257 | sdata_assert_lock(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2258 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2259 | if (WARN_ON_ONCE(tx && !frame_buf)) |
| 2260 | return; |
| 2261 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2262 | if (WARN_ON(!ifmgd->associated)) |
| 2263 | return; |
| 2264 | |
David Spinadel | 79543d8 | 2012-06-12 09:59:45 +0300 | [diff] [blame] | 2265 | ieee80211_stop_poll(sdata); |
| 2266 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2267 | ifmgd->associated = NULL; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2268 | netif_carrier_off(sdata->dev); |
| 2269 | |
Eliad Peller | 88bc40e | 2012-07-12 17:35:33 +0300 | [diff] [blame] | 2270 | /* |
| 2271 | * if we want to get out of ps before disassoc (why?) we have |
| 2272 | * to do it before sending disassoc, as otherwise the null-packet |
| 2273 | * won't be valid. |
| 2274 | */ |
| 2275 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 2276 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 2277 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 2278 | } |
| 2279 | local->ps_sdata = NULL; |
| 2280 | |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 2281 | /* disable per-vif ps */ |
| 2282 | ieee80211_recalc_ps_vif(sdata); |
| 2283 | |
Emmanuel Grumbach | 14f2ae8 | 2015-01-22 23:30:19 +0200 | [diff] [blame] | 2284 | /* make sure ongoing transmission finishes */ |
| 2285 | synchronize_net(); |
| 2286 | |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 2287 | /* |
| 2288 | * drop any frame before deauth/disassoc, this can be data or |
| 2289 | * management frame. Since we are disconnecting, we should not |
| 2290 | * insist sending these frames which can take time and delay |
| 2291 | * the disconnection and possible the roaming. |
| 2292 | */ |
Eliad Peller | f823981 | 2012-06-27 14:18:22 +0300 | [diff] [blame] | 2293 | if (tx) |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 2294 | ieee80211_flush_queues(local, sdata, true); |
Eliad Peller | f823981 | 2012-06-27 14:18:22 +0300 | [diff] [blame] | 2295 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2296 | /* deauthenticate/disassociate now */ |
Ilan Peer | 94ba927 | 2018-02-19 14:48:41 +0200 | [diff] [blame] | 2297 | if (tx || frame_buf) { |
Ilan Peer | 94ba927 | 2018-02-19 14:48:41 +0200 | [diff] [blame] | 2298 | /* |
| 2299 | * In multi channel scenarios guarantee that the virtual |
| 2300 | * interface is granted immediate airtime to transmit the |
| 2301 | * deauthentication frame by calling mgd_prepare_tx, if the |
| 2302 | * driver requested so. |
| 2303 | */ |
| 2304 | if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) && |
| 2305 | !ifmgd->have_beacon) |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 2306 | drv_mgd_prepare_tx(sdata->local, sdata, 0); |
Ilan Peer | 94ba927 | 2018-02-19 14:48:41 +0200 | [diff] [blame] | 2307 | |
Johannes Berg | 4b08d1b | 2019-08-30 14:24:51 +0300 | [diff] [blame] | 2308 | ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, |
| 2309 | ifmgd->bssid, stype, reason, |
| 2310 | tx, frame_buf); |
Ilan Peer | 94ba927 | 2018-02-19 14:48:41 +0200 | [diff] [blame] | 2311 | } |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2312 | |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 2313 | /* flush out frame - make sure the deauth was actually sent */ |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2314 | if (tx) |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 2315 | ieee80211_flush_queues(local, sdata, false); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2316 | |
Eliad Peller | 88a9e31 | 2012-06-01 11:14:03 +0300 | [diff] [blame] | 2317 | /* clear bssid only after building the needed mgmt frames */ |
Joe Perches | c84a67a | 2015-03-02 19:54:57 -0800 | [diff] [blame] | 2318 | eth_zero_addr(ifmgd->bssid); |
Eliad Peller | 88a9e31 | 2012-06-01 11:14:03 +0300 | [diff] [blame] | 2319 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2320 | /* remove AP and TDLS peers */ |
Johannes Berg | d34ba21 | 2013-12-04 22:46:11 +0100 | [diff] [blame] | 2321 | sta_info_flush(sdata); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2322 | |
| 2323 | /* finally reset all BSS / config parameters */ |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 2324 | changed |= ieee80211_reset_erp_info(sdata); |
| 2325 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 2326 | ieee80211_led_assoc(local, 0); |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2327 | changed |= BSS_CHANGED_ASSOC; |
| 2328 | sdata->vif.bss_conf.assoc = false; |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 2329 | |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 2330 | ifmgd->p2p_noa_index = -1; |
| 2331 | memset(&sdata->vif.bss_conf.p2p_noa_attr, 0, |
| 2332 | sizeof(sdata->vif.bss_conf.p2p_noa_attr)); |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 2333 | |
Johannes Berg | dd5ecfe | 2013-02-21 17:40:19 +0100 | [diff] [blame] | 2334 | /* on the next assoc, re-program HT/VHT parameters */ |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 2335 | memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa)); |
| 2336 | memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask)); |
Johannes Berg | dd5ecfe | 2013-02-21 17:40:19 +0100 | [diff] [blame] | 2337 | memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa)); |
| 2338 | memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask)); |
Sara Sharon | 23a1f8d | 2015-12-08 16:04:31 +0200 | [diff] [blame] | 2339 | |
| 2340 | /* reset MU-MIMO ownership and group data */ |
| 2341 | memset(sdata->vif.bss_conf.mu_group.membership, 0, |
| 2342 | sizeof(sdata->vif.bss_conf.mu_group.membership)); |
| 2343 | memset(sdata->vif.bss_conf.mu_group.position, 0, |
| 2344 | sizeof(sdata->vif.bss_conf.mu_group.position)); |
| 2345 | changed |= BSS_CHANGED_MU_GROUPS; |
Sara Sharon | b5a33d5 | 2016-02-16 12:48:18 +0200 | [diff] [blame] | 2346 | sdata->vif.mu_mimo_owner = false; |
Johannes Berg | 413ad50 | 2009-05-08 21:21:06 +0200 | [diff] [blame] | 2347 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2348 | sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL; |
Vasanthakumar Thiagarajan | a8302de | 2009-01-09 18:14:15 +0530 | [diff] [blame] | 2349 | |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 2350 | del_timer_sync(&local->dynamic_ps_timer); |
| 2351 | cancel_work_sync(&local->dynamic_ps_enable_work); |
| 2352 | |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2353 | /* Disable ARP filtering */ |
Johannes Berg | 0f19b41 | 2013-01-14 16:39:07 +0100 | [diff] [blame] | 2354 | if (sdata->vif.bss_conf.arp_addr_cnt) |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2355 | changed |= BSS_CHANGED_ARP_FILTER; |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2356 | |
Johannes Berg | 3abead5 | 2012-03-02 15:56:59 +0100 | [diff] [blame] | 2357 | sdata->vif.bss_conf.qos = false; |
| 2358 | changed |= BSS_CHANGED_QOS; |
| 2359 | |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 2360 | /* The BSSID (not really interesting) and HT changed */ |
| 2361 | changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT; |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2362 | ieee80211_bss_info_change_notify(sdata, changed); |
Tomas Winkler | 8e268e4 | 2008-11-25 13:05:44 +0200 | [diff] [blame] | 2363 | |
Johannes Berg | 3abead5 | 2012-03-02 15:56:59 +0100 | [diff] [blame] | 2364 | /* disassociated - set to defaults now */ |
Johannes Berg | cec6628 | 2015-10-22 17:46:04 +0200 | [diff] [blame] | 2365 | ieee80211_set_wmm_default(sdata, false, false); |
Johannes Berg | 3abead5 | 2012-03-02 15:56:59 +0100 | [diff] [blame] | 2366 | |
Johannes Berg | b9dcf71 | 2010-08-27 12:35:54 +0200 | [diff] [blame] | 2367 | del_timer_sync(&sdata->u.mgd.conn_mon_timer); |
| 2368 | del_timer_sync(&sdata->u.mgd.bcn_mon_timer); |
| 2369 | del_timer_sync(&sdata->u.mgd.timer); |
| 2370 | del_timer_sync(&sdata->u.mgd.chswitch_timer); |
Johannes Berg | 2d9957c | 2012-08-01 20:54:52 +0200 | [diff] [blame] | 2371 | |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 2372 | sdata->vif.bss_conf.dtim_period = 0; |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 2373 | sdata->vif.bss_conf.beacon_rate = NULL; |
| 2374 | |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 2375 | ifmgd->have_beacon = false; |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 2376 | |
Johannes Berg | 028e8da0 | 2012-11-26 11:57:41 +0100 | [diff] [blame] | 2377 | ifmgd->flags = 0; |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2378 | mutex_lock(&local->mtx); |
Johannes Berg | 028e8da0 | 2012-11-26 11:57:41 +0100 | [diff] [blame] | 2379 | ieee80211_vif_release_channel(sdata); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 2380 | |
| 2381 | sdata->vif.csa_active = false; |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 2382 | ifmgd->csa_waiting_bcn = false; |
Johannes Berg | f84eaa1 | 2015-03-12 08:53:26 +0200 | [diff] [blame] | 2383 | ifmgd->csa_ignored_same_chan = false; |
Luciano Coelho | a46992b | 2014-06-13 16:30:07 +0300 | [diff] [blame] | 2384 | if (sdata->csa_block_tx) { |
| 2385 | ieee80211_wake_vif_queues(local, sdata, |
| 2386 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 2387 | sdata->csa_block_tx = false; |
| 2388 | } |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2389 | mutex_unlock(&local->mtx); |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 2390 | |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 2391 | /* existing TX TSPEC sessions no longer exist */ |
| 2392 | memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec)); |
| 2393 | cancel_delayed_work_sync(&ifmgd->tx_tspec_wk); |
| 2394 | |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 2395 | sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2396 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2397 | |
Kalle Valo | 3cf335d5 | 2009-03-22 21:57:06 +0200 | [diff] [blame] | 2398 | void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata, |
| 2399 | struct ieee80211_hdr *hdr) |
| 2400 | { |
| 2401 | /* |
| 2402 | * We can postpone the mgd.timer whenever receiving unicast frames |
| 2403 | * from AP because we know that the connection is working both ways |
| 2404 | * at that time. But multicast frames (and hence also beacons) must |
| 2405 | * be ignored here, because we need to trigger the timer during |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2406 | * data idle periods for sending the periodic probe request to the |
| 2407 | * AP we're connected to. |
Kalle Valo | 3cf335d5 | 2009-03-22 21:57:06 +0200 | [diff] [blame] | 2408 | */ |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2409 | if (is_multicast_ether_addr(hdr->addr1)) |
| 2410 | return; |
| 2411 | |
Luis R. Rodriguez | be099e8 | 2010-09-16 15:12:29 -0400 | [diff] [blame] | 2412 | ieee80211_sta_reset_conn_monitor(sdata); |
Kalle Valo | 3cf335d5 | 2009-03-22 21:57:06 +0200 | [diff] [blame] | 2413 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2414 | |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2415 | static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata) |
| 2416 | { |
| 2417 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2418 | struct ieee80211_local *local = sdata->local; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2419 | |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2420 | mutex_lock(&local->mtx); |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 2421 | if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)) |
| 2422 | goto out; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2423 | |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 2424 | __ieee80211_stop_poll(sdata); |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2425 | |
| 2426 | mutex_lock(&local->iflist_mtx); |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 2427 | ieee80211_recalc_ps(local); |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2428 | mutex_unlock(&local->iflist_mtx); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2429 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2430 | if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR)) |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2431 | goto out; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2432 | |
| 2433 | /* |
| 2434 | * We've received a probe response, but are not sure whether |
| 2435 | * we have or will be receiving any beacons or data, so let's |
| 2436 | * schedule the timers again, just in case. |
| 2437 | */ |
| 2438 | ieee80211_sta_reset_beacon_monitor(sdata); |
| 2439 | |
| 2440 | mod_timer(&ifmgd->conn_mon_timer, |
| 2441 | round_jiffies_up(jiffies + |
| 2442 | IEEE80211_CONNECTION_IDLE_TIME)); |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2443 | out: |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2444 | mutex_unlock(&local->mtx); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2445 | } |
| 2446 | |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 2447 | static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata, |
| 2448 | struct ieee80211_hdr *hdr, |
| 2449 | u16 tx_time) |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2450 | { |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 2451 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Sara Sharon | a1f2ba04c | 2018-02-19 14:48:40 +0200 | [diff] [blame] | 2452 | u16 tid = ieee80211_get_tid(hdr); |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 2453 | int ac = ieee80211_ac_from_tid(tid); |
| 2454 | struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac]; |
| 2455 | unsigned long now = jiffies; |
| 2456 | |
| 2457 | if (likely(!tx_tspec->admitted_time)) |
| 2458 | return; |
| 2459 | |
| 2460 | if (time_after(now, tx_tspec->time_slice_start + HZ)) { |
| 2461 | tx_tspec->consumed_tx_time = 0; |
| 2462 | tx_tspec->time_slice_start = now; |
| 2463 | |
| 2464 | if (tx_tspec->downgraded) { |
| 2465 | tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE; |
| 2466 | schedule_delayed_work(&ifmgd->tx_tspec_wk, 0); |
| 2467 | } |
| 2468 | } |
| 2469 | |
| 2470 | if (tx_tspec->downgraded) |
| 2471 | return; |
| 2472 | |
| 2473 | tx_tspec->consumed_tx_time += tx_time; |
| 2474 | |
| 2475 | if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) { |
| 2476 | tx_tspec->downgraded = true; |
| 2477 | tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE; |
| 2478 | schedule_delayed_work(&ifmgd->tx_tspec_wk, 0); |
| 2479 | } |
| 2480 | } |
| 2481 | |
| 2482 | void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata, |
| 2483 | struct ieee80211_hdr *hdr, bool ack, u16 tx_time) |
| 2484 | { |
| 2485 | ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time); |
| 2486 | |
Felix Fietkau | 75706d0 | 2010-12-02 21:01:07 +0100 | [diff] [blame] | 2487 | if (!ieee80211_is_data(hdr->frame_control)) |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2488 | return; |
| 2489 | |
Thomas Pedersen | 30b2f0b | 2020-01-13 21:59:40 -0800 | [diff] [blame] | 2490 | if (ieee80211_is_any_nullfunc(hdr->frame_control) && |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2491 | sdata->u.mgd.probe_send_count > 0) { |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2492 | if (ack) |
Wojciech Dubowik | cab1c7f | 2013-02-14 14:08:37 +0100 | [diff] [blame] | 2493 | ieee80211_sta_reset_conn_monitor(sdata); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2494 | else |
| 2495 | sdata->u.mgd.nullfunc_failed = true; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2496 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
Wojciech Dubowik | cab1c7f | 2013-02-14 14:08:37 +0100 | [diff] [blame] | 2497 | return; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2498 | } |
Wojciech Dubowik | cab1c7f | 2013-02-14 14:08:37 +0100 | [diff] [blame] | 2499 | |
| 2500 | if (ack) |
| 2501 | ieee80211_sta_reset_conn_monitor(sdata); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2502 | } |
| 2503 | |
Johannes Berg | 45ad683 | 2018-05-28 15:47:39 +0200 | [diff] [blame] | 2504 | static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata, |
| 2505 | const u8 *src, const u8 *dst, |
| 2506 | const u8 *ssid, size_t ssid_len, |
| 2507 | struct ieee80211_channel *channel) |
| 2508 | { |
| 2509 | struct sk_buff *skb; |
| 2510 | |
| 2511 | skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel, |
| 2512 | ssid, ssid_len, NULL, 0, |
| 2513 | IEEE80211_PROBE_FLAG_DIRECTED); |
| 2514 | if (skb) |
| 2515 | ieee80211_tx_skb(sdata, skb); |
| 2516 | } |
| 2517 | |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2518 | static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata) |
| 2519 | { |
| 2520 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 2521 | const u8 *ssid; |
Luis R. Rodriguez | f01a067 | 2010-09-16 15:12:34 -0400 | [diff] [blame] | 2522 | u8 *dst = ifmgd->associated->bssid; |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 2523 | u8 unicast_limit = max(1, max_probe_tries - 3); |
Johannes Berg | 49ddf8e | 2016-03-31 20:02:10 +0300 | [diff] [blame] | 2524 | struct sta_info *sta; |
Luis R. Rodriguez | f01a067 | 2010-09-16 15:12:34 -0400 | [diff] [blame] | 2525 | |
| 2526 | /* |
| 2527 | * Try sending broadcast probe requests for the last three |
| 2528 | * probe requests after the first ones failed since some |
| 2529 | * buggy APs only support broadcast probe requests. |
| 2530 | */ |
| 2531 | if (ifmgd->probe_send_count >= unicast_limit) |
| 2532 | dst = NULL; |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2533 | |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2534 | /* |
| 2535 | * When the hardware reports an accurate Tx ACK status, it's |
| 2536 | * better to send a nullfunc frame instead of a probe request, |
| 2537 | * as it will kick us off the AP quickly if we aren't associated |
| 2538 | * anymore. The timeout will be reset if the frame is ACKed by |
| 2539 | * the AP. |
| 2540 | */ |
Soumik Das | 992e68b | 2012-05-20 15:31:13 +0530 | [diff] [blame] | 2541 | ifmgd->probe_send_count++; |
| 2542 | |
Johannes Berg | 49ddf8e | 2016-03-31 20:02:10 +0300 | [diff] [blame] | 2543 | if (dst) { |
| 2544 | mutex_lock(&sdata->local->sta_mtx); |
| 2545 | sta = sta_info_get(sdata, dst); |
| 2546 | if (!WARN_ON(!sta)) |
| 2547 | ieee80211_check_fast_rx(sta); |
| 2548 | mutex_unlock(&sdata->local->sta_mtx); |
| 2549 | } |
| 2550 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2551 | if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) { |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2552 | ifmgd->nullfunc_failed = false; |
Shay Bar | f39b07f | 2019-07-03 16:18:48 +0300 | [diff] [blame] | 2553 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) |
| 2554 | ifmgd->probe_send_count--; |
| 2555 | else |
| 2556 | ieee80211_send_nullfunc(sdata->local, sdata, false); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2557 | } else { |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 2558 | int ssid_len; |
| 2559 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2560 | rcu_read_lock(); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2561 | ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID); |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 2562 | if (WARN_ON_ONCE(ssid == NULL)) |
| 2563 | ssid_len = 0; |
| 2564 | else |
| 2565 | ssid_len = ssid[1]; |
| 2566 | |
Johannes Berg | 45ad683 | 2018-05-28 15:47:39 +0200 | [diff] [blame] | 2567 | ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst, |
| 2568 | ssid + 2, ssid_len, |
| 2569 | ifmgd->associated->channel); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2570 | rcu_read_unlock(); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2571 | } |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2572 | |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 2573 | ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2574 | run_again(sdata, ifmgd->probe_timeout); |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2575 | } |
| 2576 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2577 | static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata, |
| 2578 | bool beacon) |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2579 | { |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2580 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2581 | bool already = false; |
Johannes Berg | 34bfc41 | 2009-05-12 19:58:12 +0200 | [diff] [blame] | 2582 | |
Johannes Berg | 9607e6b66 | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 2583 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | 0e2b628 | 2009-07-13 13:23:39 +0200 | [diff] [blame] | 2584 | return; |
| 2585 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2586 | sdata_lock(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2587 | |
| 2588 | if (!ifmgd->associated) |
| 2589 | goto out; |
| 2590 | |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2591 | mutex_lock(&sdata->local->mtx); |
| 2592 | |
| 2593 | if (sdata->local->tmp_channel || sdata->local->scanning) { |
| 2594 | mutex_unlock(&sdata->local->mtx); |
| 2595 | goto out; |
| 2596 | } |
| 2597 | |
Ben Greear | a13fbe5 | 2013-03-25 11:19:35 -0700 | [diff] [blame] | 2598 | if (beacon) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2599 | mlme_dbg_ratelimited(sdata, |
Ben Greear | 59c1ec2 | 2013-03-19 14:19:56 -0700 | [diff] [blame] | 2600 | "detected beacon loss from AP (missed %d beacons) - probing\n", |
| 2601 | beacon_loss_count); |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2602 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 2603 | ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL); |
Ben Greear | a13fbe5 | 2013-03-25 11:19:35 -0700 | [diff] [blame] | 2604 | } |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2605 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2606 | /* |
| 2607 | * The driver/our work has already reported this event or the |
| 2608 | * connection monitoring has kicked in and we have already sent |
| 2609 | * a probe request. Or maybe the AP died and the driver keeps |
| 2610 | * reporting until we disassociate... |
| 2611 | * |
| 2612 | * In either case we have to ignore the current call to this |
| 2613 | * function (except for setting the correct probe reason bit) |
| 2614 | * because otherwise we would reset the timer every time and |
| 2615 | * never check whether we received a probe response! |
| 2616 | */ |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 2617 | if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2618 | already = true; |
| 2619 | |
Eliad Peller | 12b5f34 | 2013-11-18 19:06:46 +0200 | [diff] [blame] | 2620 | ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL; |
| 2621 | |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 2622 | mutex_unlock(&sdata->local->mtx); |
| 2623 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2624 | if (already) |
| 2625 | goto out; |
| 2626 | |
Johannes Berg | 4e75184 | 2009-06-10 15:16:52 +0200 | [diff] [blame] | 2627 | mutex_lock(&sdata->local->iflist_mtx); |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 2628 | ieee80211_recalc_ps(sdata->local); |
Johannes Berg | 4e75184 | 2009-06-10 15:16:52 +0200 | [diff] [blame] | 2629 | mutex_unlock(&sdata->local->iflist_mtx); |
| 2630 | |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2631 | ifmgd->probe_send_count = 0; |
| 2632 | ieee80211_mgd_probe_ap_send(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2633 | out: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2634 | sdata_unlock(sdata); |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2635 | } |
| 2636 | |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2637 | struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw, |
| 2638 | struct ieee80211_vif *vif) |
| 2639 | { |
| 2640 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 2641 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Eliad Peller | d9b3b28 | 2012-06-28 15:03:13 +0300 | [diff] [blame] | 2642 | struct cfg80211_bss *cbss; |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2643 | struct sk_buff *skb; |
| 2644 | const u8 *ssid; |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 2645 | int ssid_len; |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2646 | |
| 2647 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) |
| 2648 | return NULL; |
| 2649 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2650 | sdata_assert_lock(sdata); |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2651 | |
Eliad Peller | d9b3b28 | 2012-06-28 15:03:13 +0300 | [diff] [blame] | 2652 | if (ifmgd->associated) |
| 2653 | cbss = ifmgd->associated; |
| 2654 | else if (ifmgd->auth_data) |
| 2655 | cbss = ifmgd->auth_data->bss; |
| 2656 | else if (ifmgd->assoc_data) |
| 2657 | cbss = ifmgd->assoc_data->bss; |
| 2658 | else |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2659 | return NULL; |
| 2660 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2661 | rcu_read_lock(); |
Eliad Peller | d9b3b28 | 2012-06-28 15:03:13 +0300 | [diff] [blame] | 2662 | ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID); |
Will Deacon | 4152561 | 2019-10-04 10:51:31 +0100 | [diff] [blame] | 2663 | if (WARN_ONCE(!ssid || ssid[1] > IEEE80211_MAX_SSID_LEN, |
| 2664 | "invalid SSID element (len=%d)", ssid ? ssid[1] : -1)) |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 2665 | ssid_len = 0; |
| 2666 | else |
| 2667 | ssid_len = ssid[1]; |
| 2668 | |
Johannes Berg | a344d67 | 2014-06-12 22:24:31 +0200 | [diff] [blame] | 2669 | skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid, |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2670 | (u32) -1, cbss->channel, |
Johannes Berg | 6b77863 | 2012-07-23 14:53:27 +0200 | [diff] [blame] | 2671 | ssid + 2, ssid_len, |
Johannes Berg | 00387f3 | 2018-05-28 15:47:38 +0200 | [diff] [blame] | 2672 | NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 2673 | rcu_read_unlock(); |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 2674 | |
| 2675 | return skb; |
| 2676 | } |
| 2677 | EXPORT_SYMBOL(ieee80211_ap_probereq_get); |
| 2678 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 2679 | static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata, |
| 2680 | const u8 *buf, size_t len, bool tx, |
| 2681 | u16 reason) |
| 2682 | { |
| 2683 | struct ieee80211_event event = { |
| 2684 | .type = MLME_EVENT, |
| 2685 | .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT, |
| 2686 | .u.mlme.reason = reason, |
| 2687 | }; |
| 2688 | |
| 2689 | if (tx) |
| 2690 | cfg80211_tx_mlme_mgmt(sdata->dev, buf, len); |
| 2691 | else |
| 2692 | cfg80211_rx_mlme_mgmt(sdata->dev, buf, len); |
| 2693 | |
| 2694 | drv_event_callback(sdata->local, sdata, &event); |
| 2695 | } |
| 2696 | |
Johannes Berg | eef9e54 | 2013-01-29 13:09:34 +0100 | [diff] [blame] | 2697 | static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata) |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2698 | { |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 2699 | struct ieee80211_local *local = sdata->local; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2700 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 2701 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 2702 | bool tx; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2703 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2704 | sdata_lock(sdata); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2705 | if (!ifmgd->associated) { |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2706 | sdata_unlock(sdata); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2707 | return; |
| 2708 | } |
| 2709 | |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 2710 | tx = !sdata->csa_block_tx; |
| 2711 | |
David Spinadel | 20eb7ea | 2016-05-03 16:05:02 +0300 | [diff] [blame] | 2712 | /* AP is probably out of range (or not reachable for another reason) so |
| 2713 | * remove the bss struct for that AP. |
| 2714 | */ |
| 2715 | cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated); |
| 2716 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2717 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
| 2718 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 2719 | tx, frame_buf); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 2720 | mutex_lock(&local->mtx); |
Arik Nemtsov | 7578d57 | 2013-09-01 17:15:51 +0300 | [diff] [blame] | 2721 | sdata->vif.csa_active = false; |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 2722 | ifmgd->csa_waiting_bcn = false; |
Luciano Coelho | a46992b | 2014-06-13 16:30:07 +0300 | [diff] [blame] | 2723 | if (sdata->csa_block_tx) { |
| 2724 | ieee80211_wake_vif_queues(local, sdata, |
| 2725 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 2726 | sdata->csa_block_tx = false; |
| 2727 | } |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 2728 | mutex_unlock(&local->mtx); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 2729 | |
Emmanuel Grumbach | 6c18b27 | 2018-08-31 11:31:12 +0300 | [diff] [blame] | 2730 | ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx, |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 2731 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY); |
| 2732 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2733 | sdata_unlock(sdata); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2734 | } |
| 2735 | |
Johannes Berg | cc74c0c | 2012-08-01 16:49:34 +0200 | [diff] [blame] | 2736 | static void ieee80211_beacon_connection_loss_work(struct work_struct *work) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2737 | { |
| 2738 | struct ieee80211_sub_if_data *sdata = |
| 2739 | container_of(work, struct ieee80211_sub_if_data, |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2740 | u.mgd.beacon_connection_loss_work); |
Paul Stewart | a85e1d5 | 2011-12-09 11:01:49 -0800 | [diff] [blame] | 2741 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Paul Stewart | a85e1d5 | 2011-12-09 11:01:49 -0800 | [diff] [blame] | 2742 | |
Johannes Berg | 976bd9e | 2015-10-16 17:18:11 +0200 | [diff] [blame] | 2743 | if (ifmgd->associated) |
| 2744 | ifmgd->beacon_loss_count++; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2745 | |
Johannes Berg | 682bd38 | 2013-01-29 13:13:50 +0100 | [diff] [blame] | 2746 | if (ifmgd->connection_loss) { |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 2747 | sdata_info(sdata, "Connection to AP %pM lost\n", |
| 2748 | ifmgd->bssid); |
Johannes Berg | eef9e54 | 2013-01-29 13:09:34 +0100 | [diff] [blame] | 2749 | __ieee80211_disconnect(sdata); |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 2750 | } else { |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2751 | ieee80211_mgd_probe_ap(sdata, true); |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 2752 | } |
| 2753 | } |
| 2754 | |
| 2755 | static void ieee80211_csa_connection_drop_work(struct work_struct *work) |
| 2756 | { |
| 2757 | struct ieee80211_sub_if_data *sdata = |
| 2758 | container_of(work, struct ieee80211_sub_if_data, |
| 2759 | u.mgd.csa_connection_drop_work); |
| 2760 | |
Johannes Berg | eef9e54 | 2013-01-29 13:09:34 +0100 | [diff] [blame] | 2761 | __ieee80211_disconnect(sdata); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2762 | } |
| 2763 | |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2764 | void ieee80211_beacon_loss(struct ieee80211_vif *vif) |
| 2765 | { |
| 2766 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2767 | struct ieee80211_hw *hw = &sdata->local->hw; |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2768 | |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 2769 | trace_api_beacon_loss(sdata); |
| 2770 | |
Johannes Berg | 682bd38 | 2013-01-29 13:13:50 +0100 | [diff] [blame] | 2771 | sdata->u.mgd.connection_loss = false; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2772 | ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work); |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 2773 | } |
| 2774 | EXPORT_SYMBOL(ieee80211_beacon_loss); |
| 2775 | |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2776 | void ieee80211_connection_loss(struct ieee80211_vif *vif) |
| 2777 | { |
| 2778 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 2779 | struct ieee80211_hw *hw = &sdata->local->hw; |
| 2780 | |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 2781 | trace_api_connection_loss(sdata); |
| 2782 | |
Johannes Berg | 682bd38 | 2013-01-29 13:13:50 +0100 | [diff] [blame] | 2783 | sdata->u.mgd.connection_loss = true; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2784 | ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work); |
| 2785 | } |
| 2786 | EXPORT_SYMBOL(ieee80211_connection_loss); |
| 2787 | |
| 2788 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2789 | static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata, |
| 2790 | bool assoc) |
| 2791 | { |
| 2792 | struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data; |
| 2793 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2794 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2795 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2796 | if (!assoc) { |
Emmanuel Grumbach | c1e140b | 2015-01-19 16:53:06 +0200 | [diff] [blame] | 2797 | /* |
| 2798 | * we are not authenticated yet, the only timer that could be |
| 2799 | * running is the timeout for the authentication response which |
| 2800 | * which is not relevant anymore. |
| 2801 | */ |
| 2802 | del_timer_sync(&sdata->u.mgd.timer); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2803 | sta_info_destroy_addr(sdata, auth_data->bss->bssid); |
| 2804 | |
Joe Perches | c84a67a | 2015-03-02 19:54:57 -0800 | [diff] [blame] | 2805 | eth_zero_addr(sdata->u.mgd.bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2806 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
Johannes Berg | 028e8da0 | 2012-11-26 11:57:41 +0100 | [diff] [blame] | 2807 | sdata->u.mgd.flags = 0; |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2808 | mutex_lock(&sdata->local->mtx); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2809 | ieee80211_vif_release_channel(sdata); |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2810 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2811 | } |
| 2812 | |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 2813 | cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2814 | kfree(auth_data); |
| 2815 | sdata->u.mgd.auth_data = NULL; |
| 2816 | } |
| 2817 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 2818 | static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 2819 | bool assoc, bool abandon) |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 2820 | { |
| 2821 | struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data; |
| 2822 | |
| 2823 | sdata_assert_lock(sdata); |
| 2824 | |
| 2825 | if (!assoc) { |
| 2826 | /* |
| 2827 | * we are not associated yet, the only timer that could be |
| 2828 | * running is the timeout for the association response which |
| 2829 | * which is not relevant anymore. |
| 2830 | */ |
| 2831 | del_timer_sync(&sdata->u.mgd.timer); |
| 2832 | sta_info_destroy_addr(sdata, assoc_data->bss->bssid); |
| 2833 | |
| 2834 | eth_zero_addr(sdata->u.mgd.bssid); |
| 2835 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
| 2836 | sdata->u.mgd.flags = 0; |
Sara Sharon | b5a33d5 | 2016-02-16 12:48:18 +0200 | [diff] [blame] | 2837 | sdata->vif.mu_mimo_owner = false; |
| 2838 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 2839 | mutex_lock(&sdata->local->mtx); |
| 2840 | ieee80211_vif_release_channel(sdata); |
| 2841 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 2842 | |
| 2843 | if (abandon) |
| 2844 | cfg80211_abandon_assoc(sdata->dev, assoc_data->bss); |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 2845 | } |
| 2846 | |
| 2847 | kfree(assoc_data); |
| 2848 | sdata->u.mgd.assoc_data = NULL; |
| 2849 | } |
| 2850 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2851 | static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata, |
| 2852 | struct ieee80211_mgmt *mgmt, size_t len) |
| 2853 | { |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 2854 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2855 | struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data; |
| 2856 | u8 *pos; |
| 2857 | struct ieee802_11_elems elems; |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 2858 | u32 tx_flags = 0; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2859 | |
| 2860 | pos = mgmt->u.auth.variable; |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 2861 | ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems, |
| 2862 | mgmt->bssid, auth_data->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2863 | if (!elems.challenge) |
| 2864 | return; |
| 2865 | auth_data->expected_transaction = 4; |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 2866 | drv_mgd_prepare_tx(sdata->local, sdata, 0); |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2867 | if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 2868 | tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS | |
| 2869 | IEEE80211_TX_INTFL_MLME_CONN_TX; |
Jouni Malinen | 700e8ea | 2012-09-30 19:29:37 +0300 | [diff] [blame] | 2870 | ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0, |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2871 | elems.challenge - 2, elems.challenge_len + 2, |
| 2872 | auth_data->bss->bssid, auth_data->bss->bssid, |
| 2873 | auth_data->key, auth_data->key_len, |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 2874 | auth_data->key_idx, tx_flags); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2875 | } |
| 2876 | |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2877 | static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata, |
| 2878 | const u8 *bssid) |
| 2879 | { |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 2880 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2881 | struct sta_info *sta; |
Wei Yongjun | 33483a6 | 2018-10-16 02:35:30 +0000 | [diff] [blame] | 2882 | bool result = true; |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2883 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 2884 | sdata_info(sdata, "authenticated\n"); |
| 2885 | ifmgd->auth_data->done = true; |
| 2886 | ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC; |
| 2887 | ifmgd->auth_data->timeout_started = true; |
| 2888 | run_again(sdata, ifmgd->auth_data->timeout); |
| 2889 | |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2890 | /* move station state to auth */ |
| 2891 | mutex_lock(&sdata->local->sta_mtx); |
| 2892 | sta = sta_info_get(sdata, bssid); |
| 2893 | if (!sta) { |
| 2894 | WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid); |
Wei Yongjun | 33483a6 | 2018-10-16 02:35:30 +0000 | [diff] [blame] | 2895 | result = false; |
| 2896 | goto out; |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2897 | } |
| 2898 | if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) { |
| 2899 | sdata_info(sdata, "failed moving %pM to auth\n", bssid); |
Wei Yongjun | 33483a6 | 2018-10-16 02:35:30 +0000 | [diff] [blame] | 2900 | result = false; |
| 2901 | goto out; |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2902 | } |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2903 | |
Wei Yongjun | 33483a6 | 2018-10-16 02:35:30 +0000 | [diff] [blame] | 2904 | out: |
| 2905 | mutex_unlock(&sdata->local->sta_mtx); |
| 2906 | return result; |
Jouni Malinen | fc107a9 | 2018-10-11 00:21:19 +0300 | [diff] [blame] | 2907 | } |
| 2908 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2909 | static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata, |
| 2910 | struct ieee80211_mgmt *mgmt, size_t len) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2911 | { |
| 2912 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 2913 | u8 bssid[ETH_ALEN]; |
| 2914 | u16 auth_alg, auth_transaction, status_code; |
Emmanuel Grumbach | a940909 | 2015-03-16 23:23:35 +0200 | [diff] [blame] | 2915 | struct ieee80211_event event = { |
| 2916 | .type = MLME_EVENT, |
| 2917 | .u.mlme.data = AUTH_EVENT, |
| 2918 | }; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2919 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2920 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2921 | |
| 2922 | if (len < 24 + 6) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2923 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2924 | |
| 2925 | if (!ifmgd->auth_data || ifmgd->auth_data->done) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2926 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2927 | |
| 2928 | memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN); |
| 2929 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2930 | if (!ether_addr_equal(bssid, mgmt->bssid)) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2931 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2932 | |
| 2933 | auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); |
| 2934 | auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); |
| 2935 | status_code = le16_to_cpu(mgmt->u.auth.status_code); |
| 2936 | |
| 2937 | if (auth_alg != ifmgd->auth_data->algorithm || |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 2938 | (auth_alg != WLAN_AUTH_SAE && |
| 2939 | auth_transaction != ifmgd->auth_data->expected_transaction) || |
| 2940 | (auth_alg == WLAN_AUTH_SAE && |
| 2941 | (auth_transaction < ifmgd->auth_data->expected_transaction || |
| 2942 | auth_transaction > 2))) { |
Jouni Malinen | 0f4126e | 2012-09-30 19:29:38 +0300 | [diff] [blame] | 2943 | sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n", |
| 2944 | mgmt->sa, auth_alg, ifmgd->auth_data->algorithm, |
| 2945 | auth_transaction, |
| 2946 | ifmgd->auth_data->expected_transaction); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2947 | return; |
Jouni Malinen | 0f4126e | 2012-09-30 19:29:38 +0300 | [diff] [blame] | 2948 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2949 | |
| 2950 | if (status_code != WLAN_STATUS_SUCCESS) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2951 | sdata_info(sdata, "%pM denied authentication (status %d)\n", |
| 2952 | mgmt->sa, status_code); |
Eliad Peller | dac211e | 2012-05-13 18:07:04 +0300 | [diff] [blame] | 2953 | ieee80211_destroy_auth_data(sdata, false); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 2954 | cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len); |
Emmanuel Grumbach | a940909 | 2015-03-16 23:23:35 +0200 | [diff] [blame] | 2955 | event.u.mlme.status = MLME_DENIED; |
| 2956 | event.u.mlme.reason = status_code; |
| 2957 | drv_event_callback(sdata->local, sdata, &event); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2958 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | switch (ifmgd->auth_data->algorithm) { |
| 2962 | case WLAN_AUTH_OPEN: |
| 2963 | case WLAN_AUTH_LEAP: |
| 2964 | case WLAN_AUTH_FT: |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 2965 | case WLAN_AUTH_SAE: |
Jouni Malinen | dbc0c2c | 2016-10-27 00:42:04 +0300 | [diff] [blame] | 2966 | case WLAN_AUTH_FILS_SK: |
| 2967 | case WLAN_AUTH_FILS_SK_PFS: |
| 2968 | case WLAN_AUTH_FILS_PK: |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2969 | break; |
| 2970 | case WLAN_AUTH_SHARED_KEY: |
| 2971 | if (ifmgd->auth_data->expected_transaction != 4) { |
| 2972 | ieee80211_auth_challenge(sdata, mgmt, len); |
| 2973 | /* need another frame */ |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2974 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2975 | } |
| 2976 | break; |
| 2977 | default: |
| 2978 | WARN_ONCE(1, "invalid auth alg %d", |
| 2979 | ifmgd->auth_data->algorithm); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2980 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2981 | } |
| 2982 | |
Emmanuel Grumbach | a940909 | 2015-03-16 23:23:35 +0200 | [diff] [blame] | 2983 | event.u.mlme.status = MLME_SUCCESS; |
| 2984 | drv_event_callback(sdata->local, sdata, &event); |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 2985 | if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE || |
| 2986 | (auth_transaction == 2 && |
| 2987 | ifmgd->auth_data->expected_transaction == 2)) { |
| 2988 | if (!ieee80211_mark_sta_auth(sdata, bssid)) |
Andrei Otcheretianski | 0daa63e | 2020-02-21 10:47:20 +0100 | [diff] [blame] | 2989 | return; /* ignore frame -- wait for timeout */ |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 2990 | } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE && |
| 2991 | auth_transaction == 2) { |
| 2992 | sdata_info(sdata, "SAE peer confirmed\n"); |
| 2993 | ifmgd->auth_data->peer_confirmed = true; |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 2994 | } |
| 2995 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 2996 | cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2997 | } |
| 2998 | |
Calvin Owens | dfa1ad2 | 2014-02-11 12:36:24 -0600 | [diff] [blame] | 2999 | #define case_WLAN(type) \ |
| 3000 | case WLAN_REASON_##type: return #type |
| 3001 | |
Yu Wang | 79c92ca | 2019-05-10 17:04:52 +0800 | [diff] [blame] | 3002 | const char *ieee80211_get_reason_code_string(u16 reason_code) |
Calvin Owens | dfa1ad2 | 2014-02-11 12:36:24 -0600 | [diff] [blame] | 3003 | { |
| 3004 | switch (reason_code) { |
| 3005 | case_WLAN(UNSPECIFIED); |
| 3006 | case_WLAN(PREV_AUTH_NOT_VALID); |
| 3007 | case_WLAN(DEAUTH_LEAVING); |
| 3008 | case_WLAN(DISASSOC_DUE_TO_INACTIVITY); |
| 3009 | case_WLAN(DISASSOC_AP_BUSY); |
| 3010 | case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA); |
| 3011 | case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA); |
| 3012 | case_WLAN(DISASSOC_STA_HAS_LEFT); |
| 3013 | case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH); |
| 3014 | case_WLAN(DISASSOC_BAD_POWER); |
| 3015 | case_WLAN(DISASSOC_BAD_SUPP_CHAN); |
| 3016 | case_WLAN(INVALID_IE); |
| 3017 | case_WLAN(MIC_FAILURE); |
| 3018 | case_WLAN(4WAY_HANDSHAKE_TIMEOUT); |
| 3019 | case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT); |
| 3020 | case_WLAN(IE_DIFFERENT); |
| 3021 | case_WLAN(INVALID_GROUP_CIPHER); |
| 3022 | case_WLAN(INVALID_PAIRWISE_CIPHER); |
| 3023 | case_WLAN(INVALID_AKMP); |
| 3024 | case_WLAN(UNSUPP_RSN_VERSION); |
| 3025 | case_WLAN(INVALID_RSN_IE_CAP); |
| 3026 | case_WLAN(IEEE8021X_FAILED); |
| 3027 | case_WLAN(CIPHER_SUITE_REJECTED); |
| 3028 | case_WLAN(DISASSOC_UNSPECIFIED_QOS); |
| 3029 | case_WLAN(DISASSOC_QAP_NO_BANDWIDTH); |
| 3030 | case_WLAN(DISASSOC_LOW_ACK); |
| 3031 | case_WLAN(DISASSOC_QAP_EXCEED_TXOP); |
| 3032 | case_WLAN(QSTA_LEAVE_QBSS); |
| 3033 | case_WLAN(QSTA_NOT_USE); |
| 3034 | case_WLAN(QSTA_REQUIRE_SETUP); |
| 3035 | case_WLAN(QSTA_TIMEOUT); |
| 3036 | case_WLAN(QSTA_CIPHER_NOT_SUPP); |
| 3037 | case_WLAN(MESH_PEER_CANCELED); |
| 3038 | case_WLAN(MESH_MAX_PEERS); |
| 3039 | case_WLAN(MESH_CONFIG); |
| 3040 | case_WLAN(MESH_CLOSE); |
| 3041 | case_WLAN(MESH_MAX_RETRIES); |
| 3042 | case_WLAN(MESH_CONFIRM_TIMEOUT); |
| 3043 | case_WLAN(MESH_INVALID_GTK); |
| 3044 | case_WLAN(MESH_INCONSISTENT_PARAM); |
| 3045 | case_WLAN(MESH_INVALID_SECURITY); |
| 3046 | case_WLAN(MESH_PATH_ERROR); |
| 3047 | case_WLAN(MESH_PATH_NOFORWARD); |
| 3048 | case_WLAN(MESH_PATH_DEST_UNREACHABLE); |
| 3049 | case_WLAN(MAC_EXISTS_IN_MBSS); |
| 3050 | case_WLAN(MESH_CHAN_REGULATORY); |
| 3051 | case_WLAN(MESH_CHAN); |
| 3052 | default: return "<unknown>"; |
| 3053 | } |
| 3054 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3055 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3056 | static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata, |
| 3057 | struct ieee80211_mgmt *mgmt, size_t len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3058 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3059 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3060 | u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3061 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3062 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3063 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 3064 | if (len < 24 + 2) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3065 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3066 | |
Yu Wang | 79c92ca | 2019-05-10 17:04:52 +0800 | [diff] [blame] | 3067 | if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) { |
| 3068 | ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code); |
| 3069 | return; |
| 3070 | } |
| 3071 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3072 | if (ifmgd->associated && |
| 3073 | ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) { |
| 3074 | const u8 *bssid = ifmgd->associated->bssid; |
| 3075 | |
| 3076 | sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n", |
| 3077 | bssid, reason_code, |
| 3078 | ieee80211_get_reason_code_string(reason_code)); |
| 3079 | |
| 3080 | ieee80211_set_disassoc(sdata, 0, 0, false, NULL); |
| 3081 | |
| 3082 | ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, |
| 3083 | reason_code); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3084 | return; |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3085 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3086 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3087 | if (ifmgd->assoc_data && |
| 3088 | ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) { |
| 3089 | const u8 *bssid = ifmgd->assoc_data->bss->bssid; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3090 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3091 | sdata_info(sdata, |
| 3092 | "deauthenticated from %pM while associating (Reason: %u=%s)\n", |
| 3093 | bssid, reason_code, |
| 3094 | ieee80211_get_reason_code_string(reason_code)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3095 | |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 3096 | ieee80211_destroy_assoc_data(sdata, false, true); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3097 | |
Johannes Berg | c9c99f8 | 2015-06-01 14:10:09 +0200 | [diff] [blame] | 3098 | cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len); |
| 3099 | return; |
| 3100 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3101 | } |
| 3102 | |
| 3103 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3104 | static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata, |
| 3105 | struct ieee80211_mgmt *mgmt, size_t len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3106 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3107 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3108 | u16 reason_code; |
| 3109 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3110 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3111 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 3112 | if (len < 24 + 2) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3113 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3114 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3115 | if (!ifmgd->associated || |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 3116 | !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3117 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3118 | |
| 3119 | reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); |
| 3120 | |
Yu Wang | 79c92ca | 2019-05-10 17:04:52 +0800 | [diff] [blame] | 3121 | if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) { |
| 3122 | ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code); |
| 3123 | return; |
| 3124 | } |
| 3125 | |
Arkadiusz Miskiewicz | 68506e9 | 2017-02-15 14:21:27 +0100 | [diff] [blame] | 3126 | sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n", |
| 3127 | mgmt->sa, reason_code, |
| 3128 | ieee80211_get_reason_code_string(reason_code)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3129 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 3130 | ieee80211_set_disassoc(sdata, 0, 0, false, NULL); |
| 3131 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 3132 | ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3133 | } |
| 3134 | |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3135 | static void ieee80211_get_rates(struct ieee80211_supported_band *sband, |
| 3136 | u8 *supp_rates, unsigned int supp_rates_len, |
| 3137 | u32 *rates, u32 *basic_rates, |
| 3138 | bool *have_higher_than_11mbit, |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3139 | int *min_rate, int *min_rate_index, |
Johannes Berg | 44f6d42 | 2017-06-10 13:52:44 +0300 | [diff] [blame] | 3140 | int shift) |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3141 | { |
| 3142 | int i, j; |
| 3143 | |
| 3144 | for (i = 0; i < supp_rates_len; i++) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3145 | int rate = supp_rates[i] & 0x7f; |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3146 | bool is_basic = !!(supp_rates[i] & 0x80); |
| 3147 | |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3148 | if ((rate * 5 * (1 << shift)) > 110) |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3149 | *have_higher_than_11mbit = true; |
| 3150 | |
| 3151 | /* |
Johannes Berg | a6289d3 | 2017-03-06 22:59:04 +0100 | [diff] [blame] | 3152 | * Skip HT and VHT BSS membership selectors since they're not |
| 3153 | * rates. |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3154 | * |
Johannes Berg | a6289d3 | 2017-03-06 22:59:04 +0100 | [diff] [blame] | 3155 | * Note: Even though the membership selector and the basic |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3156 | * rate flag share the same bit, they are not exactly |
| 3157 | * the same. |
| 3158 | */ |
Johannes Berg | a6289d3 | 2017-03-06 22:59:04 +0100 | [diff] [blame] | 3159 | if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) || |
| 3160 | supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3161 | continue; |
| 3162 | |
| 3163 | for (j = 0; j < sband->n_bitrates; j++) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3164 | struct ieee80211_rate *br; |
| 3165 | int brate; |
| 3166 | |
| 3167 | br = &sband->bitrates[j]; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3168 | |
| 3169 | brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5); |
| 3170 | if (brate == rate) { |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3171 | *rates |= BIT(j); |
| 3172 | if (is_basic) |
| 3173 | *basic_rates |= BIT(j); |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 3174 | if ((rate * 5) < *min_rate) { |
| 3175 | *min_rate = rate * 5; |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3176 | *min_rate_index = j; |
| 3177 | } |
| 3178 | break; |
| 3179 | } |
| 3180 | } |
| 3181 | } |
| 3182 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3183 | |
Emmanuel Grumbach | 55ebd6e | 2018-12-15 11:03:04 +0200 | [diff] [blame] | 3184 | static bool ieee80211_twt_req_supported(const struct sta_info *sta, |
| 3185 | const struct ieee802_11_elems *elems) |
| 3186 | { |
| 3187 | if (elems->ext_capab_len < 10) |
| 3188 | return false; |
| 3189 | |
| 3190 | if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT)) |
| 3191 | return false; |
| 3192 | |
| 3193 | return sta->sta.he_cap.he_cap_elem.mac_cap_info[0] & |
| 3194 | IEEE80211_HE_MAC_CAP0_TWT_RES; |
| 3195 | } |
| 3196 | |
John Crispin | c9d3245 | 2019-05-28 13:49:47 +0200 | [diff] [blame] | 3197 | static int ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata, |
| 3198 | struct sta_info *sta, |
| 3199 | struct ieee802_11_elems *elems) |
| 3200 | { |
| 3201 | bool twt = ieee80211_twt_req_supported(sta, elems); |
| 3202 | |
| 3203 | if (sdata->vif.bss_conf.twt_requester != twt) { |
| 3204 | sdata->vif.bss_conf.twt_requester = twt; |
| 3205 | return BSS_CHANGED_TWT; |
| 3206 | } |
| 3207 | return 0; |
| 3208 | } |
| 3209 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3210 | static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata, |
| 3211 | struct cfg80211_bss *cbss, |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3212 | struct ieee80211_mgmt *mgmt, size_t len, |
| 3213 | struct ieee802_11_elems *elems) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3214 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3215 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 3216 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3217 | struct ieee80211_supported_band *sband; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3218 | struct sta_info *sta; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3219 | u16 capab_info, aid; |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 3220 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3221 | const struct cfg80211_bss_ies *bss_ies = NULL; |
| 3222 | struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 3223 | u32 changed = 0; |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 3224 | int err; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3225 | bool ret; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3226 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3227 | /* AssocResp and ReassocResp have identical structure */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3228 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3229 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3230 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3231 | |
Johannes Berg | c7c477b | 2017-12-01 13:50:51 +0200 | [diff] [blame] | 3232 | /* |
| 3233 | * The 5 MSB of the AID field are reserved |
| 3234 | * (802.11-2016 9.4.1.8 AID field) |
| 3235 | */ |
| 3236 | aid &= 0x7ff; |
Johannes Berg | 1dd84aa | 2007-10-10 12:03:41 +0200 | [diff] [blame] | 3237 | |
Johannes Berg | 05cb910 | 2011-10-28 11:59:47 +0200 | [diff] [blame] | 3238 | ifmgd->broken_ap = false; |
| 3239 | |
| 3240 | if (aid == 0 || aid > IEEE80211_MAX_AID) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3241 | sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n", |
| 3242 | aid); |
Johannes Berg | 05cb910 | 2011-10-28 11:59:47 +0200 | [diff] [blame] | 3243 | aid = 0; |
| 3244 | ifmgd->broken_ap = true; |
| 3245 | } |
| 3246 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3247 | if (!elems->supp_rates) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3248 | sdata_info(sdata, "no SuppRates element in AssocResp\n"); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3249 | return false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3250 | } |
| 3251 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3252 | ifmgd->aid = aid; |
Arik Nemtsov | 9041c1f | 2014-11-09 18:50:15 +0200 | [diff] [blame] | 3253 | ifmgd->tdls_chan_switch_prohibited = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3254 | elems->ext_capab && elems->ext_capab_len >= 5 && |
| 3255 | (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3256 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3257 | /* |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3258 | * Some APs are erroneously not including some information in their |
| 3259 | * (re)association response frames. Try to recover by using the data |
| 3260 | * from the beacon or probe response. This seems to afflict mobile |
| 3261 | * 2G/3G/4G wifi routers, reported models include the "Onda PN51T", |
| 3262 | * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device. |
| 3263 | */ |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3264 | if ((assoc_data->wmm && !elems->wmm_param) || |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3265 | (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) && |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3266 | (!elems->ht_cap_elem || !elems->ht_operation)) || |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3267 | (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3268 | (!elems->vht_cap_elem || !elems->vht_operation))) { |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3269 | const struct cfg80211_bss_ies *ies; |
| 3270 | struct ieee802_11_elems bss_elems; |
| 3271 | |
| 3272 | rcu_read_lock(); |
| 3273 | ies = rcu_dereference(cbss->ies); |
| 3274 | if (ies) |
| 3275 | bss_ies = kmemdup(ies, sizeof(*ies) + ies->len, |
| 3276 | GFP_ATOMIC); |
| 3277 | rcu_read_unlock(); |
| 3278 | if (!bss_ies) |
| 3279 | return false; |
| 3280 | |
| 3281 | ieee802_11_parse_elems(bss_ies->data, bss_ies->len, |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3282 | false, &bss_elems, |
| 3283 | mgmt->bssid, |
| 3284 | assoc_data->bss->bssid); |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3285 | if (assoc_data->wmm && |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3286 | !elems->wmm_param && bss_elems.wmm_param) { |
| 3287 | elems->wmm_param = bss_elems.wmm_param; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3288 | sdata_info(sdata, |
| 3289 | "AP bug: WMM param missing from AssocResp\n"); |
| 3290 | } |
| 3291 | |
| 3292 | /* |
| 3293 | * Also check if we requested HT/VHT, otherwise the AP doesn't |
| 3294 | * have to include the IEs in the (re)association response. |
| 3295 | */ |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3296 | if (!elems->ht_cap_elem && bss_elems.ht_cap_elem && |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3297 | !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) { |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3298 | elems->ht_cap_elem = bss_elems.ht_cap_elem; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3299 | sdata_info(sdata, |
| 3300 | "AP bug: HT capability missing from AssocResp\n"); |
| 3301 | } |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3302 | if (!elems->ht_operation && bss_elems.ht_operation && |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3303 | !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) { |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3304 | elems->ht_operation = bss_elems.ht_operation; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3305 | sdata_info(sdata, |
| 3306 | "AP bug: HT operation missing from AssocResp\n"); |
| 3307 | } |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3308 | if (!elems->vht_cap_elem && bss_elems.vht_cap_elem && |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3309 | !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) { |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3310 | elems->vht_cap_elem = bss_elems.vht_cap_elem; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3311 | sdata_info(sdata, |
| 3312 | "AP bug: VHT capa missing from AssocResp\n"); |
| 3313 | } |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3314 | if (!elems->vht_operation && bss_elems.vht_operation && |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3315 | !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) { |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3316 | elems->vht_operation = bss_elems.vht_operation; |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3317 | sdata_info(sdata, |
| 3318 | "AP bug: VHT operation missing from AssocResp\n"); |
| 3319 | } |
| 3320 | } |
| 3321 | |
| 3322 | /* |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3323 | * We previously checked these in the beacon/probe response, so |
| 3324 | * they should be present here. This is just a safety net. |
| 3325 | */ |
| 3326 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) && |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3327 | (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) { |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3328 | sdata_info(sdata, |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3329 | "HT AP is missing WMM params or HT capability/operation\n"); |
| 3330 | ret = false; |
| 3331 | goto out; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3332 | } |
| 3333 | |
| 3334 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3335 | (!elems->vht_cap_elem || !elems->vht_operation)) { |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3336 | sdata_info(sdata, |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3337 | "VHT AP is missing VHT capability/operation\n"); |
| 3338 | ret = false; |
| 3339 | goto out; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3340 | } |
| 3341 | |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 3342 | mutex_lock(&sdata->local->sta_mtx); |
| 3343 | /* |
| 3344 | * station info was already allocated and inserted before |
| 3345 | * the association and should be available to us |
| 3346 | */ |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 3347 | sta = sta_info_get(sdata, cbss->bssid); |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 3348 | if (WARN_ON(!sta)) { |
| 3349 | mutex_unlock(&sdata->local->sta_mtx); |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3350 | ret = false; |
| 3351 | goto out; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3352 | } |
| 3353 | |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 3354 | sband = ieee80211_get_sband(sdata); |
| 3355 | if (!sband) { |
| 3356 | mutex_unlock(&sdata->local->sta_mtx); |
| 3357 | ret = false; |
| 3358 | goto out; |
| 3359 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3360 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3361 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3362 | (!elems->he_cap || !elems->he_operation)) { |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3363 | mutex_unlock(&sdata->local->sta_mtx); |
| 3364 | sdata_info(sdata, |
| 3365 | "HE AP is missing HE capability/operation\n"); |
| 3366 | ret = false; |
| 3367 | goto out; |
| 3368 | } |
| 3369 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3370 | /* Set up internal HT/VHT capabilities */ |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3371 | if (elems->ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 3372 | ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband, |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3373 | elems->ht_cap_elem, sta); |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 3374 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3375 | if (elems->vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
Mahesh Palivela | 818255e | 2012-10-10 11:33:04 +0000 | [diff] [blame] | 3376 | ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband, |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3377 | elems->vht_cap_elem, sta); |
Mahesh Palivela | 818255e | 2012-10-10 11:33:04 +0000 | [diff] [blame] | 3378 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3379 | if (elems->he_operation && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && |
| 3380 | elems->he_cap) { |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3381 | ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband, |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3382 | elems->he_cap, |
| 3383 | elems->he_cap_len, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3384 | sta); |
| 3385 | |
| 3386 | bss_conf->he_support = sta->sta.he_cap.has_he; |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3387 | changed |= ieee80211_recalc_twt_req(sdata, sta, elems); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3388 | } else { |
| 3389 | bss_conf->he_support = false; |
Emmanuel Grumbach | 55ebd6e | 2018-12-15 11:03:04 +0200 | [diff] [blame] | 3390 | bss_conf->twt_requester = false; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3391 | } |
| 3392 | |
| 3393 | if (bss_conf->he_support) { |
John Crispin | dd56e90 | 2019-12-17 15:19:19 +0100 | [diff] [blame] | 3394 | bss_conf->he_bss_color.color = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3395 | le32_get_bits(elems->he_operation->he_oper_params, |
Naftali Goldstein | 77cbbc3 | 2018-09-05 08:06:07 +0300 | [diff] [blame] | 3396 | IEEE80211_HE_OPERATION_BSS_COLOR_MASK); |
John Crispin | dd56e90 | 2019-12-17 15:19:19 +0100 | [diff] [blame] | 3397 | bss_conf->he_bss_color.partial = |
| 3398 | le32_get_bits(elems->he_operation->he_oper_params, |
| 3399 | IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR); |
| 3400 | bss_conf->he_bss_color.disabled = |
| 3401 | le32_get_bits(elems->he_operation->he_oper_params, |
| 3402 | IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED); |
| 3403 | changed |= BSS_CHANGED_HE_BSS_COLOR; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3404 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3405 | bss_conf->htc_trig_based_pkt_ext = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3406 | le32_get_bits(elems->he_operation->he_oper_params, |
Naftali Goldstein | 77cbbc3 | 2018-09-05 08:06:07 +0300 | [diff] [blame] | 3407 | IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3408 | bss_conf->frame_time_rts_th = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3409 | le32_get_bits(elems->he_operation->he_oper_params, |
Naftali Goldstein | 77cbbc3 | 2018-09-05 08:06:07 +0300 | [diff] [blame] | 3410 | IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3411 | |
| 3412 | bss_conf->multi_sta_back_32bit = |
| 3413 | sta->sta.he_cap.he_cap_elem.mac_cap_info[2] & |
| 3414 | IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP; |
| 3415 | |
| 3416 | bss_conf->ack_enabled = |
| 3417 | sta->sta.he_cap.he_cap_elem.mac_cap_info[2] & |
| 3418 | IEEE80211_HE_MAC_CAP2_ACK_EN; |
| 3419 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3420 | bss_conf->uora_exists = !!elems->uora_element; |
| 3421 | if (elems->uora_element) |
| 3422 | bss_conf->uora_ocw_range = elems->uora_element[0]; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3423 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3424 | ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation); |
| 3425 | ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 3426 | /* TODO: OPEN: what happens if BSS color disable is set? */ |
| 3427 | } |
| 3428 | |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3429 | if (cbss->transmitted_bss) { |
| 3430 | bss_conf->nontransmitted = true; |
| 3431 | ether_addr_copy(bss_conf->transmitter_bssid, |
| 3432 | cbss->transmitted_bss->bssid); |
| 3433 | bss_conf->bssid_indicator = cbss->max_bssid_indicator; |
| 3434 | bss_conf->bssid_index = cbss->bssid_index; |
| 3435 | } |
| 3436 | |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 3437 | /* |
| 3438 | * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data |
| 3439 | * in their association response, so ignore that data for our own |
| 3440 | * configuration. If it changed since the last beacon, we'll get the |
| 3441 | * next beacon and update then. |
| 3442 | */ |
Johannes Berg | 1128958 | 2013-02-07 17:36:12 +0100 | [diff] [blame] | 3443 | |
Johannes Berg | bee7f586 | 2013-02-07 22:24:55 +0100 | [diff] [blame] | 3444 | /* |
| 3445 | * If an operating mode notification IE is present, override the |
| 3446 | * NSS calculation (that would be done in rate_control_rate_init()) |
| 3447 | * and use the # of streams from that element. |
| 3448 | */ |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3449 | if (elems->opmode_notif && |
| 3450 | !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) { |
Johannes Berg | bee7f586 | 2013-02-07 22:24:55 +0100 | [diff] [blame] | 3451 | u8 nss; |
| 3452 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3453 | nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK; |
Johannes Berg | bee7f586 | 2013-02-07 22:24:55 +0100 | [diff] [blame] | 3454 | nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT; |
| 3455 | nss += 1; |
| 3456 | sta->sta.rx_nss = nss; |
| 3457 | } |
| 3458 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 3459 | rate_control_rate_init(sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3460 | |
Tamizh chelvam | 93f0490 | 2015-10-07 10:40:04 +0530 | [diff] [blame] | 3461 | if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) { |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 3462 | set_sta_flag(sta, WLAN_STA_MFP); |
Tamizh chelvam | 93f0490 | 2015-10-07 10:40:04 +0530 | [diff] [blame] | 3463 | sta->sta.mfp = true; |
| 3464 | } else { |
| 3465 | sta->sta.mfp = false; |
| 3466 | } |
Jouni Malinen | 5394af4 | 2009-01-08 13:31:59 +0200 | [diff] [blame] | 3467 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3468 | sta->sta.wme = elems->wmm_param && local->hw.queues >= IEEE80211_NUM_ACS; |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 3469 | |
Johannes Berg | 3e4d40f | 2013-02-07 17:19:08 +0100 | [diff] [blame] | 3470 | err = sta_info_move_state(sta, IEEE80211_STA_ASSOC); |
Johannes Berg | c898787 | 2012-01-20 13:55:17 +0100 | [diff] [blame] | 3471 | if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT)) |
| 3472 | err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED); |
| 3473 | if (err) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3474 | sdata_info(sdata, |
| 3475 | "failed to move station %pM to desired state\n", |
| 3476 | sta->sta.addr); |
Johannes Berg | c898787 | 2012-01-20 13:55:17 +0100 | [diff] [blame] | 3477 | WARN_ON(__sta_info_destroy(sta)); |
| 3478 | mutex_unlock(&sdata->local->sta_mtx); |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3479 | ret = false; |
| 3480 | goto out; |
Johannes Berg | c898787 | 2012-01-20 13:55:17 +0100 | [diff] [blame] | 3481 | } |
| 3482 | |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 3483 | mutex_unlock(&sdata->local->sta_mtx); |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 3484 | |
Juuso Oikarinen | f2176d7 | 2010-09-28 14:39:32 +0300 | [diff] [blame] | 3485 | /* |
| 3486 | * Always handle WMM once after association regardless |
| 3487 | * of the first value the AP uses. Setting -1 here has |
| 3488 | * that effect because the AP values is an unsigned |
| 3489 | * 4-bit value. |
| 3490 | */ |
| 3491 | ifmgd->wmm_last_param_set = -1; |
Shaul Triebitz | 2e249fc | 2018-12-15 11:03:15 +0200 | [diff] [blame] | 3492 | ifmgd->mu_edca_last_param_set = -1; |
Juuso Oikarinen | f2176d7 | 2010-09-28 14:39:32 +0300 | [diff] [blame] | 3493 | |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 3494 | if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) { |
Johannes Berg | cec6628 | 2015-10-22 17:46:04 +0200 | [diff] [blame] | 3495 | ieee80211_set_wmm_default(sdata, false, false); |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3496 | } else if (!ieee80211_sta_wmm_params(local, sdata, elems->wmm_param, |
| 3497 | elems->wmm_param_len, |
| 3498 | elems->mu_edca_param_set)) { |
Johannes Berg | 2ed77ea | 2015-10-22 17:46:06 +0200 | [diff] [blame] | 3499 | /* still enable QoS since we might have HT/VHT */ |
| 3500 | ieee80211_set_wmm_default(sdata, false, true); |
| 3501 | /* set the disable-WMM flag in this case to disable |
| 3502 | * tracking WMM parameter changes in the beacon if |
| 3503 | * the parameters weren't actually valid. Doing so |
| 3504 | * avoids changing parameters very strangely when |
| 3505 | * the AP is going back and forth between valid and |
| 3506 | * invalid parameters. |
| 3507 | */ |
| 3508 | ifmgd->flags |= IEEE80211_STA_DISABLE_WMM; |
| 3509 | } |
Johannes Berg | 3abead5 | 2012-03-02 15:56:59 +0100 | [diff] [blame] | 3510 | changed |= BSS_CHANGED_QOS; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3511 | |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3512 | if (elems->max_idle_period_ie) { |
Avraham Stern | e38a017 | 2017-04-26 10:58:47 +0300 | [diff] [blame] | 3513 | bss_conf->max_idle_period = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3514 | le16_to_cpu(elems->max_idle_period_ie->max_idle_period); |
Avraham Stern | e38a017 | 2017-04-26 10:58:47 +0300 | [diff] [blame] | 3515 | bss_conf->protected_keep_alive = |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3516 | !!(elems->max_idle_period_ie->idle_options & |
Avraham Stern | e38a017 | 2017-04-26 10:58:47 +0300 | [diff] [blame] | 3517 | WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE); |
| 3518 | changed |= BSS_CHANGED_KEEP_ALIVE; |
| 3519 | } else { |
| 3520 | bss_conf->max_idle_period = 0; |
| 3521 | bss_conf->protected_keep_alive = false; |
| 3522 | } |
| 3523 | |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 3524 | /* set AID and assoc capability, |
| 3525 | * ieee80211_set_associated() will tell the driver */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3526 | bss_conf->aid = aid; |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 3527 | bss_conf->assoc_capability = capab_info; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 3528 | ieee80211_set_associated(sdata, cbss, changed); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3529 | |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 3530 | /* |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 3531 | * If we're using 4-addr mode, let the AP know that we're |
| 3532 | * doing so, so that it can create the STA VLAN on its side |
| 3533 | */ |
| 3534 | if (ifmgd->use_4addr) |
| 3535 | ieee80211_send_4addr_nullfunc(local, sdata); |
| 3536 | |
| 3537 | /* |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3538 | * Start timer to probe the connection to the AP now. |
| 3539 | * Also start the timer that will detect beacon loss. |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 3540 | */ |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3541 | ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt); |
Luis R. Rodriguez | d3a910a | 2010-09-16 15:12:32 -0400 | [diff] [blame] | 3542 | ieee80211_sta_reset_beacon_monitor(sdata); |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 3543 | |
Johannes Berg | 35d865a | 2013-05-28 10:54:03 +0200 | [diff] [blame] | 3544 | ret = true; |
| 3545 | out: |
| 3546 | kfree(bss_ies); |
| 3547 | return ret; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3548 | } |
| 3549 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3550 | static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata, |
| 3551 | struct ieee80211_mgmt *mgmt, |
| 3552 | size_t len) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3553 | { |
| 3554 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3555 | struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; |
| 3556 | u16 capab_info, status_code, aid; |
| 3557 | struct ieee802_11_elems elems; |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 3558 | int ac, uapsd_queues = -1; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3559 | u8 *pos; |
| 3560 | bool reassoc; |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3561 | struct cfg80211_bss *bss; |
Emmanuel Grumbach | d0d1a12 | 2015-03-16 23:23:36 +0200 | [diff] [blame] | 3562 | struct ieee80211_event event = { |
| 3563 | .type = MLME_EVENT, |
| 3564 | .u.mlme.data = ASSOC_EVENT, |
| 3565 | }; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3566 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3567 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3568 | |
| 3569 | if (!assoc_data) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3570 | return; |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 3571 | if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid)) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3572 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3573 | |
| 3574 | /* |
| 3575 | * AssocResp and ReassocResp have identical structure, so process both |
| 3576 | * of them in this function. |
| 3577 | */ |
| 3578 | |
| 3579 | if (len < 24 + 6) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3580 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3581 | |
Simon Dinkin | 7a7d3e4 | 2017-08-31 13:09:36 +0300 | [diff] [blame] | 3582 | reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3583 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); |
| 3584 | status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); |
| 3585 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); |
| 3586 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3587 | sdata_info(sdata, |
| 3588 | "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n", |
| 3589 | reassoc ? "Rea" : "A", mgmt->sa, |
| 3590 | capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14)))); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3591 | |
Jouni Malinen | 39404fe | 2016-10-27 00:42:05 +0300 | [diff] [blame] | 3592 | if (assoc_data->fils_kek_len && |
| 3593 | fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0) |
| 3594 | return; |
| 3595 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3596 | pos = mgmt->u.assoc_resp.variable; |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3597 | ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems, |
| 3598 | mgmt->bssid, assoc_data->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3599 | |
| 3600 | if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY && |
Johannes Berg | 79ba1d8 | 2013-03-27 14:38:07 +0100 | [diff] [blame] | 3601 | elems.timeout_int && |
| 3602 | elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3603 | u32 tu, ms; |
Johannes Berg | 79ba1d8 | 2013-03-27 14:38:07 +0100 | [diff] [blame] | 3604 | tu = le32_to_cpu(elems.timeout_int->value); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3605 | ms = tu * 1024 / 1000; |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3606 | sdata_info(sdata, |
| 3607 | "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n", |
| 3608 | mgmt->sa, tu, ms); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3609 | assoc_data->timeout = jiffies + msecs_to_jiffies(ms); |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 3610 | assoc_data->timeout_started = true; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3611 | if (ms > IEEE80211_ASSOC_TIMEOUT) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3612 | run_again(sdata, assoc_data->timeout); |
| 3613 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3614 | } |
| 3615 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3616 | bss = assoc_data->bss; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3617 | |
| 3618 | if (status_code != WLAN_STATUS_SUCCESS) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3619 | sdata_info(sdata, "%pM denied association (code=%d)\n", |
| 3620 | mgmt->sa, status_code); |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 3621 | ieee80211_destroy_assoc_data(sdata, false, false); |
Emmanuel Grumbach | d0d1a12 | 2015-03-16 23:23:36 +0200 | [diff] [blame] | 3622 | event.u.mlme.status = MLME_DENIED; |
| 3623 | event.u.mlme.reason = status_code; |
| 3624 | drv_event_callback(sdata->local, sdata, &event); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3625 | } else { |
Johannes Berg | f61d788 | 2019-10-28 12:52:42 +0100 | [diff] [blame] | 3626 | if (!ieee80211_assoc_success(sdata, bss, mgmt, len, &elems)) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3627 | /* oops -- internal error -- send timeout for now */ |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 3628 | ieee80211_destroy_assoc_data(sdata, false, false); |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 3629 | cfg80211_assoc_timeout(sdata->dev, bss); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3630 | return; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3631 | } |
Emmanuel Grumbach | d0d1a12 | 2015-03-16 23:23:36 +0200 | [diff] [blame] | 3632 | event.u.mlme.status = MLME_SUCCESS; |
| 3633 | drv_event_callback(sdata->local, sdata, &event); |
John W. Linville | 635d999 | 2012-07-09 16:34:34 -0400 | [diff] [blame] | 3634 | sdata_info(sdata, "associated\n"); |
Johannes Berg | 79ebfb8 | 2012-02-20 14:19:58 +0100 | [diff] [blame] | 3635 | |
| 3636 | /* |
| 3637 | * destroy assoc_data afterwards, as otherwise an idle |
| 3638 | * recalc after assoc_data is NULL but before associated |
| 3639 | * is set can cause the interface to go idle |
| 3640 | */ |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 3641 | ieee80211_destroy_assoc_data(sdata, true, false); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 3642 | |
| 3643 | /* get uapsd queues configuration */ |
| 3644 | uapsd_queues = 0; |
| 3645 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) |
| 3646 | if (sdata->tx_conf[ac].uapsd) |
Emmanuel Grumbach | f438ceb | 2016-10-18 23:12:12 +0300 | [diff] [blame] | 3647 | uapsd_queues |= ieee80211_ac_to_qos_mask[ac]; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3648 | } |
| 3649 | |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 3650 | cfg80211_rx_assoc_resp(sdata->dev, bss, (u8 *)mgmt, len, uapsd_queues, |
| 3651 | ifmgd->assoc_req_ies, ifmgd->assoc_req_ies_len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3652 | } |
Johannes Berg | 8e3c1b7 | 2012-12-10 13:44:19 +0100 | [diff] [blame] | 3653 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3654 | static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 8e3c1b7 | 2012-12-10 13:44:19 +0100 | [diff] [blame] | 3655 | struct ieee80211_mgmt *mgmt, size_t len, |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3656 | struct ieee80211_rx_status *rx_status) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3657 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3658 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 3659 | struct ieee80211_bss *bss; |
Johannes Berg | fab7d4a | 2008-03-16 18:42:44 +0100 | [diff] [blame] | 3660 | struct ieee80211_channel *channel; |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 3661 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3662 | sdata_assert_lock(sdata); |
Johannes Berg | b4f286a1 | 2013-03-26 14:13:58 +0100 | [diff] [blame] | 3663 | |
Emmanuel Grumbach | 3afc216 | 2014-03-04 16:50:13 +0200 | [diff] [blame] | 3664 | channel = ieee80211_get_channel(local->hw.wiphy, rx_status->freq); |
| 3665 | if (!channel) |
Johannes Berg | 5bda617 | 2008-09-08 11:05:10 +0200 | [diff] [blame] | 3666 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3667 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3668 | bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel); |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 3669 | if (bss) { |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 3670 | sdata->vif.bss_conf.beacon_rate = bss->beacon_rate; |
Johannes Berg | d2722f8 | 2014-03-04 11:43:28 +0100 | [diff] [blame] | 3671 | ieee80211_rx_bss_put(local, bss); |
Alexander Bondar | 817cee7 | 2013-05-19 14:23:57 +0300 | [diff] [blame] | 3672 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3673 | } |
| 3674 | |
| 3675 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3676 | 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] | 3677 | struct sk_buff *skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3678 | { |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3679 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 3680 | struct ieee80211_if_managed *ifmgd; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3681 | struct ieee80211_rx_status *rx_status = (void *) skb->cb; |
Andrei Otcheretianski | 85b27ef | 2020-01-31 13:12:50 +0200 | [diff] [blame] | 3682 | struct ieee80211_channel *channel; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3683 | size_t baselen, len = skb->len; |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 3684 | |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 3685 | ifmgd = &sdata->u.mgd; |
| 3686 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 3687 | sdata_assert_lock(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3688 | |
Andrei Otcheretianski | 85b27ef | 2020-01-31 13:12:50 +0200 | [diff] [blame] | 3689 | /* |
| 3690 | * According to Draft P802.11ax D6.0 clause 26.17.2.3.2: |
| 3691 | * "If a 6 GHz AP receives a Probe Request frame and responds with |
| 3692 | * a Probe Response frame [..], the Address 1 field of the Probe |
| 3693 | * Response frame shall be set to the broadcast address [..]" |
| 3694 | * So, on 6GHz band we should also accept broadcast responses. |
| 3695 | */ |
| 3696 | channel = ieee80211_get_channel(sdata->local->hw.wiphy, |
| 3697 | rx_status->freq); |
| 3698 | if (!channel) |
| 3699 | return; |
| 3700 | |
| 3701 | if (!ether_addr_equal(mgmt->da, sdata->vif.addr) && |
| 3702 | (channel->band != NL80211_BAND_6GHZ || |
| 3703 | !is_broadcast_ether_addr(mgmt->da))) |
Tomas Winkler | 8e7cdbb | 2008-08-03 14:32:01 +0300 | [diff] [blame] | 3704 | return; /* ignore ProbeResp to foreign address */ |
| 3705 | |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 3706 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; |
| 3707 | if (baselen > len) |
| 3708 | return; |
| 3709 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3710 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status); |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 3711 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3712 | if (ifmgd->associated && |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 3713 | ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 3714 | ieee80211_reset_ap_probe(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3715 | } |
| 3716 | |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 3717 | /* |
| 3718 | * This is the canonical list of information elements we care about, |
| 3719 | * 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] | 3720 | * (00:50:F2) vendor IE which is used for WMM which we need to track, |
| 3721 | * as well as the DTPC IE (part of the Cisco OUI) used for signaling |
| 3722 | * changes to requested client power. |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 3723 | * |
| 3724 | * We implement beacon filtering in software since that means we can |
| 3725 | * avoid processing the frame here and in cfg80211, and userspace |
| 3726 | * will not be able to tell whether the hardware supports it or not. |
| 3727 | * |
| 3728 | * XXX: This list needs to be dynamic -- userspace needs to be able to |
| 3729 | * add items it requires. It also needs to be able to tell us to |
| 3730 | * look out for other vendor IEs. |
| 3731 | */ |
| 3732 | static const u64 care_about_ies = |
Johannes Berg | 1d4df3a | 2009-04-22 11:25:43 +0200 | [diff] [blame] | 3733 | (1ULL << WLAN_EID_COUNTRY) | |
| 3734 | (1ULL << WLAN_EID_ERP_INFO) | |
| 3735 | (1ULL << WLAN_EID_CHANNEL_SWITCH) | |
| 3736 | (1ULL << WLAN_EID_PWR_CONSTRAINT) | |
| 3737 | (1ULL << WLAN_EID_HT_CAPABILITY) | |
Johannes Berg | 70a3fd6 | 2015-03-12 08:53:29 +0200 | [diff] [blame] | 3738 | (1ULL << WLAN_EID_HT_OPERATION) | |
| 3739 | (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN); |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 3740 | |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3741 | static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data *sdata, |
| 3742 | struct ieee80211_if_managed *ifmgd, |
| 3743 | struct ieee80211_bss_conf *bss_conf, |
| 3744 | struct ieee80211_local *local, |
| 3745 | struct ieee80211_rx_status *rx_status) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3746 | { |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3747 | /* Track average RSSI from the Beacon frames of the current AP */ |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3748 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3749 | if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) { |
| 3750 | ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE; |
Johannes Berg | 338c17a | 2015-08-28 10:52:54 +0200 | [diff] [blame] | 3751 | ewma_beacon_signal_init(&ifmgd->ave_beacon_signal); |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3752 | ifmgd->last_cqm_event_signal = 0; |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 3753 | ifmgd->count_beacon_signal = 1; |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3754 | ifmgd->last_ave_beacon_signal = 0; |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3755 | } else { |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 3756 | ifmgd->count_beacon_signal++; |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3757 | } |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3758 | |
Johannes Berg | 338c17a | 2015-08-28 10:52:54 +0200 | [diff] [blame] | 3759 | ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal); |
| 3760 | |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3761 | if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold && |
| 3762 | ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) { |
Johannes Berg | 338c17a | 2015-08-28 10:52:54 +0200 | [diff] [blame] | 3763 | int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal); |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3764 | int last_sig = ifmgd->last_ave_beacon_signal; |
Emmanuel Grumbach | a818292 | 2015-03-16 23:23:34 +0200 | [diff] [blame] | 3765 | struct ieee80211_event event = { |
| 3766 | .type = RSSI_EVENT, |
| 3767 | }; |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3768 | |
| 3769 | /* |
| 3770 | * if signal crosses either of the boundaries, invoke callback |
| 3771 | * with appropriate parameters |
| 3772 | */ |
| 3773 | if (sig > ifmgd->rssi_max_thold && |
| 3774 | (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) { |
| 3775 | ifmgd->last_ave_beacon_signal = sig; |
Emmanuel Grumbach | a818292 | 2015-03-16 23:23:34 +0200 | [diff] [blame] | 3776 | event.u.rssi.data = RSSI_EVENT_HIGH; |
| 3777 | drv_event_callback(local, sdata, &event); |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3778 | } else if (sig < ifmgd->rssi_min_thold && |
| 3779 | (last_sig >= ifmgd->rssi_max_thold || |
| 3780 | last_sig == 0)) { |
| 3781 | ifmgd->last_ave_beacon_signal = sig; |
Emmanuel Grumbach | a818292 | 2015-03-16 23:23:34 +0200 | [diff] [blame] | 3782 | event.u.rssi.data = RSSI_EVENT_LOW; |
| 3783 | drv_event_callback(local, sdata, &event); |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 3784 | } |
| 3785 | } |
| 3786 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3787 | if (bss_conf->cqm_rssi_thold && |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 3788 | ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT && |
Johannes Berg | ea08635 | 2012-01-19 09:29:58 +0100 | [diff] [blame] | 3789 | !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) { |
Johannes Berg | 338c17a | 2015-08-28 10:52:54 +0200 | [diff] [blame] | 3790 | int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal); |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3791 | int last_event = ifmgd->last_cqm_event_signal; |
| 3792 | int thold = bss_conf->cqm_rssi_thold; |
| 3793 | int hyst = bss_conf->cqm_rssi_hyst; |
Johannes Berg | 338c17a | 2015-08-28 10:52:54 +0200 | [diff] [blame] | 3794 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3795 | if (sig < thold && |
| 3796 | (last_event == 0 || sig < last_event - hyst)) { |
| 3797 | ifmgd->last_cqm_event_signal = sig; |
| 3798 | ieee80211_cqm_rssi_notify( |
| 3799 | &sdata->vif, |
| 3800 | NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW, |
Andrzej Zaborowski | 769f07d | 2017-01-25 12:43:40 +0100 | [diff] [blame] | 3801 | sig, GFP_KERNEL); |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3802 | } else if (sig > thold && |
| 3803 | (last_event == 0 || sig > last_event + hyst)) { |
| 3804 | ifmgd->last_cqm_event_signal = sig; |
| 3805 | ieee80211_cqm_rssi_notify( |
| 3806 | &sdata->vif, |
| 3807 | NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, |
Andrzej Zaborowski | 769f07d | 2017-01-25 12:43:40 +0100 | [diff] [blame] | 3808 | sig, GFP_KERNEL); |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 3809 | } |
| 3810 | } |
| 3811 | |
Andrew Zaborowski | 2c3c5f8c | 2017-02-10 04:50:22 +0100 | [diff] [blame] | 3812 | if (bss_conf->cqm_rssi_low && |
| 3813 | ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) { |
| 3814 | int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal); |
| 3815 | int last_event = ifmgd->last_cqm_event_signal; |
| 3816 | int low = bss_conf->cqm_rssi_low; |
| 3817 | int high = bss_conf->cqm_rssi_high; |
| 3818 | |
| 3819 | if (sig < low && |
| 3820 | (last_event == 0 || last_event >= low)) { |
| 3821 | ifmgd->last_cqm_event_signal = sig; |
| 3822 | ieee80211_cqm_rssi_notify( |
| 3823 | &sdata->vif, |
| 3824 | NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW, |
| 3825 | sig, GFP_KERNEL); |
| 3826 | } else if (sig > high && |
| 3827 | (last_event == 0 || last_event <= high)) { |
| 3828 | ifmgd->last_cqm_event_signal = sig; |
| 3829 | ieee80211_cqm_rssi_notify( |
| 3830 | &sdata->vif, |
| 3831 | NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, |
| 3832 | sig, GFP_KERNEL); |
| 3833 | } |
| 3834 | } |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3835 | } |
| 3836 | |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3837 | static bool ieee80211_rx_our_beacon(const u8 *tx_bssid, |
| 3838 | struct cfg80211_bss *bss) |
| 3839 | { |
| 3840 | if (ether_addr_equal(tx_bssid, bss->bssid)) |
| 3841 | return true; |
| 3842 | if (!bss->transmitted_bss) |
| 3843 | return false; |
| 3844 | return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid); |
| 3845 | } |
| 3846 | |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3847 | static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata, |
| 3848 | struct ieee80211_mgmt *mgmt, size_t len, |
| 3849 | struct ieee80211_rx_status *rx_status) |
| 3850 | { |
| 3851 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3852 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
| 3853 | size_t baselen; |
| 3854 | struct ieee802_11_elems elems; |
| 3855 | struct ieee80211_local *local = sdata->local; |
| 3856 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 3857 | struct ieee80211_channel *chan; |
| 3858 | struct sta_info *sta; |
| 3859 | u32 changed = 0; |
| 3860 | bool erp_valid; |
| 3861 | u8 erp_value = 0; |
| 3862 | u32 ncrc; |
| 3863 | u8 *bssid; |
| 3864 | u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
| 3865 | |
| 3866 | sdata_assert_lock(sdata); |
| 3867 | |
| 3868 | /* Process beacon from the current BSS */ |
| 3869 | baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; |
| 3870 | if (baselen > len) |
| 3871 | return; |
| 3872 | |
| 3873 | rcu_read_lock(); |
| 3874 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 3875 | if (!chanctx_conf) { |
| 3876 | rcu_read_unlock(); |
| 3877 | return; |
| 3878 | } |
| 3879 | |
| 3880 | if (rx_status->freq != chanctx_conf->def.chan->center_freq) { |
| 3881 | rcu_read_unlock(); |
| 3882 | return; |
| 3883 | } |
| 3884 | chan = chanctx_conf->def.chan; |
| 3885 | rcu_read_unlock(); |
| 3886 | |
| 3887 | if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon && |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3888 | ieee80211_rx_our_beacon(mgmt->bssid, ifmgd->assoc_data->bss)) { |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3889 | ieee802_11_parse_elems(mgmt->u.beacon.variable, |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3890 | len - baselen, false, &elems, |
| 3891 | mgmt->bssid, |
| 3892 | ifmgd->assoc_data->bss->bssid); |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3893 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3894 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status); |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3895 | |
| 3896 | if (elems.dtim_period) |
| 3897 | ifmgd->dtim_period = elems.dtim_period; |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3898 | ifmgd->have_beacon = true; |
| 3899 | ifmgd->assoc_data->need_beacon = false; |
| 3900 | if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) { |
| 3901 | sdata->vif.bss_conf.sync_tsf = |
| 3902 | le64_to_cpu(mgmt->u.beacon.timestamp); |
| 3903 | sdata->vif.bss_conf.sync_device_ts = |
| 3904 | rx_status->device_timestamp; |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3905 | sdata->vif.bss_conf.sync_dtim_count = elems.dtim_count; |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3906 | } |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3907 | |
| 3908 | if (elems.mbssid_config_ie) |
| 3909 | bss_conf->profile_periodicity = |
| 3910 | elems.mbssid_config_ie->profile_periodicity; |
| 3911 | |
| 3912 | if (elems.ext_capab_len >= 11 && |
| 3913 | (elems.ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT)) |
| 3914 | bss_conf->ema_ap = true; |
| 3915 | |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3916 | /* continue assoc process */ |
| 3917 | ifmgd->assoc_data->timeout = jiffies; |
| 3918 | ifmgd->assoc_data->timeout_started = true; |
| 3919 | run_again(sdata, ifmgd->assoc_data->timeout); |
| 3920 | return; |
| 3921 | } |
| 3922 | |
| 3923 | if (!ifmgd->associated || |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 3924 | !ieee80211_rx_our_beacon(mgmt->bssid, ifmgd->associated)) |
Tosoni | 1ad22fb | 2018-03-14 16:58:34 +0000 | [diff] [blame] | 3925 | return; |
| 3926 | bssid = ifmgd->associated->bssid; |
| 3927 | |
| 3928 | if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL)) |
| 3929 | ieee80211_handle_beacon_sig(sdata, ifmgd, bss_conf, |
| 3930 | local, rx_status); |
Andrew Zaborowski | 2c3c5f8c | 2017-02-10 04:50:22 +0100 | [diff] [blame] | 3931 | |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 3932 | if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3933 | mlme_dbg_ratelimited(sdata, |
Johannes Berg | 112c31f | 2013-02-08 22:59:00 +0100 | [diff] [blame] | 3934 | "cancelling AP probe due to a received beacon\n"); |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 3935 | ieee80211_reset_ap_probe(sdata); |
Jouni Malinen | 9277818 | 2009-05-14 21:15:36 +0300 | [diff] [blame] | 3936 | } |
| 3937 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3938 | /* |
| 3939 | * Push the beacon loss detection into the future since |
| 3940 | * we are processing a beacon from the AP just now. |
| 3941 | */ |
Luis R. Rodriguez | d3a910a | 2010-09-16 15:12:32 -0400 | [diff] [blame] | 3942 | ieee80211_sta_reset_beacon_monitor(sdata); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3943 | |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 3944 | ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4); |
| 3945 | ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable, |
Johannes Berg | b2e506b | 2013-03-26 14:54:16 +0100 | [diff] [blame] | 3946 | len - baselen, false, &elems, |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 3947 | care_about_ies, ncrc, |
| 3948 | mgmt->bssid, bssid); |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 3949 | |
Johannes Berg | 90d13e8 | 2015-09-24 16:13:07 +0200 | [diff] [blame] | 3950 | if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) && |
| 3951 | ieee80211_check_tim(elems.tim, elems.tim_len, ifmgd->aid)) { |
| 3952 | if (local->hw.conf.dynamic_ps_timeout > 0) { |
| 3953 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 3954 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 3955 | ieee80211_hw_config(local, |
| 3956 | IEEE80211_CONF_CHANGE_PS); |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 3957 | } |
Johannes Berg | 076cdcb | 2015-09-24 16:14:55 +0200 | [diff] [blame] | 3958 | ieee80211_send_nullfunc(local, sdata, false); |
Johannes Berg | 90d13e8 | 2015-09-24 16:13:07 +0200 | [diff] [blame] | 3959 | } else if (!local->pspolling && sdata->u.mgd.powersave) { |
| 3960 | local->pspolling = true; |
| 3961 | |
| 3962 | /* |
| 3963 | * Here is assumed that the driver will be |
| 3964 | * able to send ps-poll frame and receive a |
| 3965 | * response even though power save mode is |
| 3966 | * enabled, but some drivers might require |
| 3967 | * to disable power save here. This needs |
| 3968 | * to be investigated. |
| 3969 | */ |
| 3970 | ieee80211_send_pspoll(local, sdata); |
Vivek Natarajan | a97b77b | 2008-12-23 18:39:02 -0800 | [diff] [blame] | 3971 | } |
| 3972 | } |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 3973 | |
Janusz.Dziedzic@tieto.com | b115b97 | 2015-10-27 08:38:40 +0100 | [diff] [blame] | 3974 | if (sdata->vif.p2p || |
| 3975 | sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) { |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 3976 | struct ieee80211_p2p_noa_attr noa = {}; |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 3977 | int ret; |
| 3978 | |
| 3979 | ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable, |
| 3980 | len - baselen, |
| 3981 | IEEE80211_P2P_ATTR_ABSENCE_NOTICE, |
Janusz Dziedzic | 934457e | 2013-03-21 15:47:55 +0100 | [diff] [blame] | 3982 | (u8 *) &noa, sizeof(noa)); |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 3983 | if (ret >= 2) { |
| 3984 | if (sdata->u.mgd.p2p_noa_index != noa.index) { |
| 3985 | /* valid noa_attr and index changed */ |
| 3986 | sdata->u.mgd.p2p_noa_index = noa.index; |
| 3987 | memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa)); |
| 3988 | changed |= BSS_CHANGED_P2P_PS; |
| 3989 | /* |
| 3990 | * make sure we update all information, the CRC |
| 3991 | * mechanism doesn't look at P2P attributes. |
| 3992 | */ |
| 3993 | ifmgd->beacon_crc_valid = false; |
| 3994 | } |
| 3995 | } else if (sdata->u.mgd.p2p_noa_index != -1) { |
| 3996 | /* noa_attr not found and we had valid noa_attr before */ |
| 3997 | sdata->u.mgd.p2p_noa_index = -1; |
| 3998 | 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] | 3999 | changed |= BSS_CHANGED_P2P_PS; |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 4000 | ifmgd->beacon_crc_valid = false; |
| 4001 | } |
| 4002 | } |
| 4003 | |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 4004 | if (ifmgd->csa_waiting_bcn) |
| 4005 | ieee80211_chswitch_post_beacon(sdata); |
| 4006 | |
Alexander Bondar | 2ecc390 | 2015-03-01 09:10:00 +0200 | [diff] [blame] | 4007 | /* |
| 4008 | * Update beacon timing and dtim count on every beacon appearance. This |
| 4009 | * will allow the driver to use the most updated values. Do it before |
| 4010 | * comparing this one with last received beacon. |
| 4011 | * IMPORTANT: These parameters would possibly be out of sync by the time |
| 4012 | * the driver will use them. The synchronized view is currently |
| 4013 | * guaranteed only in certain callbacks. |
| 4014 | */ |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 4015 | if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) { |
Alexander Bondar | 2ecc390 | 2015-03-01 09:10:00 +0200 | [diff] [blame] | 4016 | sdata->vif.bss_conf.sync_tsf = |
| 4017 | le64_to_cpu(mgmt->u.beacon.timestamp); |
| 4018 | sdata->vif.bss_conf.sync_device_ts = |
| 4019 | rx_status->device_timestamp; |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 4020 | sdata->vif.bss_conf.sync_dtim_count = elems.dtim_count; |
Alexander Bondar | 2ecc390 | 2015-03-01 09:10:00 +0200 | [diff] [blame] | 4021 | } |
| 4022 | |
Juuso Oikarinen | d8ec443 | 2010-10-01 16:02:31 +0300 | [diff] [blame] | 4023 | if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4024 | return; |
Jouni Malinen | 3019667 | 2009-05-19 17:01:43 +0300 | [diff] [blame] | 4025 | ifmgd->beacon_crc = ncrc; |
Juuso Oikarinen | d8ec443 | 2010-10-01 16:02:31 +0300 | [diff] [blame] | 4026 | ifmgd->beacon_crc_valid = true; |
Jouni Malinen | 3019667 | 2009-05-19 17:01:43 +0300 | [diff] [blame] | 4027 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 4028 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status); |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 4029 | |
Johannes Berg | d70b761 | 2013-08-23 15:48:48 +0200 | [diff] [blame] | 4030 | ieee80211_sta_process_chanswitch(sdata, rx_status->mactime, |
Luciano Coelho | 2ba4538 | 2014-10-08 09:48:35 +0300 | [diff] [blame] | 4031 | rx_status->device_timestamp, |
Johannes Berg | d70b761 | 2013-08-23 15:48:48 +0200 | [diff] [blame] | 4032 | &elems, true); |
| 4033 | |
Johannes Berg | 095d81c | 2013-10-15 12:25:07 +0200 | [diff] [blame] | 4034 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) && |
| 4035 | ieee80211_sta_wmm_params(local, sdata, elems.wmm_param, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4036 | elems.wmm_param_len, |
| 4037 | elems.mu_edca_param_set)) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 4038 | changed |= BSS_CHANGED_QOS; |
| 4039 | |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 4040 | /* |
| 4041 | * 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] | 4042 | * DTIM period (and beacon timing if desired) now. |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 4043 | */ |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 4044 | if (!ifmgd->have_beacon) { |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 4045 | /* a few bogus AP send dtim_period = 0 or no TIM IE */ |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 4046 | bss_conf->dtim_period = elems.dtim_period ?: 1; |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 4047 | |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 4048 | changed |= BSS_CHANGED_BEACON_INFO; |
| 4049 | ifmgd->have_beacon = true; |
Alexander Bondar | 482a9c7 | 2013-06-03 17:29:33 +0300 | [diff] [blame] | 4050 | |
| 4051 | mutex_lock(&local->iflist_mtx); |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 4052 | ieee80211_recalc_ps(local); |
Alexander Bondar | 482a9c7 | 2013-06-03 17:29:33 +0300 | [diff] [blame] | 4053 | mutex_unlock(&local->iflist_mtx); |
| 4054 | |
Alexander Bondar | ce85788 | 2013-05-06 17:17:04 +0300 | [diff] [blame] | 4055 | ieee80211_recalc_ps_vif(sdata); |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 4056 | } |
| 4057 | |
Johannes Berg | 1946bed | 2013-03-27 14:31:53 +0100 | [diff] [blame] | 4058 | if (elems.erp_info) { |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 4059 | erp_valid = true; |
| 4060 | erp_value = elems.erp_info[0]; |
| 4061 | } else { |
| 4062 | erp_valid = false; |
John W. Linville | 50c4afb | 2008-04-15 14:09:27 -0400 | [diff] [blame] | 4063 | } |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 4064 | changed |= ieee80211_handle_bss_capability(sdata, |
| 4065 | le16_to_cpu(mgmt->u.beacon.capab_info), |
| 4066 | erp_valid, erp_value); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4067 | |
Johannes Berg | 1128958 | 2013-02-07 17:36:12 +0100 | [diff] [blame] | 4068 | mutex_lock(&local->sta_mtx); |
Johannes Berg | bee7f586 | 2013-02-07 22:24:55 +0100 | [diff] [blame] | 4069 | sta = sta_info_get(sdata, bssid); |
| 4070 | |
John Crispin | c9d3245 | 2019-05-28 13:49:47 +0200 | [diff] [blame] | 4071 | changed |= ieee80211_recalc_twt_req(sdata, sta, &elems); |
| 4072 | |
Eliad Peller | 53b954e | 2014-07-24 11:20:05 +0300 | [diff] [blame] | 4073 | if (ieee80211_config_bw(sdata, sta, |
| 4074 | elems.ht_cap_elem, elems.ht_operation, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4075 | elems.vht_operation, elems.he_operation, |
| 4076 | bssid, &changed)) { |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 4077 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | 89f774e | 2016-01-25 15:46:36 +0200 | [diff] [blame] | 4078 | sdata_info(sdata, |
| 4079 | "failed to follow AP %pM bandwidth change, disconnect\n", |
| 4080 | bssid); |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 4081 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
| 4082 | WLAN_REASON_DEAUTH_LEAVING, |
| 4083 | true, deauth_buf); |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 4084 | ieee80211_report_disconnect(sdata, deauth_buf, |
| 4085 | sizeof(deauth_buf), true, |
| 4086 | WLAN_REASON_DEAUTH_LEAVING); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4087 | return; |
Johannes Berg | 30eb1dc | 2013-02-08 15:12:14 +0100 | [diff] [blame] | 4088 | } |
Johannes Berg | bee7f586 | 2013-02-07 22:24:55 +0100 | [diff] [blame] | 4089 | |
| 4090 | if (sta && elems.opmode_notif) |
| 4091 | ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif, |
Eyal Shapira | cf1e05c | 2015-12-08 16:04:36 +0200 | [diff] [blame] | 4092 | rx_status->band); |
Johannes Berg | 1128958 | 2013-02-07 17:36:12 +0100 | [diff] [blame] | 4093 | mutex_unlock(&local->sta_mtx); |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 4094 | |
Steinar H. Gunderson | 24a4e40 | 2014-09-03 06:22:10 -0700 | [diff] [blame] | 4095 | changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt, |
| 4096 | elems.country_elem, |
| 4097 | elems.country_elem_len, |
Steinar H. Gunderson | c8d6591 | 2014-09-03 06:48:37 -0700 | [diff] [blame] | 4098 | elems.pwr_constr_elem, |
| 4099 | elems.cisco_dtpc_elem); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 4100 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4101 | ieee80211_bss_info_change_notify(sdata, changed); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4102 | } |
| 4103 | |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 4104 | void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, |
| 4105 | struct sk_buff *skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4106 | { |
| 4107 | struct ieee80211_rx_status *rx_status; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4108 | struct ieee80211_mgmt *mgmt; |
| 4109 | u16 fc; |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 4110 | struct ieee802_11_elems elems; |
| 4111 | int ies_len; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4112 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4113 | rx_status = (struct ieee80211_rx_status *) skb->cb; |
| 4114 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 4115 | fc = le16_to_cpu(mgmt->frame_control); |
| 4116 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4117 | sdata_lock(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 4118 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4119 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 4120 | case IEEE80211_STYPE_BEACON: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4121 | ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4122 | break; |
| 4123 | case IEEE80211_STYPE_PROBE_RESP: |
| 4124 | ieee80211_rx_mgmt_probe_resp(sdata, skb); |
| 4125 | break; |
| 4126 | case IEEE80211_STYPE_AUTH: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4127 | ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4128 | break; |
| 4129 | case IEEE80211_STYPE_DEAUTH: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4130 | ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4131 | break; |
| 4132 | case IEEE80211_STYPE_DISASSOC: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4133 | ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4134 | break; |
| 4135 | case IEEE80211_STYPE_ASSOC_RESP: |
| 4136 | case IEEE80211_STYPE_REASSOC_RESP: |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4137 | ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4138 | break; |
| 4139 | case IEEE80211_STYPE_ACTION: |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 4140 | if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) { |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 4141 | ies_len = skb->len - |
| 4142 | offsetof(struct ieee80211_mgmt, |
| 4143 | u.action.u.chan_switch.variable); |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 4144 | |
| 4145 | if (ies_len < 0) |
| 4146 | break; |
| 4147 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 4148 | /* CSA IE cannot be overridden, no need for BSSID */ |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 4149 | ieee802_11_parse_elems( |
| 4150 | mgmt->u.action.u.chan_switch.variable, |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 4151 | ies_len, true, &elems, mgmt->bssid, NULL); |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 4152 | |
| 4153 | if (elems.parse_error) |
| 4154 | break; |
| 4155 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4156 | ieee80211_sta_process_chanswitch(sdata, |
Luciano Coelho | 2ba4538 | 2014-10-08 09:48:35 +0300 | [diff] [blame] | 4157 | rx_status->mactime, |
| 4158 | rx_status->device_timestamp, |
| 4159 | &elems, false); |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 4160 | } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) { |
| 4161 | ies_len = skb->len - |
| 4162 | offsetof(struct ieee80211_mgmt, |
| 4163 | u.action.u.ext_chan_switch.variable); |
| 4164 | |
| 4165 | if (ies_len < 0) |
| 4166 | break; |
| 4167 | |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 4168 | /* |
| 4169 | * extended CSA IE can't be overridden, no need for |
| 4170 | * BSSID |
| 4171 | */ |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 4172 | ieee802_11_parse_elems( |
| 4173 | mgmt->u.action.u.ext_chan_switch.variable, |
Sara Sharon | 4abb52a | 2019-01-16 12:14:41 +0200 | [diff] [blame] | 4174 | ies_len, true, &elems, mgmt->bssid, NULL); |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 4175 | |
| 4176 | if (elems.parse_error) |
| 4177 | break; |
| 4178 | |
| 4179 | /* for the handling code pretend this was also an IE */ |
| 4180 | elems.ext_chansw_ie = |
| 4181 | &mgmt->u.action.u.ext_chan_switch.data; |
| 4182 | |
| 4183 | ieee80211_sta_process_chanswitch(sdata, |
Luciano Coelho | 2ba4538 | 2014-10-08 09:48:35 +0300 | [diff] [blame] | 4184 | rx_status->mactime, |
| 4185 | rx_status->device_timestamp, |
| 4186 | &elems, false); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 4187 | } |
Johannes Berg | 37799e5 | 2013-03-26 14:02:26 +0100 | [diff] [blame] | 4188 | break; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 4189 | } |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4190 | sdata_unlock(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4191 | } |
| 4192 | |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4193 | static void ieee80211_sta_timer(struct timer_list *t) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4194 | { |
| 4195 | struct ieee80211_sub_if_data *sdata = |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4196 | from_timer(sdata, t, u.mgd.timer); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4197 | |
Stanislaw Gruszka | 9b7d72c | 2013-02-28 10:55:27 +0100 | [diff] [blame] | 4198 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4199 | } |
| 4200 | |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4201 | static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 6b684db | 2013-01-29 11:35:29 +0100 | [diff] [blame] | 4202 | u8 *bssid, u8 reason, bool tx) |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4203 | { |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 4204 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4205 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 4206 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason, |
Johannes Berg | 6b684db | 2013-01-29 11:35:29 +0100 | [diff] [blame] | 4207 | tx, frame_buf); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 4208 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 4209 | ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true, |
| 4210 | reason); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4211 | } |
| 4212 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4213 | static int ieee80211_auth(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4214 | { |
| 4215 | struct ieee80211_local *local = sdata->local; |
| 4216 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 4217 | struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data; |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4218 | u32 tx_flags = 0; |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4219 | u16 trans = 1; |
| 4220 | u16 status = 0; |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 4221 | u16 prepare_tx_duration = 0; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4222 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4223 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4224 | |
| 4225 | if (WARN_ON_ONCE(!auth_data)) |
| 4226 | return -EINVAL; |
| 4227 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4228 | auth_data->tries++; |
| 4229 | |
| 4230 | if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4231 | sdata_info(sdata, "authentication with %pM timed out\n", |
| 4232 | auth_data->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4233 | |
| 4234 | /* |
| 4235 | * Most likely AP is not in the range so remove the |
| 4236 | * bss struct for that AP. |
| 4237 | */ |
| 4238 | cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss); |
| 4239 | |
| 4240 | return -ETIMEDOUT; |
| 4241 | } |
| 4242 | |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 4243 | if (auth_data->algorithm == WLAN_AUTH_SAE) |
| 4244 | prepare_tx_duration = |
| 4245 | jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE); |
| 4246 | |
| 4247 | drv_mgd_prepare_tx(local, sdata, prepare_tx_duration); |
Johannes Berg | a1845fc | 2012-06-27 13:18:36 +0200 | [diff] [blame] | 4248 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4249 | sdata_info(sdata, "send auth to %pM (try %d/%d)\n", |
| 4250 | auth_data->bss->bssid, auth_data->tries, |
| 4251 | IEEE80211_AUTH_MAX_TRIES); |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 4252 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4253 | auth_data->expected_transaction = 2; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4254 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4255 | if (auth_data->algorithm == WLAN_AUTH_SAE) { |
| 4256 | trans = auth_data->sae_trans; |
| 4257 | status = auth_data->sae_status; |
| 4258 | auth_data->expected_transaction = trans; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4259 | } |
| 4260 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4261 | if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
| 4262 | tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS | |
| 4263 | IEEE80211_TX_INTFL_MLME_CONN_TX; |
| 4264 | |
| 4265 | ieee80211_send_auth(sdata, trans, auth_data->algorithm, status, |
| 4266 | auth_data->data, auth_data->data_len, |
| 4267 | auth_data->bss->bssid, |
| 4268 | auth_data->bss->bssid, NULL, 0, 0, |
| 4269 | tx_flags); |
| 4270 | |
Stanislaw Gruszka | 6211dd1 | 2013-05-17 13:43:04 +0200 | [diff] [blame] | 4271 | if (tx_flags == 0) { |
Ilan Peer | 407879b | 2018-04-20 13:49:20 +0300 | [diff] [blame] | 4272 | if (auth_data->algorithm == WLAN_AUTH_SAE) |
| 4273 | auth_data->timeout = jiffies + |
| 4274 | IEEE80211_AUTH_TIMEOUT_SAE; |
| 4275 | else |
| 4276 | auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT; |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4277 | } else { |
Johannes Berg | cb236d2 | 2013-07-29 23:07:43 +0200 | [diff] [blame] | 4278 | auth_data->timeout = |
| 4279 | round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG); |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4280 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4281 | |
Ilan Peer | 407879b | 2018-04-20 13:49:20 +0300 | [diff] [blame] | 4282 | auth_data->timeout_started = true; |
| 4283 | run_again(sdata, auth_data->timeout); |
| 4284 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4285 | return 0; |
| 4286 | } |
| 4287 | |
| 4288 | static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata) |
| 4289 | { |
| 4290 | struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data; |
| 4291 | struct ieee80211_local *local = sdata->local; |
| 4292 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4293 | sdata_assert_lock(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4294 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4295 | assoc_data->tries++; |
| 4296 | if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4297 | sdata_info(sdata, "association with %pM timed out\n", |
| 4298 | assoc_data->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4299 | |
| 4300 | /* |
| 4301 | * Most likely AP is not in the range so remove the |
| 4302 | * bss struct for that AP. |
| 4303 | */ |
| 4304 | cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss); |
| 4305 | |
| 4306 | return -ETIMEDOUT; |
| 4307 | } |
| 4308 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4309 | sdata_info(sdata, "associate with %pM (try %d/%d)\n", |
| 4310 | assoc_data->bss->bssid, assoc_data->tries, |
| 4311 | IEEE80211_ASSOC_MAX_TRIES); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4312 | ieee80211_send_assoc(sdata); |
| 4313 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 4314 | if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) { |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4315 | assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT; |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4316 | assoc_data->timeout_started = true; |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4317 | run_again(sdata, assoc_data->timeout); |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4318 | } else { |
Johannes Berg | cb236d2 | 2013-07-29 23:07:43 +0200 | [diff] [blame] | 4319 | assoc_data->timeout = |
| 4320 | round_jiffies_up(jiffies + |
| 4321 | IEEE80211_ASSOC_TIMEOUT_LONG); |
| 4322 | assoc_data->timeout_started = true; |
| 4323 | run_again(sdata, assoc_data->timeout); |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4324 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4325 | |
| 4326 | return 0; |
| 4327 | } |
| 4328 | |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4329 | void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata, |
| 4330 | __le16 fc, bool acked) |
| 4331 | { |
| 4332 | struct ieee80211_local *local = sdata->local; |
| 4333 | |
| 4334 | sdata->u.mgd.status_fc = fc; |
| 4335 | sdata->u.mgd.status_acked = acked; |
| 4336 | sdata->u.mgd.status_received = true; |
| 4337 | |
| 4338 | ieee80211_queue_work(&local->hw, &sdata->work); |
| 4339 | } |
| 4340 | |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 4341 | void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 4342 | { |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 4343 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 4344 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 4345 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4346 | sdata_lock(sdata); |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 4347 | |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4348 | if (ifmgd->status_received) { |
| 4349 | __le16 fc = ifmgd->status_fc; |
| 4350 | bool status_acked = ifmgd->status_acked; |
| 4351 | |
| 4352 | ifmgd->status_received = false; |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4353 | if (ifmgd->auth_data && ieee80211_is_auth(fc)) { |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4354 | if (status_acked) { |
Ilan Peer | 407879b | 2018-04-20 13:49:20 +0300 | [diff] [blame] | 4355 | if (ifmgd->auth_data->algorithm == |
| 4356 | WLAN_AUTH_SAE) |
| 4357 | ifmgd->auth_data->timeout = |
| 4358 | jiffies + |
| 4359 | IEEE80211_AUTH_TIMEOUT_SAE; |
| 4360 | else |
| 4361 | ifmgd->auth_data->timeout = |
| 4362 | jiffies + |
| 4363 | IEEE80211_AUTH_TIMEOUT_SHORT; |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4364 | run_again(sdata, ifmgd->auth_data->timeout); |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4365 | } else { |
| 4366 | ifmgd->auth_data->timeout = jiffies - 1; |
| 4367 | } |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4368 | ifmgd->auth_data->timeout_started = true; |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4369 | } else if (ifmgd->assoc_data && |
| 4370 | (ieee80211_is_assoc_req(fc) || |
| 4371 | ieee80211_is_reassoc_req(fc))) { |
| 4372 | if (status_acked) { |
| 4373 | ifmgd->assoc_data->timeout = |
| 4374 | jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT; |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4375 | run_again(sdata, ifmgd->assoc_data->timeout); |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4376 | } else { |
| 4377 | ifmgd->assoc_data->timeout = jiffies - 1; |
| 4378 | } |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4379 | ifmgd->assoc_data->timeout_started = true; |
Johannes Berg | 1672c0e3 | 2013-01-29 15:02:27 +0100 | [diff] [blame] | 4380 | } |
| 4381 | } |
| 4382 | |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4383 | if (ifmgd->auth_data && ifmgd->auth_data->timeout_started && |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4384 | time_after(jiffies, ifmgd->auth_data->timeout)) { |
| 4385 | if (ifmgd->auth_data->done) { |
| 4386 | /* |
| 4387 | * ok ... we waited for assoc but userspace didn't, |
| 4388 | * so let's just kill the auth data |
| 4389 | */ |
| 4390 | ieee80211_destroy_auth_data(sdata, false); |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 4391 | } else if (ieee80211_auth(sdata)) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4392 | u8 bssid[ETH_ALEN]; |
Emmanuel Grumbach | a940909 | 2015-03-16 23:23:35 +0200 | [diff] [blame] | 4393 | struct ieee80211_event event = { |
| 4394 | .type = MLME_EVENT, |
| 4395 | .u.mlme.data = AUTH_EVENT, |
| 4396 | .u.mlme.status = MLME_TIMEOUT, |
| 4397 | }; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4398 | |
| 4399 | memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN); |
| 4400 | |
| 4401 | ieee80211_destroy_auth_data(sdata, false); |
| 4402 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 4403 | cfg80211_auth_timeout(sdata->dev, bssid); |
Emmanuel Grumbach | a940909 | 2015-03-16 23:23:35 +0200 | [diff] [blame] | 4404 | drv_event_callback(sdata->local, sdata, &event); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4405 | } |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4406 | } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4407 | run_again(sdata, ifmgd->auth_data->timeout); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4408 | |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4409 | if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started && |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4410 | time_after(jiffies, ifmgd->assoc_data->timeout)) { |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 4411 | if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) || |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4412 | ieee80211_do_assoc(sdata)) { |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 4413 | struct cfg80211_bss *bss = ifmgd->assoc_data->bss; |
Emmanuel Grumbach | d0d1a12 | 2015-03-16 23:23:36 +0200 | [diff] [blame] | 4414 | struct ieee80211_event event = { |
| 4415 | .type = MLME_EVENT, |
| 4416 | .u.mlme.data = ASSOC_EVENT, |
| 4417 | .u.mlme.status = MLME_TIMEOUT, |
| 4418 | }; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4419 | |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 4420 | ieee80211_destroy_assoc_data(sdata, false, false); |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 4421 | cfg80211_assoc_timeout(sdata->dev, bss); |
Emmanuel Grumbach | d0d1a12 | 2015-03-16 23:23:36 +0200 | [diff] [blame] | 4422 | drv_event_callback(sdata->local, sdata, &event); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4423 | } |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 4424 | } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4425 | run_again(sdata, ifmgd->assoc_data->timeout); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 4426 | |
Stanislaw Gruszka | 392b9ff | 2013-08-27 11:36:35 +0200 | [diff] [blame] | 4427 | if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL && |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4428 | ifmgd->associated) { |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 4429 | u8 bssid[ETH_ALEN]; |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 4430 | int max_tries; |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 4431 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 4432 | memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 4433 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 4434 | if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 4435 | max_tries = max_nullfunc_tries; |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 4436 | else |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 4437 | max_tries = max_probe_tries; |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 4438 | |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 4439 | /* ACK received for nullfunc probing frame */ |
| 4440 | if (!ifmgd->probe_send_count) |
| 4441 | ieee80211_reset_ap_probe(sdata); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4442 | else if (ifmgd->nullfunc_failed) { |
| 4443 | if (ifmgd->probe_send_count < max_tries) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4444 | mlme_dbg(sdata, |
| 4445 | "No ack for nullfunc frame to AP %pM, try %d/%i\n", |
| 4446 | bssid, ifmgd->probe_send_count, |
| 4447 | max_tries); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4448 | ieee80211_mgd_probe_ap_send(sdata); |
| 4449 | } else { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4450 | mlme_dbg(sdata, |
| 4451 | "No ack for nullfunc frame to AP %pM, disconnecting.\n", |
| 4452 | bssid); |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 4453 | ieee80211_sta_connection_lost(sdata, bssid, |
Johannes Berg | 6b684db | 2013-01-29 11:35:29 +0100 | [diff] [blame] | 4454 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, |
| 4455 | false); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4456 | } |
| 4457 | } else if (time_is_after_jiffies(ifmgd->probe_timeout)) |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4458 | run_again(sdata, ifmgd->probe_timeout); |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 4459 | else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4460 | mlme_dbg(sdata, |
| 4461 | "Failed to send nullfunc to AP %pM after %dms, disconnecting\n", |
| 4462 | bssid, probe_wait_ms); |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 4463 | ieee80211_sta_connection_lost(sdata, bssid, |
Johannes Berg | 6b684db | 2013-01-29 11:35:29 +0100 | [diff] [blame] | 4464 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4465 | } else if (ifmgd->probe_send_count < max_tries) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4466 | mlme_dbg(sdata, |
| 4467 | "No probe response from AP %pM after %dms, try %d/%i\n", |
| 4468 | bssid, probe_wait_ms, |
| 4469 | ifmgd->probe_send_count, max_tries); |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 4470 | ieee80211_mgd_probe_ap_send(sdata); |
| 4471 | } else { |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4472 | /* |
| 4473 | * We actually lost the connection ... or did we? |
| 4474 | * Let's make sure! |
| 4475 | */ |
Johannes Berg | 89f774e | 2016-01-25 15:46:36 +0200 | [diff] [blame] | 4476 | mlme_dbg(sdata, |
| 4477 | "No probe response from AP %pM after %dms, disconnecting.\n", |
| 4478 | bssid, probe_wait_ms); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 4479 | |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 4480 | ieee80211_sta_connection_lost(sdata, bssid, |
Johannes Berg | 6b684db | 2013-01-29 11:35:29 +0100 | [diff] [blame] | 4481 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4482 | } |
| 4483 | } |
| 4484 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4485 | sdata_unlock(sdata); |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 4486 | } |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 4487 | |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4488 | static void ieee80211_sta_bcn_mon_timer(struct timer_list *t) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4489 | { |
| 4490 | struct ieee80211_sub_if_data *sdata = |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4491 | from_timer(sdata, t, u.mgd.bcn_mon_timer); |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 4492 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4493 | |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 4494 | if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn) |
Michal Kazior | e5593f5 | 2014-04-09 15:45:36 +0200 | [diff] [blame] | 4495 | return; |
| 4496 | |
Johannes Berg | 682bd38 | 2013-01-29 13:13:50 +0100 | [diff] [blame] | 4497 | sdata->u.mgd.connection_loss = false; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 4498 | ieee80211_queue_work(&sdata->local->hw, |
| 4499 | &sdata->u.mgd.beacon_connection_loss_work); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4500 | } |
| 4501 | |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4502 | static void ieee80211_sta_conn_mon_timer(struct timer_list *t) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4503 | { |
| 4504 | struct ieee80211_sub_if_data *sdata = |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4505 | from_timer(sdata, t, u.mgd.conn_mon_timer); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4506 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 4507 | struct ieee80211_local *local = sdata->local; |
| 4508 | |
Luciano Coelho | 0c21e63 | 2014-10-08 09:48:39 +0300 | [diff] [blame] | 4509 | if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn) |
Michal Kazior | e5593f5 | 2014-04-09 15:45:36 +0200 | [diff] [blame] | 4510 | return; |
| 4511 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 4512 | ieee80211_queue_work(&local->hw, &ifmgd->monitor_work); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4513 | } |
| 4514 | |
| 4515 | static void ieee80211_sta_monitor_work(struct work_struct *work) |
| 4516 | { |
| 4517 | struct ieee80211_sub_if_data *sdata = |
| 4518 | container_of(work, struct ieee80211_sub_if_data, |
| 4519 | u.mgd.monitor_work); |
| 4520 | |
| 4521 | ieee80211_mgd_probe_ap(sdata, false); |
| 4522 | } |
| 4523 | |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 4524 | static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata) |
| 4525 | { |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 4526 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 4527 | __ieee80211_stop_poll(sdata); |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 4528 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4529 | /* let's probe the connection once */ |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 4530 | if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR)) |
Eliad Peller | 494f1fe | 2012-02-19 15:26:09 +0200 | [diff] [blame] | 4531 | ieee80211_queue_work(&sdata->local->hw, |
| 4532 | &sdata->u.mgd.monitor_work); |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 4533 | } |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 4534 | } |
| 4535 | |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4536 | #ifdef CONFIG_PM |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4537 | void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata) |
| 4538 | { |
| 4539 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 4540 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
| 4541 | |
| 4542 | sdata_lock(sdata); |
| 4543 | |
Emmanuel Grumbach | c52666a | 2014-05-13 12:54:09 +0300 | [diff] [blame] | 4544 | if (ifmgd->auth_data || ifmgd->assoc_data) { |
| 4545 | const u8 *bssid = ifmgd->auth_data ? |
| 4546 | ifmgd->auth_data->bss->bssid : |
| 4547 | ifmgd->assoc_data->bss->bssid; |
| 4548 | |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4549 | /* |
Emmanuel Grumbach | c52666a | 2014-05-13 12:54:09 +0300 | [diff] [blame] | 4550 | * If we are trying to authenticate / associate while suspending, |
| 4551 | * cfg80211 won't know and won't actually abort those attempts, |
| 4552 | * thus we need to do that ourselves. |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4553 | */ |
Johannes Berg | 4b08d1b | 2019-08-30 14:24:51 +0300 | [diff] [blame] | 4554 | ieee80211_send_deauth_disassoc(sdata, bssid, bssid, |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4555 | IEEE80211_STYPE_DEAUTH, |
| 4556 | WLAN_REASON_DEAUTH_LEAVING, |
| 4557 | false, frame_buf); |
Emmanuel Grumbach | c52666a | 2014-05-13 12:54:09 +0300 | [diff] [blame] | 4558 | if (ifmgd->assoc_data) |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 4559 | ieee80211_destroy_assoc_data(sdata, false, true); |
Emmanuel Grumbach | c52666a | 2014-05-13 12:54:09 +0300 | [diff] [blame] | 4560 | if (ifmgd->auth_data) |
| 4561 | ieee80211_destroy_auth_data(sdata, false); |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4562 | cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf, |
| 4563 | IEEE80211_DEAUTH_FRAME_LEN); |
| 4564 | } |
| 4565 | |
Johannes Berg | be72afe | 2015-03-01 09:10:03 +0200 | [diff] [blame] | 4566 | /* This is a bit of a hack - we should find a better and more generic |
| 4567 | * solution to this. Normally when suspending, cfg80211 will in fact |
| 4568 | * deauthenticate. However, it doesn't (and cannot) stop an ongoing |
| 4569 | * auth (not so important) or assoc (this is the problem) process. |
| 4570 | * |
| 4571 | * As a consequence, it can happen that we are in the process of both |
| 4572 | * associating and suspending, and receive an association response |
| 4573 | * after cfg80211 has checked if it needs to disconnect, but before |
| 4574 | * we actually set the flag to drop incoming frames. This will then |
| 4575 | * cause the workqueue flush to process the association response in |
| 4576 | * the suspend, resulting in a successful association just before it |
| 4577 | * tries to remove the interface from the driver, which now though |
| 4578 | * has a channel context assigned ... this results in issues. |
| 4579 | * |
| 4580 | * To work around this (for now) simply deauth here again if we're |
| 4581 | * now connected. |
| 4582 | */ |
| 4583 | if (ifmgd->associated && !sdata->local->wowlan) { |
| 4584 | u8 bssid[ETH_ALEN]; |
| 4585 | struct cfg80211_deauth_request req = { |
| 4586 | .reason_code = WLAN_REASON_DEAUTH_LEAVING, |
| 4587 | .bssid = bssid, |
| 4588 | }; |
| 4589 | |
| 4590 | memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN); |
| 4591 | ieee80211_mgd_deauth(sdata, &req); |
| 4592 | } |
| 4593 | |
Johannes Berg | 1a1cb74 | 2014-03-19 09:55:55 +0100 | [diff] [blame] | 4594 | sdata_unlock(sdata); |
| 4595 | } |
| 4596 | |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4597 | void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata) |
| 4598 | { |
| 4599 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 4600 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4601 | sdata_lock(sdata); |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4602 | if (!ifmgd->associated) { |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4603 | sdata_unlock(sdata); |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4604 | return; |
| 4605 | } |
| 4606 | |
| 4607 | if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) { |
| 4608 | sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME; |
| 4609 | mlme_dbg(sdata, "driver requested disconnect after resume\n"); |
| 4610 | ieee80211_sta_connection_lost(sdata, |
| 4611 | ifmgd->associated->bssid, |
| 4612 | WLAN_REASON_UNSPECIFIED, |
| 4613 | true); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4614 | sdata_unlock(sdata); |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4615 | return; |
| 4616 | } |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 4617 | sdata_unlock(sdata); |
Johannes Berg | b8360ab | 2013-04-29 14:57:44 +0200 | [diff] [blame] | 4618 | } |
| 4619 | #endif |
| 4620 | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 4621 | /* interface setup */ |
| 4622 | void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata) |
| 4623 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 4624 | struct ieee80211_if_managed *ifmgd; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 4625 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 4626 | ifmgd = &sdata->u.mgd; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 4627 | INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 4628 | INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 4629 | INIT_WORK(&ifmgd->beacon_connection_loss_work, |
| 4630 | ieee80211_beacon_connection_loss_work); |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 4631 | INIT_WORK(&ifmgd->csa_connection_drop_work, |
| 4632 | ieee80211_csa_connection_drop_work); |
Emmanuel Grumbach | 687da13 | 2013-10-01 16:45:43 +0300 | [diff] [blame] | 4633 | INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work); |
Arik Nemtsov | 81dd2b8 | 2014-07-17 17:14:25 +0300 | [diff] [blame] | 4634 | INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work, |
| 4635 | ieee80211_tdls_peer_del_work); |
Kees Cook | 34f11cd | 2017-10-16 16:35:49 -0700 | [diff] [blame] | 4636 | timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0); |
| 4637 | timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0); |
| 4638 | timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0); |
| 4639 | timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0); |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 4640 | INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk, |
| 4641 | ieee80211_sta_handle_tspec_ac_params_wk); |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 4642 | |
Johannes Berg | ab1faea | 2009-07-01 21:41:17 +0200 | [diff] [blame] | 4643 | ifmgd->flags = 0; |
Mohammed Shafi Shajakhan | 1478acb | 2011-12-14 19:46:08 +0530 | [diff] [blame] | 4644 | ifmgd->powersave = sdata->wdev.ps; |
Alexander Bondar | 219c386 | 2013-01-22 16:52:23 +0200 | [diff] [blame] | 4645 | ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues; |
| 4646 | ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len; |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 4647 | ifmgd->p2p_noa_index = -1; |
Johannes Berg | bbbdff9 | 2009-04-16 13:27:42 +0200 | [diff] [blame] | 4648 | |
Eliad Peller | 0d8614b | 2014-09-10 14:07:36 +0300 | [diff] [blame] | 4649 | if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS) |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 4650 | ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC; |
| 4651 | else |
| 4652 | ifmgd->req_smps = IEEE80211_SMPS_OFF; |
Liad Kaufman | 1277b4a | 2014-11-09 18:50:08 +0200 | [diff] [blame] | 4653 | |
| 4654 | /* Setup TDLS data */ |
| 4655 | spin_lock_init(&ifmgd->teardown_lock); |
| 4656 | ifmgd->teardown_skb = NULL; |
| 4657 | ifmgd->orig_teardown_skb = NULL; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 4658 | } |
| 4659 | |
| 4660 | /* scan finished notification */ |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 4661 | void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local) |
| 4662 | { |
Johannes Berg | 31ee67a | 2012-07-06 21:18:24 +0200 | [diff] [blame] | 4663 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 4664 | |
| 4665 | /* Restart STA timers */ |
| 4666 | rcu_read_lock(); |
Ben Greear | 370bd00 | 2013-03-19 17:50:50 -0700 | [diff] [blame] | 4667 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
| 4668 | if (ieee80211_sdata_running(sdata)) |
| 4669 | ieee80211_restart_sta_timer(sdata); |
| 4670 | } |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 4671 | rcu_read_unlock(); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 4672 | } |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 4673 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4674 | static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata, |
| 4675 | struct cfg80211_bss *cbss) |
| 4676 | { |
| 4677 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 4678 | const u8 *ht_cap_ie, *vht_cap_ie; |
| 4679 | const struct ieee80211_ht_cap *ht_cap; |
| 4680 | const struct ieee80211_vht_cap *vht_cap; |
| 4681 | u8 chains = 1; |
| 4682 | |
| 4683 | if (ifmgd->flags & IEEE80211_STA_DISABLE_HT) |
| 4684 | return chains; |
| 4685 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 4686 | ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY); |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4687 | if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) { |
| 4688 | ht_cap = (void *)(ht_cap_ie + 2); |
| 4689 | chains = ieee80211_mcs_to_chains(&ht_cap->mcs); |
| 4690 | /* |
| 4691 | * TODO: use "Tx Maximum Number Spatial Streams Supported" and |
| 4692 | * "Tx Unequal Modulation Supported" fields. |
| 4693 | */ |
| 4694 | } |
| 4695 | |
| 4696 | if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT) |
| 4697 | return chains; |
| 4698 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 4699 | vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY); |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4700 | if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) { |
| 4701 | u8 nss; |
| 4702 | u16 tx_mcs_map; |
| 4703 | |
| 4704 | vht_cap = (void *)(vht_cap_ie + 2); |
| 4705 | tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map); |
| 4706 | for (nss = 8; nss > 0; nss--) { |
| 4707 | if (((tx_mcs_map >> (2 * (nss - 1))) & 3) != |
| 4708 | IEEE80211_VHT_MCS_NOT_SUPPORTED) |
| 4709 | break; |
| 4710 | } |
| 4711 | /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */ |
| 4712 | chains = max(chains, nss); |
| 4713 | } |
| 4714 | |
| 4715 | return chains; |
| 4716 | } |
| 4717 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4718 | static bool |
| 4719 | ieee80211_verify_sta_he_mcs_support(struct ieee80211_supported_band *sband, |
| 4720 | const struct ieee80211_he_operation *he_op) |
| 4721 | { |
| 4722 | const struct ieee80211_sta_he_cap *sta_he_cap = |
| 4723 | ieee80211_get_he_sta_cap(sband); |
Gustavo A. R. Silva | 47aa786 | 2018-06-18 07:41:34 -0500 | [diff] [blame] | 4724 | u16 ap_min_req_set; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4725 | int i; |
| 4726 | |
| 4727 | if (!sta_he_cap || !he_op) |
| 4728 | return false; |
| 4729 | |
Gustavo A. R. Silva | 47aa786 | 2018-06-18 07:41:34 -0500 | [diff] [blame] | 4730 | ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set); |
| 4731 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4732 | /* Need to go over for 80MHz, 160MHz and for 80+80 */ |
| 4733 | for (i = 0; i < 3; i++) { |
| 4734 | const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp = |
| 4735 | &sta_he_cap->he_mcs_nss_supp; |
| 4736 | u16 sta_mcs_map_rx = |
| 4737 | le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]); |
| 4738 | u16 sta_mcs_map_tx = |
| 4739 | le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]); |
| 4740 | u8 nss; |
| 4741 | bool verified = true; |
| 4742 | |
| 4743 | /* |
| 4744 | * For each band there is a maximum of 8 spatial streams |
| 4745 | * possible. Each of the sta_mcs_map_* is a 16-bit struct built |
| 4746 | * of 2 bits per NSS (1-8), with the values defined in enum |
| 4747 | * ieee80211_he_mcs_support. Need to make sure STA TX and RX |
| 4748 | * capabilities aren't less than the AP's minimum requirements |
| 4749 | * for this HE BSS per SS. |
| 4750 | * It is enough to find one such band that meets the reqs. |
| 4751 | */ |
| 4752 | for (nss = 8; nss > 0; nss--) { |
| 4753 | u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3; |
| 4754 | u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3; |
| 4755 | u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3; |
| 4756 | |
| 4757 | if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED) |
| 4758 | continue; |
| 4759 | |
| 4760 | /* |
| 4761 | * Make sure the HE AP doesn't require MCSs that aren't |
| 4762 | * supported by the client |
| 4763 | */ |
| 4764 | if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED || |
| 4765 | sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED || |
| 4766 | (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) { |
| 4767 | verified = false; |
| 4768 | break; |
| 4769 | } |
| 4770 | } |
| 4771 | |
| 4772 | if (verified) |
| 4773 | return true; |
| 4774 | } |
| 4775 | |
| 4776 | /* If here, STA doesn't meet AP's HE min requirements */ |
| 4777 | return false; |
| 4778 | } |
| 4779 | |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 4780 | static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata, |
| 4781 | struct cfg80211_bss *cbss) |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 4782 | { |
| 4783 | struct ieee80211_local *local = sdata->local; |
| 4784 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Eliad Peller | 53b954e | 2014-07-24 11:20:05 +0300 | [diff] [blame] | 4785 | const struct ieee80211_ht_cap *ht_cap = NULL; |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4786 | const struct ieee80211_ht_operation *ht_oper = NULL; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4787 | const struct ieee80211_vht_operation *vht_oper = NULL; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4788 | const struct ieee80211_he_operation *he_oper = NULL; |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4789 | struct ieee80211_supported_band *sband; |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 4790 | struct cfg80211_chan_def chandef; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4791 | int ret; |
Arik Nemtsov | 52a45f3 | 2015-08-15 22:39:53 +0300 | [diff] [blame] | 4792 | u32 i; |
| 4793 | bool have_80mhz; |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 4794 | |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4795 | sband = local->hw.wiphy->bands[cbss->channel->band]; |
| 4796 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4797 | ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ | |
| 4798 | IEEE80211_STA_DISABLE_80P80MHZ | |
| 4799 | IEEE80211_STA_DISABLE_160MHZ); |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4800 | |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 4801 | /* disable HT/VHT/HE if we don't support them */ |
| 4802 | if (!sband->ht_cap.ht_supported) { |
| 4803 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
| 4804 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
| 4805 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
| 4806 | } |
| 4807 | |
| 4808 | if (!sband->vht_cap.vht_supported) |
| 4809 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
| 4810 | |
| 4811 | if (!ieee80211_get_he_sta_cap(sband)) |
| 4812 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
| 4813 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 4814 | rcu_read_lock(); |
| 4815 | |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 4816 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) { |
Eliad Peller | 53b954e | 2014-07-24 11:20:05 +0300 | [diff] [blame] | 4817 | const u8 *ht_oper_ie, *ht_cap_ie; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4818 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 4819 | ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION); |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4820 | if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper)) |
| 4821 | ht_oper = (void *)(ht_oper_ie + 2); |
Johannes Berg | 08e6effa | 2013-02-07 23:33:32 +0100 | [diff] [blame] | 4822 | |
Eliad Peller | 53b954e | 2014-07-24 11:20:05 +0300 | [diff] [blame] | 4823 | ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY); |
| 4824 | if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) |
| 4825 | ht_cap = (void *)(ht_cap_ie + 2); |
| 4826 | |
| 4827 | if (!ht_cap) { |
Johannes Berg | 08e6effa | 2013-02-07 23:33:32 +0100 | [diff] [blame] | 4828 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
| 4829 | ht_oper = NULL; |
| 4830 | } |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4831 | } |
| 4832 | |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 4833 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) { |
Johannes Berg | 08e6effa | 2013-02-07 23:33:32 +0100 | [diff] [blame] | 4834 | const u8 *vht_oper_ie, *vht_cap; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4835 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 4836 | vht_oper_ie = ieee80211_bss_get_ie(cbss, |
| 4837 | WLAN_EID_VHT_OPERATION); |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4838 | if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper)) |
| 4839 | vht_oper = (void *)(vht_oper_ie + 2); |
| 4840 | if (vht_oper && !ht_oper) { |
| 4841 | vht_oper = NULL; |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4842 | sdata_info(sdata, |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 4843 | "AP advertised VHT without HT, disabling HT/VHT/HE\n"); |
Johannes Berg | cb14502 | 2013-02-07 20:41:50 +0100 | [diff] [blame] | 4844 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
| 4845 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 4846 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4847 | } |
Johannes Berg | 08e6effa | 2013-02-07 23:33:32 +0100 | [diff] [blame] | 4848 | |
| 4849 | vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY); |
| 4850 | if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) { |
| 4851 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
| 4852 | vht_oper = NULL; |
| 4853 | } |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4854 | } |
| 4855 | |
Shaul Triebitz | 002245e | 2018-12-15 11:03:19 +0200 | [diff] [blame] | 4856 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) { |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4857 | const struct cfg80211_bss_ies *ies; |
| 4858 | const u8 *he_oper_ie; |
| 4859 | |
| 4860 | ies = rcu_dereference(cbss->ies); |
| 4861 | he_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION, |
| 4862 | ies->data, ies->len); |
| 4863 | if (he_oper_ie && |
| 4864 | he_oper_ie[1] == ieee80211_he_oper_size(&he_oper_ie[3])) |
| 4865 | he_oper = (void *)(he_oper_ie + 3); |
| 4866 | else |
| 4867 | he_oper = NULL; |
| 4868 | |
Johannes Berg | f0c0407 | 2018-06-29 09:51:39 +0200 | [diff] [blame] | 4869 | if (!ieee80211_verify_sta_he_mcs_support(sband, he_oper)) |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4870 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
| 4871 | } |
| 4872 | |
Arik Nemtsov | 52a45f3 | 2015-08-15 22:39:53 +0300 | [diff] [blame] | 4873 | /* Allow VHT if at least one channel on the sband supports 80 MHz */ |
| 4874 | have_80mhz = false; |
| 4875 | for (i = 0; i < sband->n_channels; i++) { |
| 4876 | if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED | |
| 4877 | IEEE80211_CHAN_NO_80MHZ)) |
| 4878 | continue; |
| 4879 | |
| 4880 | have_80mhz = true; |
| 4881 | break; |
| 4882 | } |
| 4883 | |
| 4884 | if (!have_80mhz) |
| 4885 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
| 4886 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4887 | ifmgd->flags |= ieee80211_determine_chantype(sdata, sband, |
| 4888 | cbss->channel, |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 4889 | ht_oper, vht_oper, he_oper, |
Johannes Berg | 5cdaed1 | 2013-07-31 11:23:06 +0200 | [diff] [blame] | 4890 | &chandef, false); |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 4891 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4892 | sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss), |
| 4893 | local->rx_chains); |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 4894 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 4895 | rcu_read_unlock(); |
| 4896 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 4897 | /* will change later if needed */ |
| 4898 | sdata->smps_mode = IEEE80211_SMPS_OFF; |
| 4899 | |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 4900 | mutex_lock(&local->mtx); |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4901 | /* |
| 4902 | * If this fails (possibly due to channel context sharing |
| 4903 | * on incompatible channels, e.g. 80+80 and 160 sharing the |
| 4904 | * same control channel) try to use a smaller bandwidth. |
| 4905 | */ |
| 4906 | ret = ieee80211_vif_use_channel(sdata, &chandef, |
| 4907 | IEEE80211_CHANCTX_SHARED); |
Simon Wunderlich | 0418a44 | 2013-05-16 13:00:31 +0200 | [diff] [blame] | 4908 | |
| 4909 | /* don't downgrade for 5 and 10 MHz channels, though. */ |
| 4910 | if (chandef.width == NL80211_CHAN_WIDTH_5 || |
| 4911 | chandef.width == NL80211_CHAN_WIDTH_10) |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 4912 | goto out; |
Simon Wunderlich | 0418a44 | 2013-05-16 13:00:31 +0200 | [diff] [blame] | 4913 | |
Johannes Berg | d601cd8 | 2013-02-07 20:54:51 +0100 | [diff] [blame] | 4914 | while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) { |
Simon Wunderlich | e6b7cde | 2013-08-28 13:41:29 +0200 | [diff] [blame] | 4915 | ifmgd->flags |= ieee80211_chandef_downgrade(&chandef); |
Johannes Berg | d601cd8 | 2013-02-07 20:54:51 +0100 | [diff] [blame] | 4916 | ret = ieee80211_vif_use_channel(sdata, &chandef, |
| 4917 | IEEE80211_CHANCTX_SHARED); |
| 4918 | } |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 4919 | out: |
| 4920 | mutex_unlock(&local->mtx); |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 4921 | return ret; |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 4922 | } |
| 4923 | |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 4924 | static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies, |
| 4925 | u8 *dtim_count, u8 *dtim_period) |
| 4926 | { |
| 4927 | const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len); |
| 4928 | const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data, |
| 4929 | ies->len); |
| 4930 | const struct ieee80211_tim_ie *tim = NULL; |
| 4931 | const struct ieee80211_bssid_index *idx; |
| 4932 | bool valid = tim_ie && tim_ie[1] >= 2; |
| 4933 | |
| 4934 | if (valid) |
| 4935 | tim = (void *)(tim_ie + 2); |
| 4936 | |
| 4937 | if (dtim_count) |
| 4938 | *dtim_count = valid ? tim->dtim_count : 0; |
| 4939 | |
| 4940 | if (dtim_period) |
| 4941 | *dtim_period = valid ? tim->dtim_period : 0; |
| 4942 | |
| 4943 | /* Check if value is overridden by non-transmitted profile */ |
| 4944 | if (!idx_ie || idx_ie[1] < 3) |
| 4945 | return valid; |
| 4946 | |
| 4947 | idx = (void *)(idx_ie + 2); |
| 4948 | |
| 4949 | if (dtim_count) |
| 4950 | *dtim_count = idx->dtim_count; |
| 4951 | |
| 4952 | if (dtim_period) |
| 4953 | *dtim_period = idx->dtim_period; |
| 4954 | |
| 4955 | return true; |
| 4956 | } |
| 4957 | |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 4958 | static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata, |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 4959 | struct cfg80211_bss *cbss, bool assoc, |
| 4960 | bool override) |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 4961 | { |
| 4962 | struct ieee80211_local *local = sdata->local; |
| 4963 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 4964 | struct ieee80211_bss *bss = (void *)cbss->priv; |
| 4965 | struct sta_info *new_sta = NULL; |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 4966 | struct ieee80211_supported_band *sband; |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 4967 | bool have_sta = false; |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 4968 | int err; |
| 4969 | |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 4970 | sband = local->hw.wiphy->bands[cbss->channel->band]; |
| 4971 | |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 4972 | if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data)) |
| 4973 | return -EINVAL; |
| 4974 | |
Luca Coelho | f8860ce | 2017-05-02 17:56:21 +0300 | [diff] [blame] | 4975 | /* If a reconfig is happening, bail out */ |
| 4976 | if (local->in_reconfig) |
| 4977 | return -EBUSY; |
| 4978 | |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 4979 | if (assoc) { |
| 4980 | rcu_read_lock(); |
| 4981 | have_sta = sta_info_get(sdata, cbss->bssid); |
| 4982 | rcu_read_unlock(); |
| 4983 | } |
| 4984 | |
| 4985 | if (!have_sta) { |
| 4986 | new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL); |
| 4987 | if (!new_sta) |
| 4988 | return -ENOMEM; |
| 4989 | } |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 4990 | |
Johannes Berg | c87905b | 2017-06-10 13:52:43 +0300 | [diff] [blame] | 4991 | /* |
| 4992 | * Set up the information for the new channel before setting the |
| 4993 | * new channel. We can't - completely race-free - change the basic |
| 4994 | * rates bitmap and the channel (sband) that it refers to, but if |
| 4995 | * we set it up before we at least avoid calling into the driver's |
| 4996 | * bss_info_changed() method with invalid information (since we do |
| 4997 | * call that from changing the channel - only for IDLE and perhaps |
| 4998 | * some others, but ...). |
| 4999 | * |
| 5000 | * So to avoid that, just set up all the new information before the |
| 5001 | * channel, but tell the driver to apply it only afterwards, since |
| 5002 | * it might need the new channel for that. |
| 5003 | */ |
Johannes Berg | 13e0c8e | 2012-07-27 10:43:16 +0200 | [diff] [blame] | 5004 | if (new_sta) { |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5005 | u32 rates = 0, basic_rates = 0; |
| 5006 | bool have_higher_than_11mbit; |
| 5007 | int min_rate = INT_MAX, min_rate_index = -1; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5008 | const struct cfg80211_bss_ies *ies; |
Chaya Rachel Ivgi | 179b8fc | 2014-12-14 10:38:59 +0200 | [diff] [blame] | 5009 | int shift = ieee80211_vif_get_shift(&sdata->vif); |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5010 | |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5011 | ieee80211_get_rates(sband, bss->supp_rates, |
| 5012 | bss->supp_rates_len, |
| 5013 | &rates, &basic_rates, |
| 5014 | &have_higher_than_11mbit, |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 5015 | &min_rate, &min_rate_index, |
Johannes Berg | 44f6d42 | 2017-06-10 13:52:44 +0300 | [diff] [blame] | 5016 | shift); |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5017 | |
| 5018 | /* |
| 5019 | * This used to be a workaround for basic rates missing |
| 5020 | * in the association response frame. Now that we no |
| 5021 | * longer use the basic rates from there, it probably |
| 5022 | * doesn't happen any more, but keep the workaround so |
| 5023 | * in case some *other* APs are buggy in different ways |
| 5024 | * we can connect -- with a warning. |
| 5025 | */ |
| 5026 | if (!basic_rates && min_rate_index >= 0) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 5027 | sdata_info(sdata, |
| 5028 | "No basic rates, using min rate instead\n"); |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5029 | basic_rates = BIT(min_rate_index); |
| 5030 | } |
| 5031 | |
Johannes Berg | bd718fc | 2019-05-29 15:25:35 +0300 | [diff] [blame] | 5032 | if (rates) |
| 5033 | new_sta->sta.supp_rates[cbss->channel->band] = rates; |
| 5034 | else |
| 5035 | sdata_info(sdata, |
| 5036 | "No rates found, keeping mandatory only\n"); |
| 5037 | |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5038 | sdata->vif.bss_conf.basic_rates = basic_rates; |
| 5039 | |
| 5040 | /* cf. IEEE 802.11 9.2.12 */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5041 | if (cbss->channel->band == NL80211_BAND_2GHZ && |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5042 | have_higher_than_11mbit) |
| 5043 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; |
| 5044 | else |
| 5045 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; |
| 5046 | |
| 5047 | memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN); |
| 5048 | |
Johannes Berg | 8c358bc | 2012-05-22 22:13:05 +0200 | [diff] [blame] | 5049 | /* set timing information */ |
| 5050 | sdata->vif.bss_conf.beacon_int = cbss->beacon_interval; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5051 | rcu_read_lock(); |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5052 | ies = rcu_dereference(cbss->beacon_ies); |
| 5053 | if (ies) { |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5054 | sdata->vif.bss_conf.sync_tsf = ies->tsf; |
| 5055 | sdata->vif.bss_conf.sync_device_ts = |
| 5056 | bss->device_ts_beacon; |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 5057 | |
| 5058 | ieee80211_get_dtim(ies, |
| 5059 | &sdata->vif.bss_conf.sync_dtim_count, |
| 5060 | NULL); |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 5061 | } else if (!ieee80211_hw_check(&sdata->local->hw, |
| 5062 | TIMING_BEACON_ONLY)) { |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5063 | ies = rcu_dereference(cbss->proberesp_ies); |
| 5064 | /* must be non-NULL since beacon IEs were NULL */ |
| 5065 | sdata->vif.bss_conf.sync_tsf = ies->tsf; |
| 5066 | sdata->vif.bss_conf.sync_device_ts = |
| 5067 | bss->device_ts_presp; |
| 5068 | sdata->vif.bss_conf.sync_dtim_count = 0; |
| 5069 | } else { |
| 5070 | sdata->vif.bss_conf.sync_tsf = 0; |
| 5071 | sdata->vif.bss_conf.sync_device_ts = 0; |
| 5072 | sdata->vif.bss_conf.sync_dtim_count = 0; |
| 5073 | } |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5074 | rcu_read_unlock(); |
Johannes Berg | c87905b | 2017-06-10 13:52:43 +0300 | [diff] [blame] | 5075 | } |
Johannes Berg | 8c358bc | 2012-05-22 22:13:05 +0200 | [diff] [blame] | 5076 | |
Johannes Berg | c87905b | 2017-06-10 13:52:43 +0300 | [diff] [blame] | 5077 | if (new_sta || override) { |
| 5078 | err = ieee80211_prep_channel(sdata, cbss); |
| 5079 | if (err) { |
| 5080 | if (new_sta) |
| 5081 | sta_info_free(local, new_sta); |
| 5082 | return -EINVAL; |
| 5083 | } |
| 5084 | } |
| 5085 | |
| 5086 | if (new_sta) { |
| 5087 | /* |
| 5088 | * tell driver about BSSID, basic rates and timing |
| 5089 | * this was set up above, before setting the channel |
| 5090 | */ |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 5091 | ieee80211_bss_info_change_notify(sdata, |
Johannes Berg | 8c358bc | 2012-05-22 22:13:05 +0200 | [diff] [blame] | 5092 | BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES | |
| 5093 | BSS_CHANGED_BEACON_INT); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5094 | |
| 5095 | if (assoc) |
Johannes Berg | 13e0c8e | 2012-07-27 10:43:16 +0200 | [diff] [blame] | 5096 | sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5097 | |
Johannes Berg | 13e0c8e | 2012-07-27 10:43:16 +0200 | [diff] [blame] | 5098 | err = sta_info_insert(new_sta); |
| 5099 | new_sta = NULL; |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5100 | if (err) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 5101 | sdata_info(sdata, |
| 5102 | "failed to insert STA entry for the AP (error %d)\n", |
| 5103 | err); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5104 | return err; |
| 5105 | } |
| 5106 | } else |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 5107 | WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid)); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5108 | |
David Spinadel | 7d830a1 | 2015-03-17 19:58:38 +0200 | [diff] [blame] | 5109 | /* Cancel scan to ensure that nothing interferes with connection */ |
| 5110 | if (local->scanning) |
| 5111 | ieee80211_scan_cancel(local); |
| 5112 | |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5113 | return 0; |
| 5114 | } |
| 5115 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5116 | /* config hooks */ |
| 5117 | int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata, |
| 5118 | struct cfg80211_auth_request *req) |
| 5119 | { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5120 | struct ieee80211_local *local = sdata->local; |
| 5121 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 5122 | struct ieee80211_mgd_auth_data *auth_data; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5123 | u16 auth_alg; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5124 | int err; |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5125 | bool cont_auth; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5126 | |
| 5127 | /* prepare auth data structure */ |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5128 | |
| 5129 | switch (req->auth_type) { |
| 5130 | case NL80211_AUTHTYPE_OPEN_SYSTEM: |
| 5131 | auth_alg = WLAN_AUTH_OPEN; |
| 5132 | break; |
| 5133 | case NL80211_AUTHTYPE_SHARED_KEY: |
Ard Biesheuvel | 5fdb373 | 2019-06-12 18:19:54 +0200 | [diff] [blame] | 5134 | if (fips_enabled) |
Johannes Berg | 9dca9c4 | 2010-07-21 10:09:25 +0200 | [diff] [blame] | 5135 | return -EOPNOTSUPP; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5136 | auth_alg = WLAN_AUTH_SHARED_KEY; |
| 5137 | break; |
| 5138 | case NL80211_AUTHTYPE_FT: |
| 5139 | auth_alg = WLAN_AUTH_FT; |
| 5140 | break; |
| 5141 | case NL80211_AUTHTYPE_NETWORK_EAP: |
| 5142 | auth_alg = WLAN_AUTH_LEAP; |
| 5143 | break; |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 5144 | case NL80211_AUTHTYPE_SAE: |
| 5145 | auth_alg = WLAN_AUTH_SAE; |
| 5146 | break; |
Jouni Malinen | dbc0c2c | 2016-10-27 00:42:04 +0300 | [diff] [blame] | 5147 | case NL80211_AUTHTYPE_FILS_SK: |
| 5148 | auth_alg = WLAN_AUTH_FILS_SK; |
| 5149 | break; |
| 5150 | case NL80211_AUTHTYPE_FILS_SK_PFS: |
| 5151 | auth_alg = WLAN_AUTH_FILS_SK_PFS; |
| 5152 | break; |
| 5153 | case NL80211_AUTHTYPE_FILS_PK: |
| 5154 | auth_alg = WLAN_AUTH_FILS_PK; |
| 5155 | break; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5156 | default: |
| 5157 | return -EOPNOTSUPP; |
| 5158 | } |
| 5159 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5160 | if (ifmgd->assoc_data) |
Jouni Malinen | 8d7432a | 2018-10-11 00:21:20 +0300 | [diff] [blame] | 5161 | return -EBUSY; |
| 5162 | |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 5163 | auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len + |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 5164 | req->ie_len, GFP_KERNEL); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5165 | if (!auth_data) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5166 | return -ENOMEM; |
| 5167 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5168 | auth_data->bss = req->bss; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5169 | |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 5170 | if (req->auth_data_len >= 4) { |
Jouni Malinen | 6ec6361 | 2016-10-27 00:41:59 +0300 | [diff] [blame] | 5171 | if (req->auth_type == NL80211_AUTHTYPE_SAE) { |
| 5172 | __le16 *pos = (__le16 *) req->auth_data; |
| 5173 | |
| 5174 | auth_data->sae_trans = le16_to_cpu(pos[0]); |
| 5175 | auth_data->sae_status = le16_to_cpu(pos[1]); |
| 5176 | } |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 5177 | memcpy(auth_data->data, req->auth_data + 4, |
| 5178 | req->auth_data_len - 4); |
| 5179 | auth_data->data_len += req->auth_data_len - 4; |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 5180 | } |
| 5181 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5182 | /* Check if continuing authentication or trying to authenticate with the |
| 5183 | * same BSS that we were in the process of authenticating with and avoid |
| 5184 | * removal and re-addition of the STA entry in |
| 5185 | * ieee80211_prep_connection(). |
| 5186 | */ |
| 5187 | cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss; |
| 5188 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5189 | if (req->ie && req->ie_len) { |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 5190 | memcpy(&auth_data->data[auth_data->data_len], |
| 5191 | req->ie, req->ie_len); |
| 5192 | auth_data->data_len += req->ie_len; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5193 | } |
| 5194 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5195 | if (req->key && req->key_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5196 | auth_data->key_len = req->key_len; |
| 5197 | auth_data->key_idx = req->key_idx; |
| 5198 | memcpy(auth_data->key, req->key, req->key_len); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5199 | } |
| 5200 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5201 | auth_data->algorithm = auth_alg; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5202 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5203 | /* try to authenticate/probe */ |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 5204 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5205 | if (ifmgd->auth_data) { |
| 5206 | if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) { |
| 5207 | auth_data->peer_confirmed = |
| 5208 | ifmgd->auth_data->peer_confirmed; |
| 5209 | } |
| 5210 | ieee80211_destroy_auth_data(sdata, cont_auth); |
| 5211 | } |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 5212 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5213 | /* prep auth_data so we don't go into idle on disassoc */ |
| 5214 | ifmgd->auth_data = auth_data; |
| 5215 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5216 | /* If this is continuation of an ongoing SAE authentication exchange |
| 5217 | * (i.e., request to send SAE Confirm) and the peer has already |
| 5218 | * confirmed, mark authentication completed since we are about to send |
| 5219 | * out SAE Confirm. |
| 5220 | */ |
| 5221 | if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE && |
| 5222 | auth_data->peer_confirmed && auth_data->sae_trans == 2) |
| 5223 | ieee80211_mark_sta_auth(sdata, req->bss->bssid); |
| 5224 | |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5225 | if (ifmgd->associated) { |
| 5226 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
| 5227 | |
Johannes Berg | 89f774e | 2016-01-25 15:46:36 +0200 | [diff] [blame] | 5228 | sdata_info(sdata, |
| 5229 | "disconnect from AP %pM for new auth to %pM\n", |
| 5230 | ifmgd->associated->bssid, req->bss->bssid); |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5231 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
| 5232 | WLAN_REASON_UNSPECIFIED, |
| 5233 | false, frame_buf); |
| 5234 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 5235 | ieee80211_report_disconnect(sdata, frame_buf, |
| 5236 | sizeof(frame_buf), true, |
| 5237 | WLAN_REASON_UNSPECIFIED); |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5238 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5239 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 5240 | sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5241 | |
Jouni Malinen | efb543e | 2018-10-11 00:21:21 +0300 | [diff] [blame] | 5242 | err = ieee80211_prep_connection(sdata, req->bss, cont_auth, false); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5243 | if (err) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5244 | goto err_clear; |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 5245 | |
Johannes Berg | 46cad4b | 2015-08-15 22:39:54 +0300 | [diff] [blame] | 5246 | err = ieee80211_auth(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5247 | if (err) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5248 | sta_info_destroy_addr(sdata, req->bss->bssid); |
| 5249 | goto err_clear; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5250 | } |
| 5251 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5252 | /* hold our own reference */ |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 5253 | cfg80211_ref_bss(local->hw.wiphy, auth_data->bss); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 5254 | return 0; |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 5255 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5256 | err_clear: |
Joe Perches | c84a67a | 2015-03-02 19:54:57 -0800 | [diff] [blame] | 5257 | eth_zero_addr(ifmgd->bssid); |
Eliad Peller | 3d2abdf | 2012-09-04 17:44:45 +0300 | [diff] [blame] | 5258 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5259 | ifmgd->auth_data = NULL; |
Michal Kazior | d01f858 | 2015-06-03 08:36:13 +0200 | [diff] [blame] | 5260 | mutex_lock(&sdata->local->mtx); |
| 5261 | ieee80211_vif_release_channel(sdata); |
| 5262 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5263 | kfree(auth_data); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5264 | return err; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5265 | } |
| 5266 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5267 | int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, |
| 5268 | struct cfg80211_assoc_request *req) |
| 5269 | { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5270 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5271 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 5272 | struct ieee80211_bss *bss = (void *)req->bss->priv; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5273 | struct ieee80211_mgd_assoc_data *assoc_data; |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5274 | const struct cfg80211_bss_ies *beacon_ies; |
Johannes Berg | 4e74bfd | 2012-03-08 15:02:04 +0100 | [diff] [blame] | 5275 | struct ieee80211_supported_band *sband; |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 5276 | const u8 *ssidie, *ht_ie, *vht_ie; |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 5277 | int i, err; |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 5278 | bool override = false; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5279 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5280 | assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL); |
| 5281 | if (!assoc_data) |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5282 | return -ENOMEM; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5283 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5284 | rcu_read_lock(); |
| 5285 | ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID); |
Will Deacon | 4152561 | 2019-10-04 10:51:31 +0100 | [diff] [blame] | 5286 | if (!ssidie || ssidie[1] > sizeof(assoc_data->ssid)) { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5287 | rcu_read_unlock(); |
| 5288 | kfree(assoc_data); |
| 5289 | return -EINVAL; |
| 5290 | } |
| 5291 | memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]); |
| 5292 | assoc_data->ssid_len = ssidie[1]; |
| 5293 | rcu_read_unlock(); |
| 5294 | |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5295 | if (ifmgd->associated) { |
| 5296 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
| 5297 | |
Johannes Berg | 89f774e | 2016-01-25 15:46:36 +0200 | [diff] [blame] | 5298 | sdata_info(sdata, |
| 5299 | "disconnect from AP %pM for new assoc to %pM\n", |
| 5300 | ifmgd->associated->bssid, req->bss->bssid); |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5301 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
| 5302 | WLAN_REASON_UNSPECIFIED, |
| 5303 | false, frame_buf); |
| 5304 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 5305 | ieee80211_report_disconnect(sdata, frame_buf, |
| 5306 | sizeof(frame_buf), true, |
| 5307 | WLAN_REASON_UNSPECIFIED); |
Johannes Berg | 7b119dc | 2013-04-10 21:38:36 +0200 | [diff] [blame] | 5308 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5309 | |
| 5310 | if (ifmgd->auth_data && !ifmgd->auth_data->done) { |
| 5311 | err = -EBUSY; |
| 5312 | goto err_free; |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 5313 | } |
| 5314 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5315 | if (ifmgd->assoc_data) { |
| 5316 | err = -EBUSY; |
| 5317 | goto err_free; |
| 5318 | } |
| 5319 | |
| 5320 | if (ifmgd->auth_data) { |
| 5321 | bool match; |
| 5322 | |
| 5323 | /* keep sta info, bssid if matching */ |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 5324 | match = ether_addr_equal(ifmgd->bssid, req->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5325 | ieee80211_destroy_auth_data(sdata, match); |
| 5326 | } |
| 5327 | |
| 5328 | /* prepare assoc data */ |
Johannes Berg | 095d81c | 2013-10-15 12:25:07 +0200 | [diff] [blame] | 5329 | |
Juuso Oikarinen | d8ec443 | 2010-10-01 16:02:31 +0300 | [diff] [blame] | 5330 | ifmgd->beacon_crc_valid = false; |
| 5331 | |
Johannes Berg | 095d81c | 2013-10-15 12:25:07 +0200 | [diff] [blame] | 5332 | assoc_data->wmm = bss->wmm_used && |
| 5333 | (local->hw.queues >= IEEE80211_NUM_ACS); |
Johannes Berg | 095d81c | 2013-10-15 12:25:07 +0200 | [diff] [blame] | 5334 | |
Johannes Berg | de5036a | 2012-03-08 15:02:03 +0100 | [diff] [blame] | 5335 | /* |
| 5336 | * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode. |
| 5337 | * We still associate in non-HT mode (11a/b/g) if any one of these |
| 5338 | * ciphers is configured as pairwise. |
| 5339 | * We can set this to true for non-11n hardware, that'll be checked |
| 5340 | * separately along with the peer capabilities. |
| 5341 | */ |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 5342 | for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) { |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5343 | if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 || |
| 5344 | req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP || |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 5345 | req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) { |
Johannes Berg | a8243b7 | 2012-11-22 14:32:09 +0100 | [diff] [blame] | 5346 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 5347 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 5348 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 5349 | netdev_info(sdata->dev, |
Johannes Berg | 5462632 | 2019-08-30 14:24:46 +0300 | [diff] [blame] | 5350 | "disabling HT/VHT/HE due to WEP/TKIP use\n"); |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 5351 | } |
| 5352 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5353 | |
Johannes Berg | 4e74bfd | 2012-03-08 15:02:04 +0100 | [diff] [blame] | 5354 | sband = local->hw.wiphy->bands[req->bss->channel->band]; |
Johannes Berg | 4e74bfd | 2012-03-08 15:02:04 +0100 | [diff] [blame] | 5355 | |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 5356 | /* also disable HT/VHT/HE if the AP doesn't use WMM */ |
| 5357 | if (!bss->wmm_used) { |
| 5358 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 5359 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 5360 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
| 5361 | netdev_info(sdata->dev, |
| 5362 | "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] | 5363 | } |
| 5364 | |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 5365 | memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa)); |
| 5366 | memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask, |
| 5367 | sizeof(ifmgd->ht_capa_mask)); |
| 5368 | |
Johannes Berg | dd5ecfe | 2013-02-21 17:40:19 +0100 | [diff] [blame] | 5369 | memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa)); |
| 5370 | memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask, |
| 5371 | sizeof(ifmgd->vht_capa_mask)); |
| 5372 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5373 | if (req->ie && req->ie_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5374 | memcpy(assoc_data->ie, req->ie, req->ie_len); |
| 5375 | assoc_data->ie_len = req->ie_len; |
| 5376 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5377 | |
Jouni Malinen | 39404fe | 2016-10-27 00:42:05 +0300 | [diff] [blame] | 5378 | if (req->fils_kek) { |
| 5379 | /* should already be checked in cfg80211 - so warn */ |
| 5380 | if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) { |
| 5381 | err = -EINVAL; |
| 5382 | goto err_free; |
| 5383 | } |
| 5384 | memcpy(assoc_data->fils_kek, req->fils_kek, |
| 5385 | req->fils_kek_len); |
| 5386 | assoc_data->fils_kek_len = req->fils_kek_len; |
| 5387 | } |
| 5388 | |
| 5389 | if (req->fils_nonces) |
| 5390 | memcpy(assoc_data->fils_nonces, req->fils_nonces, |
| 5391 | 2 * FILS_NONCE_LEN); |
| 5392 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5393 | assoc_data->bss = req->bss; |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 5394 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5395 | if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) { |
| 5396 | if (ifmgd->powersave) |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 5397 | sdata->smps_mode = IEEE80211_SMPS_DYNAMIC; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5398 | else |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 5399 | sdata->smps_mode = IEEE80211_SMPS_OFF; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5400 | } else |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 5401 | sdata->smps_mode = ifmgd->req_smps; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 5402 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5403 | assoc_data->capability = req->bss->capability; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5404 | assoc_data->supp_rates = bss->supp_rates; |
| 5405 | assoc_data->supp_rates_len = bss->supp_rates_len; |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 5406 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5407 | rcu_read_lock(); |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 5408 | ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION); |
| 5409 | if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation)) |
| 5410 | assoc_data->ap_ht_param = |
| 5411 | ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param; |
| 5412 | else |
Johannes Berg | a8243b7 | 2012-11-22 14:32:09 +0100 | [diff] [blame] | 5413 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
Johannes Berg | b08fbbd | 2012-12-07 13:06:48 +0100 | [diff] [blame] | 5414 | vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY); |
| 5415 | if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap)) |
| 5416 | memcpy(&assoc_data->ap_vht_cap, vht_ie + 2, |
| 5417 | sizeof(struct ieee80211_vht_cap)); |
| 5418 | else |
| 5419 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5420 | rcu_read_unlock(); |
Johannes Berg | 63f170e | 2009-12-23 13:15:33 +0100 | [diff] [blame] | 5421 | |
Johannes Berg | 848955c | 2014-11-11 12:48:42 +0100 | [diff] [blame] | 5422 | if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) && |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 5423 | ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK), |
Johannes Berg | 848955c | 2014-11-11 12:48:42 +0100 | [diff] [blame] | 5424 | "U-APSD not supported with HW_PS_NULLFUNC_STACK\n")) |
| 5425 | sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; |
| 5426 | |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 5427 | if (bss->wmm_used && bss->uapsd_supported && |
Johannes Berg | 848955c | 2014-11-11 12:48:42 +0100 | [diff] [blame] | 5428 | (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) { |
Johannes Berg | 76f0303 | 2012-03-08 15:02:05 +0100 | [diff] [blame] | 5429 | assoc_data->uapsd = true; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 5430 | ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED; |
| 5431 | } else { |
Johannes Berg | 76f0303 | 2012-03-08 15:02:05 +0100 | [diff] [blame] | 5432 | assoc_data->uapsd = false; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 5433 | ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED; |
| 5434 | } |
| 5435 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5436 | if (req->prev_bssid) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5437 | memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5438 | |
| 5439 | if (req->use_mfp) { |
| 5440 | ifmgd->mfp = IEEE80211_MFP_REQUIRED; |
| 5441 | ifmgd->flags |= IEEE80211_STA_MFP_ENABLED; |
| 5442 | } else { |
| 5443 | ifmgd->mfp = IEEE80211_MFP_DISABLED; |
| 5444 | ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED; |
| 5445 | } |
| 5446 | |
Assaf Krauss | cd2f5dd | 2014-09-03 15:25:02 +0300 | [diff] [blame] | 5447 | if (req->flags & ASSOC_REQ_USE_RRM) |
| 5448 | ifmgd->flags |= IEEE80211_STA_ENABLE_RRM; |
| 5449 | else |
| 5450 | ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM; |
| 5451 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5452 | if (req->crypto.control_port) |
| 5453 | ifmgd->flags |= IEEE80211_STA_CONTROL_PORT; |
| 5454 | else |
| 5455 | ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT; |
| 5456 | |
Johannes Berg | a621fa4 | 2010-08-27 14:26:54 +0300 | [diff] [blame] | 5457 | sdata->control_port_protocol = req->crypto.control_port_ethertype; |
| 5458 | sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt; |
Denis Kenzior | 018f6fb | 2018-03-26 12:52:51 -0500 | [diff] [blame] | 5459 | sdata->control_port_over_nl80211 = |
| 5460 | req->crypto.control_port_over_nl80211; |
Markus Theil | 7f3f96c | 2020-03-12 10:10:54 +0100 | [diff] [blame] | 5461 | sdata->control_port_no_preauth = req->crypto.control_port_no_preauth; |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 5462 | sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto, |
| 5463 | sdata->vif.type); |
Johannes Berg | a621fa4 | 2010-08-27 14:26:54 +0300 | [diff] [blame] | 5464 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5465 | /* kick off associate process */ |
| 5466 | |
| 5467 | ifmgd->assoc_data = assoc_data; |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 5468 | ifmgd->dtim_period = 0; |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 5469 | ifmgd->have_beacon = false; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5470 | |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 5471 | /* override HT/VHT configuration only if the AP and we support it */ |
| 5472 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) { |
| 5473 | struct ieee80211_sta_ht_cap sta_ht_cap; |
| 5474 | |
| 5475 | if (req->flags & ASSOC_REQ_DISABLE_HT) |
| 5476 | override = true; |
| 5477 | |
| 5478 | memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap)); |
| 5479 | ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap); |
| 5480 | |
| 5481 | /* check for 40 MHz disable override */ |
| 5482 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) && |
| 5483 | sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 && |
| 5484 | !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) |
| 5485 | override = true; |
| 5486 | |
| 5487 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && |
| 5488 | req->flags & ASSOC_REQ_DISABLE_VHT) |
| 5489 | override = true; |
| 5490 | } |
| 5491 | |
| 5492 | if (req->flags & ASSOC_REQ_DISABLE_HT) { |
| 5493 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
| 5494 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 75e296e | 2020-01-31 13:12:39 +0200 | [diff] [blame] | 5495 | ifmgd->flags |= IEEE80211_STA_DISABLE_HE; |
Chaya Rachel Ivgi | c1041f1 | 2015-04-20 22:51:46 +0300 | [diff] [blame] | 5496 | } |
| 5497 | |
| 5498 | if (req->flags & ASSOC_REQ_DISABLE_VHT) |
| 5499 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
| 5500 | |
| 5501 | err = ieee80211_prep_connection(sdata, req->bss, true, override); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 5502 | if (err) |
| 5503 | goto err_clear; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5504 | |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5505 | rcu_read_lock(); |
| 5506 | beacon_ies = rcu_dereference(req->bss->beacon_ies); |
Johannes Berg | 826262c | 2012-12-10 16:38:14 +0200 | [diff] [blame] | 5507 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 5508 | if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) && |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5509 | !beacon_ies) { |
| 5510 | /* |
| 5511 | * Wait up to one beacon interval ... |
| 5512 | * should this be more if we miss one? |
| 5513 | */ |
| 5514 | sdata_info(sdata, "waiting for beacon from %pM\n", |
| 5515 | ifmgd->bssid); |
| 5516 | assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval); |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 5517 | assoc_data->timeout_started = true; |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5518 | assoc_data->need_beacon = true; |
| 5519 | } else if (beacon_ies) { |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 5520 | const u8 *ie; |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5521 | u8 dtim_count = 0; |
| 5522 | |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 5523 | ieee80211_get_dtim(beacon_ies, &dtim_count, |
| 5524 | &ifmgd->dtim_period); |
| 5525 | |
Alexander Bondar | 989c650 | 2013-05-16 17:34:17 +0300 | [diff] [blame] | 5526 | ifmgd->have_beacon = true; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5527 | assoc_data->timeout = jiffies; |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 5528 | assoc_data->timeout_started = true; |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5529 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 5530 | if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) { |
Johannes Berg | ef429da | 2013-02-05 17:48:40 +0100 | [diff] [blame] | 5531 | sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf; |
| 5532 | sdata->vif.bss_conf.sync_device_ts = |
| 5533 | bss->device_ts_beacon; |
| 5534 | sdata->vif.bss_conf.sync_dtim_count = dtim_count; |
| 5535 | } |
Sara Sharon | 78ac51f | 2019-01-16 18:22:56 +0200 | [diff] [blame] | 5536 | |
| 5537 | ie = cfg80211_find_ext_ie(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION, |
| 5538 | beacon_ies->data, beacon_ies->len); |
| 5539 | if (ie && ie[1] >= 3) |
| 5540 | sdata->vif.bss_conf.profile_periodicity = ie[4]; |
| 5541 | |
| 5542 | ie = cfg80211_find_ie(WLAN_EID_EXT_CAPABILITY, |
| 5543 | beacon_ies->data, beacon_ies->len); |
| 5544 | if (ie && ie[1] >= 11 && |
| 5545 | (ie[10] & WLAN_EXT_CAPA11_EMA_SUPPORT)) |
| 5546 | sdata->vif.bss_conf.ema_ap = true; |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5547 | } else { |
| 5548 | assoc_data->timeout = jiffies; |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 5549 | assoc_data->timeout_started = true; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5550 | } |
Emmanuel Grumbach | c65dd14 | 2012-12-12 10:12:24 +0200 | [diff] [blame] | 5551 | rcu_read_unlock(); |
| 5552 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 5553 | run_again(sdata, assoc_data->timeout); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5554 | |
Paul Stewart | fcff4f1 | 2012-02-23 17:59:53 -0800 | [diff] [blame] | 5555 | if (bss->corrupt_data) { |
| 5556 | char *corrupt_type = "data"; |
| 5557 | if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) { |
| 5558 | if (bss->corrupt_data & |
| 5559 | IEEE80211_BSS_CORRUPT_PROBE_RESP) |
| 5560 | corrupt_type = "beacon and probe response"; |
| 5561 | else |
| 5562 | corrupt_type = "beacon"; |
| 5563 | } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP) |
| 5564 | corrupt_type = "probe response"; |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 5565 | sdata_info(sdata, "associating with AP with corrupt %s\n", |
| 5566 | corrupt_type); |
Paul Stewart | fcff4f1 | 2012-02-23 17:59:53 -0800 | [diff] [blame] | 5567 | } |
| 5568 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 5569 | return 0; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5570 | err_clear: |
Joe Perches | c84a67a | 2015-03-02 19:54:57 -0800 | [diff] [blame] | 5571 | eth_zero_addr(ifmgd->bssid); |
Eliad Peller | 3d2abdf | 2012-09-04 17:44:45 +0300 | [diff] [blame] | 5572 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5573 | ifmgd->assoc_data = NULL; |
| 5574 | err_free: |
| 5575 | kfree(assoc_data); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 5576 | return err; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5577 | } |
| 5578 | |
| 5579 | int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 63c9c5e | 2012-02-24 13:50:51 +0100 | [diff] [blame] | 5580 | struct cfg80211_deauth_request *req) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5581 | { |
| 5582 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 5583 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Stanislaw Gruszka | 6863255 | 2012-10-15 14:52:41 +0200 | [diff] [blame] | 5584 | bool tx = !req->local_state_change; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5585 | |
Johannes Berg | c9c3a06 | 2014-03-19 09:11:19 +0100 | [diff] [blame] | 5586 | if (ifmgd->auth_data && |
| 5587 | ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) { |
| 5588 | sdata_info(sdata, |
| 5589 | "aborting authentication with %pM by local choice (Reason: %u=%s)\n", |
| 5590 | req->bssid, req->reason_code, |
| 5591 | ieee80211_get_reason_code_string(req->reason_code)); |
Johannes Berg | 0ff7161 | 2009-09-26 14:45:41 +0200 | [diff] [blame] | 5592 | |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 5593 | drv_mgd_prepare_tx(sdata->local, sdata, 0); |
Johannes Berg | 4b08d1b | 2019-08-30 14:24:51 +0300 | [diff] [blame] | 5594 | ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid, |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 5595 | IEEE80211_STYPE_DEAUTH, |
Stanislaw Gruszka | 6863255 | 2012-10-15 14:52:41 +0200 | [diff] [blame] | 5596 | req->reason_code, tx, |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 5597 | frame_buf); |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 5598 | ieee80211_destroy_auth_data(sdata, false); |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 5599 | ieee80211_report_disconnect(sdata, frame_buf, |
| 5600 | sizeof(frame_buf), true, |
| 5601 | req->reason_code); |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 5602 | |
Johannes Berg | c9c3a06 | 2014-03-19 09:11:19 +0100 | [diff] [blame] | 5603 | return 0; |
Emmanuel Grumbach | 8c7d857 | 2012-07-25 01:42:36 +0300 | [diff] [blame] | 5604 | } |
| 5605 | |
Andrei Otcheretianski | a64cba3 | 2015-10-25 10:59:38 +0200 | [diff] [blame] | 5606 | if (ifmgd->assoc_data && |
| 5607 | ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) { |
| 5608 | sdata_info(sdata, |
| 5609 | "aborting association with %pM by local choice (Reason: %u=%s)\n", |
| 5610 | req->bssid, req->reason_code, |
| 5611 | ieee80211_get_reason_code_string(req->reason_code)); |
| 5612 | |
Ilan Peer | d4e36e5 | 2018-04-20 13:49:25 +0300 | [diff] [blame] | 5613 | drv_mgd_prepare_tx(sdata->local, sdata, 0); |
Johannes Berg | 4b08d1b | 2019-08-30 14:24:51 +0300 | [diff] [blame] | 5614 | ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid, |
Andrei Otcheretianski | a64cba3 | 2015-10-25 10:59:38 +0200 | [diff] [blame] | 5615 | IEEE80211_STYPE_DEAUTH, |
| 5616 | req->reason_code, tx, |
| 5617 | frame_buf); |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 5618 | ieee80211_destroy_assoc_data(sdata, false, true); |
Andrei Otcheretianski | a64cba3 | 2015-10-25 10:59:38 +0200 | [diff] [blame] | 5619 | ieee80211_report_disconnect(sdata, frame_buf, |
| 5620 | sizeof(frame_buf), true, |
| 5621 | req->reason_code); |
| 5622 | return 0; |
| 5623 | } |
| 5624 | |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 5625 | if (ifmgd->associated && |
| 5626 | ether_addr_equal(ifmgd->associated->bssid, req->bssid)) { |
Johannes Berg | c9c3a06 | 2014-03-19 09:11:19 +0100 | [diff] [blame] | 5627 | sdata_info(sdata, |
| 5628 | "deauthenticating from %pM by local choice (Reason: %u=%s)\n", |
| 5629 | req->bssid, req->reason_code, |
| 5630 | ieee80211_get_reason_code_string(req->reason_code)); |
| 5631 | |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 5632 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
| 5633 | req->reason_code, tx, frame_buf); |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 5634 | ieee80211_report_disconnect(sdata, frame_buf, |
| 5635 | sizeof(frame_buf), true, |
| 5636 | req->reason_code); |
Johannes Berg | c9c3a06 | 2014-03-19 09:11:19 +0100 | [diff] [blame] | 5637 | return 0; |
| 5638 | } |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 5639 | |
Johannes Berg | c9c3a06 | 2014-03-19 09:11:19 +0100 | [diff] [blame] | 5640 | return -ENOTCONN; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5641 | } |
| 5642 | |
| 5643 | int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 63c9c5e | 2012-02-24 13:50:51 +0100 | [diff] [blame] | 5644 | struct cfg80211_disassoc_request *req) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5645 | { |
| 5646 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 5647 | u8 bssid[ETH_ALEN]; |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 5648 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5649 | |
Johannes Berg | 8d8b261 | 2009-07-25 11:58:36 +0200 | [diff] [blame] | 5650 | /* |
| 5651 | * cfg80211 should catch this ... but it's racy since |
| 5652 | * we can receive a disassoc frame, process it, hand it |
| 5653 | * to cfg80211 while that's in a locked section already |
| 5654 | * trying to tell us that the user wants to disconnect. |
| 5655 | */ |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 5656 | if (ifmgd->associated != req->bss) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5657 | return -ENOLINK; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5658 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 5659 | sdata_info(sdata, |
Calvin Owens | dfa1ad2 | 2014-02-11 12:36:24 -0600 | [diff] [blame] | 5660 | "disassociating from %pM by local choice (Reason: %u=%s)\n", |
| 5661 | 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] | 5662 | |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 5663 | memcpy(bssid, req->bss->bssid, ETH_ALEN); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 5664 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC, |
| 5665 | req->reason_code, !req->local_state_change, |
| 5666 | frame_buf); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5667 | |
Emmanuel Grumbach | a90faa9 | 2015-03-16 23:23:37 +0200 | [diff] [blame] | 5668 | ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true, |
| 5669 | req->reason_code); |
Johannes Berg | bc83b68 | 2009-11-29 12:19:06 +0100 | [diff] [blame] | 5670 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 5671 | return 0; |
| 5672 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5673 | |
Eliad Peller | afa762f | 2012-04-23 14:45:15 +0300 | [diff] [blame] | 5674 | void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 54e4ffb | 2012-02-25 21:48:08 +0100 | [diff] [blame] | 5675 | { |
| 5676 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 5677 | |
Ben Greear | 4992185 | 2013-02-20 09:41:09 -0800 | [diff] [blame] | 5678 | /* |
| 5679 | * Make sure some work items will not run after this, |
| 5680 | * they will not do anything but might not have been |
| 5681 | * cancelled when disconnecting. |
| 5682 | */ |
| 5683 | cancel_work_sync(&ifmgd->monitor_work); |
| 5684 | cancel_work_sync(&ifmgd->beacon_connection_loss_work); |
| 5685 | cancel_work_sync(&ifmgd->request_smps_work); |
| 5686 | cancel_work_sync(&ifmgd->csa_connection_drop_work); |
| 5687 | cancel_work_sync(&ifmgd->chswitch_work); |
Arik Nemtsov | 81dd2b8 | 2014-07-17 17:14:25 +0300 | [diff] [blame] | 5688 | cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work); |
Ben Greear | 4992185 | 2013-02-20 09:41:09 -0800 | [diff] [blame] | 5689 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 5690 | sdata_lock(sdata); |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 5691 | if (ifmgd->assoc_data) { |
| 5692 | struct cfg80211_bss *bss = ifmgd->assoc_data->bss; |
Johannes Berg | e6f462d | 2016-12-08 17:22:09 +0100 | [diff] [blame] | 5693 | ieee80211_destroy_assoc_data(sdata, false, false); |
Johannes Berg | 959867f | 2013-06-19 13:05:42 +0200 | [diff] [blame] | 5694 | cfg80211_assoc_timeout(sdata->dev, bss); |
| 5695 | } |
Johannes Berg | 54e4ffb | 2012-02-25 21:48:08 +0100 | [diff] [blame] | 5696 | if (ifmgd->auth_data) |
| 5697 | ieee80211_destroy_auth_data(sdata, false); |
Liad Kaufman | 1277b4a | 2014-11-09 18:50:08 +0200 | [diff] [blame] | 5698 | spin_lock_bh(&ifmgd->teardown_lock); |
| 5699 | if (ifmgd->teardown_skb) { |
| 5700 | kfree_skb(ifmgd->teardown_skb); |
| 5701 | ifmgd->teardown_skb = NULL; |
| 5702 | ifmgd->orig_teardown_skb = NULL; |
| 5703 | } |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 5704 | kfree(ifmgd->assoc_req_ies); |
| 5705 | ifmgd->assoc_req_ies = NULL; |
| 5706 | ifmgd->assoc_req_ies_len = 0; |
Liad Kaufman | 1277b4a | 2014-11-09 18:50:08 +0200 | [diff] [blame] | 5707 | spin_unlock_bh(&ifmgd->teardown_lock); |
Johannes Berg | 54e4ffb | 2012-02-25 21:48:08 +0100 | [diff] [blame] | 5708 | del_timer_sync(&ifmgd->timer); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 5709 | sdata_unlock(sdata); |
Johannes Berg | 54e4ffb | 2012-02-25 21:48:08 +0100 | [diff] [blame] | 5710 | } |
| 5711 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 5712 | void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif, |
| 5713 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
Andrzej Zaborowski | 769f07d | 2017-01-25 12:43:40 +0100 | [diff] [blame] | 5714 | s32 rssi_level, |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 5715 | gfp_t gfp) |
| 5716 | { |
| 5717 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 5718 | |
Andrzej Zaborowski | 769f07d | 2017-01-25 12:43:40 +0100 | [diff] [blame] | 5719 | trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level); |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 5720 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 5721 | cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp); |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 5722 | } |
| 5723 | EXPORT_SYMBOL(ieee80211_cqm_rssi_notify); |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 5724 | |
| 5725 | void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp) |
| 5726 | { |
| 5727 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 5728 | |
| 5729 | trace_api_cqm_beacon_loss_notify(sdata->local, sdata); |
| 5730 | |
| 5731 | cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp); |
| 5732 | } |
| 5733 | EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify); |