1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * BSS client mode implementation 4 * Copyright 2003-2008, Jouni Malinen <j@w1.fi> 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> 9 * Copyright 2013-2014 Intel Mobile Communications GmbH 10 * Copyright (C) 2015 - 2017 Intel Deutschland GmbH 11 * Copyright (C) 2018 - 2024 Intel Corporation 12 */ 13 14 #include <linux/delay.h> 15 #include <linux/fips.h> 16 #include <linux/if_ether.h> 17 #include <linux/skbuff.h> 18 #include <linux/if_arp.h> 19 #include <linux/etherdevice.h> 20 #include <linux/moduleparam.h> 21 #include <linux/rtnetlink.h> 22 #include <linux/crc32.h> 23 #include <linux/slab.h> 24 #include <linux/export.h> 25 #include <net/mac80211.h> 26 #include <asm/unaligned.h> 27 28 #include "ieee80211_i.h" 29 #include "driver-ops.h" 30 #include "rate.h" 31 #include "led.h" 32 #include "fils_aead.h" 33 34 #define IEEE80211_AUTH_TIMEOUT (HZ / 5) 35 #define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2) 36 #define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10) 37 #define IEEE80211_AUTH_TIMEOUT_SAE (HZ * 2) 38 #define IEEE80211_AUTH_MAX_TRIES 3 39 #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5) 40 #define IEEE80211_AUTH_WAIT_SAE_RETRY (HZ * 2) 41 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5) 42 #define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2) 43 #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10) 44 #define IEEE80211_ASSOC_MAX_TRIES 3 45 46 #define IEEE80211_ADV_TTLM_SAFETY_BUFFER_MS msecs_to_jiffies(100) 47 #define IEEE80211_ADV_TTLM_ST_UNDERFLOW 0xff00 48 49 #define IEEE80211_NEG_TTLM_REQ_TIMEOUT (HZ / 5) 50 51 static int max_nullfunc_tries = 2; 52 module_param(max_nullfunc_tries, int, 0644); 53 MODULE_PARM_DESC(max_nullfunc_tries, 54 "Maximum nullfunc tx tries before disconnecting (reason 4)."); 55 56 static int max_probe_tries = 5; 57 module_param(max_probe_tries, int, 0644); 58 MODULE_PARM_DESC(max_probe_tries, 59 "Maximum probe tries before disconnecting (reason 4)."); 60 61 /* 62 * Beacon loss timeout is calculated as N frames times the 63 * advertised beacon interval. This may need to be somewhat 64 * higher than what hardware might detect to account for 65 * delays in the host processing frames. But since we also 66 * probe on beacon miss before declaring the connection lost 67 * default to what we want. 68 */ 69 static int beacon_loss_count = 7; 70 module_param(beacon_loss_count, int, 0644); 71 MODULE_PARM_DESC(beacon_loss_count, 72 "Number of beacon intervals before we decide beacon was lost."); 73 74 /* 75 * Time the connection can be idle before we probe 76 * it to see if we can still talk to the AP. 77 */ 78 #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ) 79 /* 80 * Time we wait for a probe response after sending 81 * a probe request because of beacon loss or for 82 * checking the connection still works. 83 */ 84 static int probe_wait_ms = 500; 85 module_param(probe_wait_ms, int, 0644); 86 MODULE_PARM_DESC(probe_wait_ms, 87 "Maximum time(ms) to wait for probe response" 88 " before disconnecting (reason 4)."); 89 90 /* 91 * How many Beacon frames need to have been used in average signal strength 92 * before starting to indicate signal change events. 93 */ 94 #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4 95 96 /* 97 * We can have multiple work items (and connection probing) 98 * scheduling this timer, but we need to take care to only 99 * reschedule it when it should fire _earlier_ than it was 100 * asked for before, or if it's not pending right now. This 101 * function ensures that. Note that it then is required to 102 * run this function for all timeouts after the first one 103 * has happened -- the work that runs from this timer will 104 * do that. 105 */ 106 static void run_again(struct ieee80211_sub_if_data *sdata, 107 unsigned long timeout) 108 { 109 lockdep_assert_wiphy(sdata->local->hw.wiphy); 110 111 if (!timer_pending(&sdata->u.mgd.timer) || 112 time_before(timeout, sdata->u.mgd.timer.expires)) 113 mod_timer(&sdata->u.mgd.timer, timeout); 114 } 115 116 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata) 117 { 118 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER) 119 return; 120 121 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR)) 122 return; 123 124 mod_timer(&sdata->u.mgd.bcn_mon_timer, 125 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout)); 126 } 127 128 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata) 129 { 130 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 131 132 if (unlikely(!ifmgd->associated)) 133 return; 134 135 if (ifmgd->probe_send_count) 136 ifmgd->probe_send_count = 0; 137 138 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR)) 139 return; 140 141 mod_timer(&ifmgd->conn_mon_timer, 142 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME)); 143 } 144 145 static int ecw2cw(int ecw) 146 { 147 return (1 << ecw) - 1; 148 } 149 150 static enum ieee80211_conn_mode 151 ieee80211_determine_ap_chan(struct ieee80211_sub_if_data *sdata, 152 struct ieee80211_channel *channel, 153 u32 vht_cap_info, 154 const struct ieee802_11_elems *elems, 155 bool ignore_ht_channel_mismatch, 156 const struct ieee80211_conn_settings *conn, 157 struct cfg80211_chan_def *chandef) 158 { 159 const struct ieee80211_ht_operation *ht_oper = elems->ht_operation; 160 const struct ieee80211_vht_operation *vht_oper = elems->vht_operation; 161 const struct ieee80211_he_operation *he_oper = elems->he_operation; 162 const struct ieee80211_eht_operation *eht_oper = elems->eht_operation; 163 struct ieee80211_supported_band *sband = 164 sdata->local->hw.wiphy->bands[channel->band]; 165 struct cfg80211_chan_def vht_chandef; 166 bool no_vht = false; 167 u32 ht_cfreq; 168 169 *chandef = (struct cfg80211_chan_def) { 170 .chan = channel, 171 .width = NL80211_CHAN_WIDTH_20_NOHT, 172 .center_freq1 = channel->center_freq, 173 .freq1_offset = channel->freq_offset, 174 }; 175 176 /* get special S1G case out of the way */ 177 if (sband->band == NL80211_BAND_S1GHZ) { 178 if (!ieee80211_chandef_s1g_oper(elems->s1g_oper, chandef)) { 179 sdata_info(sdata, 180 "Missing S1G Operation Element? Trying operating == primary\n"); 181 chandef->width = ieee80211_s1g_channel_width(channel); 182 } 183 184 return IEEE80211_CONN_MODE_S1G; 185 } 186 187 /* get special 6 GHz case out of the way */ 188 if (sband->band == NL80211_BAND_6GHZ) { 189 enum ieee80211_conn_mode mode = IEEE80211_CONN_MODE_EHT; 190 191 /* this is an error */ 192 if (conn->mode < IEEE80211_CONN_MODE_HE) 193 return IEEE80211_CONN_MODE_LEGACY; 194 195 if (!elems->he_6ghz_capa || !elems->he_cap) { 196 sdata_info(sdata, 197 "HE 6 GHz AP is missing HE/HE 6 GHz band capability\n"); 198 return IEEE80211_CONN_MODE_LEGACY; 199 } 200 201 if (!eht_oper || !elems->eht_cap) { 202 eht_oper = NULL; 203 mode = IEEE80211_CONN_MODE_HE; 204 } 205 206 if (!ieee80211_chandef_he_6ghz_oper(sdata->local, he_oper, 207 eht_oper, chandef)) { 208 sdata_info(sdata, "bad HE/EHT 6 GHz operation\n"); 209 return IEEE80211_CONN_MODE_LEGACY; 210 } 211 212 return mode; 213 } 214 215 /* now we have the progression HT, VHT, ... */ 216 if (conn->mode < IEEE80211_CONN_MODE_HT) 217 return IEEE80211_CONN_MODE_LEGACY; 218 219 if (!ht_oper || !elems->ht_cap_elem) 220 return IEEE80211_CONN_MODE_LEGACY; 221 222 chandef->width = NL80211_CHAN_WIDTH_20; 223 224 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan, 225 channel->band); 226 /* check that channel matches the right operating channel */ 227 if (!ignore_ht_channel_mismatch && channel->center_freq != ht_cfreq) { 228 /* 229 * It's possible that some APs are confused here; 230 * Netgear WNDR3700 sometimes reports 4 higher than 231 * the actual channel in association responses, but 232 * since we look at probe response/beacon data here 233 * it should be OK. 234 */ 235 sdata_info(sdata, 236 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n", 237 channel->center_freq, ht_cfreq, 238 ht_oper->primary_chan, channel->band); 239 return IEEE80211_CONN_MODE_LEGACY; 240 } 241 242 ieee80211_chandef_ht_oper(ht_oper, chandef); 243 244 if (conn->mode < IEEE80211_CONN_MODE_VHT) 245 return IEEE80211_CONN_MODE_HT; 246 247 vht_chandef = *chandef; 248 249 /* 250 * having he_cap/he_oper parsed out implies we're at 251 * least operating as HE STA 252 */ 253 if (elems->he_cap && he_oper && 254 he_oper->he_oper_params & cpu_to_le32(IEEE80211_HE_OPERATION_VHT_OPER_INFO)) { 255 struct ieee80211_vht_operation he_oper_vht_cap; 256 257 /* 258 * Set only first 3 bytes (other 2 aren't used in 259 * ieee80211_chandef_vht_oper() anyway) 260 */ 261 memcpy(&he_oper_vht_cap, he_oper->optional, 3); 262 he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0); 263 264 if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_cap_info, 265 &he_oper_vht_cap, ht_oper, 266 &vht_chandef)) { 267 sdata_info(sdata, 268 "HE AP VHT information is invalid, disabling HE\n"); 269 /* this will cause us to re-parse as VHT STA */ 270 return IEEE80211_CONN_MODE_VHT; 271 } 272 } else if (!vht_oper || !elems->vht_cap_elem) { 273 if (sband->band == NL80211_BAND_5GHZ) { 274 sdata_info(sdata, 275 "VHT information is missing, disabling VHT\n"); 276 return IEEE80211_CONN_MODE_HT; 277 } 278 no_vht = true; 279 } else if (sband->band == NL80211_BAND_2GHZ) { 280 no_vht = true; 281 } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw, 282 vht_cap_info, 283 vht_oper, ht_oper, 284 &vht_chandef)) { 285 sdata_info(sdata, 286 "AP VHT information is invalid, disabling VHT\n"); 287 return IEEE80211_CONN_MODE_HT; 288 } 289 290 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) { 291 sdata_info(sdata, 292 "AP VHT information doesn't match HT, disabling VHT\n"); 293 return IEEE80211_CONN_MODE_HT; 294 } 295 296 *chandef = vht_chandef; 297 298 /* stick to current max mode if we or the AP don't have HE */ 299 if (conn->mode < IEEE80211_CONN_MODE_HE || 300 !elems->he_operation || !elems->he_cap) { 301 if (no_vht) 302 return IEEE80211_CONN_MODE_HT; 303 return IEEE80211_CONN_MODE_VHT; 304 } 305 306 /* stick to HE if we or the AP don't have EHT */ 307 if (conn->mode < IEEE80211_CONN_MODE_EHT || 308 !eht_oper || !elems->eht_cap) 309 return IEEE80211_CONN_MODE_HE; 310 311 /* 312 * handle the case that the EHT operation indicates that it holds EHT 313 * operation information (in case that the channel width differs from 314 * the channel width reported in HT/VHT/HE). 315 */ 316 if (eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT) { 317 struct cfg80211_chan_def eht_chandef = *chandef; 318 319 ieee80211_chandef_eht_oper((const void *)eht_oper->optional, 320 &eht_chandef); 321 322 eht_chandef.punctured = 323 ieee80211_eht_oper_dis_subchan_bitmap(eht_oper); 324 325 if (!cfg80211_chandef_valid(&eht_chandef)) { 326 sdata_info(sdata, 327 "AP EHT information is invalid, disabling EHT\n"); 328 return IEEE80211_CONN_MODE_HE; 329 } 330 331 if (!cfg80211_chandef_compatible(chandef, &eht_chandef)) { 332 sdata_info(sdata, 333 "AP EHT information doesn't match HT/VHT/HE, disabling EHT\n"); 334 return IEEE80211_CONN_MODE_HE; 335 } 336 337 *chandef = eht_chandef; 338 } 339 340 return IEEE80211_CONN_MODE_EHT; 341 } 342 343 static bool 344 ieee80211_verify_peer_he_mcs_support(struct ieee80211_sub_if_data *sdata, 345 const struct ieee80211_he_cap_elem *he_cap, 346 const struct ieee80211_he_operation *he_op) 347 { 348 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp; 349 u16 mcs_80_map_tx, mcs_80_map_rx; 350 u16 ap_min_req_set; 351 int nss; 352 353 if (!he_cap) 354 return false; 355 356 /* mcs_nss is right after he_cap info */ 357 he_mcs_nss_supp = (void *)(he_cap + 1); 358 359 mcs_80_map_tx = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80); 360 mcs_80_map_rx = le16_to_cpu(he_mcs_nss_supp->rx_mcs_80); 361 362 /* P802.11-REVme/D0.3 363 * 27.1.1 Introduction to the HE PHY 364 * ... 365 * An HE STA shall support the following features: 366 * ... 367 * Single spatial stream HE-MCSs 0 to 7 (transmit and receive) in all 368 * supported channel widths for HE SU PPDUs 369 */ 370 if ((mcs_80_map_tx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED || 371 (mcs_80_map_rx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED) { 372 sdata_info(sdata, 373 "Missing mandatory rates for 1 Nss, rx 0x%x, tx 0x%x, disable HE\n", 374 mcs_80_map_tx, mcs_80_map_rx); 375 return false; 376 } 377 378 if (!he_op) 379 return true; 380 381 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set); 382 383 /* 384 * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all 385 * zeroes, which is nonsense, and completely inconsistent with itself 386 * (it doesn't have 8 streams). Accept the settings in this case anyway. 387 */ 388 if (!ap_min_req_set) 389 return true; 390 391 /* make sure the AP is consistent with itself 392 * 393 * P802.11-REVme/D0.3 394 * 26.17.1 Basic HE BSS operation 395 * 396 * A STA that is operating in an HE BSS shall be able to receive and 397 * transmit at each of the <HE-MCS, NSS> tuple values indicated by the 398 * Basic HE-MCS And NSS Set field of the HE Operation parameter of the 399 * MLME-START.request primitive and shall be able to receive at each of 400 * the <HE-MCS, NSS> tuple values indicated by the Supported HE-MCS and 401 * NSS Set field in the HE Capabilities parameter of the MLMESTART.request 402 * primitive 403 */ 404 for (nss = 8; nss > 0; nss--) { 405 u8 ap_op_val = (ap_min_req_set >> (2 * (nss - 1))) & 3; 406 u8 ap_rx_val; 407 u8 ap_tx_val; 408 409 if (ap_op_val == IEEE80211_HE_MCS_NOT_SUPPORTED) 410 continue; 411 412 ap_rx_val = (mcs_80_map_rx >> (2 * (nss - 1))) & 3; 413 ap_tx_val = (mcs_80_map_tx >> (2 * (nss - 1))) & 3; 414 415 if (ap_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED || 416 ap_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED || 417 ap_rx_val < ap_op_val || ap_tx_val < ap_op_val) { 418 sdata_info(sdata, 419 "Invalid rates for %d Nss, rx %d, tx %d oper %d, disable HE\n", 420 nss, ap_rx_val, ap_rx_val, ap_op_val); 421 return false; 422 } 423 } 424 425 return true; 426 } 427 428 static bool 429 ieee80211_verify_sta_he_mcs_support(struct ieee80211_sub_if_data *sdata, 430 struct ieee80211_supported_band *sband, 431 const struct ieee80211_he_operation *he_op) 432 { 433 const struct ieee80211_sta_he_cap *sta_he_cap = 434 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif); 435 u16 ap_min_req_set; 436 int i; 437 438 if (!sta_he_cap || !he_op) 439 return false; 440 441 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set); 442 443 /* 444 * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all 445 * zeroes, which is nonsense, and completely inconsistent with itself 446 * (it doesn't have 8 streams). Accept the settings in this case anyway. 447 */ 448 if (!ap_min_req_set) 449 return true; 450 451 /* Need to go over for 80MHz, 160MHz and for 80+80 */ 452 for (i = 0; i < 3; i++) { 453 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp = 454 &sta_he_cap->he_mcs_nss_supp; 455 u16 sta_mcs_map_rx = 456 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]); 457 u16 sta_mcs_map_tx = 458 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]); 459 u8 nss; 460 bool verified = true; 461 462 /* 463 * For each band there is a maximum of 8 spatial streams 464 * possible. Each of the sta_mcs_map_* is a 16-bit struct built 465 * of 2 bits per NSS (1-8), with the values defined in enum 466 * ieee80211_he_mcs_support. Need to make sure STA TX and RX 467 * capabilities aren't less than the AP's minimum requirements 468 * for this HE BSS per SS. 469 * It is enough to find one such band that meets the reqs. 470 */ 471 for (nss = 8; nss > 0; nss--) { 472 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3; 473 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3; 474 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3; 475 476 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED) 477 continue; 478 479 /* 480 * Make sure the HE AP doesn't require MCSs that aren't 481 * supported by the client as required by spec 482 * 483 * P802.11-REVme/D0.3 484 * 26.17.1 Basic HE BSS operation 485 * 486 * An HE STA shall not attempt to join * (MLME-JOIN.request primitive) 487 * a BSS, unless it supports (i.e., is able to both transmit and 488 * receive using) all of the <HE-MCS, NSS> tuples in the basic 489 * HE-MCS and NSS set. 490 */ 491 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED || 492 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED || 493 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) { 494 verified = false; 495 break; 496 } 497 } 498 499 if (verified) 500 return true; 501 } 502 503 /* If here, STA doesn't meet AP's HE min requirements */ 504 return false; 505 } 506 507 static u8 508 ieee80211_get_eht_cap_mcs_nss(const struct ieee80211_sta_he_cap *sta_he_cap, 509 const struct ieee80211_sta_eht_cap *sta_eht_cap, 510 unsigned int idx, int bw) 511 { 512 u8 he_phy_cap0 = sta_he_cap->he_cap_elem.phy_cap_info[0]; 513 u8 eht_phy_cap0 = sta_eht_cap->eht_cap_elem.phy_cap_info[0]; 514 515 /* handle us being a 20 MHz-only EHT STA - with four values 516 * for MCS 0-7, 8-9, 10-11, 12-13. 517 */ 518 if (!(he_phy_cap0 & IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_MASK_ALL)) 519 return sta_eht_cap->eht_mcs_nss_supp.only_20mhz.rx_tx_max_nss[idx]; 520 521 /* the others have MCS 0-9 together, rather than separately from 0-7 */ 522 if (idx > 0) 523 idx--; 524 525 switch (bw) { 526 case 0: 527 return sta_eht_cap->eht_mcs_nss_supp.bw._80.rx_tx_max_nss[idx]; 528 case 1: 529 if (!(he_phy_cap0 & 530 (IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G | 531 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G))) 532 return 0xff; /* pass check */ 533 return sta_eht_cap->eht_mcs_nss_supp.bw._160.rx_tx_max_nss[idx]; 534 case 2: 535 if (!(eht_phy_cap0 & IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ)) 536 return 0xff; /* pass check */ 537 return sta_eht_cap->eht_mcs_nss_supp.bw._320.rx_tx_max_nss[idx]; 538 } 539 540 WARN_ON(1); 541 return 0; 542 } 543 544 static bool 545 ieee80211_verify_sta_eht_mcs_support(struct ieee80211_sub_if_data *sdata, 546 struct ieee80211_supported_band *sband, 547 const struct ieee80211_eht_operation *eht_op) 548 { 549 const struct ieee80211_sta_he_cap *sta_he_cap = 550 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif); 551 const struct ieee80211_sta_eht_cap *sta_eht_cap = 552 ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif); 553 const struct ieee80211_eht_mcs_nss_supp_20mhz_only *req; 554 unsigned int i; 555 556 if (!sta_he_cap || !sta_eht_cap || !eht_op) 557 return false; 558 559 req = &eht_op->basic_mcs_nss; 560 561 for (i = 0; i < ARRAY_SIZE(req->rx_tx_max_nss); i++) { 562 u8 req_rx_nss, req_tx_nss; 563 unsigned int bw; 564 565 req_rx_nss = u8_get_bits(req->rx_tx_max_nss[i], 566 IEEE80211_EHT_MCS_NSS_RX); 567 req_tx_nss = u8_get_bits(req->rx_tx_max_nss[i], 568 IEEE80211_EHT_MCS_NSS_TX); 569 570 for (bw = 0; bw < 3; bw++) { 571 u8 have, have_rx_nss, have_tx_nss; 572 573 have = ieee80211_get_eht_cap_mcs_nss(sta_he_cap, 574 sta_eht_cap, 575 i, bw); 576 have_rx_nss = u8_get_bits(have, 577 IEEE80211_EHT_MCS_NSS_RX); 578 have_tx_nss = u8_get_bits(have, 579 IEEE80211_EHT_MCS_NSS_TX); 580 581 if (req_rx_nss > have_rx_nss || 582 req_tx_nss > have_tx_nss) 583 return false; 584 } 585 } 586 587 return true; 588 } 589 590 static bool ieee80211_chandef_usable(struct ieee80211_sub_if_data *sdata, 591 const struct cfg80211_chan_def *chandef, 592 u32 prohibited_flags) 593 { 594 if (!cfg80211_chandef_usable(sdata->local->hw.wiphy, 595 chandef, prohibited_flags)) 596 return false; 597 598 if (chandef->punctured && 599 ieee80211_hw_check(&sdata->local->hw, DISALLOW_PUNCTURING)) 600 return false; 601 602 return true; 603 } 604 605 static struct ieee802_11_elems * 606 ieee80211_determine_chan_mode(struct ieee80211_sub_if_data *sdata, 607 struct ieee80211_conn_settings *conn, 608 struct cfg80211_bss *cbss, int link_id, 609 struct ieee80211_chan_req *chanreq) 610 { 611 const struct cfg80211_bss_ies *ies = rcu_dereference(cbss->ies); 612 struct ieee80211_bss *bss = (void *)cbss->priv; 613 struct ieee80211_channel *channel = cbss->channel; 614 struct ieee80211_elems_parse_params parse_params = { 615 .link_id = -1, 616 .from_ap = true, 617 .start = ies->data, 618 .len = ies->len, 619 .mode = conn->mode, 620 }; 621 struct ieee802_11_elems *elems; 622 struct ieee80211_supported_band *sband; 623 struct cfg80211_chan_def ap_chandef; 624 enum ieee80211_conn_mode ap_mode; 625 int ret; 626 627 again: 628 elems = ieee802_11_parse_elems_full(&parse_params); 629 if (!elems) 630 return ERR_PTR(-ENOMEM); 631 632 ap_mode = ieee80211_determine_ap_chan(sdata, channel, bss->vht_cap_info, 633 elems, false, conn, &ap_chandef); 634 635 mlme_link_id_dbg(sdata, link_id, "determined AP %pM to be %s\n", 636 cbss->bssid, ieee80211_conn_mode_str(ap_mode)); 637 638 /* this should be impossible since parsing depends on our mode */ 639 if (WARN_ON(ap_mode > conn->mode)) { 640 ret = -EINVAL; 641 goto free; 642 } 643 644 sband = sdata->local->hw.wiphy->bands[channel->band]; 645 646 switch (channel->band) { 647 case NL80211_BAND_S1GHZ: 648 if (WARN_ON(ap_mode != IEEE80211_CONN_MODE_S1G)) { 649 ret = -EINVAL; 650 goto free; 651 } 652 return elems; 653 case NL80211_BAND_6GHZ: 654 if (ap_mode < IEEE80211_CONN_MODE_HE) { 655 sdata_info(sdata, 656 "Rejecting non-HE 6/7 GHz connection"); 657 ret = -EINVAL; 658 goto free; 659 } 660 break; 661 default: 662 if (WARN_ON(ap_mode == IEEE80211_CONN_MODE_S1G)) { 663 ret = -EINVAL; 664 goto free; 665 } 666 } 667 668 switch (ap_mode) { 669 case IEEE80211_CONN_MODE_S1G: 670 WARN_ON(1); 671 ret = -EINVAL; 672 goto free; 673 case IEEE80211_CONN_MODE_LEGACY: 674 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20; 675 break; 676 case IEEE80211_CONN_MODE_HT: 677 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit, 678 conn->bw_limit, 679 IEEE80211_CONN_BW_LIMIT_40); 680 break; 681 case IEEE80211_CONN_MODE_VHT: 682 case IEEE80211_CONN_MODE_HE: 683 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit, 684 conn->bw_limit, 685 IEEE80211_CONN_BW_LIMIT_160); 686 break; 687 case IEEE80211_CONN_MODE_EHT: 688 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit, 689 conn->bw_limit, 690 IEEE80211_CONN_BW_LIMIT_320); 691 break; 692 } 693 694 conn->mode = ap_mode; 695 chanreq->oper = ap_chandef; 696 697 /* wider-bandwidth OFDMA is only done in EHT */ 698 if (conn->mode >= IEEE80211_CONN_MODE_EHT && 699 !(sdata->vif.driver_flags & IEEE80211_VIF_IGNORE_OFDMA_WIDER_BW)) 700 chanreq->ap = ap_chandef; 701 else 702 chanreq->ap.chan = NULL; 703 704 while (!ieee80211_chandef_usable(sdata, &chanreq->oper, 705 IEEE80211_CHAN_DISABLED)) { 706 if (WARN_ON(chanreq->oper.width == NL80211_CHAN_WIDTH_20_NOHT)) { 707 ret = -EINVAL; 708 goto free; 709 } 710 711 ieee80211_chanreq_downgrade(chanreq, conn); 712 } 713 714 if (conn->mode >= IEEE80211_CONN_MODE_HE && 715 !cfg80211_chandef_usable(sdata->wdev.wiphy, &chanreq->oper, 716 IEEE80211_CHAN_NO_HE)) { 717 conn->mode = IEEE80211_CONN_MODE_VHT; 718 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit, 719 conn->bw_limit, 720 IEEE80211_CONN_BW_LIMIT_160); 721 } 722 723 if (conn->mode >= IEEE80211_CONN_MODE_EHT && 724 !cfg80211_chandef_usable(sdata->wdev.wiphy, &chanreq->oper, 725 IEEE80211_CHAN_NO_EHT)) { 726 conn->mode = IEEE80211_CONN_MODE_HE; 727 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit, 728 conn->bw_limit, 729 IEEE80211_CONN_BW_LIMIT_160); 730 } 731 732 if (chanreq->oper.width != ap_chandef.width || ap_mode != conn->mode) 733 sdata_info(sdata, 734 "regulatory prevented using AP config, downgraded\n"); 735 736 if (conn->mode >= IEEE80211_CONN_MODE_HE && 737 (!ieee80211_verify_peer_he_mcs_support(sdata, (void *)elems->he_cap, 738 elems->he_operation) || 739 !ieee80211_verify_sta_he_mcs_support(sdata, sband, 740 elems->he_operation))) { 741 conn->mode = IEEE80211_CONN_MODE_VHT; 742 sdata_info(sdata, "required MCSes not supported, disabling HE\n"); 743 } 744 745 if (conn->mode >= IEEE80211_CONN_MODE_EHT && 746 !ieee80211_verify_sta_eht_mcs_support(sdata, sband, 747 elems->eht_operation)) { 748 conn->mode = IEEE80211_CONN_MODE_HE; 749 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit, 750 conn->bw_limit, 751 IEEE80211_CONN_BW_LIMIT_160); 752 sdata_info(sdata, "required MCSes not supported, disabling EHT\n"); 753 } 754 755 /* the mode can only decrease, so this must terminate */ 756 if (ap_mode != conn->mode) 757 goto again; 758 759 mlme_link_id_dbg(sdata, link_id, 760 "connecting with %s mode, max bandwidth %d MHz\n", 761 ieee80211_conn_mode_str(conn->mode), 762 20 * (1 << conn->bw_limit)); 763 764 if (WARN_ON_ONCE(!cfg80211_chandef_valid(&chanreq->oper))) { 765 ret = -EINVAL; 766 goto free; 767 } 768 769 return elems; 770 free: 771 kfree(elems); 772 return ERR_PTR(ret); 773 } 774 775 static int ieee80211_config_bw(struct ieee80211_link_data *link, 776 struct ieee802_11_elems *elems, 777 bool update, u64 *changed) 778 { 779 struct ieee80211_channel *channel = link->conf->chanreq.oper.chan; 780 struct ieee80211_sub_if_data *sdata = link->sdata; 781 struct ieee80211_chan_req chanreq = {}; 782 enum ieee80211_conn_mode ap_mode; 783 u32 vht_cap_info = 0; 784 u16 ht_opmode; 785 int ret; 786 787 /* don't track any bandwidth changes in legacy/S1G modes */ 788 if (link->u.mgd.conn.mode == IEEE80211_CONN_MODE_LEGACY || 789 link->u.mgd.conn.mode == IEEE80211_CONN_MODE_S1G) 790 return 0; 791 792 if (elems->vht_cap_elem) 793 vht_cap_info = le32_to_cpu(elems->vht_cap_elem->vht_cap_info); 794 795 ap_mode = ieee80211_determine_ap_chan(sdata, channel, vht_cap_info, 796 elems, true, &link->u.mgd.conn, 797 &chanreq.ap); 798 799 if (ap_mode != link->u.mgd.conn.mode) { 800 link_info(link, 801 "AP appears to change mode (expected %s, found %s), disconnect\n", 802 ieee80211_conn_mode_str(link->u.mgd.conn.mode), 803 ieee80211_conn_mode_str(ap_mode)); 804 return -EINVAL; 805 } 806 807 chanreq.oper = chanreq.ap; 808 if (link->u.mgd.conn.mode < IEEE80211_CONN_MODE_EHT || 809 sdata->vif.driver_flags & IEEE80211_VIF_IGNORE_OFDMA_WIDER_BW) 810 chanreq.ap.chan = NULL; 811 812 /* 813 * if HT operation mode changed store the new one - 814 * this may be applicable even if channel is identical 815 */ 816 if (elems->ht_operation) { 817 ht_opmode = le16_to_cpu(elems->ht_operation->operation_mode); 818 if (link->conf->ht_operation_mode != ht_opmode) { 819 *changed |= BSS_CHANGED_HT; 820 link->conf->ht_operation_mode = ht_opmode; 821 } 822 } 823 824 /* 825 * Downgrade the new channel if we associated with restricted 826 * bandwidth capabilities. For example, if we associated as a 827 * 20 MHz STA to a 40 MHz AP (due to regulatory, capabilities 828 * or config reasons) then switching to a 40 MHz channel now 829 * won't do us any good -- we couldn't use it with the AP. 830 */ 831 while (link->u.mgd.conn.bw_limit < 832 ieee80211_min_bw_limit_from_chandef(&chanreq.oper)) 833 ieee80211_chandef_downgrade(&chanreq.oper, NULL); 834 835 if (ieee80211_chanreq_identical(&chanreq, &link->conf->chanreq)) 836 return 0; 837 838 link_info(link, 839 "AP %pM changed bandwidth, new used config is %d.%03d MHz, width %d (%d.%03d/%d MHz)\n", 840 link->u.mgd.bssid, chanreq.oper.chan->center_freq, 841 chanreq.oper.chan->freq_offset, chanreq.oper.width, 842 chanreq.oper.center_freq1, chanreq.oper.freq1_offset, 843 chanreq.oper.center_freq2); 844 845 if (!cfg80211_chandef_valid(&chanreq.oper)) { 846 sdata_info(sdata, 847 "AP %pM changed caps/bw in a way we can't support - disconnect\n", 848 link->u.mgd.bssid); 849 return -EINVAL; 850 } 851 852 if (!update) { 853 link->conf->chanreq = chanreq; 854 return 0; 855 } 856 857 /* 858 * We're tracking the current AP here, so don't do any further checks 859 * here. This keeps us from playing ping-pong with regulatory, without 860 * it the following can happen (for example): 861 * - connect to an AP with 80 MHz, world regdom allows 80 MHz 862 * - AP advertises regdom US 863 * - CRDA loads regdom US with 80 MHz prohibited (old database) 864 * - we detect an unsupported channel and disconnect 865 * - disconnect causes CRDA to reload world regdomain and the game 866 * starts anew. 867 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881) 868 * 869 * It seems possible that there are still scenarios with CSA or real 870 * bandwidth changes where a this could happen, but those cases are 871 * less common and wouldn't completely prevent using the AP. 872 */ 873 874 ret = ieee80211_link_change_chanreq(link, &chanreq, changed); 875 if (ret) { 876 sdata_info(sdata, 877 "AP %pM changed bandwidth to incompatible one - disconnect\n", 878 link->u.mgd.bssid); 879 return ret; 880 } 881 882 cfg80211_schedule_channels_check(&sdata->wdev); 883 return 0; 884 } 885 886 /* frame sending functions */ 887 888 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata, 889 struct sk_buff *skb, u8 ap_ht_param, 890 struct ieee80211_supported_band *sband, 891 struct ieee80211_channel *channel, 892 enum ieee80211_smps_mode smps, 893 const struct ieee80211_conn_settings *conn) 894 { 895 u8 *pos; 896 u32 flags = channel->flags; 897 u16 cap; 898 struct ieee80211_sta_ht_cap ht_cap; 899 900 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap)); 901 902 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap)); 903 ieee80211_apply_htcap_overrides(sdata, &ht_cap); 904 905 /* determine capability flags */ 906 cap = ht_cap.cap; 907 908 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { 909 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: 910 if (flags & IEEE80211_CHAN_NO_HT40PLUS) { 911 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; 912 cap &= ~IEEE80211_HT_CAP_SGI_40; 913 } 914 break; 915 case IEEE80211_HT_PARAM_CHA_SEC_BELOW: 916 if (flags & IEEE80211_CHAN_NO_HT40MINUS) { 917 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; 918 cap &= ~IEEE80211_HT_CAP_SGI_40; 919 } 920 break; 921 } 922 923 /* 924 * If 40 MHz was disabled associate as though we weren't 925 * capable of 40 MHz -- some broken APs will never fall 926 * back to trying to transmit in 20 MHz. 927 */ 928 if (conn->bw_limit <= IEEE80211_CONN_BW_LIMIT_20) { 929 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; 930 cap &= ~IEEE80211_HT_CAP_SGI_40; 931 } 932 933 /* set SM PS mode properly */ 934 cap &= ~IEEE80211_HT_CAP_SM_PS; 935 switch (smps) { 936 case IEEE80211_SMPS_AUTOMATIC: 937 case IEEE80211_SMPS_NUM_MODES: 938 WARN_ON(1); 939 fallthrough; 940 case IEEE80211_SMPS_OFF: 941 cap |= WLAN_HT_CAP_SM_PS_DISABLED << 942 IEEE80211_HT_CAP_SM_PS_SHIFT; 943 break; 944 case IEEE80211_SMPS_STATIC: 945 cap |= WLAN_HT_CAP_SM_PS_STATIC << 946 IEEE80211_HT_CAP_SM_PS_SHIFT; 947 break; 948 case IEEE80211_SMPS_DYNAMIC: 949 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC << 950 IEEE80211_HT_CAP_SM_PS_SHIFT; 951 break; 952 } 953 954 /* reserve and fill IE */ 955 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2); 956 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap); 957 } 958 959 /* This function determines vht capability flags for the association 960 * and builds the IE. 961 * Note - the function returns true to own the MU-MIMO capability 962 */ 963 static bool ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata, 964 struct sk_buff *skb, 965 struct ieee80211_supported_band *sband, 966 struct ieee80211_vht_cap *ap_vht_cap, 967 const struct ieee80211_conn_settings *conn) 968 { 969 struct ieee80211_local *local = sdata->local; 970 u8 *pos; 971 u32 cap; 972 struct ieee80211_sta_vht_cap vht_cap; 973 u32 mask, ap_bf_sts, our_bf_sts; 974 bool mu_mimo_owner = false; 975 976 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap)); 977 978 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap)); 979 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap); 980 981 /* determine capability flags */ 982 cap = vht_cap.cap; 983 984 if (conn->bw_limit <= IEEE80211_CONN_BW_LIMIT_80) { 985 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160; 986 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; 987 } 988 989 /* 990 * Some APs apparently get confused if our capabilities are better 991 * than theirs, so restrict what we advertise in the assoc request. 992 */ 993 if (!(ap_vht_cap->vht_cap_info & 994 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE))) 995 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | 996 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE); 997 else if (!(ap_vht_cap->vht_cap_info & 998 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))) 999 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE; 1000 1001 /* 1002 * If some other vif is using the MU-MIMO capability we cannot associate 1003 * using MU-MIMO - this will lead to contradictions in the group-id 1004 * mechanism. 1005 * Ownership is defined since association request, in order to avoid 1006 * simultaneous associations with MU-MIMO. 1007 */ 1008 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) { 1009 bool disable_mu_mimo = false; 1010 struct ieee80211_sub_if_data *other; 1011 1012 list_for_each_entry_rcu(other, &local->interfaces, list) { 1013 if (other->vif.bss_conf.mu_mimo_owner) { 1014 disable_mu_mimo = true; 1015 break; 1016 } 1017 } 1018 if (disable_mu_mimo) 1019 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE; 1020 else 1021 mu_mimo_owner = true; 1022 } 1023 1024 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK; 1025 1026 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask; 1027 our_bf_sts = cap & mask; 1028 1029 if (ap_bf_sts < our_bf_sts) { 1030 cap &= ~mask; 1031 cap |= ap_bf_sts; 1032 } 1033 1034 /* reserve and fill IE */ 1035 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2); 1036 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap); 1037 1038 return mu_mimo_owner; 1039 } 1040 1041 static void ieee80211_assoc_add_rates(struct sk_buff *skb, 1042 enum nl80211_chan_width width, 1043 struct ieee80211_supported_band *sband, 1044 struct ieee80211_mgd_assoc_data *assoc_data) 1045 { 1046 u32 rates; 1047 1048 if (assoc_data->supp_rates_len) { 1049 /* 1050 * Get all rates supported by the device and the AP as 1051 * some APs don't like getting a superset of their rates 1052 * in the association request (e.g. D-Link DAP 1353 in 1053 * b-only mode)... 1054 */ 1055 ieee80211_parse_bitrates(width, sband, 1056 assoc_data->supp_rates, 1057 assoc_data->supp_rates_len, 1058 &rates); 1059 } else { 1060 /* 1061 * In case AP not provide any supported rates information 1062 * before association, we send information element(s) with 1063 * all rates that we support. 1064 */ 1065 rates = ~0; 1066 } 1067 1068 ieee80211_put_srates_elem(skb, sband, 0, 0, ~rates, 1069 WLAN_EID_SUPP_RATES); 1070 ieee80211_put_srates_elem(skb, sband, 0, 0, ~rates, 1071 WLAN_EID_EXT_SUPP_RATES); 1072 } 1073 1074 static size_t ieee80211_add_before_ht_elems(struct sk_buff *skb, 1075 const u8 *elems, 1076 size_t elems_len, 1077 size_t offset) 1078 { 1079 size_t noffset; 1080 1081 static const u8 before_ht[] = { 1082 WLAN_EID_SSID, 1083 WLAN_EID_SUPP_RATES, 1084 WLAN_EID_EXT_SUPP_RATES, 1085 WLAN_EID_PWR_CAPABILITY, 1086 WLAN_EID_SUPPORTED_CHANNELS, 1087 WLAN_EID_RSN, 1088 WLAN_EID_QOS_CAPA, 1089 WLAN_EID_RRM_ENABLED_CAPABILITIES, 1090 WLAN_EID_MOBILITY_DOMAIN, 1091 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */ 1092 WLAN_EID_RIC_DATA, /* reassoc only */ 1093 WLAN_EID_SUPPORTED_REGULATORY_CLASSES, 1094 }; 1095 static const u8 after_ric[] = { 1096 WLAN_EID_SUPPORTED_REGULATORY_CLASSES, 1097 WLAN_EID_HT_CAPABILITY, 1098 WLAN_EID_BSS_COEX_2040, 1099 /* luckily this is almost always there */ 1100 WLAN_EID_EXT_CAPABILITY, 1101 WLAN_EID_QOS_TRAFFIC_CAPA, 1102 WLAN_EID_TIM_BCAST_REQ, 1103 WLAN_EID_INTERWORKING, 1104 /* 60 GHz (Multi-band, DMG, MMS) can't happen */ 1105 WLAN_EID_VHT_CAPABILITY, 1106 WLAN_EID_OPMODE_NOTIF, 1107 }; 1108 1109 if (!elems_len) 1110 return offset; 1111 1112 noffset = ieee80211_ie_split_ric(elems, elems_len, 1113 before_ht, 1114 ARRAY_SIZE(before_ht), 1115 after_ric, 1116 ARRAY_SIZE(after_ric), 1117 offset); 1118 skb_put_data(skb, elems + offset, noffset - offset); 1119 1120 return noffset; 1121 } 1122 1123 static size_t ieee80211_add_before_vht_elems(struct sk_buff *skb, 1124 const u8 *elems, 1125 size_t elems_len, 1126 size_t offset) 1127 { 1128 static const u8 before_vht[] = { 1129 /* 1130 * no need to list the ones split off before HT 1131 * or generated here 1132 */ 1133 WLAN_EID_BSS_COEX_2040, 1134 WLAN_EID_EXT_CAPABILITY, 1135 WLAN_EID_QOS_TRAFFIC_CAPA, 1136 WLAN_EID_TIM_BCAST_REQ, 1137 WLAN_EID_INTERWORKING, 1138 /* 60 GHz (Multi-band, DMG, MMS) can't happen */ 1139 }; 1140 size_t noffset; 1141 1142 if (!elems_len) 1143 return offset; 1144 1145 /* RIC already taken care of in ieee80211_add_before_ht_elems() */ 1146 noffset = ieee80211_ie_split(elems, elems_len, 1147 before_vht, ARRAY_SIZE(before_vht), 1148 offset); 1149 skb_put_data(skb, elems + offset, noffset - offset); 1150 1151 return noffset; 1152 } 1153 1154 static size_t ieee80211_add_before_he_elems(struct sk_buff *skb, 1155 const u8 *elems, 1156 size_t elems_len, 1157 size_t offset) 1158 { 1159 static const u8 before_he[] = { 1160 /* 1161 * no need to list the ones split off before VHT 1162 * or generated here 1163 */ 1164 WLAN_EID_OPMODE_NOTIF, 1165 WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE, 1166 /* 11ai elements */ 1167 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION, 1168 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY, 1169 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM, 1170 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER, 1171 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN, 1172 /* TODO: add 11ah/11aj/11ak elements */ 1173 }; 1174 size_t noffset; 1175 1176 if (!elems_len) 1177 return offset; 1178 1179 /* RIC already taken care of in ieee80211_add_before_ht_elems() */ 1180 noffset = ieee80211_ie_split(elems, elems_len, 1181 before_he, ARRAY_SIZE(before_he), 1182 offset); 1183 skb_put_data(skb, elems + offset, noffset - offset); 1184 1185 return noffset; 1186 } 1187 1188 #define PRESENT_ELEMS_MAX 8 1189 #define PRESENT_ELEM_EXT_OFFS 0x100 1190 1191 static void ieee80211_assoc_add_ml_elem(struct ieee80211_sub_if_data *sdata, 1192 struct sk_buff *skb, u16 capab, 1193 const struct element *ext_capa, 1194 const u16 *present_elems); 1195 1196 static size_t ieee80211_assoc_link_elems(struct ieee80211_sub_if_data *sdata, 1197 struct sk_buff *skb, u16 *capab, 1198 const struct element *ext_capa, 1199 const u8 *extra_elems, 1200 size_t extra_elems_len, 1201 unsigned int link_id, 1202 struct ieee80211_link_data *link, 1203 u16 *present_elems) 1204 { 1205 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif); 1206 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1207 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; 1208 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss; 1209 struct ieee80211_channel *chan = cbss->channel; 1210 const struct ieee80211_sband_iftype_data *iftd; 1211 struct ieee80211_local *local = sdata->local; 1212 struct ieee80211_supported_band *sband; 1213 enum nl80211_chan_width width = NL80211_CHAN_WIDTH_20; 1214 struct ieee80211_chanctx_conf *chanctx_conf; 1215 enum ieee80211_smps_mode smps_mode; 1216 u16 orig_capab = *capab; 1217 size_t offset = 0; 1218 int present_elems_len = 0; 1219 u8 *pos; 1220 int i; 1221 1222 #define ADD_PRESENT_ELEM(id) do { \ 1223 /* need a last for termination - we use 0 == SSID */ \ 1224 if (!WARN_ON(present_elems_len >= PRESENT_ELEMS_MAX - 1)) \ 1225 present_elems[present_elems_len++] = (id); \ 1226 } while (0) 1227 #define ADD_PRESENT_EXT_ELEM(id) ADD_PRESENT_ELEM(PRESENT_ELEM_EXT_OFFS | (id)) 1228 1229 if (link) 1230 smps_mode = link->smps_mode; 1231 else if (sdata->u.mgd.powersave) 1232 smps_mode = IEEE80211_SMPS_DYNAMIC; 1233 else 1234 smps_mode = IEEE80211_SMPS_OFF; 1235 1236 if (link) { 1237 /* 1238 * 5/10 MHz scenarios are only viable without MLO, in which 1239 * case this pointer should be used ... All of this is a bit 1240 * unclear though, not sure this even works at all. 1241 */ 1242 rcu_read_lock(); 1243 chanctx_conf = rcu_dereference(link->conf->chanctx_conf); 1244 if (chanctx_conf) 1245 width = chanctx_conf->def.width; 1246 rcu_read_unlock(); 1247 } 1248 1249 sband = local->hw.wiphy->bands[chan->band]; 1250 iftd = ieee80211_get_sband_iftype_data(sband, iftype); 1251 1252 if (sband->band == NL80211_BAND_2GHZ) { 1253 *capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME; 1254 *capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; 1255 } 1256 1257 if ((cbss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) && 1258 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT)) 1259 *capab |= WLAN_CAPABILITY_SPECTRUM_MGMT; 1260 1261 if (sband->band != NL80211_BAND_S1GHZ) 1262 ieee80211_assoc_add_rates(skb, width, sband, assoc_data); 1263 1264 if (*capab & WLAN_CAPABILITY_SPECTRUM_MGMT || 1265 *capab & WLAN_CAPABILITY_RADIO_MEASURE) { 1266 struct cfg80211_chan_def chandef = { 1267 .width = width, 1268 .chan = chan, 1269 }; 1270 1271 pos = skb_put(skb, 4); 1272 *pos++ = WLAN_EID_PWR_CAPABILITY; 1273 *pos++ = 2; 1274 *pos++ = 0; /* min tx power */ 1275 /* max tx power */ 1276 *pos++ = ieee80211_chandef_max_power(&chandef); 1277 ADD_PRESENT_ELEM(WLAN_EID_PWR_CAPABILITY); 1278 } 1279 1280 /* 1281 * Per spec, we shouldn't include the list of channels if we advertise 1282 * support for extended channel switching, but we've always done that; 1283 * (for now?) apply this restriction only on the (new) 6 GHz band. 1284 */ 1285 if (*capab & WLAN_CAPABILITY_SPECTRUM_MGMT && 1286 (sband->band != NL80211_BAND_6GHZ || 1287 !ext_capa || ext_capa->datalen < 1 || 1288 !(ext_capa->data[0] & WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING))) { 1289 /* TODO: get this in reg domain format */ 1290 pos = skb_put(skb, 2 * sband->n_channels + 2); 1291 *pos++ = WLAN_EID_SUPPORTED_CHANNELS; 1292 *pos++ = 2 * sband->n_channels; 1293 for (i = 0; i < sband->n_channels; i++) { 1294 int cf = sband->channels[i].center_freq; 1295 1296 *pos++ = ieee80211_frequency_to_channel(cf); 1297 *pos++ = 1; /* one channel in the subband*/ 1298 } 1299 ADD_PRESENT_ELEM(WLAN_EID_SUPPORTED_CHANNELS); 1300 } 1301 1302 /* if present, add any custom IEs that go before HT */ 1303 offset = ieee80211_add_before_ht_elems(skb, extra_elems, 1304 extra_elems_len, 1305 offset); 1306 1307 if (sband->band != NL80211_BAND_6GHZ && 1308 assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_HT) { 1309 ieee80211_add_ht_ie(sdata, skb, 1310 assoc_data->link[link_id].ap_ht_param, 1311 sband, chan, smps_mode, 1312 &assoc_data->link[link_id].conn); 1313 ADD_PRESENT_ELEM(WLAN_EID_HT_CAPABILITY); 1314 } 1315 1316 /* if present, add any custom IEs that go before VHT */ 1317 offset = ieee80211_add_before_vht_elems(skb, extra_elems, 1318 extra_elems_len, 1319 offset); 1320 1321 if (sband->band != NL80211_BAND_6GHZ && 1322 assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_VHT && 1323 sband->vht_cap.vht_supported) { 1324 bool mu_mimo_owner = 1325 ieee80211_add_vht_ie(sdata, skb, sband, 1326 &assoc_data->link[link_id].ap_vht_cap, 1327 &assoc_data->link[link_id].conn); 1328 1329 if (link) 1330 link->conf->mu_mimo_owner = mu_mimo_owner; 1331 ADD_PRESENT_ELEM(WLAN_EID_VHT_CAPABILITY); 1332 } 1333 1334 /* if present, add any custom IEs that go before HE */ 1335 offset = ieee80211_add_before_he_elems(skb, extra_elems, 1336 extra_elems_len, 1337 offset); 1338 1339 if (assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_HE) { 1340 ieee80211_put_he_cap(skb, sdata, sband, 1341 &assoc_data->link[link_id].conn); 1342 ADD_PRESENT_EXT_ELEM(WLAN_EID_EXT_HE_CAPABILITY); 1343 ieee80211_put_he_6ghz_cap(skb, sdata, smps_mode); 1344 } 1345 1346 /* 1347 * careful - need to know about all the present elems before 1348 * calling ieee80211_assoc_add_ml_elem(), so add this one if 1349 * we're going to put it after the ML element 1350 */ 1351 if (assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_EHT) 1352 ADD_PRESENT_EXT_ELEM(WLAN_EID_EXT_EHT_CAPABILITY); 1353 1354 if (link_id == assoc_data->assoc_link_id) 1355 ieee80211_assoc_add_ml_elem(sdata, skb, orig_capab, ext_capa, 1356 present_elems); 1357 1358 /* crash if somebody gets it wrong */ 1359 present_elems = NULL; 1360 1361 if (assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_EHT) 1362 ieee80211_put_eht_cap(skb, sdata, sband, 1363 &assoc_data->link[link_id].conn); 1364 1365 if (sband->band == NL80211_BAND_S1GHZ) { 1366 ieee80211_add_aid_request_ie(sdata, skb); 1367 ieee80211_add_s1g_capab_ie(sdata, &sband->s1g_cap, skb); 1368 } 1369 1370 if (iftd && iftd->vendor_elems.data && iftd->vendor_elems.len) 1371 skb_put_data(skb, iftd->vendor_elems.data, iftd->vendor_elems.len); 1372 1373 return offset; 1374 } 1375 1376 static void ieee80211_add_non_inheritance_elem(struct sk_buff *skb, 1377 const u16 *outer, 1378 const u16 *inner) 1379 { 1380 unsigned int skb_len = skb->len; 1381 bool at_extension = false; 1382 bool added = false; 1383 int i, j; 1384 u8 *len, *list_len = NULL; 1385 1386 skb_put_u8(skb, WLAN_EID_EXTENSION); 1387 len = skb_put(skb, 1); 1388 skb_put_u8(skb, WLAN_EID_EXT_NON_INHERITANCE); 1389 1390 for (i = 0; i < PRESENT_ELEMS_MAX && outer[i]; i++) { 1391 u16 elem = outer[i]; 1392 bool have_inner = false; 1393 1394 /* should at least be sorted in the sense of normal -> ext */ 1395 WARN_ON(at_extension && elem < PRESENT_ELEM_EXT_OFFS); 1396 1397 /* switch to extension list */ 1398 if (!at_extension && elem >= PRESENT_ELEM_EXT_OFFS) { 1399 at_extension = true; 1400 if (!list_len) 1401 skb_put_u8(skb, 0); 1402 list_len = NULL; 1403 } 1404 1405 for (j = 0; j < PRESENT_ELEMS_MAX && inner[j]; j++) { 1406 if (elem == inner[j]) { 1407 have_inner = true; 1408 break; 1409 } 1410 } 1411 1412 if (have_inner) 1413 continue; 1414 1415 if (!list_len) { 1416 list_len = skb_put(skb, 1); 1417 *list_len = 0; 1418 } 1419 *list_len += 1; 1420 skb_put_u8(skb, (u8)elem); 1421 added = true; 1422 } 1423 1424 /* if we added a list but no extension list, make a zero-len one */ 1425 if (added && (!at_extension || !list_len)) 1426 skb_put_u8(skb, 0); 1427 1428 /* if nothing added remove extension element completely */ 1429 if (!added) 1430 skb_trim(skb, skb_len); 1431 else 1432 *len = skb->len - skb_len - 2; 1433 } 1434 1435 static void ieee80211_assoc_add_ml_elem(struct ieee80211_sub_if_data *sdata, 1436 struct sk_buff *skb, u16 capab, 1437 const struct element *ext_capa, 1438 const u16 *outer_present_elems) 1439 { 1440 struct ieee80211_local *local = sdata->local; 1441 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1442 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; 1443 struct ieee80211_multi_link_elem *ml_elem; 1444 struct ieee80211_mle_basic_common_info *common; 1445 const struct wiphy_iftype_ext_capab *ift_ext_capa; 1446 __le16 eml_capa = 0, mld_capa_ops = 0; 1447 unsigned int link_id; 1448 u8 *ml_elem_len; 1449 void *capab_pos; 1450 1451 if (!ieee80211_vif_is_mld(&sdata->vif)) 1452 return; 1453 1454 ift_ext_capa = cfg80211_get_iftype_ext_capa(local->hw.wiphy, 1455 ieee80211_vif_type_p2p(&sdata->vif)); 1456 if (ift_ext_capa) { 1457 eml_capa = cpu_to_le16(ift_ext_capa->eml_capabilities); 1458 mld_capa_ops = cpu_to_le16(ift_ext_capa->mld_capa_and_ops); 1459 } 1460 1461 skb_put_u8(skb, WLAN_EID_EXTENSION); 1462 ml_elem_len = skb_put(skb, 1); 1463 skb_put_u8(skb, WLAN_EID_EXT_EHT_MULTI_LINK); 1464 ml_elem = skb_put(skb, sizeof(*ml_elem)); 1465 ml_elem->control = 1466 cpu_to_le16(IEEE80211_ML_CONTROL_TYPE_BASIC | 1467 IEEE80211_MLC_BASIC_PRES_MLD_CAPA_OP); 1468 common = skb_put(skb, sizeof(*common)); 1469 common->len = sizeof(*common) + 1470 2; /* MLD capa/ops */ 1471 memcpy(common->mld_mac_addr, sdata->vif.addr, ETH_ALEN); 1472 1473 /* add EML_CAPA only if needed, see Draft P802.11be_D2.1, 35.3.17 */ 1474 if (eml_capa & 1475 cpu_to_le16((IEEE80211_EML_CAP_EMLSR_SUPP | 1476 IEEE80211_EML_CAP_EMLMR_SUPPORT))) { 1477 common->len += 2; /* EML capabilities */ 1478 ml_elem->control |= 1479 cpu_to_le16(IEEE80211_MLC_BASIC_PRES_EML_CAPA); 1480 skb_put_data(skb, &eml_capa, sizeof(eml_capa)); 1481 } 1482 skb_put_data(skb, &mld_capa_ops, sizeof(mld_capa_ops)); 1483 1484 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { 1485 u16 link_present_elems[PRESENT_ELEMS_MAX] = {}; 1486 const u8 *extra_elems; 1487 size_t extra_elems_len; 1488 size_t extra_used; 1489 u8 *subelem_len = NULL; 1490 __le16 ctrl; 1491 1492 if (!assoc_data->link[link_id].bss || 1493 link_id == assoc_data->assoc_link_id) 1494 continue; 1495 1496 extra_elems = assoc_data->link[link_id].elems; 1497 extra_elems_len = assoc_data->link[link_id].elems_len; 1498 1499 skb_put_u8(skb, IEEE80211_MLE_SUBELEM_PER_STA_PROFILE); 1500 subelem_len = skb_put(skb, 1); 1501 1502 ctrl = cpu_to_le16(link_id | 1503 IEEE80211_MLE_STA_CONTROL_COMPLETE_PROFILE | 1504 IEEE80211_MLE_STA_CONTROL_STA_MAC_ADDR_PRESENT); 1505 skb_put_data(skb, &ctrl, sizeof(ctrl)); 1506 skb_put_u8(skb, 1 + ETH_ALEN); /* STA Info Length */ 1507 skb_put_data(skb, assoc_data->link[link_id].addr, 1508 ETH_ALEN); 1509 /* 1510 * Now add the contents of the (re)association request, 1511 * but the "listen interval" and "current AP address" 1512 * (if applicable) are skipped. So we only have 1513 * the capability field (remember the position and fill 1514 * later), followed by the elements added below by 1515 * calling ieee80211_assoc_link_elems(). 1516 */ 1517 capab_pos = skb_put(skb, 2); 1518 1519 extra_used = ieee80211_assoc_link_elems(sdata, skb, &capab, 1520 ext_capa, 1521 extra_elems, 1522 extra_elems_len, 1523 link_id, NULL, 1524 link_present_elems); 1525 if (extra_elems) 1526 skb_put_data(skb, extra_elems + extra_used, 1527 extra_elems_len - extra_used); 1528 1529 put_unaligned_le16(capab, capab_pos); 1530 1531 ieee80211_add_non_inheritance_elem(skb, outer_present_elems, 1532 link_present_elems); 1533 1534 ieee80211_fragment_element(skb, subelem_len, 1535 IEEE80211_MLE_SUBELEM_FRAGMENT); 1536 } 1537 1538 ieee80211_fragment_element(skb, ml_elem_len, WLAN_EID_FRAGMENT); 1539 } 1540 1541 static int ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata) 1542 { 1543 struct ieee80211_local *local = sdata->local; 1544 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1545 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; 1546 struct ieee80211_link_data *link; 1547 struct sk_buff *skb; 1548 struct ieee80211_mgmt *mgmt; 1549 u8 *pos, qos_info, *ie_start; 1550 size_t offset, noffset; 1551 u16 capab = 0, link_capab; 1552 __le16 listen_int; 1553 struct element *ext_capa = NULL; 1554 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif); 1555 struct ieee80211_prep_tx_info info = {}; 1556 unsigned int link_id, n_links = 0; 1557 u16 present_elems[PRESENT_ELEMS_MAX] = {}; 1558 void *capab_pos; 1559 size_t size; 1560 int ret; 1561 1562 /* we know it's writable, cast away the const */ 1563 if (assoc_data->ie_len) 1564 ext_capa = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, 1565 assoc_data->ie, 1566 assoc_data->ie_len); 1567 1568 lockdep_assert_wiphy(sdata->local->hw.wiphy); 1569 1570 size = local->hw.extra_tx_headroom + 1571 sizeof(*mgmt) + /* bit too much but doesn't matter */ 1572 2 + assoc_data->ssid_len + /* SSID */ 1573 assoc_data->ie_len + /* extra IEs */ 1574 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) + 1575 9; /* WMM */ 1576 1577 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { 1578 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss; 1579 const struct ieee80211_sband_iftype_data *iftd; 1580 struct ieee80211_supported_band *sband; 1581 1582 if (!cbss) 1583 continue; 1584 1585 sband = local->hw.wiphy->bands[cbss->channel->band]; 1586 1587 n_links++; 1588 /* add STA profile elements length */ 1589 size += assoc_data->link[link_id].elems_len; 1590 /* and supported rates length */ 1591 size += 4 + sband->n_bitrates; 1592 /* supported channels */ 1593 size += 2 + 2 * sband->n_channels; 1594 1595 iftd = ieee80211_get_sband_iftype_data(sband, iftype); 1596 if (iftd) 1597 size += iftd->vendor_elems.len; 1598 1599 /* power capability */ 1600 size += 4; 1601 1602 /* HT, VHT, HE, EHT */ 1603 size += 2 + sizeof(struct ieee80211_ht_cap); 1604 size += 2 + sizeof(struct ieee80211_vht_cap); 1605 size += 2 + 1 + sizeof(struct ieee80211_he_cap_elem) + 1606 sizeof(struct ieee80211_he_mcs_nss_supp) + 1607 IEEE80211_HE_PPE_THRES_MAX_LEN; 1608 1609 if (sband->band == NL80211_BAND_6GHZ) 1610 size += 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa); 1611 1612 size += 2 + 1 + sizeof(struct ieee80211_eht_cap_elem) + 1613 sizeof(struct ieee80211_eht_mcs_nss_supp) + 1614 IEEE80211_EHT_PPE_THRES_MAX_LEN; 1615 1616 /* non-inheritance element */ 1617 size += 2 + 2 + PRESENT_ELEMS_MAX; 1618 1619 /* should be the same across all BSSes */ 1620 if (cbss->capability & WLAN_CAPABILITY_PRIVACY) 1621 capab |= WLAN_CAPABILITY_PRIVACY; 1622 } 1623 1624 if (ieee80211_vif_is_mld(&sdata->vif)) { 1625 /* consider the multi-link element with STA profile */ 1626 size += sizeof(struct ieee80211_multi_link_elem); 1627 /* max common info field in basic multi-link element */ 1628 size += sizeof(struct ieee80211_mle_basic_common_info) + 1629 2 + /* capa & op */ 1630 2; /* EML capa */ 1631 1632 /* 1633 * The capability elements were already considered above; 1634 * note this over-estimates a bit because there's no 1635 * STA profile for the assoc link. 1636 */ 1637 size += (n_links - 1) * 1638 (1 + 1 + /* subelement ID/length */ 1639 2 + /* STA control */ 1640 1 + ETH_ALEN + 2 /* STA Info field */); 1641 } 1642 1643 link = sdata_dereference(sdata->link[assoc_data->assoc_link_id], sdata); 1644 if (WARN_ON(!link)) 1645 return -EINVAL; 1646 1647 if (WARN_ON(!assoc_data->link[assoc_data->assoc_link_id].bss)) 1648 return -EINVAL; 1649 1650 skb = alloc_skb(size, GFP_KERNEL); 1651 if (!skb) 1652 return -ENOMEM; 1653 1654 skb_reserve(skb, local->hw.extra_tx_headroom); 1655 1656 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM) 1657 capab |= WLAN_CAPABILITY_RADIO_MEASURE; 1658 1659 /* Set MBSSID support for HE AP if needed */ 1660 if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) && 1661 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HE && 1662 ext_capa && ext_capa->datalen >= 3) 1663 ext_capa->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT; 1664 1665 mgmt = skb_put_zero(skb, 24); 1666 memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN); 1667 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); 1668 memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN); 1669 1670 listen_int = cpu_to_le16(assoc_data->s1g ? 1671 ieee80211_encode_usf(local->hw.conf.listen_interval) : 1672 local->hw.conf.listen_interval); 1673 if (!is_zero_ether_addr(assoc_data->prev_ap_addr)) { 1674 skb_put(skb, 10); 1675 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 1676 IEEE80211_STYPE_REASSOC_REQ); 1677 capab_pos = &mgmt->u.reassoc_req.capab_info; 1678 mgmt->u.reassoc_req.listen_interval = listen_int; 1679 memcpy(mgmt->u.reassoc_req.current_ap, 1680 assoc_data->prev_ap_addr, ETH_ALEN); 1681 info.subtype = IEEE80211_STYPE_REASSOC_REQ; 1682 } else { 1683 skb_put(skb, 4); 1684 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 1685 IEEE80211_STYPE_ASSOC_REQ); 1686 capab_pos = &mgmt->u.assoc_req.capab_info; 1687 mgmt->u.assoc_req.listen_interval = listen_int; 1688 info.subtype = IEEE80211_STYPE_ASSOC_REQ; 1689 } 1690 1691 /* SSID */ 1692 pos = skb_put(skb, 2 + assoc_data->ssid_len); 1693 ie_start = pos; 1694 *pos++ = WLAN_EID_SSID; 1695 *pos++ = assoc_data->ssid_len; 1696 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len); 1697 1698 /* 1699 * This bit is technically reserved, so it shouldn't matter for either 1700 * the AP or us, but it also means we shouldn't set it. However, we've 1701 * always set it in the past, and apparently some EHT APs check that 1702 * we don't set it. To avoid interoperability issues with old APs that 1703 * for some reason check it and want it to be set, set the bit for all 1704 * pre-EHT connections as we used to do. 1705 */ 1706 if (link->u.mgd.conn.mode < IEEE80211_CONN_MODE_EHT) 1707 capab |= WLAN_CAPABILITY_ESS; 1708 1709 /* add the elements for the assoc (main) link */ 1710 link_capab = capab; 1711 offset = ieee80211_assoc_link_elems(sdata, skb, &link_capab, 1712 ext_capa, 1713 assoc_data->ie, 1714 assoc_data->ie_len, 1715 assoc_data->assoc_link_id, link, 1716 present_elems); 1717 put_unaligned_le16(link_capab, capab_pos); 1718 1719 /* if present, add any custom non-vendor IEs */ 1720 if (assoc_data->ie_len) { 1721 noffset = ieee80211_ie_split_vendor(assoc_data->ie, 1722 assoc_data->ie_len, 1723 offset); 1724 skb_put_data(skb, assoc_data->ie + offset, noffset - offset); 1725 offset = noffset; 1726 } 1727 1728 if (assoc_data->wmm) { 1729 if (assoc_data->uapsd) { 1730 qos_info = ifmgd->uapsd_queues; 1731 qos_info |= (ifmgd->uapsd_max_sp_len << 1732 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT); 1733 } else { 1734 qos_info = 0; 1735 } 1736 1737 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info); 1738 } 1739 1740 /* add any remaining custom (i.e. vendor specific here) IEs */ 1741 if (assoc_data->ie_len) { 1742 noffset = assoc_data->ie_len; 1743 skb_put_data(skb, assoc_data->ie + offset, noffset - offset); 1744 } 1745 1746 if (assoc_data->fils_kek_len) { 1747 ret = fils_encrypt_assoc_req(skb, assoc_data); 1748 if (ret < 0) { 1749 dev_kfree_skb(skb); 1750 return ret; 1751 } 1752 } 1753 1754 pos = skb_tail_pointer(skb); 1755 kfree(ifmgd->assoc_req_ies); 1756 ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC); 1757 if (!ifmgd->assoc_req_ies) { 1758 dev_kfree_skb(skb); 1759 return -ENOMEM; 1760 } 1761 1762 ifmgd->assoc_req_ies_len = pos - ie_start; 1763 1764 info.link_id = assoc_data->assoc_link_id; 1765 drv_mgd_prepare_tx(local, sdata, &info); 1766 1767 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; 1768 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) 1769 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS | 1770 IEEE80211_TX_INTFL_MLME_CONN_TX; 1771 ieee80211_tx_skb(sdata, skb); 1772 1773 return 0; 1774 } 1775 1776 void ieee80211_send_pspoll(struct ieee80211_local *local, 1777 struct ieee80211_sub_if_data *sdata) 1778 { 1779 struct ieee80211_pspoll *pspoll; 1780 struct sk_buff *skb; 1781 1782 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif); 1783 if (!skb) 1784 return; 1785 1786 pspoll = (struct ieee80211_pspoll *) skb->data; 1787 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); 1788 1789 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; 1790 ieee80211_tx_skb(sdata, skb); 1791 } 1792 1793 void ieee80211_send_nullfunc(struct ieee80211_local *local, 1794 struct ieee80211_sub_if_data *sdata, 1795 bool powersave) 1796 { 1797 struct sk_buff *skb; 1798 struct ieee80211_hdr_3addr *nullfunc; 1799 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1800 1801 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif, -1, 1802 !ieee80211_hw_check(&local->hw, 1803 DOESNT_SUPPORT_QOS_NDP)); 1804 if (!skb) 1805 return; 1806 1807 nullfunc = (struct ieee80211_hdr_3addr *) skb->data; 1808 if (powersave) 1809 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); 1810 1811 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT | 1812 IEEE80211_TX_INTFL_OFFCHAN_TX_OK; 1813 1814 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) 1815 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; 1816 1817 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) 1818 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE; 1819 1820 ieee80211_tx_skb(sdata, skb); 1821 } 1822 1823 void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local, 1824 struct ieee80211_sub_if_data *sdata) 1825 { 1826 struct sk_buff *skb; 1827 struct ieee80211_hdr *nullfunc; 1828 __le16 fc; 1829 1830 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) 1831 return; 1832 1833 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30); 1834 if (!skb) 1835 return; 1836 1837 skb_reserve(skb, local->hw.extra_tx_headroom); 1838 1839 nullfunc = skb_put_zero(skb, 30); 1840 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | 1841 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); 1842 nullfunc->frame_control = fc; 1843 memcpy(nullfunc->addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN); 1844 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); 1845 memcpy(nullfunc->addr3, sdata->deflink.u.mgd.bssid, ETH_ALEN); 1846 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN); 1847 1848 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; 1849 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE; 1850 ieee80211_tx_skb(sdata, skb); 1851 } 1852 1853 /* spectrum management related things */ 1854 static void ieee80211_chswitch_work(struct wiphy *wiphy, 1855 struct wiphy_work *work) 1856 { 1857 struct ieee80211_link_data *link = 1858 container_of(work, struct ieee80211_link_data, 1859 u.mgd.chswitch_work.work); 1860 struct ieee80211_sub_if_data *sdata = link->sdata; 1861 struct ieee80211_local *local = sdata->local; 1862 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1863 int ret; 1864 1865 if (!ieee80211_sdata_running(sdata)) 1866 return; 1867 1868 lockdep_assert_wiphy(local->hw.wiphy); 1869 1870 if (!ifmgd->associated) 1871 return; 1872 1873 if (!link->conf->csa_active) 1874 return; 1875 1876 /* 1877 * using reservation isn't immediate as it may be deferred until later 1878 * with multi-vif. once reservation is complete it will re-schedule the 1879 * work with no reserved_chanctx so verify chandef to check if it 1880 * completed successfully 1881 */ 1882 1883 if (link->reserved_chanctx) { 1884 /* 1885 * with multi-vif csa driver may call ieee80211_csa_finish() 1886 * many times while waiting for other interfaces to use their 1887 * reservations 1888 */ 1889 if (link->reserved_ready) 1890 return; 1891 1892 ret = ieee80211_link_use_reserved_context(link); 1893 if (ret) { 1894 sdata_info(sdata, 1895 "failed to use reserved channel context, disconnecting (err=%d)\n", 1896 ret); 1897 wiphy_work_queue(sdata->local->hw.wiphy, 1898 &ifmgd->csa_connection_drop_work); 1899 } 1900 return; 1901 } 1902 1903 if (!ieee80211_chanreq_identical(&link->conf->chanreq, 1904 &link->csa_chanreq)) { 1905 sdata_info(sdata, 1906 "failed to finalize channel switch, disconnecting\n"); 1907 wiphy_work_queue(sdata->local->hw.wiphy, 1908 &ifmgd->csa_connection_drop_work); 1909 return; 1910 } 1911 1912 link->u.mgd.csa_waiting_bcn = true; 1913 1914 ieee80211_sta_reset_beacon_monitor(sdata); 1915 ieee80211_sta_reset_conn_monitor(sdata); 1916 } 1917 1918 static void ieee80211_chswitch_post_beacon(struct ieee80211_link_data *link) 1919 { 1920 struct ieee80211_sub_if_data *sdata = link->sdata; 1921 struct ieee80211_local *local = sdata->local; 1922 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1923 int ret; 1924 1925 lockdep_assert_wiphy(sdata->local->hw.wiphy); 1926 1927 WARN_ON(!link->conf->csa_active); 1928 1929 if (sdata->csa_blocked_tx) { 1930 ieee80211_wake_vif_queues(local, sdata, 1931 IEEE80211_QUEUE_STOP_REASON_CSA); 1932 sdata->csa_blocked_tx = false; 1933 } 1934 1935 link->conf->csa_active = false; 1936 link->u.mgd.csa_waiting_bcn = false; 1937 1938 ret = drv_post_channel_switch(link); 1939 if (ret) { 1940 sdata_info(sdata, 1941 "driver post channel switch failed, disconnecting\n"); 1942 wiphy_work_queue(sdata->local->hw.wiphy, 1943 &ifmgd->csa_connection_drop_work); 1944 return; 1945 } 1946 1947 cfg80211_ch_switch_notify(sdata->dev, &link->reserved.oper, 1948 link->link_id); 1949 } 1950 1951 void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success, 1952 unsigned int link_id) 1953 { 1954 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 1955 1956 trace_api_chswitch_done(sdata, success, link_id); 1957 1958 rcu_read_lock(); 1959 1960 if (!success) { 1961 sdata_info(sdata, 1962 "driver channel switch failed, disconnecting\n"); 1963 wiphy_work_queue(sdata->local->hw.wiphy, 1964 &sdata->u.mgd.csa_connection_drop_work); 1965 } else { 1966 struct ieee80211_link_data *link = 1967 rcu_dereference(sdata->link[link_id]); 1968 1969 if (WARN_ON(!link)) { 1970 rcu_read_unlock(); 1971 return; 1972 } 1973 1974 wiphy_delayed_work_queue(sdata->local->hw.wiphy, 1975 &link->u.mgd.chswitch_work, 0); 1976 } 1977 1978 rcu_read_unlock(); 1979 } 1980 EXPORT_SYMBOL(ieee80211_chswitch_done); 1981 1982 static void 1983 ieee80211_sta_abort_chanswitch(struct ieee80211_link_data *link) 1984 { 1985 struct ieee80211_sub_if_data *sdata = link->sdata; 1986 struct ieee80211_local *local = sdata->local; 1987 1988 lockdep_assert_wiphy(local->hw.wiphy); 1989 1990 if (!local->ops->abort_channel_switch) 1991 return; 1992 1993 ieee80211_link_unreserve_chanctx(link); 1994 1995 if (sdata->csa_blocked_tx) { 1996 ieee80211_wake_vif_queues(local, sdata, 1997 IEEE80211_QUEUE_STOP_REASON_CSA); 1998 sdata->csa_blocked_tx = false; 1999 } 2000 2001 link->conf->csa_active = false; 2002 2003 drv_abort_channel_switch(link); 2004 } 2005 2006 static void 2007 ieee80211_sta_process_chanswitch(struct ieee80211_link_data *link, 2008 u64 timestamp, u32 device_timestamp, 2009 struct ieee802_11_elems *elems, 2010 bool beacon) 2011 { 2012 struct ieee80211_sub_if_data *sdata = link->sdata; 2013 struct ieee80211_local *local = sdata->local; 2014 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2015 struct cfg80211_bss *cbss = link->conf->bss; 2016 struct ieee80211_chanctx_conf *conf; 2017 struct ieee80211_chanctx *chanctx; 2018 enum nl80211_band current_band; 2019 struct ieee80211_csa_ie csa_ie; 2020 struct ieee80211_channel_switch ch_switch = { 2021 .link_id = link->link_id, 2022 }; 2023 struct ieee80211_bss *bss; 2024 unsigned long timeout; 2025 int res; 2026 2027 lockdep_assert_wiphy(local->hw.wiphy); 2028 2029 if (!cbss) 2030 return; 2031 2032 current_band = cbss->channel->band; 2033 bss = (void *)cbss->priv; 2034 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band, 2035 bss->vht_cap_info, 2036 &link->u.mgd.conn, 2037 link->u.mgd.bssid, &csa_ie); 2038 2039 if (!res) { 2040 ch_switch.timestamp = timestamp; 2041 ch_switch.device_timestamp = device_timestamp; 2042 ch_switch.block_tx = csa_ie.mode; 2043 ch_switch.chandef = csa_ie.chanreq.oper; 2044 ch_switch.count = csa_ie.count; 2045 ch_switch.delay = csa_ie.max_switch_time; 2046 } 2047 2048 if (res < 0) 2049 goto drop_connection; 2050 2051 if (link->conf->csa_active) { 2052 /* already processing - disregard action frames */ 2053 if (!beacon) 2054 return; 2055 2056 if (link->u.mgd.csa_waiting_bcn) { 2057 ieee80211_chswitch_post_beacon(link); 2058 /* 2059 * If the CSA IE is still present in the beacon after 2060 * the switch, we need to consider it as a new CSA 2061 * (possibly to self) - this happens by not returning 2062 * here so we'll get to the check below. 2063 */ 2064 } else if (res) { 2065 ieee80211_sta_abort_chanswitch(link); 2066 return; 2067 } else { 2068 drv_channel_switch_rx_beacon(sdata, &ch_switch); 2069 return; 2070 } 2071 } 2072 2073 /* nothing to do at all - no active CSA nor a new one */ 2074 if (res) 2075 return; 2076 2077 if (link->conf->chanreq.oper.chan->band != 2078 csa_ie.chanreq.oper.chan->band) { 2079 sdata_info(sdata, 2080 "AP %pM switches to different band (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n", 2081 link->u.mgd.bssid, 2082 csa_ie.chanreq.oper.chan->center_freq, 2083 csa_ie.chanreq.oper.width, 2084 csa_ie.chanreq.oper.center_freq1, 2085 csa_ie.chanreq.oper.center_freq2); 2086 goto drop_connection; 2087 } 2088 2089 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chanreq.oper, 2090 IEEE80211_CHAN_DISABLED)) { 2091 sdata_info(sdata, 2092 "AP %pM switches to unsupported channel " 2093 "(%d.%03d MHz, width:%d, CF1/2: %d.%03d/%d MHz), " 2094 "disconnecting\n", 2095 link->u.mgd.bssid, 2096 csa_ie.chanreq.oper.chan->center_freq, 2097 csa_ie.chanreq.oper.chan->freq_offset, 2098 csa_ie.chanreq.oper.width, 2099 csa_ie.chanreq.oper.center_freq1, 2100 csa_ie.chanreq.oper.freq1_offset, 2101 csa_ie.chanreq.oper.center_freq2); 2102 goto drop_connection; 2103 } 2104 2105 if (cfg80211_chandef_identical(&csa_ie.chanreq.oper, 2106 &link->conf->chanreq.oper) && 2107 (!csa_ie.mode || !beacon)) { 2108 if (link->u.mgd.csa_ignored_same_chan) 2109 return; 2110 sdata_info(sdata, 2111 "AP %pM tries to chanswitch to same channel, ignore\n", 2112 link->u.mgd.bssid); 2113 link->u.mgd.csa_ignored_same_chan = true; 2114 return; 2115 } 2116 2117 /* 2118 * Drop all TDLS peers on the affected link - either we disconnect or 2119 * move to a different channel from this point on. There's no telling 2120 * what our peer will do. 2121 * The TDLS WIDER_BW scenario is also problematic, as peers might now 2122 * have an incompatible wider chandef. 2123 */ 2124 ieee80211_teardown_tdls_peers(link); 2125 2126 conf = rcu_dereference_protected(link->conf->chanctx_conf, 2127 lockdep_is_held(&local->hw.wiphy->mtx)); 2128 if (!conf) { 2129 sdata_info(sdata, 2130 "no channel context assigned to vif?, disconnecting\n"); 2131 goto drop_connection; 2132 } 2133 2134 chanctx = container_of(conf, struct ieee80211_chanctx, conf); 2135 2136 if (!ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) { 2137 sdata_info(sdata, 2138 "driver doesn't support chan-switch with channel contexts\n"); 2139 goto drop_connection; 2140 } 2141 2142 if (drv_pre_channel_switch(sdata, &ch_switch)) { 2143 sdata_info(sdata, 2144 "preparing for channel switch failed, disconnecting\n"); 2145 goto drop_connection; 2146 } 2147 2148 res = ieee80211_link_reserve_chanctx(link, &csa_ie.chanreq, 2149 chanctx->mode, false); 2150 if (res) { 2151 sdata_info(sdata, 2152 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n", 2153 res); 2154 goto drop_connection; 2155 } 2156 2157 link->conf->csa_active = true; 2158 link->csa_chanreq = csa_ie.chanreq; 2159 link->u.mgd.csa_ignored_same_chan = false; 2160 link->u.mgd.beacon_crc_valid = false; 2161 2162 if (csa_ie.mode && 2163 !ieee80211_hw_check(&local->hw, HANDLES_QUIET_CSA)) { 2164 ieee80211_stop_vif_queues(local, sdata, 2165 IEEE80211_QUEUE_STOP_REASON_CSA); 2166 sdata->csa_blocked_tx = true; 2167 } 2168 2169 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chanreq.oper, 2170 link->link_id, csa_ie.count, 2171 csa_ie.mode); 2172 2173 if (local->ops->channel_switch) { 2174 /* use driver's channel switch callback */ 2175 drv_channel_switch(local, sdata, &ch_switch); 2176 return; 2177 } 2178 2179 /* channel switch handled in software */ 2180 timeout = TU_TO_JIFFIES((max_t(int, csa_ie.count, 1) - 1) * 2181 cbss->beacon_interval); 2182 wiphy_delayed_work_queue(local->hw.wiphy, 2183 &link->u.mgd.chswitch_work, 2184 timeout); 2185 return; 2186 drop_connection: 2187 /* 2188 * This is just so that the disconnect flow will know that 2189 * we were trying to switch channel and failed. In case the 2190 * mode is 1 (we are not allowed to Tx), we will know not to 2191 * send a deauthentication frame. Those two fields will be 2192 * reset when the disconnection worker runs. 2193 */ 2194 link->conf->csa_active = true; 2195 sdata->csa_blocked_tx = 2196 csa_ie.mode && !ieee80211_hw_check(&local->hw, HANDLES_QUIET_CSA); 2197 2198 wiphy_work_queue(sdata->local->hw.wiphy, 2199 &ifmgd->csa_connection_drop_work); 2200 } 2201 2202 static bool 2203 ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata, 2204 struct ieee80211_channel *channel, 2205 const u8 *country_ie, u8 country_ie_len, 2206 const u8 *pwr_constr_elem, 2207 int *chan_pwr, int *pwr_reduction) 2208 { 2209 struct ieee80211_country_ie_triplet *triplet; 2210 int chan = ieee80211_frequency_to_channel(channel->center_freq); 2211 int i, chan_increment; 2212 bool have_chan_pwr = false; 2213 2214 /* Invalid IE */ 2215 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) 2216 return false; 2217 2218 triplet = (void *)(country_ie + 3); 2219 country_ie_len -= 3; 2220 2221 switch (channel->band) { 2222 default: 2223 WARN_ON_ONCE(1); 2224 fallthrough; 2225 case NL80211_BAND_2GHZ: 2226 case NL80211_BAND_60GHZ: 2227 case NL80211_BAND_LC: 2228 chan_increment = 1; 2229 break; 2230 case NL80211_BAND_5GHZ: 2231 chan_increment = 4; 2232 break; 2233 case NL80211_BAND_6GHZ: 2234 /* 2235 * In the 6 GHz band, the "maximum transmit power level" 2236 * field in the triplets is reserved, and thus will be 2237 * zero and we shouldn't use it to control TX power. 2238 * The actual TX power will be given in the transmit 2239 * power envelope element instead. 2240 */ 2241 return false; 2242 } 2243 2244 /* find channel */ 2245 while (country_ie_len >= 3) { 2246 u8 first_channel = triplet->chans.first_channel; 2247 2248 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID) 2249 goto next; 2250 2251 for (i = 0; i < triplet->chans.num_channels; i++) { 2252 if (first_channel + i * chan_increment == chan) { 2253 have_chan_pwr = true; 2254 *chan_pwr = triplet->chans.max_power; 2255 break; 2256 } 2257 } 2258 if (have_chan_pwr) 2259 break; 2260 2261 next: 2262 triplet++; 2263 country_ie_len -= 3; 2264 } 2265 2266 if (have_chan_pwr && pwr_constr_elem) 2267 *pwr_reduction = *pwr_constr_elem; 2268 else 2269 *pwr_reduction = 0; 2270 2271 return have_chan_pwr; 2272 } 2273 2274 static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata, 2275 struct ieee80211_channel *channel, 2276 const u8 *cisco_dtpc_ie, 2277 int *pwr_level) 2278 { 2279 /* From practical testing, the first data byte of the DTPC element 2280 * seems to contain the requested dBm level, and the CLI on Cisco 2281 * APs clearly state the range is -127 to 127 dBm, which indicates 2282 * a signed byte, although it seemingly never actually goes negative. 2283 * The other byte seems to always be zero. 2284 */ 2285 *pwr_level = (__s8)cisco_dtpc_ie[4]; 2286 } 2287 2288 static u64 ieee80211_handle_pwr_constr(struct ieee80211_link_data *link, 2289 struct ieee80211_channel *channel, 2290 struct ieee80211_mgmt *mgmt, 2291 const u8 *country_ie, u8 country_ie_len, 2292 const u8 *pwr_constr_ie, 2293 const u8 *cisco_dtpc_ie) 2294 { 2295 struct ieee80211_sub_if_data *sdata = link->sdata; 2296 bool has_80211h_pwr = false, has_cisco_pwr = false; 2297 int chan_pwr = 0, pwr_reduction_80211h = 0; 2298 int pwr_level_cisco, pwr_level_80211h; 2299 int new_ap_level; 2300 __le16 capab = mgmt->u.probe_resp.capab_info; 2301 2302 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) 2303 return 0; /* TODO */ 2304 2305 if (country_ie && 2306 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) || 2307 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) { 2308 has_80211h_pwr = ieee80211_find_80211h_pwr_constr( 2309 sdata, channel, country_ie, country_ie_len, 2310 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h); 2311 pwr_level_80211h = 2312 max_t(int, 0, chan_pwr - pwr_reduction_80211h); 2313 } 2314 2315 if (cisco_dtpc_ie) { 2316 ieee80211_find_cisco_dtpc( 2317 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco); 2318 has_cisco_pwr = true; 2319 } 2320 2321 if (!has_80211h_pwr && !has_cisco_pwr) 2322 return 0; 2323 2324 /* If we have both 802.11h and Cisco DTPC, apply both limits 2325 * by picking the smallest of the two power levels advertised. 2326 */ 2327 if (has_80211h_pwr && 2328 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) { 2329 new_ap_level = pwr_level_80211h; 2330 2331 if (link->ap_power_level == new_ap_level) 2332 return 0; 2333 2334 sdata_dbg(sdata, 2335 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n", 2336 pwr_level_80211h, chan_pwr, pwr_reduction_80211h, 2337 link->u.mgd.bssid); 2338 } else { /* has_cisco_pwr is always true here. */ 2339 new_ap_level = pwr_level_cisco; 2340 2341 if (link->ap_power_level == new_ap_level) 2342 return 0; 2343 2344 sdata_dbg(sdata, 2345 "Limiting TX power to %d dBm as advertised by %pM\n", 2346 pwr_level_cisco, link->u.mgd.bssid); 2347 } 2348 2349 link->ap_power_level = new_ap_level; 2350 if (__ieee80211_recalc_txpower(sdata)) 2351 return BSS_CHANGED_TXPOWER; 2352 return 0; 2353 } 2354 2355 /* powersave */ 2356 static void ieee80211_enable_ps(struct ieee80211_local *local, 2357 struct ieee80211_sub_if_data *sdata) 2358 { 2359 struct ieee80211_conf *conf = &local->hw.conf; 2360 2361 /* 2362 * If we are scanning right now then the parameters will 2363 * take effect when scan finishes. 2364 */ 2365 if (local->scanning) 2366 return; 2367 2368 if (conf->dynamic_ps_timeout > 0 && 2369 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) { 2370 mod_timer(&local->dynamic_ps_timer, jiffies + 2371 msecs_to_jiffies(conf->dynamic_ps_timeout)); 2372 } else { 2373 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) 2374 ieee80211_send_nullfunc(local, sdata, true); 2375 2376 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) && 2377 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) 2378 return; 2379 2380 conf->flags |= IEEE80211_CONF_PS; 2381 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); 2382 } 2383 } 2384 2385 static void ieee80211_change_ps(struct ieee80211_local *local) 2386 { 2387 struct ieee80211_conf *conf = &local->hw.conf; 2388 2389 if (local->ps_sdata) { 2390 ieee80211_enable_ps(local, local->ps_sdata); 2391 } else if (conf->flags & IEEE80211_CONF_PS) { 2392 conf->flags &= ~IEEE80211_CONF_PS; 2393 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); 2394 del_timer_sync(&local->dynamic_ps_timer); 2395 wiphy_work_cancel(local->hw.wiphy, 2396 &local->dynamic_ps_enable_work); 2397 } 2398 } 2399 2400 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata) 2401 { 2402 struct ieee80211_local *local = sdata->local; 2403 struct ieee80211_if_managed *mgd = &sdata->u.mgd; 2404 struct sta_info *sta = NULL; 2405 bool authorized = false; 2406 2407 if (!mgd->powersave) 2408 return false; 2409 2410 if (mgd->broken_ap) 2411 return false; 2412 2413 if (!mgd->associated) 2414 return false; 2415 2416 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL) 2417 return false; 2418 2419 if (!(local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO) && 2420 !sdata->deflink.u.mgd.have_beacon) 2421 return false; 2422 2423 rcu_read_lock(); 2424 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr); 2425 if (sta) 2426 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED); 2427 rcu_read_unlock(); 2428 2429 return authorized; 2430 } 2431 2432 /* need to hold RTNL or interface lock */ 2433 void ieee80211_recalc_ps(struct ieee80211_local *local) 2434 { 2435 struct ieee80211_sub_if_data *sdata, *found = NULL; 2436 int count = 0; 2437 int timeout; 2438 2439 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS) || 2440 ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) { 2441 local->ps_sdata = NULL; 2442 return; 2443 } 2444 2445 list_for_each_entry(sdata, &local->interfaces, list) { 2446 if (!ieee80211_sdata_running(sdata)) 2447 continue; 2448 if (sdata->vif.type == NL80211_IFTYPE_AP) { 2449 /* If an AP vif is found, then disable PS 2450 * by setting the count to zero thereby setting 2451 * ps_sdata to NULL. 2452 */ 2453 count = 0; 2454 break; 2455 } 2456 if (sdata->vif.type != NL80211_IFTYPE_STATION) 2457 continue; 2458 found = sdata; 2459 count++; 2460 } 2461 2462 if (count == 1 && ieee80211_powersave_allowed(found)) { 2463 u8 dtimper = found->deflink.u.mgd.dtim_period; 2464 2465 timeout = local->dynamic_ps_forced_timeout; 2466 if (timeout < 0) 2467 timeout = 100; 2468 local->hw.conf.dynamic_ps_timeout = timeout; 2469 2470 /* If the TIM IE is invalid, pretend the value is 1 */ 2471 if (!dtimper) 2472 dtimper = 1; 2473 2474 local->hw.conf.ps_dtim_period = dtimper; 2475 local->ps_sdata = found; 2476 } else { 2477 local->ps_sdata = NULL; 2478 } 2479 2480 ieee80211_change_ps(local); 2481 } 2482 2483 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata) 2484 { 2485 bool ps_allowed = ieee80211_powersave_allowed(sdata); 2486 2487 if (sdata->vif.cfg.ps != ps_allowed) { 2488 sdata->vif.cfg.ps = ps_allowed; 2489 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_PS); 2490 } 2491 } 2492 2493 void ieee80211_dynamic_ps_disable_work(struct wiphy *wiphy, 2494 struct wiphy_work *work) 2495 { 2496 struct ieee80211_local *local = 2497 container_of(work, struct ieee80211_local, 2498 dynamic_ps_disable_work); 2499 2500 if (local->hw.conf.flags & IEEE80211_CONF_PS) { 2501 local->hw.conf.flags &= ~IEEE80211_CONF_PS; 2502 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); 2503 } 2504 2505 ieee80211_wake_queues_by_reason(&local->hw, 2506 IEEE80211_MAX_QUEUE_MAP, 2507 IEEE80211_QUEUE_STOP_REASON_PS, 2508 false); 2509 } 2510 2511 void ieee80211_dynamic_ps_enable_work(struct wiphy *wiphy, 2512 struct wiphy_work *work) 2513 { 2514 struct ieee80211_local *local = 2515 container_of(work, struct ieee80211_local, 2516 dynamic_ps_enable_work); 2517 struct ieee80211_sub_if_data *sdata = local->ps_sdata; 2518 struct ieee80211_if_managed *ifmgd; 2519 unsigned long flags; 2520 int q; 2521 2522 /* can only happen when PS was just disabled anyway */ 2523 if (!sdata) 2524 return; 2525 2526 ifmgd = &sdata->u.mgd; 2527 2528 if (local->hw.conf.flags & IEEE80211_CONF_PS) 2529 return; 2530 2531 if (local->hw.conf.dynamic_ps_timeout > 0) { 2532 /* don't enter PS if TX frames are pending */ 2533 if (drv_tx_frames_pending(local)) { 2534 mod_timer(&local->dynamic_ps_timer, jiffies + 2535 msecs_to_jiffies( 2536 local->hw.conf.dynamic_ps_timeout)); 2537 return; 2538 } 2539 2540 /* 2541 * transmission can be stopped by others which leads to 2542 * dynamic_ps_timer expiry. Postpone the ps timer if it 2543 * is not the actual idle state. 2544 */ 2545 spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 2546 for (q = 0; q < local->hw.queues; q++) { 2547 if (local->queue_stop_reasons[q]) { 2548 spin_unlock_irqrestore(&local->queue_stop_reason_lock, 2549 flags); 2550 mod_timer(&local->dynamic_ps_timer, jiffies + 2551 msecs_to_jiffies( 2552 local->hw.conf.dynamic_ps_timeout)); 2553 return; 2554 } 2555 } 2556 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 2557 } 2558 2559 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) && 2560 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) { 2561 if (drv_tx_frames_pending(local)) { 2562 mod_timer(&local->dynamic_ps_timer, jiffies + 2563 msecs_to_jiffies( 2564 local->hw.conf.dynamic_ps_timeout)); 2565 } else { 2566 ieee80211_send_nullfunc(local, sdata, true); 2567 /* Flush to get the tx status of nullfunc frame */ 2568 ieee80211_flush_queues(local, sdata, false); 2569 } 2570 } 2571 2572 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) && 2573 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) || 2574 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) { 2575 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED; 2576 local->hw.conf.flags |= IEEE80211_CONF_PS; 2577 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); 2578 } 2579 } 2580 2581 void ieee80211_dynamic_ps_timer(struct timer_list *t) 2582 { 2583 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer); 2584 2585 wiphy_work_queue(local->hw.wiphy, &local->dynamic_ps_enable_work); 2586 } 2587 2588 void ieee80211_dfs_cac_timer_work(struct wiphy *wiphy, struct wiphy_work *work) 2589 { 2590 struct ieee80211_link_data *link = 2591 container_of(work, struct ieee80211_link_data, 2592 dfs_cac_timer_work.work); 2593 struct cfg80211_chan_def chandef = link->conf->chanreq.oper; 2594 struct ieee80211_sub_if_data *sdata = link->sdata; 2595 2596 lockdep_assert_wiphy(sdata->local->hw.wiphy); 2597 2598 if (sdata->wdev.cac_started) { 2599 ieee80211_link_release_channel(link); 2600 cfg80211_cac_event(sdata->dev, &chandef, 2601 NL80211_RADAR_CAC_FINISHED, 2602 GFP_KERNEL); 2603 } 2604 } 2605 2606 static bool 2607 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata) 2608 { 2609 struct ieee80211_local *local = sdata->local; 2610 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2611 bool ret = false; 2612 int ac; 2613 2614 if (local->hw.queues < IEEE80211_NUM_ACS) 2615 return false; 2616 2617 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 2618 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac]; 2619 int non_acm_ac; 2620 unsigned long now = jiffies; 2621 2622 if (tx_tspec->action == TX_TSPEC_ACTION_NONE && 2623 tx_tspec->admitted_time && 2624 time_after(now, tx_tspec->time_slice_start + HZ)) { 2625 tx_tspec->consumed_tx_time = 0; 2626 tx_tspec->time_slice_start = now; 2627 2628 if (tx_tspec->downgraded) 2629 tx_tspec->action = 2630 TX_TSPEC_ACTION_STOP_DOWNGRADE; 2631 } 2632 2633 switch (tx_tspec->action) { 2634 case TX_TSPEC_ACTION_STOP_DOWNGRADE: 2635 /* take the original parameters */ 2636 if (drv_conf_tx(local, &sdata->deflink, ac, 2637 &sdata->deflink.tx_conf[ac])) 2638 link_err(&sdata->deflink, 2639 "failed to set TX queue parameters for queue %d\n", 2640 ac); 2641 tx_tspec->action = TX_TSPEC_ACTION_NONE; 2642 tx_tspec->downgraded = false; 2643 ret = true; 2644 break; 2645 case TX_TSPEC_ACTION_DOWNGRADE: 2646 if (time_after(now, tx_tspec->time_slice_start + HZ)) { 2647 tx_tspec->action = TX_TSPEC_ACTION_NONE; 2648 ret = true; 2649 break; 2650 } 2651 /* downgrade next lower non-ACM AC */ 2652 for (non_acm_ac = ac + 1; 2653 non_acm_ac < IEEE80211_NUM_ACS; 2654 non_acm_ac++) 2655 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac))) 2656 break; 2657 /* Usually the loop will result in using BK even if it 2658 * requires admission control, but such a configuration 2659 * makes no sense and we have to transmit somehow - the 2660 * AC selection does the same thing. 2661 * If we started out trying to downgrade from BK, then 2662 * the extra condition here might be needed. 2663 */ 2664 if (non_acm_ac >= IEEE80211_NUM_ACS) 2665 non_acm_ac = IEEE80211_AC_BK; 2666 if (drv_conf_tx(local, &sdata->deflink, ac, 2667 &sdata->deflink.tx_conf[non_acm_ac])) 2668 link_err(&sdata->deflink, 2669 "failed to set TX queue parameters for queue %d\n", 2670 ac); 2671 tx_tspec->action = TX_TSPEC_ACTION_NONE; 2672 ret = true; 2673 wiphy_delayed_work_queue(local->hw.wiphy, 2674 &ifmgd->tx_tspec_wk, 2675 tx_tspec->time_slice_start + 2676 HZ - now + 1); 2677 break; 2678 case TX_TSPEC_ACTION_NONE: 2679 /* nothing now */ 2680 break; 2681 } 2682 } 2683 2684 return ret; 2685 } 2686 2687 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata) 2688 { 2689 if (__ieee80211_sta_handle_tspec_ac_params(sdata)) 2690 ieee80211_link_info_change_notify(sdata, &sdata->deflink, 2691 BSS_CHANGED_QOS); 2692 } 2693 2694 static void ieee80211_sta_handle_tspec_ac_params_wk(struct wiphy *wiphy, 2695 struct wiphy_work *work) 2696 { 2697 struct ieee80211_sub_if_data *sdata; 2698 2699 sdata = container_of(work, struct ieee80211_sub_if_data, 2700 u.mgd.tx_tspec_wk.work); 2701 ieee80211_sta_handle_tspec_ac_params(sdata); 2702 } 2703 2704 void ieee80211_mgd_set_link_qos_params(struct ieee80211_link_data *link) 2705 { 2706 struct ieee80211_sub_if_data *sdata = link->sdata; 2707 struct ieee80211_local *local = sdata->local; 2708 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2709 struct ieee80211_tx_queue_params *params = link->tx_conf; 2710 u8 ac; 2711 2712 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 2713 mlme_dbg(sdata, 2714 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n", 2715 ac, params[ac].acm, 2716 params[ac].aifs, params[ac].cw_min, params[ac].cw_max, 2717 params[ac].txop, params[ac].uapsd, 2718 ifmgd->tx_tspec[ac].downgraded); 2719 if (!ifmgd->tx_tspec[ac].downgraded && 2720 drv_conf_tx(local, link, ac, ¶ms[ac])) 2721 link_err(link, 2722 "failed to set TX queue parameters for AC %d\n", 2723 ac); 2724 } 2725 } 2726 2727 /* MLME */ 2728 static bool 2729 ieee80211_sta_wmm_params(struct ieee80211_local *local, 2730 struct ieee80211_link_data *link, 2731 const u8 *wmm_param, size_t wmm_param_len, 2732 const struct ieee80211_mu_edca_param_set *mu_edca) 2733 { 2734 struct ieee80211_sub_if_data *sdata = link->sdata; 2735 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS]; 2736 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2737 size_t left; 2738 int count, mu_edca_count, ac; 2739 const u8 *pos; 2740 u8 uapsd_queues = 0; 2741 2742 if (!local->ops->conf_tx) 2743 return false; 2744 2745 if (local->hw.queues < IEEE80211_NUM_ACS) 2746 return false; 2747 2748 if (!wmm_param) 2749 return false; 2750 2751 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1) 2752 return false; 2753 2754 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED) 2755 uapsd_queues = ifmgd->uapsd_queues; 2756 2757 count = wmm_param[6] & 0x0f; 2758 /* -1 is the initial value of ifmgd->mu_edca_last_param_set. 2759 * if mu_edca was preset before and now it disappeared tell 2760 * the driver about it. 2761 */ 2762 mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1; 2763 if (count == link->u.mgd.wmm_last_param_set && 2764 mu_edca_count == link->u.mgd.mu_edca_last_param_set) 2765 return false; 2766 link->u.mgd.wmm_last_param_set = count; 2767 link->u.mgd.mu_edca_last_param_set = mu_edca_count; 2768 2769 pos = wmm_param + 8; 2770 left = wmm_param_len - 8; 2771 2772 memset(¶ms, 0, sizeof(params)); 2773 2774 sdata->wmm_acm = 0; 2775 for (; left >= 4; left -= 4, pos += 4) { 2776 int aci = (pos[0] >> 5) & 0x03; 2777 int acm = (pos[0] >> 4) & 0x01; 2778 bool uapsd = false; 2779 2780 switch (aci) { 2781 case 1: /* AC_BK */ 2782 ac = IEEE80211_AC_BK; 2783 if (acm) 2784 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */ 2785 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) 2786 uapsd = true; 2787 params[ac].mu_edca = !!mu_edca; 2788 if (mu_edca) 2789 params[ac].mu_edca_param_rec = mu_edca->ac_bk; 2790 break; 2791 case 2: /* AC_VI */ 2792 ac = IEEE80211_AC_VI; 2793 if (acm) 2794 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */ 2795 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) 2796 uapsd = true; 2797 params[ac].mu_edca = !!mu_edca; 2798 if (mu_edca) 2799 params[ac].mu_edca_param_rec = mu_edca->ac_vi; 2800 break; 2801 case 3: /* AC_VO */ 2802 ac = IEEE80211_AC_VO; 2803 if (acm) 2804 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */ 2805 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) 2806 uapsd = true; 2807 params[ac].mu_edca = !!mu_edca; 2808 if (mu_edca) 2809 params[ac].mu_edca_param_rec = mu_edca->ac_vo; 2810 break; 2811 case 0: /* AC_BE */ 2812 default: 2813 ac = IEEE80211_AC_BE; 2814 if (acm) 2815 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */ 2816 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) 2817 uapsd = true; 2818 params[ac].mu_edca = !!mu_edca; 2819 if (mu_edca) 2820 params[ac].mu_edca_param_rec = mu_edca->ac_be; 2821 break; 2822 } 2823 2824 params[ac].aifs = pos[0] & 0x0f; 2825 2826 if (params[ac].aifs < 2) { 2827 link_info(link, 2828 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n", 2829 params[ac].aifs, aci); 2830 params[ac].aifs = 2; 2831 } 2832 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4); 2833 params[ac].cw_min = ecw2cw(pos[1] & 0x0f); 2834 params[ac].txop = get_unaligned_le16(pos + 2); 2835 params[ac].acm = acm; 2836 params[ac].uapsd = uapsd; 2837 2838 if (params[ac].cw_min == 0 || 2839 params[ac].cw_min > params[ac].cw_max) { 2840 link_info(link, 2841 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n", 2842 params[ac].cw_min, params[ac].cw_max, aci); 2843 return false; 2844 } 2845 ieee80211_regulatory_limit_wmm_params(sdata, ¶ms[ac], ac); 2846 } 2847 2848 /* WMM specification requires all 4 ACIs. */ 2849 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 2850 if (params[ac].cw_min == 0) { 2851 link_info(link, 2852 "AP has invalid WMM params (missing AC %d), using defaults\n", 2853 ac); 2854 return false; 2855 } 2856 } 2857 2858 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) 2859 link->tx_conf[ac] = params[ac]; 2860 2861 ieee80211_mgd_set_link_qos_params(link); 2862 2863 /* enable WMM or activate new settings */ 2864 link->conf->qos = true; 2865 return true; 2866 } 2867 2868 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata) 2869 { 2870 lockdep_assert_wiphy(sdata->local->hw.wiphy); 2871 2872 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL; 2873 ieee80211_run_deferred_scan(sdata->local); 2874 } 2875 2876 static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata) 2877 { 2878 lockdep_assert_wiphy(sdata->local->hw.wiphy); 2879 2880 __ieee80211_stop_poll(sdata); 2881 } 2882 2883 static u64 ieee80211_handle_bss_capability(struct ieee80211_link_data *link, 2884 u16 capab, bool erp_valid, u8 erp) 2885 { 2886 struct ieee80211_bss_conf *bss_conf = link->conf; 2887 struct ieee80211_supported_band *sband; 2888 u64 changed = 0; 2889 bool use_protection; 2890 bool use_short_preamble; 2891 bool use_short_slot; 2892 2893 sband = ieee80211_get_link_sband(link); 2894 if (!sband) 2895 return changed; 2896 2897 if (erp_valid) { 2898 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0; 2899 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0; 2900 } else { 2901 use_protection = false; 2902 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE); 2903 } 2904 2905 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME); 2906 if (sband->band == NL80211_BAND_5GHZ || 2907 sband->band == NL80211_BAND_6GHZ) 2908 use_short_slot = true; 2909 2910 if (use_protection != bss_conf->use_cts_prot) { 2911 bss_conf->use_cts_prot = use_protection; 2912 changed |= BSS_CHANGED_ERP_CTS_PROT; 2913 } 2914 2915 if (use_short_preamble != bss_conf->use_short_preamble) { 2916 bss_conf->use_short_preamble = use_short_preamble; 2917 changed |= BSS_CHANGED_ERP_PREAMBLE; 2918 } 2919 2920 if (use_short_slot != bss_conf->use_short_slot) { 2921 bss_conf->use_short_slot = use_short_slot; 2922 changed |= BSS_CHANGED_ERP_SLOT; 2923 } 2924 2925 return changed; 2926 } 2927 2928 static u64 ieee80211_link_set_associated(struct ieee80211_link_data *link, 2929 struct cfg80211_bss *cbss) 2930 { 2931 struct ieee80211_sub_if_data *sdata = link->sdata; 2932 struct ieee80211_bss_conf *bss_conf = link->conf; 2933 struct ieee80211_bss *bss = (void *)cbss->priv; 2934 u64 changed = BSS_CHANGED_QOS; 2935 2936 /* not really used in MLO */ 2937 sdata->u.mgd.beacon_timeout = 2938 usecs_to_jiffies(ieee80211_tu_to_usec(beacon_loss_count * 2939 bss_conf->beacon_int)); 2940 2941 changed |= ieee80211_handle_bss_capability(link, 2942 bss_conf->assoc_capability, 2943 bss->has_erp_value, 2944 bss->erp_value); 2945 2946 ieee80211_check_rate_mask(link); 2947 2948 link->conf->bss = cbss; 2949 memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN); 2950 2951 if (sdata->vif.p2p || 2952 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) { 2953 const struct cfg80211_bss_ies *ies; 2954 2955 rcu_read_lock(); 2956 ies = rcu_dereference(cbss->ies); 2957 if (ies) { 2958 int ret; 2959 2960 ret = cfg80211_get_p2p_attr( 2961 ies->data, ies->len, 2962 IEEE80211_P2P_ATTR_ABSENCE_NOTICE, 2963 (u8 *) &bss_conf->p2p_noa_attr, 2964 sizeof(bss_conf->p2p_noa_attr)); 2965 if (ret >= 2) { 2966 link->u.mgd.p2p_noa_index = 2967 bss_conf->p2p_noa_attr.index; 2968 changed |= BSS_CHANGED_P2P_PS; 2969 } 2970 } 2971 rcu_read_unlock(); 2972 } 2973 2974 if (link->u.mgd.have_beacon) { 2975 bss_conf->beacon_rate = bss->beacon_rate; 2976 changed |= BSS_CHANGED_BEACON_INFO; 2977 } else { 2978 bss_conf->beacon_rate = NULL; 2979 } 2980 2981 /* Tell the driver to monitor connection quality (if supported) */ 2982 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI && 2983 bss_conf->cqm_rssi_thold) 2984 changed |= BSS_CHANGED_CQM; 2985 2986 return changed; 2987 } 2988 2989 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata, 2990 struct ieee80211_mgd_assoc_data *assoc_data, 2991 u64 changed[IEEE80211_MLD_MAX_NUM_LINKS]) 2992 { 2993 struct ieee80211_local *local = sdata->local; 2994 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg; 2995 u64 vif_changed = BSS_CHANGED_ASSOC; 2996 unsigned int link_id; 2997 2998 lockdep_assert_wiphy(local->hw.wiphy); 2999 3000 sdata->u.mgd.associated = true; 3001 3002 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { 3003 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss; 3004 struct ieee80211_link_data *link; 3005 3006 if (!cbss || 3007 assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) 3008 continue; 3009 3010 if (ieee80211_vif_is_mld(&sdata->vif) && 3011 !(ieee80211_vif_usable_links(&sdata->vif) & BIT(link_id))) 3012 continue; 3013 3014 link = sdata_dereference(sdata->link[link_id], sdata); 3015 if (WARN_ON(!link)) 3016 return; 3017 3018 changed[link_id] |= ieee80211_link_set_associated(link, cbss); 3019 } 3020 3021 /* just to be sure */ 3022 ieee80211_stop_poll(sdata); 3023 3024 ieee80211_led_assoc(local, 1); 3025 3026 vif_cfg->assoc = 1; 3027 3028 /* Enable ARP filtering */ 3029 if (vif_cfg->arp_addr_cnt) 3030 vif_changed |= BSS_CHANGED_ARP_FILTER; 3031 3032 if (ieee80211_vif_is_mld(&sdata->vif)) { 3033 for (link_id = 0; 3034 link_id < IEEE80211_MLD_MAX_NUM_LINKS; 3035 link_id++) { 3036 struct ieee80211_link_data *link; 3037 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss; 3038 3039 if (!cbss || 3040 !(BIT(link_id) & 3041 ieee80211_vif_usable_links(&sdata->vif)) || 3042 assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) 3043 continue; 3044 3045 link = sdata_dereference(sdata->link[link_id], sdata); 3046 if (WARN_ON(!link)) 3047 return; 3048 3049 ieee80211_link_info_change_notify(sdata, link, 3050 changed[link_id]); 3051 3052 ieee80211_recalc_smps(sdata, link); 3053 } 3054 3055 ieee80211_vif_cfg_change_notify(sdata, vif_changed); 3056 } else { 3057 ieee80211_bss_info_change_notify(sdata, 3058 vif_changed | changed[0]); 3059 } 3060 3061 ieee80211_recalc_ps(local); 3062 3063 /* leave this here to not change ordering in non-MLO cases */ 3064 if (!ieee80211_vif_is_mld(&sdata->vif)) 3065 ieee80211_recalc_smps(sdata, &sdata->deflink); 3066 ieee80211_recalc_ps_vif(sdata); 3067 3068 netif_carrier_on(sdata->dev); 3069 } 3070 3071 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata, 3072 u16 stype, u16 reason, bool tx, 3073 u8 *frame_buf) 3074 { 3075 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 3076 struct ieee80211_local *local = sdata->local; 3077 unsigned int link_id; 3078 u64 changed = 0; 3079 struct ieee80211_prep_tx_info info = { 3080 .subtype = stype, 3081 }; 3082 3083 lockdep_assert_wiphy(local->hw.wiphy); 3084 3085 if (WARN_ON_ONCE(tx && !frame_buf)) 3086 return; 3087 3088 if (WARN_ON(!ifmgd->associated)) 3089 return; 3090 3091 ieee80211_stop_poll(sdata); 3092 3093 ifmgd->associated = false; 3094 3095 /* other links will be destroyed */ 3096 sdata->deflink.conf->bss = NULL; 3097 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF; 3098 3099 netif_carrier_off(sdata->dev); 3100 3101 /* 3102 * if we want to get out of ps before disassoc (why?) we have 3103 * to do it before sending disassoc, as otherwise the null-packet 3104 * won't be valid. 3105 */ 3106 if (local->hw.conf.flags & IEEE80211_CONF_PS) { 3107 local->hw.conf.flags &= ~IEEE80211_CONF_PS; 3108 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); 3109 } 3110 local->ps_sdata = NULL; 3111 3112 /* disable per-vif ps */ 3113 ieee80211_recalc_ps_vif(sdata); 3114 3115 /* make sure ongoing transmission finishes */ 3116 synchronize_net(); 3117 3118 /* 3119 * drop any frame before deauth/disassoc, this can be data or 3120 * management frame. Since we are disconnecting, we should not 3121 * insist sending these frames which can take time and delay 3122 * the disconnection and possible the roaming. 3123 */ 3124 if (tx) 3125 ieee80211_flush_queues(local, sdata, true); 3126 3127 /* deauthenticate/disassociate now */ 3128 if (tx || frame_buf) { 3129 /* 3130 * In multi channel scenarios guarantee that the virtual 3131 * interface is granted immediate airtime to transmit the 3132 * deauthentication frame by calling mgd_prepare_tx, if the 3133 * driver requested so. 3134 */ 3135 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP)) { 3136 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); 3137 link_id++) { 3138 struct ieee80211_link_data *link; 3139 3140 link = sdata_dereference(sdata->link[link_id], 3141 sdata); 3142 if (!link) 3143 continue; 3144 if (link->u.mgd.have_beacon) 3145 break; 3146 } 3147 if (link_id == IEEE80211_MLD_MAX_NUM_LINKS) { 3148 info.link_id = ffs(sdata->vif.active_links) - 1; 3149 drv_mgd_prepare_tx(sdata->local, sdata, &info); 3150 } 3151 } 3152 3153 ieee80211_send_deauth_disassoc(sdata, sdata->vif.cfg.ap_addr, 3154 sdata->vif.cfg.ap_addr, stype, 3155 reason, tx, frame_buf); 3156 } 3157 3158 /* flush out frame - make sure the deauth was actually sent */ 3159 if (tx) 3160 ieee80211_flush_queues(local, sdata, false); 3161 3162 drv_mgd_complete_tx(sdata->local, sdata, &info); 3163 3164 /* clear AP addr only after building the needed mgmt frames */ 3165 eth_zero_addr(sdata->deflink.u.mgd.bssid); 3166 eth_zero_addr(sdata->vif.cfg.ap_addr); 3167 3168 sdata->vif.cfg.ssid_len = 0; 3169 3170 /* remove AP and TDLS peers */ 3171 sta_info_flush(sdata, -1); 3172 3173 /* finally reset all BSS / config parameters */ 3174 if (!ieee80211_vif_is_mld(&sdata->vif)) 3175 changed |= ieee80211_reset_erp_info(sdata); 3176 3177 ieee80211_led_assoc(local, 0); 3178 changed |= BSS_CHANGED_ASSOC; 3179 sdata->vif.cfg.assoc = false; 3180 3181 sdata->deflink.u.mgd.p2p_noa_index = -1; 3182 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0, 3183 sizeof(sdata->vif.bss_conf.p2p_noa_attr)); 3184 3185 /* on the next assoc, re-program HT/VHT parameters */ 3186 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa)); 3187 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask)); 3188 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa)); 3189 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask)); 3190 3191 /* 3192 * reset MU-MIMO ownership and group data in default link, 3193 * if used, other links are destroyed 3194 */ 3195 memset(sdata->vif.bss_conf.mu_group.membership, 0, 3196 sizeof(sdata->vif.bss_conf.mu_group.membership)); 3197 memset(sdata->vif.bss_conf.mu_group.position, 0, 3198 sizeof(sdata->vif.bss_conf.mu_group.position)); 3199 if (!ieee80211_vif_is_mld(&sdata->vif)) 3200 changed |= BSS_CHANGED_MU_GROUPS; 3201 sdata->vif.bss_conf.mu_mimo_owner = false; 3202 3203 sdata->deflink.ap_power_level = IEEE80211_UNSET_POWER_LEVEL; 3204 3205 del_timer_sync(&local->dynamic_ps_timer); 3206 wiphy_work_cancel(local->hw.wiphy, &local->dynamic_ps_enable_work); 3207 3208 /* Disable ARP filtering */ 3209 if (sdata->vif.cfg.arp_addr_cnt) 3210 changed |= BSS_CHANGED_ARP_FILTER; 3211 3212 sdata->vif.bss_conf.qos = false; 3213 if (!ieee80211_vif_is_mld(&sdata->vif)) { 3214 changed |= BSS_CHANGED_QOS; 3215 /* The BSSID (not really interesting) and HT changed */ 3216 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT; 3217 ieee80211_bss_info_change_notify(sdata, changed); 3218 } else { 3219 ieee80211_vif_cfg_change_notify(sdata, changed); 3220 } 3221 3222 /* disassociated - set to defaults now */ 3223 ieee80211_set_wmm_default(&sdata->deflink, false, false); 3224 3225 del_timer_sync(&sdata->u.mgd.conn_mon_timer); 3226 del_timer_sync(&sdata->u.mgd.bcn_mon_timer); 3227 del_timer_sync(&sdata->u.mgd.timer); 3228 3229 sdata->vif.bss_conf.dtim_period = 0; 3230 sdata->vif.bss_conf.beacon_rate = NULL; 3231 3232 sdata->deflink.u.mgd.have_beacon = false; 3233 sdata->deflink.u.mgd.tracking_signal_avg = false; 3234 sdata->deflink.u.mgd.disable_wmm_tracking = false; 3235 3236 ifmgd->flags = 0; 3237 3238 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) { 3239 struct ieee80211_link_data *link; 3240 3241 link = sdata_dereference(sdata->link[link_id], sdata); 3242 if (!link) 3243 continue; 3244 ieee80211_link_release_channel(link); 3245 } 3246 3247 sdata->vif.bss_conf.csa_active = false; 3248 sdata->deflink.u.mgd.csa_waiting_bcn = false; 3249 sdata->deflink.u.mgd.csa_ignored_same_chan = false; 3250 if (sdata->csa_blocked_tx) { 3251 ieee80211_wake_vif_queues(local, sdata, 3252 IEEE80211_QUEUE_STOP_REASON_CSA); 3253 sdata->csa_blocked_tx = false; 3254 } 3255 3256 /* existing TX TSPEC sessions no longer exist */ 3257 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec)); 3258 wiphy_delayed_work_cancel(local->hw.wiphy, &ifmgd->tx_tspec_wk); 3259 3260 sdata->vif.bss_conf.power_type = IEEE80211_REG_UNSET_AP; 3261 sdata->vif.bss_conf.pwr_reduction = 0; 3262 sdata->vif.bss_conf.tx_pwr_env_num = 0; 3263 memset(sdata->vif.bss_conf.tx_pwr_env, 0, 3264 sizeof(sdata->vif.bss_conf.tx_pwr_env)); 3265 3266 sdata->vif.cfg.eml_cap = 0; 3267 sdata->vif.cfg.eml_med_sync_delay = 0; 3268 sdata->vif.cfg.mld_capa_op = 0; 3269 3270 memset(&sdata->u.mgd.ttlm_info, 0, 3271 sizeof(sdata->u.mgd.ttlm_info)); 3272 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, &ifmgd->ttlm_work); 3273 3274 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, 3275 &ifmgd->neg_ttlm_timeout_work); 3276 ieee80211_vif_set_links(sdata, 0, 0); 3277 3278 ifmgd->mcast_seq_last = IEEE80211_SN_MODULO; 3279 } 3280 3281 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata) 3282 { 3283 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 3284 struct ieee80211_local *local = sdata->local; 3285 3286 lockdep_assert_wiphy(local->hw.wiphy); 3287 3288 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)) 3289 return; 3290 3291 __ieee80211_stop_poll(sdata); 3292 3293 ieee80211_recalc_ps(local); 3294 3295 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR)) 3296 return; 3297 3298 /* 3299 * We've received a probe response, but are not sure whether 3300 * we have or will be receiving any beacons or data, so let's 3301 * schedule the timers again, just in case. 3302 */ 3303 ieee80211_sta_reset_beacon_monitor(sdata); 3304 3305 mod_timer(&ifmgd->conn_mon_timer, 3306 round_jiffies_up(jiffies + 3307 IEEE80211_CONNECTION_IDLE_TIME)); 3308 } 3309 3310 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata, 3311 struct ieee80211_hdr *hdr, 3312 u16 tx_time) 3313 { 3314 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 3315 u16 tid; 3316 int ac; 3317 struct ieee80211_sta_tx_tspec *tx_tspec; 3318 unsigned long now = jiffies; 3319 3320 if (!ieee80211_is_data_qos(hdr->frame_control)) 3321 return; 3322 3323 tid = ieee80211_get_tid(hdr); 3324 ac = ieee80211_ac_from_tid(tid); 3325 tx_tspec = &ifmgd->tx_tspec[ac]; 3326 3327 if (likely(!tx_tspec->admitted_time)) 3328 return; 3329 3330 if (time_after(now, tx_tspec->time_slice_start + HZ)) { 3331 tx_tspec->consumed_tx_time = 0; 3332 tx_tspec->time_slice_start = now; 3333 3334 if (tx_tspec->downgraded) { 3335 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE; 3336 wiphy_delayed_work_queue(sdata->local->hw.wiphy, 3337 &ifmgd->tx_tspec_wk, 0); 3338 } 3339 } 3340 3341 if (tx_tspec->downgraded) 3342 return; 3343 3344 tx_tspec->consumed_tx_time += tx_time; 3345 3346 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) { 3347 tx_tspec->downgraded = true; 3348 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE; 3349 wiphy_delayed_work_queue(sdata->local->hw.wiphy, 3350 &ifmgd->tx_tspec_wk, 0); 3351 } 3352 } 3353 3354 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata, 3355 struct ieee80211_hdr *hdr, bool ack, u16 tx_time) 3356 { 3357 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time); 3358 3359 if (!ieee80211_is_any_nullfunc(hdr->frame_control) || 3360 !sdata->u.mgd.probe_send_count) 3361 return; 3362 3363 if (ack) 3364 sdata->u.mgd.probe_send_count = 0; 3365 else 3366 sdata->u.mgd.nullfunc_failed = true; 3367 wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work); 3368 } 3369 3370 static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata, 3371 const u8 *src, const u8 *dst, 3372 const u8 *ssid, size_t ssid_len, 3373 struct ieee80211_channel *channel) 3374 { 3375 struct sk_buff *skb; 3376 3377 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel, 3378 ssid, ssid_len, NULL, 0, 3379 IEEE80211_PROBE_FLAG_DIRECTED); 3380 if (skb) 3381 ieee80211_tx_skb(sdata, skb); 3382 } 3383 3384 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata) 3385 { 3386 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 3387 u8 *dst = sdata->vif.cfg.ap_addr; 3388 u8 unicast_limit = max(1, max_probe_tries - 3); 3389 struct sta_info *sta; 3390 3391 lockdep_assert_wiphy(sdata->local->hw.wiphy); 3392 3393 if (WARN_ON(ieee80211_vif_is_mld(&sdata->vif))) 3394 return; 3395 3396 /* 3397 * Try sending broadcast probe requests for the last three 3398 * probe requests after the first ones failed since some 3399 * buggy APs only support broadcast probe requests. 3400 */ 3401 if (ifmgd->probe_send_count >= unicast_limit) 3402 dst = NULL; 3403 3404 /* 3405 * When the hardware reports an accurate Tx ACK status, it's 3406 * better to send a nullfunc frame instead of a probe request, 3407 * as it will kick us off the AP quickly if we aren't associated 3408 * anymore. The timeout will be reset if the frame is ACKed by 3409 * the AP. 3410 */ 3411 ifmgd->probe_send_count++; 3412 3413 if (dst) { 3414 sta = sta_info_get(sdata, dst); 3415 if (!WARN_ON(!sta)) 3416 ieee80211_check_fast_rx(sta); 3417 } 3418 3419 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) { 3420 ifmgd->nullfunc_failed = false; 3421 ieee80211_send_nullfunc(sdata->local, sdata, false); 3422 } else { 3423 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst, 3424 sdata->vif.cfg.ssid, 3425 sdata->vif.cfg.ssid_len, 3426 sdata->deflink.conf->bss->channel); 3427 } 3428 3429 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms); 3430 run_again(sdata, ifmgd->probe_timeout); 3431 } 3432 3433 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata, 3434 bool beacon) 3435 { 3436 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 3437 bool already = false; 3438 3439 lockdep_assert_wiphy(sdata->local->hw.wiphy); 3440 3441 if (WARN_ON_ONCE(ieee80211_vif_is_mld(&sdata->vif))) 3442 return; 3443 3444 if (!ieee80211_sdata_running(sdata)) 3445 return; 3446 3447 if (!ifmgd->associated) 3448 return; 3449 3450 if (sdata->local->tmp_channel || sdata->local->scanning) 3451 return; 3452 3453 if (sdata->local->suspending) { 3454 /* reschedule after resume */ 3455 ieee80211_reset_ap_probe(sdata); 3456 return; 3457 } 3458 3459 if (beacon) { 3460 mlme_dbg_ratelimited(sdata, 3461 "detected beacon loss from AP (missed %d beacons) - probing\n", 3462 beacon_loss_count); 3463 3464 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL); 3465 } 3466 3467 /* 3468 * The driver/our work has already reported this event or the 3469 * connection monitoring has kicked in and we have already sent 3470 * a probe request. Or maybe the AP died and the driver keeps 3471 * reporting until we disassociate... 3472 * 3473 * In either case we have to ignore the current call to this 3474 * function (except for setting the correct probe reason bit) 3475 * because otherwise we would reset the timer every time and 3476 * never check whether we received a probe response! 3477 */ 3478 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) 3479 already = true; 3480 3481 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL; 3482 3483 if (already) 3484 return; 3485 3486 ieee80211_recalc_ps(sdata->local); 3487 3488 ifmgd->probe_send_count = 0; 3489 ieee80211_mgd_probe_ap_send(sdata); 3490 } 3491 3492 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw, 3493 struct ieee80211_vif *vif) 3494 { 3495 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 3496 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 3497 struct cfg80211_bss *cbss; 3498 struct sk_buff *skb; 3499 const struct element *ssid; 3500 int ssid_len; 3501 3502 lockdep_assert_wiphy(sdata->local->hw.wiphy); 3503 3504 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION || 3505 ieee80211_vif_is_mld(&sdata->vif))) 3506 return NULL; 3507 3508 if (ifmgd->associated) 3509 cbss = sdata->deflink.conf->bss; 3510 else if (ifmgd->auth_data) 3511 cbss = ifmgd->auth_data->bss; 3512 else if (ifmgd->assoc_data && ifmgd->assoc_data->link[0].bss) 3513 cbss = ifmgd->assoc_data->link[0].bss; 3514 else 3515 return NULL; 3516 3517 rcu_read_lock(); 3518 ssid = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID); 3519 if (WARN_ONCE(!ssid || ssid->datalen > IEEE80211_MAX_SSID_LEN, 3520 "invalid SSID element (len=%d)", 3521 ssid ? ssid->datalen : -1)) 3522 ssid_len = 0; 3523 else 3524 ssid_len = ssid->datalen; 3525 3526 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid, 3527 (u32) -1, cbss->channel, 3528 ssid->data, ssid_len, 3529 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED); 3530 rcu_read_unlock(); 3531 3532 return skb; 3533 } 3534 EXPORT_SYMBOL(ieee80211_ap_probereq_get); 3535 3536 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata, 3537 const u8 *buf, size_t len, bool tx, 3538 u16 reason, bool reconnect) 3539 { 3540 struct ieee80211_event event = { 3541 .type = MLME_EVENT, 3542 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT, 3543 .u.mlme.reason = reason, 3544 }; 3545 3546 if (tx) 3547 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect); 3548 else 3549 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len); 3550 3551 drv_event_callback(sdata->local, sdata, &event); 3552 } 3553 3554 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata) 3555 { 3556 struct ieee80211_local *local = sdata->local; 3557 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 3558 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; 3559 bool tx; 3560 3561 lockdep_assert_wiphy(local->hw.wiphy); 3562 3563 if (!ifmgd->associated) 3564 return; 3565 3566 /* 3567 * MLO drivers should have HANDLES_QUIET_CSA, so that csa_blocked_tx 3568 * is always false; if they don't then this may try to transmit the 3569 * frame but queues will be stopped. 3570 */ 3571 tx = !sdata->csa_blocked_tx; 3572 3573 if (!ifmgd->driver_disconnect) { 3574 unsigned int link_id; 3575 3576 /* 3577 * AP is probably out of range (or not reachable for another 3578 * reason) so remove the bss structs for that AP. In the case 3579 * of multi-link, it's not clear that all of them really are 3580 * out of range, but if they weren't the driver likely would 3581 * have switched to just have a single link active? 3582 */ 3583 for (link_id = 0; 3584 link_id < ARRAY_SIZE(sdata->link); 3585 link_id++) { 3586 struct ieee80211_link_data *link; 3587 3588 link = sdata_dereference(sdata->link[link_id], sdata); 3589 if (!link) 3590 continue; 3591 cfg80211_unlink_bss(local->hw.wiphy, link->conf->bss); 3592 link->conf->bss = NULL; 3593 } 3594 } 3595 3596 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, 3597 ifmgd->driver_disconnect ? 3598 WLAN_REASON_DEAUTH_LEAVING : 3599 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, 3600 tx, frame_buf); 3601 /* the other links will be destroyed */ 3602 sdata->vif.bss_conf.csa_active = false; 3603 sdata->deflink.u.mgd.csa_waiting_bcn = false; 3604 if (sdata->csa_blocked_tx) { 3605 ieee80211_wake_vif_queues(local, sdata, 3606 IEEE80211_QUEUE_STOP_REASON_CSA); 3607 sdata->csa_blocked_tx = false; 3608 } 3609 3610 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx, 3611 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, 3612 ifmgd->reconnect); 3613 ifmgd->reconnect = false; 3614 } 3615 3616 static void ieee80211_beacon_connection_loss_work(struct wiphy *wiphy, 3617 struct wiphy_work *work) 3618 { 3619 struct ieee80211_sub_if_data *sdata = 3620 container_of(work, struct ieee80211_sub_if_data, 3621 u.mgd.beacon_connection_loss_work); 3622 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 3623 3624 if (ifmgd->connection_loss) { 3625 sdata_info(sdata, "Connection to AP %pM lost\n", 3626 sdata->vif.cfg.ap_addr); 3627 __ieee80211_disconnect(sdata); 3628 ifmgd->connection_loss = false; 3629 } else if (ifmgd->driver_disconnect) { 3630 sdata_info(sdata, 3631 "Driver requested disconnection from AP %pM\n", 3632 sdata->vif.cfg.ap_addr); 3633 __ieee80211_disconnect(sdata); 3634 ifmgd->driver_disconnect = false; 3635 } else { 3636 if (ifmgd->associated) 3637 sdata->deflink.u.mgd.beacon_loss_count++; 3638 ieee80211_mgd_probe_ap(sdata, true); 3639 } 3640 } 3641 3642 static void ieee80211_csa_connection_drop_work(struct wiphy *wiphy, 3643 struct wiphy_work *work) 3644 { 3645 struct ieee80211_sub_if_data *sdata = 3646 container_of(work, struct ieee80211_sub_if_data, 3647 u.mgd.csa_connection_drop_work); 3648 3649 __ieee80211_disconnect(sdata); 3650 } 3651 3652 void ieee80211_beacon_loss(struct ieee80211_vif *vif) 3653 { 3654 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 3655 struct ieee80211_hw *hw = &sdata->local->hw; 3656 3657 trace_api_beacon_loss(sdata); 3658 3659 sdata->u.mgd.connection_loss = false; 3660 wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work); 3661 } 3662 EXPORT_SYMBOL(ieee80211_beacon_loss); 3663 3664 void ieee80211_connection_loss(struct ieee80211_vif *vif) 3665 { 3666 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 3667 struct ieee80211_hw *hw = &sdata->local->hw; 3668 3669 trace_api_connection_loss(sdata); 3670 3671 sdata->u.mgd.connection_loss = true; 3672 wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work); 3673 } 3674 EXPORT_SYMBOL(ieee80211_connection_loss); 3675 3676 void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect) 3677 { 3678 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 3679 struct ieee80211_hw *hw = &sdata->local->hw; 3680 3681 trace_api_disconnect(sdata, reconnect); 3682 3683 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) 3684 return; 3685 3686 sdata->u.mgd.driver_disconnect = true; 3687 sdata->u.mgd.reconnect = reconnect; 3688 wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work); 3689 } 3690 EXPORT_SYMBOL(ieee80211_disconnect); 3691 3692 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata, 3693 bool assoc) 3694 { 3695 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data; 3696 3697 lockdep_assert_wiphy(sdata->local->hw.wiphy); 3698 3699 if (!assoc) { 3700 /* 3701 * we are not authenticated yet, the only timer that could be 3702 * running is the timeout for the authentication response which 3703 * which is not relevant anymore. 3704 */ 3705 del_timer_sync(&sdata->u.mgd.timer); 3706 sta_info_destroy_addr(sdata, auth_data->ap_addr); 3707 3708 /* other links are destroyed */ 3709 eth_zero_addr(sdata->deflink.u.mgd.bssid); 3710 ieee80211_link_info_change_notify(sdata, &sdata->deflink, 3711 BSS_CHANGED_BSSID); 3712 sdata->u.mgd.flags = 0; 3713 3714 ieee80211_link_release_channel(&sdata->deflink); 3715 ieee80211_vif_set_links(sdata, 0, 0); 3716 } 3717 3718 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss); 3719 kfree(auth_data); 3720 sdata->u.mgd.auth_data = NULL; 3721 } 3722 3723 enum assoc_status { 3724 ASSOC_SUCCESS, 3725 ASSOC_REJECTED, 3726 ASSOC_TIMEOUT, 3727 ASSOC_ABANDON, 3728 }; 3729 3730 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata, 3731 enum assoc_status status) 3732 { 3733 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data; 3734 3735 lockdep_assert_wiphy(sdata->local->hw.wiphy); 3736 3737 if (status != ASSOC_SUCCESS) { 3738 /* 3739 * we are not associated yet, the only timer that could be 3740 * running is the timeout for the association response which 3741 * which is not relevant anymore. 3742 */ 3743 del_timer_sync(&sdata->u.mgd.timer); 3744 sta_info_destroy_addr(sdata, assoc_data->ap_addr); 3745 3746 eth_zero_addr(sdata->deflink.u.mgd.bssid); 3747 ieee80211_link_info_change_notify(sdata, &sdata->deflink, 3748 BSS_CHANGED_BSSID); 3749 sdata->u.mgd.flags = 0; 3750 sdata->vif.bss_conf.mu_mimo_owner = false; 3751 3752 if (status != ASSOC_REJECTED) { 3753 struct cfg80211_assoc_failure data = { 3754 .timeout = status == ASSOC_TIMEOUT, 3755 }; 3756 int i; 3757 3758 BUILD_BUG_ON(ARRAY_SIZE(data.bss) != 3759 ARRAY_SIZE(assoc_data->link)); 3760 3761 for (i = 0; i < ARRAY_SIZE(data.bss); i++) 3762 data.bss[i] = assoc_data->link[i].bss; 3763 3764 if (ieee80211_vif_is_mld(&sdata->vif)) 3765 data.ap_mld_addr = assoc_data->ap_addr; 3766 3767 cfg80211_assoc_failure(sdata->dev, &data); 3768 } 3769 3770 ieee80211_link_release_channel(&sdata->deflink); 3771 ieee80211_vif_set_links(sdata, 0, 0); 3772 } 3773 3774 kfree(assoc_data); 3775 sdata->u.mgd.assoc_data = NULL; 3776 } 3777 3778 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata, 3779 struct ieee80211_mgmt *mgmt, size_t len) 3780 { 3781 struct ieee80211_local *local = sdata->local; 3782 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data; 3783 const struct element *challenge; 3784 u8 *pos; 3785 u32 tx_flags = 0; 3786 struct ieee80211_prep_tx_info info = { 3787 .subtype = IEEE80211_STYPE_AUTH, 3788 .link_id = auth_data->link_id, 3789 }; 3790 3791 pos = mgmt->u.auth.variable; 3792 challenge = cfg80211_find_elem(WLAN_EID_CHALLENGE, pos, 3793 len - (pos - (u8 *)mgmt)); 3794 if (!challenge) 3795 return; 3796 auth_data->expected_transaction = 4; 3797 drv_mgd_prepare_tx(sdata->local, sdata, &info); 3798 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) 3799 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS | 3800 IEEE80211_TX_INTFL_MLME_CONN_TX; 3801 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0, 3802 (void *)challenge, 3803 challenge->datalen + sizeof(*challenge), 3804 auth_data->ap_addr, auth_data->ap_addr, 3805 auth_data->key, auth_data->key_len, 3806 auth_data->key_idx, tx_flags); 3807 } 3808 3809 static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata) 3810 { 3811 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 3812 const u8 *ap_addr = ifmgd->auth_data->ap_addr; 3813 struct sta_info *sta; 3814 3815 lockdep_assert_wiphy(sdata->local->hw.wiphy); 3816 3817 sdata_info(sdata, "authenticated\n"); 3818 ifmgd->auth_data->done = true; 3819 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC; 3820 ifmgd->auth_data->timeout_started = true; 3821 run_again(sdata, ifmgd->auth_data->timeout); 3822 3823 /* move station state to auth */ 3824 sta = sta_info_get(sdata, ap_addr); 3825 if (!sta) { 3826 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, ap_addr); 3827 return false; 3828 } 3829 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) { 3830 sdata_info(sdata, "failed moving %pM to auth\n", ap_addr); 3831 return false; 3832 } 3833 3834 return true; 3835 } 3836 3837 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata, 3838 struct ieee80211_mgmt *mgmt, size_t len) 3839 { 3840 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 3841 u16 auth_alg, auth_transaction, status_code; 3842 struct ieee80211_event event = { 3843 .type = MLME_EVENT, 3844 .u.mlme.data = AUTH_EVENT, 3845 }; 3846 struct ieee80211_prep_tx_info info = { 3847 .subtype = IEEE80211_STYPE_AUTH, 3848 }; 3849 3850 lockdep_assert_wiphy(sdata->local->hw.wiphy); 3851 3852 if (len < 24 + 6) 3853 return; 3854 3855 if (!ifmgd->auth_data || ifmgd->auth_data->done) 3856 return; 3857 3858 if (!ether_addr_equal(ifmgd->auth_data->ap_addr, mgmt->bssid)) 3859 return; 3860 3861 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); 3862 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); 3863 status_code = le16_to_cpu(mgmt->u.auth.status_code); 3864 3865 if (auth_alg != ifmgd->auth_data->algorithm || 3866 (auth_alg != WLAN_AUTH_SAE && 3867 auth_transaction != ifmgd->auth_data->expected_transaction) || 3868 (auth_alg == WLAN_AUTH_SAE && 3869 (auth_transaction < ifmgd->auth_data->expected_transaction || 3870 auth_transaction > 2))) { 3871 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n", 3872 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm, 3873 auth_transaction, 3874 ifmgd->auth_data->expected_transaction); 3875 goto notify_driver; 3876 } 3877 3878 if (status_code != WLAN_STATUS_SUCCESS) { 3879 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len); 3880 3881 if (auth_alg == WLAN_AUTH_SAE && 3882 (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED || 3883 (auth_transaction == 1 && 3884 (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT || 3885 status_code == WLAN_STATUS_SAE_PK)))) { 3886 /* waiting for userspace now */ 3887 ifmgd->auth_data->waiting = true; 3888 ifmgd->auth_data->timeout = 3889 jiffies + IEEE80211_AUTH_WAIT_SAE_RETRY; 3890 ifmgd->auth_data->timeout_started = true; 3891 run_again(sdata, ifmgd->auth_data->timeout); 3892 goto notify_driver; 3893 } 3894 3895 sdata_info(sdata, "%pM denied authentication (status %d)\n", 3896 mgmt->sa, status_code); 3897 ieee80211_destroy_auth_data(sdata, false); 3898 event.u.mlme.status = MLME_DENIED; 3899 event.u.mlme.reason = status_code; 3900 drv_event_callback(sdata->local, sdata, &event); 3901 goto notify_driver; 3902 } 3903 3904 switch (ifmgd->auth_data->algorithm) { 3905 case WLAN_AUTH_OPEN: 3906 case WLAN_AUTH_LEAP: 3907 case WLAN_AUTH_FT: 3908 case WLAN_AUTH_SAE: 3909 case WLAN_AUTH_FILS_SK: 3910 case WLAN_AUTH_FILS_SK_PFS: 3911 case WLAN_AUTH_FILS_PK: 3912 break; 3913 case WLAN_AUTH_SHARED_KEY: 3914 if (ifmgd->auth_data->expected_transaction != 4) { 3915 ieee80211_auth_challenge(sdata, mgmt, len); 3916 /* need another frame */ 3917 return; 3918 } 3919 break; 3920 default: 3921 WARN_ONCE(1, "invalid auth alg %d", 3922 ifmgd->auth_data->algorithm); 3923 goto notify_driver; 3924 } 3925 3926 event.u.mlme.status = MLME_SUCCESS; 3927 info.success = 1; 3928 drv_event_callback(sdata->local, sdata, &event); 3929 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE || 3930 (auth_transaction == 2 && 3931 ifmgd->auth_data->expected_transaction == 2)) { 3932 if (!ieee80211_mark_sta_auth(sdata)) 3933 return; /* ignore frame -- wait for timeout */ 3934 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE && 3935 auth_transaction == 2) { 3936 sdata_info(sdata, "SAE peer confirmed\n"); 3937 ifmgd->auth_data->peer_confirmed = true; 3938 } 3939 3940 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len); 3941 notify_driver: 3942 drv_mgd_complete_tx(sdata->local, sdata, &info); 3943 } 3944 3945 #define case_WLAN(type) \ 3946 case WLAN_REASON_##type: return #type 3947 3948 const char *ieee80211_get_reason_code_string(u16 reason_code) 3949 { 3950 switch (reason_code) { 3951 case_WLAN(UNSPECIFIED); 3952 case_WLAN(PREV_AUTH_NOT_VALID); 3953 case_WLAN(DEAUTH_LEAVING); 3954 case_WLAN(DISASSOC_DUE_TO_INACTIVITY); 3955 case_WLAN(DISASSOC_AP_BUSY); 3956 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA); 3957 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA); 3958 case_WLAN(DISASSOC_STA_HAS_LEFT); 3959 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH); 3960 case_WLAN(DISASSOC_BAD_POWER); 3961 case_WLAN(DISASSOC_BAD_SUPP_CHAN); 3962 case_WLAN(INVALID_IE); 3963 case_WLAN(MIC_FAILURE); 3964 case_WLAN(4WAY_HANDSHAKE_TIMEOUT); 3965 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT); 3966 case_WLAN(IE_DIFFERENT); 3967 case_WLAN(INVALID_GROUP_CIPHER); 3968 case_WLAN(INVALID_PAIRWISE_CIPHER); 3969 case_WLAN(INVALID_AKMP); 3970 case_WLAN(UNSUPP_RSN_VERSION); 3971 case_WLAN(INVALID_RSN_IE_CAP); 3972 case_WLAN(IEEE8021X_FAILED); 3973 case_WLAN(CIPHER_SUITE_REJECTED); 3974 case_WLAN(DISASSOC_UNSPECIFIED_QOS); 3975 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH); 3976 case_WLAN(DISASSOC_LOW_ACK); 3977 case_WLAN(DISASSOC_QAP_EXCEED_TXOP); 3978 case_WLAN(QSTA_LEAVE_QBSS); 3979 case_WLAN(QSTA_NOT_USE); 3980 case_WLAN(QSTA_REQUIRE_SETUP); 3981 case_WLAN(QSTA_TIMEOUT); 3982 case_WLAN(QSTA_CIPHER_NOT_SUPP); 3983 case_WLAN(MESH_PEER_CANCELED); 3984 case_WLAN(MESH_MAX_PEERS); 3985 case_WLAN(MESH_CONFIG); 3986 case_WLAN(MESH_CLOSE); 3987 case_WLAN(MESH_MAX_RETRIES); 3988 case_WLAN(MESH_CONFIRM_TIMEOUT); 3989 case_WLAN(MESH_INVALID_GTK); 3990 case_WLAN(MESH_INCONSISTENT_PARAM); 3991 case_WLAN(MESH_INVALID_SECURITY); 3992 case_WLAN(MESH_PATH_ERROR); 3993 case_WLAN(MESH_PATH_NOFORWARD); 3994 case_WLAN(MESH_PATH_DEST_UNREACHABLE); 3995 case_WLAN(MAC_EXISTS_IN_MBSS); 3996 case_WLAN(MESH_CHAN_REGULATORY); 3997 case_WLAN(MESH_CHAN); 3998 default: return "<unknown>"; 3999 } 4000 } 4001 4002 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata, 4003 struct ieee80211_mgmt *mgmt, size_t len) 4004 { 4005 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 4006 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); 4007 4008 lockdep_assert_wiphy(sdata->local->hw.wiphy); 4009 4010 if (len < 24 + 2) 4011 return; 4012 4013 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) { 4014 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code); 4015 return; 4016 } 4017 4018 if (ifmgd->associated && 4019 ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr)) { 4020 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n", 4021 sdata->vif.cfg.ap_addr, reason_code, 4022 ieee80211_get_reason_code_string(reason_code)); 4023 4024 ieee80211_set_disassoc(sdata, 0, 0, false, NULL); 4025 4026 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, 4027 reason_code, false); 4028 return; 4029 } 4030 4031 if (ifmgd->assoc_data && 4032 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->ap_addr)) { 4033 sdata_info(sdata, 4034 "deauthenticated from %pM while associating (Reason: %u=%s)\n", 4035 ifmgd->assoc_data->ap_addr, reason_code, 4036 ieee80211_get_reason_code_string(reason_code)); 4037 4038 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON); 4039 4040 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len); 4041 return; 4042 } 4043 } 4044 4045 4046 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata, 4047 struct ieee80211_mgmt *mgmt, size_t len) 4048 { 4049 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 4050 u16 reason_code; 4051 4052 lockdep_assert_wiphy(sdata->local->hw.wiphy); 4053 4054 if (len < 24 + 2) 4055 return; 4056 4057 if (!ifmgd->associated || 4058 !ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr)) 4059 return; 4060 4061 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); 4062 4063 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) { 4064 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code); 4065 return; 4066 } 4067 4068 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n", 4069 sdata->vif.cfg.ap_addr, reason_code, 4070 ieee80211_get_reason_code_string(reason_code)); 4071 4072 ieee80211_set_disassoc(sdata, 0, 0, false, NULL); 4073 4074 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code, 4075 false); 4076 } 4077 4078 static void ieee80211_get_rates(struct ieee80211_supported_band *sband, 4079 u8 *supp_rates, unsigned int supp_rates_len, 4080 u32 *rates, u32 *basic_rates, 4081 bool *have_higher_than_11mbit, 4082 int *min_rate, int *min_rate_index) 4083 { 4084 int i, j; 4085 4086 for (i = 0; i < supp_rates_len; i++) { 4087 int rate = supp_rates[i] & 0x7f; 4088 bool is_basic = !!(supp_rates[i] & 0x80); 4089 4090 if ((rate * 5) > 110) 4091 *have_higher_than_11mbit = true; 4092 4093 /* 4094 * Skip HT, VHT, HE, EHT and SAE H2E only BSS membership 4095 * selectors since they're not rates. 4096 * 4097 * Note: Even though the membership selector and the basic 4098 * rate flag share the same bit, they are not exactly 4099 * the same. 4100 */ 4101 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) || 4102 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY) || 4103 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY) || 4104 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_EHT_PHY) || 4105 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E)) 4106 continue; 4107 4108 for (j = 0; j < sband->n_bitrates; j++) { 4109 struct ieee80211_rate *br; 4110 int brate; 4111 4112 br = &sband->bitrates[j]; 4113 4114 brate = DIV_ROUND_UP(br->bitrate, 5); 4115 if (brate == rate) { 4116 *rates |= BIT(j); 4117 if (is_basic) 4118 *basic_rates |= BIT(j); 4119 if ((rate * 5) < *min_rate) { 4120 *min_rate = rate * 5; 4121 *min_rate_index = j; 4122 } 4123 break; 4124 } 4125 } 4126 } 4127 } 4128 4129 static bool ieee80211_twt_req_supported(struct ieee80211_sub_if_data *sdata, 4130 struct ieee80211_supported_band *sband, 4131 const struct link_sta_info *link_sta, 4132 const struct ieee802_11_elems *elems) 4133 { 4134 const struct ieee80211_sta_he_cap *own_he_cap = 4135 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif); 4136 4137 if (elems->ext_capab_len < 10) 4138 return false; 4139 4140 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT)) 4141 return false; 4142 4143 return link_sta->pub->he_cap.he_cap_elem.mac_cap_info[0] & 4144 IEEE80211_HE_MAC_CAP0_TWT_RES && 4145 own_he_cap && 4146 (own_he_cap->he_cap_elem.mac_cap_info[0] & 4147 IEEE80211_HE_MAC_CAP0_TWT_REQ); 4148 } 4149 4150 static u64 ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata, 4151 struct ieee80211_supported_band *sband, 4152 struct ieee80211_link_data *link, 4153 struct link_sta_info *link_sta, 4154 struct ieee802_11_elems *elems) 4155 { 4156 bool twt = ieee80211_twt_req_supported(sdata, sband, link_sta, elems); 4157 4158 if (link->conf->twt_requester != twt) { 4159 link->conf->twt_requester = twt; 4160 return BSS_CHANGED_TWT; 4161 } 4162 return 0; 4163 } 4164 4165 static bool ieee80211_twt_bcast_support(struct ieee80211_sub_if_data *sdata, 4166 struct ieee80211_bss_conf *bss_conf, 4167 struct ieee80211_supported_band *sband, 4168 struct link_sta_info *link_sta) 4169 { 4170 const struct ieee80211_sta_he_cap *own_he_cap = 4171 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif); 4172 4173 return bss_conf->he_support && 4174 (link_sta->pub->he_cap.he_cap_elem.mac_cap_info[2] & 4175 IEEE80211_HE_MAC_CAP2_BCAST_TWT) && 4176 own_he_cap && 4177 (own_he_cap->he_cap_elem.mac_cap_info[2] & 4178 IEEE80211_HE_MAC_CAP2_BCAST_TWT); 4179 } 4180 4181 static bool ieee80211_assoc_config_link(struct ieee80211_link_data *link, 4182 struct link_sta_info *link_sta, 4183 struct cfg80211_bss *cbss, 4184 struct ieee80211_mgmt *mgmt, 4185 const u8 *elem_start, 4186 unsigned int elem_len, 4187 u64 *changed) 4188 { 4189 struct ieee80211_sub_if_data *sdata = link->sdata; 4190 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data; 4191 struct ieee80211_bss_conf *bss_conf = link->conf; 4192 struct ieee80211_local *local = sdata->local; 4193 unsigned int link_id = link->link_id; 4194 struct ieee80211_elems_parse_params parse_params = { 4195 .mode = link->u.mgd.conn.mode, 4196 .start = elem_start, 4197 .len = elem_len, 4198 .link_id = link_id == assoc_data->assoc_link_id ? -1 : link_id, 4199 .from_ap = true, 4200 }; 4201 bool is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ; 4202 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ; 4203 bool is_s1g = cbss->channel->band == NL80211_BAND_S1GHZ; 4204 const struct cfg80211_bss_ies *bss_ies = NULL; 4205 struct ieee80211_supported_band *sband; 4206 struct ieee802_11_elems *elems; 4207 const __le16 prof_bss_param_ch_present = 4208 cpu_to_le16(IEEE80211_MLE_STA_CONTROL_BSS_PARAM_CHANGE_CNT_PRESENT); 4209 u16 capab_info; 4210 bool ret; 4211 4212 elems = ieee802_11_parse_elems_full(&parse_params); 4213 if (!elems) 4214 return false; 4215 4216 if (link_id == assoc_data->assoc_link_id) { 4217 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); 4218 4219 /* 4220 * we should not get to this flow unless the association was 4221 * successful, so set the status directly to success 4222 */ 4223 assoc_data->link[link_id].status = WLAN_STATUS_SUCCESS; 4224 if (elems->ml_basic) { 4225 int bss_param_ch_cnt = 4226 ieee80211_mle_get_bss_param_ch_cnt((const void *)elems->ml_basic); 4227 4228 if (bss_param_ch_cnt < 0) { 4229 ret = false; 4230 goto out; 4231 } 4232 link->u.mgd.bss_param_ch_cnt = bss_param_ch_cnt; 4233 } 4234 } else if (elems->parse_error & IEEE80211_PARSE_ERR_DUP_NEST_ML_BASIC || 4235 !elems->prof || 4236 !(elems->prof->control & prof_bss_param_ch_present)) { 4237 ret = false; 4238 goto out; 4239 } else { 4240 const u8 *ptr = elems->prof->variable + 4241 elems->prof->sta_info_len - 1; 4242 4243 /* 4244 * During parsing, we validated that these fields exist, 4245 * otherwise elems->prof would have been set to NULL. 4246 */ 4247 capab_info = get_unaligned_le16(ptr); 4248 assoc_data->link[link_id].status = get_unaligned_le16(ptr + 2); 4249 link->u.mgd.bss_param_ch_cnt = 4250 ieee80211_mle_basic_sta_prof_bss_param_ch_cnt(elems->prof); 4251 4252 if (assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) { 4253 link_info(link, "association response status code=%u\n", 4254 assoc_data->link[link_id].status); 4255 ret = true; 4256 goto out; 4257 } 4258 } 4259 4260 if (!is_s1g && !elems->supp_rates) { 4261 sdata_info(sdata, "no SuppRates element in AssocResp\n"); 4262 ret = false; 4263 goto out; 4264 } 4265 4266 link->u.mgd.tdls_chan_switch_prohibited = 4267 elems->ext_capab && elems->ext_capab_len >= 5 && 4268 (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED); 4269 4270 /* 4271 * Some APs are erroneously not including some information in their 4272 * (re)association response frames. Try to recover by using the data 4273 * from the beacon or probe response. This seems to afflict mobile 4274 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T", 4275 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device. 4276 */ 4277 if (!is_6ghz && 4278 ((assoc_data->wmm && !elems->wmm_param) || 4279 (link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HT && 4280 (!elems->ht_cap_elem || !elems->ht_operation)) || 4281 (link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_VHT && 4282 (!elems->vht_cap_elem || !elems->vht_operation)))) { 4283 const struct cfg80211_bss_ies *ies; 4284 struct ieee802_11_elems *bss_elems; 4285 4286 rcu_read_lock(); 4287 ies = rcu_dereference(cbss->ies); 4288 if (ies) 4289 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len, 4290 GFP_ATOMIC); 4291 rcu_read_unlock(); 4292 if (!bss_ies) { 4293 ret = false; 4294 goto out; 4295 } 4296 4297 parse_params.start = bss_ies->data; 4298 parse_params.len = bss_ies->len; 4299 parse_params.bss = cbss; 4300 bss_elems = ieee802_11_parse_elems_full(&parse_params); 4301 if (!bss_elems) { 4302 ret = false; 4303 goto out; 4304 } 4305 4306 if (assoc_data->wmm && 4307 !elems->wmm_param && bss_elems->wmm_param) { 4308 elems->wmm_param = bss_elems->wmm_param; 4309 sdata_info(sdata, 4310 "AP bug: WMM param missing from AssocResp\n"); 4311 } 4312 4313 /* 4314 * Also check if we requested HT/VHT, otherwise the AP doesn't 4315 * have to include the IEs in the (re)association response. 4316 */ 4317 if (!elems->ht_cap_elem && bss_elems->ht_cap_elem && 4318 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HT) { 4319 elems->ht_cap_elem = bss_elems->ht_cap_elem; 4320 sdata_info(sdata, 4321 "AP bug: HT capability missing from AssocResp\n"); 4322 } 4323 if (!elems->ht_operation && bss_elems->ht_operation && 4324 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HT) { 4325 elems->ht_operation = bss_elems->ht_operation; 4326 sdata_info(sdata, 4327 "AP bug: HT operation missing from AssocResp\n"); 4328 } 4329 if (!elems->vht_cap_elem && bss_elems->vht_cap_elem && 4330 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_VHT) { 4331 elems->vht_cap_elem = bss_elems->vht_cap_elem; 4332 sdata_info(sdata, 4333 "AP bug: VHT capa missing from AssocResp\n"); 4334 } 4335 if (!elems->vht_operation && bss_elems->vht_operation && 4336 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_VHT) { 4337 elems->vht_operation = bss_elems->vht_operation; 4338 sdata_info(sdata, 4339 "AP bug: VHT operation missing from AssocResp\n"); 4340 } 4341 4342 kfree(bss_elems); 4343 } 4344 4345 /* 4346 * We previously checked these in the beacon/probe response, so 4347 * they should be present here. This is just a safety net. 4348 * Note that the ieee80211_config_bw() below would also check 4349 * for this (and more), but this has better error reporting. 4350 */ 4351 if (!is_6ghz && link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HT && 4352 (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) { 4353 sdata_info(sdata, 4354 "HT AP is missing WMM params or HT capability/operation\n"); 4355 ret = false; 4356 goto out; 4357 } 4358 4359 if (is_5ghz && link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_VHT && 4360 (!elems->vht_cap_elem || !elems->vht_operation)) { 4361 sdata_info(sdata, 4362 "VHT AP is missing VHT capability/operation\n"); 4363 ret = false; 4364 goto out; 4365 } 4366 4367 /* check/update if AP changed anything in assoc response vs. scan */ 4368 if (ieee80211_config_bw(link, elems, 4369 link_id == assoc_data->assoc_link_id, 4370 changed)) { 4371 ret = false; 4372 goto out; 4373 } 4374 4375 if (WARN_ON(!link->conf->chanreq.oper.chan)) { 4376 ret = false; 4377 goto out; 4378 } 4379 sband = local->hw.wiphy->bands[link->conf->chanreq.oper.chan->band]; 4380 4381 /* Set up internal HT/VHT capabilities */ 4382 if (elems->ht_cap_elem && link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HT) 4383 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband, 4384 elems->ht_cap_elem, 4385 link_sta); 4386 4387 if (elems->vht_cap_elem && 4388 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_VHT) { 4389 const struct ieee80211_vht_cap *bss_vht_cap = NULL; 4390 const struct cfg80211_bss_ies *ies; 4391 4392 /* 4393 * Cisco AP module 9115 with FW 17.3 has a bug and sends a 4394 * too large maximum MPDU length in the association response 4395 * (indicating 12k) that it cannot actually process ... 4396 * Work around that. 4397 */ 4398 rcu_read_lock(); 4399 ies = rcu_dereference(cbss->ies); 4400 if (ies) { 4401 const struct element *elem; 4402 4403 elem = cfg80211_find_elem(WLAN_EID_VHT_CAPABILITY, 4404 ies->data, ies->len); 4405 if (elem && elem->datalen >= sizeof(*bss_vht_cap)) 4406 bss_vht_cap = (const void *)elem->data; 4407 } 4408 4409 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband, 4410 elems->vht_cap_elem, 4411 bss_vht_cap, link_sta); 4412 rcu_read_unlock(); 4413 } 4414 4415 if (elems->he_operation && 4416 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HE && 4417 elems->he_cap) { 4418 const struct ieee80211_he_6ghz_oper *he_6ghz_oper; 4419 4420 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband, 4421 elems->he_cap, 4422 elems->he_cap_len, 4423 elems->he_6ghz_capa, 4424 link_sta); 4425 4426 he_6ghz_oper = ieee80211_he_6ghz_oper(elems->he_operation); 4427 4428 if (is_6ghz && he_6ghz_oper) { 4429 switch (u8_get_bits(he_6ghz_oper->control, 4430 IEEE80211_HE_6GHZ_OPER_CTRL_REG_INFO)) { 4431 case IEEE80211_6GHZ_CTRL_REG_LPI_AP: 4432 bss_conf->power_type = IEEE80211_REG_LPI_AP; 4433 break; 4434 case IEEE80211_6GHZ_CTRL_REG_SP_AP: 4435 bss_conf->power_type = IEEE80211_REG_SP_AP; 4436 break; 4437 case IEEE80211_6GHZ_CTRL_REG_VLP_AP: 4438 bss_conf->power_type = IEEE80211_REG_VLP_AP; 4439 break; 4440 default: 4441 bss_conf->power_type = IEEE80211_REG_UNSET_AP; 4442 break; 4443 } 4444 } else if (is_6ghz) { 4445 link_info(link, 4446 "HE 6 GHz operation missing (on %d MHz), expect issues\n", 4447 bss_conf->chanreq.oper.chan->center_freq); 4448 } 4449 4450 bss_conf->he_support = link_sta->pub->he_cap.has_he; 4451 if (elems->rsnx && elems->rsnx_len && 4452 (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) && 4453 wiphy_ext_feature_isset(local->hw.wiphy, 4454 NL80211_EXT_FEATURE_PROTECTED_TWT)) 4455 bss_conf->twt_protected = true; 4456 else 4457 bss_conf->twt_protected = false; 4458 4459 *changed |= ieee80211_recalc_twt_req(sdata, sband, link, 4460 link_sta, elems); 4461 4462 if (elems->eht_operation && elems->eht_cap && 4463 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_EHT) { 4464 ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband, 4465 elems->he_cap, 4466 elems->he_cap_len, 4467 elems->eht_cap, 4468 elems->eht_cap_len, 4469 link_sta); 4470 4471 bss_conf->eht_support = link_sta->pub->eht_cap.has_eht; 4472 } else { 4473 bss_conf->eht_support = false; 4474 } 4475 } else { 4476 bss_conf->he_support = false; 4477 bss_conf->twt_requester = false; 4478 bss_conf->twt_protected = false; 4479 bss_conf->eht_support = false; 4480 } 4481 4482 bss_conf->twt_broadcast = 4483 ieee80211_twt_bcast_support(sdata, bss_conf, sband, link_sta); 4484 4485 if (bss_conf->he_support) { 4486 bss_conf->he_bss_color.color = 4487 le32_get_bits(elems->he_operation->he_oper_params, 4488 IEEE80211_HE_OPERATION_BSS_COLOR_MASK); 4489 bss_conf->he_bss_color.partial = 4490 le32_get_bits(elems->he_operation->he_oper_params, 4491 IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR); 4492 bss_conf->he_bss_color.enabled = 4493 !le32_get_bits(elems->he_operation->he_oper_params, 4494 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED); 4495 4496 if (bss_conf->he_bss_color.enabled) 4497 *changed |= BSS_CHANGED_HE_BSS_COLOR; 4498 4499 bss_conf->htc_trig_based_pkt_ext = 4500 le32_get_bits(elems->he_operation->he_oper_params, 4501 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK); 4502 bss_conf->frame_time_rts_th = 4503 le32_get_bits(elems->he_operation->he_oper_params, 4504 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK); 4505 4506 bss_conf->uora_exists = !!elems->uora_element; 4507 if (elems->uora_element) 4508 bss_conf->uora_ocw_range = elems->uora_element[0]; 4509 4510 ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation); 4511 ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr); 4512 /* TODO: OPEN: what happens if BSS color disable is set? */ 4513 } 4514 4515 if (cbss->transmitted_bss) { 4516 bss_conf->nontransmitted = true; 4517 ether_addr_copy(bss_conf->transmitter_bssid, 4518 cbss->transmitted_bss->bssid); 4519 bss_conf->bssid_indicator = cbss->max_bssid_indicator; 4520 bss_conf->bssid_index = cbss->bssid_index; 4521 } 4522 4523 /* 4524 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data 4525 * in their association response, so ignore that data for our own 4526 * configuration. If it changed since the last beacon, we'll get the 4527 * next beacon and update then. 4528 */ 4529 4530 /* 4531 * If an operating mode notification IE is present, override the 4532 * NSS calculation (that would be done in rate_control_rate_init()) 4533 * and use the # of streams from that element. 4534 */ 4535 if (elems->opmode_notif && 4536 !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) { 4537 u8 nss; 4538 4539 nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK; 4540 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT; 4541 nss += 1; 4542 link_sta->pub->rx_nss = nss; 4543 } 4544 4545 /* 4546 * Always handle WMM once after association regardless 4547 * of the first value the AP uses. Setting -1 here has 4548 * that effect because the AP values is an unsigned 4549 * 4-bit value. 4550 */ 4551 link->u.mgd.wmm_last_param_set = -1; 4552 link->u.mgd.mu_edca_last_param_set = -1; 4553 4554 if (link->u.mgd.disable_wmm_tracking) { 4555 ieee80211_set_wmm_default(link, false, false); 4556 } else if (!ieee80211_sta_wmm_params(local, link, elems->wmm_param, 4557 elems->wmm_param_len, 4558 elems->mu_edca_param_set)) { 4559 /* still enable QoS since we might have HT/VHT */ 4560 ieee80211_set_wmm_default(link, false, true); 4561 /* disable WMM tracking in this case to disable 4562 * tracking WMM parameter changes in the beacon if 4563 * the parameters weren't actually valid. Doing so 4564 * avoids changing parameters very strangely when 4565 * the AP is going back and forth between valid and 4566 * invalid parameters. 4567 */ 4568 link->u.mgd.disable_wmm_tracking = true; 4569 } 4570 4571 if (elems->max_idle_period_ie) { 4572 bss_conf->max_idle_period = 4573 le16_to_cpu(elems->max_idle_period_ie->max_idle_period); 4574 bss_conf->protected_keep_alive = 4575 !!(elems->max_idle_period_ie->idle_options & 4576 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE); 4577 *changed |= BSS_CHANGED_KEEP_ALIVE; 4578 } else { 4579 bss_conf->max_idle_period = 0; 4580 bss_conf->protected_keep_alive = false; 4581 } 4582 4583 /* set assoc capability (AID was already set earlier), 4584 * ieee80211_set_associated() will tell the driver */ 4585 bss_conf->assoc_capability = capab_info; 4586 4587 ret = true; 4588 out: 4589 kfree(elems); 4590 kfree(bss_ies); 4591 return ret; 4592 } 4593 4594 static int ieee80211_mgd_setup_link_sta(struct ieee80211_link_data *link, 4595 struct sta_info *sta, 4596 struct link_sta_info *link_sta, 4597 struct cfg80211_bss *cbss) 4598 { 4599 struct ieee80211_sub_if_data *sdata = link->sdata; 4600 struct ieee80211_local *local = sdata->local; 4601 struct ieee80211_bss *bss = (void *)cbss->priv; 4602 u32 rates = 0, basic_rates = 0; 4603 bool have_higher_than_11mbit = false; 4604 int min_rate = INT_MAX, min_rate_index = -1; 4605 struct ieee80211_supported_band *sband; 4606 4607 memcpy(link_sta->addr, cbss->bssid, ETH_ALEN); 4608 memcpy(link_sta->pub->addr, cbss->bssid, ETH_ALEN); 4609 4610 /* TODO: S1G Basic Rate Set is expressed elsewhere */ 4611 if (cbss->channel->band == NL80211_BAND_S1GHZ) { 4612 ieee80211_s1g_sta_rate_init(sta); 4613 return 0; 4614 } 4615 4616 sband = local->hw.wiphy->bands[cbss->channel->band]; 4617 4618 ieee80211_get_rates(sband, bss->supp_rates, bss->supp_rates_len, 4619 &rates, &basic_rates, &have_higher_than_11mbit, 4620 &min_rate, &min_rate_index); 4621 4622 /* 4623 * This used to be a workaround for basic rates missing 4624 * in the association response frame. Now that we no 4625 * longer use the basic rates from there, it probably 4626 * doesn't happen any more, but keep the workaround so 4627 * in case some *other* APs are buggy in different ways 4628 * we can connect -- with a warning. 4629 * Allow this workaround only in case the AP provided at least 4630 * one rate. 4631 */ 4632 if (min_rate_index < 0) { 4633 link_info(link, "No legacy rates in association response\n"); 4634 return -EINVAL; 4635 } else if (!basic_rates) { 4636 link_info(link, "No basic rates, using min rate instead\n"); 4637 basic_rates = BIT(min_rate_index); 4638 } 4639 4640 if (rates) 4641 link_sta->pub->supp_rates[cbss->channel->band] = rates; 4642 else 4643 link_info(link, "No rates found, keeping mandatory only\n"); 4644 4645 link->conf->basic_rates = basic_rates; 4646 4647 /* cf. IEEE 802.11 9.2.12 */ 4648 link->operating_11g_mode = sband->band == NL80211_BAND_2GHZ && 4649 have_higher_than_11mbit; 4650 4651 return 0; 4652 } 4653 4654 static u8 ieee80211_max_rx_chains(struct ieee80211_link_data *link, 4655 struct cfg80211_bss *cbss) 4656 { 4657 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp; 4658 const struct element *ht_cap_elem, *vht_cap_elem; 4659 const struct cfg80211_bss_ies *ies; 4660 const struct ieee80211_ht_cap *ht_cap; 4661 const struct ieee80211_vht_cap *vht_cap; 4662 const struct ieee80211_he_cap_elem *he_cap; 4663 const struct element *he_cap_elem; 4664 u16 mcs_80_map, mcs_160_map; 4665 int i, mcs_nss_size; 4666 bool support_160; 4667 u8 chains = 1; 4668 4669 if (link->u.mgd.conn.mode < IEEE80211_CONN_MODE_HT) 4670 return chains; 4671 4672 ht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_CAPABILITY); 4673 if (ht_cap_elem && ht_cap_elem->datalen >= sizeof(*ht_cap)) { 4674 ht_cap = (void *)ht_cap_elem->data; 4675 chains = ieee80211_mcs_to_chains(&ht_cap->mcs); 4676 /* 4677 * TODO: use "Tx Maximum Number Spatial Streams Supported" and 4678 * "Tx Unequal Modulation Supported" fields. 4679 */ 4680 } 4681 4682 if (link->u.mgd.conn.mode < IEEE80211_CONN_MODE_VHT) 4683 return chains; 4684 4685 vht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY); 4686 if (vht_cap_elem && vht_cap_elem->datalen >= sizeof(*vht_cap)) { 4687 u8 nss; 4688 u16 tx_mcs_map; 4689 4690 vht_cap = (void *)vht_cap_elem->data; 4691 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map); 4692 for (nss = 8; nss > 0; nss--) { 4693 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) != 4694 IEEE80211_VHT_MCS_NOT_SUPPORTED) 4695 break; 4696 } 4697 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */ 4698 chains = max(chains, nss); 4699 } 4700 4701 if (link->u.mgd.conn.mode < IEEE80211_CONN_MODE_HE) 4702 return chains; 4703 4704 ies = rcu_dereference(cbss->ies); 4705 he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY, 4706 ies->data, ies->len); 4707 4708 if (!he_cap_elem || he_cap_elem->datalen < sizeof(*he_cap)) 4709 return chains; 4710 4711 /* skip one byte ext_tag_id */ 4712 he_cap = (void *)(he_cap_elem->data + 1); 4713 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap); 4714 4715 /* invalid HE IE */ 4716 if (he_cap_elem->datalen < 1 + mcs_nss_size + sizeof(*he_cap)) 4717 return chains; 4718 4719 /* mcs_nss is right after he_cap info */ 4720 he_mcs_nss_supp = (void *)(he_cap + 1); 4721 4722 mcs_80_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80); 4723 4724 for (i = 7; i >= 0; i--) { 4725 u8 mcs_80 = mcs_80_map >> (2 * i) & 3; 4726 4727 if (mcs_80 != IEEE80211_VHT_MCS_NOT_SUPPORTED) { 4728 chains = max_t(u8, chains, i + 1); 4729 break; 4730 } 4731 } 4732 4733 support_160 = he_cap->phy_cap_info[0] & 4734 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G; 4735 4736 if (!support_160) 4737 return chains; 4738 4739 mcs_160_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_160); 4740 for (i = 7; i >= 0; i--) { 4741 u8 mcs_160 = mcs_160_map >> (2 * i) & 3; 4742 4743 if (mcs_160 != IEEE80211_VHT_MCS_NOT_SUPPORTED) { 4744 chains = max_t(u8, chains, i + 1); 4745 break; 4746 } 4747 } 4748 4749 return chains; 4750 } 4751 4752 static void 4753 ieee80211_determine_our_sta_mode(struct ieee80211_sub_if_data *sdata, 4754 struct ieee80211_supported_band *sband, 4755 struct cfg80211_assoc_request *req, 4756 bool wmm_used, int link_id, 4757 struct ieee80211_conn_settings *conn) 4758 { 4759 struct ieee80211_sta_ht_cap sta_ht_cap = sband->ht_cap; 4760 bool is_5ghz = sband->band == NL80211_BAND_5GHZ; 4761 bool is_6ghz = sband->band == NL80211_BAND_6GHZ; 4762 const struct ieee80211_sta_he_cap *he_cap; 4763 const struct ieee80211_sta_eht_cap *eht_cap; 4764 struct ieee80211_sta_vht_cap vht_cap; 4765 4766 if (sband->band == NL80211_BAND_S1GHZ) { 4767 conn->mode = IEEE80211_CONN_MODE_S1G; 4768 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20; 4769 mlme_dbg(sdata, "operating as S1G STA\n"); 4770 return; 4771 } 4772 4773 conn->mode = IEEE80211_CONN_MODE_LEGACY; 4774 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20; 4775 4776 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap); 4777 4778 if (req && req->flags & ASSOC_REQ_DISABLE_HT) { 4779 mlme_link_id_dbg(sdata, link_id, 4780 "HT disabled by flag, limiting to legacy\n"); 4781 goto out; 4782 } 4783 4784 if (!wmm_used) { 4785 mlme_link_id_dbg(sdata, link_id, 4786 "WMM/QoS not supported, limiting to legacy\n"); 4787 goto out; 4788 } 4789 4790 if (req) { 4791 unsigned int i; 4792 4793 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) { 4794 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 || 4795 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP || 4796 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) { 4797 netdev_info(sdata->dev, 4798 "WEP/TKIP use, limiting to legacy\n"); 4799 goto out; 4800 } 4801 } 4802 } 4803 4804 if (!sta_ht_cap.ht_supported && !is_6ghz) { 4805 mlme_link_id_dbg(sdata, link_id, 4806 "HT not supported (and not on 6 GHz), limiting to legacy\n"); 4807 goto out; 4808 } 4809 4810 /* HT is fine */ 4811 conn->mode = IEEE80211_CONN_MODE_HT; 4812 conn->bw_limit = sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ? 4813 IEEE80211_CONN_BW_LIMIT_40 : 4814 IEEE80211_CONN_BW_LIMIT_20; 4815 4816 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap)); 4817 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap); 4818 4819 if (req && req->flags & ASSOC_REQ_DISABLE_VHT) { 4820 mlme_link_id_dbg(sdata, link_id, 4821 "VHT disabled by flag, limiting to HT\n"); 4822 goto out; 4823 } 4824 4825 if (vht_cap.vht_supported && is_5ghz) { 4826 bool have_80mhz = false; 4827 unsigned int i; 4828 4829 if (conn->bw_limit == IEEE80211_CONN_BW_LIMIT_20) { 4830 mlme_link_id_dbg(sdata, link_id, 4831 "no 40 MHz support on 5 GHz, limiting to HT\n"); 4832 goto out; 4833 } 4834 4835 /* Allow VHT if at least one channel on the sband supports 80 MHz */ 4836 for (i = 0; i < sband->n_channels; i++) { 4837 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED | 4838 IEEE80211_CHAN_NO_80MHZ)) 4839 continue; 4840 4841 have_80mhz = true; 4842 break; 4843 } 4844 4845 if (!have_80mhz) { 4846 mlme_link_id_dbg(sdata, link_id, 4847 "no 80 MHz channel support on 5 GHz, limiting to HT\n"); 4848 goto out; 4849 } 4850 } else if (is_5ghz) { /* !vht_supported but on 5 GHz */ 4851 mlme_link_id_dbg(sdata, link_id, 4852 "no VHT support on 5 GHz, limiting to HT\n"); 4853 goto out; 4854 } 4855 4856 /* VHT - if we have - is fine, including 80 MHz, check 160 below again */ 4857 if (sband->band != NL80211_BAND_2GHZ) { 4858 conn->mode = IEEE80211_CONN_MODE_VHT; 4859 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_160; 4860 } 4861 4862 if (is_5ghz && 4863 !(vht_cap.cap & (IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ | 4864 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ))) { 4865 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_80; 4866 mlme_link_id_dbg(sdata, link_id, 4867 "no VHT 160 MHz capability on 5 GHz, limiting to 80 MHz"); 4868 } 4869 4870 if (req && req->flags & ASSOC_REQ_DISABLE_HE) { 4871 mlme_link_id_dbg(sdata, link_id, 4872 "HE disabled by flag, limiting to HT/VHT\n"); 4873 goto out; 4874 } 4875 4876 he_cap = ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif); 4877 if (!he_cap) { 4878 WARN_ON(is_6ghz); 4879 mlme_link_id_dbg(sdata, link_id, 4880 "no HE support, limiting to HT/VHT\n"); 4881 goto out; 4882 } 4883 4884 /* so we have HE */ 4885 conn->mode = IEEE80211_CONN_MODE_HE; 4886 4887 /* check bandwidth */ 4888 switch (sband->band) { 4889 default: 4890 case NL80211_BAND_2GHZ: 4891 if (he_cap->he_cap_elem.phy_cap_info[0] & 4892 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G) 4893 break; 4894 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20; 4895 mlme_link_id_dbg(sdata, link_id, 4896 "no 40 MHz HE cap in 2.4 GHz, limiting to 20 MHz\n"); 4897 break; 4898 case NL80211_BAND_5GHZ: 4899 if (!(he_cap->he_cap_elem.phy_cap_info[0] & 4900 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G)) { 4901 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20; 4902 mlme_link_id_dbg(sdata, link_id, 4903 "no 40/80 MHz HE cap in 5 GHz, limiting to 20 MHz\n"); 4904 break; 4905 } 4906 if (!(he_cap->he_cap_elem.phy_cap_info[0] & 4907 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G)) { 4908 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit, 4909 conn->bw_limit, 4910 IEEE80211_CONN_BW_LIMIT_80); 4911 mlme_link_id_dbg(sdata, link_id, 4912 "no 160 MHz HE cap in 5 GHz, limiting to 80 MHz\n"); 4913 } 4914 break; 4915 case NL80211_BAND_6GHZ: 4916 if (he_cap->he_cap_elem.phy_cap_info[0] & 4917 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G) 4918 break; 4919 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit, 4920 conn->bw_limit, 4921 IEEE80211_CONN_BW_LIMIT_80); 4922 mlme_link_id_dbg(sdata, link_id, 4923 "no 160 MHz HE cap in 6 GHz, limiting to 80 MHz\n"); 4924 break; 4925 } 4926 4927 if (req && req->flags & ASSOC_REQ_DISABLE_EHT) { 4928 mlme_link_id_dbg(sdata, link_id, 4929 "EHT disabled by flag, limiting to HE\n"); 4930 goto out; 4931 } 4932 4933 eht_cap = ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif); 4934 if (!eht_cap) { 4935 mlme_link_id_dbg(sdata, link_id, 4936 "no EHT support, limiting to HE\n"); 4937 goto out; 4938 } 4939 4940 /* we have EHT */ 4941 4942 conn->mode = IEEE80211_CONN_MODE_EHT; 4943 4944 /* check bandwidth */ 4945 if (is_6ghz && 4946 eht_cap->eht_cap_elem.phy_cap_info[0] & IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ) 4947 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_320; 4948 else if (is_6ghz) 4949 mlme_link_id_dbg(sdata, link_id, 4950 "no EHT 320 MHz cap in 6 GHz, limiting to 160 MHz\n"); 4951 4952 out: 4953 mlme_link_id_dbg(sdata, link_id, 4954 "determined local STA to be %s, BW limited to %d MHz\n", 4955 ieee80211_conn_mode_str(conn->mode), 4956 20 * (1 << conn->bw_limit)); 4957 } 4958 4959 static void 4960 ieee80211_determine_our_sta_mode_auth(struct ieee80211_sub_if_data *sdata, 4961 struct ieee80211_supported_band *sband, 4962 struct cfg80211_auth_request *req, 4963 bool wmm_used, 4964 struct ieee80211_conn_settings *conn) 4965 { 4966 ieee80211_determine_our_sta_mode(sdata, sband, NULL, wmm_used, 4967 req->link_id > 0 ? req->link_id : 0, 4968 conn); 4969 } 4970 4971 static void 4972 ieee80211_determine_our_sta_mode_assoc(struct ieee80211_sub_if_data *sdata, 4973 struct ieee80211_supported_band *sband, 4974 struct cfg80211_assoc_request *req, 4975 bool wmm_used, int link_id, 4976 struct ieee80211_conn_settings *conn) 4977 { 4978 struct ieee80211_conn_settings tmp; 4979 4980 WARN_ON(!req); 4981 4982 ieee80211_determine_our_sta_mode(sdata, sband, req, wmm_used, link_id, 4983 &tmp); 4984 4985 conn->mode = min_t(enum ieee80211_conn_mode, 4986 conn->mode, tmp.mode); 4987 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit, 4988 conn->bw_limit, tmp.bw_limit); 4989 } 4990 4991 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata, 4992 struct ieee80211_link_data *link, 4993 int link_id, 4994 struct cfg80211_bss *cbss, bool mlo, 4995 struct ieee80211_conn_settings *conn) 4996 { 4997 struct ieee80211_local *local = sdata->local; 4998 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ; 4999 struct ieee80211_chan_req chanreq = {}; 5000 struct ieee802_11_elems *elems; 5001 int ret; 5002 u32 i; 5003 5004 lockdep_assert_wiphy(local->hw.wiphy); 5005 5006 rcu_read_lock(); 5007 elems = ieee80211_determine_chan_mode(sdata, conn, cbss, link_id, 5008 &chanreq); 5009 5010 if (IS_ERR(elems)) { 5011 rcu_read_unlock(); 5012 return PTR_ERR(elems); 5013 } 5014 5015 if (mlo && !elems->ml_basic) { 5016 sdata_info(sdata, "Rejecting MLO as it is not supported by AP\n"); 5017 rcu_read_unlock(); 5018 kfree(elems); 5019 return -EINVAL; 5020 } 5021 5022 if (link && is_6ghz && conn->mode >= IEEE80211_CONN_MODE_HE) { 5023 struct ieee80211_bss_conf *bss_conf; 5024 u8 j = 0; 5025 5026 bss_conf = link->conf; 5027 5028 if (elems->pwr_constr_elem) 5029 bss_conf->pwr_reduction = *elems->pwr_constr_elem; 5030 5031 BUILD_BUG_ON(ARRAY_SIZE(bss_conf->tx_pwr_env) != 5032 ARRAY_SIZE(elems->tx_pwr_env)); 5033 5034 for (i = 0; i < elems->tx_pwr_env_num; i++) { 5035 if (elems->tx_pwr_env_len[i] > sizeof(bss_conf->tx_pwr_env[j])) 5036 continue; 5037 5038 bss_conf->tx_pwr_env_num++; 5039 memcpy(&bss_conf->tx_pwr_env[j], elems->tx_pwr_env[i], 5040 elems->tx_pwr_env_len[i]); 5041 j++; 5042 } 5043 } 5044 rcu_read_unlock(); 5045 /* the element data was RCU protected so no longer valid anyway */ 5046 kfree(elems); 5047 elems = NULL; 5048 5049 if (!link) 5050 return 0; 5051 5052 rcu_read_lock(); 5053 link->needed_rx_chains = min(ieee80211_max_rx_chains(link, cbss), 5054 local->rx_chains); 5055 rcu_read_unlock(); 5056 5057 /* 5058 * If this fails (possibly due to channel context sharing 5059 * on incompatible channels, e.g. 80+80 and 160 sharing the 5060 * same control channel) try to use a smaller bandwidth. 5061 */ 5062 ret = ieee80211_link_use_channel(link, &chanreq, 5063 IEEE80211_CHANCTX_SHARED); 5064 5065 /* don't downgrade for 5 and 10 MHz channels, though. */ 5066 if (chanreq.oper.width == NL80211_CHAN_WIDTH_5 || 5067 chanreq.oper.width == NL80211_CHAN_WIDTH_10) 5068 return ret; 5069 5070 while (ret && chanreq.oper.width != NL80211_CHAN_WIDTH_20_NOHT) { 5071 ieee80211_chanreq_downgrade(&chanreq, conn); 5072 5073 ret = ieee80211_link_use_channel(link, &chanreq, 5074 IEEE80211_CHANCTX_SHARED); 5075 } 5076 5077 return ret; 5078 } 5079 5080 static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies, 5081 u8 *dtim_count, u8 *dtim_period) 5082 { 5083 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len); 5084 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data, 5085 ies->len); 5086 const struct ieee80211_tim_ie *tim = NULL; 5087 const struct ieee80211_bssid_index *idx; 5088 bool valid = tim_ie && tim_ie[1] >= 2; 5089 5090 if (valid) 5091 tim = (void *)(tim_ie + 2); 5092 5093 if (dtim_count) 5094 *dtim_count = valid ? tim->dtim_count : 0; 5095 5096 if (dtim_period) 5097 *dtim_period = valid ? tim->dtim_period : 0; 5098 5099 /* Check if value is overridden by non-transmitted profile */ 5100 if (!idx_ie || idx_ie[1] < 3) 5101 return valid; 5102 5103 idx = (void *)(idx_ie + 2); 5104 5105 if (dtim_count) 5106 *dtim_count = idx->dtim_count; 5107 5108 if (dtim_period) 5109 *dtim_period = idx->dtim_period; 5110 5111 return true; 5112 } 5113 5114 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata, 5115 struct ieee80211_mgmt *mgmt, 5116 struct ieee802_11_elems *elems, 5117 const u8 *elem_start, unsigned int elem_len) 5118 { 5119 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 5120 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; 5121 struct ieee80211_local *local = sdata->local; 5122 unsigned int link_id; 5123 struct sta_info *sta; 5124 u64 changed[IEEE80211_MLD_MAX_NUM_LINKS] = {}; 5125 u16 valid_links = 0, dormant_links = 0; 5126 int err; 5127 5128 lockdep_assert_wiphy(sdata->local->hw.wiphy); 5129 /* 5130 * station info was already allocated and inserted before 5131 * the association and should be available to us 5132 */ 5133 sta = sta_info_get(sdata, assoc_data->ap_addr); 5134 if (WARN_ON(!sta)) 5135 goto out_err; 5136 5137 sta->sta.spp_amsdu = assoc_data->spp_amsdu; 5138 5139 if (ieee80211_vif_is_mld(&sdata->vif)) { 5140 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { 5141 if (!assoc_data->link[link_id].bss) 5142 continue; 5143 5144 valid_links |= BIT(link_id); 5145 if (assoc_data->link[link_id].disabled) 5146 dormant_links |= BIT(link_id); 5147 5148 if (link_id != assoc_data->assoc_link_id) { 5149 err = ieee80211_sta_allocate_link(sta, link_id); 5150 if (err) 5151 goto out_err; 5152 } 5153 } 5154 5155 ieee80211_vif_set_links(sdata, valid_links, dormant_links); 5156 } 5157 5158 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { 5159 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss; 5160 struct ieee80211_link_data *link; 5161 struct link_sta_info *link_sta; 5162 5163 if (!cbss) 5164 continue; 5165 5166 link = sdata_dereference(sdata->link[link_id], sdata); 5167 if (WARN_ON(!link)) 5168 goto out_err; 5169 5170 if (ieee80211_vif_is_mld(&sdata->vif)) 5171 link_info(link, 5172 "local address %pM, AP link address %pM%s\n", 5173 link->conf->addr, 5174 assoc_data->link[link_id].bss->bssid, 5175 link_id == assoc_data->assoc_link_id ? 5176 " (assoc)" : ""); 5177 5178 link_sta = rcu_dereference_protected(sta->link[link_id], 5179 lockdep_is_held(&local->hw.wiphy->mtx)); 5180 if (WARN_ON(!link_sta)) 5181 goto out_err; 5182 5183 if (!link->u.mgd.have_beacon) { 5184 const struct cfg80211_bss_ies *ies; 5185 5186 rcu_read_lock(); 5187 ies = rcu_dereference(cbss->beacon_ies); 5188 if (ies) 5189 link->u.mgd.have_beacon = true; 5190 else 5191 ies = rcu_dereference(cbss->ies); 5192 ieee80211_get_dtim(ies, 5193 &link->conf->sync_dtim_count, 5194 &link->u.mgd.dtim_period); 5195 link->conf->beacon_int = cbss->beacon_interval; 5196 rcu_read_unlock(); 5197 } 5198 5199 link->conf->dtim_period = link->u.mgd.dtim_period ?: 1; 5200 5201 if (link_id != assoc_data->assoc_link_id) { 5202 link->u.mgd.conn = assoc_data->link[link_id].conn; 5203 5204 err = ieee80211_prep_channel(sdata, link, link_id, cbss, 5205 true, &link->u.mgd.conn); 5206 if (err) { 5207 link_info(link, "prep_channel failed\n"); 5208 goto out_err; 5209 } 5210 } 5211 5212 err = ieee80211_mgd_setup_link_sta(link, sta, link_sta, 5213 assoc_data->link[link_id].bss); 5214 if (err) 5215 goto out_err; 5216 5217 if (!ieee80211_assoc_config_link(link, link_sta, 5218 assoc_data->link[link_id].bss, 5219 mgmt, elem_start, elem_len, 5220 &changed[link_id])) 5221 goto out_err; 5222 5223 if (assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) { 5224 valid_links &= ~BIT(link_id); 5225 ieee80211_sta_remove_link(sta, link_id); 5226 continue; 5227 } 5228 5229 if (link_id != assoc_data->assoc_link_id) { 5230 err = ieee80211_sta_activate_link(sta, link_id); 5231 if (err) 5232 goto out_err; 5233 } 5234 } 5235 5236 /* links might have changed due to rejected ones, set them again */ 5237 ieee80211_vif_set_links(sdata, valid_links, dormant_links); 5238 5239 rate_control_rate_init(sta); 5240 5241 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) { 5242 set_sta_flag(sta, WLAN_STA_MFP); 5243 sta->sta.mfp = true; 5244 } else { 5245 sta->sta.mfp = false; 5246 } 5247 5248 ieee80211_sta_set_max_amsdu_subframes(sta, elems->ext_capab, 5249 elems->ext_capab_len); 5250 5251 sta->sta.wme = (elems->wmm_param || elems->s1g_capab) && 5252 local->hw.queues >= IEEE80211_NUM_ACS; 5253 5254 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC); 5255 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT)) 5256 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED); 5257 if (err) { 5258 sdata_info(sdata, 5259 "failed to move station %pM to desired state\n", 5260 sta->sta.addr); 5261 WARN_ON(__sta_info_destroy(sta)); 5262 goto out_err; 5263 } 5264 5265 if (sdata->wdev.use_4addr) 5266 drv_sta_set_4addr(local, sdata, &sta->sta, true); 5267 5268 ieee80211_set_associated(sdata, assoc_data, changed); 5269 5270 /* 5271 * If we're using 4-addr mode, let the AP know that we're 5272 * doing so, so that it can create the STA VLAN on its side 5273 */ 5274 if (ifmgd->use_4addr) 5275 ieee80211_send_4addr_nullfunc(local, sdata); 5276 5277 /* 5278 * Start timer to probe the connection to the AP now. 5279 * Also start the timer that will detect beacon loss. 5280 */ 5281 ieee80211_sta_reset_beacon_monitor(sdata); 5282 ieee80211_sta_reset_conn_monitor(sdata); 5283 5284 return true; 5285 out_err: 5286 eth_zero_addr(sdata->vif.cfg.ap_addr); 5287 return false; 5288 } 5289 5290 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata, 5291 struct ieee80211_mgmt *mgmt, 5292 size_t len) 5293 { 5294 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 5295 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; 5296 u16 capab_info, status_code, aid; 5297 struct ieee80211_elems_parse_params parse_params = { 5298 .bss = NULL, 5299 .link_id = -1, 5300 .from_ap = true, 5301 }; 5302 struct ieee802_11_elems *elems; 5303 int ac; 5304 const u8 *elem_start; 5305 unsigned int elem_len; 5306 bool reassoc; 5307 struct ieee80211_event event = { 5308 .type = MLME_EVENT, 5309 .u.mlme.data = ASSOC_EVENT, 5310 }; 5311 struct ieee80211_prep_tx_info info = {}; 5312 struct cfg80211_rx_assoc_resp_data resp = { 5313 .uapsd_queues = -1, 5314 }; 5315 u8 ap_mld_addr[ETH_ALEN] __aligned(2); 5316 unsigned int link_id; 5317 5318 lockdep_assert_wiphy(sdata->local->hw.wiphy); 5319 5320 if (!assoc_data) 5321 return; 5322 5323 parse_params.mode = 5324 assoc_data->link[assoc_data->assoc_link_id].conn.mode; 5325 5326 if (!ether_addr_equal(assoc_data->ap_addr, mgmt->bssid) || 5327 !ether_addr_equal(assoc_data->ap_addr, mgmt->sa)) 5328 return; 5329 5330 /* 5331 * AssocResp and ReassocResp have identical structure, so process both 5332 * of them in this function. 5333 */ 5334 5335 if (len < 24 + 6) 5336 return; 5337 5338 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control); 5339 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); 5340 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); 5341 if (assoc_data->s1g) 5342 elem_start = mgmt->u.s1g_assoc_resp.variable; 5343 else 5344 elem_start = mgmt->u.assoc_resp.variable; 5345 5346 /* 5347 * Note: this may not be perfect, AP might misbehave - if 5348 * anyone needs to rely on perfect complete notification 5349 * with the exact right subtype, then we need to track what 5350 * we actually transmitted. 5351 */ 5352 info.subtype = reassoc ? IEEE80211_STYPE_REASSOC_REQ : 5353 IEEE80211_STYPE_ASSOC_REQ; 5354 5355 if (assoc_data->fils_kek_len && 5356 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0) 5357 return; 5358 5359 elem_len = len - (elem_start - (u8 *)mgmt); 5360 parse_params.start = elem_start; 5361 parse_params.len = elem_len; 5362 elems = ieee802_11_parse_elems_full(&parse_params); 5363 if (!elems) 5364 goto notify_driver; 5365 5366 if (elems->aid_resp) 5367 aid = le16_to_cpu(elems->aid_resp->aid); 5368 else if (assoc_data->s1g) 5369 aid = 0; /* TODO */ 5370 else 5371 aid = le16_to_cpu(mgmt->u.assoc_resp.aid); 5372 5373 /* 5374 * The 5 MSB of the AID field are reserved 5375 * (802.11-2016 9.4.1.8 AID field) 5376 */ 5377 aid &= 0x7ff; 5378 5379 sdata_info(sdata, 5380 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n", 5381 reassoc ? "Rea" : "A", assoc_data->ap_addr, 5382 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14)))); 5383 5384 ifmgd->broken_ap = false; 5385 5386 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY && 5387 elems->timeout_int && 5388 elems->timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) { 5389 u32 tu, ms; 5390 5391 cfg80211_assoc_comeback(sdata->dev, assoc_data->ap_addr, 5392 le32_to_cpu(elems->timeout_int->value)); 5393 5394 tu = le32_to_cpu(elems->timeout_int->value); 5395 ms = tu * 1024 / 1000; 5396 sdata_info(sdata, 5397 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n", 5398 assoc_data->ap_addr, tu, ms); 5399 assoc_data->timeout = jiffies + msecs_to_jiffies(ms); 5400 assoc_data->timeout_started = true; 5401 assoc_data->comeback = true; 5402 if (ms > IEEE80211_ASSOC_TIMEOUT) 5403 run_again(sdata, assoc_data->timeout); 5404 goto notify_driver; 5405 } 5406 5407 if (status_code != WLAN_STATUS_SUCCESS) { 5408 sdata_info(sdata, "%pM denied association (code=%d)\n", 5409 assoc_data->ap_addr, status_code); 5410 event.u.mlme.status = MLME_DENIED; 5411 event.u.mlme.reason = status_code; 5412 drv_event_callback(sdata->local, sdata, &event); 5413 } else { 5414 if (aid == 0 || aid > IEEE80211_MAX_AID) { 5415 sdata_info(sdata, 5416 "invalid AID value %d (out of range), turn off PS\n", 5417 aid); 5418 aid = 0; 5419 ifmgd->broken_ap = true; 5420 } 5421 5422 if (ieee80211_vif_is_mld(&sdata->vif)) { 5423 struct ieee80211_mle_basic_common_info *common; 5424 5425 if (!elems->ml_basic) { 5426 sdata_info(sdata, 5427 "MLO association with %pM but no (basic) multi-link element in response!\n", 5428 assoc_data->ap_addr); 5429 goto abandon_assoc; 5430 } 5431 5432 common = (void *)elems->ml_basic->variable; 5433 5434 if (memcmp(assoc_data->ap_addr, 5435 common->mld_mac_addr, ETH_ALEN)) { 5436 sdata_info(sdata, 5437 "AP MLD MAC address mismatch: got %pM expected %pM\n", 5438 common->mld_mac_addr, 5439 assoc_data->ap_addr); 5440 goto abandon_assoc; 5441 } 5442 5443 sdata->vif.cfg.eml_cap = 5444 ieee80211_mle_get_eml_cap((const void *)elems->ml_basic); 5445 sdata->vif.cfg.eml_med_sync_delay = 5446 ieee80211_mle_get_eml_med_sync_delay((const void *)elems->ml_basic); 5447 sdata->vif.cfg.mld_capa_op = 5448 ieee80211_mle_get_mld_capa_op((const void *)elems->ml_basic); 5449 } 5450 5451 sdata->vif.cfg.aid = aid; 5452 5453 if (!ieee80211_assoc_success(sdata, mgmt, elems, 5454 elem_start, elem_len)) { 5455 /* oops -- internal error -- send timeout for now */ 5456 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT); 5457 goto notify_driver; 5458 } 5459 event.u.mlme.status = MLME_SUCCESS; 5460 drv_event_callback(sdata->local, sdata, &event); 5461 sdata_info(sdata, "associated\n"); 5462 5463 info.success = 1; 5464 } 5465 5466 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { 5467 struct ieee80211_link_data *link; 5468 5469 if (!assoc_data->link[link_id].bss) 5470 continue; 5471 5472 resp.links[link_id].bss = assoc_data->link[link_id].bss; 5473 ether_addr_copy(resp.links[link_id].addr, 5474 assoc_data->link[link_id].addr); 5475 resp.links[link_id].status = assoc_data->link[link_id].status; 5476 5477 link = sdata_dereference(sdata->link[link_id], sdata); 5478 if (!link) 5479 continue; 5480 5481 /* get uapsd queues configuration - same for all links */ 5482 resp.uapsd_queues = 0; 5483 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) 5484 if (link->tx_conf[ac].uapsd) 5485 resp.uapsd_queues |= ieee80211_ac_to_qos_mask[ac]; 5486 } 5487 5488 if (ieee80211_vif_is_mld(&sdata->vif)) { 5489 ether_addr_copy(ap_mld_addr, sdata->vif.cfg.ap_addr); 5490 resp.ap_mld_addr = ap_mld_addr; 5491 } 5492 5493 ieee80211_destroy_assoc_data(sdata, 5494 status_code == WLAN_STATUS_SUCCESS ? 5495 ASSOC_SUCCESS : 5496 ASSOC_REJECTED); 5497 5498 resp.buf = (u8 *)mgmt; 5499 resp.len = len; 5500 resp.req_ies = ifmgd->assoc_req_ies; 5501 resp.req_ies_len = ifmgd->assoc_req_ies_len; 5502 cfg80211_rx_assoc_resp(sdata->dev, &resp); 5503 notify_driver: 5504 drv_mgd_complete_tx(sdata->local, sdata, &info); 5505 kfree(elems); 5506 return; 5507 abandon_assoc: 5508 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON); 5509 goto notify_driver; 5510 } 5511 5512 static void ieee80211_rx_bss_info(struct ieee80211_link_data *link, 5513 struct ieee80211_mgmt *mgmt, size_t len, 5514 struct ieee80211_rx_status *rx_status) 5515 { 5516 struct ieee80211_sub_if_data *sdata = link->sdata; 5517 struct ieee80211_local *local = sdata->local; 5518 struct ieee80211_bss *bss; 5519 struct ieee80211_channel *channel; 5520 5521 lockdep_assert_wiphy(sdata->local->hw.wiphy); 5522 5523 channel = ieee80211_get_channel_khz(local->hw.wiphy, 5524 ieee80211_rx_status_to_khz(rx_status)); 5525 if (!channel) 5526 return; 5527 5528 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel); 5529 if (bss) { 5530 link->conf->beacon_rate = bss->beacon_rate; 5531 ieee80211_rx_bss_put(local, bss); 5532 } 5533 } 5534 5535 5536 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_link_data *link, 5537 struct sk_buff *skb) 5538 { 5539 struct ieee80211_sub_if_data *sdata = link->sdata; 5540 struct ieee80211_mgmt *mgmt = (void *)skb->data; 5541 struct ieee80211_if_managed *ifmgd; 5542 struct ieee80211_rx_status *rx_status = (void *) skb->cb; 5543 struct ieee80211_channel *channel; 5544 size_t baselen, len = skb->len; 5545 5546 ifmgd = &sdata->u.mgd; 5547 5548 lockdep_assert_wiphy(sdata->local->hw.wiphy); 5549 5550 /* 5551 * According to Draft P802.11ax D6.0 clause 26.17.2.3.2: 5552 * "If a 6 GHz AP receives a Probe Request frame and responds with 5553 * a Probe Response frame [..], the Address 1 field of the Probe 5554 * Response frame shall be set to the broadcast address [..]" 5555 * So, on 6GHz band we should also accept broadcast responses. 5556 */ 5557 channel = ieee80211_get_channel(sdata->local->hw.wiphy, 5558 rx_status->freq); 5559 if (!channel) 5560 return; 5561 5562 if (!ether_addr_equal(mgmt->da, sdata->vif.addr) && 5563 (channel->band != NL80211_BAND_6GHZ || 5564 !is_broadcast_ether_addr(mgmt->da))) 5565 return; /* ignore ProbeResp to foreign address */ 5566 5567 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; 5568 if (baselen > len) 5569 return; 5570 5571 ieee80211_rx_bss_info(link, mgmt, len, rx_status); 5572 5573 if (ifmgd->associated && 5574 ether_addr_equal(mgmt->bssid, link->u.mgd.bssid)) 5575 ieee80211_reset_ap_probe(sdata); 5576 } 5577 5578 /* 5579 * This is the canonical list of information elements we care about, 5580 * the filter code also gives us all changes to the Microsoft OUI 5581 * (00:50:F2) vendor IE which is used for WMM which we need to track, 5582 * as well as the DTPC IE (part of the Cisco OUI) used for signaling 5583 * changes to requested client power. 5584 * 5585 * We implement beacon filtering in software since that means we can 5586 * avoid processing the frame here and in cfg80211, and userspace 5587 * will not be able to tell whether the hardware supports it or not. 5588 * 5589 * XXX: This list needs to be dynamic -- userspace needs to be able to 5590 * add items it requires. It also needs to be able to tell us to 5591 * look out for other vendor IEs. 5592 */ 5593 static const u64 care_about_ies = 5594 (1ULL << WLAN_EID_COUNTRY) | 5595 (1ULL << WLAN_EID_ERP_INFO) | 5596 (1ULL << WLAN_EID_CHANNEL_SWITCH) | 5597 (1ULL << WLAN_EID_PWR_CONSTRAINT) | 5598 (1ULL << WLAN_EID_HT_CAPABILITY) | 5599 (1ULL << WLAN_EID_HT_OPERATION) | 5600 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN); 5601 5602 static void ieee80211_handle_beacon_sig(struct ieee80211_link_data *link, 5603 struct ieee80211_if_managed *ifmgd, 5604 struct ieee80211_bss_conf *bss_conf, 5605 struct ieee80211_local *local, 5606 struct ieee80211_rx_status *rx_status) 5607 { 5608 struct ieee80211_sub_if_data *sdata = link->sdata; 5609 5610 /* Track average RSSI from the Beacon frames of the current AP */ 5611 5612 if (!link->u.mgd.tracking_signal_avg) { 5613 link->u.mgd.tracking_signal_avg = true; 5614 ewma_beacon_signal_init(&link->u.mgd.ave_beacon_signal); 5615 link->u.mgd.last_cqm_event_signal = 0; 5616 link->u.mgd.count_beacon_signal = 1; 5617 link->u.mgd.last_ave_beacon_signal = 0; 5618 } else { 5619 link->u.mgd.count_beacon_signal++; 5620 } 5621 5622 ewma_beacon_signal_add(&link->u.mgd.ave_beacon_signal, 5623 -rx_status->signal); 5624 5625 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold && 5626 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) { 5627 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal); 5628 int last_sig = link->u.mgd.last_ave_beacon_signal; 5629 struct ieee80211_event event = { 5630 .type = RSSI_EVENT, 5631 }; 5632 5633 /* 5634 * if signal crosses either of the boundaries, invoke callback 5635 * with appropriate parameters 5636 */ 5637 if (sig > ifmgd->rssi_max_thold && 5638 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) { 5639 link->u.mgd.last_ave_beacon_signal = sig; 5640 event.u.rssi.data = RSSI_EVENT_HIGH; 5641 drv_event_callback(local, sdata, &event); 5642 } else if (sig < ifmgd->rssi_min_thold && 5643 (last_sig >= ifmgd->rssi_max_thold || 5644 last_sig == 0)) { 5645 link->u.mgd.last_ave_beacon_signal = sig; 5646 event.u.rssi.data = RSSI_EVENT_LOW; 5647 drv_event_callback(local, sdata, &event); 5648 } 5649 } 5650 5651 if (bss_conf->cqm_rssi_thold && 5652 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT && 5653 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) { 5654 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal); 5655 int last_event = link->u.mgd.last_cqm_event_signal; 5656 int thold = bss_conf->cqm_rssi_thold; 5657 int hyst = bss_conf->cqm_rssi_hyst; 5658 5659 if (sig < thold && 5660 (last_event == 0 || sig < last_event - hyst)) { 5661 link->u.mgd.last_cqm_event_signal = sig; 5662 ieee80211_cqm_rssi_notify( 5663 &sdata->vif, 5664 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW, 5665 sig, GFP_KERNEL); 5666 } else if (sig > thold && 5667 (last_event == 0 || sig > last_event + hyst)) { 5668 link->u.mgd.last_cqm_event_signal = sig; 5669 ieee80211_cqm_rssi_notify( 5670 &sdata->vif, 5671 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, 5672 sig, GFP_KERNEL); 5673 } 5674 } 5675 5676 if (bss_conf->cqm_rssi_low && 5677 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) { 5678 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal); 5679 int last_event = link->u.mgd.last_cqm_event_signal; 5680 int low = bss_conf->cqm_rssi_low; 5681 int high = bss_conf->cqm_rssi_high; 5682 5683 if (sig < low && 5684 (last_event == 0 || last_event >= low)) { 5685 link->u.mgd.last_cqm_event_signal = sig; 5686 ieee80211_cqm_rssi_notify( 5687 &sdata->vif, 5688 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW, 5689 sig, GFP_KERNEL); 5690 } else if (sig > high && 5691 (last_event == 0 || last_event <= high)) { 5692 link->u.mgd.last_cqm_event_signal = sig; 5693 ieee80211_cqm_rssi_notify( 5694 &sdata->vif, 5695 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, 5696 sig, GFP_KERNEL); 5697 } 5698 } 5699 } 5700 5701 static bool ieee80211_rx_our_beacon(const u8 *tx_bssid, 5702 struct cfg80211_bss *bss) 5703 { 5704 if (ether_addr_equal(tx_bssid, bss->bssid)) 5705 return true; 5706 if (!bss->transmitted_bss) 5707 return false; 5708 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid); 5709 } 5710 5711 static void ieee80211_ml_reconf_work(struct wiphy *wiphy, 5712 struct wiphy_work *work) 5713 { 5714 struct ieee80211_sub_if_data *sdata = 5715 container_of(work, struct ieee80211_sub_if_data, 5716 u.mgd.ml_reconf_work.work); 5717 u16 new_valid_links, new_active_links, new_dormant_links; 5718 int ret; 5719 5720 if (!sdata->u.mgd.removed_links) 5721 return; 5722 5723 sdata_info(sdata, 5724 "MLO Reconfiguration: work: valid=0x%x, removed=0x%x\n", 5725 sdata->vif.valid_links, sdata->u.mgd.removed_links); 5726 5727 new_valid_links = sdata->vif.valid_links & ~sdata->u.mgd.removed_links; 5728 if (new_valid_links == sdata->vif.valid_links) 5729 return; 5730 5731 if (!new_valid_links || 5732 !(new_valid_links & ~sdata->vif.dormant_links)) { 5733 sdata_info(sdata, "No valid links after reconfiguration\n"); 5734 ret = -EINVAL; 5735 goto out; 5736 } 5737 5738 new_active_links = sdata->vif.active_links & ~sdata->u.mgd.removed_links; 5739 if (new_active_links != sdata->vif.active_links) { 5740 if (!new_active_links) 5741 new_active_links = 5742 BIT(ffs(new_valid_links & 5743 ~sdata->vif.dormant_links) - 1); 5744 5745 ret = ieee80211_set_active_links(&sdata->vif, new_active_links); 5746 if (ret) { 5747 sdata_info(sdata, 5748 "Failed setting active links\n"); 5749 goto out; 5750 } 5751 } 5752 5753 new_dormant_links = sdata->vif.dormant_links & ~sdata->u.mgd.removed_links; 5754 5755 ret = ieee80211_vif_set_links(sdata, new_valid_links, 5756 new_dormant_links); 5757 if (ret) 5758 sdata_info(sdata, "Failed setting valid links\n"); 5759 5760 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_MLD_VALID_LINKS); 5761 5762 out: 5763 if (!ret) 5764 cfg80211_links_removed(sdata->dev, sdata->u.mgd.removed_links); 5765 else 5766 __ieee80211_disconnect(sdata); 5767 5768 sdata->u.mgd.removed_links = 0; 5769 } 5770 5771 static void ieee80211_ml_reconfiguration(struct ieee80211_sub_if_data *sdata, 5772 struct ieee802_11_elems *elems) 5773 { 5774 const struct element *sub; 5775 unsigned long removed_links = 0; 5776 u16 link_removal_timeout[IEEE80211_MLD_MAX_NUM_LINKS] = {}; 5777 u8 link_id; 5778 u32 delay; 5779 5780 if (!ieee80211_vif_is_mld(&sdata->vif) || !elems->ml_reconf) 5781 return; 5782 5783 /* Directly parse the sub elements as the common information doesn't 5784 * hold any useful information. 5785 */ 5786 for_each_mle_subelement(sub, (const u8 *)elems->ml_reconf, 5787 elems->ml_reconf_len) { 5788 struct ieee80211_mle_per_sta_profile *prof = (void *)sub->data; 5789 u8 *pos = prof->variable; 5790 u16 control; 5791 5792 if (sub->id != IEEE80211_MLE_SUBELEM_PER_STA_PROFILE) 5793 continue; 5794 5795 if (!ieee80211_mle_reconf_sta_prof_size_ok(sub->data, 5796 sub->datalen)) 5797 return; 5798 5799 control = le16_to_cpu(prof->control); 5800 link_id = control & IEEE80211_MLE_STA_RECONF_CONTROL_LINK_ID; 5801 5802 removed_links |= BIT(link_id); 5803 5804 /* the MAC address should not be included, but handle it */ 5805 if (control & 5806 IEEE80211_MLE_STA_RECONF_CONTROL_STA_MAC_ADDR_PRESENT) 5807 pos += 6; 5808 5809 /* According to Draft P802.11be_D3.0, the control should 5810 * include the AP Removal Timer present. If the AP Removal Timer 5811 * is not present assume immediate removal. 5812 */ 5813 if (control & 5814 IEEE80211_MLE_STA_RECONF_CONTROL_AP_REM_TIMER_PRESENT) 5815 link_removal_timeout[link_id] = le16_to_cpu(*(__le16 *)pos); 5816 } 5817 5818 removed_links &= sdata->vif.valid_links; 5819 if (!removed_links) { 5820 /* In case the removal was cancelled, abort it */ 5821 if (sdata->u.mgd.removed_links) { 5822 sdata->u.mgd.removed_links = 0; 5823 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, 5824 &sdata->u.mgd.ml_reconf_work); 5825 } 5826 return; 5827 } 5828 5829 delay = 0; 5830 for_each_set_bit(link_id, &removed_links, IEEE80211_MLD_MAX_NUM_LINKS) { 5831 struct ieee80211_bss_conf *link_conf = 5832 sdata_dereference(sdata->vif.link_conf[link_id], sdata); 5833 u32 link_delay; 5834 5835 if (!link_conf) { 5836 removed_links &= ~BIT(link_id); 5837 continue; 5838 } 5839 5840 link_delay = link_conf->beacon_int * 5841 link_removal_timeout[link_id]; 5842 5843 if (!delay) 5844 delay = link_delay; 5845 else 5846 delay = min(delay, link_delay); 5847 } 5848 5849 sdata->u.mgd.removed_links = removed_links; 5850 wiphy_delayed_work_queue(sdata->local->hw.wiphy, 5851 &sdata->u.mgd.ml_reconf_work, 5852 TU_TO_JIFFIES(delay)); 5853 } 5854 5855 static int ieee80211_ttlm_set_links(struct ieee80211_sub_if_data *sdata, 5856 u16 active_links, u16 dormant_links, 5857 u16 suspended_links) 5858 { 5859 u64 changed = 0; 5860 int ret; 5861 5862 if (!active_links) { 5863 ret = -EINVAL; 5864 goto out; 5865 } 5866 5867 /* If there is an active negotiated TTLM, it should be discarded by 5868 * the new negotiated/advertised TTLM. 5869 */ 5870 if (sdata->vif.neg_ttlm.valid) { 5871 memset(&sdata->vif.neg_ttlm, 0, sizeof(sdata->vif.neg_ttlm)); 5872 sdata->vif.suspended_links = 0; 5873 changed = BSS_CHANGED_MLD_TTLM; 5874 } 5875 5876 if (sdata->vif.active_links != active_links) { 5877 ret = ieee80211_set_active_links(&sdata->vif, active_links); 5878 if (ret) { 5879 sdata_info(sdata, "Failed to set TTLM active links\n"); 5880 goto out; 5881 } 5882 } 5883 5884 ret = ieee80211_vif_set_links(sdata, sdata->vif.valid_links, 5885 dormant_links); 5886 if (ret) { 5887 sdata_info(sdata, "Failed to set TTLM dormant links\n"); 5888 goto out; 5889 } 5890 5891 changed |= BSS_CHANGED_MLD_VALID_LINKS; 5892 sdata->vif.suspended_links = suspended_links; 5893 if (sdata->vif.suspended_links) 5894 changed |= BSS_CHANGED_MLD_TTLM; 5895 5896 ieee80211_vif_cfg_change_notify(sdata, changed); 5897 5898 out: 5899 if (ret) 5900 ieee80211_disconnect(&sdata->vif, false); 5901 5902 return ret; 5903 } 5904 5905 static void ieee80211_tid_to_link_map_work(struct wiphy *wiphy, 5906 struct wiphy_work *work) 5907 { 5908 u16 new_active_links, new_dormant_links; 5909 struct ieee80211_sub_if_data *sdata = 5910 container_of(work, struct ieee80211_sub_if_data, 5911 u.mgd.ttlm_work.work); 5912 5913 new_active_links = sdata->u.mgd.ttlm_info.map & 5914 sdata->vif.valid_links; 5915 new_dormant_links = ~sdata->u.mgd.ttlm_info.map & 5916 sdata->vif.valid_links; 5917 5918 ieee80211_vif_set_links(sdata, sdata->vif.valid_links, 0); 5919 if (ieee80211_ttlm_set_links(sdata, new_active_links, new_dormant_links, 5920 0)) 5921 return; 5922 5923 sdata->u.mgd.ttlm_info.active = true; 5924 sdata->u.mgd.ttlm_info.switch_time = 0; 5925 } 5926 5927 static u16 ieee80211_get_ttlm(u8 bm_size, u8 *data) 5928 { 5929 if (bm_size == 1) 5930 return *data; 5931 else 5932 return get_unaligned_le16(data); 5933 } 5934 5935 static int 5936 ieee80211_parse_adv_t2l(struct ieee80211_sub_if_data *sdata, 5937 const struct ieee80211_ttlm_elem *ttlm, 5938 struct ieee80211_adv_ttlm_info *ttlm_info) 5939 { 5940 /* The element size was already validated in 5941 * ieee80211_tid_to_link_map_size_ok() 5942 */ 5943 u8 control, link_map_presence, map_size, tid; 5944 u8 *pos; 5945 5946 memset(ttlm_info, 0, sizeof(*ttlm_info)); 5947 pos = (void *)ttlm->optional; 5948 control = ttlm->control; 5949 5950 if ((control & IEEE80211_TTLM_CONTROL_DEF_LINK_MAP) || 5951 !(control & IEEE80211_TTLM_CONTROL_SWITCH_TIME_PRESENT)) 5952 return 0; 5953 5954 if ((control & IEEE80211_TTLM_CONTROL_DIRECTION) != 5955 IEEE80211_TTLM_DIRECTION_BOTH) { 5956 sdata_info(sdata, "Invalid advertised T2L map direction\n"); 5957 return -EINVAL; 5958 } 5959 5960 link_map_presence = *pos; 5961 pos++; 5962 5963 ttlm_info->switch_time = get_unaligned_le16(pos); 5964 5965 /* Since ttlm_info->switch_time == 0 means no switch time, bump it 5966 * by 1. 5967 */ 5968 if (!ttlm_info->switch_time) 5969 ttlm_info->switch_time = 1; 5970 5971 pos += 2; 5972 5973 if (control & IEEE80211_TTLM_CONTROL_EXPECTED_DUR_PRESENT) { 5974 ttlm_info->duration = pos[0] | pos[1] << 8 | pos[2] << 16; 5975 pos += 3; 5976 } 5977 5978 if (control & IEEE80211_TTLM_CONTROL_LINK_MAP_SIZE) 5979 map_size = 1; 5980 else 5981 map_size = 2; 5982 5983 /* According to Draft P802.11be_D3.0 clause 35.3.7.1.7, an AP MLD shall 5984 * not advertise a TID-to-link mapping that does not map all TIDs to the 5985 * same link set, reject frame if not all links have mapping 5986 */ 5987 if (link_map_presence != 0xff) { 5988 sdata_info(sdata, 5989 "Invalid advertised T2L mapping presence indicator\n"); 5990 return -EINVAL; 5991 } 5992 5993 ttlm_info->map = ieee80211_get_ttlm(map_size, pos); 5994 if (!ttlm_info->map) { 5995 sdata_info(sdata, 5996 "Invalid advertised T2L map for TID 0\n"); 5997 return -EINVAL; 5998 } 5999 6000 pos += map_size; 6001 6002 for (tid = 1; tid < 8; tid++) { 6003 u16 map = ieee80211_get_ttlm(map_size, pos); 6004 6005 if (map != ttlm_info->map) { 6006 sdata_info(sdata, "Invalid advertised T2L map for tid %d\n", 6007 tid); 6008 return -EINVAL; 6009 } 6010 6011 pos += map_size; 6012 } 6013 return 0; 6014 } 6015 6016 static void ieee80211_process_adv_ttlm(struct ieee80211_sub_if_data *sdata, 6017 struct ieee802_11_elems *elems, 6018 u64 beacon_ts) 6019 { 6020 u8 i; 6021 int ret; 6022 6023 if (!ieee80211_vif_is_mld(&sdata->vif)) 6024 return; 6025 6026 if (!elems->ttlm_num) { 6027 if (sdata->u.mgd.ttlm_info.switch_time) { 6028 /* if a planned TID-to-link mapping was cancelled - 6029 * abort it 6030 */ 6031 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, 6032 &sdata->u.mgd.ttlm_work); 6033 } else if (sdata->u.mgd.ttlm_info.active) { 6034 /* if no TID-to-link element, set to default mapping in 6035 * which all TIDs are mapped to all setup links 6036 */ 6037 ret = ieee80211_vif_set_links(sdata, 6038 sdata->vif.valid_links, 6039 0); 6040 if (ret) { 6041 sdata_info(sdata, "Failed setting valid/dormant links\n"); 6042 return; 6043 } 6044 ieee80211_vif_cfg_change_notify(sdata, 6045 BSS_CHANGED_MLD_VALID_LINKS); 6046 } 6047 memset(&sdata->u.mgd.ttlm_info, 0, 6048 sizeof(sdata->u.mgd.ttlm_info)); 6049 return; 6050 } 6051 6052 for (i = 0; i < elems->ttlm_num; i++) { 6053 struct ieee80211_adv_ttlm_info ttlm_info; 6054 u32 res; 6055 6056 res = ieee80211_parse_adv_t2l(sdata, elems->ttlm[i], 6057 &ttlm_info); 6058 6059 if (res) { 6060 __ieee80211_disconnect(sdata); 6061 return; 6062 } 6063 6064 if (ttlm_info.switch_time) { 6065 u16 beacon_ts_tu, st_tu, delay; 6066 u32 delay_jiffies; 6067 u64 mask; 6068 6069 /* The t2l map switch time is indicated with a partial 6070 * TSF value (bits 10 to 25), get the partial beacon TS 6071 * as well, and calc the delay to the start time. 6072 */ 6073 mask = GENMASK_ULL(25, 10); 6074 beacon_ts_tu = (beacon_ts & mask) >> 10; 6075 st_tu = ttlm_info.switch_time; 6076 delay = st_tu - beacon_ts_tu; 6077 6078 /* 6079 * If the switch time is far in the future, then it 6080 * could also be the previous switch still being 6081 * announced. 6082 * We can simply ignore it for now, if it is a future 6083 * switch the AP will continue to announce it anyway. 6084 */ 6085 if (delay > IEEE80211_ADV_TTLM_ST_UNDERFLOW) 6086 return; 6087 6088 delay_jiffies = TU_TO_JIFFIES(delay); 6089 6090 /* Link switching can take time, so schedule it 6091 * 100ms before to be ready on time 6092 */ 6093 if (delay_jiffies > IEEE80211_ADV_TTLM_SAFETY_BUFFER_MS) 6094 delay_jiffies -= 6095 IEEE80211_ADV_TTLM_SAFETY_BUFFER_MS; 6096 else 6097 delay_jiffies = 0; 6098 6099 sdata->u.mgd.ttlm_info = ttlm_info; 6100 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, 6101 &sdata->u.mgd.ttlm_work); 6102 wiphy_delayed_work_queue(sdata->local->hw.wiphy, 6103 &sdata->u.mgd.ttlm_work, 6104 delay_jiffies); 6105 return; 6106 } 6107 } 6108 } 6109 6110 static void ieee80211_rx_mgmt_beacon(struct ieee80211_link_data *link, 6111 struct ieee80211_hdr *hdr, size_t len, 6112 struct ieee80211_rx_status *rx_status) 6113 { 6114 struct ieee80211_sub_if_data *sdata = link->sdata; 6115 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 6116 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; 6117 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg; 6118 struct ieee80211_mgmt *mgmt = (void *) hdr; 6119 size_t baselen; 6120 struct ieee802_11_elems *elems; 6121 struct ieee80211_local *local = sdata->local; 6122 struct ieee80211_chanctx_conf *chanctx_conf; 6123 struct ieee80211_supported_band *sband; 6124 struct ieee80211_channel *chan; 6125 struct link_sta_info *link_sta; 6126 struct sta_info *sta; 6127 u64 changed = 0; 6128 bool erp_valid; 6129 u8 erp_value = 0; 6130 u32 ncrc = 0; 6131 u8 *bssid, *variable = mgmt->u.beacon.variable; 6132 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN]; 6133 struct ieee80211_elems_parse_params parse_params = { 6134 .mode = link->u.mgd.conn.mode, 6135 .link_id = -1, 6136 .from_ap = true, 6137 }; 6138 6139 lockdep_assert_wiphy(local->hw.wiphy); 6140 6141 /* Process beacon from the current BSS */ 6142 bssid = ieee80211_get_bssid(hdr, len, sdata->vif.type); 6143 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) { 6144 struct ieee80211_ext *ext = (void *) mgmt; 6145 6146 if (ieee80211_is_s1g_short_beacon(ext->frame_control)) 6147 variable = ext->u.s1g_short_beacon.variable; 6148 else 6149 variable = ext->u.s1g_beacon.variable; 6150 } 6151 6152 baselen = (u8 *) variable - (u8 *) mgmt; 6153 if (baselen > len) 6154 return; 6155 6156 parse_params.start = variable; 6157 parse_params.len = len - baselen; 6158 6159 rcu_read_lock(); 6160 chanctx_conf = rcu_dereference(link->conf->chanctx_conf); 6161 if (!chanctx_conf) { 6162 rcu_read_unlock(); 6163 return; 6164 } 6165 6166 if (ieee80211_rx_status_to_khz(rx_status) != 6167 ieee80211_channel_to_khz(chanctx_conf->def.chan)) { 6168 rcu_read_unlock(); 6169 return; 6170 } 6171 chan = chanctx_conf->def.chan; 6172 rcu_read_unlock(); 6173 6174 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon && 6175 !WARN_ON(ieee80211_vif_is_mld(&sdata->vif)) && 6176 ieee80211_rx_our_beacon(bssid, ifmgd->assoc_data->link[0].bss)) { 6177 parse_params.bss = ifmgd->assoc_data->link[0].bss; 6178 elems = ieee802_11_parse_elems_full(&parse_params); 6179 if (!elems) 6180 return; 6181 6182 ieee80211_rx_bss_info(link, mgmt, len, rx_status); 6183 6184 if (elems->dtim_period) 6185 link->u.mgd.dtim_period = elems->dtim_period; 6186 link->u.mgd.have_beacon = true; 6187 ifmgd->assoc_data->need_beacon = false; 6188 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) { 6189 link->conf->sync_tsf = 6190 le64_to_cpu(mgmt->u.beacon.timestamp); 6191 link->conf->sync_device_ts = 6192 rx_status->device_timestamp; 6193 link->conf->sync_dtim_count = elems->dtim_count; 6194 } 6195 6196 if (elems->mbssid_config_ie) 6197 bss_conf->profile_periodicity = 6198 elems->mbssid_config_ie->profile_periodicity; 6199 else 6200 bss_conf->profile_periodicity = 0; 6201 6202 if (elems->ext_capab_len >= 11 && 6203 (elems->ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT)) 6204 bss_conf->ema_ap = true; 6205 else 6206 bss_conf->ema_ap = false; 6207 6208 /* continue assoc process */ 6209 ifmgd->assoc_data->timeout = jiffies; 6210 ifmgd->assoc_data->timeout_started = true; 6211 run_again(sdata, ifmgd->assoc_data->timeout); 6212 kfree(elems); 6213 return; 6214 } 6215 6216 if (!ifmgd->associated || 6217 !ieee80211_rx_our_beacon(bssid, link->conf->bss)) 6218 return; 6219 bssid = link->u.mgd.bssid; 6220 6221 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL)) 6222 ieee80211_handle_beacon_sig(link, ifmgd, bss_conf, 6223 local, rx_status); 6224 6225 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) { 6226 mlme_dbg_ratelimited(sdata, 6227 "cancelling AP probe due to a received beacon\n"); 6228 ieee80211_reset_ap_probe(sdata); 6229 } 6230 6231 /* 6232 * Push the beacon loss detection into the future since 6233 * we are processing a beacon from the AP just now. 6234 */ 6235 ieee80211_sta_reset_beacon_monitor(sdata); 6236 6237 /* TODO: CRC urrently not calculated on S1G Beacon Compatibility 6238 * element (which carries the beacon interval). Don't forget to add a 6239 * bit to care_about_ies[] above if mac80211 is interested in a 6240 * changing S1G element. 6241 */ 6242 if (!ieee80211_is_s1g_beacon(hdr->frame_control)) 6243 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4); 6244 parse_params.bss = link->conf->bss; 6245 parse_params.filter = care_about_ies; 6246 parse_params.crc = ncrc; 6247 elems = ieee802_11_parse_elems_full(&parse_params); 6248 if (!elems) 6249 return; 6250 ncrc = elems->crc; 6251 6252 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) && 6253 ieee80211_check_tim(elems->tim, elems->tim_len, vif_cfg->aid)) { 6254 if (local->hw.conf.dynamic_ps_timeout > 0) { 6255 if (local->hw.conf.flags & IEEE80211_CONF_PS) { 6256 local->hw.conf.flags &= ~IEEE80211_CONF_PS; 6257 ieee80211_hw_config(local, 6258 IEEE80211_CONF_CHANGE_PS); 6259 } 6260 ieee80211_send_nullfunc(local, sdata, false); 6261 } else if (!local->pspolling && sdata->u.mgd.powersave) { 6262 local->pspolling = true; 6263 6264 /* 6265 * Here is assumed that the driver will be 6266 * able to send ps-poll frame and receive a 6267 * response even though power save mode is 6268 * enabled, but some drivers might require 6269 * to disable power save here. This needs 6270 * to be investigated. 6271 */ 6272 ieee80211_send_pspoll(local, sdata); 6273 } 6274 } 6275 6276 if (sdata->vif.p2p || 6277 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) { 6278 struct ieee80211_p2p_noa_attr noa = {}; 6279 int ret; 6280 6281 ret = cfg80211_get_p2p_attr(variable, 6282 len - baselen, 6283 IEEE80211_P2P_ATTR_ABSENCE_NOTICE, 6284 (u8 *) &noa, sizeof(noa)); 6285 if (ret >= 2) { 6286 if (link->u.mgd.p2p_noa_index != noa.index) { 6287 /* valid noa_attr and index changed */ 6288 link->u.mgd.p2p_noa_index = noa.index; 6289 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa)); 6290 changed |= BSS_CHANGED_P2P_PS; 6291 /* 6292 * make sure we update all information, the CRC 6293 * mechanism doesn't look at P2P attributes. 6294 */ 6295 link->u.mgd.beacon_crc_valid = false; 6296 } 6297 } else if (link->u.mgd.p2p_noa_index != -1) { 6298 /* noa_attr not found and we had valid noa_attr before */ 6299 link->u.mgd.p2p_noa_index = -1; 6300 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr)); 6301 changed |= BSS_CHANGED_P2P_PS; 6302 link->u.mgd.beacon_crc_valid = false; 6303 } 6304 } 6305 6306 /* 6307 * Update beacon timing and dtim count on every beacon appearance. This 6308 * will allow the driver to use the most updated values. Do it before 6309 * comparing this one with last received beacon. 6310 * IMPORTANT: These parameters would possibly be out of sync by the time 6311 * the driver will use them. The synchronized view is currently 6312 * guaranteed only in certain callbacks. 6313 */ 6314 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) && 6315 !ieee80211_is_s1g_beacon(hdr->frame_control)) { 6316 link->conf->sync_tsf = 6317 le64_to_cpu(mgmt->u.beacon.timestamp); 6318 link->conf->sync_device_ts = 6319 rx_status->device_timestamp; 6320 link->conf->sync_dtim_count = elems->dtim_count; 6321 } 6322 6323 if ((ncrc == link->u.mgd.beacon_crc && link->u.mgd.beacon_crc_valid) || 6324 ieee80211_is_s1g_short_beacon(mgmt->frame_control)) 6325 goto free; 6326 link->u.mgd.beacon_crc = ncrc; 6327 link->u.mgd.beacon_crc_valid = true; 6328 6329 ieee80211_rx_bss_info(link, mgmt, len, rx_status); 6330 6331 ieee80211_sta_process_chanswitch(link, rx_status->mactime, 6332 rx_status->device_timestamp, 6333 elems, true); 6334 6335 if (!link->u.mgd.disable_wmm_tracking && 6336 ieee80211_sta_wmm_params(local, link, elems->wmm_param, 6337 elems->wmm_param_len, 6338 elems->mu_edca_param_set)) 6339 changed |= BSS_CHANGED_QOS; 6340 6341 /* 6342 * If we haven't had a beacon before, tell the driver about the 6343 * DTIM period (and beacon timing if desired) now. 6344 */ 6345 if (!link->u.mgd.have_beacon) { 6346 /* a few bogus AP send dtim_period = 0 or no TIM IE */ 6347 bss_conf->dtim_period = elems->dtim_period ?: 1; 6348 6349 changed |= BSS_CHANGED_BEACON_INFO; 6350 link->u.mgd.have_beacon = true; 6351 6352 ieee80211_recalc_ps(local); 6353 6354 ieee80211_recalc_ps_vif(sdata); 6355 } 6356 6357 if (elems->erp_info) { 6358 erp_valid = true; 6359 erp_value = elems->erp_info[0]; 6360 } else { 6361 erp_valid = false; 6362 } 6363 6364 if (!ieee80211_is_s1g_beacon(hdr->frame_control)) 6365 changed |= ieee80211_handle_bss_capability(link, 6366 le16_to_cpu(mgmt->u.beacon.capab_info), 6367 erp_valid, erp_value); 6368 6369 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr); 6370 if (WARN_ON(!sta)) { 6371 goto free; 6372 } 6373 link_sta = rcu_dereference_protected(sta->link[link->link_id], 6374 lockdep_is_held(&local->hw.wiphy->mtx)); 6375 if (WARN_ON(!link_sta)) { 6376 goto free; 6377 } 6378 6379 if (WARN_ON(!link->conf->chanreq.oper.chan)) 6380 goto free; 6381 6382 sband = local->hw.wiphy->bands[link->conf->chanreq.oper.chan->band]; 6383 6384 changed |= ieee80211_recalc_twt_req(sdata, sband, link, link_sta, elems); 6385 6386 if (ieee80211_config_bw(link, elems, true, &changed)) { 6387 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, 6388 WLAN_REASON_DEAUTH_LEAVING, 6389 true, deauth_buf); 6390 ieee80211_report_disconnect(sdata, deauth_buf, 6391 sizeof(deauth_buf), true, 6392 WLAN_REASON_DEAUTH_LEAVING, 6393 false); 6394 goto free; 6395 } 6396 6397 if (elems->opmode_notif) 6398 ieee80211_vht_handle_opmode(sdata, link_sta, 6399 *elems->opmode_notif, 6400 rx_status->band); 6401 6402 changed |= ieee80211_handle_pwr_constr(link, chan, mgmt, 6403 elems->country_elem, 6404 elems->country_elem_len, 6405 elems->pwr_constr_elem, 6406 elems->cisco_dtpc_elem); 6407 6408 ieee80211_ml_reconfiguration(sdata, elems); 6409 ieee80211_process_adv_ttlm(sdata, elems, 6410 le64_to_cpu(mgmt->u.beacon.timestamp)); 6411 6412 ieee80211_link_info_change_notify(sdata, link, changed); 6413 free: 6414 kfree(elems); 6415 } 6416 6417 static void ieee80211_apply_neg_ttlm(struct ieee80211_sub_if_data *sdata, 6418 struct ieee80211_neg_ttlm neg_ttlm) 6419 { 6420 u16 new_active_links, new_dormant_links, new_suspended_links, map = 0; 6421 u8 i; 6422 6423 for (i = 0; i < IEEE80211_TTLM_NUM_TIDS; i++) 6424 map |= neg_ttlm.downlink[i] | neg_ttlm.uplink[i]; 6425 6426 /* If there is an active TTLM, unset previously suspended links */ 6427 if (sdata->vif.neg_ttlm.valid) 6428 sdata->vif.dormant_links &= ~sdata->vif.suspended_links; 6429 6430 /* exclude links that are already disabled by advertised TTLM */ 6431 new_active_links = 6432 map & sdata->vif.valid_links & ~sdata->vif.dormant_links; 6433 new_suspended_links = 6434 (~map & sdata->vif.valid_links) & ~sdata->vif.dormant_links; 6435 new_dormant_links = sdata->vif.dormant_links | new_suspended_links; 6436 if (ieee80211_ttlm_set_links(sdata, new_active_links, 6437 new_dormant_links, new_suspended_links)) 6438 return; 6439 6440 sdata->vif.neg_ttlm = neg_ttlm; 6441 sdata->vif.neg_ttlm.valid = true; 6442 } 6443 6444 static void ieee80211_neg_ttlm_timeout_work(struct wiphy *wiphy, 6445 struct wiphy_work *work) 6446 { 6447 struct ieee80211_sub_if_data *sdata = 6448 container_of(work, struct ieee80211_sub_if_data, 6449 u.mgd.neg_ttlm_timeout_work.work); 6450 6451 sdata_info(sdata, 6452 "No negotiated TTLM response from AP, disconnecting.\n"); 6453 6454 __ieee80211_disconnect(sdata); 6455 } 6456 6457 static void 6458 ieee80211_neg_ttlm_add_suggested_map(struct sk_buff *skb, 6459 struct ieee80211_neg_ttlm *neg_ttlm) 6460 { 6461 u8 i, direction[IEEE80211_TTLM_MAX_CNT]; 6462 6463 if (memcmp(neg_ttlm->downlink, neg_ttlm->uplink, 6464 sizeof(neg_ttlm->downlink))) { 6465 direction[0] = IEEE80211_TTLM_DIRECTION_DOWN; 6466 direction[1] = IEEE80211_TTLM_DIRECTION_UP; 6467 } else { 6468 direction[0] = IEEE80211_TTLM_DIRECTION_BOTH; 6469 } 6470 6471 for (i = 0; i < ARRAY_SIZE(direction); i++) { 6472 u8 tid, len, map_ind = 0, *len_pos, *map_ind_pos, *pos; 6473 __le16 map; 6474 6475 len = sizeof(struct ieee80211_ttlm_elem) + 1 + 1; 6476 6477 pos = skb_put(skb, len + 2); 6478 *pos++ = WLAN_EID_EXTENSION; 6479 len_pos = pos++; 6480 *pos++ = WLAN_EID_EXT_TID_TO_LINK_MAPPING; 6481 *pos++ = direction[i]; 6482 map_ind_pos = pos++; 6483 for (tid = 0; tid < IEEE80211_TTLM_NUM_TIDS; tid++) { 6484 map = direction[i] == IEEE80211_TTLM_DIRECTION_UP ? 6485 cpu_to_le16(neg_ttlm->uplink[tid]) : 6486 cpu_to_le16(neg_ttlm->downlink[tid]); 6487 if (!map) 6488 continue; 6489 6490 len += 2; 6491 map_ind |= BIT(tid); 6492 skb_put_data(skb, &map, sizeof(map)); 6493 } 6494 6495 *map_ind_pos = map_ind; 6496 *len_pos = len; 6497 6498 if (direction[i] == IEEE80211_TTLM_DIRECTION_BOTH) 6499 break; 6500 } 6501 } 6502 6503 static void 6504 ieee80211_send_neg_ttlm_req(struct ieee80211_sub_if_data *sdata, 6505 struct ieee80211_neg_ttlm *neg_ttlm, 6506 u8 dialog_token) 6507 { 6508 struct ieee80211_local *local = sdata->local; 6509 struct ieee80211_mgmt *mgmt; 6510 struct sk_buff *skb; 6511 int hdr_len = offsetofend(struct ieee80211_mgmt, u.action.u.ttlm_req); 6512 int ttlm_max_len = 2 + 1 + sizeof(struct ieee80211_ttlm_elem) + 1 + 6513 2 * 2 * IEEE80211_TTLM_NUM_TIDS; 6514 6515 skb = dev_alloc_skb(local->tx_headroom + hdr_len + ttlm_max_len); 6516 if (!skb) 6517 return; 6518 6519 skb_reserve(skb, local->tx_headroom); 6520 mgmt = skb_put_zero(skb, hdr_len); 6521 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 6522 IEEE80211_STYPE_ACTION); 6523 memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN); 6524 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); 6525 memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN); 6526 6527 mgmt->u.action.category = WLAN_CATEGORY_PROTECTED_EHT; 6528 mgmt->u.action.u.ttlm_req.action_code = 6529 WLAN_PROTECTED_EHT_ACTION_TTLM_REQ; 6530 mgmt->u.action.u.ttlm_req.dialog_token = dialog_token; 6531 ieee80211_neg_ttlm_add_suggested_map(skb, neg_ttlm); 6532 ieee80211_tx_skb(sdata, skb); 6533 } 6534 6535 int ieee80211_req_neg_ttlm(struct ieee80211_sub_if_data *sdata, 6536 struct cfg80211_ttlm_params *params) 6537 { 6538 struct ieee80211_neg_ttlm neg_ttlm = {}; 6539 u8 i; 6540 6541 if (!ieee80211_vif_is_mld(&sdata->vif) || 6542 !(sdata->vif.cfg.mld_capa_op & 6543 IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP)) 6544 return -EINVAL; 6545 6546 for (i = 0; i < IEEE80211_TTLM_NUM_TIDS; i++) { 6547 if ((params->dlink[i] & ~sdata->vif.valid_links) || 6548 (params->ulink[i] & ~sdata->vif.valid_links)) 6549 return -EINVAL; 6550 6551 neg_ttlm.downlink[i] = params->dlink[i]; 6552 neg_ttlm.uplink[i] = params->ulink[i]; 6553 } 6554 6555 if (drv_can_neg_ttlm(sdata->local, sdata, &neg_ttlm) != 6556 NEG_TTLM_RES_ACCEPT) 6557 return -EINVAL; 6558 6559 ieee80211_apply_neg_ttlm(sdata, neg_ttlm); 6560 sdata->u.mgd.dialog_token_alloc++; 6561 ieee80211_send_neg_ttlm_req(sdata, &sdata->vif.neg_ttlm, 6562 sdata->u.mgd.dialog_token_alloc); 6563 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, 6564 &sdata->u.mgd.neg_ttlm_timeout_work); 6565 wiphy_delayed_work_queue(sdata->local->hw.wiphy, 6566 &sdata->u.mgd.neg_ttlm_timeout_work, 6567 IEEE80211_NEG_TTLM_REQ_TIMEOUT); 6568 return 0; 6569 } 6570 6571 static void 6572 ieee80211_send_neg_ttlm_res(struct ieee80211_sub_if_data *sdata, 6573 enum ieee80211_neg_ttlm_res ttlm_res, 6574 u8 dialog_token, 6575 struct ieee80211_neg_ttlm *neg_ttlm) 6576 { 6577 struct ieee80211_local *local = sdata->local; 6578 struct ieee80211_mgmt *mgmt; 6579 struct sk_buff *skb; 6580 int hdr_len = offsetofend(struct ieee80211_mgmt, u.action.u.ttlm_res); 6581 int ttlm_max_len = 2 + 1 + sizeof(struct ieee80211_ttlm_elem) + 1 + 6582 2 * 2 * IEEE80211_TTLM_NUM_TIDS; 6583 6584 skb = dev_alloc_skb(local->tx_headroom + hdr_len + ttlm_max_len); 6585 if (!skb) 6586 return; 6587 6588 skb_reserve(skb, local->tx_headroom); 6589 mgmt = skb_put_zero(skb, hdr_len); 6590 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 6591 IEEE80211_STYPE_ACTION); 6592 memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN); 6593 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); 6594 memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN); 6595 6596 mgmt->u.action.category = WLAN_CATEGORY_PROTECTED_EHT; 6597 mgmt->u.action.u.ttlm_res.action_code = 6598 WLAN_PROTECTED_EHT_ACTION_TTLM_RES; 6599 mgmt->u.action.u.ttlm_res.dialog_token = dialog_token; 6600 switch (ttlm_res) { 6601 default: 6602 WARN_ON(1); 6603 fallthrough; 6604 case NEG_TTLM_RES_REJECT: 6605 mgmt->u.action.u.ttlm_res.status_code = 6606 WLAN_STATUS_DENIED_TID_TO_LINK_MAPPING; 6607 break; 6608 case NEG_TTLM_RES_ACCEPT: 6609 mgmt->u.action.u.ttlm_res.status_code = WLAN_STATUS_SUCCESS; 6610 break; 6611 case NEG_TTLM_RES_SUGGEST_PREFERRED: 6612 mgmt->u.action.u.ttlm_res.status_code = 6613 WLAN_STATUS_PREF_TID_TO_LINK_MAPPING_SUGGESTED; 6614 ieee80211_neg_ttlm_add_suggested_map(skb, neg_ttlm); 6615 break; 6616 } 6617 6618 ieee80211_tx_skb(sdata, skb); 6619 } 6620 6621 static int 6622 ieee80211_parse_neg_ttlm(struct ieee80211_sub_if_data *sdata, 6623 const struct ieee80211_ttlm_elem *ttlm, 6624 struct ieee80211_neg_ttlm *neg_ttlm, 6625 u8 *direction) 6626 { 6627 u8 control, link_map_presence, map_size, tid; 6628 u8 *pos; 6629 6630 /* The element size was already validated in 6631 * ieee80211_tid_to_link_map_size_ok() 6632 */ 6633 pos = (void *)ttlm->optional; 6634 6635 control = ttlm->control; 6636 6637 /* mapping switch time and expected duration fields are not expected 6638 * in case of negotiated TTLM 6639 */ 6640 if (control & (IEEE80211_TTLM_CONTROL_SWITCH_TIME_PRESENT | 6641 IEEE80211_TTLM_CONTROL_EXPECTED_DUR_PRESENT)) { 6642 mlme_dbg(sdata, 6643 "Invalid TTLM element in negotiated TTLM request\n"); 6644 return -EINVAL; 6645 } 6646 6647 if (control & IEEE80211_TTLM_CONTROL_DEF_LINK_MAP) { 6648 for (tid = 0; tid < IEEE80211_TTLM_NUM_TIDS; tid++) { 6649 neg_ttlm->downlink[tid] = sdata->vif.valid_links; 6650 neg_ttlm->uplink[tid] = sdata->vif.valid_links; 6651 } 6652 *direction = IEEE80211_TTLM_DIRECTION_BOTH; 6653 return 0; 6654 } 6655 6656 *direction = u8_get_bits(control, IEEE80211_TTLM_CONTROL_DIRECTION); 6657 if (*direction != IEEE80211_TTLM_DIRECTION_DOWN && 6658 *direction != IEEE80211_TTLM_DIRECTION_UP && 6659 *direction != IEEE80211_TTLM_DIRECTION_BOTH) 6660 return -EINVAL; 6661 6662 link_map_presence = *pos; 6663 pos++; 6664 6665 if (control & IEEE80211_TTLM_CONTROL_LINK_MAP_SIZE) 6666 map_size = 1; 6667 else 6668 map_size = 2; 6669 6670 for (tid = 0; tid < IEEE80211_TTLM_NUM_TIDS; tid++) { 6671 u16 map; 6672 6673 if (link_map_presence & BIT(tid)) { 6674 map = ieee80211_get_ttlm(map_size, pos); 6675 if (!map) { 6676 mlme_dbg(sdata, 6677 "No active links for TID %d", tid); 6678 return -EINVAL; 6679 } 6680 } else { 6681 map = 0; 6682 } 6683 6684 switch (*direction) { 6685 case IEEE80211_TTLM_DIRECTION_BOTH: 6686 neg_ttlm->downlink[tid] = map; 6687 neg_ttlm->uplink[tid] = map; 6688 break; 6689 case IEEE80211_TTLM_DIRECTION_DOWN: 6690 neg_ttlm->downlink[tid] = map; 6691 break; 6692 case IEEE80211_TTLM_DIRECTION_UP: 6693 neg_ttlm->uplink[tid] = map; 6694 break; 6695 default: 6696 return -EINVAL; 6697 } 6698 pos += map_size; 6699 } 6700 return 0; 6701 } 6702 6703 void ieee80211_process_neg_ttlm_req(struct ieee80211_sub_if_data *sdata, 6704 struct ieee80211_mgmt *mgmt, size_t len) 6705 { 6706 u8 dialog_token, direction[IEEE80211_TTLM_MAX_CNT] = {}, i; 6707 size_t ies_len; 6708 enum ieee80211_neg_ttlm_res ttlm_res = NEG_TTLM_RES_ACCEPT; 6709 struct ieee802_11_elems *elems = NULL; 6710 struct ieee80211_neg_ttlm neg_ttlm = {}; 6711 6712 BUILD_BUG_ON(ARRAY_SIZE(direction) != ARRAY_SIZE(elems->ttlm)); 6713 6714 if (!ieee80211_vif_is_mld(&sdata->vif)) 6715 return; 6716 6717 dialog_token = mgmt->u.action.u.ttlm_req.dialog_token; 6718 ies_len = len - offsetof(struct ieee80211_mgmt, 6719 u.action.u.ttlm_req.variable); 6720 elems = ieee802_11_parse_elems(mgmt->u.action.u.ttlm_req.variable, 6721 ies_len, true, NULL); 6722 if (!elems) { 6723 ttlm_res = NEG_TTLM_RES_REJECT; 6724 goto out; 6725 } 6726 6727 for (i = 0; i < elems->ttlm_num; i++) { 6728 if (ieee80211_parse_neg_ttlm(sdata, elems->ttlm[i], 6729 &neg_ttlm, &direction[i]) || 6730 (direction[i] == IEEE80211_TTLM_DIRECTION_BOTH && 6731 elems->ttlm_num != 1)) { 6732 ttlm_res = NEG_TTLM_RES_REJECT; 6733 goto out; 6734 } 6735 } 6736 6737 if (!elems->ttlm_num || 6738 (elems->ttlm_num == 2 && direction[0] == direction[1])) { 6739 ttlm_res = NEG_TTLM_RES_REJECT; 6740 goto out; 6741 } 6742 6743 for (i = 0; i < IEEE80211_TTLM_NUM_TIDS; i++) { 6744 if ((neg_ttlm.downlink[i] && 6745 (neg_ttlm.downlink[i] & ~sdata->vif.valid_links)) || 6746 (neg_ttlm.uplink[i] && 6747 (neg_ttlm.uplink[i] & ~sdata->vif.valid_links))) { 6748 ttlm_res = NEG_TTLM_RES_REJECT; 6749 goto out; 6750 } 6751 } 6752 6753 ttlm_res = drv_can_neg_ttlm(sdata->local, sdata, &neg_ttlm); 6754 6755 if (ttlm_res != NEG_TTLM_RES_ACCEPT) 6756 goto out; 6757 6758 ieee80211_apply_neg_ttlm(sdata, neg_ttlm); 6759 out: 6760 kfree(elems); 6761 ieee80211_send_neg_ttlm_res(sdata, ttlm_res, dialog_token, &neg_ttlm); 6762 } 6763 6764 void ieee80211_process_neg_ttlm_res(struct ieee80211_sub_if_data *sdata, 6765 struct ieee80211_mgmt *mgmt, size_t len) 6766 { 6767 if (!ieee80211_vif_is_mld(&sdata->vif) || 6768 mgmt->u.action.u.ttlm_req.dialog_token != 6769 sdata->u.mgd.dialog_token_alloc) 6770 return; 6771 6772 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, 6773 &sdata->u.mgd.neg_ttlm_timeout_work); 6774 6775 /* MLD station sends a TID to link mapping request, mainly to handle 6776 * BTM (BSS transition management) request, in which case it needs to 6777 * restrict the active links set. 6778 * In this case it's not expected that the MLD AP will reject the 6779 * negotiated TTLM request. 6780 * This can be better implemented in the future, to handle request 6781 * rejections. 6782 */ 6783 if (mgmt->u.action.u.ttlm_res.status_code != WLAN_STATUS_SUCCESS) 6784 __ieee80211_disconnect(sdata); 6785 } 6786 6787 void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data *sdata, 6788 struct sk_buff *skb) 6789 { 6790 struct ieee80211_link_data *link = &sdata->deflink; 6791 struct ieee80211_rx_status *rx_status; 6792 struct ieee80211_hdr *hdr; 6793 u16 fc; 6794 6795 lockdep_assert_wiphy(sdata->local->hw.wiphy); 6796 6797 rx_status = (struct ieee80211_rx_status *) skb->cb; 6798 hdr = (struct ieee80211_hdr *) skb->data; 6799 fc = le16_to_cpu(hdr->frame_control); 6800 6801 switch (fc & IEEE80211_FCTL_STYPE) { 6802 case IEEE80211_STYPE_S1G_BEACON: 6803 ieee80211_rx_mgmt_beacon(link, hdr, skb->len, rx_status); 6804 break; 6805 } 6806 } 6807 6808 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, 6809 struct sk_buff *skb) 6810 { 6811 struct ieee80211_link_data *link = &sdata->deflink; 6812 struct ieee80211_rx_status *rx_status; 6813 struct ieee80211_mgmt *mgmt; 6814 u16 fc; 6815 int ies_len; 6816 6817 lockdep_assert_wiphy(sdata->local->hw.wiphy); 6818 6819 rx_status = (struct ieee80211_rx_status *) skb->cb; 6820 mgmt = (struct ieee80211_mgmt *) skb->data; 6821 fc = le16_to_cpu(mgmt->frame_control); 6822 6823 if (rx_status->link_valid) { 6824 link = sdata_dereference(sdata->link[rx_status->link_id], 6825 sdata); 6826 if (!link) 6827 return; 6828 } 6829 6830 switch (fc & IEEE80211_FCTL_STYPE) { 6831 case IEEE80211_STYPE_BEACON: 6832 ieee80211_rx_mgmt_beacon(link, (void *)mgmt, 6833 skb->len, rx_status); 6834 break; 6835 case IEEE80211_STYPE_PROBE_RESP: 6836 ieee80211_rx_mgmt_probe_resp(link, skb); 6837 break; 6838 case IEEE80211_STYPE_AUTH: 6839 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len); 6840 break; 6841 case IEEE80211_STYPE_DEAUTH: 6842 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len); 6843 break; 6844 case IEEE80211_STYPE_DISASSOC: 6845 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len); 6846 break; 6847 case IEEE80211_STYPE_ASSOC_RESP: 6848 case IEEE80211_STYPE_REASSOC_RESP: 6849 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len); 6850 break; 6851 case IEEE80211_STYPE_ACTION: 6852 if (!sdata->u.mgd.associated || 6853 !ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr)) 6854 break; 6855 6856 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) { 6857 struct ieee802_11_elems *elems; 6858 6859 ies_len = skb->len - 6860 offsetof(struct ieee80211_mgmt, 6861 u.action.u.chan_switch.variable); 6862 6863 if (ies_len < 0) 6864 break; 6865 6866 /* CSA IE cannot be overridden, no need for BSSID */ 6867 elems = ieee802_11_parse_elems( 6868 mgmt->u.action.u.chan_switch.variable, 6869 ies_len, true, NULL); 6870 6871 if (elems && !elems->parse_error) 6872 ieee80211_sta_process_chanswitch(link, 6873 rx_status->mactime, 6874 rx_status->device_timestamp, 6875 elems, false); 6876 kfree(elems); 6877 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) { 6878 struct ieee802_11_elems *elems; 6879 6880 ies_len = skb->len - 6881 offsetof(struct ieee80211_mgmt, 6882 u.action.u.ext_chan_switch.variable); 6883 6884 if (ies_len < 0) 6885 break; 6886 6887 /* 6888 * extended CSA IE can't be overridden, no need for 6889 * BSSID 6890 */ 6891 elems = ieee802_11_parse_elems( 6892 mgmt->u.action.u.ext_chan_switch.variable, 6893 ies_len, true, NULL); 6894 6895 if (elems && !elems->parse_error) { 6896 /* for the handling code pretend it was an IE */ 6897 elems->ext_chansw_ie = 6898 &mgmt->u.action.u.ext_chan_switch.data; 6899 6900 ieee80211_sta_process_chanswitch(link, 6901 rx_status->mactime, 6902 rx_status->device_timestamp, 6903 elems, false); 6904 } 6905 6906 kfree(elems); 6907 } 6908 break; 6909 } 6910 } 6911 6912 static void ieee80211_sta_timer(struct timer_list *t) 6913 { 6914 struct ieee80211_sub_if_data *sdata = 6915 from_timer(sdata, t, u.mgd.timer); 6916 6917 wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work); 6918 } 6919 6920 void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata, 6921 u8 reason, bool tx) 6922 { 6923 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; 6924 6925 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason, 6926 tx, frame_buf); 6927 6928 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true, 6929 reason, false); 6930 } 6931 6932 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata) 6933 { 6934 struct ieee80211_local *local = sdata->local; 6935 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 6936 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data; 6937 u32 tx_flags = 0; 6938 u16 trans = 1; 6939 u16 status = 0; 6940 struct ieee80211_prep_tx_info info = { 6941 .subtype = IEEE80211_STYPE_AUTH, 6942 }; 6943 6944 lockdep_assert_wiphy(sdata->local->hw.wiphy); 6945 6946 if (WARN_ON_ONCE(!auth_data)) 6947 return -EINVAL; 6948 6949 auth_data->tries++; 6950 6951 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) { 6952 sdata_info(sdata, "authentication with %pM timed out\n", 6953 auth_data->ap_addr); 6954 6955 /* 6956 * Most likely AP is not in the range so remove the 6957 * bss struct for that AP. 6958 */ 6959 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss); 6960 6961 return -ETIMEDOUT; 6962 } 6963 6964 if (auth_data->algorithm == WLAN_AUTH_SAE) 6965 info.duration = jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE); 6966 6967 info.link_id = auth_data->link_id; 6968 drv_mgd_prepare_tx(local, sdata, &info); 6969 6970 sdata_info(sdata, "send auth to %pM (try %d/%d)\n", 6971 auth_data->ap_addr, auth_data->tries, 6972 IEEE80211_AUTH_MAX_TRIES); 6973 6974 auth_data->expected_transaction = 2; 6975 6976 if (auth_data->algorithm == WLAN_AUTH_SAE) { 6977 trans = auth_data->sae_trans; 6978 status = auth_data->sae_status; 6979 auth_data->expected_transaction = trans; 6980 } 6981 6982 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) 6983 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS | 6984 IEEE80211_TX_INTFL_MLME_CONN_TX; 6985 6986 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status, 6987 auth_data->data, auth_data->data_len, 6988 auth_data->ap_addr, auth_data->ap_addr, 6989 NULL, 0, 0, tx_flags); 6990 6991 if (tx_flags == 0) { 6992 if (auth_data->algorithm == WLAN_AUTH_SAE) 6993 auth_data->timeout = jiffies + 6994 IEEE80211_AUTH_TIMEOUT_SAE; 6995 else 6996 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT; 6997 } else { 6998 auth_data->timeout = 6999 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG); 7000 } 7001 7002 auth_data->timeout_started = true; 7003 run_again(sdata, auth_data->timeout); 7004 7005 return 0; 7006 } 7007 7008 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata) 7009 { 7010 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data; 7011 struct ieee80211_local *local = sdata->local; 7012 int ret; 7013 7014 lockdep_assert_wiphy(sdata->local->hw.wiphy); 7015 7016 assoc_data->tries++; 7017 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) { 7018 sdata_info(sdata, "association with %pM timed out\n", 7019 assoc_data->ap_addr); 7020 7021 /* 7022 * Most likely AP is not in the range so remove the 7023 * bss struct for that AP. 7024 */ 7025 cfg80211_unlink_bss(local->hw.wiphy, 7026 assoc_data->link[assoc_data->assoc_link_id].bss); 7027 7028 return -ETIMEDOUT; 7029 } 7030 7031 sdata_info(sdata, "associate with %pM (try %d/%d)\n", 7032 assoc_data->ap_addr, assoc_data->tries, 7033 IEEE80211_ASSOC_MAX_TRIES); 7034 ret = ieee80211_send_assoc(sdata); 7035 if (ret) 7036 return ret; 7037 7038 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) { 7039 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT; 7040 assoc_data->timeout_started = true; 7041 run_again(sdata, assoc_data->timeout); 7042 } else { 7043 assoc_data->timeout = 7044 round_jiffies_up(jiffies + 7045 IEEE80211_ASSOC_TIMEOUT_LONG); 7046 assoc_data->timeout_started = true; 7047 run_again(sdata, assoc_data->timeout); 7048 } 7049 7050 return 0; 7051 } 7052 7053 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata, 7054 __le16 fc, bool acked) 7055 { 7056 struct ieee80211_local *local = sdata->local; 7057 7058 sdata->u.mgd.status_fc = fc; 7059 sdata->u.mgd.status_acked = acked; 7060 sdata->u.mgd.status_received = true; 7061 7062 wiphy_work_queue(local->hw.wiphy, &sdata->work); 7063 } 7064 7065 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata) 7066 { 7067 struct ieee80211_local *local = sdata->local; 7068 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 7069 7070 lockdep_assert_wiphy(sdata->local->hw.wiphy); 7071 7072 if (ifmgd->status_received) { 7073 __le16 fc = ifmgd->status_fc; 7074 bool status_acked = ifmgd->status_acked; 7075 7076 ifmgd->status_received = false; 7077 if (ifmgd->auth_data && ieee80211_is_auth(fc)) { 7078 if (status_acked) { 7079 if (ifmgd->auth_data->algorithm == 7080 WLAN_AUTH_SAE) 7081 ifmgd->auth_data->timeout = 7082 jiffies + 7083 IEEE80211_AUTH_TIMEOUT_SAE; 7084 else 7085 ifmgd->auth_data->timeout = 7086 jiffies + 7087 IEEE80211_AUTH_TIMEOUT_SHORT; 7088 run_again(sdata, ifmgd->auth_data->timeout); 7089 } else { 7090 ifmgd->auth_data->timeout = jiffies - 1; 7091 } 7092 ifmgd->auth_data->timeout_started = true; 7093 } else if (ifmgd->assoc_data && 7094 !ifmgd->assoc_data->comeback && 7095 (ieee80211_is_assoc_req(fc) || 7096 ieee80211_is_reassoc_req(fc))) { 7097 /* 7098 * Update association timeout based on the TX status 7099 * for the (Re)Association Request frame. Skip this if 7100 * we have already processed a (Re)Association Response 7101 * frame that indicated need for association comeback 7102 * at a specific time in the future. This could happen 7103 * if the TX status information is delayed enough for 7104 * the response to be received and processed first. 7105 */ 7106 if (status_acked) { 7107 ifmgd->assoc_data->timeout = 7108 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT; 7109 run_again(sdata, ifmgd->assoc_data->timeout); 7110 } else { 7111 ifmgd->assoc_data->timeout = jiffies - 1; 7112 } 7113 ifmgd->assoc_data->timeout_started = true; 7114 } 7115 } 7116 7117 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started && 7118 time_after(jiffies, ifmgd->auth_data->timeout)) { 7119 if (ifmgd->auth_data->done || ifmgd->auth_data->waiting) { 7120 /* 7121 * ok ... we waited for assoc or continuation but 7122 * userspace didn't do it, so kill the auth data 7123 */ 7124 ieee80211_destroy_auth_data(sdata, false); 7125 } else if (ieee80211_auth(sdata)) { 7126 u8 ap_addr[ETH_ALEN]; 7127 struct ieee80211_event event = { 7128 .type = MLME_EVENT, 7129 .u.mlme.data = AUTH_EVENT, 7130 .u.mlme.status = MLME_TIMEOUT, 7131 }; 7132 7133 memcpy(ap_addr, ifmgd->auth_data->ap_addr, ETH_ALEN); 7134 7135 ieee80211_destroy_auth_data(sdata, false); 7136 7137 cfg80211_auth_timeout(sdata->dev, ap_addr); 7138 drv_event_callback(sdata->local, sdata, &event); 7139 } 7140 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started) 7141 run_again(sdata, ifmgd->auth_data->timeout); 7142 7143 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started && 7144 time_after(jiffies, ifmgd->assoc_data->timeout)) { 7145 if ((ifmgd->assoc_data->need_beacon && 7146 !sdata->deflink.u.mgd.have_beacon) || 7147 ieee80211_do_assoc(sdata)) { 7148 struct ieee80211_event event = { 7149 .type = MLME_EVENT, 7150 .u.mlme.data = ASSOC_EVENT, 7151 .u.mlme.status = MLME_TIMEOUT, 7152 }; 7153 7154 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT); 7155 drv_event_callback(sdata->local, sdata, &event); 7156 } 7157 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started) 7158 run_again(sdata, ifmgd->assoc_data->timeout); 7159 7160 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL && 7161 ifmgd->associated) { 7162 u8 *bssid = sdata->deflink.u.mgd.bssid; 7163 int max_tries; 7164 7165 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) 7166 max_tries = max_nullfunc_tries; 7167 else 7168 max_tries = max_probe_tries; 7169 7170 /* ACK received for nullfunc probing frame */ 7171 if (!ifmgd->probe_send_count) 7172 ieee80211_reset_ap_probe(sdata); 7173 else if (ifmgd->nullfunc_failed) { 7174 if (ifmgd->probe_send_count < max_tries) { 7175 mlme_dbg(sdata, 7176 "No ack for nullfunc frame to AP %pM, try %d/%i\n", 7177 bssid, ifmgd->probe_send_count, 7178 max_tries); 7179 ieee80211_mgd_probe_ap_send(sdata); 7180 } else { 7181 mlme_dbg(sdata, 7182 "No ack for nullfunc frame to AP %pM, disconnecting.\n", 7183 bssid); 7184 ieee80211_sta_connection_lost(sdata, 7185 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, 7186 false); 7187 } 7188 } else if (time_is_after_jiffies(ifmgd->probe_timeout)) 7189 run_again(sdata, ifmgd->probe_timeout); 7190 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) { 7191 mlme_dbg(sdata, 7192 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n", 7193 bssid, probe_wait_ms); 7194 ieee80211_sta_connection_lost(sdata, 7195 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false); 7196 } else if (ifmgd->probe_send_count < max_tries) { 7197 mlme_dbg(sdata, 7198 "No probe response from AP %pM after %dms, try %d/%i\n", 7199 bssid, probe_wait_ms, 7200 ifmgd->probe_send_count, max_tries); 7201 ieee80211_mgd_probe_ap_send(sdata); 7202 } else { 7203 /* 7204 * We actually lost the connection ... or did we? 7205 * Let's make sure! 7206 */ 7207 mlme_dbg(sdata, 7208 "No probe response from AP %pM after %dms, disconnecting.\n", 7209 bssid, probe_wait_ms); 7210 7211 ieee80211_sta_connection_lost(sdata, 7212 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false); 7213 } 7214 } 7215 } 7216 7217 static void ieee80211_sta_bcn_mon_timer(struct timer_list *t) 7218 { 7219 struct ieee80211_sub_if_data *sdata = 7220 from_timer(sdata, t, u.mgd.bcn_mon_timer); 7221 7222 if (WARN_ON(ieee80211_vif_is_mld(&sdata->vif))) 7223 return; 7224 7225 if (sdata->vif.bss_conf.csa_active && 7226 !sdata->deflink.u.mgd.csa_waiting_bcn) 7227 return; 7228 7229 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER) 7230 return; 7231 7232 sdata->u.mgd.connection_loss = false; 7233 wiphy_work_queue(sdata->local->hw.wiphy, 7234 &sdata->u.mgd.beacon_connection_loss_work); 7235 } 7236 7237 static void ieee80211_sta_conn_mon_timer(struct timer_list *t) 7238 { 7239 struct ieee80211_sub_if_data *sdata = 7240 from_timer(sdata, t, u.mgd.conn_mon_timer); 7241 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 7242 struct ieee80211_local *local = sdata->local; 7243 struct sta_info *sta; 7244 unsigned long timeout; 7245 7246 if (WARN_ON(ieee80211_vif_is_mld(&sdata->vif))) 7247 return; 7248 7249 if (sdata->vif.bss_conf.csa_active && 7250 !sdata->deflink.u.mgd.csa_waiting_bcn) 7251 return; 7252 7253 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr); 7254 if (!sta) 7255 return; 7256 7257 timeout = sta->deflink.status_stats.last_ack; 7258 if (time_before(sta->deflink.status_stats.last_ack, sta->deflink.rx_stats.last_rx)) 7259 timeout = sta->deflink.rx_stats.last_rx; 7260 timeout += IEEE80211_CONNECTION_IDLE_TIME; 7261 7262 /* If timeout is after now, then update timer to fire at 7263 * the later date, but do not actually probe at this time. 7264 */ 7265 if (time_is_after_jiffies(timeout)) { 7266 mod_timer(&ifmgd->conn_mon_timer, round_jiffies_up(timeout)); 7267 return; 7268 } 7269 7270 wiphy_work_queue(local->hw.wiphy, &sdata->u.mgd.monitor_work); 7271 } 7272 7273 static void ieee80211_sta_monitor_work(struct wiphy *wiphy, 7274 struct wiphy_work *work) 7275 { 7276 struct ieee80211_sub_if_data *sdata = 7277 container_of(work, struct ieee80211_sub_if_data, 7278 u.mgd.monitor_work); 7279 7280 ieee80211_mgd_probe_ap(sdata, false); 7281 } 7282 7283 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata) 7284 { 7285 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 7286 __ieee80211_stop_poll(sdata); 7287 7288 /* let's probe the connection once */ 7289 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR)) 7290 wiphy_work_queue(sdata->local->hw.wiphy, 7291 &sdata->u.mgd.monitor_work); 7292 } 7293 } 7294 7295 #ifdef CONFIG_PM 7296 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata) 7297 { 7298 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 7299 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; 7300 7301 lockdep_assert_wiphy(sdata->local->hw.wiphy); 7302 7303 if (ifmgd->auth_data || ifmgd->assoc_data) { 7304 const u8 *ap_addr = ifmgd->auth_data ? 7305 ifmgd->auth_data->ap_addr : 7306 ifmgd->assoc_data->ap_addr; 7307 7308 /* 7309 * If we are trying to authenticate / associate while suspending, 7310 * cfg80211 won't know and won't actually abort those attempts, 7311 * thus we need to do that ourselves. 7312 */ 7313 ieee80211_send_deauth_disassoc(sdata, ap_addr, ap_addr, 7314 IEEE80211_STYPE_DEAUTH, 7315 WLAN_REASON_DEAUTH_LEAVING, 7316 false, frame_buf); 7317 if (ifmgd->assoc_data) 7318 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON); 7319 if (ifmgd->auth_data) 7320 ieee80211_destroy_auth_data(sdata, false); 7321 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf, 7322 IEEE80211_DEAUTH_FRAME_LEN, 7323 false); 7324 } 7325 7326 /* This is a bit of a hack - we should find a better and more generic 7327 * solution to this. Normally when suspending, cfg80211 will in fact 7328 * deauthenticate. However, it doesn't (and cannot) stop an ongoing 7329 * auth (not so important) or assoc (this is the problem) process. 7330 * 7331 * As a consequence, it can happen that we are in the process of both 7332 * associating and suspending, and receive an association response 7333 * after cfg80211 has checked if it needs to disconnect, but before 7334 * we actually set the flag to drop incoming frames. This will then 7335 * cause the workqueue flush to process the association response in 7336 * the suspend, resulting in a successful association just before it 7337 * tries to remove the interface from the driver, which now though 7338 * has a channel context assigned ... this results in issues. 7339 * 7340 * To work around this (for now) simply deauth here again if we're 7341 * now connected. 7342 */ 7343 if (ifmgd->associated && !sdata->local->wowlan) { 7344 u8 bssid[ETH_ALEN]; 7345 struct cfg80211_deauth_request req = { 7346 .reason_code = WLAN_REASON_DEAUTH_LEAVING, 7347 .bssid = bssid, 7348 }; 7349 7350 memcpy(bssid, sdata->vif.cfg.ap_addr, ETH_ALEN); 7351 ieee80211_mgd_deauth(sdata, &req); 7352 } 7353 } 7354 #endif 7355 7356 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata) 7357 { 7358 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 7359 7360 lockdep_assert_wiphy(sdata->local->hw.wiphy); 7361 7362 if (!ifmgd->associated) 7363 return; 7364 7365 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) { 7366 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME; 7367 mlme_dbg(sdata, "driver requested disconnect after resume\n"); 7368 ieee80211_sta_connection_lost(sdata, 7369 WLAN_REASON_UNSPECIFIED, 7370 true); 7371 return; 7372 } 7373 7374 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_HW_RESTART) { 7375 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_HW_RESTART; 7376 mlme_dbg(sdata, "driver requested disconnect after hardware restart\n"); 7377 ieee80211_sta_connection_lost(sdata, 7378 WLAN_REASON_UNSPECIFIED, 7379 true); 7380 return; 7381 } 7382 } 7383 7384 static void ieee80211_request_smps_mgd_work(struct wiphy *wiphy, 7385 struct wiphy_work *work) 7386 { 7387 struct ieee80211_link_data *link = 7388 container_of(work, struct ieee80211_link_data, 7389 u.mgd.request_smps_work); 7390 7391 __ieee80211_request_smps_mgd(link->sdata, link, 7392 link->u.mgd.driver_smps_mode); 7393 } 7394 7395 /* interface setup */ 7396 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata) 7397 { 7398 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 7399 7400 wiphy_work_init(&ifmgd->monitor_work, ieee80211_sta_monitor_work); 7401 wiphy_work_init(&ifmgd->beacon_connection_loss_work, 7402 ieee80211_beacon_connection_loss_work); 7403 wiphy_work_init(&ifmgd->csa_connection_drop_work, 7404 ieee80211_csa_connection_drop_work); 7405 wiphy_delayed_work_init(&ifmgd->tdls_peer_del_work, 7406 ieee80211_tdls_peer_del_work); 7407 wiphy_delayed_work_init(&ifmgd->ml_reconf_work, 7408 ieee80211_ml_reconf_work); 7409 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0); 7410 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0); 7411 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0); 7412 wiphy_delayed_work_init(&ifmgd->tx_tspec_wk, 7413 ieee80211_sta_handle_tspec_ac_params_wk); 7414 wiphy_delayed_work_init(&ifmgd->ttlm_work, 7415 ieee80211_tid_to_link_map_work); 7416 wiphy_delayed_work_init(&ifmgd->neg_ttlm_timeout_work, 7417 ieee80211_neg_ttlm_timeout_work); 7418 7419 ifmgd->flags = 0; 7420 ifmgd->powersave = sdata->wdev.ps; 7421 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues; 7422 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len; 7423 /* Setup TDLS data */ 7424 spin_lock_init(&ifmgd->teardown_lock); 7425 ifmgd->teardown_skb = NULL; 7426 ifmgd->orig_teardown_skb = NULL; 7427 ifmgd->mcast_seq_last = IEEE80211_SN_MODULO; 7428 } 7429 7430 static void ieee80211_recalc_smps_work(struct wiphy *wiphy, 7431 struct wiphy_work *work) 7432 { 7433 struct ieee80211_link_data *link = 7434 container_of(work, struct ieee80211_link_data, 7435 u.mgd.recalc_smps); 7436 7437 ieee80211_recalc_smps(link->sdata, link); 7438 } 7439 7440 void ieee80211_mgd_setup_link(struct ieee80211_link_data *link) 7441 { 7442 struct ieee80211_sub_if_data *sdata = link->sdata; 7443 struct ieee80211_local *local = sdata->local; 7444 unsigned int link_id = link->link_id; 7445 7446 link->u.mgd.p2p_noa_index = -1; 7447 link->conf->bssid = link->u.mgd.bssid; 7448 link->smps_mode = IEEE80211_SMPS_OFF; 7449 7450 wiphy_work_init(&link->u.mgd.request_smps_work, 7451 ieee80211_request_smps_mgd_work); 7452 wiphy_work_init(&link->u.mgd.recalc_smps, 7453 ieee80211_recalc_smps_work); 7454 if (local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS) 7455 link->u.mgd.req_smps = IEEE80211_SMPS_AUTOMATIC; 7456 else 7457 link->u.mgd.req_smps = IEEE80211_SMPS_OFF; 7458 7459 wiphy_delayed_work_init(&link->u.mgd.chswitch_work, 7460 ieee80211_chswitch_work); 7461 7462 if (sdata->u.mgd.assoc_data) 7463 ether_addr_copy(link->conf->addr, 7464 sdata->u.mgd.assoc_data->link[link_id].addr); 7465 else if (!is_valid_ether_addr(link->conf->addr)) 7466 eth_random_addr(link->conf->addr); 7467 } 7468 7469 /* scan finished notification */ 7470 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local) 7471 { 7472 struct ieee80211_sub_if_data *sdata; 7473 7474 /* Restart STA timers */ 7475 rcu_read_lock(); 7476 list_for_each_entry_rcu(sdata, &local->interfaces, list) { 7477 if (ieee80211_sdata_running(sdata)) 7478 ieee80211_restart_sta_timer(sdata); 7479 } 7480 rcu_read_unlock(); 7481 } 7482 7483 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata, 7484 struct cfg80211_bss *cbss, s8 link_id, 7485 const u8 *ap_mld_addr, bool assoc, 7486 struct ieee80211_conn_settings *conn, 7487 bool override) 7488 { 7489 struct ieee80211_local *local = sdata->local; 7490 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 7491 struct ieee80211_bss *bss = (void *)cbss->priv; 7492 struct sta_info *new_sta = NULL; 7493 struct ieee80211_link_data *link; 7494 bool have_sta = false; 7495 bool mlo; 7496 int err; 7497 7498 if (link_id >= 0) { 7499 mlo = true; 7500 if (WARN_ON(!ap_mld_addr)) 7501 return -EINVAL; 7502 err = ieee80211_vif_set_links(sdata, BIT(link_id), 0); 7503 } else { 7504 if (WARN_ON(ap_mld_addr)) 7505 return -EINVAL; 7506 ap_mld_addr = cbss->bssid; 7507 err = ieee80211_vif_set_links(sdata, 0, 0); 7508 link_id = 0; 7509 mlo = false; 7510 } 7511 7512 if (err) 7513 return err; 7514 7515 link = sdata_dereference(sdata->link[link_id], sdata); 7516 if (WARN_ON(!link)) { 7517 err = -ENOLINK; 7518 goto out_err; 7519 } 7520 7521 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data)) { 7522 err = -EINVAL; 7523 goto out_err; 7524 } 7525 7526 /* If a reconfig is happening, bail out */ 7527 if (local->in_reconfig) { 7528 err = -EBUSY; 7529 goto out_err; 7530 } 7531 7532 if (assoc) { 7533 rcu_read_lock(); 7534 have_sta = sta_info_get(sdata, ap_mld_addr); 7535 rcu_read_unlock(); 7536 } 7537 7538 if (!have_sta) { 7539 if (mlo) 7540 new_sta = sta_info_alloc_with_link(sdata, ap_mld_addr, 7541 link_id, cbss->bssid, 7542 GFP_KERNEL); 7543 else 7544 new_sta = sta_info_alloc(sdata, ap_mld_addr, GFP_KERNEL); 7545 7546 if (!new_sta) { 7547 err = -ENOMEM; 7548 goto out_err; 7549 } 7550 7551 new_sta->sta.mlo = mlo; 7552 } 7553 7554 /* 7555 * Set up the information for the new channel before setting the 7556 * new channel. We can't - completely race-free - change the basic 7557 * rates bitmap and the channel (sband) that it refers to, but if 7558 * we set it up before we at least avoid calling into the driver's 7559 * bss_info_changed() method with invalid information (since we do 7560 * call that from changing the channel - only for IDLE and perhaps 7561 * some others, but ...). 7562 * 7563 * So to avoid that, just set up all the new information before the 7564 * channel, but tell the driver to apply it only afterwards, since 7565 * it might need the new channel for that. 7566 */ 7567 if (new_sta) { 7568 const struct cfg80211_bss_ies *ies; 7569 struct link_sta_info *link_sta; 7570 7571 rcu_read_lock(); 7572 link_sta = rcu_dereference(new_sta->link[link_id]); 7573 if (WARN_ON(!link_sta)) { 7574 rcu_read_unlock(); 7575 sta_info_free(local, new_sta); 7576 err = -EINVAL; 7577 goto out_err; 7578 } 7579 7580 err = ieee80211_mgd_setup_link_sta(link, new_sta, 7581 link_sta, cbss); 7582 if (err) { 7583 rcu_read_unlock(); 7584 sta_info_free(local, new_sta); 7585 goto out_err; 7586 } 7587 7588 memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN); 7589 7590 /* set timing information */ 7591 link->conf->beacon_int = cbss->beacon_interval; 7592 ies = rcu_dereference(cbss->beacon_ies); 7593 if (ies) { 7594 link->conf->sync_tsf = ies->tsf; 7595 link->conf->sync_device_ts = 7596 bss->device_ts_beacon; 7597 7598 ieee80211_get_dtim(ies, 7599 &link->conf->sync_dtim_count, 7600 NULL); 7601 } else if (!ieee80211_hw_check(&sdata->local->hw, 7602 TIMING_BEACON_ONLY)) { 7603 ies = rcu_dereference(cbss->proberesp_ies); 7604 /* must be non-NULL since beacon IEs were NULL */ 7605 link->conf->sync_tsf = ies->tsf; 7606 link->conf->sync_device_ts = 7607 bss->device_ts_presp; 7608 link->conf->sync_dtim_count = 0; 7609 } else { 7610 link->conf->sync_tsf = 0; 7611 link->conf->sync_device_ts = 0; 7612 link->conf->sync_dtim_count = 0; 7613 } 7614 rcu_read_unlock(); 7615 } 7616 7617 if (new_sta || override) { 7618 /* 7619 * Only set this if we're also going to calculate the AP 7620 * settings etc., otherwise this was set before in a 7621 * previous call. Note override is set to %true in assoc 7622 * if the settings were changed. 7623 */ 7624 link->u.mgd.conn = *conn; 7625 err = ieee80211_prep_channel(sdata, link, link->link_id, cbss, 7626 mlo, &link->u.mgd.conn); 7627 if (err) { 7628 if (new_sta) 7629 sta_info_free(local, new_sta); 7630 goto out_err; 7631 } 7632 /* pass out for use in assoc */ 7633 *conn = link->u.mgd.conn; 7634 } 7635 7636 if (new_sta) { 7637 /* 7638 * tell driver about BSSID, basic rates and timing 7639 * this was set up above, before setting the channel 7640 */ 7641 ieee80211_link_info_change_notify(sdata, link, 7642 BSS_CHANGED_BSSID | 7643 BSS_CHANGED_BASIC_RATES | 7644 BSS_CHANGED_BEACON_INT); 7645 7646 if (assoc) 7647 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH); 7648 7649 err = sta_info_insert(new_sta); 7650 new_sta = NULL; 7651 if (err) { 7652 sdata_info(sdata, 7653 "failed to insert STA entry for the AP (error %d)\n", 7654 err); 7655 goto out_err; 7656 } 7657 } else 7658 WARN_ON_ONCE(!ether_addr_equal(link->u.mgd.bssid, cbss->bssid)); 7659 7660 /* Cancel scan to ensure that nothing interferes with connection */ 7661 if (local->scanning) 7662 ieee80211_scan_cancel(local); 7663 7664 return 0; 7665 7666 out_err: 7667 ieee80211_link_release_channel(&sdata->deflink); 7668 ieee80211_vif_set_links(sdata, 0, 0); 7669 return err; 7670 } 7671 7672 static bool ieee80211_mgd_csa_present(struct ieee80211_sub_if_data *sdata, 7673 const struct cfg80211_bss_ies *ies, 7674 u8 cur_channel, bool ignore_ecsa) 7675 { 7676 const struct element *csa_elem, *ecsa_elem; 7677 struct ieee80211_channel_sw_ie *csa = NULL; 7678 struct ieee80211_ext_chansw_ie *ecsa = NULL; 7679 7680 if (!ies) 7681 return false; 7682 7683 csa_elem = cfg80211_find_elem(WLAN_EID_CHANNEL_SWITCH, 7684 ies->data, ies->len); 7685 if (csa_elem && csa_elem->datalen == sizeof(*csa)) 7686 csa = (void *)csa_elem->data; 7687 7688 ecsa_elem = cfg80211_find_elem(WLAN_EID_EXT_CHANSWITCH_ANN, 7689 ies->data, ies->len); 7690 if (ecsa_elem && ecsa_elem->datalen == sizeof(*ecsa)) 7691 ecsa = (void *)ecsa_elem->data; 7692 7693 if (csa && csa->count == 0) 7694 csa = NULL; 7695 if (csa && !csa->mode && csa->new_ch_num == cur_channel) 7696 csa = NULL; 7697 7698 if (ecsa && ecsa->count == 0) 7699 ecsa = NULL; 7700 if (ecsa && !ecsa->mode && ecsa->new_ch_num == cur_channel) 7701 ecsa = NULL; 7702 7703 if (ignore_ecsa && ecsa) { 7704 sdata_info(sdata, 7705 "Ignoring ECSA in probe response - was considered stuck!\n"); 7706 return csa; 7707 } 7708 7709 return csa || ecsa; 7710 } 7711 7712 static bool ieee80211_mgd_csa_in_process(struct ieee80211_sub_if_data *sdata, 7713 struct cfg80211_bss *bss) 7714 { 7715 u8 cur_channel; 7716 bool ret; 7717 7718 cur_channel = ieee80211_frequency_to_channel(bss->channel->center_freq); 7719 7720 rcu_read_lock(); 7721 if (ieee80211_mgd_csa_present(sdata, 7722 rcu_dereference(bss->beacon_ies), 7723 cur_channel, false)) { 7724 ret = true; 7725 goto out; 7726 } 7727 7728 if (ieee80211_mgd_csa_present(sdata, 7729 rcu_dereference(bss->proberesp_ies), 7730 cur_channel, bss->proberesp_ecsa_stuck)) { 7731 ret = true; 7732 goto out; 7733 } 7734 7735 ret = false; 7736 out: 7737 rcu_read_unlock(); 7738 return ret; 7739 } 7740 7741 /* config hooks */ 7742 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata, 7743 struct cfg80211_auth_request *req) 7744 { 7745 struct ieee80211_local *local = sdata->local; 7746 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 7747 struct ieee80211_mgd_auth_data *auth_data; 7748 struct ieee80211_conn_settings conn; 7749 struct ieee80211_link_data *link; 7750 struct ieee80211_supported_band *sband; 7751 struct ieee80211_bss *bss; 7752 u16 auth_alg; 7753 int err; 7754 bool cont_auth, wmm_used; 7755 7756 lockdep_assert_wiphy(sdata->local->hw.wiphy); 7757 7758 /* prepare auth data structure */ 7759 7760 switch (req->auth_type) { 7761 case NL80211_AUTHTYPE_OPEN_SYSTEM: 7762 auth_alg = WLAN_AUTH_OPEN; 7763 break; 7764 case NL80211_AUTHTYPE_SHARED_KEY: 7765 if (fips_enabled) 7766 return -EOPNOTSUPP; 7767 auth_alg = WLAN_AUTH_SHARED_KEY; 7768 break; 7769 case NL80211_AUTHTYPE_FT: 7770 auth_alg = WLAN_AUTH_FT; 7771 break; 7772 case NL80211_AUTHTYPE_NETWORK_EAP: 7773 auth_alg = WLAN_AUTH_LEAP; 7774 break; 7775 case NL80211_AUTHTYPE_SAE: 7776 auth_alg = WLAN_AUTH_SAE; 7777 break; 7778 case NL80211_AUTHTYPE_FILS_SK: 7779 auth_alg = WLAN_AUTH_FILS_SK; 7780 break; 7781 case NL80211_AUTHTYPE_FILS_SK_PFS: 7782 auth_alg = WLAN_AUTH_FILS_SK_PFS; 7783 break; 7784 case NL80211_AUTHTYPE_FILS_PK: 7785 auth_alg = WLAN_AUTH_FILS_PK; 7786 break; 7787 default: 7788 return -EOPNOTSUPP; 7789 } 7790 7791 if (ifmgd->assoc_data) 7792 return -EBUSY; 7793 7794 if (ieee80211_mgd_csa_in_process(sdata, req->bss)) { 7795 sdata_info(sdata, "AP is in CSA process, reject auth\n"); 7796 return -EINVAL; 7797 } 7798 7799 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len + 7800 req->ie_len, GFP_KERNEL); 7801 if (!auth_data) 7802 return -ENOMEM; 7803 7804 memcpy(auth_data->ap_addr, 7805 req->ap_mld_addr ?: req->bss->bssid, 7806 ETH_ALEN); 7807 auth_data->bss = req->bss; 7808 auth_data->link_id = req->link_id; 7809 7810 if (req->auth_data_len >= 4) { 7811 if (req->auth_type == NL80211_AUTHTYPE_SAE) { 7812 __le16 *pos = (__le16 *) req->auth_data; 7813 7814 auth_data->sae_trans = le16_to_cpu(pos[0]); 7815 auth_data->sae_status = le16_to_cpu(pos[1]); 7816 } 7817 memcpy(auth_data->data, req->auth_data + 4, 7818 req->auth_data_len - 4); 7819 auth_data->data_len += req->auth_data_len - 4; 7820 } 7821 7822 /* Check if continuing authentication or trying to authenticate with the 7823 * same BSS that we were in the process of authenticating with and avoid 7824 * removal and re-addition of the STA entry in 7825 * ieee80211_prep_connection(). 7826 */ 7827 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss && 7828 ifmgd->auth_data->link_id == req->link_id; 7829 7830 if (req->ie && req->ie_len) { 7831 memcpy(&auth_data->data[auth_data->data_len], 7832 req->ie, req->ie_len); 7833 auth_data->data_len += req->ie_len; 7834 } 7835 7836 if (req->key && req->key_len) { 7837 auth_data->key_len = req->key_len; 7838 auth_data->key_idx = req->key_idx; 7839 memcpy(auth_data->key, req->key, req->key_len); 7840 } 7841 7842 auth_data->algorithm = auth_alg; 7843 7844 /* try to authenticate/probe */ 7845 7846 if (ifmgd->auth_data) { 7847 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) { 7848 auth_data->peer_confirmed = 7849 ifmgd->auth_data->peer_confirmed; 7850 } 7851 ieee80211_destroy_auth_data(sdata, cont_auth); 7852 } 7853 7854 /* prep auth_data so we don't go into idle on disassoc */ 7855 ifmgd->auth_data = auth_data; 7856 7857 /* If this is continuation of an ongoing SAE authentication exchange 7858 * (i.e., request to send SAE Confirm) and the peer has already 7859 * confirmed, mark authentication completed since we are about to send 7860 * out SAE Confirm. 7861 */ 7862 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE && 7863 auth_data->peer_confirmed && auth_data->sae_trans == 2) 7864 ieee80211_mark_sta_auth(sdata); 7865 7866 if (ifmgd->associated) { 7867 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; 7868 7869 sdata_info(sdata, 7870 "disconnect from AP %pM for new auth to %pM\n", 7871 sdata->vif.cfg.ap_addr, auth_data->ap_addr); 7872 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, 7873 WLAN_REASON_UNSPECIFIED, 7874 false, frame_buf); 7875 7876 ieee80211_report_disconnect(sdata, frame_buf, 7877 sizeof(frame_buf), true, 7878 WLAN_REASON_UNSPECIFIED, 7879 false); 7880 } 7881 7882 /* needed for transmitting the auth frame(s) properly */ 7883 memcpy(sdata->vif.cfg.ap_addr, auth_data->ap_addr, ETH_ALEN); 7884 7885 bss = (void *)req->bss->priv; 7886 wmm_used = bss->wmm_used && (local->hw.queues >= IEEE80211_NUM_ACS); 7887 7888 sband = local->hw.wiphy->bands[req->bss->channel->band]; 7889 7890 ieee80211_determine_our_sta_mode_auth(sdata, sband, req, wmm_used, 7891 &conn); 7892 7893 err = ieee80211_prep_connection(sdata, req->bss, req->link_id, 7894 req->ap_mld_addr, cont_auth, 7895 &conn, false); 7896 if (err) 7897 goto err_clear; 7898 7899 if (req->link_id >= 0) 7900 link = sdata_dereference(sdata->link[req->link_id], sdata); 7901 else 7902 link = &sdata->deflink; 7903 7904 if (WARN_ON(!link)) { 7905 err = -ENOLINK; 7906 goto err_clear; 7907 } 7908 7909 sdata_info(sdata, "authenticate with %pM (local address=%pM)\n", 7910 auth_data->ap_addr, link->conf->addr); 7911 7912 err = ieee80211_auth(sdata); 7913 if (err) { 7914 sta_info_destroy_addr(sdata, auth_data->ap_addr); 7915 goto err_clear; 7916 } 7917 7918 /* hold our own reference */ 7919 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss); 7920 return 0; 7921 7922 err_clear: 7923 if (!ieee80211_vif_is_mld(&sdata->vif)) { 7924 eth_zero_addr(sdata->deflink.u.mgd.bssid); 7925 ieee80211_link_info_change_notify(sdata, &sdata->deflink, 7926 BSS_CHANGED_BSSID); 7927 ieee80211_link_release_channel(&sdata->deflink); 7928 } 7929 ifmgd->auth_data = NULL; 7930 kfree(auth_data); 7931 return err; 7932 } 7933 7934 static void 7935 ieee80211_setup_assoc_link(struct ieee80211_sub_if_data *sdata, 7936 struct ieee80211_mgd_assoc_data *assoc_data, 7937 struct cfg80211_assoc_request *req, 7938 struct ieee80211_conn_settings *conn, 7939 unsigned int link_id) 7940 { 7941 struct ieee80211_local *local = sdata->local; 7942 const struct cfg80211_bss_ies *bss_ies; 7943 struct ieee80211_supported_band *sband; 7944 struct ieee80211_link_data *link; 7945 struct cfg80211_bss *cbss; 7946 struct ieee80211_bss *bss; 7947 7948 cbss = assoc_data->link[link_id].bss; 7949 if (WARN_ON(!cbss)) 7950 return; 7951 7952 bss = (void *)cbss->priv; 7953 7954 sband = local->hw.wiphy->bands[cbss->channel->band]; 7955 if (WARN_ON(!sband)) 7956 return; 7957 7958 link = sdata_dereference(sdata->link[link_id], sdata); 7959 if (WARN_ON(!link)) 7960 return; 7961 7962 /* for MLO connections assume advertising all rates is OK */ 7963 if (!req->ap_mld_addr) { 7964 assoc_data->supp_rates = bss->supp_rates; 7965 assoc_data->supp_rates_len = bss->supp_rates_len; 7966 } 7967 7968 /* copy and link elems for the STA profile */ 7969 if (req->links[link_id].elems_len) { 7970 memcpy(assoc_data->ie_pos, req->links[link_id].elems, 7971 req->links[link_id].elems_len); 7972 assoc_data->link[link_id].elems = assoc_data->ie_pos; 7973 assoc_data->link[link_id].elems_len = req->links[link_id].elems_len; 7974 assoc_data->ie_pos += req->links[link_id].elems_len; 7975 } 7976 7977 link->u.mgd.beacon_crc_valid = false; 7978 link->u.mgd.dtim_period = 0; 7979 link->u.mgd.have_beacon = false; 7980 7981 /* override HT configuration only if the AP and we support it */ 7982 if (conn->mode >= IEEE80211_CONN_MODE_HT) { 7983 struct ieee80211_sta_ht_cap sta_ht_cap; 7984 7985 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap)); 7986 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap); 7987 } 7988 7989 rcu_read_lock(); 7990 bss_ies = rcu_dereference(cbss->beacon_ies); 7991 if (bss_ies) { 7992 u8 dtim_count = 0; 7993 7994 ieee80211_get_dtim(bss_ies, &dtim_count, 7995 &link->u.mgd.dtim_period); 7996 7997 sdata->deflink.u.mgd.have_beacon = true; 7998 7999 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) { 8000 link->conf->sync_tsf = bss_ies->tsf; 8001 link->conf->sync_device_ts = bss->device_ts_beacon; 8002 link->conf->sync_dtim_count = dtim_count; 8003 } 8004 } else { 8005 bss_ies = rcu_dereference(cbss->ies); 8006 } 8007 8008 if (bss_ies) { 8009 const struct element *elem; 8010 8011 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION, 8012 bss_ies->data, bss_ies->len); 8013 if (elem && elem->datalen >= 3) 8014 link->conf->profile_periodicity = elem->data[2]; 8015 else 8016 link->conf->profile_periodicity = 0; 8017 8018 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, 8019 bss_ies->data, bss_ies->len); 8020 if (elem && elem->datalen >= 11 && 8021 (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT)) 8022 link->conf->ema_ap = true; 8023 else 8024 link->conf->ema_ap = false; 8025 } 8026 rcu_read_unlock(); 8027 8028 if (bss->corrupt_data) { 8029 char *corrupt_type = "data"; 8030 8031 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) { 8032 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP) 8033 corrupt_type = "beacon and probe response"; 8034 else 8035 corrupt_type = "beacon"; 8036 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP) { 8037 corrupt_type = "probe response"; 8038 } 8039 sdata_info(sdata, "associating to AP %pM with corrupt %s\n", 8040 cbss->bssid, corrupt_type); 8041 } 8042 8043 if (link->u.mgd.req_smps == IEEE80211_SMPS_AUTOMATIC) { 8044 if (sdata->u.mgd.powersave) 8045 link->smps_mode = IEEE80211_SMPS_DYNAMIC; 8046 else 8047 link->smps_mode = IEEE80211_SMPS_OFF; 8048 } else { 8049 link->smps_mode = link->u.mgd.req_smps; 8050 } 8051 } 8052 8053 static int 8054 ieee80211_mgd_get_ap_ht_vht_capa(struct ieee80211_sub_if_data *sdata, 8055 struct ieee80211_mgd_assoc_data *assoc_data, 8056 int link_id) 8057 { 8058 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss; 8059 enum nl80211_band band = cbss->channel->band; 8060 struct ieee80211_supported_band *sband; 8061 const struct element *elem; 8062 int err; 8063 8064 /* neither HT nor VHT elements used on 6 GHz */ 8065 if (band == NL80211_BAND_6GHZ) 8066 return 0; 8067 8068 if (assoc_data->link[link_id].conn.mode < IEEE80211_CONN_MODE_HT) 8069 return 0; 8070 8071 rcu_read_lock(); 8072 elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_OPERATION); 8073 if (!elem || elem->datalen < sizeof(struct ieee80211_ht_operation)) { 8074 mlme_link_id_dbg(sdata, link_id, "no HT operation on BSS %pM\n", 8075 cbss->bssid); 8076 err = -EINVAL; 8077 goto out_rcu; 8078 } 8079 assoc_data->link[link_id].ap_ht_param = 8080 ((struct ieee80211_ht_operation *)(elem->data))->ht_param; 8081 rcu_read_unlock(); 8082 8083 if (assoc_data->link[link_id].conn.mode < IEEE80211_CONN_MODE_VHT) 8084 return 0; 8085 8086 /* some drivers want to support VHT on 2.4 GHz even */ 8087 sband = sdata->local->hw.wiphy->bands[band]; 8088 if (!sband->vht_cap.vht_supported) 8089 return 0; 8090 8091 rcu_read_lock(); 8092 elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY); 8093 /* but even then accept it not being present on the AP */ 8094 if (!elem && band == NL80211_BAND_2GHZ) { 8095 err = 0; 8096 goto out_rcu; 8097 } 8098 if (!elem || elem->datalen < sizeof(struct ieee80211_vht_cap)) { 8099 mlme_link_id_dbg(sdata, link_id, "no VHT capa on BSS %pM\n", 8100 cbss->bssid); 8101 err = -EINVAL; 8102 goto out_rcu; 8103 } 8104 memcpy(&assoc_data->link[link_id].ap_vht_cap, elem->data, 8105 sizeof(struct ieee80211_vht_cap)); 8106 rcu_read_unlock(); 8107 8108 return 0; 8109 out_rcu: 8110 rcu_read_unlock(); 8111 return err; 8112 } 8113 8114 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, 8115 struct cfg80211_assoc_request *req) 8116 { 8117 unsigned int assoc_link_id = req->link_id < 0 ? 0 : req->link_id; 8118 struct ieee80211_local *local = sdata->local; 8119 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 8120 struct ieee80211_mgd_assoc_data *assoc_data; 8121 const struct element *ssid_elem; 8122 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg; 8123 struct ieee80211_link_data *link; 8124 struct cfg80211_bss *cbss; 8125 bool override, uapsd_supported; 8126 bool match_auth; 8127 int i, err; 8128 size_t size = sizeof(*assoc_data) + req->ie_len; 8129 8130 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) 8131 size += req->links[i].elems_len; 8132 8133 /* FIXME: no support for 4-addr MLO yet */ 8134 if (sdata->u.mgd.use_4addr && req->link_id >= 0) 8135 return -EOPNOTSUPP; 8136 8137 assoc_data = kzalloc(size, GFP_KERNEL); 8138 if (!assoc_data) 8139 return -ENOMEM; 8140 8141 cbss = req->link_id < 0 ? req->bss : req->links[req->link_id].bss; 8142 8143 if (ieee80211_mgd_csa_in_process(sdata, cbss)) { 8144 sdata_info(sdata, "AP is in CSA process, reject assoc\n"); 8145 err = -EINVAL; 8146 goto err_free; 8147 } 8148 8149 rcu_read_lock(); 8150 ssid_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID); 8151 if (!ssid_elem || ssid_elem->datalen > sizeof(assoc_data->ssid)) { 8152 rcu_read_unlock(); 8153 err = -EINVAL; 8154 goto err_free; 8155 } 8156 8157 memcpy(assoc_data->ssid, ssid_elem->data, ssid_elem->datalen); 8158 assoc_data->ssid_len = ssid_elem->datalen; 8159 rcu_read_unlock(); 8160 8161 if (req->ap_mld_addr) 8162 memcpy(assoc_data->ap_addr, req->ap_mld_addr, ETH_ALEN); 8163 else 8164 memcpy(assoc_data->ap_addr, cbss->bssid, ETH_ALEN); 8165 8166 if (ifmgd->associated) { 8167 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; 8168 8169 sdata_info(sdata, 8170 "disconnect from AP %pM for new assoc to %pM\n", 8171 sdata->vif.cfg.ap_addr, assoc_data->ap_addr); 8172 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, 8173 WLAN_REASON_UNSPECIFIED, 8174 false, frame_buf); 8175 8176 ieee80211_report_disconnect(sdata, frame_buf, 8177 sizeof(frame_buf), true, 8178 WLAN_REASON_UNSPECIFIED, 8179 false); 8180 } 8181 8182 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa)); 8183 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask, 8184 sizeof(ifmgd->ht_capa_mask)); 8185 8186 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa)); 8187 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask, 8188 sizeof(ifmgd->vht_capa_mask)); 8189 8190 memcpy(&ifmgd->s1g_capa, &req->s1g_capa, sizeof(ifmgd->s1g_capa)); 8191 memcpy(&ifmgd->s1g_capa_mask, &req->s1g_capa_mask, 8192 sizeof(ifmgd->s1g_capa_mask)); 8193 8194 /* keep some setup (AP STA, channel, ...) if matching */ 8195 match_auth = ifmgd->auth_data && 8196 ether_addr_equal(ifmgd->auth_data->ap_addr, 8197 assoc_data->ap_addr) && 8198 ifmgd->auth_data->link_id == req->link_id; 8199 8200 if (req->ap_mld_addr) { 8201 uapsd_supported = true; 8202 8203 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) { 8204 struct ieee80211_supported_band *sband; 8205 struct cfg80211_bss *link_cbss = req->links[i].bss; 8206 struct ieee80211_bss *bss; 8207 8208 if (!link_cbss) 8209 continue; 8210 8211 bss = (void *)link_cbss->priv; 8212 8213 if (!bss->wmm_used) { 8214 err = -EINVAL; 8215 goto err_free; 8216 } 8217 8218 if (req->flags & (ASSOC_REQ_DISABLE_HT | 8219 ASSOC_REQ_DISABLE_VHT | 8220 ASSOC_REQ_DISABLE_HE | 8221 ASSOC_REQ_DISABLE_EHT)) { 8222 err = -EINVAL; 8223 goto err_free; 8224 } 8225 8226 if (link_cbss->channel->band == NL80211_BAND_S1GHZ) { 8227 err = -EINVAL; 8228 goto err_free; 8229 } 8230 8231 link = sdata_dereference(sdata->link[i], sdata); 8232 if (link) 8233 ether_addr_copy(assoc_data->link[i].addr, 8234 link->conf->addr); 8235 else 8236 eth_random_addr(assoc_data->link[i].addr); 8237 sband = local->hw.wiphy->bands[link_cbss->channel->band]; 8238 8239 if (match_auth && i == assoc_link_id && link) 8240 assoc_data->link[i].conn = link->u.mgd.conn; 8241 else 8242 assoc_data->link[i].conn = 8243 ieee80211_conn_settings_unlimited; 8244 ieee80211_determine_our_sta_mode_assoc(sdata, sband, 8245 req, true, i, 8246 &assoc_data->link[i].conn); 8247 assoc_data->link[i].bss = link_cbss; 8248 assoc_data->link[i].disabled = req->links[i].disabled; 8249 8250 if (!bss->uapsd_supported) 8251 uapsd_supported = false; 8252 8253 if (assoc_data->link[i].conn.mode < IEEE80211_CONN_MODE_EHT) { 8254 err = -EINVAL; 8255 req->links[i].error = err; 8256 goto err_free; 8257 } 8258 8259 err = ieee80211_mgd_get_ap_ht_vht_capa(sdata, 8260 assoc_data, i); 8261 if (err) { 8262 err = -EINVAL; 8263 req->links[i].error = err; 8264 goto err_free; 8265 } 8266 } 8267 8268 assoc_data->wmm = true; 8269 } else { 8270 struct ieee80211_supported_band *sband; 8271 struct ieee80211_bss *bss = (void *)cbss->priv; 8272 8273 memcpy(assoc_data->link[0].addr, sdata->vif.addr, ETH_ALEN); 8274 assoc_data->s1g = cbss->channel->band == NL80211_BAND_S1GHZ; 8275 8276 assoc_data->wmm = bss->wmm_used && 8277 (local->hw.queues >= IEEE80211_NUM_ACS); 8278 8279 if (cbss->channel->band == NL80211_BAND_6GHZ && 8280 req->flags & (ASSOC_REQ_DISABLE_HT | 8281 ASSOC_REQ_DISABLE_VHT | 8282 ASSOC_REQ_DISABLE_HE)) { 8283 err = -EINVAL; 8284 goto err_free; 8285 } 8286 8287 sband = local->hw.wiphy->bands[cbss->channel->band]; 8288 8289 assoc_data->link[0].bss = cbss; 8290 8291 if (match_auth) 8292 assoc_data->link[0].conn = sdata->deflink.u.mgd.conn; 8293 else 8294 assoc_data->link[0].conn = 8295 ieee80211_conn_settings_unlimited; 8296 ieee80211_determine_our_sta_mode_assoc(sdata, sband, req, 8297 assoc_data->wmm, 0, 8298 &assoc_data->link[0].conn); 8299 8300 uapsd_supported = bss->uapsd_supported; 8301 8302 err = ieee80211_mgd_get_ap_ht_vht_capa(sdata, assoc_data, 0); 8303 if (err) 8304 goto err_free; 8305 } 8306 8307 assoc_data->spp_amsdu = req->flags & ASSOC_REQ_SPP_AMSDU; 8308 8309 if (ifmgd->auth_data && !ifmgd->auth_data->done) { 8310 err = -EBUSY; 8311 goto err_free; 8312 } 8313 8314 if (ifmgd->assoc_data) { 8315 err = -EBUSY; 8316 goto err_free; 8317 } 8318 8319 /* Cleanup is delayed if auth_data matches */ 8320 if (ifmgd->auth_data && !match_auth) 8321 ieee80211_destroy_auth_data(sdata, false); 8322 8323 if (req->ie && req->ie_len) { 8324 memcpy(assoc_data->ie, req->ie, req->ie_len); 8325 assoc_data->ie_len = req->ie_len; 8326 assoc_data->ie_pos = assoc_data->ie + assoc_data->ie_len; 8327 } else { 8328 assoc_data->ie_pos = assoc_data->ie; 8329 } 8330 8331 if (req->fils_kek) { 8332 /* should already be checked in cfg80211 - so warn */ 8333 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) { 8334 err = -EINVAL; 8335 goto err_free; 8336 } 8337 memcpy(assoc_data->fils_kek, req->fils_kek, 8338 req->fils_kek_len); 8339 assoc_data->fils_kek_len = req->fils_kek_len; 8340 } 8341 8342 if (req->fils_nonces) 8343 memcpy(assoc_data->fils_nonces, req->fils_nonces, 8344 2 * FILS_NONCE_LEN); 8345 8346 /* default timeout */ 8347 assoc_data->timeout = jiffies; 8348 assoc_data->timeout_started = true; 8349 8350 assoc_data->assoc_link_id = assoc_link_id; 8351 8352 if (req->ap_mld_addr) { 8353 /* if there was no authentication, set up the link */ 8354 err = ieee80211_vif_set_links(sdata, BIT(assoc_link_id), 0); 8355 if (err) 8356 goto err_clear; 8357 } 8358 8359 link = sdata_dereference(sdata->link[assoc_link_id], sdata); 8360 if (WARN_ON(!link)) { 8361 err = -EINVAL; 8362 goto err_clear; 8363 } 8364 8365 override = link->u.mgd.conn.mode != 8366 assoc_data->link[assoc_link_id].conn.mode || 8367 link->u.mgd.conn.bw_limit != 8368 assoc_data->link[assoc_link_id].conn.bw_limit; 8369 link->u.mgd.conn = assoc_data->link[assoc_link_id].conn; 8370 8371 ieee80211_setup_assoc_link(sdata, assoc_data, req, &link->u.mgd.conn, 8372 assoc_link_id); 8373 8374 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) && 8375 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK), 8376 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n")) 8377 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 8378 8379 if (assoc_data->wmm && uapsd_supported && 8380 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) { 8381 assoc_data->uapsd = true; 8382 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED; 8383 } else { 8384 assoc_data->uapsd = false; 8385 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED; 8386 } 8387 8388 if (req->prev_bssid) 8389 memcpy(assoc_data->prev_ap_addr, req->prev_bssid, ETH_ALEN); 8390 8391 if (req->use_mfp) { 8392 ifmgd->mfp = IEEE80211_MFP_REQUIRED; 8393 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED; 8394 } else { 8395 ifmgd->mfp = IEEE80211_MFP_DISABLED; 8396 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED; 8397 } 8398 8399 if (req->flags & ASSOC_REQ_USE_RRM) 8400 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM; 8401 else 8402 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM; 8403 8404 if (req->crypto.control_port) 8405 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT; 8406 else 8407 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT; 8408 8409 sdata->control_port_protocol = req->crypto.control_port_ethertype; 8410 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt; 8411 sdata->control_port_over_nl80211 = 8412 req->crypto.control_port_over_nl80211; 8413 sdata->control_port_no_preauth = req->crypto.control_port_no_preauth; 8414 8415 /* kick off associate process */ 8416 ifmgd->assoc_data = assoc_data; 8417 8418 for (i = 0; i < ARRAY_SIZE(assoc_data->link); i++) { 8419 if (!assoc_data->link[i].bss) 8420 continue; 8421 if (i == assoc_data->assoc_link_id) 8422 continue; 8423 /* only calculate the mode, hence link == NULL */ 8424 err = ieee80211_prep_channel(sdata, NULL, i, 8425 assoc_data->link[i].bss, true, 8426 &assoc_data->link[i].conn); 8427 if (err) { 8428 req->links[i].error = err; 8429 goto err_clear; 8430 } 8431 } 8432 8433 memcpy(vif_cfg->ssid, assoc_data->ssid, assoc_data->ssid_len); 8434 vif_cfg->ssid_len = assoc_data->ssid_len; 8435 8436 /* needed for transmitting the assoc frames properly */ 8437 memcpy(sdata->vif.cfg.ap_addr, assoc_data->ap_addr, ETH_ALEN); 8438 8439 err = ieee80211_prep_connection(sdata, cbss, req->link_id, 8440 req->ap_mld_addr, true, 8441 &assoc_data->link[assoc_link_id].conn, 8442 override); 8443 if (err) 8444 goto err_clear; 8445 8446 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC)) { 8447 const struct cfg80211_bss_ies *beacon_ies; 8448 8449 rcu_read_lock(); 8450 beacon_ies = rcu_dereference(req->bss->beacon_ies); 8451 if (!beacon_ies) { 8452 /* 8453 * Wait up to one beacon interval ... 8454 * should this be more if we miss one? 8455 */ 8456 sdata_info(sdata, "waiting for beacon from %pM\n", 8457 link->u.mgd.bssid); 8458 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval); 8459 assoc_data->timeout_started = true; 8460 assoc_data->need_beacon = true; 8461 } 8462 rcu_read_unlock(); 8463 } 8464 8465 run_again(sdata, assoc_data->timeout); 8466 8467 /* We are associating, clean up auth_data */ 8468 if (ifmgd->auth_data) 8469 ieee80211_destroy_auth_data(sdata, true); 8470 8471 return 0; 8472 err_clear: 8473 if (!ifmgd->auth_data) { 8474 eth_zero_addr(sdata->deflink.u.mgd.bssid); 8475 ieee80211_link_info_change_notify(sdata, &sdata->deflink, 8476 BSS_CHANGED_BSSID); 8477 } 8478 ifmgd->assoc_data = NULL; 8479 err_free: 8480 kfree(assoc_data); 8481 return err; 8482 } 8483 8484 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata, 8485 struct cfg80211_deauth_request *req) 8486 { 8487 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 8488 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; 8489 bool tx = !req->local_state_change; 8490 struct ieee80211_prep_tx_info info = { 8491 .subtype = IEEE80211_STYPE_DEAUTH, 8492 }; 8493 8494 if (ifmgd->auth_data && 8495 ether_addr_equal(ifmgd->auth_data->ap_addr, req->bssid)) { 8496 sdata_info(sdata, 8497 "aborting authentication with %pM by local choice (Reason: %u=%s)\n", 8498 req->bssid, req->reason_code, 8499 ieee80211_get_reason_code_string(req->reason_code)); 8500 8501 info.link_id = ifmgd->auth_data->link_id; 8502 drv_mgd_prepare_tx(sdata->local, sdata, &info); 8503 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid, 8504 IEEE80211_STYPE_DEAUTH, 8505 req->reason_code, tx, 8506 frame_buf); 8507 ieee80211_destroy_auth_data(sdata, false); 8508 ieee80211_report_disconnect(sdata, frame_buf, 8509 sizeof(frame_buf), true, 8510 req->reason_code, false); 8511 drv_mgd_complete_tx(sdata->local, sdata, &info); 8512 return 0; 8513 } 8514 8515 if (ifmgd->assoc_data && 8516 ether_addr_equal(ifmgd->assoc_data->ap_addr, req->bssid)) { 8517 sdata_info(sdata, 8518 "aborting association with %pM by local choice (Reason: %u=%s)\n", 8519 req->bssid, req->reason_code, 8520 ieee80211_get_reason_code_string(req->reason_code)); 8521 8522 info.link_id = ifmgd->assoc_data->assoc_link_id; 8523 drv_mgd_prepare_tx(sdata->local, sdata, &info); 8524 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid, 8525 IEEE80211_STYPE_DEAUTH, 8526 req->reason_code, tx, 8527 frame_buf); 8528 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON); 8529 ieee80211_report_disconnect(sdata, frame_buf, 8530 sizeof(frame_buf), true, 8531 req->reason_code, false); 8532 drv_mgd_complete_tx(sdata->local, sdata, &info); 8533 return 0; 8534 } 8535 8536 if (ifmgd->associated && 8537 ether_addr_equal(sdata->vif.cfg.ap_addr, req->bssid)) { 8538 sdata_info(sdata, 8539 "deauthenticating from %pM by local choice (Reason: %u=%s)\n", 8540 req->bssid, req->reason_code, 8541 ieee80211_get_reason_code_string(req->reason_code)); 8542 8543 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, 8544 req->reason_code, tx, frame_buf); 8545 ieee80211_report_disconnect(sdata, frame_buf, 8546 sizeof(frame_buf), true, 8547 req->reason_code, false); 8548 drv_mgd_complete_tx(sdata->local, sdata, &info); 8549 return 0; 8550 } 8551 8552 return -ENOTCONN; 8553 } 8554 8555 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata, 8556 struct cfg80211_disassoc_request *req) 8557 { 8558 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; 8559 8560 if (!sdata->u.mgd.associated || 8561 memcmp(sdata->vif.cfg.ap_addr, req->ap_addr, ETH_ALEN)) 8562 return -ENOTCONN; 8563 8564 sdata_info(sdata, 8565 "disassociating from %pM by local choice (Reason: %u=%s)\n", 8566 req->ap_addr, req->reason_code, 8567 ieee80211_get_reason_code_string(req->reason_code)); 8568 8569 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC, 8570 req->reason_code, !req->local_state_change, 8571 frame_buf); 8572 8573 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true, 8574 req->reason_code, false); 8575 8576 return 0; 8577 } 8578 8579 void ieee80211_mgd_stop_link(struct ieee80211_link_data *link) 8580 { 8581 wiphy_work_cancel(link->sdata->local->hw.wiphy, 8582 &link->u.mgd.request_smps_work); 8583 wiphy_work_cancel(link->sdata->local->hw.wiphy, 8584 &link->u.mgd.recalc_smps); 8585 wiphy_delayed_work_cancel(link->sdata->local->hw.wiphy, 8586 &link->u.mgd.chswitch_work); 8587 } 8588 8589 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata) 8590 { 8591 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 8592 8593 /* 8594 * Make sure some work items will not run after this, 8595 * they will not do anything but might not have been 8596 * cancelled when disconnecting. 8597 */ 8598 wiphy_work_cancel(sdata->local->hw.wiphy, 8599 &ifmgd->monitor_work); 8600 wiphy_work_cancel(sdata->local->hw.wiphy, 8601 &ifmgd->beacon_connection_loss_work); 8602 wiphy_work_cancel(sdata->local->hw.wiphy, 8603 &ifmgd->csa_connection_drop_work); 8604 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, 8605 &ifmgd->tdls_peer_del_work); 8606 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, 8607 &ifmgd->ml_reconf_work); 8608 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, &ifmgd->ttlm_work); 8609 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, 8610 &ifmgd->neg_ttlm_timeout_work); 8611 8612 if (ifmgd->assoc_data) 8613 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT); 8614 if (ifmgd->auth_data) 8615 ieee80211_destroy_auth_data(sdata, false); 8616 spin_lock_bh(&ifmgd->teardown_lock); 8617 if (ifmgd->teardown_skb) { 8618 kfree_skb(ifmgd->teardown_skb); 8619 ifmgd->teardown_skb = NULL; 8620 ifmgd->orig_teardown_skb = NULL; 8621 } 8622 kfree(ifmgd->assoc_req_ies); 8623 ifmgd->assoc_req_ies = NULL; 8624 ifmgd->assoc_req_ies_len = 0; 8625 spin_unlock_bh(&ifmgd->teardown_lock); 8626 del_timer_sync(&ifmgd->timer); 8627 } 8628 8629 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif, 8630 enum nl80211_cqm_rssi_threshold_event rssi_event, 8631 s32 rssi_level, 8632 gfp_t gfp) 8633 { 8634 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 8635 8636 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level); 8637 8638 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp); 8639 } 8640 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify); 8641 8642 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp) 8643 { 8644 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 8645 8646 trace_api_cqm_beacon_loss_notify(sdata->local, sdata); 8647 8648 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp); 8649 } 8650 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify); 8651 8652 static void _ieee80211_enable_rssi_reports(struct ieee80211_sub_if_data *sdata, 8653 int rssi_min_thold, 8654 int rssi_max_thold) 8655 { 8656 trace_api_enable_rssi_reports(sdata, rssi_min_thold, rssi_max_thold); 8657 8658 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) 8659 return; 8660 8661 /* 8662 * Scale up threshold values before storing it, as the RSSI averaging 8663 * algorithm uses a scaled up value as well. Change this scaling 8664 * factor if the RSSI averaging algorithm changes. 8665 */ 8666 sdata->u.mgd.rssi_min_thold = rssi_min_thold*16; 8667 sdata->u.mgd.rssi_max_thold = rssi_max_thold*16; 8668 } 8669 8670 void ieee80211_enable_rssi_reports(struct ieee80211_vif *vif, 8671 int rssi_min_thold, 8672 int rssi_max_thold) 8673 { 8674 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 8675 8676 WARN_ON(rssi_min_thold == rssi_max_thold || 8677 rssi_min_thold > rssi_max_thold); 8678 8679 _ieee80211_enable_rssi_reports(sdata, rssi_min_thold, 8680 rssi_max_thold); 8681 } 8682 EXPORT_SYMBOL(ieee80211_enable_rssi_reports); 8683 8684 void ieee80211_disable_rssi_reports(struct ieee80211_vif *vif) 8685 { 8686 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 8687 8688 _ieee80211_enable_rssi_reports(sdata, 0, 0); 8689 } 8690 EXPORT_SYMBOL(ieee80211_disable_rssi_reports); 8691