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 - 2026 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 <linux/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 #include <kunit/static_stub.h> 35 36 #define IEEE80211_AUTH_TIMEOUT (HZ / 5) 37 #define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2) 38 #define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10) 39 #define IEEE80211_AUTH_TIMEOUT_SAE (HZ * 2) 40 #define IEEE80211_AUTH_MAX_TRIES 3 41 #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5) 42 #define IEEE80211_AUTH_WAIT_SAE_RETRY (HZ * 2) 43 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5) 44 #define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2) 45 #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10) 46 #define IEEE80211_ASSOC_MAX_TRIES 3 47 48 #define IEEE80211_ADV_TTLM_SAFETY_BUFFER_MS (100 * USEC_PER_MSEC) 49 #define IEEE80211_ADV_TTLM_ST_UNDERFLOW 0xff00 50 51 #define IEEE80211_NEG_TTLM_REQ_TIMEOUT (HZ / 5) 52 53 static int max_nullfunc_tries = 2; 54 module_param(max_nullfunc_tries, int, 0644); 55 MODULE_PARM_DESC(max_nullfunc_tries, 56 "Maximum nullfunc tx tries before disconnecting (reason 4)."); 57 58 static int max_probe_tries = 5; 59 module_param(max_probe_tries, int, 0644); 60 MODULE_PARM_DESC(max_probe_tries, 61 "Maximum probe tries before disconnecting (reason 4)."); 62 63 /* 64 * Beacon loss timeout is calculated as N frames times the 65 * advertised beacon interval. This may need to be somewhat 66 * higher than what hardware might detect to account for 67 * delays in the host processing frames. But since we also 68 * probe on beacon miss before declaring the connection lost 69 * default to what we want. 70 */ 71 static int beacon_loss_count = 7; 72 module_param(beacon_loss_count, int, 0644); 73 MODULE_PARM_DESC(beacon_loss_count, 74 "Number of beacon intervals before we decide beacon was lost."); 75 76 /* 77 * Time the connection can be idle before we probe 78 * it to see if we can still talk to the AP. 79 */ 80 #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ) 81 /* 82 * Time we wait for a probe response after sending 83 * a probe request because of beacon loss or for 84 * checking the connection still works. 85 */ 86 static int probe_wait_ms = 500; 87 module_param(probe_wait_ms, int, 0644); 88 MODULE_PARM_DESC(probe_wait_ms, 89 "Maximum time(ms) to wait for probe response" 90 " before disconnecting (reason 4)."); 91 92 /* 93 * How many Beacon frames need to have been used in average signal strength 94 * before starting to indicate signal change events. 95 */ 96 #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4 97 98 /* 99 * We can have multiple work items (and connection probing) 100 * scheduling this timer, but we need to take care to only 101 * reschedule it when it should fire _earlier_ than it was 102 * asked for before, or if it's not pending right now. This 103 * function ensures that. Note that it then is required to 104 * run this function for all timeouts after the first one 105 * has happened -- the work that runs from this timer will 106 * do that. 107 */ 108 static void run_again(struct ieee80211_sub_if_data *sdata, 109 unsigned long timeout) 110 { 111 lockdep_assert_wiphy(sdata->local->hw.wiphy); 112 113 if (!timer_pending(&sdata->u.mgd.timer) || 114 time_before(timeout, sdata->u.mgd.timer.expires)) 115 mod_timer(&sdata->u.mgd.timer, timeout); 116 } 117 118 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata) 119 { 120 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER) 121 return; 122 123 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR)) 124 return; 125 126 mod_timer(&sdata->u.mgd.bcn_mon_timer, 127 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout)); 128 } 129 130 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata) 131 { 132 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 133 134 if (unlikely(!ifmgd->associated)) 135 return; 136 137 if (ifmgd->probe_send_count) 138 ifmgd->probe_send_count = 0; 139 140 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR)) 141 return; 142 143 mod_timer(&ifmgd->conn_mon_timer, 144 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME)); 145 } 146 147 static int ecw2cw(int ecw) 148 { 149 return (1 << ecw) - 1; 150 } 151 152 static enum ieee80211_conn_mode 153 ieee80211_determine_ap_chan(struct ieee80211_sub_if_data *sdata, 154 struct ieee80211_channel *channel, 155 u32 vht_cap_info, 156 const struct ieee802_11_elems *elems, 157 bool ignore_ht_channel_mismatch, 158 const struct ieee80211_conn_settings *conn, 159 struct cfg80211_chan_def *chandef) 160 { 161 const struct ieee80211_ht_operation *ht_oper = elems->ht_operation; 162 const struct ieee80211_vht_operation *vht_oper = elems->vht_operation; 163 const struct ieee80211_he_operation *he_oper = elems->he_operation; 164 const struct ieee80211_eht_operation *eht_oper = elems->eht_operation; 165 const struct ieee80211_uhr_operation *uhr_oper = elems->uhr_operation; 166 struct ieee80211_supported_band *sband = 167 sdata->local->hw.wiphy->bands[channel->band]; 168 struct cfg80211_chan_def vht_chandef; 169 bool no_vht = false; 170 u32 ht_cfreq; 171 172 if (ieee80211_hw_check(&sdata->local->hw, STRICT)) 173 ignore_ht_channel_mismatch = false; 174 175 *chandef = (struct cfg80211_chan_def) { 176 .chan = channel, 177 .width = NL80211_CHAN_WIDTH_20_NOHT, 178 .center_freq1 = channel->center_freq, 179 .freq1_offset = channel->freq_offset, 180 }; 181 182 /* get special S1G case out of the way */ 183 if (sband->band == NL80211_BAND_S1GHZ) { 184 if (!ieee80211_chandef_s1g_oper(sdata->local, elems->s1g_oper, 185 chandef)) { 186 /* Fallback to default 1MHz */ 187 chandef->width = NL80211_CHAN_WIDTH_1; 188 chandef->s1g_primary_2mhz = false; 189 } 190 191 return IEEE80211_CONN_MODE_S1G; 192 } 193 194 /* get special 6 GHz case out of the way */ 195 if (sband->band == NL80211_BAND_6GHZ) { 196 enum ieee80211_conn_mode mode = IEEE80211_CONN_MODE_HIGHEST; 197 198 /* this is an error */ 199 if (conn->mode < IEEE80211_CONN_MODE_HE) 200 return IEEE80211_CONN_MODE_LEGACY; 201 202 if (!elems->he_6ghz_capa || !elems->he_cap) { 203 sdata_info(sdata, 204 "HE 6 GHz AP is missing HE/HE 6 GHz band capability\n"); 205 return IEEE80211_CONN_MODE_LEGACY; 206 } 207 208 if (!eht_oper || !elems->eht_cap) { 209 eht_oper = NULL; 210 mode = IEEE80211_CONN_MODE_HE; 211 } 212 213 if (!ieee80211_chandef_he_6ghz_oper(sdata->local, he_oper, 214 eht_oper, chandef)) { 215 sdata_info(sdata, "bad HE/EHT 6 GHz operation\n"); 216 return IEEE80211_CONN_MODE_LEGACY; 217 } 218 219 if (mode <= IEEE80211_CONN_MODE_EHT) 220 return mode; 221 goto check_uhr; 222 } 223 224 /* now we have the progression HT, VHT, ... */ 225 if (conn->mode < IEEE80211_CONN_MODE_HT) 226 return IEEE80211_CONN_MODE_LEGACY; 227 228 if (!ht_oper || !elems->ht_cap_elem) 229 return IEEE80211_CONN_MODE_LEGACY; 230 231 chandef->width = NL80211_CHAN_WIDTH_20; 232 233 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan, 234 channel->band); 235 /* check that channel matches the right operating channel */ 236 if (!ignore_ht_channel_mismatch && channel->center_freq != ht_cfreq) { 237 /* 238 * It's possible that some APs are confused here; 239 * Netgear WNDR3700 sometimes reports 4 higher than 240 * the actual channel in association responses, but 241 * since we look at probe response/beacon data here 242 * it should be OK. 243 */ 244 sdata_info(sdata, 245 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n", 246 channel->center_freq, ht_cfreq, 247 ht_oper->primary_chan, channel->band); 248 return IEEE80211_CONN_MODE_LEGACY; 249 } 250 251 ieee80211_chandef_ht_oper(ht_oper, chandef); 252 253 if (conn->mode < IEEE80211_CONN_MODE_VHT) 254 return IEEE80211_CONN_MODE_HT; 255 256 vht_chandef = *chandef; 257 258 /* 259 * having he_cap/he_oper parsed out implies we're at 260 * least operating as HE STA 261 */ 262 if (elems->he_cap && he_oper && 263 he_oper->he_oper_params & cpu_to_le32(IEEE80211_HE_OPERATION_VHT_OPER_INFO)) { 264 struct ieee80211_vht_operation he_oper_vht_cap; 265 266 /* 267 * Set only first 3 bytes (other 2 aren't used in 268 * ieee80211_chandef_vht_oper() anyway) 269 */ 270 memcpy(&he_oper_vht_cap, he_oper->optional, 3); 271 he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0); 272 273 if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_cap_info, 274 &he_oper_vht_cap, ht_oper, 275 &vht_chandef)) { 276 sdata_info(sdata, 277 "HE AP VHT information is invalid, disabling HE\n"); 278 /* this will cause us to re-parse as VHT STA */ 279 return IEEE80211_CONN_MODE_VHT; 280 } 281 } else if (!vht_oper || !elems->vht_cap_elem) { 282 if (sband->band == NL80211_BAND_5GHZ) 283 return IEEE80211_CONN_MODE_HT; 284 no_vht = true; 285 } else if (sband->band == NL80211_BAND_2GHZ) { 286 no_vht = true; 287 } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw, 288 vht_cap_info, 289 vht_oper, ht_oper, 290 &vht_chandef)) { 291 sdata_info(sdata, 292 "AP VHT information is invalid, disabling VHT\n"); 293 return IEEE80211_CONN_MODE_HT; 294 } 295 296 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) { 297 sdata_info(sdata, 298 "AP VHT information doesn't match HT, disabling VHT\n"); 299 return IEEE80211_CONN_MODE_HT; 300 } 301 302 *chandef = vht_chandef; 303 304 /* stick to current max mode if we or the AP don't have HE */ 305 if (conn->mode < IEEE80211_CONN_MODE_HE || 306 !elems->he_operation || !elems->he_cap) { 307 if (no_vht) 308 return IEEE80211_CONN_MODE_HT; 309 return IEEE80211_CONN_MODE_VHT; 310 } 311 312 /* stick to HE if we or the AP don't have EHT */ 313 if (conn->mode < IEEE80211_CONN_MODE_EHT || 314 !eht_oper || !elems->eht_cap) 315 return IEEE80211_CONN_MODE_HE; 316 317 /* 318 * handle the case that the EHT operation indicates that it holds EHT 319 * operation information (in case that the channel width differs from 320 * the channel width reported in HT/VHT/HE). 321 */ 322 if (eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT) { 323 struct cfg80211_chan_def eht_chandef = *chandef; 324 325 ieee80211_chandef_eht_oper((const void *)eht_oper->optional, 326 &eht_chandef); 327 328 eht_chandef.punctured = 329 ieee80211_eht_oper_dis_subchan_bitmap(eht_oper); 330 331 if (!cfg80211_chandef_valid(&eht_chandef)) { 332 sdata_info(sdata, 333 "AP EHT information is invalid, disabling EHT\n"); 334 return IEEE80211_CONN_MODE_HE; 335 } 336 337 if (!cfg80211_chandef_compatible(chandef, &eht_chandef)) { 338 sdata_info(sdata, 339 "AP EHT information doesn't match HT/VHT/HE, disabling EHT\n"); 340 return IEEE80211_CONN_MODE_HE; 341 } 342 343 *chandef = eht_chandef; 344 } 345 346 check_uhr: 347 if (conn->mode < IEEE80211_CONN_MODE_UHR || !uhr_oper) 348 return IEEE80211_CONN_MODE_EHT; 349 350 /* 351 * In beacons we don't have all the data - but we know the size was OK, 352 * so if the size is valid as a non-beacon case, we have more data and 353 * can validate the NPCA parameters. 354 */ 355 if (ieee80211_uhr_oper_size_ok((const void *)uhr_oper, 356 elems->uhr_operation_len, 357 false)) { 358 struct cfg80211_chan_def npca_chandef = *chandef; 359 const struct ieee80211_uhr_npca_info *npca; 360 const __le16 *dis_subch_bmap; 361 u16 punct = chandef->punctured, npca_punct; 362 363 npca = ieee80211_uhr_npca_info(uhr_oper); 364 if (npca) { 365 int width = cfg80211_chandef_get_width(chandef); 366 u8 offs = le32_get_bits(npca->params, 367 IEEE80211_UHR_NPCA_PARAMS_PRIMARY_CHAN_OFFS); 368 u32 cf1 = chandef->center_freq1; 369 bool pri_upper, npca_upper; 370 371 pri_upper = chandef->chan->center_freq > cf1; 372 npca_upper = 20 * offs >= width / 2; 373 374 if (20 * offs >= cfg80211_chandef_get_width(chandef) || 375 pri_upper == npca_upper) { 376 sdata_info(sdata, 377 "AP UHR NPCA primary channel invalid, disabling UHR\n"); 378 return IEEE80211_CONN_MODE_EHT; 379 } 380 } 381 382 dis_subch_bmap = ieee80211_uhr_npca_dis_subch_bitmap(uhr_oper); 383 384 if (dis_subch_bmap) { 385 npca_punct = get_unaligned_le16(dis_subch_bmap); 386 npca_chandef.punctured = npca_punct; 387 } 388 389 /* 390 * must be a valid puncturing pattern for this channel as 391 * well as puncturing all subchannels that are already in 392 * the disabled subchannel bitmap on the primary channel 393 */ 394 if (!cfg80211_chandef_valid(&npca_chandef) || 395 ((punct & npca_punct) != punct)) { 396 sdata_info(sdata, 397 "AP UHR NPCA disabled subchannel bitmap invalid, disabling UHR\n"); 398 return IEEE80211_CONN_MODE_EHT; 399 } 400 } 401 402 return IEEE80211_CONN_MODE_UHR; 403 } 404 405 static bool 406 ieee80211_verify_sta_ht_mcs_support(struct ieee80211_sub_if_data *sdata, 407 struct ieee80211_supported_band *sband, 408 const struct ieee80211_ht_operation *ht_op) 409 { 410 struct ieee80211_sta_ht_cap sta_ht_cap; 411 int i; 412 413 if (sband->band == NL80211_BAND_6GHZ) 414 return true; 415 416 if (!ht_op) 417 return false; 418 419 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap)); 420 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap); 421 422 /* 423 * P802.11REVme/D7.0 - 6.5.4.2.4 424 * ... 425 * If the MLME of an HT STA receives an MLME-JOIN.request primitive 426 * with the SelectedBSS parameter containing a Basic HT-MCS Set field 427 * in the HT Operation parameter that contains any unsupported MCSs, 428 * the MLME response in the resulting MLME-JOIN.confirm primitive shall 429 * contain a ResultCode parameter that is not set to the value SUCCESS. 430 * ... 431 */ 432 433 /* Simply check that all basic rates are in the STA RX mask */ 434 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { 435 if ((ht_op->basic_set[i] & sta_ht_cap.mcs.rx_mask[i]) != 436 ht_op->basic_set[i]) 437 return false; 438 } 439 440 return true; 441 } 442 443 static bool 444 ieee80211_verify_sta_vht_mcs_support(struct ieee80211_sub_if_data *sdata, 445 int link_id, 446 struct ieee80211_supported_band *sband, 447 const struct ieee80211_vht_operation *vht_op) 448 { 449 struct ieee80211_sta_vht_cap sta_vht_cap; 450 u16 ap_min_req_set, sta_rx_mcs_map, sta_tx_mcs_map; 451 int nss; 452 453 if (sband->band != NL80211_BAND_5GHZ) 454 return true; 455 456 if (!vht_op) 457 return false; 458 459 memcpy(&sta_vht_cap, &sband->vht_cap, sizeof(sta_vht_cap)); 460 ieee80211_apply_vhtcap_overrides(sdata, &sta_vht_cap); 461 462 ap_min_req_set = le16_to_cpu(vht_op->basic_mcs_set); 463 sta_rx_mcs_map = le16_to_cpu(sta_vht_cap.vht_mcs.rx_mcs_map); 464 sta_tx_mcs_map = le16_to_cpu(sta_vht_cap.vht_mcs.tx_mcs_map); 465 466 /* 467 * Many APs are incorrectly advertising an all-zero value here, 468 * which really means MCS 0-7 are required for 1-8 streams, but 469 * they don't really mean it that way. 470 * Some other APs are incorrectly advertising 3 spatial streams 471 * with MCS 0-7 are required, but don't really mean it that way 472 * and we'll connect only with HT, rather than even HE. 473 * As a result, unfortunately the VHT basic MCS/NSS set cannot 474 * be used at all, so check it only in strict mode. 475 */ 476 if (!ieee80211_hw_check(&sdata->local->hw, STRICT)) 477 return true; 478 479 /* 480 * P802.11REVme/D7.0 - 6.5.4.2.4 481 * ... 482 * If the MLME of a VHT STA receives an MLME-JOIN.request primitive 483 * with a SelectedBSS parameter containing a Basic VHT-MCS And NSS Set 484 * field in the VHT Operation parameter that contains any unsupported 485 * <VHT-MCS, NSS> tuple, the MLME response in the resulting 486 * MLME-JOIN.confirm primitive shall contain a ResultCode parameter 487 * that is not set to the value SUCCESS. 488 * ... 489 */ 490 for (nss = 8; nss > 0; nss--) { 491 u8 ap_op_val = (ap_min_req_set >> (2 * (nss - 1))) & 3; 492 u8 sta_rx_val; 493 u8 sta_tx_val; 494 495 if (ap_op_val == IEEE80211_HE_MCS_NOT_SUPPORTED) 496 continue; 497 498 sta_rx_val = (sta_rx_mcs_map >> (2 * (nss - 1))) & 3; 499 sta_tx_val = (sta_tx_mcs_map >> (2 * (nss - 1))) & 3; 500 501 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED || 502 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED || 503 sta_rx_val < ap_op_val || sta_tx_val < ap_op_val) { 504 link_id_info(sdata, link_id, 505 "Missing mandatory rates for %d Nss, rx %d, tx %d oper %d, disable VHT\n", 506 nss, sta_rx_val, sta_tx_val, ap_op_val); 507 return false; 508 } 509 } 510 511 return true; 512 } 513 514 static bool 515 ieee80211_verify_peer_he_mcs_support(struct ieee80211_sub_if_data *sdata, 516 int link_id, 517 const struct ieee80211_he_cap_elem *he_cap, 518 const struct ieee80211_he_operation *he_op) 519 { 520 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp; 521 u16 mcs_80_map_tx, mcs_80_map_rx; 522 u16 ap_min_req_set; 523 int nss; 524 525 if (!he_cap) 526 return false; 527 528 /* mcs_nss is right after he_cap info */ 529 he_mcs_nss_supp = (void *)(he_cap + 1); 530 531 mcs_80_map_tx = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80); 532 mcs_80_map_rx = le16_to_cpu(he_mcs_nss_supp->rx_mcs_80); 533 534 /* P802.11-REVme/D0.3 535 * 27.1.1 Introduction to the HE PHY 536 * ... 537 * An HE STA shall support the following features: 538 * ... 539 * Single spatial stream HE-MCSs 0 to 7 (transmit and receive) in all 540 * supported channel widths for HE SU PPDUs 541 */ 542 if ((mcs_80_map_tx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED || 543 (mcs_80_map_rx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED) { 544 link_id_info(sdata, link_id, 545 "Missing mandatory rates for 1 Nss, rx 0x%x, tx 0x%x, disable HE\n", 546 mcs_80_map_tx, mcs_80_map_rx); 547 return false; 548 } 549 550 if (!he_op) 551 return true; 552 553 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set); 554 555 /* 556 * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all 557 * zeroes, which is nonsense, and completely inconsistent with itself 558 * (it doesn't have 8 streams). Accept the settings in this case anyway. 559 */ 560 if (!ieee80211_hw_check(&sdata->local->hw, STRICT) && !ap_min_req_set) 561 return true; 562 563 /* make sure the AP is consistent with itself 564 * 565 * P802.11-REVme/D0.3 566 * 26.17.1 Basic HE BSS operation 567 * 568 * A STA that is operating in an HE BSS shall be able to receive and 569 * transmit at each of the <HE-MCS, NSS> tuple values indicated by the 570 * Basic HE-MCS And NSS Set field of the HE Operation parameter of the 571 * MLME-START.request primitive and shall be able to receive at each of 572 * the <HE-MCS, NSS> tuple values indicated by the Supported HE-MCS and 573 * NSS Set field in the HE Capabilities parameter of the MLMESTART.request 574 * primitive 575 */ 576 for (nss = 8; nss > 0; nss--) { 577 u8 ap_op_val = (ap_min_req_set >> (2 * (nss - 1))) & 3; 578 u8 ap_rx_val; 579 u8 ap_tx_val; 580 581 if (ap_op_val == IEEE80211_HE_MCS_NOT_SUPPORTED) 582 continue; 583 584 ap_rx_val = (mcs_80_map_rx >> (2 * (nss - 1))) & 3; 585 ap_tx_val = (mcs_80_map_tx >> (2 * (nss - 1))) & 3; 586 587 if (ap_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED || 588 ap_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED || 589 ap_rx_val < ap_op_val || ap_tx_val < ap_op_val) { 590 link_id_info(sdata, link_id, 591 "Invalid rates for %d Nss, rx %d, tx %d oper %d, disable HE\n", 592 nss, ap_rx_val, ap_tx_val, ap_op_val); 593 return false; 594 } 595 } 596 597 return true; 598 } 599 600 static bool 601 ieee80211_verify_sta_he_mcs_support(struct ieee80211_sub_if_data *sdata, 602 struct ieee80211_supported_band *sband, 603 const struct ieee80211_he_operation *he_op) 604 { 605 const struct ieee80211_sta_he_cap *sta_he_cap = 606 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif); 607 u16 ap_min_req_set; 608 int i; 609 610 if (!sta_he_cap || !he_op) 611 return false; 612 613 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set); 614 615 /* 616 * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all 617 * zeroes, which is nonsense, and completely inconsistent with itself 618 * (it doesn't have 8 streams). Accept the settings in this case anyway. 619 */ 620 if (!ieee80211_hw_check(&sdata->local->hw, STRICT) && !ap_min_req_set) 621 return true; 622 623 /* Need to go over for 80MHz, 160MHz and for 80+80 */ 624 for (i = 0; i < 3; i++) { 625 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp = 626 &sta_he_cap->he_mcs_nss_supp; 627 u16 sta_mcs_map_rx = 628 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]); 629 u16 sta_mcs_map_tx = 630 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]); 631 u8 nss; 632 bool verified = true; 633 634 /* 635 * For each band there is a maximum of 8 spatial streams 636 * possible. Each of the sta_mcs_map_* is a 16-bit struct built 637 * of 2 bits per NSS (1-8), with the values defined in enum 638 * ieee80211_he_mcs_support. Need to make sure STA TX and RX 639 * capabilities aren't less than the AP's minimum requirements 640 * for this HE BSS per SS. 641 * It is enough to find one such band that meets the reqs. 642 */ 643 for (nss = 8; nss > 0; nss--) { 644 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3; 645 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3; 646 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3; 647 648 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED) 649 continue; 650 651 /* 652 * Make sure the HE AP doesn't require MCSs that aren't 653 * supported by the client as required by spec 654 * 655 * P802.11-REVme/D0.3 656 * 26.17.1 Basic HE BSS operation 657 * 658 * An HE STA shall not attempt to join * (MLME-JOIN.request primitive) 659 * a BSS, unless it supports (i.e., is able to both transmit and 660 * receive using) all of the <HE-MCS, NSS> tuples in the basic 661 * HE-MCS and NSS set. 662 */ 663 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED || 664 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED || 665 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) { 666 verified = false; 667 break; 668 } 669 } 670 671 if (verified) 672 return true; 673 } 674 675 /* If here, STA doesn't meet AP's HE min requirements */ 676 return false; 677 } 678 679 static u8 680 ieee80211_get_eht_cap_mcs_nss(const struct ieee80211_sta_he_cap *sta_he_cap, 681 const struct ieee80211_sta_eht_cap *sta_eht_cap, 682 unsigned int idx, int bw) 683 { 684 u8 he_phy_cap0 = sta_he_cap->he_cap_elem.phy_cap_info[0]; 685 u8 eht_phy_cap0 = sta_eht_cap->eht_cap_elem.phy_cap_info[0]; 686 687 /* handle us being a 20 MHz-only EHT STA - with four values 688 * for MCS 0-7, 8-9, 10-11, 12-13. 689 */ 690 if (!(he_phy_cap0 & IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_MASK_ALL)) 691 return sta_eht_cap->eht_mcs_nss_supp.only_20mhz.rx_tx_max_nss[idx]; 692 693 /* the others have MCS 0-9 together, rather than separately from 0-7 */ 694 if (idx > 0) 695 idx--; 696 697 switch (bw) { 698 case 0: 699 return sta_eht_cap->eht_mcs_nss_supp.bw._80.rx_tx_max_nss[idx]; 700 case 1: 701 if (!(he_phy_cap0 & 702 (IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G | 703 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G))) 704 return 0xff; /* pass check */ 705 return sta_eht_cap->eht_mcs_nss_supp.bw._160.rx_tx_max_nss[idx]; 706 case 2: 707 if (!(eht_phy_cap0 & IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ)) 708 return 0xff; /* pass check */ 709 return sta_eht_cap->eht_mcs_nss_supp.bw._320.rx_tx_max_nss[idx]; 710 } 711 712 WARN_ON(1); 713 return 0; 714 } 715 716 static bool 717 ieee80211_verify_sta_eht_mcs_support(struct ieee80211_sub_if_data *sdata, 718 struct ieee80211_supported_band *sband, 719 const struct ieee80211_eht_operation *eht_op) 720 { 721 const struct ieee80211_sta_he_cap *sta_he_cap = 722 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif); 723 const struct ieee80211_sta_eht_cap *sta_eht_cap = 724 ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif); 725 const struct ieee80211_eht_mcs_nss_supp_20mhz_only *req; 726 unsigned int i; 727 728 if (!sta_he_cap || !sta_eht_cap || !eht_op) 729 return false; 730 731 req = &eht_op->basic_mcs_nss; 732 733 for (i = 0; i < ARRAY_SIZE(req->rx_tx_max_nss); i++) { 734 u8 req_rx_nss, req_tx_nss; 735 unsigned int bw; 736 737 req_rx_nss = u8_get_bits(req->rx_tx_max_nss[i], 738 IEEE80211_EHT_MCS_NSS_RX); 739 req_tx_nss = u8_get_bits(req->rx_tx_max_nss[i], 740 IEEE80211_EHT_MCS_NSS_TX); 741 742 for (bw = 0; bw < 3; bw++) { 743 u8 have, have_rx_nss, have_tx_nss; 744 745 have = ieee80211_get_eht_cap_mcs_nss(sta_he_cap, 746 sta_eht_cap, 747 i, bw); 748 have_rx_nss = u8_get_bits(have, 749 IEEE80211_EHT_MCS_NSS_RX); 750 have_tx_nss = u8_get_bits(have, 751 IEEE80211_EHT_MCS_NSS_TX); 752 753 if (req_rx_nss > have_rx_nss || 754 req_tx_nss > have_tx_nss) 755 return false; 756 } 757 } 758 759 return true; 760 } 761 762 static void ieee80211_get_rates(struct ieee80211_supported_band *sband, 763 const u8 *supp_rates, 764 unsigned int supp_rates_len, 765 const u8 *ext_supp_rates, 766 unsigned int ext_supp_rates_len, 767 u32 *rates, u32 *basic_rates, 768 unsigned long *unknown_rates_selectors, 769 bool *have_higher_than_11mbit, 770 int *min_rate, int *min_rate_index) 771 { 772 int i, j; 773 774 for (i = 0; i < supp_rates_len + ext_supp_rates_len; i++) { 775 u8 supp_rate = i < supp_rates_len ? 776 supp_rates[i] : 777 ext_supp_rates[i - supp_rates_len]; 778 int rate = supp_rate & 0x7f; 779 bool is_basic = !!(supp_rate & 0x80); 780 781 if ((rate * 5) > 110 && have_higher_than_11mbit) 782 *have_higher_than_11mbit = true; 783 784 /* 785 * Skip membership selectors since they're not rates. 786 * 787 * Note: Even though the membership selector and the basic 788 * rate flag share the same bit, they are not exactly 789 * the same. 790 */ 791 if (is_basic && rate >= BSS_MEMBERSHIP_SELECTOR_MIN) { 792 if (unknown_rates_selectors) 793 set_bit(rate, unknown_rates_selectors); 794 continue; 795 } 796 797 for (j = 0; j < sband->n_bitrates; j++) { 798 struct ieee80211_rate *br; 799 int brate; 800 801 br = &sband->bitrates[j]; 802 803 brate = DIV_ROUND_UP(br->bitrate, 5); 804 if (brate == rate) { 805 if (rates) 806 *rates |= BIT(j); 807 if (is_basic && basic_rates) 808 *basic_rates |= BIT(j); 809 if (min_rate && (rate * 5) < *min_rate) { 810 *min_rate = rate * 5; 811 if (min_rate_index) 812 *min_rate_index = j; 813 } 814 break; 815 } 816 } 817 818 /* Handle an unknown entry as if it is an unknown selector */ 819 if (is_basic && unknown_rates_selectors && j == sband->n_bitrates) 820 set_bit(rate, unknown_rates_selectors); 821 } 822 } 823 824 static bool ieee80211_chandef_usable(struct ieee80211_sub_if_data *sdata, 825 const struct cfg80211_chan_def *chandef, 826 u32 prohibited_flags) 827 { 828 if (!cfg80211_chandef_usable(sdata->local->hw.wiphy, 829 chandef, prohibited_flags)) 830 return false; 831 832 if (chandef->punctured && 833 ieee80211_hw_check(&sdata->local->hw, DISALLOW_PUNCTURING)) 834 return false; 835 836 return true; 837 } 838 839 static int ieee80211_chandef_num_subchans(const struct cfg80211_chan_def *c) 840 { 841 if (c->width == NL80211_CHAN_WIDTH_80P80) 842 return 4 + 4; 843 844 return cfg80211_chandef_get_width(c) / 20; 845 } 846 847 static int ieee80211_chandef_num_widths(const struct cfg80211_chan_def *c) 848 { 849 switch (c->width) { 850 case NL80211_CHAN_WIDTH_20: 851 case NL80211_CHAN_WIDTH_20_NOHT: 852 return 1; 853 case NL80211_CHAN_WIDTH_40: 854 return 2; 855 case NL80211_CHAN_WIDTH_80P80: 856 case NL80211_CHAN_WIDTH_80: 857 return 3; 858 case NL80211_CHAN_WIDTH_160: 859 return 4; 860 case NL80211_CHAN_WIDTH_320: 861 return 5; 862 default: 863 WARN_ON(1); 864 return 0; 865 } 866 } 867 868 VISIBLE_IF_MAC80211_KUNIT int 869 ieee80211_calc_chandef_subchan_offset(const struct cfg80211_chan_def *ap, 870 u8 n_partial_subchans) 871 { 872 int n = ieee80211_chandef_num_subchans(ap); 873 struct cfg80211_chan_def tmp = *ap; 874 int offset = 0; 875 876 /* 877 * Given a chandef (in this context, it's the AP's) and a number 878 * of subchannels that we want to look at ('n_partial_subchans'), 879 * calculate the offset in number of subchannels between the full 880 * and the subset with the desired width. 881 */ 882 883 /* same number of subchannels means no offset, obviously */ 884 if (n == n_partial_subchans) 885 return 0; 886 887 /* don't WARN - misconfigured APs could cause this if their N > width */ 888 if (n < n_partial_subchans) 889 return 0; 890 891 while (ieee80211_chandef_num_subchans(&tmp) > n_partial_subchans) { 892 u32 prev = tmp.center_freq1; 893 894 ieee80211_chandef_downgrade(&tmp, NULL); 895 896 /* 897 * if center_freq moved up, half the original channels 898 * are gone now but were below, so increase offset 899 */ 900 if (prev < tmp.center_freq1) 901 offset += ieee80211_chandef_num_subchans(&tmp); 902 } 903 904 /* 905 * 80+80 with secondary 80 below primary - four subchannels for it 906 * (we cannot downgrade *to* 80+80, so no need to consider 'tmp') 907 */ 908 if (ap->width == NL80211_CHAN_WIDTH_80P80 && 909 ap->center_freq2 < ap->center_freq1) 910 offset += 4; 911 912 return offset; 913 } 914 EXPORT_SYMBOL_IF_MAC80211_KUNIT(ieee80211_calc_chandef_subchan_offset); 915 916 VISIBLE_IF_MAC80211_KUNIT void 917 ieee80211_rearrange_tpe_psd(struct ieee80211_parsed_tpe_psd *psd, 918 const struct cfg80211_chan_def *ap, 919 const struct cfg80211_chan_def *used) 920 { 921 u8 needed = ieee80211_chandef_num_subchans(used); 922 u8 have = ieee80211_chandef_num_subchans(ap); 923 u8 tmp[IEEE80211_TPE_PSD_ENTRIES_320MHZ]; 924 u8 offset; 925 926 if (!psd->valid) 927 return; 928 929 /* if N is zero, all defaults were used, no point in rearranging */ 930 if (!psd->n) 931 goto out; 932 933 BUILD_BUG_ON(sizeof(tmp) != sizeof(psd->power)); 934 935 /* 936 * This assumes that 'N' is consistent with the HE channel, as 937 * it should be (otherwise the AP is broken). 938 * 939 * In psd->power we have values in the order 0..N, 0..K, where 940 * N+K should cover the entire channel per 'ap', but even if it 941 * doesn't then we've pre-filled 'unlimited' as defaults. 942 * 943 * But this is all the wrong order, we want to have them in the 944 * order of the 'used' channel. 945 * 946 * So for example, we could have a 320 MHz EHT AP, which has the 947 * HE channel as 80 MHz (e.g. due to puncturing, which doesn't 948 * seem to be considered for the TPE), as follows: 949 * 950 * EHT 320: | | | | | | | | | | | | | | | | | 951 * HE 80: | | | | | 952 * used 160: | | | | | | | | | 953 * 954 * N entries: |--|--|--|--| 955 * K entries: |--|--|--|--|--|--|--|--| |--|--|--|--| 956 * power idx: 4 5 6 7 8 9 10 11 0 1 2 3 12 13 14 15 957 * full chan: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 958 * used chan: 0 1 2 3 4 5 6 7 959 * 960 * The idx in the power array ('power idx') is like this since it 961 * comes directly from the element's N and K entries in their 962 * element order, and those are this way for HE compatibility. 963 * 964 * Rearrange them as desired here, first by putting them into the 965 * 'full chan' order, and then selecting the necessary subset for 966 * the 'used chan'. 967 */ 968 969 /* first reorder according to AP channel */ 970 offset = ieee80211_calc_chandef_subchan_offset(ap, psd->n); 971 for (int i = 0; i < have; i++) { 972 if (i < offset) 973 tmp[i] = psd->power[i + psd->n]; 974 else if (i < offset + psd->n) 975 tmp[i] = psd->power[i - offset]; 976 else 977 tmp[i] = psd->power[i]; 978 } 979 980 /* 981 * and then select the subset for the used channel 982 * (set everything to defaults first in case a driver is confused) 983 */ 984 memset(psd->power, IEEE80211_TPE_PSD_NO_LIMIT, sizeof(psd->power)); 985 offset = ieee80211_calc_chandef_subchan_offset(ap, needed); 986 for (int i = 0; i < needed; i++) 987 psd->power[i] = tmp[offset + i]; 988 989 out: 990 /* limit, but don't lie if there are defaults in the data */ 991 if (needed < psd->count) 992 psd->count = needed; 993 } 994 EXPORT_SYMBOL_IF_MAC80211_KUNIT(ieee80211_rearrange_tpe_psd); 995 996 static void ieee80211_rearrange_tpe(struct ieee80211_parsed_tpe *tpe, 997 const struct cfg80211_chan_def *ap, 998 const struct cfg80211_chan_def *used) 999 { 1000 /* ignore this completely for narrow/invalid channels */ 1001 if (!ieee80211_chandef_num_subchans(ap) || 1002 !ieee80211_chandef_num_subchans(used)) { 1003 ieee80211_clear_tpe(tpe); 1004 return; 1005 } 1006 1007 for (int i = 0; i < 2; i++) { 1008 int needed_pwr_count; 1009 1010 ieee80211_rearrange_tpe_psd(&tpe->psd_local[i], ap, used); 1011 ieee80211_rearrange_tpe_psd(&tpe->psd_reg_client[i], ap, used); 1012 1013 /* limit this to the widths we actually need */ 1014 needed_pwr_count = ieee80211_chandef_num_widths(used); 1015 if (needed_pwr_count < tpe->max_local[i].count) 1016 tpe->max_local[i].count = needed_pwr_count; 1017 if (needed_pwr_count < tpe->max_reg_client[i].count) 1018 tpe->max_reg_client[i].count = needed_pwr_count; 1019 } 1020 } 1021 1022 /* 1023 * The AP part of the channel request is used to distinguish settings 1024 * to the device used for wider bandwidth OFDMA. This is used in the 1025 * channel context code to assign two channel contexts even if they're 1026 * both for the same channel, if the AP bandwidths are incompatible. 1027 * If not EHT (or driver override) then ap.chan == NULL indicates that 1028 * there's no wider BW OFDMA used. 1029 */ 1030 static void ieee80211_set_chanreq_ap(struct ieee80211_sub_if_data *sdata, 1031 struct ieee80211_chan_req *chanreq, 1032 struct ieee80211_conn_settings *conn, 1033 struct cfg80211_chan_def *ap_chandef) 1034 { 1035 chanreq->ap.chan = NULL; 1036 1037 if (conn->mode < IEEE80211_CONN_MODE_EHT) 1038 return; 1039 if (sdata->vif.driver_flags & IEEE80211_VIF_IGNORE_OFDMA_WIDER_BW) 1040 return; 1041 1042 chanreq->ap = *ap_chandef; 1043 } 1044 1045 VISIBLE_IF_MAC80211_KUNIT struct ieee802_11_elems * 1046 ieee80211_determine_chan_mode(struct ieee80211_sub_if_data *sdata, 1047 struct ieee80211_conn_settings *conn, 1048 struct cfg80211_bss *cbss, int link_id, 1049 struct ieee80211_chan_req *chanreq, 1050 struct cfg80211_chan_def *ap_chandef, 1051 unsigned long *userspace_selectors) 1052 { 1053 const struct cfg80211_bss_ies *ies = rcu_dereference(cbss->ies); 1054 struct ieee80211_bss *bss = (void *)cbss->priv; 1055 struct ieee80211_channel *channel = cbss->channel; 1056 struct ieee80211_elems_parse_params parse_params = { 1057 .link_id = -1, 1058 .from_ap = true, 1059 .start = ies->data, 1060 .len = ies->len, 1061 .type = ies->from_beacon ? 1062 IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON : 1063 IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP, 1064 }; 1065 struct ieee802_11_elems *elems; 1066 struct ieee80211_supported_band *sband; 1067 enum ieee80211_conn_mode ap_mode; 1068 unsigned long unknown_rates_selectors[BITS_TO_LONGS(128)] = {}; 1069 unsigned long sta_selectors[BITS_TO_LONGS(128)] = {}; 1070 int ret; 1071 1072 again: 1073 parse_params.mode = conn->mode; 1074 elems = ieee802_11_parse_elems_full(&parse_params); 1075 if (!elems) 1076 return ERR_PTR(-ENOMEM); 1077 1078 ap_mode = ieee80211_determine_ap_chan(sdata, channel, bss->vht_cap_info, 1079 elems, false, conn, ap_chandef); 1080 1081 /* this should be impossible since parsing depends on our mode */ 1082 if (WARN_ON(ap_mode > conn->mode)) { 1083 ret = -EINVAL; 1084 goto free; 1085 } 1086 1087 if (conn->mode != ap_mode) { 1088 conn->mode = ap_mode; 1089 kfree(elems); 1090 goto again; 1091 } 1092 1093 mlme_link_id_dbg(sdata, link_id, "determined AP %pM to be %s\n", 1094 cbss->bssid, ieee80211_conn_mode_str(ap_mode)); 1095 1096 sband = sdata->local->hw.wiphy->bands[channel->band]; 1097 1098 ieee80211_get_rates(sband, elems->supp_rates, elems->supp_rates_len, 1099 elems->ext_supp_rates, elems->ext_supp_rates_len, 1100 NULL, NULL, unknown_rates_selectors, NULL, NULL, 1101 NULL); 1102 1103 switch (channel->band) { 1104 case NL80211_BAND_S1GHZ: 1105 if (WARN_ON(ap_mode != IEEE80211_CONN_MODE_S1G)) { 1106 ret = -EINVAL; 1107 goto free; 1108 } 1109 1110 chanreq->oper = *ap_chandef; 1111 if (!cfg80211_chandef_usable(sdata->wdev.wiphy, &chanreq->oper, 1112 IEEE80211_CHAN_DISABLED)) { 1113 ret = -EINVAL; 1114 goto free; 1115 } 1116 1117 return elems; 1118 case NL80211_BAND_6GHZ: 1119 if (ap_mode < IEEE80211_CONN_MODE_HE) { 1120 link_id_info(sdata, link_id, 1121 "Rejecting non-HE 6/7 GHz connection"); 1122 ret = -EINVAL; 1123 goto free; 1124 } 1125 break; 1126 default: 1127 if (WARN_ON(ap_mode == IEEE80211_CONN_MODE_S1G)) { 1128 ret = -EINVAL; 1129 goto free; 1130 } 1131 } 1132 1133 switch (ap_mode) { 1134 case IEEE80211_CONN_MODE_S1G: 1135 WARN_ON(1); 1136 ret = -EINVAL; 1137 goto free; 1138 case IEEE80211_CONN_MODE_LEGACY: 1139 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20; 1140 break; 1141 case IEEE80211_CONN_MODE_HT: 1142 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit, 1143 conn->bw_limit, 1144 IEEE80211_CONN_BW_LIMIT_40); 1145 break; 1146 case IEEE80211_CONN_MODE_VHT: 1147 case IEEE80211_CONN_MODE_HE: 1148 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit, 1149 conn->bw_limit, 1150 IEEE80211_CONN_BW_LIMIT_160); 1151 break; 1152 case IEEE80211_CONN_MODE_EHT: 1153 case IEEE80211_CONN_MODE_UHR: 1154 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit, 1155 conn->bw_limit, 1156 IEEE80211_CONN_BW_LIMIT_320); 1157 break; 1158 } 1159 1160 chanreq->oper = *ap_chandef; 1161 1162 bitmap_copy(sta_selectors, userspace_selectors, 128); 1163 if (conn->mode >= IEEE80211_CONN_MODE_HT) 1164 set_bit(BSS_MEMBERSHIP_SELECTOR_HT_PHY, sta_selectors); 1165 if (conn->mode >= IEEE80211_CONN_MODE_VHT) 1166 set_bit(BSS_MEMBERSHIP_SELECTOR_VHT_PHY, sta_selectors); 1167 if (conn->mode >= IEEE80211_CONN_MODE_HE) 1168 set_bit(BSS_MEMBERSHIP_SELECTOR_HE_PHY, sta_selectors); 1169 if (conn->mode >= IEEE80211_CONN_MODE_EHT) 1170 set_bit(BSS_MEMBERSHIP_SELECTOR_EHT_PHY, sta_selectors); 1171 if (conn->mode >= IEEE80211_CONN_MODE_UHR) 1172 set_bit(BSS_MEMBERSHIP_SELECTOR_UHR_PHY, sta_selectors); 1173 1174 /* 1175 * We do not support EPD or GLK so never add them. 1176 * SAE_H2E is handled through userspace_selectors. 1177 */ 1178 1179 /* Check if we support all required features */ 1180 if (!bitmap_subset(unknown_rates_selectors, sta_selectors, 128)) { 1181 link_id_info(sdata, link_id, 1182 "required basic rate or BSS membership selectors not supported or disabled, rejecting connection\n"); 1183 ret = -EINVAL; 1184 goto free; 1185 } 1186 1187 ieee80211_set_chanreq_ap(sdata, chanreq, conn, ap_chandef); 1188 1189 while (!ieee80211_chandef_usable(sdata, &chanreq->oper, 1190 IEEE80211_CHAN_DISABLED)) { 1191 if (chanreq->oper.width == NL80211_CHAN_WIDTH_20_NOHT) { 1192 link_id_info(sdata, link_id, 1193 "unusable channel (%d MHz) for connection\n", 1194 chanreq->oper.chan->center_freq); 1195 ret = -EINVAL; 1196 goto free; 1197 } 1198 1199 ieee80211_chanreq_downgrade(chanreq, conn); 1200 } 1201 1202 if (conn->mode >= IEEE80211_CONN_MODE_HE && 1203 !cfg80211_chandef_usable(sdata->wdev.wiphy, &chanreq->oper, 1204 IEEE80211_CHAN_NO_HE)) { 1205 conn->mode = IEEE80211_CONN_MODE_VHT; 1206 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit, 1207 conn->bw_limit, 1208 IEEE80211_CONN_BW_LIMIT_160); 1209 } 1210 1211 if (conn->mode >= IEEE80211_CONN_MODE_EHT && 1212 !cfg80211_chandef_usable(sdata->wdev.wiphy, &chanreq->oper, 1213 IEEE80211_CHAN_NO_EHT)) { 1214 conn->mode = IEEE80211_CONN_MODE_HE; 1215 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit, 1216 conn->bw_limit, 1217 IEEE80211_CONN_BW_LIMIT_160); 1218 } 1219 1220 if (conn->mode >= IEEE80211_CONN_MODE_UHR && 1221 !cfg80211_chandef_usable(sdata->wdev.wiphy, &chanreq->oper, 1222 IEEE80211_CHAN_NO_UHR)) 1223 conn->mode = IEEE80211_CONN_MODE_EHT; 1224 1225 if (chanreq->oper.width != ap_chandef->width || ap_mode != conn->mode) 1226 link_id_info(sdata, link_id, 1227 "regulatory prevented using AP config, downgraded\n"); 1228 1229 if (conn->mode >= IEEE80211_CONN_MODE_HT && 1230 !ieee80211_verify_sta_ht_mcs_support(sdata, sband, 1231 elems->ht_operation)) { 1232 conn->mode = IEEE80211_CONN_MODE_LEGACY; 1233 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20; 1234 link_id_info(sdata, link_id, 1235 "required MCSes not supported, disabling HT\n"); 1236 } 1237 1238 if (conn->mode >= IEEE80211_CONN_MODE_VHT && 1239 !ieee80211_verify_sta_vht_mcs_support(sdata, link_id, sband, 1240 elems->vht_operation)) { 1241 conn->mode = IEEE80211_CONN_MODE_HT; 1242 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit, 1243 conn->bw_limit, 1244 IEEE80211_CONN_BW_LIMIT_40); 1245 link_id_info(sdata, link_id, 1246 "required MCSes not supported, disabling VHT\n"); 1247 } 1248 1249 if (conn->mode >= IEEE80211_CONN_MODE_HE && 1250 (!ieee80211_verify_peer_he_mcs_support(sdata, link_id, 1251 (void *)elems->he_cap, 1252 elems->he_operation) || 1253 !ieee80211_verify_sta_he_mcs_support(sdata, sband, 1254 elems->he_operation))) { 1255 conn->mode = IEEE80211_CONN_MODE_VHT; 1256 link_id_info(sdata, link_id, 1257 "required MCSes not supported, disabling HE\n"); 1258 } 1259 1260 if (conn->mode >= IEEE80211_CONN_MODE_EHT && 1261 !ieee80211_verify_sta_eht_mcs_support(sdata, sband, 1262 elems->eht_operation)) { 1263 conn->mode = IEEE80211_CONN_MODE_HE; 1264 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit, 1265 conn->bw_limit, 1266 IEEE80211_CONN_BW_LIMIT_160); 1267 link_id_info(sdata, link_id, 1268 "required MCSes not supported, disabling EHT\n"); 1269 } 1270 1271 if (conn->mode >= IEEE80211_CONN_MODE_EHT && 1272 channel->band != NL80211_BAND_2GHZ && 1273 conn->bw_limit == IEEE80211_CONN_BW_LIMIT_40) { 1274 conn->mode = IEEE80211_CONN_MODE_HE; 1275 link_id_info(sdata, link_id, 1276 "required bandwidth not supported, disabling EHT\n"); 1277 } 1278 1279 /* the mode can only decrease, so this must terminate */ 1280 if (ap_mode != conn->mode) { 1281 kfree(elems); 1282 goto again; 1283 } 1284 1285 mlme_link_id_dbg(sdata, link_id, 1286 "connecting with %s mode, max bandwidth %d MHz\n", 1287 ieee80211_conn_mode_str(conn->mode), 1288 20 * (1 << conn->bw_limit)); 1289 1290 if (WARN_ON_ONCE(!cfg80211_chandef_valid(&chanreq->oper))) { 1291 ret = -EINVAL; 1292 goto free; 1293 } 1294 1295 return elems; 1296 free: 1297 kfree(elems); 1298 return ERR_PTR(ret); 1299 } 1300 EXPORT_SYMBOL_IF_MAC80211_KUNIT(ieee80211_determine_chan_mode); 1301 1302 static int ieee80211_config_bw(struct ieee80211_link_data *link, 1303 struct ieee802_11_elems *elems, 1304 bool update, u64 *changed, u16 stype) 1305 { 1306 struct ieee80211_channel *channel = link->conf->chanreq.oper.chan; 1307 struct ieee80211_sub_if_data *sdata = link->sdata; 1308 struct ieee80211_chan_req chanreq = {}; 1309 struct cfg80211_chan_def ap_chandef; 1310 enum ieee80211_conn_mode ap_mode; 1311 const char *frame; 1312 u32 vht_cap_info = 0; 1313 u16 ht_opmode; 1314 int ret; 1315 1316 switch (stype) { 1317 case IEEE80211_STYPE_BEACON: 1318 frame = "beacon"; 1319 break; 1320 case IEEE80211_STYPE_ASSOC_RESP: 1321 frame = "assoc response"; 1322 break; 1323 case IEEE80211_STYPE_REASSOC_RESP: 1324 frame = "reassoc response"; 1325 break; 1326 case IEEE80211_STYPE_ACTION: 1327 /* the only action frame that gets here */ 1328 frame = "ML reconf response"; 1329 break; 1330 default: 1331 return -EINVAL; 1332 } 1333 1334 /* don't track any bandwidth changes in legacy/S1G modes */ 1335 if (link->u.mgd.conn.mode == IEEE80211_CONN_MODE_LEGACY || 1336 link->u.mgd.conn.mode == IEEE80211_CONN_MODE_S1G) 1337 return 0; 1338 1339 if (elems->vht_cap_elem) 1340 vht_cap_info = le32_to_cpu(elems->vht_cap_elem->vht_cap_info); 1341 1342 ap_mode = ieee80211_determine_ap_chan(sdata, channel, vht_cap_info, 1343 elems, true, &link->u.mgd.conn, 1344 &ap_chandef); 1345 1346 if (ap_mode != link->u.mgd.conn.mode) { 1347 link_info(link, 1348 "AP %pM appears to change mode (expected %s, found %s) in %s, disconnect\n", 1349 link->u.mgd.bssid, 1350 ieee80211_conn_mode_str(link->u.mgd.conn.mode), 1351 ieee80211_conn_mode_str(ap_mode), frame); 1352 return -EINVAL; 1353 } 1354 1355 chanreq.oper = ap_chandef; 1356 ieee80211_set_chanreq_ap(sdata, &chanreq, &link->u.mgd.conn, 1357 &ap_chandef); 1358 1359 /* 1360 * if HT operation mode changed store the new one - 1361 * this may be applicable even if channel is identical 1362 */ 1363 if (elems->ht_operation) { 1364 ht_opmode = le16_to_cpu(elems->ht_operation->operation_mode); 1365 if (link->conf->ht_operation_mode != ht_opmode) { 1366 *changed |= BSS_CHANGED_HT; 1367 link->conf->ht_operation_mode = ht_opmode; 1368 } 1369 } 1370 1371 /* 1372 * Downgrade the new channel if we associated with restricted 1373 * bandwidth capabilities. For example, if we associated as a 1374 * 20 MHz STA to a 40 MHz AP (due to regulatory, capabilities 1375 * or config reasons) then switching to a 40 MHz channel now 1376 * won't do us any good -- we couldn't use it with the AP. 1377 */ 1378 while (link->u.mgd.conn.bw_limit < 1379 ieee80211_min_bw_limit_from_chandef(&chanreq.oper)) 1380 ieee80211_chandef_downgrade(&chanreq.oper, NULL); 1381 1382 /* TPE element is not present in (re)assoc/ML reconfig response */ 1383 if (stype == IEEE80211_STYPE_BEACON && 1384 ap_chandef.chan->band == NL80211_BAND_6GHZ && 1385 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HE) { 1386 ieee80211_rearrange_tpe(&elems->tpe, &ap_chandef, 1387 &chanreq.oper); 1388 if (memcmp(&link->conf->tpe, &elems->tpe, sizeof(elems->tpe))) { 1389 link->conf->tpe = elems->tpe; 1390 *changed |= BSS_CHANGED_TPE; 1391 } 1392 } 1393 1394 if (ieee80211_chanreq_identical(&chanreq, &link->conf->chanreq)) 1395 return 0; 1396 1397 link_info(link, 1398 "AP %pM changed bandwidth in %s, new used config is %d.%03d MHz, width %d (%d.%03d/%d MHz)\n", 1399 link->u.mgd.bssid, frame, chanreq.oper.chan->center_freq, 1400 chanreq.oper.chan->freq_offset, chanreq.oper.width, 1401 chanreq.oper.center_freq1, chanreq.oper.freq1_offset, 1402 chanreq.oper.center_freq2); 1403 1404 if (!cfg80211_chandef_valid(&chanreq.oper)) { 1405 sdata_info(sdata, 1406 "AP %pM changed caps/bw in %s in a way we can't support - disconnect\n", 1407 link->u.mgd.bssid, frame); 1408 return -EINVAL; 1409 } 1410 1411 if (!update) { 1412 link->conf->chanreq = chanreq; 1413 return 0; 1414 } 1415 1416 /* 1417 * We're tracking the current AP here, so don't do any further checks 1418 * here. This keeps us from playing ping-pong with regulatory, without 1419 * it the following can happen (for example): 1420 * - connect to an AP with 80 MHz, world regdom allows 80 MHz 1421 * - AP advertises regdom US 1422 * - CRDA loads regdom US with 80 MHz prohibited (old database) 1423 * - we detect an unsupported channel and disconnect 1424 * - disconnect causes CRDA to reload world regdomain and the game 1425 * starts anew. 1426 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881) 1427 * 1428 * It seems possible that there are still scenarios with CSA or real 1429 * bandwidth changes where a this could happen, but those cases are 1430 * less common and wouldn't completely prevent using the AP. 1431 */ 1432 1433 ret = ieee80211_link_change_chanreq(link, &chanreq, changed); 1434 if (ret) { 1435 sdata_info(sdata, 1436 "AP %pM changed bandwidth in %s to incompatible one - disconnect\n", 1437 link->u.mgd.bssid, frame); 1438 return ret; 1439 } 1440 1441 cfg80211_schedule_channels_check(&sdata->wdev); 1442 return 0; 1443 } 1444 1445 /* frame sending functions */ 1446 1447 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata, 1448 struct sk_buff *skb, u8 ap_ht_param, 1449 struct ieee80211_supported_band *sband, 1450 struct ieee80211_channel *channel, 1451 enum ieee80211_smps_mode smps, 1452 const struct ieee80211_conn_settings *conn) 1453 { 1454 u8 *pos; 1455 u32 flags = channel->flags; 1456 u16 cap; 1457 struct ieee80211_sta_ht_cap ht_cap; 1458 1459 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap)); 1460 1461 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap)); 1462 ieee80211_apply_htcap_overrides(sdata, &ht_cap); 1463 1464 /* determine capability flags */ 1465 cap = ht_cap.cap; 1466 1467 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { 1468 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: 1469 if (flags & IEEE80211_CHAN_NO_HT40PLUS) { 1470 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; 1471 cap &= ~IEEE80211_HT_CAP_SGI_40; 1472 } 1473 break; 1474 case IEEE80211_HT_PARAM_CHA_SEC_BELOW: 1475 if (flags & IEEE80211_CHAN_NO_HT40MINUS) { 1476 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; 1477 cap &= ~IEEE80211_HT_CAP_SGI_40; 1478 } 1479 break; 1480 } 1481 1482 /* 1483 * If 40 MHz was disabled associate as though we weren't 1484 * capable of 40 MHz -- some broken APs will never fall 1485 * back to trying to transmit in 20 MHz. 1486 */ 1487 if (conn->bw_limit <= IEEE80211_CONN_BW_LIMIT_20) { 1488 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; 1489 cap &= ~IEEE80211_HT_CAP_SGI_40; 1490 } 1491 1492 /* set SM PS mode properly */ 1493 cap &= ~IEEE80211_HT_CAP_SM_PS; 1494 switch (smps) { 1495 case IEEE80211_SMPS_AUTOMATIC: 1496 case IEEE80211_SMPS_NUM_MODES: 1497 WARN_ON(1); 1498 fallthrough; 1499 case IEEE80211_SMPS_OFF: 1500 cap |= WLAN_HT_CAP_SM_PS_DISABLED << 1501 IEEE80211_HT_CAP_SM_PS_SHIFT; 1502 break; 1503 case IEEE80211_SMPS_STATIC: 1504 cap |= WLAN_HT_CAP_SM_PS_STATIC << 1505 IEEE80211_HT_CAP_SM_PS_SHIFT; 1506 break; 1507 case IEEE80211_SMPS_DYNAMIC: 1508 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC << 1509 IEEE80211_HT_CAP_SM_PS_SHIFT; 1510 break; 1511 } 1512 1513 /* reserve and fill IE */ 1514 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2); 1515 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap); 1516 } 1517 1518 /* This function determines vht capability flags for the association 1519 * and builds the IE. 1520 * Note - the function returns true to own the MU-MIMO capability 1521 */ 1522 static bool ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata, 1523 struct sk_buff *skb, 1524 struct ieee80211_supported_band *sband, 1525 struct ieee80211_vht_cap *ap_vht_cap, 1526 const struct ieee80211_conn_settings *conn) 1527 { 1528 struct ieee80211_local *local = sdata->local; 1529 u8 *pos; 1530 u32 cap; 1531 struct ieee80211_sta_vht_cap vht_cap; 1532 u32 mask, ap_bf_sts, our_bf_sts; 1533 bool mu_mimo_owner = false; 1534 1535 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap)); 1536 1537 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap)); 1538 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap); 1539 1540 /* determine capability flags */ 1541 cap = vht_cap.cap; 1542 1543 if (conn->bw_limit <= IEEE80211_CONN_BW_LIMIT_80) { 1544 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160; 1545 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK; 1546 } 1547 1548 /* 1549 * Some APs apparently get confused if our capabilities are better 1550 * than theirs, so restrict what we advertise in the assoc request. 1551 */ 1552 if (!ieee80211_hw_check(&local->hw, STRICT)) { 1553 if (!(ap_vht_cap->vht_cap_info & 1554 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE))) 1555 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | 1556 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE); 1557 else if (!(ap_vht_cap->vht_cap_info & 1558 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))) 1559 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE; 1560 } 1561 1562 /* 1563 * If some other vif is using the MU-MIMO capability we cannot associate 1564 * using MU-MIMO - this will lead to contradictions in the group-id 1565 * mechanism. 1566 * Ownership is defined since association request, in order to avoid 1567 * simultaneous associations with MU-MIMO. 1568 */ 1569 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) { 1570 bool disable_mu_mimo = false; 1571 struct ieee80211_sub_if_data *other; 1572 1573 list_for_each_entry(other, &local->interfaces, list) { 1574 if (other->vif.bss_conf.mu_mimo_owner) { 1575 disable_mu_mimo = true; 1576 break; 1577 } 1578 } 1579 if (disable_mu_mimo) 1580 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE; 1581 else 1582 mu_mimo_owner = true; 1583 } 1584 1585 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK; 1586 1587 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask; 1588 our_bf_sts = cap & mask; 1589 1590 if (ap_bf_sts < our_bf_sts) { 1591 cap &= ~mask; 1592 cap |= ap_bf_sts; 1593 } 1594 1595 /* reserve and fill IE */ 1596 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2); 1597 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap); 1598 1599 return mu_mimo_owner; 1600 } 1601 1602 static void ieee80211_assoc_add_rates(struct ieee80211_local *local, 1603 struct sk_buff *skb, 1604 enum nl80211_chan_width width, 1605 struct ieee80211_supported_band *sband, 1606 struct ieee80211_mgd_assoc_data *assoc_data) 1607 { 1608 u32 rates; 1609 1610 if (assoc_data->supp_rates_len && 1611 !ieee80211_hw_check(&local->hw, STRICT)) { 1612 /* 1613 * Get all rates supported by the device and the AP as 1614 * some APs don't like getting a superset of their rates 1615 * in the association request (e.g. D-Link DAP 1353 in 1616 * b-only mode)... 1617 */ 1618 ieee80211_parse_bitrates(sband, 1619 assoc_data->supp_rates, 1620 assoc_data->supp_rates_len, 1621 &rates); 1622 } else { 1623 /* 1624 * In case AP not provide any supported rates information 1625 * before association, we send information element(s) with 1626 * all rates that we support. 1627 */ 1628 rates = ~0; 1629 } 1630 1631 ieee80211_put_srates_elem(skb, sband, 0, ~rates, 1632 WLAN_EID_SUPP_RATES); 1633 ieee80211_put_srates_elem(skb, sband, 0, ~rates, 1634 WLAN_EID_EXT_SUPP_RATES); 1635 } 1636 1637 static size_t ieee80211_add_before_ht_elems(struct sk_buff *skb, 1638 const u8 *elems, 1639 size_t elems_len, 1640 size_t offset) 1641 { 1642 size_t noffset; 1643 1644 static const u8 before_ht[] = { 1645 WLAN_EID_SSID, 1646 WLAN_EID_SUPP_RATES, 1647 WLAN_EID_EXT_SUPP_RATES, 1648 WLAN_EID_PWR_CAPABILITY, 1649 WLAN_EID_SUPPORTED_CHANNELS, 1650 WLAN_EID_RSN, 1651 WLAN_EID_QOS_CAPA, 1652 WLAN_EID_RRM_ENABLED_CAPABILITIES, 1653 WLAN_EID_MOBILITY_DOMAIN, 1654 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */ 1655 WLAN_EID_RIC_DATA, /* reassoc only */ 1656 WLAN_EID_SUPPORTED_REGULATORY_CLASSES, 1657 }; 1658 static const u8 after_ric[] = { 1659 WLAN_EID_SUPPORTED_REGULATORY_CLASSES, 1660 WLAN_EID_HT_CAPABILITY, 1661 WLAN_EID_BSS_COEX_2040, 1662 /* luckily this is almost always there */ 1663 WLAN_EID_EXT_CAPABILITY, 1664 WLAN_EID_QOS_TRAFFIC_CAPA, 1665 WLAN_EID_TIM_BCAST_REQ, 1666 WLAN_EID_INTERWORKING, 1667 /* 60 GHz (Multi-band, DMG, MMS) can't happen */ 1668 WLAN_EID_VHT_CAPABILITY, 1669 WLAN_EID_OPMODE_NOTIF, 1670 }; 1671 1672 if (!elems_len) 1673 return offset; 1674 1675 noffset = ieee80211_ie_split_ric(elems, elems_len, 1676 before_ht, 1677 ARRAY_SIZE(before_ht), 1678 after_ric, 1679 ARRAY_SIZE(after_ric), 1680 offset); 1681 skb_put_data(skb, elems + offset, noffset - offset); 1682 1683 return noffset; 1684 } 1685 1686 static size_t ieee80211_add_before_vht_elems(struct sk_buff *skb, 1687 const u8 *elems, 1688 size_t elems_len, 1689 size_t offset) 1690 { 1691 static const u8 before_vht[] = { 1692 /* 1693 * no need to list the ones split off before HT 1694 * or generated here 1695 */ 1696 WLAN_EID_BSS_COEX_2040, 1697 WLAN_EID_EXT_CAPABILITY, 1698 WLAN_EID_QOS_TRAFFIC_CAPA, 1699 WLAN_EID_TIM_BCAST_REQ, 1700 WLAN_EID_INTERWORKING, 1701 /* 60 GHz (Multi-band, DMG, MMS) can't happen */ 1702 }; 1703 size_t noffset; 1704 1705 if (!elems_len) 1706 return offset; 1707 1708 /* RIC already taken care of in ieee80211_add_before_ht_elems() */ 1709 noffset = ieee80211_ie_split(elems, elems_len, 1710 before_vht, ARRAY_SIZE(before_vht), 1711 offset); 1712 skb_put_data(skb, elems + offset, noffset - offset); 1713 1714 return noffset; 1715 } 1716 1717 static size_t ieee80211_add_before_he_elems(struct sk_buff *skb, 1718 const u8 *elems, 1719 size_t elems_len, 1720 size_t offset) 1721 { 1722 static const u8 before_he[] = { 1723 /* 1724 * no need to list the ones split off before VHT 1725 * or generated here 1726 */ 1727 WLAN_EID_OPMODE_NOTIF, 1728 WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE, 1729 /* 11ai elements */ 1730 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION, 1731 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY, 1732 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM, 1733 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER, 1734 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN, 1735 /* TODO: add 11ah/11aj/11ak elements */ 1736 }; 1737 size_t noffset; 1738 1739 if (!elems_len) 1740 return offset; 1741 1742 /* RIC already taken care of in ieee80211_add_before_ht_elems() */ 1743 noffset = ieee80211_ie_split(elems, elems_len, 1744 before_he, ARRAY_SIZE(before_he), 1745 offset); 1746 skb_put_data(skb, elems + offset, noffset - offset); 1747 1748 return noffset; 1749 } 1750 1751 static size_t ieee80211_add_before_reg_conn(struct sk_buff *skb, 1752 const u8 *elems, size_t elems_len, 1753 size_t offset) 1754 { 1755 static const u8 before_reg_conn[] = { 1756 /* 1757 * no need to list the ones split off before HE 1758 * or generated here 1759 */ 1760 WLAN_EID_EXTENSION, WLAN_EID_EXT_DH_PARAMETER, 1761 WLAN_EID_EXTENSION, WLAN_EID_EXT_KNOWN_STA_IDENTIFCATION, 1762 }; 1763 size_t noffset; 1764 1765 if (!elems_len) 1766 return offset; 1767 1768 noffset = ieee80211_ie_split(elems, elems_len, before_reg_conn, 1769 ARRAY_SIZE(before_reg_conn), offset); 1770 skb_put_data(skb, elems + offset, noffset - offset); 1771 1772 return noffset; 1773 } 1774 1775 #define PRESENT_ELEMS_MAX 8 1776 #define PRESENT_ELEM_EXT_OFFS 0x100 1777 1778 static void 1779 ieee80211_assoc_add_ml_elem(struct ieee80211_sub_if_data *sdata, 1780 struct sk_buff *skb, u16 capab, 1781 const struct element *ext_capa, 1782 const u16 *present_elems, 1783 struct ieee80211_mgd_assoc_data *assoc_data); 1784 1785 static size_t 1786 ieee80211_add_link_elems(struct ieee80211_sub_if_data *sdata, 1787 struct sk_buff *skb, u16 *capab, 1788 const struct element *ext_capa, 1789 const u8 *extra_elems, 1790 size_t extra_elems_len, 1791 unsigned int link_id, 1792 struct ieee80211_link_data *link, 1793 u16 *present_elems, 1794 struct ieee80211_mgd_assoc_data *assoc_data) 1795 { 1796 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif); 1797 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss; 1798 struct ieee80211_channel *chan = cbss->channel; 1799 const struct ieee80211_sband_iftype_data *iftd; 1800 struct ieee80211_local *local = sdata->local; 1801 struct ieee80211_supported_band *sband; 1802 enum nl80211_chan_width width = NL80211_CHAN_WIDTH_20; 1803 struct ieee80211_chanctx_conf *chanctx_conf; 1804 enum ieee80211_smps_mode smps_mode; 1805 u16 orig_capab = *capab; 1806 size_t offset = 0; 1807 int present_elems_len = 0; 1808 u8 *pos; 1809 int i; 1810 1811 #define ADD_PRESENT_ELEM(id) do { \ 1812 /* need a last for termination - we use 0 == SSID */ \ 1813 if (!WARN_ON(present_elems_len >= PRESENT_ELEMS_MAX - 1)) \ 1814 present_elems[present_elems_len++] = (id); \ 1815 } while (0) 1816 #define ADD_PRESENT_EXT_ELEM(id) ADD_PRESENT_ELEM(PRESENT_ELEM_EXT_OFFS | (id)) 1817 1818 if (link) 1819 smps_mode = link->smps_mode; 1820 else if (sdata->u.mgd.powersave) 1821 smps_mode = IEEE80211_SMPS_DYNAMIC; 1822 else 1823 smps_mode = IEEE80211_SMPS_OFF; 1824 1825 if (link) { 1826 /* 1827 * 5/10 MHz scenarios are only viable without MLO, in which 1828 * case this pointer should be used ... All of this is a bit 1829 * unclear though, not sure this even works at all. 1830 */ 1831 rcu_read_lock(); 1832 chanctx_conf = rcu_dereference(link->conf->chanctx_conf); 1833 if (chanctx_conf) 1834 width = chanctx_conf->def.width; 1835 rcu_read_unlock(); 1836 } 1837 1838 sband = local->hw.wiphy->bands[chan->band]; 1839 iftd = ieee80211_get_sband_iftype_data(sband, iftype); 1840 1841 if (sband->band == NL80211_BAND_2GHZ) { 1842 *capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME; 1843 *capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; 1844 } 1845 1846 if ((cbss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) && 1847 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT)) 1848 *capab |= WLAN_CAPABILITY_SPECTRUM_MGMT; 1849 1850 if (sband->band != NL80211_BAND_S1GHZ) 1851 ieee80211_assoc_add_rates(local, skb, width, sband, assoc_data); 1852 1853 if (*capab & WLAN_CAPABILITY_SPECTRUM_MGMT || 1854 *capab & WLAN_CAPABILITY_RADIO_MEASURE) { 1855 struct cfg80211_chan_def chandef = { 1856 .width = width, 1857 .chan = chan, 1858 }; 1859 1860 pos = skb_put(skb, 4); 1861 *pos++ = WLAN_EID_PWR_CAPABILITY; 1862 *pos++ = 2; 1863 *pos++ = 0; /* min tx power */ 1864 /* max tx power */ 1865 *pos++ = ieee80211_chandef_max_power(&chandef); 1866 ADD_PRESENT_ELEM(WLAN_EID_PWR_CAPABILITY); 1867 } 1868 1869 /* 1870 * Per spec, we shouldn't include the list of channels if we advertise 1871 * support for extended channel switching, but we've always done that; 1872 * (for now?) apply this restriction only on the (new) 6 GHz band. 1873 */ 1874 if (*capab & WLAN_CAPABILITY_SPECTRUM_MGMT && 1875 (sband->band != NL80211_BAND_6GHZ || 1876 !ext_capa || ext_capa->datalen < 1 || 1877 !(ext_capa->data[0] & WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING))) { 1878 /* TODO: get this in reg domain format */ 1879 pos = skb_put(skb, 2 * sband->n_channels + 2); 1880 *pos++ = WLAN_EID_SUPPORTED_CHANNELS; 1881 *pos++ = 2 * sband->n_channels; 1882 for (i = 0; i < sband->n_channels; i++) { 1883 int cf = sband->channels[i].center_freq; 1884 1885 *pos++ = ieee80211_frequency_to_channel(cf); 1886 *pos++ = 1; /* one channel in the subband*/ 1887 } 1888 ADD_PRESENT_ELEM(WLAN_EID_SUPPORTED_CHANNELS); 1889 } 1890 1891 /* if present, add any custom IEs that go before HT */ 1892 offset = ieee80211_add_before_ht_elems(skb, extra_elems, 1893 extra_elems_len, 1894 offset); 1895 1896 if (sband->band != NL80211_BAND_6GHZ && 1897 assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_HT) { 1898 ieee80211_add_ht_ie(sdata, skb, 1899 assoc_data->link[link_id].ap_ht_param, 1900 sband, chan, smps_mode, 1901 &assoc_data->link[link_id].conn); 1902 ADD_PRESENT_ELEM(WLAN_EID_HT_CAPABILITY); 1903 } 1904 1905 /* if present, add any custom IEs that go before VHT */ 1906 offset = ieee80211_add_before_vht_elems(skb, extra_elems, 1907 extra_elems_len, 1908 offset); 1909 1910 if (sband->band != NL80211_BAND_6GHZ && 1911 assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_VHT && 1912 sband->vht_cap.vht_supported) { 1913 bool mu_mimo_owner = 1914 ieee80211_add_vht_ie(sdata, skb, sband, 1915 &assoc_data->link[link_id].ap_vht_cap, 1916 &assoc_data->link[link_id].conn); 1917 1918 if (link) 1919 link->conf->mu_mimo_owner = mu_mimo_owner; 1920 ADD_PRESENT_ELEM(WLAN_EID_VHT_CAPABILITY); 1921 } 1922 1923 /* if present, add any custom IEs that go before HE */ 1924 offset = ieee80211_add_before_he_elems(skb, extra_elems, 1925 extra_elems_len, 1926 offset); 1927 1928 if (assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_HE) { 1929 ieee80211_put_he_cap(skb, sdata, sband, 1930 &assoc_data->link[link_id].conn); 1931 ADD_PRESENT_EXT_ELEM(WLAN_EID_EXT_HE_CAPABILITY); 1932 if (sband->band == NL80211_BAND_6GHZ) 1933 ieee80211_put_he_6ghz_cap(skb, sdata, smps_mode); 1934 } 1935 1936 /* 1937 * if present, add any custom IEs that go before regulatory 1938 * connectivity element 1939 */ 1940 offset = ieee80211_add_before_reg_conn(skb, extra_elems, 1941 extra_elems_len, offset); 1942 1943 if (sband->band == NL80211_BAND_6GHZ) { 1944 /* 1945 * as per Section E.2.7 of IEEE 802.11 REVme D7.0, non-AP STA 1946 * capable of operating on the 6 GHz band shall transmit 1947 * regulatory connectivity element. 1948 */ 1949 ieee80211_put_reg_conn(skb, chan->flags); 1950 } 1951 1952 /* 1953 * careful - need to know about all the present elems before 1954 * calling ieee80211_assoc_add_ml_elem(), so add these if 1955 * we're going to put them after the ML element 1956 */ 1957 if (assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_EHT) 1958 ADD_PRESENT_EXT_ELEM(WLAN_EID_EXT_EHT_CAPABILITY); 1959 if (assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_UHR) 1960 ADD_PRESENT_EXT_ELEM(WLAN_EID_EXT_UHR_CAPA); 1961 1962 if (link_id == assoc_data->assoc_link_id) 1963 ieee80211_assoc_add_ml_elem(sdata, skb, orig_capab, ext_capa, 1964 present_elems, assoc_data); 1965 1966 /* crash if somebody gets it wrong */ 1967 present_elems = NULL; 1968 1969 if (assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_EHT) 1970 ieee80211_put_eht_cap(skb, sdata, sband, 1971 &assoc_data->link[link_id].conn); 1972 1973 if (assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_UHR) 1974 ieee80211_put_uhr_cap(skb, sdata, sband); 1975 1976 if (sband->band == NL80211_BAND_S1GHZ) { 1977 ieee80211_add_aid_request_ie(sdata, skb); 1978 ieee80211_add_s1g_capab_ie(sdata, &sband->s1g_cap, skb); 1979 } 1980 1981 if (iftd && iftd->vendor_elems.data && iftd->vendor_elems.len) 1982 skb_put_data(skb, iftd->vendor_elems.data, iftd->vendor_elems.len); 1983 1984 return offset; 1985 } 1986 1987 static void ieee80211_add_non_inheritance_elem(struct sk_buff *skb, 1988 const u16 *outer, 1989 const u16 *inner) 1990 { 1991 unsigned int skb_len = skb->len; 1992 bool at_extension = false; 1993 bool added = false; 1994 int i, j; 1995 u8 *len, *list_len = NULL; 1996 1997 skb_put_u8(skb, WLAN_EID_EXTENSION); 1998 len = skb_put(skb, 1); 1999 skb_put_u8(skb, WLAN_EID_EXT_NON_INHERITANCE); 2000 2001 for (i = 0; i < PRESENT_ELEMS_MAX && outer[i]; i++) { 2002 u16 elem = outer[i]; 2003 bool have_inner = false; 2004 2005 /* should at least be sorted in the sense of normal -> ext */ 2006 WARN_ON(at_extension && elem < PRESENT_ELEM_EXT_OFFS); 2007 2008 /* switch to extension list */ 2009 if (!at_extension && elem >= PRESENT_ELEM_EXT_OFFS) { 2010 at_extension = true; 2011 if (!list_len) 2012 skb_put_u8(skb, 0); 2013 list_len = NULL; 2014 } 2015 2016 for (j = 0; j < PRESENT_ELEMS_MAX && inner[j]; j++) { 2017 if (elem == inner[j]) { 2018 have_inner = true; 2019 break; 2020 } 2021 } 2022 2023 if (have_inner) 2024 continue; 2025 2026 if (!list_len) { 2027 list_len = skb_put(skb, 1); 2028 *list_len = 0; 2029 } 2030 *list_len += 1; 2031 skb_put_u8(skb, (u8)elem); 2032 added = true; 2033 } 2034 2035 /* if we added a list but no extension list, make a zero-len one */ 2036 if (added && (!at_extension || !list_len)) 2037 skb_put_u8(skb, 0); 2038 2039 /* if nothing added remove extension element completely */ 2040 if (!added) 2041 skb_trim(skb, skb_len); 2042 else 2043 *len = skb->len - skb_len - 2; 2044 } 2045 2046 static void 2047 ieee80211_assoc_add_ml_elem(struct ieee80211_sub_if_data *sdata, 2048 struct sk_buff *skb, u16 capab, 2049 const struct element *ext_capa, 2050 const u16 *outer_present_elems, 2051 struct ieee80211_mgd_assoc_data *assoc_data) 2052 { 2053 struct ieee80211_local *local = sdata->local; 2054 struct ieee80211_multi_link_elem *ml_elem; 2055 struct ieee80211_mle_basic_common_info *common; 2056 const struct wiphy_iftype_ext_capab *ift_ext_capa; 2057 __le16 eml_capa = 0, mld_capa_ops = 0; 2058 unsigned int link_id; 2059 u8 *ml_elem_len; 2060 void *capab_pos; 2061 2062 if (!ieee80211_vif_is_mld(&sdata->vif)) 2063 return; 2064 2065 ift_ext_capa = cfg80211_get_iftype_ext_capa(local->hw.wiphy, 2066 ieee80211_vif_type_p2p(&sdata->vif)); 2067 if (ift_ext_capa) { 2068 eml_capa = cpu_to_le16(ift_ext_capa->eml_capabilities); 2069 mld_capa_ops = cpu_to_le16(ift_ext_capa->mld_capa_and_ops); 2070 } 2071 2072 skb_put_u8(skb, WLAN_EID_EXTENSION); 2073 ml_elem_len = skb_put(skb, 1); 2074 skb_put_u8(skb, WLAN_EID_EXT_EHT_MULTI_LINK); 2075 ml_elem = skb_put(skb, sizeof(*ml_elem)); 2076 ml_elem->control = 2077 cpu_to_le16(IEEE80211_ML_CONTROL_TYPE_BASIC | 2078 IEEE80211_MLC_BASIC_PRES_MLD_CAPA_OP); 2079 common = skb_put(skb, sizeof(*common)); 2080 common->len = sizeof(*common) + 2081 2; /* MLD capa/ops */ 2082 memcpy(common->mld_mac_addr, sdata->vif.addr, ETH_ALEN); 2083 2084 /* add EML_CAPA only if needed, see Draft P802.11be_D2.1, 35.3.17 */ 2085 if (eml_capa & 2086 cpu_to_le16((IEEE80211_EML_CAP_EMLSR_SUPP | 2087 IEEE80211_EML_CAP_EMLMR_SUPPORT))) { 2088 common->len += 2; /* EML capabilities */ 2089 ml_elem->control |= 2090 cpu_to_le16(IEEE80211_MLC_BASIC_PRES_EML_CAPA); 2091 skb_put_data(skb, &eml_capa, sizeof(eml_capa)); 2092 } 2093 skb_put_data(skb, &mld_capa_ops, sizeof(mld_capa_ops)); 2094 2095 if (assoc_data->ext_mld_capa_ops) { 2096 ml_elem->control |= 2097 cpu_to_le16(IEEE80211_MLC_BASIC_PRES_EXT_MLD_CAPA_OP); 2098 common->len += 2; 2099 skb_put_data(skb, &assoc_data->ext_mld_capa_ops, 2100 sizeof(assoc_data->ext_mld_capa_ops)); 2101 } 2102 2103 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { 2104 u16 link_present_elems[PRESENT_ELEMS_MAX] = {}; 2105 const u8 *extra_elems; 2106 size_t extra_elems_len; 2107 size_t extra_used; 2108 u8 *subelem_len = NULL; 2109 __le16 ctrl; 2110 2111 if (!assoc_data->link[link_id].bss || 2112 link_id == assoc_data->assoc_link_id) 2113 continue; 2114 2115 extra_elems = assoc_data->link[link_id].elems; 2116 extra_elems_len = assoc_data->link[link_id].elems_len; 2117 2118 skb_put_u8(skb, IEEE80211_MLE_SUBELEM_PER_STA_PROFILE); 2119 subelem_len = skb_put(skb, 1); 2120 2121 ctrl = cpu_to_le16(link_id | 2122 IEEE80211_MLE_STA_CONTROL_COMPLETE_PROFILE | 2123 IEEE80211_MLE_STA_CONTROL_STA_MAC_ADDR_PRESENT); 2124 skb_put_data(skb, &ctrl, sizeof(ctrl)); 2125 skb_put_u8(skb, 1 + ETH_ALEN); /* STA Info Length */ 2126 skb_put_data(skb, assoc_data->link[link_id].addr, 2127 ETH_ALEN); 2128 /* 2129 * Now add the contents of the (re)association request, 2130 * but the "listen interval" and "current AP address" 2131 * (if applicable) are skipped. So we only have 2132 * the capability field (remember the position and fill 2133 * later), followed by the elements added below by 2134 * calling ieee80211_add_link_elems(). 2135 */ 2136 capab_pos = skb_put(skb, 2); 2137 2138 extra_used = ieee80211_add_link_elems(sdata, skb, &capab, 2139 ext_capa, 2140 extra_elems, 2141 extra_elems_len, 2142 link_id, NULL, 2143 link_present_elems, 2144 assoc_data); 2145 if (extra_elems) 2146 skb_put_data(skb, extra_elems + extra_used, 2147 extra_elems_len - extra_used); 2148 2149 put_unaligned_le16(capab, capab_pos); 2150 2151 ieee80211_add_non_inheritance_elem(skb, outer_present_elems, 2152 link_present_elems); 2153 2154 ieee80211_fragment_element(skb, subelem_len, 2155 IEEE80211_MLE_SUBELEM_FRAGMENT); 2156 } 2157 2158 ieee80211_fragment_element(skb, ml_elem_len, WLAN_EID_FRAGMENT); 2159 } 2160 2161 static int 2162 ieee80211_link_common_elems_size(struct ieee80211_sub_if_data *sdata, 2163 enum nl80211_iftype iftype, 2164 struct cfg80211_bss *cbss, 2165 size_t elems_len) 2166 { 2167 struct ieee80211_local *local = sdata->local; 2168 const struct ieee80211_sband_iftype_data *iftd; 2169 struct ieee80211_supported_band *sband; 2170 size_t size = 0; 2171 2172 if (!cbss) 2173 return size; 2174 2175 sband = local->hw.wiphy->bands[cbss->channel->band]; 2176 2177 /* add STA profile elements length */ 2178 size += elems_len; 2179 2180 /* and supported rates length */ 2181 size += 4 + sband->n_bitrates; 2182 2183 /* supported channels */ 2184 size += 2 + 2 * sband->n_channels; 2185 2186 iftd = ieee80211_get_sband_iftype_data(sband, iftype); 2187 if (iftd) 2188 size += iftd->vendor_elems.len; 2189 2190 /* power capability */ 2191 size += 4; 2192 2193 /* HT, VHT, HE, EHT */ 2194 size += 2 + sizeof(struct ieee80211_ht_cap); 2195 size += 2 + sizeof(struct ieee80211_vht_cap); 2196 size += 2 + 1 + sizeof(struct ieee80211_he_cap_elem) + 2197 sizeof(struct ieee80211_he_mcs_nss_supp) + 2198 IEEE80211_HE_PPE_THRES_MAX_LEN; 2199 2200 if (sband->band == NL80211_BAND_6GHZ) { 2201 size += 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa); 2202 /* reg connection */ 2203 size += 4; 2204 } 2205 2206 size += 2 + 1 + sizeof(struct ieee80211_eht_cap_elem) + 2207 sizeof(struct ieee80211_eht_mcs_nss_supp) + 2208 IEEE80211_EHT_PPE_THRES_MAX_LEN; 2209 2210 size += 2 + 1 + sizeof(struct ieee80211_uhr_cap) + 2211 sizeof(struct ieee80211_uhr_cap_phy); 2212 2213 return size; 2214 } 2215 2216 static int ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata) 2217 { 2218 struct ieee80211_local *local = sdata->local; 2219 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2220 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; 2221 struct ieee80211_link_data *link; 2222 struct sk_buff *skb; 2223 struct ieee80211_mgmt *mgmt; 2224 u8 *pos, qos_info, *ie_start; 2225 size_t offset, noffset; 2226 u16 capab = 0, link_capab; 2227 __le16 listen_int; 2228 struct element *ext_capa = NULL; 2229 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif); 2230 struct ieee80211_prep_tx_info info = {}; 2231 unsigned int link_id, n_links = 0; 2232 u16 present_elems[PRESENT_ELEMS_MAX] = {}; 2233 struct sta_info *sta; 2234 bool assoc_encrypt; 2235 void *capab_pos; 2236 size_t size; 2237 int ret; 2238 2239 /* we know it's writable, cast away the const */ 2240 if (assoc_data->ie_len) 2241 ext_capa = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, 2242 assoc_data->ie, 2243 assoc_data->ie_len); 2244 2245 lockdep_assert_wiphy(sdata->local->hw.wiphy); 2246 2247 size = local->hw.extra_tx_headroom + 2248 sizeof(*mgmt) + /* bit too much but doesn't matter */ 2249 2 + assoc_data->ssid_len + /* SSID */ 2250 assoc_data->ie_len + /* extra IEs */ 2251 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) + 2252 9; /* WMM */ 2253 2254 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { 2255 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss; 2256 size_t elems_len = assoc_data->link[link_id].elems_len; 2257 2258 if (!cbss) 2259 continue; 2260 2261 n_links++; 2262 2263 size += ieee80211_link_common_elems_size(sdata, iftype, cbss, 2264 elems_len); 2265 2266 /* non-inheritance element */ 2267 size += 2 + 2 + PRESENT_ELEMS_MAX; 2268 2269 /* should be the same across all BSSes */ 2270 if (cbss->capability & WLAN_CAPABILITY_PRIVACY) 2271 capab |= WLAN_CAPABILITY_PRIVACY; 2272 } 2273 2274 if (ieee80211_vif_is_mld(&sdata->vif)) { 2275 /* consider the multi-link element with STA profile */ 2276 size += sizeof(struct ieee80211_multi_link_elem); 2277 /* max common info field in basic multi-link element */ 2278 size += sizeof(struct ieee80211_mle_basic_common_info) + 2279 2 + /* capa & op */ 2280 2 + /* ext capa & op */ 2281 2; /* EML capa */ 2282 2283 /* The capability elements were already considered above */ 2284 size += (n_links - 1) * 2285 (1 + 1 + /* subelement ID/length */ 2286 2 + /* STA control */ 2287 1 + ETH_ALEN + 2 /* STA Info field */); 2288 } 2289 2290 link = sdata_dereference(sdata->link[assoc_data->assoc_link_id], sdata); 2291 if (WARN_ON(!link)) 2292 return -EINVAL; 2293 2294 if (WARN_ON(!assoc_data->link[assoc_data->assoc_link_id].bss)) 2295 return -EINVAL; 2296 2297 skb = alloc_skb(size, GFP_KERNEL); 2298 if (!skb) 2299 return -ENOMEM; 2300 2301 skb_reserve(skb, local->hw.extra_tx_headroom); 2302 2303 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM) 2304 capab |= WLAN_CAPABILITY_RADIO_MEASURE; 2305 2306 /* Set MBSSID support for HE AP if needed */ 2307 if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) && 2308 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HE && 2309 ext_capa && ext_capa->datalen >= 3) 2310 ext_capa->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT; 2311 2312 mgmt = skb_put_zero(skb, 24); 2313 memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN); 2314 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); 2315 memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN); 2316 2317 listen_int = cpu_to_le16(assoc_data->s1g ? 2318 ieee80211_encode_usf(local->hw.conf.listen_interval) : 2319 local->hw.conf.listen_interval); 2320 if (!is_zero_ether_addr(assoc_data->prev_ap_addr)) { 2321 skb_put(skb, 10); 2322 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 2323 IEEE80211_STYPE_REASSOC_REQ); 2324 capab_pos = &mgmt->u.reassoc_req.capab_info; 2325 mgmt->u.reassoc_req.listen_interval = listen_int; 2326 memcpy(mgmt->u.reassoc_req.current_ap, 2327 assoc_data->prev_ap_addr, ETH_ALEN); 2328 info.subtype = IEEE80211_STYPE_REASSOC_REQ; 2329 } else { 2330 skb_put(skb, 4); 2331 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 2332 IEEE80211_STYPE_ASSOC_REQ); 2333 capab_pos = &mgmt->u.assoc_req.capab_info; 2334 mgmt->u.assoc_req.listen_interval = listen_int; 2335 info.subtype = IEEE80211_STYPE_ASSOC_REQ; 2336 } 2337 2338 /* SSID */ 2339 pos = skb_put(skb, 2 + assoc_data->ssid_len); 2340 ie_start = pos; 2341 *pos++ = WLAN_EID_SSID; 2342 *pos++ = assoc_data->ssid_len; 2343 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len); 2344 2345 /* 2346 * This bit is technically reserved, so it shouldn't matter for either 2347 * the AP or us, but it also means we shouldn't set it. However, we've 2348 * always set it in the past, and apparently some EHT APs check that 2349 * we don't set it. To avoid interoperability issues with old APs that 2350 * for some reason check it and want it to be set, set the bit for all 2351 * pre-EHT connections as we used to do. 2352 */ 2353 if (link->u.mgd.conn.mode < IEEE80211_CONN_MODE_EHT && 2354 !ieee80211_hw_check(&local->hw, STRICT)) 2355 capab |= WLAN_CAPABILITY_ESS; 2356 2357 /* add the elements for the assoc (main) link */ 2358 link_capab = capab; 2359 offset = ieee80211_add_link_elems(sdata, skb, &link_capab, 2360 ext_capa, 2361 assoc_data->ie, 2362 assoc_data->ie_len, 2363 assoc_data->assoc_link_id, link, 2364 present_elems, assoc_data); 2365 put_unaligned_le16(link_capab, capab_pos); 2366 2367 /* if present, add any custom non-vendor IEs */ 2368 if (assoc_data->ie_len) { 2369 noffset = ieee80211_ie_split_vendor(assoc_data->ie, 2370 assoc_data->ie_len, 2371 offset); 2372 skb_put_data(skb, assoc_data->ie + offset, noffset - offset); 2373 offset = noffset; 2374 } 2375 2376 if (assoc_data->wmm) { 2377 if (assoc_data->uapsd) { 2378 qos_info = ifmgd->uapsd_queues; 2379 qos_info |= (ifmgd->uapsd_max_sp_len << 2380 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT); 2381 } else { 2382 qos_info = 0; 2383 } 2384 2385 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info); 2386 } 2387 2388 /* add any remaining custom (i.e. vendor specific here) IEs */ 2389 if (assoc_data->ie_len) { 2390 noffset = assoc_data->ie_len; 2391 skb_put_data(skb, assoc_data->ie + offset, noffset - offset); 2392 } 2393 2394 if (assoc_data->fils_kek_len) { 2395 ret = fils_encrypt_assoc_req(skb, assoc_data); 2396 if (ret < 0) { 2397 dev_kfree_skb(skb); 2398 return ret; 2399 } 2400 } 2401 2402 pos = skb_tail_pointer(skb); 2403 kfree(ifmgd->assoc_req_ies); 2404 ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC); 2405 if (!ifmgd->assoc_req_ies) { 2406 dev_kfree_skb(skb); 2407 return -ENOMEM; 2408 } 2409 2410 ifmgd->assoc_req_ies_len = pos - ie_start; 2411 2412 info.link_id = assoc_data->assoc_link_id; 2413 drv_mgd_prepare_tx(local, sdata, &info); 2414 2415 sta = sta_info_get_bss(sdata, sdata->vif.cfg.ap_addr); 2416 2417 assoc_encrypt = sta && sta->sta.epp_peer && 2418 wiphy_dereference(sdata->local->hw.wiphy, 2419 sta->ptk[sta->ptk_idx]); 2420 2421 if (!assoc_encrypt) 2422 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; 2423 2424 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) 2425 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS | 2426 IEEE80211_TX_INTFL_MLME_CONN_TX; 2427 ieee80211_tx_skb(sdata, skb); 2428 2429 return 0; 2430 } 2431 2432 void ieee80211_send_pspoll(struct ieee80211_local *local, 2433 struct ieee80211_sub_if_data *sdata) 2434 { 2435 struct ieee80211_pspoll *pspoll; 2436 struct sk_buff *skb; 2437 2438 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif); 2439 if (!skb) 2440 return; 2441 2442 pspoll = (struct ieee80211_pspoll *) skb->data; 2443 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); 2444 2445 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; 2446 ieee80211_tx_skb(sdata, skb); 2447 } 2448 2449 void ieee80211_send_nullfunc(struct ieee80211_local *local, 2450 struct ieee80211_sub_if_data *sdata, 2451 bool powersave) 2452 { 2453 struct sk_buff *skb; 2454 struct ieee80211_hdr_3addr *nullfunc; 2455 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2456 2457 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif, -1, 2458 !ieee80211_hw_check(&local->hw, 2459 DOESNT_SUPPORT_QOS_NDP)); 2460 if (!skb) 2461 return; 2462 2463 nullfunc = (struct ieee80211_hdr_3addr *) skb->data; 2464 if (powersave) 2465 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); 2466 2467 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT | 2468 IEEE80211_TX_INTFL_OFFCHAN_TX_OK; 2469 2470 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) 2471 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; 2472 2473 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) 2474 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE; 2475 2476 ieee80211_tx_skb(sdata, skb); 2477 } 2478 2479 void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local, 2480 struct ieee80211_sub_if_data *sdata) 2481 { 2482 struct sk_buff *skb; 2483 struct ieee80211_hdr *nullfunc; 2484 __le16 fc; 2485 2486 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) 2487 return; 2488 2489 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30); 2490 if (!skb) 2491 return; 2492 2493 skb_reserve(skb, local->hw.extra_tx_headroom); 2494 2495 nullfunc = skb_put_zero(skb, 30); 2496 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | 2497 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); 2498 nullfunc->frame_control = fc; 2499 memcpy(nullfunc->addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN); 2500 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); 2501 memcpy(nullfunc->addr3, sdata->deflink.u.mgd.bssid, ETH_ALEN); 2502 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN); 2503 2504 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; 2505 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE; 2506 ieee80211_tx_skb(sdata, skb); 2507 } 2508 2509 /* spectrum management related things */ 2510 static void ieee80211_csa_switch_work(struct wiphy *wiphy, 2511 struct wiphy_work *work) 2512 { 2513 struct ieee80211_link_data *link = 2514 container_of(work, struct ieee80211_link_data, 2515 u.mgd.csa.switch_work.work); 2516 struct ieee80211_sub_if_data *sdata = link->sdata; 2517 struct ieee80211_local *local = sdata->local; 2518 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2519 int ret; 2520 2521 if (!ieee80211_sdata_running(sdata)) 2522 return; 2523 2524 lockdep_assert_wiphy(local->hw.wiphy); 2525 2526 if (!ifmgd->associated) 2527 return; 2528 2529 if (!link->conf->csa_active) 2530 return; 2531 2532 /* 2533 * If the link isn't active (now), we cannot wait for beacons, won't 2534 * have a reserved chanctx, etc. Just switch over the chandef and 2535 * update cfg80211 directly. 2536 */ 2537 if (!ieee80211_vif_link_active(&sdata->vif, link->link_id)) { 2538 struct link_sta_info *link_sta; 2539 struct sta_info *ap_sta; 2540 2541 link->conf->chanreq = link->csa.chanreq; 2542 cfg80211_ch_switch_notify(sdata->dev, &link->csa.chanreq.oper, 2543 link->link_id); 2544 link->conf->csa_active = false; 2545 2546 ap_sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr); 2547 if (WARN_ON(!ap_sta)) 2548 return; 2549 2550 link_sta = wiphy_dereference(wiphy, 2551 ap_sta->link[link->link_id]); 2552 if (WARN_ON(!link_sta)) 2553 return; 2554 2555 link_sta->pub->bandwidth = 2556 _ieee80211_sta_cur_vht_bw(link_sta, 2557 &link->csa.chanreq.oper); 2558 return; 2559 } 2560 2561 /* 2562 * using reservation isn't immediate as it may be deferred until later 2563 * with multi-vif. once reservation is complete it will re-schedule the 2564 * work with no reserved_chanctx so verify chandef to check if it 2565 * completed successfully 2566 */ 2567 2568 if (link->reserved_chanctx) { 2569 /* 2570 * with multi-vif csa driver may call ieee80211_csa_finish() 2571 * many times while waiting for other interfaces to use their 2572 * reservations 2573 */ 2574 if (link->reserved_ready) 2575 return; 2576 2577 ret = ieee80211_link_use_reserved_context(link); 2578 if (ret) { 2579 link_info(link, 2580 "failed to use reserved channel context, disconnecting (err=%d)\n", 2581 ret); 2582 wiphy_work_queue(sdata->local->hw.wiphy, 2583 &ifmgd->csa_connection_drop_work); 2584 } 2585 return; 2586 } 2587 2588 if (!ieee80211_chanreq_identical(&link->conf->chanreq, 2589 &link->csa.chanreq)) { 2590 link_info(link, 2591 "failed to finalize channel switch, disconnecting\n"); 2592 wiphy_work_queue(sdata->local->hw.wiphy, 2593 &ifmgd->csa_connection_drop_work); 2594 return; 2595 } 2596 2597 link->u.mgd.csa.waiting_bcn = true; 2598 2599 /* 2600 * The next beacon really should always be different, so this should 2601 * have no effect whatsoever. However, some APs (we observed this in 2602 * an Asus AXE11000), the beacon after the CSA might be identical to 2603 * the last beacon on the old channel - in this case we'd ignore it. 2604 * Resetting the CRC will lead us to handle it better (albeit with a 2605 * disconnect, but clearly the AP is broken.) 2606 */ 2607 link->u.mgd.beacon_crc_valid = false; 2608 2609 /* apply new TPE restrictions immediately on the new channel */ 2610 if (link->u.mgd.csa.ap_chandef.chan->band == NL80211_BAND_6GHZ && 2611 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HE) { 2612 ieee80211_rearrange_tpe(&link->u.mgd.csa.tpe, 2613 &link->u.mgd.csa.ap_chandef, 2614 &link->conf->chanreq.oper); 2615 if (memcmp(&link->conf->tpe, &link->u.mgd.csa.tpe, 2616 sizeof(link->u.mgd.csa.tpe))) { 2617 link->conf->tpe = link->u.mgd.csa.tpe; 2618 ieee80211_link_info_change_notify(sdata, link, 2619 BSS_CHANGED_TPE); 2620 } 2621 } 2622 2623 /* 2624 * It is not necessary to reset these timers if any link does not 2625 * have an active CSA and that link still receives the beacons 2626 * when other links have active CSA. 2627 */ 2628 for_each_link_data(sdata, link) { 2629 if (!link->conf->csa_active) 2630 return; 2631 } 2632 2633 /* 2634 * Reset the beacon monitor and connection monitor timers when CSA 2635 * is active for all links in MLO when channel switch occurs in all 2636 * the links. 2637 */ 2638 ieee80211_sta_reset_beacon_monitor(sdata); 2639 ieee80211_sta_reset_conn_monitor(sdata); 2640 } 2641 2642 static void ieee80211_chswitch_post_beacon(struct ieee80211_link_data *link) 2643 { 2644 struct ieee80211_sub_if_data *sdata = link->sdata; 2645 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2646 int ret; 2647 2648 lockdep_assert_wiphy(sdata->local->hw.wiphy); 2649 2650 WARN_ON(!link->conf->csa_active); 2651 2652 ieee80211_vif_unblock_queues_csa(sdata); 2653 2654 link->conf->csa_active = false; 2655 link->u.mgd.csa.blocked_tx = false; 2656 link->u.mgd.csa.waiting_bcn = false; 2657 2658 ret = drv_post_channel_switch(link); 2659 if (ret) { 2660 link_info(link, 2661 "driver post channel switch failed, disconnecting\n"); 2662 wiphy_work_queue(sdata->local->hw.wiphy, 2663 &ifmgd->csa_connection_drop_work); 2664 return; 2665 } 2666 2667 cfg80211_ch_switch_notify(sdata->dev, &link->conf->chanreq.oper, 2668 link->link_id); 2669 } 2670 2671 void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success, 2672 unsigned int link_id) 2673 { 2674 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 2675 2676 trace_api_chswitch_done(sdata, success, link_id); 2677 2678 rcu_read_lock(); 2679 2680 if (!success) { 2681 sdata_info(sdata, 2682 "driver channel switch failed (link %d), disconnecting\n", 2683 link_id); 2684 wiphy_work_queue(sdata->local->hw.wiphy, 2685 &sdata->u.mgd.csa_connection_drop_work); 2686 } else { 2687 struct ieee80211_link_data *link = 2688 rcu_dereference(sdata->link[link_id]); 2689 2690 if (WARN_ON(!link)) { 2691 rcu_read_unlock(); 2692 return; 2693 } 2694 2695 wiphy_hrtimer_work_queue(sdata->local->hw.wiphy, 2696 &link->u.mgd.csa.switch_work, 0); 2697 } 2698 2699 rcu_read_unlock(); 2700 } 2701 EXPORT_SYMBOL(ieee80211_chswitch_done); 2702 2703 static void 2704 ieee80211_sta_abort_chanswitch(struct ieee80211_link_data *link) 2705 { 2706 struct ieee80211_sub_if_data *sdata = link->sdata; 2707 struct ieee80211_local *local = sdata->local; 2708 2709 lockdep_assert_wiphy(local->hw.wiphy); 2710 2711 if (!local->ops->abort_channel_switch) 2712 return; 2713 2714 if (rcu_access_pointer(link->conf->chanctx_conf)) 2715 ieee80211_link_unreserve_chanctx(link); 2716 2717 ieee80211_vif_unblock_queues_csa(sdata); 2718 2719 link->conf->csa_active = false; 2720 link->u.mgd.csa.blocked_tx = false; 2721 2722 drv_abort_channel_switch(link); 2723 } 2724 2725 struct sta_csa_rnr_iter_data { 2726 struct ieee80211_link_data *link; 2727 struct ieee80211_channel *chan; 2728 u8 mld_id; 2729 }; 2730 2731 static enum cfg80211_rnr_iter_ret 2732 ieee80211_sta_csa_rnr_iter(void *_data, u8 type, 2733 const struct ieee80211_neighbor_ap_info *info, 2734 const u8 *tbtt_info, u8 tbtt_info_len) 2735 { 2736 struct sta_csa_rnr_iter_data *data = _data; 2737 struct ieee80211_link_data *link = data->link; 2738 struct ieee80211_sub_if_data *sdata = link->sdata; 2739 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2740 const struct ieee80211_tbtt_info_ge_11 *ti; 2741 enum nl80211_band band; 2742 unsigned int center_freq; 2743 int link_id; 2744 2745 if (type != IEEE80211_TBTT_INFO_TYPE_TBTT) 2746 return RNR_ITER_CONTINUE; 2747 2748 if (tbtt_info_len < sizeof(*ti)) 2749 return RNR_ITER_CONTINUE; 2750 2751 ti = (const void *)tbtt_info; 2752 2753 if (ti->mld_params.mld_id != data->mld_id) 2754 return RNR_ITER_CONTINUE; 2755 2756 link_id = le16_get_bits(ti->mld_params.params, 2757 IEEE80211_RNR_MLD_PARAMS_LINK_ID); 2758 if (link_id != data->link->link_id) 2759 return RNR_ITER_CONTINUE; 2760 2761 /* we found the entry for our link! */ 2762 2763 /* this AP is confused, it had this right before ... just disconnect */ 2764 if (!ieee80211_operating_class_to_band(info->op_class, &band)) { 2765 link_info(link, 2766 "AP now has invalid operating class in RNR, disconnect\n"); 2767 wiphy_work_queue(sdata->local->hw.wiphy, 2768 &ifmgd->csa_connection_drop_work); 2769 return RNR_ITER_BREAK; 2770 } 2771 2772 center_freq = ieee80211_channel_to_frequency(info->channel, band); 2773 data->chan = ieee80211_get_channel(sdata->local->hw.wiphy, center_freq); 2774 2775 return RNR_ITER_BREAK; 2776 } 2777 2778 static void 2779 ieee80211_sta_other_link_csa_disappeared(struct ieee80211_link_data *link, 2780 struct ieee802_11_elems *elems) 2781 { 2782 struct ieee80211_sub_if_data *sdata = link->sdata; 2783 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2784 struct sta_csa_rnr_iter_data data = { 2785 .link = link, 2786 }; 2787 2788 /* 2789 * If we get here, we see a beacon from another link without 2790 * CSA still being reported for it, so now we have to check 2791 * if the CSA was aborted or completed. This may not even be 2792 * perfectly possible if the CSA was only done for changing 2793 * the puncturing, but in that case if the link in inactive 2794 * we don't really care, and if it's an active link (or when 2795 * it's activated later) we'll get a beacon and adjust. 2796 */ 2797 2798 if (WARN_ON(!elems->ml_basic)) 2799 return; 2800 2801 data.mld_id = ieee80211_mle_get_mld_id((const void *)elems->ml_basic); 2802 2803 /* 2804 * So in order to do this, iterate the RNR element(s) and see 2805 * what channel is reported now. 2806 */ 2807 cfg80211_iter_rnr(elems->ie_start, elems->total_len, 2808 ieee80211_sta_csa_rnr_iter, &data); 2809 2810 if (!data.chan) { 2811 link_info(link, 2812 "couldn't find (valid) channel in RNR for CSA, disconnect\n"); 2813 wiphy_work_queue(sdata->local->hw.wiphy, 2814 &ifmgd->csa_connection_drop_work); 2815 return; 2816 } 2817 2818 /* 2819 * If it doesn't match the CSA, then assume it aborted. This 2820 * may erroneously detect that it was _not_ aborted when it 2821 * was in fact aborted, but only changed the bandwidth or the 2822 * puncturing configuration, but we don't have enough data to 2823 * detect that. 2824 */ 2825 if (data.chan != link->csa.chanreq.oper.chan) 2826 ieee80211_sta_abort_chanswitch(link); 2827 } 2828 2829 enum ieee80211_csa_source { 2830 IEEE80211_CSA_SOURCE_BEACON, 2831 IEEE80211_CSA_SOURCE_OTHER_LINK, 2832 IEEE80211_CSA_SOURCE_PROT_ACTION, 2833 IEEE80211_CSA_SOURCE_UNPROT_ACTION, 2834 }; 2835 2836 static void 2837 ieee80211_sta_process_chanswitch(struct ieee80211_link_data *link, 2838 u64 timestamp, u32 device_timestamp, 2839 struct ieee802_11_elems *full_elems, 2840 struct ieee802_11_elems *csa_elems, 2841 enum ieee80211_csa_source source) 2842 { 2843 struct ieee80211_sub_if_data *sdata = link->sdata; 2844 struct ieee80211_local *local = sdata->local; 2845 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2846 struct ieee80211_chanctx *chanctx = NULL; 2847 struct ieee80211_chanctx_conf *conf; 2848 struct ieee80211_csa_ie csa_ie = {}; 2849 struct ieee80211_channel_switch ch_switch = { 2850 .link_id = link->link_id, 2851 .timestamp = timestamp, 2852 .device_timestamp = device_timestamp, 2853 }; 2854 u32 csa_time_tu; 2855 ktime_t now; 2856 int res; 2857 2858 lockdep_assert_wiphy(local->hw.wiphy); 2859 2860 if (csa_elems) { 2861 struct cfg80211_bss *cbss = link->conf->bss; 2862 enum nl80211_band current_band; 2863 struct ieee80211_bss *bss; 2864 2865 if (WARN_ON(!cbss)) 2866 return; 2867 2868 current_band = cbss->channel->band; 2869 bss = (void *)cbss->priv; 2870 2871 res = ieee80211_parse_ch_switch_ie(sdata, csa_elems, 2872 current_band, 2873 bss->vht_cap_info, 2874 &link->u.mgd.conn, 2875 link->u.mgd.bssid, 2876 source == IEEE80211_CSA_SOURCE_UNPROT_ACTION, 2877 &csa_ie); 2878 if (res == 0) { 2879 ch_switch.block_tx = csa_ie.mode; 2880 ch_switch.chandef = csa_ie.chanreq.oper; 2881 ch_switch.count = csa_ie.count; 2882 ch_switch.delay = csa_ie.max_switch_time; 2883 } 2884 2885 link->u.mgd.csa.tpe = csa_elems->csa_tpe; 2886 } else { 2887 /* 2888 * If there was no per-STA profile for this link, we 2889 * get called with csa_elems == NULL. This of course means 2890 * there are no CSA elements, so set res=1 indicating 2891 * no more CSA. 2892 */ 2893 res = 1; 2894 } 2895 2896 if (res < 0) { 2897 /* ignore this case, not a protected frame */ 2898 if (source == IEEE80211_CSA_SOURCE_UNPROT_ACTION) 2899 return; 2900 goto drop_connection; 2901 } 2902 2903 if (link->conf->csa_active) { 2904 switch (source) { 2905 case IEEE80211_CSA_SOURCE_PROT_ACTION: 2906 case IEEE80211_CSA_SOURCE_UNPROT_ACTION: 2907 /* already processing - disregard action frames */ 2908 return; 2909 case IEEE80211_CSA_SOURCE_BEACON: 2910 if (link->u.mgd.csa.waiting_bcn) { 2911 ieee80211_chswitch_post_beacon(link); 2912 /* 2913 * If the CSA is still present after the switch 2914 * we need to consider it as a new CSA (possibly 2915 * to self). This happens by not returning here 2916 * so we'll get to the check below. 2917 */ 2918 } else if (res) { 2919 ieee80211_sta_abort_chanswitch(link); 2920 return; 2921 } else { 2922 drv_channel_switch_rx_beacon(sdata, &ch_switch); 2923 return; 2924 } 2925 break; 2926 case IEEE80211_CSA_SOURCE_OTHER_LINK: 2927 /* active link: we want to see the beacon to continue */ 2928 if (ieee80211_vif_link_active(&sdata->vif, 2929 link->link_id)) 2930 return; 2931 2932 /* switch work ran, so just complete the process */ 2933 if (link->u.mgd.csa.waiting_bcn) { 2934 ieee80211_chswitch_post_beacon(link); 2935 /* 2936 * If the CSA is still present after the switch 2937 * we need to consider it as a new CSA (possibly 2938 * to self). This happens by not returning here 2939 * so we'll get to the check below. 2940 */ 2941 break; 2942 } 2943 2944 /* link still has CSA but we already know, do nothing */ 2945 if (!res) 2946 return; 2947 2948 /* check in the RNR if the CSA aborted */ 2949 ieee80211_sta_other_link_csa_disappeared(link, 2950 full_elems); 2951 return; 2952 } 2953 } 2954 2955 /* no active CSA nor a new one */ 2956 if (res) { 2957 /* 2958 * However, we may have stopped queues when receiving a public 2959 * action frame that couldn't be protected, if it had the quiet 2960 * bit set. This is a trade-off, we want to be quiet as soon as 2961 * possible, but also don't trust the public action frame much, 2962 * as it can't be protected. 2963 */ 2964 if (unlikely(link->u.mgd.csa.blocked_tx)) { 2965 link->u.mgd.csa.blocked_tx = false; 2966 ieee80211_vif_unblock_queues_csa(sdata); 2967 } 2968 return; 2969 } 2970 2971 /* 2972 * We don't really trust public action frames, but block queues (go to 2973 * quiet mode) for them anyway, we should get a beacon soon to either 2974 * know what the CSA really is, or figure out the public action frame 2975 * was actually an attack. 2976 */ 2977 if (source == IEEE80211_CSA_SOURCE_UNPROT_ACTION) { 2978 if (csa_ie.mode) { 2979 link->u.mgd.csa.blocked_tx = true; 2980 ieee80211_vif_block_queues_csa(sdata); 2981 } 2982 return; 2983 } 2984 2985 if (link->conf->chanreq.oper.chan->band != 2986 csa_ie.chanreq.oper.chan->band) { 2987 link_info(link, 2988 "AP %pM switches to different band (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n", 2989 link->u.mgd.bssid, 2990 csa_ie.chanreq.oper.chan->center_freq, 2991 csa_ie.chanreq.oper.width, 2992 csa_ie.chanreq.oper.center_freq1, 2993 csa_ie.chanreq.oper.center_freq2); 2994 goto drop_connection; 2995 } 2996 2997 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chanreq.oper, 2998 IEEE80211_CHAN_DISABLED)) { 2999 link_info(link, 3000 "AP %pM switches to unsupported channel (%d.%03d MHz, width:%d, CF1/2: %d.%03d/%d MHz), disconnecting\n", 3001 link->u.mgd.bssid, 3002 csa_ie.chanreq.oper.chan->center_freq, 3003 csa_ie.chanreq.oper.chan->freq_offset, 3004 csa_ie.chanreq.oper.width, 3005 csa_ie.chanreq.oper.center_freq1, 3006 csa_ie.chanreq.oper.freq1_offset, 3007 csa_ie.chanreq.oper.center_freq2); 3008 goto drop_connection; 3009 } 3010 3011 if (cfg80211_chandef_identical(&csa_ie.chanreq.oper, 3012 &link->conf->chanreq.oper) && 3013 (!csa_ie.mode || source != IEEE80211_CSA_SOURCE_BEACON)) { 3014 if (link->u.mgd.csa.ignored_same_chan) 3015 return; 3016 link_info(link, 3017 "AP %pM tries to chanswitch to same channel, ignore\n", 3018 link->u.mgd.bssid); 3019 link->u.mgd.csa.ignored_same_chan = true; 3020 return; 3021 } 3022 3023 /* 3024 * Drop all TDLS peers on the affected link - either we disconnect or 3025 * move to a different channel from this point on. There's no telling 3026 * what our peer will do. 3027 * The TDLS WIDER_BW scenario is also problematic, as peers might now 3028 * have an incompatible wider chandef. 3029 */ 3030 ieee80211_teardown_tdls_peers(link); 3031 3032 conf = rcu_dereference_protected(link->conf->chanctx_conf, 3033 lockdep_is_held(&local->hw.wiphy->mtx)); 3034 if (ieee80211_vif_link_active(&sdata->vif, link->link_id) && !conf) { 3035 link_info(link, 3036 "no channel context assigned to vif?, disconnecting\n"); 3037 goto drop_connection; 3038 } 3039 3040 if (conf) 3041 chanctx = container_of(conf, struct ieee80211_chanctx, conf); 3042 3043 if (!ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) { 3044 link_info(link, 3045 "driver doesn't support chan-switch with channel contexts\n"); 3046 goto drop_connection; 3047 } 3048 3049 if (drv_pre_channel_switch(sdata, &ch_switch)) { 3050 link_info(link, 3051 "preparing for channel switch failed, disconnecting\n"); 3052 goto drop_connection; 3053 } 3054 3055 link->u.mgd.csa.ap_chandef = csa_ie.chanreq.ap; 3056 3057 link->csa.chanreq.oper = csa_ie.chanreq.oper; 3058 ieee80211_set_chanreq_ap(sdata, &link->csa.chanreq, &link->u.mgd.conn, 3059 &csa_ie.chanreq.ap); 3060 3061 if (chanctx) { 3062 res = ieee80211_link_reserve_chanctx(link, &link->csa.chanreq, 3063 chanctx->mode, false); 3064 if (res) { 3065 link_info(link, 3066 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n", 3067 res); 3068 goto drop_connection; 3069 } 3070 } 3071 3072 link->conf->csa_active = true; 3073 link->u.mgd.csa.ignored_same_chan = false; 3074 link->u.mgd.beacon_crc_valid = false; 3075 link->u.mgd.csa.blocked_tx = csa_ie.mode; 3076 3077 if (csa_ie.mode) 3078 ieee80211_vif_block_queues_csa(sdata); 3079 3080 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chanreq.oper, 3081 link->link_id, csa_ie.count, 3082 csa_ie.mode); 3083 3084 /* we may have to handle timeout for deactivated link in software */ 3085 now = ktime_get_boottime(); 3086 csa_time_tu = (max_t(int, csa_ie.count, 1) - 1) * link->conf->beacon_int; 3087 link->u.mgd.csa.time = now + us_to_ktime(ieee80211_tu_to_usec(csa_time_tu)); 3088 3089 if (ieee80211_vif_link_active(&sdata->vif, link->link_id) && 3090 local->ops->channel_switch) { 3091 /* 3092 * Use driver's channel switch callback, the driver will 3093 * later call ieee80211_chswitch_done(). It may deactivate 3094 * the link as well, we handle that elsewhere and queue 3095 * the csa.switch_work for the calculated time then. 3096 */ 3097 drv_channel_switch(local, sdata, &ch_switch); 3098 return; 3099 } 3100 3101 /* channel switch handled in software */ 3102 wiphy_hrtimer_work_queue(local->hw.wiphy, 3103 &link->u.mgd.csa.switch_work, 3104 link->u.mgd.csa.time - now); 3105 return; 3106 drop_connection: 3107 /* 3108 * This is just so that the disconnect flow will know that 3109 * we were trying to switch channel and failed. In case the 3110 * mode is 1 (we are not allowed to Tx), we will know not to 3111 * send a deauthentication frame. Those two fields will be 3112 * reset when the disconnection worker runs. 3113 */ 3114 link->conf->csa_active = true; 3115 link->u.mgd.csa.blocked_tx = csa_ie.mode; 3116 3117 wiphy_work_queue(sdata->local->hw.wiphy, 3118 &ifmgd->csa_connection_drop_work); 3119 } 3120 3121 struct sta_bss_param_ch_cnt_data { 3122 struct ieee80211_sub_if_data *sdata; 3123 u8 reporting_link_id; 3124 u8 mld_id; 3125 }; 3126 3127 static enum cfg80211_rnr_iter_ret 3128 ieee80211_sta_bss_param_ch_cnt_iter(void *_data, u8 type, 3129 const struct ieee80211_neighbor_ap_info *info, 3130 const u8 *tbtt_info, u8 tbtt_info_len) 3131 { 3132 struct sta_bss_param_ch_cnt_data *data = _data; 3133 struct ieee80211_sub_if_data *sdata = data->sdata; 3134 const struct ieee80211_tbtt_info_ge_11 *ti; 3135 u8 bss_param_ch_cnt; 3136 int link_id; 3137 3138 if (type != IEEE80211_TBTT_INFO_TYPE_TBTT) 3139 return RNR_ITER_CONTINUE; 3140 3141 if (tbtt_info_len < sizeof(*ti)) 3142 return RNR_ITER_CONTINUE; 3143 3144 ti = (const void *)tbtt_info; 3145 3146 if (ti->mld_params.mld_id != data->mld_id) 3147 return RNR_ITER_CONTINUE; 3148 3149 link_id = le16_get_bits(ti->mld_params.params, 3150 IEEE80211_RNR_MLD_PARAMS_LINK_ID); 3151 bss_param_ch_cnt = 3152 le16_get_bits(ti->mld_params.params, 3153 IEEE80211_RNR_MLD_PARAMS_BSS_CHANGE_COUNT); 3154 3155 if (bss_param_ch_cnt != 255 && 3156 link_id < ARRAY_SIZE(sdata->link)) { 3157 struct ieee80211_link_data *link = 3158 sdata_dereference(sdata->link[link_id], sdata); 3159 3160 if (link && link->conf->bss_param_ch_cnt != bss_param_ch_cnt) { 3161 link->conf->bss_param_ch_cnt = bss_param_ch_cnt; 3162 link->conf->bss_param_ch_cnt_link_id = 3163 data->reporting_link_id; 3164 } 3165 } 3166 3167 return RNR_ITER_CONTINUE; 3168 } 3169 3170 static void 3171 ieee80211_mgd_update_bss_param_ch_cnt(struct ieee80211_sub_if_data *sdata, 3172 struct ieee80211_bss_conf *bss_conf, 3173 struct ieee802_11_elems *elems) 3174 { 3175 struct sta_bss_param_ch_cnt_data data = { 3176 .reporting_link_id = bss_conf->link_id, 3177 .sdata = sdata, 3178 }; 3179 int bss_param_ch_cnt; 3180 3181 if (!elems->ml_basic) 3182 return; 3183 3184 data.mld_id = ieee80211_mle_get_mld_id((const void *)elems->ml_basic); 3185 3186 cfg80211_iter_rnr(elems->ie_start, elems->total_len, 3187 ieee80211_sta_bss_param_ch_cnt_iter, &data); 3188 3189 bss_param_ch_cnt = 3190 ieee80211_mle_get_bss_param_ch_cnt((const void *)elems->ml_basic); 3191 3192 /* 3193 * Update bss_param_ch_cnt_link_id even if bss_param_ch_cnt 3194 * didn't change to indicate that we got a beacon on our own 3195 * link. 3196 */ 3197 if (bss_param_ch_cnt >= 0 && bss_param_ch_cnt != 255) { 3198 bss_conf->bss_param_ch_cnt = bss_param_ch_cnt; 3199 bss_conf->bss_param_ch_cnt_link_id = 3200 bss_conf->link_id; 3201 } 3202 } 3203 3204 static bool 3205 ieee80211_find_80211h_pwr_constr(struct ieee80211_channel *channel, 3206 const u8 *country_ie, u8 country_ie_len, 3207 const u8 *pwr_constr_elem, 3208 int *chan_pwr, int *pwr_reduction) 3209 { 3210 struct ieee80211_country_ie_triplet *triplet; 3211 int chan = ieee80211_frequency_to_channel(channel->center_freq); 3212 int i, chan_increment; 3213 bool have_chan_pwr = false; 3214 3215 /* Invalid IE */ 3216 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) 3217 return false; 3218 3219 triplet = (void *)(country_ie + 3); 3220 country_ie_len -= 3; 3221 3222 switch (channel->band) { 3223 default: 3224 WARN_ON_ONCE(1); 3225 fallthrough; 3226 case NL80211_BAND_2GHZ: 3227 case NL80211_BAND_60GHZ: 3228 case NL80211_BAND_LC: 3229 chan_increment = 1; 3230 break; 3231 case NL80211_BAND_5GHZ: 3232 chan_increment = 4; 3233 break; 3234 case NL80211_BAND_6GHZ: 3235 /* 3236 * In the 6 GHz band, the "maximum transmit power level" 3237 * field in the triplets is reserved, and thus will be 3238 * zero and we shouldn't use it to control TX power. 3239 * The actual TX power will be given in the transmit 3240 * power envelope element instead. 3241 */ 3242 return false; 3243 } 3244 3245 /* find channel */ 3246 while (country_ie_len >= 3) { 3247 u8 first_channel = triplet->chans.first_channel; 3248 3249 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID) 3250 goto next; 3251 3252 for (i = 0; i < triplet->chans.num_channels; i++) { 3253 if (first_channel + i * chan_increment == chan) { 3254 have_chan_pwr = true; 3255 *chan_pwr = triplet->chans.max_power; 3256 break; 3257 } 3258 } 3259 if (have_chan_pwr) 3260 break; 3261 3262 next: 3263 triplet++; 3264 country_ie_len -= 3; 3265 } 3266 3267 if (have_chan_pwr && pwr_constr_elem) 3268 *pwr_reduction = *pwr_constr_elem; 3269 else 3270 *pwr_reduction = 0; 3271 3272 return have_chan_pwr; 3273 } 3274 3275 static void ieee80211_find_cisco_dtpc(struct ieee80211_channel *channel, 3276 const u8 *cisco_dtpc_ie, 3277 int *pwr_level) 3278 { 3279 /* From practical testing, the first data byte of the DTPC element 3280 * seems to contain the requested dBm level, and the CLI on Cisco 3281 * APs clearly state the range is -127 to 127 dBm, which indicates 3282 * a signed byte, although it seemingly never actually goes negative. 3283 * The other byte seems to always be zero. 3284 */ 3285 *pwr_level = (__s8)cisco_dtpc_ie[4]; 3286 } 3287 3288 static u64 ieee80211_handle_pwr_constr(struct ieee80211_link_data *link, 3289 struct ieee80211_channel *channel, 3290 struct ieee80211_mgmt *mgmt, 3291 const u8 *country_ie, u8 country_ie_len, 3292 const u8 *pwr_constr_ie, 3293 const u8 *cisco_dtpc_ie) 3294 { 3295 struct ieee80211_sub_if_data *sdata = link->sdata; 3296 bool has_80211h_pwr = false, has_cisco_pwr = false; 3297 int chan_pwr = 0, pwr_reduction_80211h = 0; 3298 int pwr_level_cisco, pwr_level_80211h; 3299 int new_ap_level; 3300 __le16 capab = mgmt->u.probe_resp.capab_info; 3301 3302 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) 3303 return 0; /* TODO */ 3304 3305 if (country_ie && 3306 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) || 3307 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) { 3308 has_80211h_pwr = ieee80211_find_80211h_pwr_constr( 3309 channel, country_ie, country_ie_len, 3310 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h); 3311 pwr_level_80211h = 3312 max_t(int, 0, chan_pwr - pwr_reduction_80211h); 3313 } 3314 3315 if (cisco_dtpc_ie) { 3316 ieee80211_find_cisco_dtpc( 3317 channel, cisco_dtpc_ie, &pwr_level_cisco); 3318 has_cisco_pwr = true; 3319 } 3320 3321 if (!has_80211h_pwr && !has_cisco_pwr) 3322 return 0; 3323 3324 /* If we have both 802.11h and Cisco DTPC, apply both limits 3325 * by picking the smallest of the two power levels advertised. 3326 */ 3327 if (has_80211h_pwr && 3328 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) { 3329 new_ap_level = pwr_level_80211h; 3330 3331 if (link->ap_power_level == new_ap_level) 3332 return 0; 3333 3334 sdata_dbg(sdata, 3335 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n", 3336 pwr_level_80211h, chan_pwr, pwr_reduction_80211h, 3337 link->u.mgd.bssid); 3338 } else { /* has_cisco_pwr is always true here. */ 3339 new_ap_level = pwr_level_cisco; 3340 3341 if (link->ap_power_level == new_ap_level) 3342 return 0; 3343 3344 sdata_dbg(sdata, 3345 "Limiting TX power to %d dBm as advertised by %pM\n", 3346 pwr_level_cisco, link->u.mgd.bssid); 3347 } 3348 3349 link->ap_power_level = new_ap_level; 3350 if (__ieee80211_recalc_txpower(link)) 3351 return BSS_CHANGED_TXPOWER; 3352 return 0; 3353 } 3354 3355 /* powersave */ 3356 static void ieee80211_enable_ps(struct ieee80211_local *local, 3357 struct ieee80211_sub_if_data *sdata) 3358 { 3359 struct ieee80211_conf *conf = &local->hw.conf; 3360 3361 /* 3362 * If we are scanning right now then the parameters will 3363 * take effect when scan finishes. 3364 */ 3365 if (local->scanning) 3366 return; 3367 3368 if (conf->dynamic_ps_timeout > 0 && 3369 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) { 3370 mod_timer(&local->dynamic_ps_timer, jiffies + 3371 msecs_to_jiffies(conf->dynamic_ps_timeout)); 3372 } else { 3373 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) 3374 ieee80211_send_nullfunc(local, sdata, true); 3375 3376 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) && 3377 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) 3378 return; 3379 3380 conf->flags |= IEEE80211_CONF_PS; 3381 ieee80211_hw_config(local, -1, IEEE80211_CONF_CHANGE_PS); 3382 } 3383 } 3384 3385 static void ieee80211_change_ps(struct ieee80211_local *local) 3386 { 3387 struct ieee80211_conf *conf = &local->hw.conf; 3388 3389 if (local->ps_sdata) { 3390 ieee80211_enable_ps(local, local->ps_sdata); 3391 } else if (conf->flags & IEEE80211_CONF_PS) { 3392 conf->flags &= ~IEEE80211_CONF_PS; 3393 ieee80211_hw_config(local, -1, IEEE80211_CONF_CHANGE_PS); 3394 timer_delete_sync(&local->dynamic_ps_timer); 3395 wiphy_work_cancel(local->hw.wiphy, 3396 &local->dynamic_ps_enable_work); 3397 } 3398 } 3399 3400 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata) 3401 { 3402 struct ieee80211_local *local = sdata->local; 3403 struct ieee80211_if_managed *mgd = &sdata->u.mgd; 3404 struct sta_info *sta = NULL; 3405 bool authorized = false; 3406 3407 if (!mgd->powersave) 3408 return false; 3409 3410 if (mgd->broken_ap) 3411 return false; 3412 3413 if (!mgd->associated) 3414 return false; 3415 3416 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL) 3417 return false; 3418 3419 if (!(local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO) && 3420 !sdata->deflink.u.mgd.have_beacon) 3421 return false; 3422 3423 rcu_read_lock(); 3424 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr); 3425 if (sta) 3426 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED); 3427 rcu_read_unlock(); 3428 3429 return authorized; 3430 } 3431 3432 /* need to hold RTNL or interface lock */ 3433 void ieee80211_recalc_ps(struct ieee80211_local *local) 3434 { 3435 struct ieee80211_sub_if_data *sdata, *found = NULL; 3436 int count = 0; 3437 int timeout; 3438 3439 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS) || 3440 ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) { 3441 local->ps_sdata = NULL; 3442 return; 3443 } 3444 3445 list_for_each_entry(sdata, &local->interfaces, list) { 3446 if (!ieee80211_sdata_running(sdata)) 3447 continue; 3448 if (sdata->vif.type == NL80211_IFTYPE_AP) { 3449 /* If an AP vif is found, then disable PS 3450 * by setting the count to zero thereby setting 3451 * ps_sdata to NULL. 3452 */ 3453 count = 0; 3454 break; 3455 } 3456 if (sdata->vif.type != NL80211_IFTYPE_STATION) 3457 continue; 3458 found = sdata; 3459 count++; 3460 } 3461 3462 if (count == 1 && ieee80211_powersave_allowed(found)) { 3463 u8 dtimper = found->deflink.u.mgd.dtim_period; 3464 3465 timeout = local->dynamic_ps_forced_timeout; 3466 if (timeout < 0) 3467 timeout = 100; 3468 local->hw.conf.dynamic_ps_timeout = timeout; 3469 3470 /* If the TIM IE is invalid, pretend the value is 1 */ 3471 if (!dtimper) 3472 dtimper = 1; 3473 3474 local->hw.conf.ps_dtim_period = dtimper; 3475 local->ps_sdata = found; 3476 } else { 3477 local->ps_sdata = NULL; 3478 } 3479 3480 ieee80211_change_ps(local); 3481 } 3482 3483 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata) 3484 { 3485 bool ps_allowed = ieee80211_powersave_allowed(sdata); 3486 3487 if (sdata->vif.cfg.ps != ps_allowed) { 3488 sdata->vif.cfg.ps = ps_allowed; 3489 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_PS); 3490 } 3491 } 3492 3493 void ieee80211_dynamic_ps_disable_work(struct wiphy *wiphy, 3494 struct wiphy_work *work) 3495 { 3496 struct ieee80211_local *local = 3497 container_of(work, struct ieee80211_local, 3498 dynamic_ps_disable_work); 3499 3500 if (local->hw.conf.flags & IEEE80211_CONF_PS) { 3501 local->hw.conf.flags &= ~IEEE80211_CONF_PS; 3502 ieee80211_hw_config(local, -1, IEEE80211_CONF_CHANGE_PS); 3503 } 3504 3505 ieee80211_wake_queues_by_reason(&local->hw, 3506 IEEE80211_MAX_QUEUE_MAP, 3507 IEEE80211_QUEUE_STOP_REASON_PS, 3508 false); 3509 } 3510 3511 void ieee80211_dynamic_ps_enable_work(struct wiphy *wiphy, 3512 struct wiphy_work *work) 3513 { 3514 struct ieee80211_local *local = 3515 container_of(work, struct ieee80211_local, 3516 dynamic_ps_enable_work); 3517 struct ieee80211_sub_if_data *sdata = local->ps_sdata; 3518 struct ieee80211_if_managed *ifmgd; 3519 unsigned long flags; 3520 int q; 3521 3522 /* can only happen when PS was just disabled anyway */ 3523 if (!sdata) 3524 return; 3525 3526 ifmgd = &sdata->u.mgd; 3527 3528 if (local->hw.conf.flags & IEEE80211_CONF_PS) 3529 return; 3530 3531 if (local->hw.conf.dynamic_ps_timeout > 0) { 3532 /* don't enter PS if TX frames are pending */ 3533 if (drv_tx_frames_pending(local)) { 3534 mod_timer(&local->dynamic_ps_timer, jiffies + 3535 msecs_to_jiffies( 3536 local->hw.conf.dynamic_ps_timeout)); 3537 return; 3538 } 3539 3540 /* 3541 * transmission can be stopped by others which leads to 3542 * dynamic_ps_timer expiry. Postpone the ps timer if it 3543 * is not the actual idle state. 3544 */ 3545 spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 3546 for (q = 0; q < local->hw.queues; q++) { 3547 if (local->queue_stop_reasons[q]) { 3548 spin_unlock_irqrestore(&local->queue_stop_reason_lock, 3549 flags); 3550 mod_timer(&local->dynamic_ps_timer, jiffies + 3551 msecs_to_jiffies( 3552 local->hw.conf.dynamic_ps_timeout)); 3553 return; 3554 } 3555 } 3556 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 3557 } 3558 3559 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) && 3560 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) { 3561 if (drv_tx_frames_pending(local)) { 3562 mod_timer(&local->dynamic_ps_timer, jiffies + 3563 msecs_to_jiffies( 3564 local->hw.conf.dynamic_ps_timeout)); 3565 } else { 3566 ieee80211_send_nullfunc(local, sdata, true); 3567 /* Flush to get the tx status of nullfunc frame */ 3568 ieee80211_flush_queues(local, sdata, false); 3569 } 3570 } 3571 3572 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) && 3573 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) || 3574 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) { 3575 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED; 3576 local->hw.conf.flags |= IEEE80211_CONF_PS; 3577 ieee80211_hw_config(local, -1, IEEE80211_CONF_CHANGE_PS); 3578 } 3579 } 3580 3581 void ieee80211_dynamic_ps_timer(struct timer_list *t) 3582 { 3583 struct ieee80211_local *local = timer_container_of(local, t, 3584 dynamic_ps_timer); 3585 3586 wiphy_work_queue(local->hw.wiphy, &local->dynamic_ps_enable_work); 3587 } 3588 3589 void ieee80211_dfs_cac_timer_work(struct wiphy *wiphy, struct wiphy_work *work) 3590 { 3591 struct ieee80211_link_data *link = 3592 container_of(work, struct ieee80211_link_data, 3593 dfs_cac_timer_work.work); 3594 struct cfg80211_chan_def chandef = link->conf->chanreq.oper; 3595 struct ieee80211_sub_if_data *sdata = link->sdata; 3596 3597 lockdep_assert_wiphy(sdata->local->hw.wiphy); 3598 3599 if (sdata->wdev.links[link->link_id].cac_started) { 3600 ieee80211_link_release_channel(link); 3601 cfg80211_cac_event(sdata->dev, &chandef, 3602 NL80211_RADAR_CAC_FINISHED, 3603 GFP_KERNEL, link->link_id); 3604 } 3605 } 3606 3607 static bool 3608 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata) 3609 { 3610 struct ieee80211_local *local = sdata->local; 3611 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 3612 bool ret = false; 3613 int ac; 3614 3615 if (local->hw.queues < IEEE80211_NUM_ACS) 3616 return false; 3617 3618 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 3619 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac]; 3620 int non_acm_ac; 3621 unsigned long now = jiffies; 3622 3623 if (tx_tspec->action == TX_TSPEC_ACTION_NONE && 3624 tx_tspec->admitted_time && 3625 time_after(now, tx_tspec->time_slice_start + HZ)) { 3626 tx_tspec->consumed_tx_time = 0; 3627 tx_tspec->time_slice_start = now; 3628 3629 if (tx_tspec->downgraded) 3630 tx_tspec->action = 3631 TX_TSPEC_ACTION_STOP_DOWNGRADE; 3632 } 3633 3634 switch (tx_tspec->action) { 3635 case TX_TSPEC_ACTION_STOP_DOWNGRADE: 3636 /* take the original parameters */ 3637 if (drv_conf_tx(local, &sdata->deflink, ac, 3638 &sdata->deflink.tx_conf[ac])) 3639 link_err(&sdata->deflink, 3640 "failed to set TX queue parameters for queue %d\n", 3641 ac); 3642 tx_tspec->action = TX_TSPEC_ACTION_NONE; 3643 tx_tspec->downgraded = false; 3644 ret = true; 3645 break; 3646 case TX_TSPEC_ACTION_DOWNGRADE: 3647 if (time_after(now, tx_tspec->time_slice_start + HZ)) { 3648 tx_tspec->action = TX_TSPEC_ACTION_NONE; 3649 ret = true; 3650 break; 3651 } 3652 /* downgrade next lower non-ACM AC */ 3653 for (non_acm_ac = ac + 1; 3654 non_acm_ac < IEEE80211_NUM_ACS; 3655 non_acm_ac++) 3656 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac))) 3657 break; 3658 /* Usually the loop will result in using BK even if it 3659 * requires admission control, but such a configuration 3660 * makes no sense and we have to transmit somehow - the 3661 * AC selection does the same thing. 3662 * If we started out trying to downgrade from BK, then 3663 * the extra condition here might be needed. 3664 */ 3665 if (non_acm_ac >= IEEE80211_NUM_ACS) 3666 non_acm_ac = IEEE80211_AC_BK; 3667 if (drv_conf_tx(local, &sdata->deflink, ac, 3668 &sdata->deflink.tx_conf[non_acm_ac])) 3669 link_err(&sdata->deflink, 3670 "failed to set TX queue parameters for queue %d\n", 3671 ac); 3672 tx_tspec->action = TX_TSPEC_ACTION_NONE; 3673 ret = true; 3674 wiphy_delayed_work_queue(local->hw.wiphy, 3675 &ifmgd->tx_tspec_wk, 3676 tx_tspec->time_slice_start + 3677 HZ - now + 1); 3678 break; 3679 case TX_TSPEC_ACTION_NONE: 3680 /* nothing now */ 3681 break; 3682 } 3683 } 3684 3685 return ret; 3686 } 3687 3688 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata) 3689 { 3690 if (__ieee80211_sta_handle_tspec_ac_params(sdata)) 3691 ieee80211_link_info_change_notify(sdata, &sdata->deflink, 3692 BSS_CHANGED_QOS); 3693 } 3694 3695 static void ieee80211_sta_handle_tspec_ac_params_wk(struct wiphy *wiphy, 3696 struct wiphy_work *work) 3697 { 3698 struct ieee80211_sub_if_data *sdata; 3699 3700 sdata = container_of(work, struct ieee80211_sub_if_data, 3701 u.mgd.tx_tspec_wk.work); 3702 ieee80211_sta_handle_tspec_ac_params(sdata); 3703 } 3704 3705 void ieee80211_mgd_set_link_qos_params(struct ieee80211_link_data *link) 3706 { 3707 struct ieee80211_sub_if_data *sdata = link->sdata; 3708 struct ieee80211_local *local = sdata->local; 3709 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 3710 struct ieee80211_tx_queue_params *params = link->tx_conf; 3711 u8 ac; 3712 3713 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 3714 mlme_dbg(sdata, 3715 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n", 3716 ac, params[ac].acm, 3717 params[ac].aifs, params[ac].cw_min, params[ac].cw_max, 3718 params[ac].txop, params[ac].uapsd, 3719 ifmgd->tx_tspec[ac].downgraded); 3720 if (!ifmgd->tx_tspec[ac].downgraded && 3721 drv_conf_tx(local, link, ac, ¶ms[ac])) 3722 link_err(link, 3723 "failed to set TX queue parameters for AC %d\n", 3724 ac); 3725 } 3726 } 3727 3728 /* MLME */ 3729 static bool 3730 _ieee80211_sta_wmm_params(struct ieee80211_local *local, 3731 struct ieee80211_link_data *link, 3732 const u8 *wmm_param, size_t wmm_param_len, 3733 const struct ieee80211_mu_edca_param_set *mu_edca) 3734 { 3735 struct ieee80211_sub_if_data *sdata = link->sdata; 3736 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS]; 3737 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 3738 size_t left; 3739 int count, mu_edca_count, ac; 3740 const u8 *pos; 3741 u8 uapsd_queues = 0; 3742 3743 if (!local->ops->conf_tx) 3744 return false; 3745 3746 if (local->hw.queues < IEEE80211_NUM_ACS) 3747 return false; 3748 3749 if (!wmm_param) 3750 return false; 3751 3752 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1) 3753 return false; 3754 3755 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED) 3756 uapsd_queues = ifmgd->uapsd_queues; 3757 3758 count = wmm_param[6] & 0x0f; 3759 /* -1 is the initial value of ifmgd->mu_edca_last_param_set. 3760 * if mu_edca was preset before and now it disappeared tell 3761 * the driver about it. 3762 */ 3763 mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1; 3764 if (count == link->u.mgd.wmm_last_param_set && 3765 mu_edca_count == link->u.mgd.mu_edca_last_param_set) 3766 return false; 3767 link->u.mgd.wmm_last_param_set = count; 3768 link->u.mgd.mu_edca_last_param_set = mu_edca_count; 3769 3770 pos = wmm_param + 8; 3771 left = wmm_param_len - 8; 3772 3773 memset(¶ms, 0, sizeof(params)); 3774 3775 sdata->wmm_acm = 0; 3776 for (; left >= 4; left -= 4, pos += 4) { 3777 int aci = (pos[0] >> 5) & 0x03; 3778 int acm = (pos[0] >> 4) & 0x01; 3779 bool uapsd = false; 3780 3781 switch (aci) { 3782 case 1: /* AC_BK */ 3783 ac = IEEE80211_AC_BK; 3784 if (acm) 3785 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */ 3786 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) 3787 uapsd = true; 3788 params[ac].mu_edca = !!mu_edca; 3789 if (mu_edca) 3790 params[ac].mu_edca_param_rec = mu_edca->ac_bk; 3791 break; 3792 case 2: /* AC_VI */ 3793 ac = IEEE80211_AC_VI; 3794 if (acm) 3795 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */ 3796 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) 3797 uapsd = true; 3798 params[ac].mu_edca = !!mu_edca; 3799 if (mu_edca) 3800 params[ac].mu_edca_param_rec = mu_edca->ac_vi; 3801 break; 3802 case 3: /* AC_VO */ 3803 ac = IEEE80211_AC_VO; 3804 if (acm) 3805 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */ 3806 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) 3807 uapsd = true; 3808 params[ac].mu_edca = !!mu_edca; 3809 if (mu_edca) 3810 params[ac].mu_edca_param_rec = mu_edca->ac_vo; 3811 break; 3812 case 0: /* AC_BE */ 3813 default: 3814 ac = IEEE80211_AC_BE; 3815 if (acm) 3816 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */ 3817 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) 3818 uapsd = true; 3819 params[ac].mu_edca = !!mu_edca; 3820 if (mu_edca) 3821 params[ac].mu_edca_param_rec = mu_edca->ac_be; 3822 break; 3823 } 3824 3825 params[ac].aifs = pos[0] & 0x0f; 3826 3827 if (params[ac].aifs < 2) { 3828 link_info(link, 3829 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n", 3830 params[ac].aifs, aci); 3831 params[ac].aifs = 2; 3832 } 3833 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4); 3834 params[ac].cw_min = ecw2cw(pos[1] & 0x0f); 3835 params[ac].txop = get_unaligned_le16(pos + 2); 3836 params[ac].acm = acm; 3837 params[ac].uapsd = uapsd; 3838 3839 if (params[ac].cw_min == 0 || 3840 params[ac].cw_min > params[ac].cw_max) { 3841 link_info(link, 3842 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n", 3843 params[ac].cw_min, params[ac].cw_max, aci); 3844 return false; 3845 } 3846 ieee80211_regulatory_limit_wmm_params(sdata, ¶ms[ac], ac); 3847 } 3848 3849 /* WMM specification requires all 4 ACIs. */ 3850 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 3851 if (params[ac].cw_min == 0) { 3852 link_info(link, 3853 "AP has invalid WMM params (missing AC %d), using defaults\n", 3854 ac); 3855 return false; 3856 } 3857 } 3858 3859 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) 3860 link->tx_conf[ac] = params[ac]; 3861 3862 return true; 3863 } 3864 3865 static bool 3866 ieee80211_sta_wmm_params(struct ieee80211_local *local, 3867 struct ieee80211_link_data *link, 3868 const u8 *wmm_param, size_t wmm_param_len, 3869 const struct ieee80211_mu_edca_param_set *mu_edca) 3870 { 3871 if (!_ieee80211_sta_wmm_params(local, link, wmm_param, wmm_param_len, 3872 mu_edca)) 3873 return false; 3874 3875 ieee80211_mgd_set_link_qos_params(link); 3876 3877 /* enable WMM or activate new settings */ 3878 link->conf->qos = true; 3879 return true; 3880 } 3881 3882 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata) 3883 { 3884 lockdep_assert_wiphy(sdata->local->hw.wiphy); 3885 3886 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL; 3887 ieee80211_run_deferred_scan(sdata->local); 3888 } 3889 3890 static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata) 3891 { 3892 lockdep_assert_wiphy(sdata->local->hw.wiphy); 3893 3894 __ieee80211_stop_poll(sdata); 3895 } 3896 3897 static u64 ieee80211_handle_bss_capability(struct ieee80211_link_data *link, 3898 u16 capab, bool erp_valid, u8 erp) 3899 { 3900 struct ieee80211_bss_conf *bss_conf = link->conf; 3901 struct ieee80211_supported_band *sband; 3902 u64 changed = 0; 3903 bool use_protection; 3904 bool use_short_preamble; 3905 bool use_short_slot; 3906 3907 sband = ieee80211_get_link_sband(link); 3908 if (!sband) 3909 return changed; 3910 3911 if (erp_valid) { 3912 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0; 3913 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0; 3914 } else { 3915 use_protection = false; 3916 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE); 3917 } 3918 3919 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME); 3920 if (sband->band == NL80211_BAND_5GHZ || 3921 sband->band == NL80211_BAND_6GHZ) 3922 use_short_slot = true; 3923 3924 if (use_protection != bss_conf->use_cts_prot) { 3925 bss_conf->use_cts_prot = use_protection; 3926 changed |= BSS_CHANGED_ERP_CTS_PROT; 3927 } 3928 3929 if (use_short_preamble != bss_conf->use_short_preamble) { 3930 bss_conf->use_short_preamble = use_short_preamble; 3931 changed |= BSS_CHANGED_ERP_PREAMBLE; 3932 } 3933 3934 if (use_short_slot != bss_conf->use_short_slot) { 3935 bss_conf->use_short_slot = use_short_slot; 3936 changed |= BSS_CHANGED_ERP_SLOT; 3937 } 3938 3939 return changed; 3940 } 3941 3942 static u64 ieee80211_link_set_associated(struct ieee80211_link_data *link, 3943 struct cfg80211_bss *cbss) 3944 { 3945 struct ieee80211_sub_if_data *sdata = link->sdata; 3946 struct ieee80211_bss_conf *bss_conf = link->conf; 3947 struct ieee80211_bss *bss = (void *)cbss->priv; 3948 u64 changed = BSS_CHANGED_QOS; 3949 3950 /* not really used in MLO */ 3951 sdata->u.mgd.beacon_timeout = 3952 usecs_to_jiffies(ieee80211_tu_to_usec(beacon_loss_count * 3953 bss_conf->beacon_int)); 3954 3955 changed |= ieee80211_handle_bss_capability(link, 3956 bss_conf->assoc_capability, 3957 bss->has_erp_value, 3958 bss->erp_value); 3959 3960 ieee80211_check_rate_mask(link); 3961 3962 link->conf->bss = cbss; 3963 memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN); 3964 3965 if (sdata->vif.p2p || 3966 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) { 3967 const struct cfg80211_bss_ies *ies; 3968 3969 rcu_read_lock(); 3970 ies = rcu_dereference(cbss->ies); 3971 if (ies) { 3972 int ret; 3973 3974 ret = cfg80211_get_p2p_attr( 3975 ies->data, ies->len, 3976 IEEE80211_P2P_ATTR_ABSENCE_NOTICE, 3977 (u8 *) &bss_conf->p2p_noa_attr, 3978 sizeof(bss_conf->p2p_noa_attr)); 3979 if (ret >= 2) { 3980 link->u.mgd.p2p_noa_index = 3981 bss_conf->p2p_noa_attr.index; 3982 changed |= BSS_CHANGED_P2P_PS; 3983 } 3984 } 3985 rcu_read_unlock(); 3986 } 3987 3988 if (link->u.mgd.have_beacon) { 3989 bss_conf->beacon_rate = bss->beacon_rate; 3990 changed |= BSS_CHANGED_BEACON_INFO; 3991 } else { 3992 bss_conf->beacon_rate = NULL; 3993 } 3994 3995 /* Tell the driver to monitor connection quality (if supported) */ 3996 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI && 3997 bss_conf->cqm_rssi_thold) 3998 changed |= BSS_CHANGED_CQM; 3999 4000 return changed; 4001 } 4002 4003 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata, 4004 struct ieee80211_mgd_assoc_data *assoc_data, 4005 u64 changed[IEEE80211_MLD_MAX_NUM_LINKS]) 4006 { 4007 struct ieee80211_local *local = sdata->local; 4008 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg; 4009 u64 vif_changed = BSS_CHANGED_ASSOC; 4010 unsigned int link_id; 4011 4012 lockdep_assert_wiphy(local->hw.wiphy); 4013 4014 sdata->u.mgd.associated = true; 4015 4016 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { 4017 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss; 4018 struct ieee80211_link_data *link; 4019 4020 if (!cbss || 4021 assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) 4022 continue; 4023 4024 if (ieee80211_vif_is_mld(&sdata->vif) && 4025 !(ieee80211_vif_usable_links(&sdata->vif) & BIT(link_id))) 4026 continue; 4027 4028 link = sdata_dereference(sdata->link[link_id], sdata); 4029 if (WARN_ON(!link)) 4030 return; 4031 4032 changed[link_id] |= ieee80211_link_set_associated(link, cbss); 4033 } 4034 4035 /* just to be sure */ 4036 ieee80211_stop_poll(sdata); 4037 4038 ieee80211_led_assoc(local, 1); 4039 4040 vif_cfg->assoc = 1; 4041 4042 /* Enable ARP filtering */ 4043 if (vif_cfg->arp_addr_cnt) 4044 vif_changed |= BSS_CHANGED_ARP_FILTER; 4045 4046 if (ieee80211_vif_is_mld(&sdata->vif)) { 4047 for (link_id = 0; 4048 link_id < IEEE80211_MLD_MAX_NUM_LINKS; 4049 link_id++) { 4050 struct ieee80211_link_data *link; 4051 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss; 4052 4053 if (!cbss || 4054 !(BIT(link_id) & 4055 ieee80211_vif_usable_links(&sdata->vif)) || 4056 assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) 4057 continue; 4058 4059 link = sdata_dereference(sdata->link[link_id], sdata); 4060 if (WARN_ON(!link)) 4061 return; 4062 4063 ieee80211_link_info_change_notify(sdata, link, 4064 changed[link_id]); 4065 4066 ieee80211_recalc_smps(sdata, link); 4067 } 4068 4069 ieee80211_vif_cfg_change_notify(sdata, vif_changed); 4070 } else { 4071 ieee80211_bss_info_change_notify(sdata, 4072 vif_changed | changed[0]); 4073 } 4074 4075 ieee80211_recalc_ps(local); 4076 4077 /* leave this here to not change ordering in non-MLO cases */ 4078 if (!ieee80211_vif_is_mld(&sdata->vif)) 4079 ieee80211_recalc_smps(sdata, &sdata->deflink); 4080 ieee80211_recalc_ps_vif(sdata); 4081 4082 netif_carrier_on(sdata->dev); 4083 } 4084 4085 static void ieee80211_ml_reconf_reset(struct ieee80211_sub_if_data *sdata) 4086 { 4087 struct ieee80211_mgd_assoc_data *add_links_data = 4088 sdata->u.mgd.reconf.add_links_data; 4089 4090 if (!ieee80211_vif_is_mld(&sdata->vif) || 4091 !(sdata->u.mgd.reconf.added_links | 4092 sdata->u.mgd.reconf.removed_links)) 4093 return; 4094 4095 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, 4096 &sdata->u.mgd.reconf.wk); 4097 sdata->u.mgd.reconf.added_links = 0; 4098 sdata->u.mgd.reconf.removed_links = 0; 4099 sdata->u.mgd.reconf.dialog_token = 0; 4100 4101 if (add_links_data) { 4102 struct cfg80211_mlo_reconf_done_data done_data = {}; 4103 u8 link_id; 4104 4105 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; 4106 link_id++) 4107 done_data.links[link_id].bss = 4108 add_links_data->link[link_id].bss; 4109 4110 cfg80211_mlo_reconf_add_done(sdata->dev, &done_data); 4111 4112 kfree(sdata->u.mgd.reconf.add_links_data); 4113 sdata->u.mgd.reconf.add_links_data = NULL; 4114 } 4115 } 4116 4117 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata, 4118 u16 stype, u16 reason, bool tx, 4119 u8 *frame_buf) 4120 { 4121 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 4122 struct ieee80211_local *local = sdata->local; 4123 struct sta_info *ap_sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr); 4124 unsigned int link_id; 4125 u64 changed = 0; 4126 struct ieee80211_prep_tx_info info = { 4127 .subtype = stype, 4128 .was_assoc = true, 4129 .link_id = ffs(sdata->vif.active_links) - 1, 4130 }; 4131 4132 lockdep_assert_wiphy(local->hw.wiphy); 4133 4134 if (frame_buf) 4135 memset(frame_buf, 0, IEEE80211_DEAUTH_FRAME_LEN); 4136 4137 if (WARN_ON(!ap_sta)) 4138 return; 4139 4140 if (WARN_ON_ONCE(tx && !frame_buf)) 4141 return; 4142 4143 if (WARN_ON(!ifmgd->associated)) 4144 return; 4145 4146 ieee80211_stop_poll(sdata); 4147 4148 ifmgd->associated = false; 4149 4150 if (tx) { 4151 bool tx_link_found = false; 4152 4153 for (link_id = 0; 4154 link_id < ARRAY_SIZE(sdata->link); 4155 link_id++) { 4156 struct ieee80211_link_data *link; 4157 4158 if (!ieee80211_vif_link_active(&sdata->vif, link_id)) 4159 continue; 4160 4161 link = sdata_dereference(sdata->link[link_id], sdata); 4162 if (WARN_ON_ONCE(!link)) 4163 continue; 4164 4165 if (link->u.mgd.csa.blocked_tx) 4166 continue; 4167 4168 tx_link_found = true; 4169 break; 4170 } 4171 4172 tx = tx_link_found; 4173 } 4174 4175 /* other links will be destroyed */ 4176 sdata->deflink.conf->bss = NULL; 4177 sdata->deflink.conf->epcs_support = false; 4178 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF; 4179 4180 netif_carrier_off(sdata->dev); 4181 4182 /* 4183 * if we want to get out of ps before disassoc (why?) we have 4184 * to do it before sending disassoc, as otherwise the null-packet 4185 * won't be valid. 4186 */ 4187 if (local->hw.conf.flags & IEEE80211_CONF_PS) { 4188 local->hw.conf.flags &= ~IEEE80211_CONF_PS; 4189 ieee80211_hw_config(local, -1, IEEE80211_CONF_CHANGE_PS); 4190 } 4191 local->ps_sdata = NULL; 4192 4193 /* disable per-vif ps */ 4194 ieee80211_recalc_ps_vif(sdata); 4195 4196 /* make sure ongoing transmission finishes */ 4197 synchronize_net(); 4198 4199 /* 4200 * drop any frame before deauth/disassoc, this can be data or 4201 * management frame. Since we are disconnecting, we should not 4202 * insist sending these frames which can take time and delay 4203 * the disconnection and possible the roaming. 4204 */ 4205 ieee80211_flush_queues(local, sdata, true); 4206 4207 if (tx) { 4208 drv_mgd_prepare_tx(sdata->local, sdata, &info); 4209 4210 ieee80211_send_deauth_disassoc(sdata, sdata->vif.cfg.ap_addr, 4211 sdata->vif.cfg.ap_addr, stype, 4212 reason, true, frame_buf); 4213 4214 /* flush out frame - make sure the deauth was actually sent */ 4215 ieee80211_flush_queues(local, sdata, false); 4216 4217 drv_mgd_complete_tx(sdata->local, sdata, &info); 4218 } else if (frame_buf) { 4219 ieee80211_send_deauth_disassoc(sdata, sdata->vif.cfg.ap_addr, 4220 sdata->vif.cfg.ap_addr, stype, 4221 reason, false, frame_buf); 4222 } 4223 4224 /* clear AP addr only after building the needed mgmt frames */ 4225 eth_zero_addr(sdata->deflink.u.mgd.bssid); 4226 eth_zero_addr(sdata->vif.cfg.ap_addr); 4227 4228 sdata->vif.cfg.ssid_len = 0; 4229 4230 /* Remove TDLS peers */ 4231 __sta_info_flush(sdata, false, -1, ap_sta); 4232 4233 if (sdata->vif.driver_flags & IEEE80211_VIF_REMOVE_AP_AFTER_DISASSOC) { 4234 /* Only move the AP state */ 4235 sta_info_move_state(ap_sta, IEEE80211_STA_NONE); 4236 } else { 4237 /* Remove AP peer */ 4238 sta_info_flush(sdata, -1); 4239 } 4240 4241 /* finally reset all BSS / config parameters */ 4242 if (!ieee80211_vif_is_mld(&sdata->vif)) 4243 changed |= ieee80211_reset_erp_info(sdata); 4244 4245 ieee80211_led_assoc(local, 0); 4246 changed |= BSS_CHANGED_ASSOC; 4247 sdata->vif.cfg.assoc = false; 4248 4249 sdata->deflink.u.mgd.p2p_noa_index = -1; 4250 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0, 4251 sizeof(sdata->vif.bss_conf.p2p_noa_attr)); 4252 4253 /* on the next assoc, re-program HT/VHT parameters */ 4254 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa)); 4255 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask)); 4256 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa)); 4257 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask)); 4258 4259 /* 4260 * reset MU-MIMO ownership and group data in default link, 4261 * if used, other links are destroyed 4262 */ 4263 memset(sdata->vif.bss_conf.mu_group.membership, 0, 4264 sizeof(sdata->vif.bss_conf.mu_group.membership)); 4265 memset(sdata->vif.bss_conf.mu_group.position, 0, 4266 sizeof(sdata->vif.bss_conf.mu_group.position)); 4267 if (!ieee80211_vif_is_mld(&sdata->vif)) 4268 changed |= BSS_CHANGED_MU_GROUPS; 4269 sdata->vif.bss_conf.mu_mimo_owner = false; 4270 4271 sdata->deflink.ap_power_level = IEEE80211_UNSET_POWER_LEVEL; 4272 4273 timer_delete_sync(&local->dynamic_ps_timer); 4274 wiphy_work_cancel(local->hw.wiphy, &local->dynamic_ps_enable_work); 4275 4276 /* Disable ARP filtering */ 4277 if (sdata->vif.cfg.arp_addr_cnt) 4278 changed |= BSS_CHANGED_ARP_FILTER; 4279 4280 sdata->vif.bss_conf.qos = false; 4281 if (!ieee80211_vif_is_mld(&sdata->vif)) { 4282 changed |= BSS_CHANGED_QOS; 4283 /* The BSSID (not really interesting) and HT changed */ 4284 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT; 4285 ieee80211_bss_info_change_notify(sdata, changed); 4286 } else { 4287 ieee80211_vif_cfg_change_notify(sdata, changed); 4288 } 4289 4290 if (sdata->vif.driver_flags & IEEE80211_VIF_REMOVE_AP_AFTER_DISASSOC) { 4291 /* 4292 * After notifying the driver about the disassoc, 4293 * remove the ap sta. 4294 */ 4295 sta_info_flush(sdata, -1); 4296 } 4297 4298 /* disassociated - set to defaults now */ 4299 ieee80211_set_wmm_default(&sdata->deflink, false, false); 4300 4301 timer_delete_sync(&sdata->u.mgd.conn_mon_timer); 4302 timer_delete_sync(&sdata->u.mgd.bcn_mon_timer); 4303 timer_delete_sync(&sdata->u.mgd.timer); 4304 4305 sdata->vif.bss_conf.dtim_period = 0; 4306 sdata->vif.bss_conf.beacon_rate = NULL; 4307 4308 sdata->deflink.u.mgd.have_beacon = false; 4309 sdata->deflink.u.mgd.tracking_signal_avg = false; 4310 sdata->deflink.u.mgd.disable_wmm_tracking = false; 4311 4312 ifmgd->flags = 0; 4313 4314 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) { 4315 struct ieee80211_link_data *link; 4316 4317 link = sdata_dereference(sdata->link[link_id], sdata); 4318 if (!link) 4319 continue; 4320 ieee80211_link_release_channel(link); 4321 } 4322 4323 sdata->vif.bss_conf.csa_active = false; 4324 sdata->deflink.u.mgd.csa.blocked_tx = false; 4325 sdata->deflink.u.mgd.csa.waiting_bcn = false; 4326 sdata->deflink.u.mgd.csa.ignored_same_chan = false; 4327 ieee80211_vif_unblock_queues_csa(sdata); 4328 4329 /* existing TX TSPEC sessions no longer exist */ 4330 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec)); 4331 wiphy_delayed_work_cancel(local->hw.wiphy, &ifmgd->tx_tspec_wk); 4332 4333 sdata->vif.bss_conf.power_type = IEEE80211_REG_UNSET_AP; 4334 sdata->vif.bss_conf.pwr_reduction = 0; 4335 ieee80211_clear_tpe(&sdata->vif.bss_conf.tpe); 4336 4337 sdata->vif.cfg.eml_cap = 0; 4338 sdata->vif.cfg.eml_med_sync_delay = 0; 4339 sdata->vif.cfg.mld_capa_op = 0; 4340 4341 memset(&sdata->u.mgd.ttlm_info, 0, 4342 sizeof(sdata->u.mgd.ttlm_info)); 4343 wiphy_hrtimer_work_cancel(sdata->local->hw.wiphy, &ifmgd->ttlm_work); 4344 4345 memset(&sdata->vif.neg_ttlm, 0, sizeof(sdata->vif.neg_ttlm)); 4346 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, 4347 &ifmgd->neg_ttlm_timeout_work); 4348 4349 sdata->u.mgd.removed_links = 0; 4350 wiphy_hrtimer_work_cancel(sdata->local->hw.wiphy, 4351 &sdata->u.mgd.ml_reconf_work); 4352 4353 wiphy_work_cancel(sdata->local->hw.wiphy, 4354 &ifmgd->teardown_ttlm_work); 4355 4356 /* if disconnection happens in the middle of the ML reconfiguration 4357 * flow, cfg80211 must called to release the BSS references obtained 4358 * when the flow started. 4359 */ 4360 ieee80211_ml_reconf_reset(sdata); 4361 4362 ieee80211_vif_set_links(sdata, 0, 0); 4363 4364 ifmgd->mcast_seq_last = IEEE80211_SN_MODULO; 4365 4366 ifmgd->epcs.enabled = false; 4367 ifmgd->epcs.dialog_token = 0; 4368 4369 memset(ifmgd->userspace_selectors, 0, 4370 sizeof(ifmgd->userspace_selectors)); 4371 } 4372 4373 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata) 4374 { 4375 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 4376 struct ieee80211_local *local = sdata->local; 4377 4378 lockdep_assert_wiphy(local->hw.wiphy); 4379 4380 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)) 4381 return; 4382 4383 __ieee80211_stop_poll(sdata); 4384 4385 ieee80211_recalc_ps(local); 4386 4387 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR)) 4388 return; 4389 4390 /* 4391 * We've received a probe response, but are not sure whether 4392 * we have or will be receiving any beacons or data, so let's 4393 * schedule the timers again, just in case. 4394 */ 4395 ieee80211_sta_reset_beacon_monitor(sdata); 4396 4397 mod_timer(&ifmgd->conn_mon_timer, 4398 round_jiffies_up(jiffies + 4399 IEEE80211_CONNECTION_IDLE_TIME)); 4400 } 4401 4402 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata, 4403 struct ieee80211_hdr *hdr, 4404 u16 tx_time) 4405 { 4406 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 4407 u16 tid; 4408 int ac; 4409 struct ieee80211_sta_tx_tspec *tx_tspec; 4410 unsigned long now = jiffies; 4411 4412 if (!ieee80211_is_data_qos(hdr->frame_control)) 4413 return; 4414 4415 tid = ieee80211_get_tid(hdr); 4416 ac = ieee80211_ac_from_tid(tid); 4417 tx_tspec = &ifmgd->tx_tspec[ac]; 4418 4419 if (likely(!tx_tspec->admitted_time)) 4420 return; 4421 4422 if (time_after(now, tx_tspec->time_slice_start + HZ)) { 4423 tx_tspec->consumed_tx_time = 0; 4424 tx_tspec->time_slice_start = now; 4425 4426 if (tx_tspec->downgraded) { 4427 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE; 4428 wiphy_delayed_work_queue(sdata->local->hw.wiphy, 4429 &ifmgd->tx_tspec_wk, 0); 4430 } 4431 } 4432 4433 if (tx_tspec->downgraded) 4434 return; 4435 4436 tx_tspec->consumed_tx_time += tx_time; 4437 4438 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) { 4439 tx_tspec->downgraded = true; 4440 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE; 4441 wiphy_delayed_work_queue(sdata->local->hw.wiphy, 4442 &ifmgd->tx_tspec_wk, 0); 4443 } 4444 } 4445 4446 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata, 4447 struct ieee80211_hdr *hdr, bool ack, u16 tx_time) 4448 { 4449 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time); 4450 4451 if (!ieee80211_is_any_nullfunc(hdr->frame_control) || 4452 !sdata->u.mgd.probe_send_count) 4453 return; 4454 4455 if (ack) 4456 sdata->u.mgd.probe_send_count = 0; 4457 else 4458 sdata->u.mgd.nullfunc_failed = true; 4459 wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work); 4460 } 4461 4462 static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata, 4463 const u8 *src, const u8 *dst, 4464 const u8 *ssid, size_t ssid_len, 4465 struct ieee80211_channel *channel) 4466 { 4467 struct sk_buff *skb; 4468 4469 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel, 4470 ssid, ssid_len, NULL, 0, 4471 IEEE80211_PROBE_FLAG_DIRECTED); 4472 if (skb) 4473 ieee80211_tx_skb(sdata, skb); 4474 } 4475 4476 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata) 4477 { 4478 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 4479 u8 *dst = sdata->vif.cfg.ap_addr; 4480 u8 unicast_limit = max(1, max_probe_tries - 3); 4481 struct sta_info *sta; 4482 4483 lockdep_assert_wiphy(sdata->local->hw.wiphy); 4484 4485 /* 4486 * Try sending broadcast probe requests for the last three 4487 * probe requests after the first ones failed since some 4488 * buggy APs only support broadcast probe requests. 4489 */ 4490 if (ifmgd->probe_send_count >= unicast_limit) 4491 dst = NULL; 4492 4493 /* 4494 * When the hardware reports an accurate Tx ACK status, it's 4495 * better to send a nullfunc frame instead of a probe request, 4496 * as it will kick us off the AP quickly if we aren't associated 4497 * anymore. The timeout will be reset if the frame is ACKed by 4498 * the AP. 4499 */ 4500 ifmgd->probe_send_count++; 4501 4502 if (dst) { 4503 sta = sta_info_get(sdata, dst); 4504 if (!WARN_ON(!sta)) 4505 ieee80211_check_fast_rx(sta); 4506 } 4507 4508 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) { 4509 ifmgd->nullfunc_failed = false; 4510 ieee80211_send_nullfunc(sdata->local, sdata, false); 4511 } else { 4512 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst, 4513 sdata->vif.cfg.ssid, 4514 sdata->vif.cfg.ssid_len, 4515 sdata->deflink.conf->bss->channel); 4516 } 4517 4518 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms); 4519 run_again(sdata, ifmgd->probe_timeout); 4520 } 4521 4522 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata, 4523 bool beacon) 4524 { 4525 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 4526 bool already = false; 4527 4528 lockdep_assert_wiphy(sdata->local->hw.wiphy); 4529 4530 if (!ieee80211_sdata_running(sdata)) 4531 return; 4532 4533 if (!ifmgd->associated) 4534 return; 4535 4536 if (sdata->local->tmp_channel || sdata->local->scanning) 4537 return; 4538 4539 if (sdata->local->suspending) { 4540 /* reschedule after resume */ 4541 ieee80211_reset_ap_probe(sdata); 4542 return; 4543 } 4544 4545 if (beacon) { 4546 mlme_dbg_ratelimited(sdata, 4547 "detected beacon loss from AP (missed %d beacons) - probing\n", 4548 beacon_loss_count); 4549 4550 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL); 4551 } 4552 4553 /* 4554 * The driver/our work has already reported this event or the 4555 * connection monitoring has kicked in and we have already sent 4556 * a probe request. Or maybe the AP died and the driver keeps 4557 * reporting until we disassociate... 4558 * 4559 * In either case we have to ignore the current call to this 4560 * function (except for setting the correct probe reason bit) 4561 * because otherwise we would reset the timer every time and 4562 * never check whether we received a probe response! 4563 */ 4564 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) 4565 already = true; 4566 4567 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL; 4568 4569 if (already) 4570 return; 4571 4572 ieee80211_recalc_ps(sdata->local); 4573 4574 ifmgd->probe_send_count = 0; 4575 ieee80211_mgd_probe_ap_send(sdata); 4576 } 4577 4578 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw, 4579 struct ieee80211_vif *vif) 4580 { 4581 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 4582 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 4583 struct cfg80211_bss *cbss; 4584 struct sk_buff *skb; 4585 const struct element *ssid; 4586 int ssid_len; 4587 4588 lockdep_assert_wiphy(sdata->local->hw.wiphy); 4589 4590 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION || 4591 ieee80211_vif_is_mld(&sdata->vif))) 4592 return NULL; 4593 4594 if (ifmgd->associated) 4595 cbss = sdata->deflink.conf->bss; 4596 else if (ifmgd->auth_data) 4597 cbss = ifmgd->auth_data->bss; 4598 else if (ifmgd->assoc_data && ifmgd->assoc_data->link[0].bss) 4599 cbss = ifmgd->assoc_data->link[0].bss; 4600 else 4601 return NULL; 4602 4603 rcu_read_lock(); 4604 ssid = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID); 4605 if (WARN_ONCE(!ssid || ssid->datalen > IEEE80211_MAX_SSID_LEN, 4606 "invalid SSID element (len=%d)", 4607 ssid ? ssid->datalen : -1)) 4608 ssid_len = 0; 4609 else 4610 ssid_len = ssid->datalen; 4611 4612 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid, 4613 (u32) -1, cbss->channel, 4614 ssid->data, ssid_len, 4615 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED); 4616 rcu_read_unlock(); 4617 4618 return skb; 4619 } 4620 EXPORT_SYMBOL(ieee80211_ap_probereq_get); 4621 4622 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata, 4623 const u8 *buf, size_t len, bool tx, 4624 u16 reason, bool reconnect) 4625 { 4626 struct ieee80211_event event = { 4627 .type = MLME_EVENT, 4628 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT, 4629 .u.mlme.reason = reason, 4630 }; 4631 4632 if (tx) 4633 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect); 4634 else 4635 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len); 4636 4637 drv_event_callback(sdata->local, sdata, &event); 4638 } 4639 4640 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata) 4641 { 4642 struct ieee80211_local *local = sdata->local; 4643 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 4644 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; 4645 4646 lockdep_assert_wiphy(local->hw.wiphy); 4647 4648 if (!ifmgd->associated) 4649 return; 4650 4651 if (!ifmgd->driver_disconnect) { 4652 unsigned int link_id; 4653 4654 /* 4655 * AP is probably out of range (or not reachable for another 4656 * reason) so remove the bss structs for that AP. In the case 4657 * of multi-link, it's not clear that all of them really are 4658 * out of range, but if they weren't the driver likely would 4659 * have switched to just have a single link active? 4660 */ 4661 for (link_id = 0; 4662 link_id < ARRAY_SIZE(sdata->link); 4663 link_id++) { 4664 struct ieee80211_link_data *link; 4665 4666 link = sdata_dereference(sdata->link[link_id], sdata); 4667 if (!link || !link->conf->bss) 4668 continue; 4669 cfg80211_unlink_bss(local->hw.wiphy, link->conf->bss); 4670 link->conf->bss = NULL; 4671 } 4672 } 4673 4674 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, 4675 ifmgd->driver_disconnect ? 4676 WLAN_REASON_DEAUTH_LEAVING : 4677 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, 4678 true, frame_buf); 4679 /* the other links will be destroyed */ 4680 sdata->vif.bss_conf.csa_active = false; 4681 sdata->deflink.u.mgd.csa.waiting_bcn = false; 4682 sdata->deflink.u.mgd.csa.blocked_tx = false; 4683 ieee80211_vif_unblock_queues_csa(sdata); 4684 4685 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true, 4686 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, 4687 ifmgd->reconnect); 4688 ifmgd->reconnect = false; 4689 } 4690 4691 static void ieee80211_beacon_connection_loss_work(struct wiphy *wiphy, 4692 struct wiphy_work *work) 4693 { 4694 struct ieee80211_sub_if_data *sdata = 4695 container_of(work, struct ieee80211_sub_if_data, 4696 u.mgd.beacon_connection_loss_work); 4697 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 4698 4699 if (ifmgd->connection_loss) { 4700 sdata_info(sdata, "Connection to AP %pM lost\n", 4701 sdata->vif.cfg.ap_addr); 4702 __ieee80211_disconnect(sdata); 4703 ifmgd->connection_loss = false; 4704 } else if (ifmgd->driver_disconnect) { 4705 sdata_info(sdata, 4706 "Driver requested disconnection from AP %pM\n", 4707 sdata->vif.cfg.ap_addr); 4708 __ieee80211_disconnect(sdata); 4709 ifmgd->driver_disconnect = false; 4710 } else { 4711 if (ifmgd->associated) 4712 sdata->deflink.u.mgd.beacon_loss_count++; 4713 ieee80211_mgd_probe_ap(sdata, true); 4714 } 4715 } 4716 4717 static void ieee80211_csa_connection_drop_work(struct wiphy *wiphy, 4718 struct wiphy_work *work) 4719 { 4720 struct ieee80211_sub_if_data *sdata = 4721 container_of(work, struct ieee80211_sub_if_data, 4722 u.mgd.csa_connection_drop_work); 4723 4724 __ieee80211_disconnect(sdata); 4725 } 4726 4727 void ieee80211_beacon_loss(struct ieee80211_vif *vif) 4728 { 4729 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 4730 struct ieee80211_hw *hw = &sdata->local->hw; 4731 4732 trace_api_beacon_loss(sdata); 4733 4734 sdata->u.mgd.connection_loss = false; 4735 wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work); 4736 } 4737 EXPORT_SYMBOL(ieee80211_beacon_loss); 4738 4739 void ieee80211_connection_loss(struct ieee80211_vif *vif) 4740 { 4741 struct ieee80211_sub_if_data *sdata; 4742 struct ieee80211_hw *hw; 4743 4744 KUNIT_STATIC_STUB_REDIRECT(ieee80211_connection_loss, vif); 4745 4746 sdata = vif_to_sdata(vif); 4747 hw = &sdata->local->hw; 4748 4749 trace_api_connection_loss(sdata); 4750 4751 sdata->u.mgd.connection_loss = true; 4752 wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work); 4753 } 4754 EXPORT_SYMBOL(ieee80211_connection_loss); 4755 4756 void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect) 4757 { 4758 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 4759 struct ieee80211_hw *hw = &sdata->local->hw; 4760 4761 trace_api_disconnect(sdata, reconnect); 4762 4763 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) 4764 return; 4765 4766 sdata->u.mgd.driver_disconnect = true; 4767 sdata->u.mgd.reconnect = reconnect; 4768 wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work); 4769 } 4770 EXPORT_SYMBOL(ieee80211_disconnect); 4771 4772 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata, 4773 bool assoc) 4774 { 4775 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data; 4776 4777 lockdep_assert_wiphy(sdata->local->hw.wiphy); 4778 4779 sdata->u.mgd.auth_data = NULL; 4780 4781 if (!assoc) { 4782 /* 4783 * we are not authenticated yet, the only timer that could be 4784 * running is the timeout for the authentication response which 4785 * which is not relevant anymore. 4786 */ 4787 timer_delete_sync(&sdata->u.mgd.timer); 4788 sta_info_destroy_addr(sdata, auth_data->ap_addr); 4789 4790 /* other links are destroyed */ 4791 eth_zero_addr(sdata->deflink.u.mgd.bssid); 4792 ieee80211_link_info_change_notify(sdata, &sdata->deflink, 4793 BSS_CHANGED_BSSID); 4794 sdata->u.mgd.flags = 0; 4795 4796 ieee80211_link_release_channel(&sdata->deflink); 4797 ieee80211_vif_set_links(sdata, 0, 0); 4798 } 4799 4800 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss); 4801 kfree(auth_data); 4802 } 4803 4804 enum assoc_status { 4805 ASSOC_SUCCESS, 4806 ASSOC_REJECTED, 4807 ASSOC_TIMEOUT, 4808 ASSOC_ABANDON, 4809 }; 4810 4811 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata, 4812 enum assoc_status status) 4813 { 4814 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data; 4815 4816 lockdep_assert_wiphy(sdata->local->hw.wiphy); 4817 4818 sdata->u.mgd.assoc_data = NULL; 4819 4820 if (status != ASSOC_SUCCESS) { 4821 /* 4822 * we are not associated yet, the only timer that could be 4823 * running is the timeout for the association response which 4824 * which is not relevant anymore. 4825 */ 4826 timer_delete_sync(&sdata->u.mgd.timer); 4827 sta_info_destroy_addr(sdata, assoc_data->ap_addr); 4828 4829 eth_zero_addr(sdata->deflink.u.mgd.bssid); 4830 ieee80211_link_info_change_notify(sdata, &sdata->deflink, 4831 BSS_CHANGED_BSSID); 4832 sdata->u.mgd.flags = 0; 4833 sdata->vif.bss_conf.mu_mimo_owner = false; 4834 4835 if (status != ASSOC_REJECTED) { 4836 struct cfg80211_assoc_failure data = { 4837 .timeout = status == ASSOC_TIMEOUT, 4838 }; 4839 int i; 4840 4841 BUILD_BUG_ON(ARRAY_SIZE(data.bss) != 4842 ARRAY_SIZE(assoc_data->link)); 4843 4844 for (i = 0; i < ARRAY_SIZE(data.bss); i++) 4845 data.bss[i] = assoc_data->link[i].bss; 4846 4847 if (ieee80211_vif_is_mld(&sdata->vif)) 4848 data.ap_mld_addr = assoc_data->ap_addr; 4849 4850 cfg80211_assoc_failure(sdata->dev, &data); 4851 } 4852 4853 ieee80211_link_release_channel(&sdata->deflink); 4854 ieee80211_vif_set_links(sdata, 0, 0); 4855 } 4856 4857 kfree(assoc_data); 4858 } 4859 4860 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata, 4861 struct ieee80211_mgmt *mgmt, size_t len) 4862 { 4863 struct ieee80211_local *local = sdata->local; 4864 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data; 4865 const struct element *challenge; 4866 u8 *pos; 4867 u32 tx_flags = 0; 4868 struct ieee80211_prep_tx_info info = { 4869 .subtype = IEEE80211_STYPE_AUTH, 4870 .link_id = auth_data->link_id, 4871 }; 4872 4873 pos = mgmt->u.auth.variable; 4874 challenge = cfg80211_find_elem(WLAN_EID_CHALLENGE, pos, 4875 len - (pos - (u8 *)mgmt)); 4876 if (!challenge) 4877 return; 4878 auth_data->expected_transaction = 4; 4879 drv_mgd_prepare_tx(sdata->local, sdata, &info); 4880 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) 4881 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS | 4882 IEEE80211_TX_INTFL_MLME_CONN_TX; 4883 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0, 4884 (void *)challenge, 4885 challenge->datalen + sizeof(*challenge), 4886 auth_data->ap_addr, auth_data->ap_addr, 4887 auth_data->key, auth_data->key_len, 4888 auth_data->key_idx, tx_flags); 4889 } 4890 4891 static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata) 4892 { 4893 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 4894 const u8 *ap_addr = ifmgd->auth_data->ap_addr; 4895 struct sta_info *sta; 4896 4897 lockdep_assert_wiphy(sdata->local->hw.wiphy); 4898 4899 sdata_info(sdata, "authenticated\n"); 4900 ifmgd->auth_data->done = true; 4901 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC; 4902 ifmgd->auth_data->timeout_started = true; 4903 run_again(sdata, ifmgd->auth_data->timeout); 4904 4905 /* move station state to auth */ 4906 sta = sta_info_get(sdata, ap_addr); 4907 if (!sta) { 4908 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, ap_addr); 4909 return false; 4910 } 4911 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) { 4912 sdata_info(sdata, "failed moving %pM to auth\n", ap_addr); 4913 return false; 4914 } 4915 4916 return true; 4917 } 4918 4919 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata, 4920 struct ieee80211_mgmt *mgmt, size_t len) 4921 { 4922 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 4923 u16 auth_alg, auth_transaction, status_code; 4924 struct ieee80211_event event = { 4925 .type = MLME_EVENT, 4926 .u.mlme.data = AUTH_EVENT, 4927 }; 4928 struct ieee80211_prep_tx_info info = { 4929 .subtype = IEEE80211_STYPE_AUTH, 4930 }; 4931 bool sae_need_confirm = false; 4932 4933 lockdep_assert_wiphy(sdata->local->hw.wiphy); 4934 4935 if (len < 24 + 6) 4936 return; 4937 4938 if (!ifmgd->auth_data || ifmgd->auth_data->done) 4939 return; 4940 4941 if (!ether_addr_equal(ifmgd->auth_data->ap_addr, mgmt->bssid)) 4942 return; 4943 4944 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); 4945 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); 4946 status_code = le16_to_cpu(mgmt->u.auth.status_code); 4947 4948 info.link_id = ifmgd->auth_data->link_id; 4949 4950 if (auth_alg != ifmgd->auth_data->algorithm || 4951 (auth_alg != WLAN_AUTH_SAE && 4952 auth_transaction != ifmgd->auth_data->expected_transaction) || 4953 (auth_alg == WLAN_AUTH_SAE && 4954 (auth_transaction < ifmgd->auth_data->expected_transaction || 4955 auth_transaction > 2))) { 4956 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n", 4957 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm, 4958 auth_transaction, 4959 ifmgd->auth_data->expected_transaction); 4960 goto notify_driver; 4961 } 4962 4963 if (status_code != WLAN_STATUS_SUCCESS) { 4964 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len); 4965 4966 if (auth_alg == WLAN_AUTH_SAE && 4967 (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED || 4968 (auth_transaction == 1 && 4969 (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT || 4970 status_code == WLAN_STATUS_SAE_PK)))) { 4971 /* waiting for userspace now */ 4972 ifmgd->auth_data->waiting = true; 4973 ifmgd->auth_data->timeout = 4974 jiffies + IEEE80211_AUTH_WAIT_SAE_RETRY; 4975 ifmgd->auth_data->timeout_started = true; 4976 run_again(sdata, ifmgd->auth_data->timeout); 4977 if (auth_transaction == 1) 4978 sae_need_confirm = true; 4979 goto notify_driver; 4980 } 4981 4982 sdata_info(sdata, "%pM denied authentication (status %d)\n", 4983 mgmt->sa, status_code); 4984 ieee80211_destroy_auth_data(sdata, false); 4985 event.u.mlme.status = MLME_DENIED; 4986 event.u.mlme.reason = status_code; 4987 drv_event_callback(sdata->local, sdata, &event); 4988 goto notify_driver; 4989 } 4990 4991 switch (ifmgd->auth_data->algorithm) { 4992 case WLAN_AUTH_OPEN: 4993 case WLAN_AUTH_LEAP: 4994 case WLAN_AUTH_FT: 4995 case WLAN_AUTH_SAE: 4996 case WLAN_AUTH_FILS_SK: 4997 case WLAN_AUTH_FILS_SK_PFS: 4998 case WLAN_AUTH_FILS_PK: 4999 case WLAN_AUTH_EPPKE: 5000 break; 5001 case WLAN_AUTH_SHARED_KEY: 5002 if (ifmgd->auth_data->expected_transaction != 4) { 5003 ieee80211_auth_challenge(sdata, mgmt, len); 5004 /* need another frame */ 5005 return; 5006 } 5007 break; 5008 default: 5009 WARN_ONCE(1, "invalid auth alg %d", 5010 ifmgd->auth_data->algorithm); 5011 goto notify_driver; 5012 } 5013 5014 event.u.mlme.status = MLME_SUCCESS; 5015 info.success = 1; 5016 drv_event_callback(sdata->local, sdata, &event); 5017 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE || 5018 (auth_transaction == 2 && 5019 ifmgd->auth_data->expected_transaction == 2)) { 5020 if (!ieee80211_mark_sta_auth(sdata)) 5021 return; /* ignore frame -- wait for timeout */ 5022 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE && 5023 auth_transaction == 1) { 5024 sae_need_confirm = true; 5025 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE && 5026 auth_transaction == 2) { 5027 sdata_info(sdata, "SAE peer confirmed\n"); 5028 ifmgd->auth_data->peer_confirmed = true; 5029 } 5030 5031 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len); 5032 notify_driver: 5033 if (!sae_need_confirm) 5034 drv_mgd_complete_tx(sdata->local, sdata, &info); 5035 } 5036 5037 #define case_WLAN(type) \ 5038 case WLAN_REASON_##type: return #type 5039 5040 const char *ieee80211_get_reason_code_string(u16 reason_code) 5041 { 5042 switch (reason_code) { 5043 case_WLAN(UNSPECIFIED); 5044 case_WLAN(PREV_AUTH_NOT_VALID); 5045 case_WLAN(DEAUTH_LEAVING); 5046 case_WLAN(DISASSOC_DUE_TO_INACTIVITY); 5047 case_WLAN(DISASSOC_AP_BUSY); 5048 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA); 5049 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA); 5050 case_WLAN(DISASSOC_STA_HAS_LEFT); 5051 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH); 5052 case_WLAN(DISASSOC_BAD_POWER); 5053 case_WLAN(DISASSOC_BAD_SUPP_CHAN); 5054 case_WLAN(INVALID_IE); 5055 case_WLAN(MIC_FAILURE); 5056 case_WLAN(4WAY_HANDSHAKE_TIMEOUT); 5057 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT); 5058 case_WLAN(IE_DIFFERENT); 5059 case_WLAN(INVALID_GROUP_CIPHER); 5060 case_WLAN(INVALID_PAIRWISE_CIPHER); 5061 case_WLAN(INVALID_AKMP); 5062 case_WLAN(UNSUPP_RSN_VERSION); 5063 case_WLAN(INVALID_RSN_IE_CAP); 5064 case_WLAN(IEEE8021X_FAILED); 5065 case_WLAN(CIPHER_SUITE_REJECTED); 5066 case_WLAN(DISASSOC_UNSPECIFIED_QOS); 5067 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH); 5068 case_WLAN(DISASSOC_LOW_ACK); 5069 case_WLAN(DISASSOC_QAP_EXCEED_TXOP); 5070 case_WLAN(QSTA_LEAVE_QBSS); 5071 case_WLAN(QSTA_NOT_USE); 5072 case_WLAN(QSTA_REQUIRE_SETUP); 5073 case_WLAN(QSTA_TIMEOUT); 5074 case_WLAN(QSTA_CIPHER_NOT_SUPP); 5075 case_WLAN(MESH_PEER_CANCELED); 5076 case_WLAN(MESH_MAX_PEERS); 5077 case_WLAN(MESH_CONFIG); 5078 case_WLAN(MESH_CLOSE); 5079 case_WLAN(MESH_MAX_RETRIES); 5080 case_WLAN(MESH_CONFIRM_TIMEOUT); 5081 case_WLAN(MESH_INVALID_GTK); 5082 case_WLAN(MESH_INCONSISTENT_PARAM); 5083 case_WLAN(MESH_INVALID_SECURITY); 5084 case_WLAN(MESH_PATH_ERROR); 5085 case_WLAN(MESH_PATH_NOFORWARD); 5086 case_WLAN(MESH_PATH_DEST_UNREACHABLE); 5087 case_WLAN(MAC_EXISTS_IN_MBSS); 5088 case_WLAN(MESH_CHAN_REGULATORY); 5089 case_WLAN(MESH_CHAN); 5090 default: return "<unknown>"; 5091 } 5092 } 5093 5094 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata, 5095 struct ieee80211_mgmt *mgmt, size_t len) 5096 { 5097 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 5098 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); 5099 5100 lockdep_assert_wiphy(sdata->local->hw.wiphy); 5101 5102 if (len < 24 + 2) 5103 return; 5104 5105 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) { 5106 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code); 5107 return; 5108 } 5109 5110 if (ifmgd->associated && 5111 ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr)) { 5112 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n", 5113 sdata->vif.cfg.ap_addr, reason_code, 5114 ieee80211_get_reason_code_string(reason_code)); 5115 5116 ieee80211_set_disassoc(sdata, 0, 0, false, NULL); 5117 5118 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, 5119 reason_code, false); 5120 return; 5121 } 5122 5123 if (ifmgd->assoc_data && 5124 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->ap_addr)) { 5125 sdata_info(sdata, 5126 "deauthenticated from %pM while associating (Reason: %u=%s)\n", 5127 ifmgd->assoc_data->ap_addr, reason_code, 5128 ieee80211_get_reason_code_string(reason_code)); 5129 5130 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON); 5131 5132 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len); 5133 return; 5134 } 5135 } 5136 5137 5138 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata, 5139 struct ieee80211_mgmt *mgmt, size_t len) 5140 { 5141 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 5142 u16 reason_code; 5143 5144 lockdep_assert_wiphy(sdata->local->hw.wiphy); 5145 5146 if (len < 24 + 2) 5147 return; 5148 5149 if (!ifmgd->associated || 5150 !ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr)) 5151 return; 5152 5153 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); 5154 5155 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) { 5156 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code); 5157 return; 5158 } 5159 5160 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n", 5161 sdata->vif.cfg.ap_addr, reason_code, 5162 ieee80211_get_reason_code_string(reason_code)); 5163 5164 ieee80211_set_disassoc(sdata, 0, 0, false, NULL); 5165 5166 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code, 5167 false); 5168 } 5169 5170 static bool ieee80211_twt_req_supported(struct ieee80211_sub_if_data *sdata, 5171 struct ieee80211_supported_band *sband, 5172 const struct link_sta_info *link_sta, 5173 const struct ieee802_11_elems *elems) 5174 { 5175 const struct ieee80211_sta_he_cap *own_he_cap = 5176 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif); 5177 5178 if (elems->ext_capab_len < 10) 5179 return false; 5180 5181 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT)) 5182 return false; 5183 5184 return link_sta->pub->he_cap.he_cap_elem.mac_cap_info[0] & 5185 IEEE80211_HE_MAC_CAP0_TWT_RES && 5186 own_he_cap && 5187 (own_he_cap->he_cap_elem.mac_cap_info[0] & 5188 IEEE80211_HE_MAC_CAP0_TWT_REQ); 5189 } 5190 5191 static u64 ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata, 5192 struct ieee80211_supported_band *sband, 5193 struct ieee80211_link_data *link, 5194 struct link_sta_info *link_sta, 5195 struct ieee802_11_elems *elems) 5196 { 5197 bool twt = ieee80211_twt_req_supported(sdata, sband, link_sta, elems); 5198 5199 if (link->conf->twt_requester != twt) { 5200 link->conf->twt_requester = twt; 5201 return BSS_CHANGED_TWT; 5202 } 5203 return 0; 5204 } 5205 5206 static bool ieee80211_twt_bcast_support(struct ieee80211_sub_if_data *sdata, 5207 struct ieee80211_bss_conf *bss_conf, 5208 struct ieee80211_supported_band *sband, 5209 struct link_sta_info *link_sta) 5210 { 5211 const struct ieee80211_sta_he_cap *own_he_cap = 5212 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif); 5213 5214 return bss_conf->he_support && 5215 (link_sta->pub->he_cap.he_cap_elem.mac_cap_info[2] & 5216 IEEE80211_HE_MAC_CAP2_BCAST_TWT) && 5217 own_he_cap && 5218 (own_he_cap->he_cap_elem.mac_cap_info[2] & 5219 IEEE80211_HE_MAC_CAP2_BCAST_TWT); 5220 } 5221 5222 static void ieee80211_epcs_changed(struct ieee80211_sub_if_data *sdata, 5223 bool enabled) 5224 { 5225 /* in any case this is called, dialog token should be reset */ 5226 sdata->u.mgd.epcs.dialog_token = 0; 5227 5228 if (sdata->u.mgd.epcs.enabled == enabled) 5229 return; 5230 5231 sdata->u.mgd.epcs.enabled = enabled; 5232 cfg80211_epcs_changed(sdata->dev, enabled); 5233 } 5234 5235 static void ieee80211_epcs_teardown(struct ieee80211_sub_if_data *sdata) 5236 { 5237 struct ieee80211_local *local = sdata->local; 5238 u8 link_id; 5239 5240 if (!sdata->u.mgd.epcs.enabled) 5241 return; 5242 5243 lockdep_assert_wiphy(local->hw.wiphy); 5244 5245 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { 5246 struct ieee802_11_elems *elems; 5247 struct ieee80211_link_data *link; 5248 const struct cfg80211_bss_ies *ies; 5249 bool ret; 5250 5251 rcu_read_lock(); 5252 5253 link = sdata_dereference(sdata->link[link_id], sdata); 5254 if (!link || !link->conf || !link->conf->bss) { 5255 rcu_read_unlock(); 5256 continue; 5257 } 5258 5259 if (link->u.mgd.disable_wmm_tracking) { 5260 rcu_read_unlock(); 5261 ieee80211_set_wmm_default(link, false, false); 5262 continue; 5263 } 5264 5265 ies = rcu_dereference(link->conf->bss->beacon_ies); 5266 if (!ies) { 5267 rcu_read_unlock(); 5268 ieee80211_set_wmm_default(link, false, false); 5269 continue; 5270 } 5271 5272 elems = ieee802_11_parse_elems(ies->data, ies->len, 5273 IEEE80211_FTYPE_MGMT | 5274 IEEE80211_STYPE_BEACON, 5275 NULL); 5276 if (!elems) { 5277 rcu_read_unlock(); 5278 ieee80211_set_wmm_default(link, false, false); 5279 continue; 5280 } 5281 5282 ret = _ieee80211_sta_wmm_params(local, link, 5283 elems->wmm_param, 5284 elems->wmm_param_len, 5285 elems->mu_edca_param_set); 5286 5287 kfree(elems); 5288 rcu_read_unlock(); 5289 5290 if (!ret) { 5291 ieee80211_set_wmm_default(link, false, false); 5292 continue; 5293 } 5294 5295 ieee80211_mgd_set_link_qos_params(link); 5296 ieee80211_link_info_change_notify(sdata, link, BSS_CHANGED_QOS); 5297 } 5298 } 5299 5300 static bool ieee80211_assoc_config_link(struct ieee80211_link_data *link, 5301 struct link_sta_info *link_sta, 5302 struct cfg80211_bss *cbss, 5303 struct ieee80211_mgmt *mgmt, 5304 const u8 *elem_start, 5305 unsigned int elem_len, 5306 u64 *changed) 5307 { 5308 struct ieee80211_sub_if_data *sdata = link->sdata; 5309 struct ieee80211_mgd_assoc_data *assoc_data = 5310 sdata->u.mgd.assoc_data ?: sdata->u.mgd.reconf.add_links_data; 5311 struct ieee80211_bss_conf *bss_conf = link->conf; 5312 struct ieee80211_local *local = sdata->local; 5313 unsigned int link_id = link->link_id; 5314 struct ieee80211_elems_parse_params parse_params = { 5315 .mode = link->u.mgd.conn.mode, 5316 .start = elem_start, 5317 .len = elem_len, 5318 .link_id = link_id == assoc_data->assoc_link_id ? -1 : link_id, 5319 .from_ap = true, 5320 .type = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_TYPE, 5321 }; 5322 bool is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ; 5323 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ; 5324 bool is_s1g = cbss->channel->band == NL80211_BAND_S1GHZ; 5325 const struct cfg80211_bss_ies *bss_ies = NULL; 5326 struct ieee80211_supported_band *sband; 5327 struct ieee802_11_elems *elems; 5328 const __le16 prof_bss_param_ch_present = 5329 cpu_to_le16(IEEE80211_MLE_STA_CONTROL_BSS_PARAM_CHANGE_CNT_PRESENT); 5330 u16 capab_info; 5331 bool ret; 5332 5333 elems = ieee802_11_parse_elems_full(&parse_params); 5334 if (!elems) 5335 return false; 5336 5337 if (link_id == assoc_data->assoc_link_id) { 5338 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); 5339 5340 /* 5341 * we should not get to this flow unless the association was 5342 * successful, so set the status directly to success 5343 */ 5344 assoc_data->link[link_id].status = WLAN_STATUS_SUCCESS; 5345 if (elems->ml_basic) { 5346 int bss_param_ch_cnt = 5347 ieee80211_mle_get_bss_param_ch_cnt((const void *)elems->ml_basic); 5348 5349 if (bss_param_ch_cnt < 0) { 5350 ret = false; 5351 goto out; 5352 } 5353 bss_conf->bss_param_ch_cnt = bss_param_ch_cnt; 5354 bss_conf->bss_param_ch_cnt_link_id = link_id; 5355 } 5356 } else if (elems->parse_error & IEEE80211_PARSE_ERR_DUP_NEST_ML_BASIC || 5357 !elems->prof || 5358 !(elems->prof->control & prof_bss_param_ch_present)) { 5359 ret = false; 5360 goto out; 5361 } else { 5362 const u8 *ptr = elems->prof->variable + 5363 elems->prof->sta_info_len - 1; 5364 int bss_param_ch_cnt; 5365 5366 /* 5367 * During parsing, we validated that these fields exist, 5368 * otherwise elems->prof would have been set to NULL. 5369 */ 5370 capab_info = get_unaligned_le16(ptr); 5371 assoc_data->link[link_id].status = get_unaligned_le16(ptr + 2); 5372 bss_param_ch_cnt = 5373 ieee80211_mle_basic_sta_prof_bss_param_ch_cnt(elems->prof); 5374 bss_conf->bss_param_ch_cnt = bss_param_ch_cnt; 5375 bss_conf->bss_param_ch_cnt_link_id = link_id; 5376 5377 if (assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) { 5378 link_info(link, "association response status code=%u\n", 5379 assoc_data->link[link_id].status); 5380 ret = true; 5381 goto out; 5382 } 5383 } 5384 5385 if (!is_s1g && !elems->supp_rates) { 5386 sdata_info(sdata, "no SuppRates element in AssocResp\n"); 5387 ret = false; 5388 goto out; 5389 } 5390 5391 link->u.mgd.tdls_chan_switch_prohibited = 5392 elems->ext_capab && elems->ext_capab_len >= 5 && 5393 (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED); 5394 5395 /* 5396 * Some APs are erroneously not including some information in their 5397 * (re)association response frames. Try to recover by using the data 5398 * from the beacon or probe response. This seems to afflict mobile 5399 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T", 5400 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device. 5401 */ 5402 if (!ieee80211_hw_check(&local->hw, STRICT) && !is_6ghz && 5403 ((assoc_data->wmm && !elems->wmm_param) || 5404 (link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HT && 5405 (!elems->ht_cap_elem || !elems->ht_operation)) || 5406 (is_5ghz && link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_VHT && 5407 (!elems->vht_cap_elem || !elems->vht_operation)))) { 5408 const struct cfg80211_bss_ies *ies; 5409 struct ieee802_11_elems *bss_elems; 5410 5411 rcu_read_lock(); 5412 ies = rcu_dereference(cbss->ies); 5413 if (ies) 5414 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len, 5415 GFP_ATOMIC); 5416 rcu_read_unlock(); 5417 if (!bss_ies) { 5418 ret = false; 5419 goto out; 5420 } 5421 5422 parse_params.start = bss_ies->data; 5423 parse_params.len = bss_ies->len; 5424 parse_params.bss = cbss; 5425 parse_params.link_id = -1; 5426 bss_elems = ieee802_11_parse_elems_full(&parse_params); 5427 if (!bss_elems) { 5428 ret = false; 5429 goto out; 5430 } 5431 5432 if (assoc_data->wmm && 5433 !elems->wmm_param && bss_elems->wmm_param) { 5434 elems->wmm_param = bss_elems->wmm_param; 5435 sdata_info(sdata, 5436 "AP bug: WMM param missing from AssocResp\n"); 5437 } 5438 5439 /* 5440 * Also check if we requested HT/VHT, otherwise the AP doesn't 5441 * have to include the IEs in the (re)association response. 5442 */ 5443 if (!elems->ht_cap_elem && bss_elems->ht_cap_elem && 5444 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HT) { 5445 elems->ht_cap_elem = bss_elems->ht_cap_elem; 5446 sdata_info(sdata, 5447 "AP bug: HT capability missing from AssocResp\n"); 5448 } 5449 if (!elems->ht_operation && bss_elems->ht_operation && 5450 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HT) { 5451 elems->ht_operation = bss_elems->ht_operation; 5452 sdata_info(sdata, 5453 "AP bug: HT operation missing from AssocResp\n"); 5454 } 5455 5456 if (is_5ghz) { 5457 if (!elems->vht_cap_elem && bss_elems->vht_cap_elem && 5458 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_VHT) { 5459 elems->vht_cap_elem = bss_elems->vht_cap_elem; 5460 sdata_info(sdata, 5461 "AP bug: VHT capa missing from AssocResp\n"); 5462 } 5463 5464 if (!elems->vht_operation && bss_elems->vht_operation && 5465 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_VHT) { 5466 elems->vht_operation = bss_elems->vht_operation; 5467 sdata_info(sdata, 5468 "AP bug: VHT operation missing from AssocResp\n"); 5469 } 5470 } 5471 kfree(bss_elems); 5472 } 5473 5474 /* 5475 * We previously checked these in the beacon/probe response, so 5476 * they should be present here. This is just a safety net. 5477 * Note that the ieee80211_config_bw() below would also check 5478 * for this (and more), but this has better error reporting. 5479 */ 5480 if (!is_6ghz && link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HT && 5481 (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) { 5482 sdata_info(sdata, 5483 "HT AP is missing WMM params or HT capability/operation\n"); 5484 ret = false; 5485 goto out; 5486 } 5487 5488 if (is_5ghz && link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_VHT && 5489 (!elems->vht_cap_elem || !elems->vht_operation)) { 5490 sdata_info(sdata, 5491 "VHT AP is missing VHT capability/operation\n"); 5492 ret = false; 5493 goto out; 5494 } 5495 5496 /* check/update if AP changed anything in assoc response vs. scan */ 5497 if (ieee80211_config_bw(link, elems, 5498 link_id == assoc_data->assoc_link_id, 5499 changed, 5500 le16_to_cpu(mgmt->frame_control) & 5501 IEEE80211_FCTL_STYPE)) { 5502 ret = false; 5503 goto out; 5504 } 5505 5506 if (WARN_ON(!link->conf->chanreq.oper.chan)) { 5507 ret = false; 5508 goto out; 5509 } 5510 sband = local->hw.wiphy->bands[link->conf->chanreq.oper.chan->band]; 5511 5512 /* Set up internal HT/VHT capabilities */ 5513 if (elems->ht_cap_elem && link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HT) 5514 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband, 5515 elems->ht_cap_elem, 5516 link_sta); 5517 5518 if (elems->vht_cap_elem && 5519 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_VHT) { 5520 const struct ieee80211_vht_cap *bss_vht_cap = NULL; 5521 const struct cfg80211_bss_ies *ies; 5522 5523 /* 5524 * Cisco AP module 9115 with FW 17.3 has a bug and sends a 5525 * too large maximum MPDU length in the association response 5526 * (indicating 12k) that it cannot actually process ... 5527 * Work around that. 5528 */ 5529 rcu_read_lock(); 5530 ies = rcu_dereference(cbss->ies); 5531 if (ies) { 5532 const struct element *elem; 5533 5534 elem = cfg80211_find_elem(WLAN_EID_VHT_CAPABILITY, 5535 ies->data, ies->len); 5536 if (elem && elem->datalen >= sizeof(*bss_vht_cap)) 5537 bss_vht_cap = (const void *)elem->data; 5538 } 5539 5540 if (ieee80211_hw_check(&local->hw, STRICT) && 5541 (!bss_vht_cap || memcmp(bss_vht_cap, elems->vht_cap_elem, 5542 sizeof(*bss_vht_cap)))) { 5543 rcu_read_unlock(); 5544 ret = false; 5545 link_info(link, "VHT capabilities mismatch\n"); 5546 goto out; 5547 } 5548 5549 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband, 5550 elems->vht_cap_elem, 5551 bss_vht_cap, link_sta); 5552 rcu_read_unlock(); 5553 } 5554 5555 if (elems->he_operation && 5556 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HE && 5557 elems->he_cap) { 5558 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband, 5559 elems->he_cap, 5560 elems->he_cap_len, 5561 elems->he_6ghz_capa, 5562 link_sta); 5563 5564 bss_conf->he_support = link_sta->pub->he_cap.has_he; 5565 if (elems->rsnx && elems->rsnx_len && 5566 (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) && 5567 wiphy_ext_feature_isset(local->hw.wiphy, 5568 NL80211_EXT_FEATURE_PROTECTED_TWT)) 5569 bss_conf->twt_protected = true; 5570 else 5571 bss_conf->twt_protected = false; 5572 5573 *changed |= ieee80211_recalc_twt_req(sdata, sband, link, 5574 link_sta, elems); 5575 5576 if (elems->eht_operation && elems->eht_cap && 5577 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_EHT) { 5578 ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband, 5579 elems->he_cap, 5580 elems->he_cap_len, 5581 elems->eht_cap, 5582 elems->eht_cap_len, 5583 link_sta); 5584 5585 bss_conf->eht_support = link_sta->pub->eht_cap.has_eht; 5586 bss_conf->epcs_support = bss_conf->eht_support && 5587 !!(elems->eht_cap->fixed.mac_cap_info[0] & 5588 IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS); 5589 5590 /* EPCS might be already enabled but a new added link 5591 * does not support EPCS. This should not really happen 5592 * in practice. 5593 */ 5594 if (sdata->u.mgd.epcs.enabled && 5595 !bss_conf->epcs_support) 5596 ieee80211_epcs_teardown(sdata); 5597 } else { 5598 bss_conf->eht_support = false; 5599 bss_conf->epcs_support = false; 5600 } 5601 } else { 5602 bss_conf->he_support = false; 5603 bss_conf->twt_requester = false; 5604 bss_conf->twt_protected = false; 5605 bss_conf->eht_support = false; 5606 bss_conf->epcs_support = false; 5607 } 5608 5609 if (elems->uhr_operation && elems->uhr_cap && 5610 link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_UHR) { 5611 ieee80211_uhr_cap_ie_to_sta_uhr_cap(sdata, sband, 5612 elems->uhr_cap, 5613 elems->uhr_cap_len, 5614 link_sta); 5615 5616 bss_conf->uhr_support = link_sta->pub->uhr_cap.has_uhr; 5617 } else { 5618 bss_conf->uhr_support = false; 5619 } 5620 5621 if (elems->s1g_oper && 5622 link->u.mgd.conn.mode == IEEE80211_CONN_MODE_S1G && 5623 elems->s1g_capab) 5624 ieee80211_s1g_cap_to_sta_s1g_cap(sdata, elems->s1g_capab, 5625 link_sta); 5626 5627 bss_conf->twt_broadcast = 5628 ieee80211_twt_bcast_support(sdata, bss_conf, sband, link_sta); 5629 5630 if (bss_conf->he_support) { 5631 bss_conf->he_bss_color.color = 5632 le32_get_bits(elems->he_operation->he_oper_params, 5633 IEEE80211_HE_OPERATION_BSS_COLOR_MASK); 5634 bss_conf->he_bss_color.partial = 5635 le32_get_bits(elems->he_operation->he_oper_params, 5636 IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR); 5637 bss_conf->he_bss_color.enabled = 5638 !le32_get_bits(elems->he_operation->he_oper_params, 5639 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED); 5640 5641 if (bss_conf->he_bss_color.enabled) 5642 *changed |= BSS_CHANGED_HE_BSS_COLOR; 5643 5644 bss_conf->htc_trig_based_pkt_ext = 5645 le32_get_bits(elems->he_operation->he_oper_params, 5646 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK); 5647 bss_conf->frame_time_rts_th = 5648 le32_get_bits(elems->he_operation->he_oper_params, 5649 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK); 5650 5651 bss_conf->uora_exists = !!elems->uora_element; 5652 if (elems->uora_element) 5653 bss_conf->uora_ocw_range = elems->uora_element[0]; 5654 5655 ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation); 5656 ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr); 5657 /* TODO: OPEN: what happens if BSS color disable is set? */ 5658 } 5659 5660 if (cbss->transmitted_bss) { 5661 bss_conf->nontransmitted = true; 5662 ether_addr_copy(bss_conf->transmitter_bssid, 5663 cbss->transmitted_bss->bssid); 5664 bss_conf->bssid_indicator = cbss->max_bssid_indicator; 5665 bss_conf->bssid_index = cbss->bssid_index; 5666 } 5667 5668 /* 5669 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data 5670 * in their association response, so ignore that data for our own 5671 * configuration. If it changed since the last beacon, we'll get the 5672 * next beacon and update then. 5673 */ 5674 5675 /* 5676 * If an operating mode notification IE is present, override the 5677 * NSS calculation (that would be done in rate_control_rate_init()) 5678 * and use the # of streams from that element. 5679 */ 5680 if (elems->opmode_notif && 5681 !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) { 5682 u8 nss; 5683 5684 nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK; 5685 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT; 5686 nss += 1; 5687 link_sta->pub->rx_nss = nss; 5688 } 5689 5690 /* 5691 * Always handle WMM once after association regardless 5692 * of the first value the AP uses. Setting -1 here has 5693 * that effect because the AP values is an unsigned 5694 * 4-bit value. 5695 */ 5696 link->u.mgd.wmm_last_param_set = -1; 5697 link->u.mgd.mu_edca_last_param_set = -1; 5698 5699 if (link->u.mgd.disable_wmm_tracking) { 5700 ieee80211_set_wmm_default(link, false, false); 5701 } else if (!ieee80211_sta_wmm_params(local, link, elems->wmm_param, 5702 elems->wmm_param_len, 5703 elems->mu_edca_param_set)) { 5704 /* still enable QoS since we might have HT/VHT */ 5705 ieee80211_set_wmm_default(link, false, true); 5706 /* disable WMM tracking in this case to disable 5707 * tracking WMM parameter changes in the beacon if 5708 * the parameters weren't actually valid. Doing so 5709 * avoids changing parameters very strangely when 5710 * the AP is going back and forth between valid and 5711 * invalid parameters. 5712 */ 5713 link->u.mgd.disable_wmm_tracking = true; 5714 } 5715 5716 if (elems->max_idle_period_ie) { 5717 bss_conf->max_idle_period = 5718 le16_to_cpu(elems->max_idle_period_ie->max_idle_period); 5719 bss_conf->protected_keep_alive = 5720 !!(elems->max_idle_period_ie->idle_options & 5721 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE); 5722 *changed |= BSS_CHANGED_KEEP_ALIVE; 5723 } else { 5724 bss_conf->max_idle_period = 0; 5725 bss_conf->protected_keep_alive = false; 5726 } 5727 5728 /* set assoc capability (AID was already set earlier), 5729 * ieee80211_set_associated() will tell the driver */ 5730 bss_conf->assoc_capability = capab_info; 5731 5732 ret = true; 5733 out: 5734 kfree(elems); 5735 kfree(bss_ies); 5736 return ret; 5737 } 5738 5739 static int ieee80211_mgd_setup_link_sta(struct ieee80211_link_data *link, 5740 struct sta_info *sta, 5741 struct link_sta_info *link_sta, 5742 struct cfg80211_bss *cbss) 5743 { 5744 struct ieee80211_sub_if_data *sdata = link->sdata; 5745 struct ieee80211_local *local = sdata->local; 5746 struct ieee80211_bss *bss = (void *)cbss->priv; 5747 u32 rates = 0, basic_rates = 0; 5748 bool have_higher_than_11mbit = false; 5749 int min_rate = INT_MAX, min_rate_index = -1; 5750 struct ieee80211_supported_band *sband; 5751 5752 memcpy(link_sta->addr, cbss->bssid, ETH_ALEN); 5753 memcpy(link_sta->pub->addr, cbss->bssid, ETH_ALEN); 5754 5755 /* TODO: S1G Basic Rate Set is expressed elsewhere */ 5756 if (cbss->channel->band == NL80211_BAND_S1GHZ) { 5757 ieee80211_s1g_sta_rate_init(sta); 5758 return 0; 5759 } 5760 5761 sband = local->hw.wiphy->bands[cbss->channel->band]; 5762 5763 ieee80211_get_rates(sband, bss->supp_rates, bss->supp_rates_len, 5764 NULL, 0, 5765 &rates, &basic_rates, NULL, 5766 &have_higher_than_11mbit, 5767 &min_rate, &min_rate_index); 5768 5769 /* 5770 * This used to be a workaround for basic rates missing 5771 * in the association response frame. Now that we no 5772 * longer use the basic rates from there, it probably 5773 * doesn't happen any more, but keep the workaround so 5774 * in case some *other* APs are buggy in different ways 5775 * we can connect -- with a warning. 5776 * Allow this workaround only in case the AP provided at least 5777 * one rate. 5778 */ 5779 if (min_rate_index < 0) { 5780 link_info(link, "No legacy rates in association response\n"); 5781 return -EINVAL; 5782 } else if (!basic_rates) { 5783 link_info(link, "No basic rates, using min rate instead\n"); 5784 basic_rates = BIT(min_rate_index); 5785 } 5786 5787 if (rates) 5788 link_sta->pub->supp_rates[cbss->channel->band] = rates; 5789 else 5790 link_info(link, "No rates found, keeping mandatory only\n"); 5791 5792 link->conf->basic_rates = basic_rates; 5793 5794 /* cf. IEEE 802.11 9.2.12 */ 5795 link->operating_11g_mode = sband->band == NL80211_BAND_2GHZ && 5796 have_higher_than_11mbit; 5797 5798 return 0; 5799 } 5800 5801 static u8 ieee80211_max_rx_chains(struct ieee80211_link_data *link, 5802 struct cfg80211_bss *cbss) 5803 { 5804 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp; 5805 const struct element *ht_cap_elem, *vht_cap_elem; 5806 const struct cfg80211_bss_ies *ies; 5807 const struct ieee80211_ht_cap *ht_cap; 5808 const struct ieee80211_vht_cap *vht_cap; 5809 const struct ieee80211_he_cap_elem *he_cap; 5810 const struct element *he_cap_elem; 5811 u16 mcs_80_map, mcs_160_map; 5812 int i, mcs_nss_size; 5813 bool support_160; 5814 u8 chains = 1; 5815 5816 if (link->u.mgd.conn.mode < IEEE80211_CONN_MODE_HT) 5817 return chains; 5818 5819 ht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_CAPABILITY); 5820 if (ht_cap_elem && ht_cap_elem->datalen >= sizeof(*ht_cap)) { 5821 ht_cap = (void *)ht_cap_elem->data; 5822 chains = ieee80211_mcs_to_chains(&ht_cap->mcs); 5823 /* 5824 * TODO: use "Tx Maximum Number Spatial Streams Supported" and 5825 * "Tx Unequal Modulation Supported" fields. 5826 */ 5827 } 5828 5829 if (link->u.mgd.conn.mode < IEEE80211_CONN_MODE_VHT) 5830 return chains; 5831 5832 vht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY); 5833 if (vht_cap_elem && vht_cap_elem->datalen >= sizeof(*vht_cap)) { 5834 u8 nss; 5835 u16 tx_mcs_map; 5836 5837 vht_cap = (void *)vht_cap_elem->data; 5838 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map); 5839 for (nss = 8; nss > 0; nss--) { 5840 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) != 5841 IEEE80211_VHT_MCS_NOT_SUPPORTED) 5842 break; 5843 } 5844 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */ 5845 chains = max(chains, nss); 5846 } 5847 5848 if (link->u.mgd.conn.mode < IEEE80211_CONN_MODE_HE) 5849 return chains; 5850 5851 ies = rcu_dereference(cbss->ies); 5852 he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY, 5853 ies->data, ies->len); 5854 5855 if (!he_cap_elem || he_cap_elem->datalen < sizeof(*he_cap) + 1) 5856 return chains; 5857 5858 /* skip one byte ext_tag_id */ 5859 he_cap = (void *)(he_cap_elem->data + 1); 5860 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap); 5861 5862 /* invalid HE IE */ 5863 if (he_cap_elem->datalen < 1 + mcs_nss_size + sizeof(*he_cap)) 5864 return chains; 5865 5866 /* mcs_nss is right after he_cap info */ 5867 he_mcs_nss_supp = (void *)(he_cap + 1); 5868 5869 mcs_80_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80); 5870 5871 for (i = 7; i >= 0; i--) { 5872 u8 mcs_80 = mcs_80_map >> (2 * i) & 3; 5873 5874 if (mcs_80 != IEEE80211_VHT_MCS_NOT_SUPPORTED) { 5875 chains = max_t(u8, chains, i + 1); 5876 break; 5877 } 5878 } 5879 5880 support_160 = he_cap->phy_cap_info[0] & 5881 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G; 5882 5883 if (!support_160) 5884 return chains; 5885 5886 mcs_160_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_160); 5887 for (i = 7; i >= 0; i--) { 5888 u8 mcs_160 = mcs_160_map >> (2 * i) & 3; 5889 5890 if (mcs_160 != IEEE80211_VHT_MCS_NOT_SUPPORTED) { 5891 chains = max_t(u8, chains, i + 1); 5892 break; 5893 } 5894 } 5895 5896 return chains; 5897 } 5898 5899 static void 5900 ieee80211_determine_our_sta_mode(struct ieee80211_sub_if_data *sdata, 5901 struct ieee80211_supported_band *sband, 5902 struct cfg80211_assoc_request *req, 5903 bool wmm_used, int link_id, 5904 struct ieee80211_conn_settings *conn) 5905 { 5906 struct ieee80211_sta_ht_cap sta_ht_cap = sband->ht_cap; 5907 bool is_5ghz = sband->band == NL80211_BAND_5GHZ; 5908 bool is_6ghz = sband->band == NL80211_BAND_6GHZ; 5909 const struct ieee80211_sta_he_cap *he_cap; 5910 const struct ieee80211_sta_eht_cap *eht_cap; 5911 const struct ieee80211_sta_uhr_cap *uhr_cap; 5912 struct ieee80211_sta_vht_cap vht_cap; 5913 5914 if (sband->band == NL80211_BAND_S1GHZ) { 5915 conn->mode = IEEE80211_CONN_MODE_S1G; 5916 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20; 5917 mlme_dbg(sdata, "operating as S1G STA\n"); 5918 return; 5919 } 5920 5921 conn->mode = IEEE80211_CONN_MODE_LEGACY; 5922 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20; 5923 5924 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap); 5925 5926 if (req && req->flags & ASSOC_REQ_DISABLE_HT) { 5927 mlme_link_id_dbg(sdata, link_id, 5928 "HT disabled by flag, limiting to legacy\n"); 5929 goto out; 5930 } 5931 5932 if (!wmm_used) { 5933 mlme_link_id_dbg(sdata, link_id, 5934 "WMM/QoS not supported, limiting to legacy\n"); 5935 goto out; 5936 } 5937 5938 if (req) { 5939 unsigned int i; 5940 5941 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) { 5942 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 || 5943 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP || 5944 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) { 5945 netdev_info(sdata->dev, 5946 "WEP/TKIP use, limiting to legacy\n"); 5947 goto out; 5948 } 5949 } 5950 } 5951 5952 if (!sta_ht_cap.ht_supported && !is_6ghz) { 5953 mlme_link_id_dbg(sdata, link_id, 5954 "HT not supported (and not on 6 GHz), limiting to legacy\n"); 5955 goto out; 5956 } 5957 5958 /* HT is fine */ 5959 conn->mode = IEEE80211_CONN_MODE_HT; 5960 conn->bw_limit = sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ? 5961 IEEE80211_CONN_BW_LIMIT_40 : 5962 IEEE80211_CONN_BW_LIMIT_20; 5963 5964 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap)); 5965 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap); 5966 5967 if (req && req->flags & ASSOC_REQ_DISABLE_VHT) { 5968 mlme_link_id_dbg(sdata, link_id, 5969 "VHT disabled by flag, limiting to HT\n"); 5970 goto out; 5971 } 5972 5973 if (vht_cap.vht_supported && is_5ghz) { 5974 bool have_80mhz = false; 5975 unsigned int i; 5976 5977 if (conn->bw_limit == IEEE80211_CONN_BW_LIMIT_20) { 5978 mlme_link_id_dbg(sdata, link_id, 5979 "no 40 MHz support on 5 GHz, limiting to HT\n"); 5980 goto out; 5981 } 5982 5983 /* Allow VHT if at least one channel on the sband supports 80 MHz */ 5984 for (i = 0; i < sband->n_channels; i++) { 5985 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED | 5986 IEEE80211_CHAN_NO_80MHZ)) 5987 continue; 5988 5989 have_80mhz = true; 5990 break; 5991 } 5992 5993 if (!have_80mhz) { 5994 mlme_link_id_dbg(sdata, link_id, 5995 "no 80 MHz channel support on 5 GHz, limiting to HT\n"); 5996 goto out; 5997 } 5998 } else if (is_5ghz) { /* !vht_supported but on 5 GHz */ 5999 mlme_link_id_dbg(sdata, link_id, 6000 "no VHT support on 5 GHz, limiting to HT\n"); 6001 goto out; 6002 } 6003 6004 /* VHT - if we have - is fine, including 80 MHz, check 160 below again */ 6005 if (sband->band != NL80211_BAND_2GHZ) { 6006 conn->mode = IEEE80211_CONN_MODE_VHT; 6007 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_160; 6008 } 6009 6010 if (is_5ghz && 6011 !(vht_cap.cap & (IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ | 6012 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ))) { 6013 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_80; 6014 mlme_link_id_dbg(sdata, link_id, 6015 "no VHT 160 MHz capability on 5 GHz, limiting to 80 MHz"); 6016 } 6017 6018 if (req && req->flags & ASSOC_REQ_DISABLE_HE) { 6019 mlme_link_id_dbg(sdata, link_id, 6020 "HE disabled by flag, limiting to HT/VHT\n"); 6021 goto out; 6022 } 6023 6024 he_cap = ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif); 6025 if (!he_cap) { 6026 WARN_ON(is_6ghz); 6027 mlme_link_id_dbg(sdata, link_id, 6028 "no HE support, limiting to HT/VHT\n"); 6029 goto out; 6030 } 6031 6032 /* so we have HE */ 6033 conn->mode = IEEE80211_CONN_MODE_HE; 6034 6035 /* check bandwidth */ 6036 switch (sband->band) { 6037 default: 6038 case NL80211_BAND_2GHZ: 6039 if (he_cap->he_cap_elem.phy_cap_info[0] & 6040 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G) 6041 break; 6042 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20; 6043 mlme_link_id_dbg(sdata, link_id, 6044 "no 40 MHz HE cap in 2.4 GHz, limiting to 20 MHz\n"); 6045 break; 6046 case NL80211_BAND_5GHZ: 6047 if (!(he_cap->he_cap_elem.phy_cap_info[0] & 6048 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G)) { 6049 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20; 6050 mlme_link_id_dbg(sdata, link_id, 6051 "no 40/80 MHz HE cap in 5 GHz, limiting to 20 MHz\n"); 6052 break; 6053 } 6054 if (!(he_cap->he_cap_elem.phy_cap_info[0] & 6055 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G)) { 6056 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit, 6057 conn->bw_limit, 6058 IEEE80211_CONN_BW_LIMIT_80); 6059 mlme_link_id_dbg(sdata, link_id, 6060 "no 160 MHz HE cap in 5 GHz, limiting to 80 MHz\n"); 6061 } 6062 break; 6063 case NL80211_BAND_6GHZ: 6064 if (he_cap->he_cap_elem.phy_cap_info[0] & 6065 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G) 6066 break; 6067 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit, 6068 conn->bw_limit, 6069 IEEE80211_CONN_BW_LIMIT_80); 6070 mlme_link_id_dbg(sdata, link_id, 6071 "no 160 MHz HE cap in 6 GHz, limiting to 80 MHz\n"); 6072 break; 6073 } 6074 6075 if (req && req->flags & ASSOC_REQ_DISABLE_EHT) { 6076 mlme_link_id_dbg(sdata, link_id, 6077 "EHT disabled by flag, limiting to HE\n"); 6078 goto out; 6079 } 6080 6081 eht_cap = ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif); 6082 if (!eht_cap) { 6083 mlme_link_id_dbg(sdata, link_id, 6084 "no EHT support, limiting to HE\n"); 6085 goto out; 6086 } 6087 conn->mode = IEEE80211_CONN_MODE_EHT; 6088 6089 /* check bandwidth */ 6090 if (is_6ghz && 6091 eht_cap->eht_cap_elem.phy_cap_info[0] & IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ) 6092 conn->bw_limit = IEEE80211_CONN_BW_LIMIT_320; 6093 else if (is_6ghz) 6094 mlme_link_id_dbg(sdata, link_id, 6095 "no EHT 320 MHz cap in 6 GHz, limiting to 160 MHz\n"); 6096 6097 if (req && req->flags & ASSOC_REQ_DISABLE_UHR) { 6098 mlme_link_id_dbg(sdata, link_id, 6099 "UHR disabled by flag, limiting to EHT\n"); 6100 goto out; 6101 } 6102 6103 uhr_cap = ieee80211_get_uhr_iftype_cap_vif(sband, &sdata->vif); 6104 if (!uhr_cap) { 6105 mlme_link_id_dbg(sdata, link_id, 6106 "no UHR support, limiting to EHT\n"); 6107 goto out; 6108 } 6109 conn->mode = IEEE80211_CONN_MODE_UHR; 6110 6111 out: 6112 mlme_link_id_dbg(sdata, link_id, 6113 "determined local STA to be %s, BW limited to %d MHz\n", 6114 ieee80211_conn_mode_str(conn->mode), 6115 20 * (1 << conn->bw_limit)); 6116 } 6117 6118 static void 6119 ieee80211_determine_our_sta_mode_auth(struct ieee80211_sub_if_data *sdata, 6120 struct ieee80211_supported_band *sband, 6121 struct cfg80211_auth_request *req, 6122 bool wmm_used, 6123 struct ieee80211_conn_settings *conn) 6124 { 6125 ieee80211_determine_our_sta_mode(sdata, sband, NULL, wmm_used, 6126 req->link_id > 0 ? req->link_id : 0, 6127 conn); 6128 } 6129 6130 static void 6131 ieee80211_determine_our_sta_mode_assoc(struct ieee80211_sub_if_data *sdata, 6132 struct ieee80211_supported_band *sband, 6133 struct cfg80211_assoc_request *req, 6134 bool wmm_used, int link_id, 6135 struct ieee80211_conn_settings *conn) 6136 { 6137 struct ieee80211_conn_settings tmp; 6138 6139 WARN_ON(!req); 6140 6141 ieee80211_determine_our_sta_mode(sdata, sband, req, wmm_used, link_id, 6142 &tmp); 6143 6144 conn->mode = min_t(enum ieee80211_conn_mode, 6145 conn->mode, tmp.mode); 6146 conn->bw_limit = min_t(enum ieee80211_conn_bw_limit, 6147 conn->bw_limit, tmp.bw_limit); 6148 } 6149 6150 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata, 6151 struct ieee80211_link_data *link, 6152 int link_id, 6153 struct cfg80211_bss *cbss, bool mlo, 6154 struct ieee80211_conn_settings *conn, 6155 unsigned long *userspace_selectors) 6156 { 6157 struct ieee80211_local *local = sdata->local; 6158 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ; 6159 struct ieee80211_chan_req chanreq = {}; 6160 struct cfg80211_chan_def ap_chandef; 6161 struct ieee802_11_elems *elems; 6162 int ret; 6163 6164 lockdep_assert_wiphy(local->hw.wiphy); 6165 6166 rcu_read_lock(); 6167 elems = ieee80211_determine_chan_mode(sdata, conn, cbss, link_id, 6168 &chanreq, &ap_chandef, 6169 userspace_selectors); 6170 6171 if (IS_ERR(elems)) { 6172 rcu_read_unlock(); 6173 return PTR_ERR(elems); 6174 } 6175 6176 if (mlo && !elems->ml_basic) { 6177 sdata_info(sdata, "Rejecting MLO as it is not supported by AP\n"); 6178 rcu_read_unlock(); 6179 kfree(elems); 6180 return -EINVAL; 6181 } 6182 6183 if (link && is_6ghz && conn->mode >= IEEE80211_CONN_MODE_HE) { 6184 const struct ieee80211_he_6ghz_oper *he_6ghz_oper; 6185 6186 if (elems->pwr_constr_elem) 6187 link->conf->pwr_reduction = *elems->pwr_constr_elem; 6188 6189 he_6ghz_oper = ieee80211_he_6ghz_oper(elems->he_operation); 6190 if (he_6ghz_oper) 6191 link->conf->power_type = 6192 cfg80211_6ghz_power_type(he_6ghz_oper->control, 6193 cbss->channel->flags); 6194 else 6195 link_info(link, 6196 "HE 6 GHz operation missing (on %d MHz), expect issues\n", 6197 cbss->channel->center_freq); 6198 6199 link->conf->tpe = elems->tpe; 6200 ieee80211_rearrange_tpe(&link->conf->tpe, &ap_chandef, 6201 &chanreq.oper); 6202 } 6203 rcu_read_unlock(); 6204 /* the element data was RCU protected so no longer valid anyway */ 6205 kfree(elems); 6206 elems = NULL; 6207 6208 if (!link) 6209 return 0; 6210 6211 rcu_read_lock(); 6212 link->needed_rx_chains = min(ieee80211_max_rx_chains(link, cbss), 6213 local->rx_chains); 6214 rcu_read_unlock(); 6215 6216 /* 6217 * If this fails (possibly due to channel context sharing 6218 * on incompatible channels, e.g. 80+80 and 160 sharing the 6219 * same control channel) try to use a smaller bandwidth. 6220 */ 6221 ret = ieee80211_link_use_channel(link, &chanreq, 6222 IEEE80211_CHANCTX_SHARED); 6223 6224 /* don't downgrade for 5/10/S1G MHz channels, though. */ 6225 if (chanreq.oper.width == NL80211_CHAN_WIDTH_5 || 6226 chanreq.oper.width == NL80211_CHAN_WIDTH_10 || 6227 cfg80211_chandef_is_s1g(&chanreq.oper)) 6228 return ret; 6229 6230 while (ret && chanreq.oper.width != NL80211_CHAN_WIDTH_20_NOHT) { 6231 ieee80211_chanreq_downgrade(&chanreq, conn); 6232 6233 ret = ieee80211_link_use_channel(link, &chanreq, 6234 IEEE80211_CHANCTX_SHARED); 6235 } 6236 6237 return ret; 6238 } 6239 6240 static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies, 6241 u8 *dtim_count, u8 *dtim_period) 6242 { 6243 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len); 6244 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data, 6245 ies->len); 6246 const struct ieee80211_tim_ie *tim = NULL; 6247 const struct ieee80211_bssid_index *idx; 6248 bool valid = tim_ie && tim_ie[1] >= 2; 6249 6250 if (valid) 6251 tim = (void *)(tim_ie + 2); 6252 6253 if (dtim_count) 6254 *dtim_count = valid ? tim->dtim_count : 0; 6255 6256 if (dtim_period) 6257 *dtim_period = valid ? tim->dtim_period : 0; 6258 6259 /* Check if value is overridden by non-transmitted profile */ 6260 if (!idx_ie || idx_ie[1] < 3) 6261 return valid; 6262 6263 idx = (void *)(idx_ie + 2); 6264 6265 if (dtim_count) 6266 *dtim_count = idx->dtim_count; 6267 6268 if (dtim_period) 6269 *dtim_period = idx->dtim_period; 6270 6271 return true; 6272 } 6273 6274 static u16 ieee80211_get_ttlm(u8 bm_size, u8 *data) 6275 { 6276 if (bm_size == 1) 6277 return *data; 6278 6279 return get_unaligned_le16(data); 6280 } 6281 6282 static int 6283 ieee80211_parse_adv_t2l(struct ieee80211_sub_if_data *sdata, 6284 const struct ieee80211_ttlm_elem *ttlm, 6285 struct ieee80211_adv_ttlm_info *ttlm_info) 6286 { 6287 /* The element size was already validated in 6288 * ieee80211_tid_to_link_map_size_ok() 6289 */ 6290 u8 control, link_map_presence, map_size, tid; 6291 u8 *pos; 6292 6293 memset(ttlm_info, 0, sizeof(*ttlm_info)); 6294 pos = (void *)ttlm->optional; 6295 control = ttlm->control; 6296 6297 if ((control & IEEE80211_TTLM_CONTROL_DIRECTION) != 6298 IEEE80211_TTLM_DIRECTION_BOTH) { 6299 sdata_info(sdata, "Invalid advertised T2L map direction\n"); 6300 return -EINVAL; 6301 } 6302 6303 if (!(control & IEEE80211_TTLM_CONTROL_DEF_LINK_MAP)) { 6304 link_map_presence = *pos; 6305 pos++; 6306 } 6307 6308 if (control & IEEE80211_TTLM_CONTROL_SWITCH_TIME_PRESENT) { 6309 ttlm_info->switch_time = get_unaligned_le16(pos); 6310 6311 /* Since ttlm_info->switch_time == 0 means no switch time, bump 6312 * it by 1. 6313 */ 6314 if (!ttlm_info->switch_time) 6315 ttlm_info->switch_time = 1; 6316 6317 pos += 2; 6318 } 6319 6320 if (control & IEEE80211_TTLM_CONTROL_EXPECTED_DUR_PRESENT) { 6321 ttlm_info->duration = pos[0] | pos[1] << 8 | pos[2] << 16; 6322 pos += 3; 6323 } 6324 6325 if (control & IEEE80211_TTLM_CONTROL_DEF_LINK_MAP) { 6326 ttlm_info->map = 0xffff; 6327 return 0; 6328 } 6329 6330 if (control & IEEE80211_TTLM_CONTROL_LINK_MAP_SIZE) 6331 map_size = 1; 6332 else 6333 map_size = 2; 6334 6335 /* According to Draft P802.11be_D3.0 clause 35.3.7.1.7, an AP MLD shall 6336 * not advertise a TID-to-link mapping that does not map all TIDs to the 6337 * same link set, reject frame if not all links have mapping 6338 */ 6339 if (link_map_presence != 0xff) { 6340 sdata_info(sdata, 6341 "Invalid advertised T2L mapping presence indicator\n"); 6342 return -EINVAL; 6343 } 6344 6345 ttlm_info->map = ieee80211_get_ttlm(map_size, pos); 6346 if (!ttlm_info->map) { 6347 sdata_info(sdata, 6348 "Invalid advertised T2L map for TID 0\n"); 6349 return -EINVAL; 6350 } 6351 6352 pos += map_size; 6353 6354 for (tid = 1; tid < 8; tid++) { 6355 u16 map = ieee80211_get_ttlm(map_size, pos); 6356 6357 if (map != ttlm_info->map) { 6358 sdata_info(sdata, "Invalid advertised T2L map for tid %d\n", 6359 tid); 6360 return -EINVAL; 6361 } 6362 6363 pos += map_size; 6364 } 6365 return 0; 6366 } 6367 6368 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata, 6369 struct ieee80211_mgmt *mgmt, 6370 struct ieee802_11_elems *elems, 6371 const u8 *elem_start, unsigned int elem_len) 6372 { 6373 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 6374 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; 6375 struct ieee80211_local *local = sdata->local; 6376 unsigned int link_id; 6377 struct sta_info *sta; 6378 u64 changed[IEEE80211_MLD_MAX_NUM_LINKS] = {}; 6379 u16 valid_links = 0, dormant_links = 0; 6380 int err; 6381 6382 lockdep_assert_wiphy(sdata->local->hw.wiphy); 6383 /* 6384 * station info was already allocated and inserted before 6385 * the association and should be available to us 6386 */ 6387 sta = sta_info_get(sdata, assoc_data->ap_addr); 6388 if (WARN_ON(!sta)) 6389 goto out_err; 6390 6391 sta->sta.spp_amsdu = assoc_data->spp_amsdu; 6392 6393 if (ieee80211_vif_is_mld(&sdata->vif)) { 6394 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { 6395 if (!assoc_data->link[link_id].bss) 6396 continue; 6397 6398 valid_links |= BIT(link_id); 6399 6400 if (link_id != assoc_data->assoc_link_id) { 6401 err = ieee80211_sta_allocate_link(sta, link_id); 6402 if (err) 6403 goto out_err; 6404 } 6405 } 6406 6407 /* 6408 * We do not support setting a negotiated TTLM during 6409 * association. As such, we can assume that if there is a TTLM, 6410 * then it is the currently active advertised TTLM. 6411 * In that case, there must be exactly one TTLM that does not 6412 * have a switch time set. This mapping should also leave us 6413 * with at least one usable link. 6414 */ 6415 if (elems->ttlm_num > 1) { 6416 sdata_info(sdata, 6417 "More than one advertised TTLM in association response\n"); 6418 goto out_err; 6419 } else if (elems->ttlm_num == 1) { 6420 if (ieee80211_parse_adv_t2l(sdata, elems->ttlm[0], 6421 &sdata->u.mgd.ttlm_info) || 6422 sdata->u.mgd.ttlm_info.switch_time != 0 || 6423 !(valid_links & sdata->u.mgd.ttlm_info.map)) { 6424 sdata_info(sdata, 6425 "Invalid advertised TTLM in association response\n"); 6426 goto out_err; 6427 } 6428 6429 sdata->u.mgd.ttlm_info.active = true; 6430 dormant_links = 6431 valid_links & ~sdata->u.mgd.ttlm_info.map; 6432 } 6433 6434 ieee80211_vif_set_links(sdata, valid_links, dormant_links); 6435 } 6436 6437 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { 6438 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss; 6439 struct ieee80211_link_data *link; 6440 struct link_sta_info *link_sta; 6441 6442 if (!cbss) 6443 continue; 6444 6445 link = sdata_dereference(sdata->link[link_id], sdata); 6446 if (WARN_ON(!link)) 6447 goto out_err; 6448 6449 if (ieee80211_vif_is_mld(&sdata->vif)) 6450 link_info(link, 6451 "local address %pM, AP link address %pM%s\n", 6452 link->conf->addr, 6453 assoc_data->link[link_id].bss->bssid, 6454 link_id == assoc_data->assoc_link_id ? 6455 " (assoc)" : ""); 6456 6457 link_sta = rcu_dereference_protected(sta->link[link_id], 6458 lockdep_is_held(&local->hw.wiphy->mtx)); 6459 if (WARN_ON(!link_sta)) 6460 goto out_err; 6461 6462 if (!link->u.mgd.have_beacon) { 6463 const struct cfg80211_bss_ies *ies; 6464 6465 rcu_read_lock(); 6466 ies = rcu_dereference(cbss->beacon_ies); 6467 if (ies) 6468 link->u.mgd.have_beacon = true; 6469 else 6470 ies = rcu_dereference(cbss->ies); 6471 ieee80211_get_dtim(ies, 6472 &link->conf->sync_dtim_count, 6473 &link->u.mgd.dtim_period); 6474 link->conf->beacon_int = cbss->beacon_interval; 6475 rcu_read_unlock(); 6476 } 6477 6478 link->conf->dtim_period = link->u.mgd.dtim_period ?: 1; 6479 6480 if (link_id != assoc_data->assoc_link_id) { 6481 link->u.mgd.conn = assoc_data->link[link_id].conn; 6482 6483 err = ieee80211_prep_channel(sdata, link, link_id, cbss, 6484 true, &link->u.mgd.conn, 6485 sdata->u.mgd.userspace_selectors); 6486 if (err) { 6487 link_info(link, "prep_channel failed\n"); 6488 goto out_err; 6489 } 6490 } 6491 6492 err = ieee80211_mgd_setup_link_sta(link, sta, link_sta, 6493 assoc_data->link[link_id].bss); 6494 if (err) 6495 goto out_err; 6496 6497 if (!ieee80211_assoc_config_link(link, link_sta, 6498 assoc_data->link[link_id].bss, 6499 mgmt, elem_start, elem_len, 6500 &changed[link_id])) 6501 goto out_err; 6502 6503 if (assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) { 6504 valid_links &= ~BIT(link_id); 6505 ieee80211_sta_remove_link(sta, link_id); 6506 continue; 6507 } 6508 6509 if (link_id != assoc_data->assoc_link_id) { 6510 err = ieee80211_sta_activate_link(sta, link_id); 6511 if (err) 6512 goto out_err; 6513 } 6514 } 6515 6516 /* links might have changed due to rejected ones, set them again */ 6517 ieee80211_vif_set_links(sdata, valid_links, dormant_links); 6518 6519 rate_control_rate_init_all_links(sta); 6520 6521 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) { 6522 set_sta_flag(sta, WLAN_STA_MFP); 6523 sta->sta.mfp = true; 6524 } else { 6525 sta->sta.mfp = false; 6526 } 6527 6528 ieee80211_sta_set_max_amsdu_subframes(sta, elems->ext_capab, 6529 elems->ext_capab_len); 6530 6531 sta->sta.wme = (elems->wmm_param || elems->s1g_capab) && 6532 local->hw.queues >= IEEE80211_NUM_ACS; 6533 6534 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC); 6535 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT)) 6536 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED); 6537 if (err) { 6538 sdata_info(sdata, 6539 "failed to move station %pM to desired state\n", 6540 sta->sta.addr); 6541 WARN_ON(__sta_info_destroy(sta)); 6542 goto out_err; 6543 } 6544 6545 if (sdata->wdev.use_4addr) 6546 drv_sta_set_4addr(local, sdata, &sta->sta, true); 6547 6548 ieee80211_set_associated(sdata, assoc_data, changed); 6549 6550 /* 6551 * If we're using 4-addr mode, let the AP know that we're 6552 * doing so, so that it can create the STA VLAN on its side 6553 */ 6554 if (ifmgd->use_4addr) 6555 ieee80211_send_4addr_nullfunc(local, sdata); 6556 6557 /* 6558 * Start timer to probe the connection to the AP now. 6559 * Also start the timer that will detect beacon loss. 6560 */ 6561 ieee80211_sta_reset_beacon_monitor(sdata); 6562 ieee80211_sta_reset_conn_monitor(sdata); 6563 6564 return true; 6565 out_err: 6566 eth_zero_addr(sdata->vif.cfg.ap_addr); 6567 return false; 6568 } 6569 6570 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata, 6571 struct ieee80211_mgmt *mgmt, 6572 size_t len) 6573 { 6574 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 6575 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; 6576 u16 capab_info, status_code, aid; 6577 struct ieee80211_elems_parse_params parse_params = { 6578 .bss = NULL, 6579 .link_id = -1, 6580 .from_ap = true, 6581 .type = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_TYPE, 6582 }; 6583 struct ieee802_11_elems *elems; 6584 int ac; 6585 const u8 *elem_start; 6586 unsigned int elem_len; 6587 bool reassoc; 6588 struct ieee80211_event event = { 6589 .type = MLME_EVENT, 6590 .u.mlme.data = ASSOC_EVENT, 6591 }; 6592 struct ieee80211_prep_tx_info info = {}; 6593 struct cfg80211_rx_assoc_resp_data resp = { 6594 .uapsd_queues = -1, 6595 }; 6596 u8 ap_mld_addr[ETH_ALEN] __aligned(2); 6597 unsigned int link_id; 6598 u16 max_aid = IEEE80211_MAX_AID; 6599 6600 lockdep_assert_wiphy(sdata->local->hw.wiphy); 6601 6602 if (!assoc_data) 6603 return; 6604 6605 info.link_id = assoc_data->assoc_link_id; 6606 6607 parse_params.mode = 6608 assoc_data->link[assoc_data->assoc_link_id].conn.mode; 6609 6610 if (!ether_addr_equal(assoc_data->ap_addr, mgmt->bssid) || 6611 !ether_addr_equal(assoc_data->ap_addr, mgmt->sa)) 6612 return; 6613 6614 /* 6615 * AssocResp and ReassocResp have identical structure, so process both 6616 * of them in this function. 6617 */ 6618 6619 if (len < 24 + 6) 6620 return; 6621 6622 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control); 6623 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); 6624 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); 6625 if (assoc_data->s1g) { 6626 elem_start = mgmt->u.s1g_assoc_resp.variable; 6627 max_aid = IEEE80211_MAX_SUPPORTED_S1G_AID; 6628 } else { 6629 elem_start = mgmt->u.assoc_resp.variable; 6630 } 6631 6632 /* 6633 * Note: this may not be perfect, AP might misbehave - if 6634 * anyone needs to rely on perfect complete notification 6635 * with the exact right subtype, then we need to track what 6636 * we actually transmitted. 6637 */ 6638 info.subtype = reassoc ? IEEE80211_STYPE_REASSOC_REQ : 6639 IEEE80211_STYPE_ASSOC_REQ; 6640 6641 if (assoc_data->fils_kek_len && 6642 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0) 6643 return; 6644 6645 elem_len = len - (elem_start - (u8 *)mgmt); 6646 parse_params.start = elem_start; 6647 parse_params.len = elem_len; 6648 elems = ieee802_11_parse_elems_full(&parse_params); 6649 if (!elems) 6650 goto notify_driver; 6651 6652 if (elems->aid_resp) 6653 aid = le16_to_cpu(elems->aid_resp->aid); 6654 else 6655 aid = le16_to_cpu(mgmt->u.assoc_resp.aid); 6656 6657 /* 6658 * The 5 MSB of the AID field are reserved for a non-S1G STA. For 6659 * an S1G STA the 3 MSBs are reserved. 6660 * (802.11-2016 9.4.1.8 AID field). 6661 */ 6662 aid &= assoc_data->s1g ? 0x1fff : 0x7ff; 6663 6664 sdata_info(sdata, 6665 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n", 6666 reassoc ? "Rea" : "A", assoc_data->ap_addr, 6667 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14)))); 6668 6669 ifmgd->broken_ap = false; 6670 6671 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY && 6672 elems->timeout_int && 6673 elems->timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) { 6674 u32 tu, ms; 6675 6676 cfg80211_assoc_comeback(sdata->dev, assoc_data->ap_addr, 6677 le32_to_cpu(elems->timeout_int->value)); 6678 6679 tu = le32_to_cpu(elems->timeout_int->value); 6680 ms = tu * 1024 / 1000; 6681 sdata_info(sdata, 6682 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n", 6683 assoc_data->ap_addr, tu, ms); 6684 assoc_data->timeout = jiffies + msecs_to_jiffies(ms); 6685 assoc_data->timeout_started = true; 6686 assoc_data->comeback = true; 6687 if (ms > IEEE80211_ASSOC_TIMEOUT) 6688 run_again(sdata, assoc_data->timeout); 6689 goto notify_driver; 6690 } 6691 6692 if (status_code != WLAN_STATUS_SUCCESS) { 6693 sdata_info(sdata, "%pM denied association (code=%d)\n", 6694 assoc_data->ap_addr, status_code); 6695 event.u.mlme.status = MLME_DENIED; 6696 event.u.mlme.reason = status_code; 6697 drv_event_callback(sdata->local, sdata, &event); 6698 } else { 6699 if (aid == 0 || aid > max_aid) { 6700 sdata_info(sdata, 6701 "invalid AID value %d (out of range), turn off PS\n", 6702 aid); 6703 aid = 0; 6704 ifmgd->broken_ap = true; 6705 } 6706 6707 if (ieee80211_vif_is_mld(&sdata->vif)) { 6708 struct ieee80211_mle_basic_common_info *common; 6709 6710 if (!elems->ml_basic) { 6711 sdata_info(sdata, 6712 "MLO association with %pM but no (basic) multi-link element in response!\n", 6713 assoc_data->ap_addr); 6714 goto abandon_assoc; 6715 } 6716 6717 common = (void *)elems->ml_basic->variable; 6718 6719 if (memcmp(assoc_data->ap_addr, 6720 common->mld_mac_addr, ETH_ALEN)) { 6721 sdata_info(sdata, 6722 "AP MLD MAC address mismatch: got %pM expected %pM\n", 6723 common->mld_mac_addr, 6724 assoc_data->ap_addr); 6725 goto abandon_assoc; 6726 } 6727 6728 sdata->vif.cfg.eml_cap = 6729 ieee80211_mle_get_eml_cap((const void *)elems->ml_basic); 6730 sdata->vif.cfg.eml_med_sync_delay = 6731 ieee80211_mle_get_eml_med_sync_delay((const void *)elems->ml_basic); 6732 sdata->vif.cfg.mld_capa_op = 6733 ieee80211_mle_get_mld_capa_op((const void *)elems->ml_basic); 6734 } 6735 6736 sdata->vif.cfg.aid = aid; 6737 sdata->vif.cfg.s1g = assoc_data->s1g; 6738 6739 if (!ieee80211_assoc_success(sdata, mgmt, elems, 6740 elem_start, elem_len)) { 6741 /* oops -- internal error -- send timeout for now */ 6742 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT); 6743 goto notify_driver; 6744 } 6745 event.u.mlme.status = MLME_SUCCESS; 6746 drv_event_callback(sdata->local, sdata, &event); 6747 sdata_info(sdata, "associated\n"); 6748 6749 info.success = 1; 6750 } 6751 6752 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { 6753 struct ieee80211_link_data *link; 6754 6755 if (!assoc_data->link[link_id].bss) 6756 continue; 6757 6758 resp.links[link_id].bss = assoc_data->link[link_id].bss; 6759 ether_addr_copy(resp.links[link_id].addr, 6760 assoc_data->link[link_id].addr); 6761 resp.links[link_id].status = assoc_data->link[link_id].status; 6762 6763 link = sdata_dereference(sdata->link[link_id], sdata); 6764 if (!link) 6765 continue; 6766 6767 /* get uapsd queues configuration - same for all links */ 6768 resp.uapsd_queues = 0; 6769 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) 6770 if (link->tx_conf[ac].uapsd) 6771 resp.uapsd_queues |= ieee80211_ac_to_qos_mask[ac]; 6772 } 6773 6774 if (ieee80211_vif_is_mld(&sdata->vif)) { 6775 ether_addr_copy(ap_mld_addr, sdata->vif.cfg.ap_addr); 6776 resp.ap_mld_addr = ap_mld_addr; 6777 } 6778 6779 ieee80211_destroy_assoc_data(sdata, 6780 status_code == WLAN_STATUS_SUCCESS ? 6781 ASSOC_SUCCESS : 6782 ASSOC_REJECTED); 6783 6784 resp.buf = (u8 *)mgmt; 6785 resp.len = len; 6786 resp.req_ies = ifmgd->assoc_req_ies; 6787 resp.req_ies_len = ifmgd->assoc_req_ies_len; 6788 cfg80211_rx_assoc_resp(sdata->dev, &resp); 6789 notify_driver: 6790 drv_mgd_complete_tx(sdata->local, sdata, &info); 6791 kfree(elems); 6792 return; 6793 abandon_assoc: 6794 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON); 6795 goto notify_driver; 6796 } 6797 6798 static void ieee80211_rx_bss_info(struct ieee80211_link_data *link, 6799 struct ieee80211_mgmt *mgmt, size_t len, 6800 struct ieee80211_rx_status *rx_status) 6801 { 6802 struct ieee80211_sub_if_data *sdata = link->sdata; 6803 struct ieee80211_local *local = sdata->local; 6804 struct ieee80211_bss *bss; 6805 struct ieee80211_channel *channel; 6806 6807 lockdep_assert_wiphy(sdata->local->hw.wiphy); 6808 6809 channel = ieee80211_get_channel_khz(local->hw.wiphy, 6810 ieee80211_rx_status_to_khz(rx_status)); 6811 if (!channel) 6812 return; 6813 6814 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel); 6815 if (bss) { 6816 link->conf->beacon_rate = bss->beacon_rate; 6817 ieee80211_rx_bss_put(local, bss); 6818 } 6819 } 6820 6821 6822 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_link_data *link, 6823 struct sk_buff *skb) 6824 { 6825 struct ieee80211_sub_if_data *sdata = link->sdata; 6826 struct ieee80211_mgmt *mgmt = (void *)skb->data; 6827 struct ieee80211_if_managed *ifmgd; 6828 struct ieee80211_rx_status *rx_status = (void *) skb->cb; 6829 struct ieee80211_channel *channel; 6830 size_t baselen, len = skb->len; 6831 6832 ifmgd = &sdata->u.mgd; 6833 6834 lockdep_assert_wiphy(sdata->local->hw.wiphy); 6835 6836 /* 6837 * According to Draft P802.11ax D6.0 clause 26.17.2.3.2: 6838 * "If a 6 GHz AP receives a Probe Request frame and responds with 6839 * a Probe Response frame [..], the Address 1 field of the Probe 6840 * Response frame shall be set to the broadcast address [..]" 6841 * So, on 6GHz band we should also accept broadcast responses. 6842 */ 6843 channel = ieee80211_get_channel_khz(sdata->local->hw.wiphy, 6844 ieee80211_rx_status_to_khz(rx_status)); 6845 if (!channel) 6846 return; 6847 6848 if (!ether_addr_equal(mgmt->da, sdata->vif.addr) && 6849 (channel->band != NL80211_BAND_6GHZ || 6850 !is_broadcast_ether_addr(mgmt->da))) 6851 return; /* ignore ProbeResp to foreign address */ 6852 6853 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; 6854 if (baselen > len) 6855 return; 6856 6857 ieee80211_rx_bss_info(link, mgmt, len, rx_status); 6858 6859 if (ifmgd->associated && 6860 ether_addr_equal(mgmt->bssid, link->u.mgd.bssid)) 6861 ieee80211_reset_ap_probe(sdata); 6862 } 6863 6864 /* 6865 * This is the canonical list of information elements we care about, 6866 * the filter code also gives us all changes to the Microsoft OUI 6867 * (00:50:F2) vendor IE which is used for WMM which we need to track, 6868 * as well as the DTPC IE (part of the Cisco OUI) used for signaling 6869 * changes to requested client power. 6870 * 6871 * We implement beacon filtering in software since that means we can 6872 * avoid processing the frame here and in cfg80211, and userspace 6873 * will not be able to tell whether the hardware supports it or not. 6874 * 6875 * XXX: This list needs to be dynamic -- userspace needs to be able to 6876 * add items it requires. It also needs to be able to tell us to 6877 * look out for other vendor IEs. 6878 */ 6879 static const u64 care_about_ies = 6880 (1ULL << WLAN_EID_COUNTRY) | 6881 (1ULL << WLAN_EID_ERP_INFO) | 6882 (1ULL << WLAN_EID_CHANNEL_SWITCH) | 6883 (1ULL << WLAN_EID_PWR_CONSTRAINT) | 6884 (1ULL << WLAN_EID_HT_CAPABILITY) | 6885 (1ULL << WLAN_EID_HT_OPERATION) | 6886 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN); 6887 6888 static void ieee80211_handle_beacon_sig(struct ieee80211_link_data *link, 6889 struct ieee80211_if_managed *ifmgd, 6890 struct ieee80211_bss_conf *bss_conf, 6891 struct ieee80211_local *local, 6892 struct ieee80211_rx_status *rx_status) 6893 { 6894 struct ieee80211_sub_if_data *sdata = link->sdata; 6895 6896 /* Track average RSSI from the Beacon frames of the current AP */ 6897 6898 if (!link->u.mgd.tracking_signal_avg) { 6899 link->u.mgd.tracking_signal_avg = true; 6900 ewma_beacon_signal_init(&link->u.mgd.ave_beacon_signal); 6901 link->u.mgd.last_cqm_event_signal = 0; 6902 link->u.mgd.count_beacon_signal = 1; 6903 link->u.mgd.last_ave_beacon_signal = 0; 6904 } else { 6905 link->u.mgd.count_beacon_signal++; 6906 } 6907 6908 ewma_beacon_signal_add(&link->u.mgd.ave_beacon_signal, 6909 -rx_status->signal); 6910 6911 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold && 6912 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) { 6913 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal); 6914 int last_sig = link->u.mgd.last_ave_beacon_signal; 6915 struct ieee80211_event event = { 6916 .type = RSSI_EVENT, 6917 }; 6918 6919 /* 6920 * if signal crosses either of the boundaries, invoke callback 6921 * with appropriate parameters 6922 */ 6923 if (sig > ifmgd->rssi_max_thold && 6924 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) { 6925 link->u.mgd.last_ave_beacon_signal = sig; 6926 event.u.rssi.data = RSSI_EVENT_HIGH; 6927 drv_event_callback(local, sdata, &event); 6928 } else if (sig < ifmgd->rssi_min_thold && 6929 (last_sig >= ifmgd->rssi_max_thold || 6930 last_sig == 0)) { 6931 link->u.mgd.last_ave_beacon_signal = sig; 6932 event.u.rssi.data = RSSI_EVENT_LOW; 6933 drv_event_callback(local, sdata, &event); 6934 } 6935 } 6936 6937 if (bss_conf->cqm_rssi_thold && 6938 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT && 6939 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) { 6940 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal); 6941 int last_event = link->u.mgd.last_cqm_event_signal; 6942 int thold = bss_conf->cqm_rssi_thold; 6943 int hyst = bss_conf->cqm_rssi_hyst; 6944 6945 if (sig < thold && 6946 (last_event == 0 || sig < last_event - hyst)) { 6947 link->u.mgd.last_cqm_event_signal = sig; 6948 ieee80211_cqm_rssi_notify( 6949 &sdata->vif, 6950 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW, 6951 sig, GFP_KERNEL); 6952 } else if (sig > thold && 6953 (last_event == 0 || sig > last_event + hyst)) { 6954 link->u.mgd.last_cqm_event_signal = sig; 6955 ieee80211_cqm_rssi_notify( 6956 &sdata->vif, 6957 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, 6958 sig, GFP_KERNEL); 6959 } 6960 } 6961 6962 if (bss_conf->cqm_rssi_low && 6963 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) { 6964 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal); 6965 int last_event = link->u.mgd.last_cqm_event_signal; 6966 int low = bss_conf->cqm_rssi_low; 6967 int high = bss_conf->cqm_rssi_high; 6968 6969 if (sig < low && 6970 (last_event == 0 || last_event >= low)) { 6971 link->u.mgd.last_cqm_event_signal = sig; 6972 ieee80211_cqm_rssi_notify( 6973 &sdata->vif, 6974 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW, 6975 sig, GFP_KERNEL); 6976 } else if (sig > high && 6977 (last_event == 0 || last_event <= high)) { 6978 link->u.mgd.last_cqm_event_signal = sig; 6979 ieee80211_cqm_rssi_notify( 6980 &sdata->vif, 6981 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, 6982 sig, GFP_KERNEL); 6983 } 6984 } 6985 } 6986 6987 static bool ieee80211_rx_our_beacon(const u8 *tx_bssid, 6988 struct cfg80211_bss *bss) 6989 { 6990 if (ether_addr_equal(tx_bssid, bss->bssid)) 6991 return true; 6992 if (!bss->transmitted_bss) 6993 return false; 6994 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid); 6995 } 6996 6997 static void ieee80211_ml_reconf_work(struct wiphy *wiphy, 6998 struct wiphy_work *work) 6999 { 7000 struct ieee80211_sub_if_data *sdata = 7001 container_of(work, struct ieee80211_sub_if_data, 7002 u.mgd.ml_reconf_work.work); 7003 u16 new_valid_links, new_active_links, new_dormant_links; 7004 int ret; 7005 7006 if (!sdata->u.mgd.removed_links) 7007 return; 7008 7009 sdata_info(sdata, 7010 "MLO Reconfiguration: work: valid=0x%x, removed=0x%x\n", 7011 sdata->vif.valid_links, sdata->u.mgd.removed_links); 7012 7013 new_valid_links = sdata->vif.valid_links & ~sdata->u.mgd.removed_links; 7014 if (new_valid_links == sdata->vif.valid_links) 7015 return; 7016 7017 if (!new_valid_links || 7018 !(new_valid_links & ~sdata->vif.dormant_links)) { 7019 sdata_info(sdata, "No valid links after reconfiguration\n"); 7020 ret = -EINVAL; 7021 goto out; 7022 } 7023 7024 new_active_links = sdata->vif.active_links & ~sdata->u.mgd.removed_links; 7025 if (new_active_links != sdata->vif.active_links) { 7026 if (!new_active_links) 7027 new_active_links = 7028 BIT(ffs(new_valid_links & 7029 ~sdata->vif.dormant_links) - 1); 7030 7031 ret = ieee80211_set_active_links(&sdata->vif, new_active_links); 7032 if (ret) { 7033 sdata_info(sdata, 7034 "Failed setting active links\n"); 7035 goto out; 7036 } 7037 } 7038 7039 new_dormant_links = sdata->vif.dormant_links & ~sdata->u.mgd.removed_links; 7040 7041 ret = ieee80211_vif_set_links(sdata, new_valid_links, 7042 new_dormant_links); 7043 if (ret) 7044 sdata_info(sdata, "Failed setting valid links\n"); 7045 7046 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_MLD_VALID_LINKS); 7047 7048 out: 7049 if (!ret) 7050 cfg80211_links_removed(sdata->dev, sdata->u.mgd.removed_links); 7051 else 7052 __ieee80211_disconnect(sdata); 7053 7054 sdata->u.mgd.removed_links = 0; 7055 } 7056 7057 static void ieee80211_ml_reconfiguration(struct ieee80211_sub_if_data *sdata, 7058 struct ieee802_11_elems *elems) 7059 { 7060 const struct element *sub; 7061 unsigned long removed_links = 0; 7062 u16 link_removal_timeout[IEEE80211_MLD_MAX_NUM_LINKS] = {}; 7063 u8 link_id; 7064 u32 delay; 7065 7066 if (!ieee80211_vif_is_mld(&sdata->vif) || !elems->ml_reconf) 7067 return; 7068 7069 /* Directly parse the sub elements as the common information doesn't 7070 * hold any useful information. 7071 */ 7072 for_each_mle_subelement(sub, (const u8 *)elems->ml_reconf, 7073 elems->ml_reconf_len) { 7074 struct ieee80211_mle_per_sta_profile *prof = (void *)sub->data; 7075 u8 *pos = prof->variable; 7076 u16 control; 7077 7078 if (sub->id != IEEE80211_MLE_SUBELEM_PER_STA_PROFILE) 7079 continue; 7080 7081 if (!ieee80211_mle_reconf_sta_prof_size_ok(sub->data, 7082 sub->datalen)) 7083 return; 7084 7085 control = le16_to_cpu(prof->control); 7086 link_id = control & IEEE80211_MLE_STA_RECONF_CONTROL_LINK_ID; 7087 7088 if (link_id >= IEEE80211_MLD_MAX_NUM_LINKS) 7089 continue; 7090 7091 removed_links |= BIT(link_id); 7092 7093 /* the MAC address should not be included, but handle it */ 7094 if (control & 7095 IEEE80211_MLE_STA_RECONF_CONTROL_STA_MAC_ADDR_PRESENT) 7096 pos += 6; 7097 7098 /* According to Draft P802.11be_D3.0, the control should 7099 * include the AP Removal Timer present. If the AP Removal Timer 7100 * is not present assume immediate removal. 7101 */ 7102 if (control & 7103 IEEE80211_MLE_STA_RECONF_CONTROL_AP_REM_TIMER_PRESENT) 7104 link_removal_timeout[link_id] = get_unaligned_le16(pos); 7105 } 7106 7107 removed_links &= sdata->vif.valid_links; 7108 if (!removed_links) { 7109 /* In case the removal was cancelled, abort it */ 7110 if (sdata->u.mgd.removed_links) { 7111 sdata->u.mgd.removed_links = 0; 7112 wiphy_hrtimer_work_cancel(sdata->local->hw.wiphy, 7113 &sdata->u.mgd.ml_reconf_work); 7114 } 7115 return; 7116 } 7117 7118 delay = 0; 7119 for_each_set_bit(link_id, &removed_links, IEEE80211_MLD_MAX_NUM_LINKS) { 7120 struct ieee80211_bss_conf *link_conf = 7121 sdata_dereference(sdata->vif.link_conf[link_id], sdata); 7122 u32 link_delay; 7123 7124 if (!link_conf) { 7125 removed_links &= ~BIT(link_id); 7126 continue; 7127 } 7128 7129 if (link_removal_timeout[link_id] < 1) 7130 link_delay = 0; 7131 else 7132 link_delay = link_conf->beacon_int * 7133 (link_removal_timeout[link_id] - 1); 7134 7135 if (!delay) 7136 delay = link_delay; 7137 else 7138 delay = min(delay, link_delay); 7139 } 7140 7141 sdata->u.mgd.removed_links = removed_links; 7142 wiphy_hrtimer_work_queue(sdata->local->hw.wiphy, 7143 &sdata->u.mgd.ml_reconf_work, 7144 us_to_ktime(ieee80211_tu_to_usec(delay))); 7145 } 7146 7147 static int ieee80211_ttlm_set_links(struct ieee80211_sub_if_data *sdata, 7148 u16 active_links, u16 dormant_links, 7149 u16 suspended_links) 7150 { 7151 u64 changed = 0; 7152 int ret; 7153 7154 if (!active_links) { 7155 ret = -EINVAL; 7156 goto out; 7157 } 7158 7159 /* If there is an active negotiated TTLM, it should be discarded by 7160 * the new negotiated/advertised TTLM. 7161 */ 7162 if (sdata->vif.neg_ttlm.valid) { 7163 memset(&sdata->vif.neg_ttlm, 0, sizeof(sdata->vif.neg_ttlm)); 7164 sdata->vif.suspended_links = 0; 7165 changed = BSS_CHANGED_MLD_TTLM; 7166 } 7167 7168 if (sdata->vif.active_links != active_links) { 7169 /* usable links are affected when active_links are changed, 7170 * so notify the driver about the status change 7171 */ 7172 changed |= BSS_CHANGED_MLD_VALID_LINKS; 7173 active_links &= sdata->vif.active_links; 7174 if (!active_links) 7175 active_links = 7176 BIT(__ffs(sdata->vif.valid_links & 7177 ~dormant_links)); 7178 ret = ieee80211_set_active_links(&sdata->vif, active_links); 7179 if (ret) { 7180 sdata_info(sdata, "Failed to set TTLM active links\n"); 7181 goto out; 7182 } 7183 } 7184 7185 ret = ieee80211_vif_set_links(sdata, sdata->vif.valid_links, 7186 dormant_links); 7187 if (ret) { 7188 sdata_info(sdata, "Failed to set TTLM dormant links\n"); 7189 goto out; 7190 } 7191 7192 sdata->vif.suspended_links = suspended_links; 7193 if (sdata->vif.suspended_links) 7194 changed |= BSS_CHANGED_MLD_TTLM; 7195 7196 ieee80211_vif_cfg_change_notify(sdata, changed); 7197 7198 out: 7199 if (ret) 7200 ieee80211_disconnect(&sdata->vif, false); 7201 7202 return ret; 7203 } 7204 7205 static void ieee80211_tid_to_link_map_work(struct wiphy *wiphy, 7206 struct wiphy_work *work) 7207 { 7208 u16 new_active_links, new_dormant_links; 7209 struct ieee80211_sub_if_data *sdata = 7210 container_of(work, struct ieee80211_sub_if_data, 7211 u.mgd.ttlm_work.work); 7212 7213 new_active_links = sdata->u.mgd.ttlm_info.map & 7214 sdata->vif.valid_links; 7215 new_dormant_links = ~sdata->u.mgd.ttlm_info.map & 7216 sdata->vif.valid_links; 7217 7218 ieee80211_vif_set_links(sdata, sdata->vif.valid_links, 0); 7219 if (ieee80211_ttlm_set_links(sdata, new_active_links, new_dormant_links, 7220 0)) 7221 return; 7222 7223 sdata->u.mgd.ttlm_info.active = true; 7224 sdata->u.mgd.ttlm_info.switch_time = 0; 7225 } 7226 7227 static void ieee80211_process_adv_ttlm(struct ieee80211_sub_if_data *sdata, 7228 struct ieee802_11_elems *elems, 7229 u64 beacon_ts) 7230 { 7231 u8 i; 7232 int ret; 7233 7234 if (!ieee80211_vif_is_mld(&sdata->vif)) 7235 return; 7236 7237 if (!elems->ttlm_num) { 7238 if (sdata->u.mgd.ttlm_info.switch_time) { 7239 /* if a planned TID-to-link mapping was cancelled - 7240 * abort it 7241 */ 7242 wiphy_hrtimer_work_cancel(sdata->local->hw.wiphy, 7243 &sdata->u.mgd.ttlm_work); 7244 } else if (sdata->u.mgd.ttlm_info.active) { 7245 /* if no TID-to-link element, set to default mapping in 7246 * which all TIDs are mapped to all setup links 7247 */ 7248 ret = ieee80211_vif_set_links(sdata, 7249 sdata->vif.valid_links, 7250 0); 7251 if (ret) { 7252 sdata_info(sdata, "Failed setting valid/dormant links\n"); 7253 return; 7254 } 7255 ieee80211_vif_cfg_change_notify(sdata, 7256 BSS_CHANGED_MLD_VALID_LINKS); 7257 } 7258 memset(&sdata->u.mgd.ttlm_info, 0, 7259 sizeof(sdata->u.mgd.ttlm_info)); 7260 return; 7261 } 7262 7263 for (i = 0; i < elems->ttlm_num; i++) { 7264 struct ieee80211_adv_ttlm_info ttlm_info; 7265 u32 res; 7266 7267 res = ieee80211_parse_adv_t2l(sdata, elems->ttlm[i], 7268 &ttlm_info); 7269 7270 if (res) { 7271 __ieee80211_disconnect(sdata); 7272 return; 7273 } 7274 7275 if (ttlm_info.switch_time) { 7276 u16 beacon_ts_tu, st_tu, delay; 7277 u64 delay_usec; 7278 u64 mask; 7279 7280 /* The t2l map switch time is indicated with a partial 7281 * TSF value (bits 10 to 25), get the partial beacon TS 7282 * as well, and calc the delay to the start time. 7283 */ 7284 mask = GENMASK_ULL(25, 10); 7285 beacon_ts_tu = (beacon_ts & mask) >> 10; 7286 st_tu = ttlm_info.switch_time; 7287 delay = st_tu - beacon_ts_tu; 7288 7289 /* 7290 * If the switch time is far in the future, then it 7291 * could also be the previous switch still being 7292 * announced. 7293 * We can simply ignore it for now, if it is a future 7294 * switch the AP will continue to announce it anyway. 7295 */ 7296 if (delay > IEEE80211_ADV_TTLM_ST_UNDERFLOW) 7297 return; 7298 7299 delay_usec = ieee80211_tu_to_usec(delay); 7300 7301 /* Link switching can take time, so schedule it 7302 * 100ms before to be ready on time 7303 */ 7304 if (delay_usec > IEEE80211_ADV_TTLM_SAFETY_BUFFER_MS) 7305 delay_usec -= 7306 IEEE80211_ADV_TTLM_SAFETY_BUFFER_MS; 7307 else 7308 delay_usec = 0; 7309 7310 sdata->u.mgd.ttlm_info = ttlm_info; 7311 wiphy_hrtimer_work_cancel(sdata->local->hw.wiphy, 7312 &sdata->u.mgd.ttlm_work); 7313 wiphy_hrtimer_work_queue(sdata->local->hw.wiphy, 7314 &sdata->u.mgd.ttlm_work, 7315 us_to_ktime(delay_usec)); 7316 return; 7317 } 7318 } 7319 } 7320 7321 static void 7322 ieee80211_mgd_check_cross_link_csa(struct ieee80211_sub_if_data *sdata, 7323 int reporting_link_id, 7324 struct ieee802_11_elems *elems) 7325 { 7326 const struct element *sta_profiles[IEEE80211_MLD_MAX_NUM_LINKS] = {}; 7327 ssize_t sta_profiles_len[IEEE80211_MLD_MAX_NUM_LINKS] = {}; 7328 const struct element *sub; 7329 const u8 *subelems; 7330 size_t subelems_len; 7331 u8 common_size; 7332 int link_id; 7333 7334 if (!ieee80211_mle_size_ok((u8 *)elems->ml_basic, elems->ml_basic_len)) 7335 return; 7336 7337 common_size = ieee80211_mle_common_size((u8 *)elems->ml_basic); 7338 subelems = (u8 *)elems->ml_basic + common_size; 7339 subelems_len = elems->ml_basic_len - common_size; 7340 7341 for_each_element_id(sub, IEEE80211_MLE_SUBELEM_PER_STA_PROFILE, 7342 subelems, subelems_len) { 7343 struct ieee80211_mle_per_sta_profile *prof = (void *)sub->data; 7344 struct ieee80211_link_data *link; 7345 ssize_t len; 7346 7347 if (!ieee80211_mle_basic_sta_prof_size_ok(sub->data, 7348 sub->datalen)) 7349 continue; 7350 7351 link_id = le16_get_bits(prof->control, 7352 IEEE80211_MLE_STA_CONTROL_LINK_ID); 7353 /* need a valid link ID, but also not our own, both AP bugs */ 7354 if (link_id == reporting_link_id || 7355 link_id >= IEEE80211_MLD_MAX_NUM_LINKS) 7356 continue; 7357 7358 link = sdata_dereference(sdata->link[link_id], sdata); 7359 if (!link) 7360 continue; 7361 7362 len = cfg80211_defragment_element(sub, subelems, subelems_len, 7363 NULL, 0, 7364 IEEE80211_MLE_SUBELEM_FRAGMENT); 7365 if (WARN_ON(len < 0)) 7366 continue; 7367 7368 sta_profiles[link_id] = sub; 7369 sta_profiles_len[link_id] = len; 7370 } 7371 7372 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { 7373 struct ieee80211_mle_per_sta_profile *prof; 7374 struct ieee802_11_elems *prof_elems; 7375 struct ieee80211_link_data *link; 7376 ssize_t len; 7377 7378 if (link_id == reporting_link_id) 7379 continue; 7380 7381 link = sdata_dereference(sdata->link[link_id], sdata); 7382 if (!link) 7383 continue; 7384 7385 if (!sta_profiles[link_id]) { 7386 prof_elems = NULL; 7387 goto handle; 7388 } 7389 7390 /* we can defragment in-place, won't use the buffer again */ 7391 len = cfg80211_defragment_element(sta_profiles[link_id], 7392 subelems, subelems_len, 7393 (void *)sta_profiles[link_id], 7394 sta_profiles_len[link_id], 7395 IEEE80211_MLE_SUBELEM_FRAGMENT); 7396 if (WARN_ON(len != sta_profiles_len[link_id])) 7397 continue; 7398 7399 prof = (void *)sta_profiles[link_id]; 7400 prof_elems = ieee802_11_parse_elems(prof->variable + 7401 (prof->sta_info_len - 1), 7402 len - 7403 (prof->sta_info_len - 1), 7404 IEEE80211_FTYPE_MGMT | 7405 IEEE80211_STYPE_BEACON, 7406 NULL); 7407 7408 /* memory allocation failed - let's hope that's transient */ 7409 if (!prof_elems) 7410 continue; 7411 7412 handle: 7413 /* 7414 * FIXME: the timings here are obviously incorrect, 7415 * but only older Intel drivers seem to care, and 7416 * those don't have MLO. If you really need this, 7417 * the problem is having to calculate it with the 7418 * TSF offset etc. The device_timestamp is still 7419 * correct, of course. 7420 */ 7421 ieee80211_sta_process_chanswitch(link, 0, 0, elems, prof_elems, 7422 IEEE80211_CSA_SOURCE_OTHER_LINK); 7423 kfree(prof_elems); 7424 } 7425 } 7426 7427 static bool ieee80211_mgd_ssid_mismatch(struct ieee80211_sub_if_data *sdata, 7428 const struct ieee802_11_elems *elems) 7429 { 7430 struct ieee80211_vif_cfg *cfg = &sdata->vif.cfg; 7431 static u8 zero_ssid[IEEE80211_MAX_SSID_LEN]; 7432 7433 if (!elems->ssid) 7434 return false; 7435 7436 /* hidden SSID: zero length */ 7437 if (elems->ssid_len == 0) 7438 return false; 7439 7440 if (elems->ssid_len != cfg->ssid_len) 7441 return true; 7442 7443 /* hidden SSID: zeroed out */ 7444 if (!memcmp(elems->ssid, zero_ssid, elems->ssid_len)) 7445 return false; 7446 7447 return memcmp(elems->ssid, cfg->ssid, cfg->ssid_len); 7448 } 7449 7450 static bool 7451 ieee80211_rx_beacon_freq_valid(struct ieee80211_local *local, 7452 struct ieee80211_mgmt *mgmt, 7453 struct ieee80211_rx_status *rx_status, 7454 struct ieee80211_chanctx_conf *chanctx) 7455 { 7456 u32 pri_2mhz_khz; 7457 struct ieee80211_channel *s1g_sibling_1mhz; 7458 u32 pri_khz = ieee80211_channel_to_khz(chanctx->def.chan); 7459 u32 rx_khz = ieee80211_rx_status_to_khz(rx_status); 7460 7461 if (rx_khz == pri_khz) 7462 return true; 7463 7464 if (!chanctx->def.s1g_primary_2mhz) 7465 return false; 7466 7467 /* 7468 * If we have an S1G interface with a 2MHz primary, beacons are 7469 * sent on the center frequency of the 2MHz primary. Find the sibling 7470 * 1MHz channel and calculate the 2MHz primary center frequency. 7471 */ 7472 s1g_sibling_1mhz = cfg80211_s1g_get_primary_sibling(local->hw.wiphy, 7473 &chanctx->def); 7474 if (!s1g_sibling_1mhz) 7475 return false; 7476 7477 pri_2mhz_khz = 7478 (pri_khz + ieee80211_channel_to_khz(s1g_sibling_1mhz)) / 2; 7479 return rx_khz == pri_2mhz_khz; 7480 } 7481 7482 static void ieee80211_rx_mgmt_beacon(struct ieee80211_link_data *link, 7483 struct ieee80211_hdr *hdr, size_t len, 7484 struct ieee80211_rx_status *rx_status) 7485 { 7486 struct ieee80211_sub_if_data *sdata = link->sdata; 7487 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 7488 struct ieee80211_bss_conf *bss_conf = link->conf; 7489 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg; 7490 struct ieee80211_mgmt *mgmt = (void *) hdr; 7491 struct ieee80211_ext *ext = NULL; 7492 size_t baselen; 7493 struct ieee802_11_elems *elems; 7494 struct ieee80211_local *local = sdata->local; 7495 struct ieee80211_chanctx_conf *chanctx_conf; 7496 struct ieee80211_supported_band *sband; 7497 struct ieee80211_channel *chan; 7498 struct link_sta_info *link_sta; 7499 struct sta_info *sta; 7500 u64 changed = 0; 7501 bool erp_valid; 7502 u8 erp_value = 0; 7503 u32 ncrc = 0; 7504 u8 *bssid, *variable = mgmt->u.beacon.variable; 7505 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN]; 7506 struct ieee80211_elems_parse_params parse_params = { 7507 .mode = link->u.mgd.conn.mode, 7508 .link_id = -1, 7509 .from_ap = true, 7510 .type = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_TYPE, 7511 }; 7512 7513 lockdep_assert_wiphy(local->hw.wiphy); 7514 7515 /* Process beacon from the current BSS */ 7516 bssid = ieee80211_get_bssid(hdr, len, sdata->vif.type); 7517 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) { 7518 ext = (void *)mgmt; 7519 variable = ext->u.s1g_beacon.variable + 7520 ieee80211_s1g_optional_len(ext->frame_control); 7521 } 7522 7523 baselen = (u8 *) variable - (u8 *) mgmt; 7524 if (baselen > len) 7525 return; 7526 7527 parse_params.start = variable; 7528 parse_params.len = len - baselen; 7529 7530 rcu_read_lock(); 7531 chanctx_conf = rcu_dereference(bss_conf->chanctx_conf); 7532 if (!chanctx_conf) { 7533 rcu_read_unlock(); 7534 return; 7535 } 7536 7537 if (!ieee80211_rx_beacon_freq_valid(local, mgmt, rx_status, 7538 chanctx_conf)) { 7539 rcu_read_unlock(); 7540 return; 7541 } 7542 chan = chanctx_conf->def.chan; 7543 rcu_read_unlock(); 7544 7545 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon && 7546 !WARN_ON(ieee80211_vif_is_mld(&sdata->vif)) && 7547 ieee80211_rx_our_beacon(bssid, ifmgd->assoc_data->link[0].bss)) { 7548 parse_params.bss = ifmgd->assoc_data->link[0].bss; 7549 elems = ieee802_11_parse_elems_full(&parse_params); 7550 if (!elems) 7551 return; 7552 7553 ieee80211_rx_bss_info(link, mgmt, len, rx_status); 7554 7555 if (elems->dtim_period) 7556 link->u.mgd.dtim_period = elems->dtim_period; 7557 link->u.mgd.have_beacon = true; 7558 ifmgd->assoc_data->need_beacon = false; 7559 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) && 7560 !ieee80211_is_s1g_beacon(hdr->frame_control)) { 7561 bss_conf->sync_tsf = 7562 le64_to_cpu(mgmt->u.beacon.timestamp); 7563 bss_conf->sync_device_ts = 7564 rx_status->device_timestamp; 7565 bss_conf->sync_dtim_count = elems->dtim_count; 7566 } 7567 7568 if (elems->mbssid_config_ie) 7569 bss_conf->profile_periodicity = 7570 elems->mbssid_config_ie->profile_periodicity; 7571 else 7572 bss_conf->profile_periodicity = 0; 7573 7574 if (elems->ext_capab_len >= 11 && 7575 (elems->ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT)) 7576 bss_conf->ema_ap = true; 7577 else 7578 bss_conf->ema_ap = false; 7579 7580 /* continue assoc process */ 7581 ifmgd->assoc_data->timeout = jiffies; 7582 ifmgd->assoc_data->timeout_started = true; 7583 run_again(sdata, ifmgd->assoc_data->timeout); 7584 kfree(elems); 7585 return; 7586 } 7587 7588 if (!ifmgd->associated || 7589 !ieee80211_rx_our_beacon(bssid, bss_conf->bss)) 7590 return; 7591 bssid = link->u.mgd.bssid; 7592 7593 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL)) 7594 ieee80211_handle_beacon_sig(link, ifmgd, bss_conf, 7595 local, rx_status); 7596 7597 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) { 7598 mlme_dbg_ratelimited(sdata, 7599 "cancelling AP probe due to a received beacon\n"); 7600 ieee80211_reset_ap_probe(sdata); 7601 } 7602 7603 /* 7604 * Push the beacon loss detection into the future since 7605 * we are processing a beacon from the AP just now. 7606 */ 7607 ieee80211_sta_reset_beacon_monitor(sdata); 7608 7609 /* TODO: CRC urrently not calculated on S1G Beacon Compatibility 7610 * element (which carries the beacon interval). Don't forget to add a 7611 * bit to care_about_ies[] above if mac80211 is interested in a 7612 * changing S1G element. 7613 */ 7614 if (!ieee80211_is_s1g_beacon(hdr->frame_control)) 7615 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4); 7616 parse_params.bss = bss_conf->bss; 7617 parse_params.filter = care_about_ies; 7618 parse_params.crc = ncrc; 7619 elems = ieee802_11_parse_elems_full(&parse_params); 7620 if (!elems) 7621 return; 7622 7623 if (rx_status->flag & RX_FLAG_DECRYPTED && 7624 ieee80211_mgd_ssid_mismatch(sdata, elems)) { 7625 sdata_info(sdata, "SSID mismatch for AP %pM, disconnect\n", 7626 sdata->vif.cfg.ap_addr); 7627 __ieee80211_disconnect(sdata); 7628 return; 7629 } 7630 7631 ncrc = elems->crc; 7632 7633 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) && 7634 ieee80211_check_tim(elems->tim, elems->tim_len, vif_cfg->aid, 7635 vif_cfg->s1g)) { 7636 if (local->hw.conf.dynamic_ps_timeout > 0) { 7637 if (local->hw.conf.flags & IEEE80211_CONF_PS) { 7638 local->hw.conf.flags &= ~IEEE80211_CONF_PS; 7639 ieee80211_hw_config(local, -1, 7640 IEEE80211_CONF_CHANGE_PS); 7641 } 7642 ieee80211_send_nullfunc(local, sdata, false); 7643 } else if (!local->pspolling && sdata->u.mgd.powersave) { 7644 local->pspolling = true; 7645 7646 /* 7647 * Here is assumed that the driver will be 7648 * able to send ps-poll frame and receive a 7649 * response even though power save mode is 7650 * enabled, but some drivers might require 7651 * to disable power save here. This needs 7652 * to be investigated. 7653 */ 7654 ieee80211_send_pspoll(local, sdata); 7655 } 7656 } 7657 7658 if (sdata->vif.p2p || 7659 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) { 7660 struct ieee80211_p2p_noa_attr noa = {}; 7661 int ret; 7662 7663 ret = cfg80211_get_p2p_attr(variable, 7664 len - baselen, 7665 IEEE80211_P2P_ATTR_ABSENCE_NOTICE, 7666 (u8 *) &noa, sizeof(noa)); 7667 if (ret >= 2) { 7668 if (link->u.mgd.p2p_noa_index != noa.index) { 7669 /* valid noa_attr and index changed */ 7670 link->u.mgd.p2p_noa_index = noa.index; 7671 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa)); 7672 changed |= BSS_CHANGED_P2P_PS; 7673 /* 7674 * make sure we update all information, the CRC 7675 * mechanism doesn't look at P2P attributes. 7676 */ 7677 link->u.mgd.beacon_crc_valid = false; 7678 } 7679 } else if (link->u.mgd.p2p_noa_index != -1) { 7680 /* noa_attr not found and we had valid noa_attr before */ 7681 link->u.mgd.p2p_noa_index = -1; 7682 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr)); 7683 changed |= BSS_CHANGED_P2P_PS; 7684 link->u.mgd.beacon_crc_valid = false; 7685 } 7686 } 7687 7688 /* 7689 * Update beacon timing and dtim count on every beacon appearance. This 7690 * will allow the driver to use the most updated values. Do it before 7691 * comparing this one with last received beacon. 7692 * IMPORTANT: These parameters would possibly be out of sync by the time 7693 * the driver will use them. The synchronized view is currently 7694 * guaranteed only in certain callbacks. 7695 */ 7696 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) && 7697 !ieee80211_is_s1g_beacon(hdr->frame_control)) { 7698 bss_conf->sync_tsf = 7699 le64_to_cpu(mgmt->u.beacon.timestamp); 7700 bss_conf->sync_device_ts = 7701 rx_status->device_timestamp; 7702 bss_conf->sync_dtim_count = elems->dtim_count; 7703 } 7704 7705 if ((ncrc == link->u.mgd.beacon_crc && link->u.mgd.beacon_crc_valid) || 7706 (ext && ieee80211_is_s1g_short_beacon(ext->frame_control, 7707 parse_params.start, 7708 parse_params.len))) 7709 goto free; 7710 link->u.mgd.beacon_crc = ncrc; 7711 link->u.mgd.beacon_crc_valid = true; 7712 7713 ieee80211_rx_bss_info(link, mgmt, len, rx_status); 7714 7715 ieee80211_sta_process_chanswitch(link, rx_status->mactime, 7716 rx_status->device_timestamp, 7717 elems, elems, 7718 IEEE80211_CSA_SOURCE_BEACON); 7719 7720 /* note that after this elems->ml_basic can no longer be used fully */ 7721 ieee80211_mgd_check_cross_link_csa(sdata, rx_status->link_id, elems); 7722 7723 ieee80211_mgd_update_bss_param_ch_cnt(sdata, bss_conf, elems); 7724 7725 if (!sdata->u.mgd.epcs.enabled && 7726 !link->u.mgd.disable_wmm_tracking && 7727 ieee80211_sta_wmm_params(local, link, elems->wmm_param, 7728 elems->wmm_param_len, 7729 elems->mu_edca_param_set)) 7730 changed |= BSS_CHANGED_QOS; 7731 7732 /* 7733 * If we haven't had a beacon before, tell the driver about the 7734 * DTIM period (and beacon timing if desired) now. 7735 */ 7736 if (!link->u.mgd.have_beacon) { 7737 /* a few bogus AP send dtim_period = 0 or no TIM IE */ 7738 bss_conf->dtim_period = elems->dtim_period ?: 1; 7739 7740 changed |= BSS_CHANGED_BEACON_INFO; 7741 link->u.mgd.have_beacon = true; 7742 7743 ieee80211_recalc_ps(local); 7744 7745 ieee80211_recalc_ps_vif(sdata); 7746 } 7747 7748 if (elems->erp_info) { 7749 erp_valid = true; 7750 erp_value = elems->erp_info[0]; 7751 } else { 7752 erp_valid = false; 7753 } 7754 7755 if (!ieee80211_is_s1g_beacon(hdr->frame_control)) 7756 changed |= ieee80211_handle_bss_capability(link, 7757 le16_to_cpu(mgmt->u.beacon.capab_info), 7758 erp_valid, erp_value); 7759 7760 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr); 7761 if (WARN_ON(!sta)) { 7762 goto free; 7763 } 7764 link_sta = rcu_dereference_protected(sta->link[link->link_id], 7765 lockdep_is_held(&local->hw.wiphy->mtx)); 7766 if (WARN_ON(!link_sta)) { 7767 goto free; 7768 } 7769 7770 if (WARN_ON(!bss_conf->chanreq.oper.chan)) 7771 goto free; 7772 7773 sband = local->hw.wiphy->bands[bss_conf->chanreq.oper.chan->band]; 7774 7775 changed |= ieee80211_recalc_twt_req(sdata, sband, link, link_sta, elems); 7776 7777 if (ieee80211_config_bw(link, elems, true, &changed, 7778 IEEE80211_STYPE_BEACON)) { 7779 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, 7780 WLAN_REASON_DEAUTH_LEAVING, 7781 true, deauth_buf); 7782 ieee80211_report_disconnect(sdata, deauth_buf, 7783 sizeof(deauth_buf), true, 7784 WLAN_REASON_DEAUTH_LEAVING, 7785 false); 7786 goto free; 7787 } 7788 7789 if (elems->opmode_notif) 7790 ieee80211_vht_handle_opmode(sdata, link_sta, 7791 *elems->opmode_notif, 7792 rx_status->band); 7793 7794 changed |= ieee80211_handle_pwr_constr(link, chan, mgmt, 7795 elems->country_elem, 7796 elems->country_elem_len, 7797 elems->pwr_constr_elem, 7798 elems->cisco_dtpc_elem); 7799 7800 ieee80211_ml_reconfiguration(sdata, elems); 7801 ieee80211_process_adv_ttlm(sdata, elems, 7802 le64_to_cpu(mgmt->u.beacon.timestamp)); 7803 7804 ieee80211_link_info_change_notify(sdata, link, changed); 7805 free: 7806 kfree(elems); 7807 } 7808 7809 static void ieee80211_apply_neg_ttlm(struct ieee80211_sub_if_data *sdata, 7810 struct ieee80211_neg_ttlm neg_ttlm) 7811 { 7812 u16 new_active_links, new_dormant_links, new_suspended_links, map = 0; 7813 u8 i; 7814 7815 for (i = 0; i < IEEE80211_TTLM_NUM_TIDS; i++) 7816 map |= neg_ttlm.downlink[i] | neg_ttlm.uplink[i]; 7817 7818 /* If there is an active TTLM, unset previously suspended links */ 7819 if (sdata->vif.neg_ttlm.valid) 7820 sdata->vif.dormant_links &= ~sdata->vif.suspended_links; 7821 7822 /* exclude links that are already disabled by advertised TTLM */ 7823 new_active_links = 7824 map & sdata->vif.valid_links & ~sdata->vif.dormant_links; 7825 new_suspended_links = 7826 (~map & sdata->vif.valid_links) & ~sdata->vif.dormant_links; 7827 new_dormant_links = sdata->vif.dormant_links | new_suspended_links; 7828 if (ieee80211_ttlm_set_links(sdata, new_active_links, 7829 new_dormant_links, new_suspended_links)) 7830 return; 7831 7832 sdata->vif.neg_ttlm = neg_ttlm; 7833 sdata->vif.neg_ttlm.valid = true; 7834 } 7835 7836 static void ieee80211_neg_ttlm_timeout_work(struct wiphy *wiphy, 7837 struct wiphy_work *work) 7838 { 7839 struct ieee80211_sub_if_data *sdata = 7840 container_of(work, struct ieee80211_sub_if_data, 7841 u.mgd.neg_ttlm_timeout_work.work); 7842 7843 sdata_info(sdata, 7844 "No negotiated TTLM response from AP, disconnecting.\n"); 7845 7846 __ieee80211_disconnect(sdata); 7847 } 7848 7849 static void 7850 ieee80211_neg_ttlm_add_suggested_map(struct sk_buff *skb, 7851 struct ieee80211_neg_ttlm *neg_ttlm) 7852 { 7853 u8 i, direction[IEEE80211_TTLM_MAX_CNT]; 7854 7855 if (memcmp(neg_ttlm->downlink, neg_ttlm->uplink, 7856 sizeof(neg_ttlm->downlink))) { 7857 direction[0] = IEEE80211_TTLM_DIRECTION_DOWN; 7858 direction[1] = IEEE80211_TTLM_DIRECTION_UP; 7859 } else { 7860 direction[0] = IEEE80211_TTLM_DIRECTION_BOTH; 7861 } 7862 7863 for (i = 0; i < ARRAY_SIZE(direction); i++) { 7864 u8 tid, len, map_ind = 0, *len_pos, *map_ind_pos, *pos; 7865 __le16 map; 7866 7867 len = sizeof(struct ieee80211_ttlm_elem) + 1 + 1; 7868 7869 pos = skb_put(skb, len + 2); 7870 *pos++ = WLAN_EID_EXTENSION; 7871 len_pos = pos++; 7872 *pos++ = WLAN_EID_EXT_TID_TO_LINK_MAPPING; 7873 *pos++ = direction[i]; 7874 map_ind_pos = pos++; 7875 for (tid = 0; tid < IEEE80211_TTLM_NUM_TIDS; tid++) { 7876 map = direction[i] == IEEE80211_TTLM_DIRECTION_UP ? 7877 cpu_to_le16(neg_ttlm->uplink[tid]) : 7878 cpu_to_le16(neg_ttlm->downlink[tid]); 7879 if (!map) 7880 continue; 7881 7882 len += 2; 7883 map_ind |= BIT(tid); 7884 skb_put_data(skb, &map, sizeof(map)); 7885 } 7886 7887 *map_ind_pos = map_ind; 7888 *len_pos = len; 7889 7890 if (direction[i] == IEEE80211_TTLM_DIRECTION_BOTH) 7891 break; 7892 } 7893 } 7894 7895 static void 7896 ieee80211_send_neg_ttlm_req(struct ieee80211_sub_if_data *sdata, 7897 struct ieee80211_neg_ttlm *neg_ttlm, 7898 u8 dialog_token) 7899 { 7900 struct ieee80211_local *local = sdata->local; 7901 struct ieee80211_mgmt *mgmt; 7902 struct sk_buff *skb; 7903 int hdr_len = offsetofend(struct ieee80211_mgmt, u.action.u.ttlm_req); 7904 int ttlm_max_len = 2 + 1 + sizeof(struct ieee80211_ttlm_elem) + 1 + 7905 2 * 2 * IEEE80211_TTLM_NUM_TIDS; 7906 7907 skb = dev_alloc_skb(local->tx_headroom + hdr_len + ttlm_max_len); 7908 if (!skb) 7909 return; 7910 7911 skb_reserve(skb, local->tx_headroom); 7912 mgmt = skb_put_zero(skb, hdr_len); 7913 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 7914 IEEE80211_STYPE_ACTION); 7915 memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN); 7916 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); 7917 memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN); 7918 7919 mgmt->u.action.category = WLAN_CATEGORY_PROTECTED_EHT; 7920 mgmt->u.action.u.ttlm_req.action_code = 7921 WLAN_PROTECTED_EHT_ACTION_TTLM_REQ; 7922 mgmt->u.action.u.ttlm_req.dialog_token = dialog_token; 7923 ieee80211_neg_ttlm_add_suggested_map(skb, neg_ttlm); 7924 ieee80211_tx_skb(sdata, skb); 7925 } 7926 7927 int ieee80211_req_neg_ttlm(struct ieee80211_sub_if_data *sdata, 7928 struct cfg80211_ttlm_params *params) 7929 { 7930 struct ieee80211_neg_ttlm neg_ttlm = {}; 7931 u8 i; 7932 7933 if (!ieee80211_vif_is_mld(&sdata->vif) || 7934 !(sdata->vif.cfg.mld_capa_op & 7935 IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP)) 7936 return -EINVAL; 7937 7938 for (i = 0; i < IEEE80211_TTLM_NUM_TIDS; i++) { 7939 if ((params->dlink[i] & ~sdata->vif.valid_links) || 7940 (params->ulink[i] & ~sdata->vif.valid_links)) 7941 return -EINVAL; 7942 7943 neg_ttlm.downlink[i] = params->dlink[i]; 7944 neg_ttlm.uplink[i] = params->ulink[i]; 7945 } 7946 7947 if (drv_can_neg_ttlm(sdata->local, sdata, &neg_ttlm) != 7948 NEG_TTLM_RES_ACCEPT) 7949 return -EINVAL; 7950 7951 ieee80211_apply_neg_ttlm(sdata, neg_ttlm); 7952 sdata->u.mgd.dialog_token_alloc++; 7953 ieee80211_send_neg_ttlm_req(sdata, &sdata->vif.neg_ttlm, 7954 sdata->u.mgd.dialog_token_alloc); 7955 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, 7956 &sdata->u.mgd.neg_ttlm_timeout_work); 7957 wiphy_delayed_work_queue(sdata->local->hw.wiphy, 7958 &sdata->u.mgd.neg_ttlm_timeout_work, 7959 IEEE80211_NEG_TTLM_REQ_TIMEOUT); 7960 return 0; 7961 } 7962 7963 static void 7964 ieee80211_send_neg_ttlm_res(struct ieee80211_sub_if_data *sdata, 7965 enum ieee80211_neg_ttlm_res ttlm_res, 7966 u8 dialog_token, 7967 struct ieee80211_neg_ttlm *neg_ttlm) 7968 { 7969 struct ieee80211_local *local = sdata->local; 7970 struct ieee80211_mgmt *mgmt; 7971 struct sk_buff *skb; 7972 int hdr_len = offsetofend(struct ieee80211_mgmt, u.action.u.ttlm_res); 7973 int ttlm_max_len = 2 + 1 + sizeof(struct ieee80211_ttlm_elem) + 1 + 7974 2 * 2 * IEEE80211_TTLM_NUM_TIDS; 7975 u16 status_code; 7976 7977 skb = dev_alloc_skb(local->tx_headroom + hdr_len + ttlm_max_len); 7978 if (!skb) 7979 return; 7980 7981 skb_reserve(skb, local->tx_headroom); 7982 mgmt = skb_put_zero(skb, hdr_len); 7983 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 7984 IEEE80211_STYPE_ACTION); 7985 memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN); 7986 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); 7987 memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN); 7988 7989 mgmt->u.action.category = WLAN_CATEGORY_PROTECTED_EHT; 7990 mgmt->u.action.u.ttlm_res.action_code = 7991 WLAN_PROTECTED_EHT_ACTION_TTLM_RES; 7992 mgmt->u.action.u.ttlm_res.dialog_token = dialog_token; 7993 switch (ttlm_res) { 7994 default: 7995 WARN_ON(1); 7996 fallthrough; 7997 case NEG_TTLM_RES_REJECT: 7998 status_code = WLAN_STATUS_DENIED_TID_TO_LINK_MAPPING; 7999 break; 8000 case NEG_TTLM_RES_ACCEPT: 8001 status_code = WLAN_STATUS_SUCCESS; 8002 break; 8003 case NEG_TTLM_RES_SUGGEST_PREFERRED: 8004 status_code = WLAN_STATUS_PREF_TID_TO_LINK_MAPPING_SUGGESTED; 8005 ieee80211_neg_ttlm_add_suggested_map(skb, neg_ttlm); 8006 break; 8007 } 8008 8009 mgmt->u.action.u.ttlm_res.status_code = cpu_to_le16(status_code); 8010 ieee80211_tx_skb(sdata, skb); 8011 } 8012 8013 static int 8014 ieee80211_parse_neg_ttlm(struct ieee80211_sub_if_data *sdata, 8015 const struct ieee80211_ttlm_elem *ttlm, 8016 struct ieee80211_neg_ttlm *neg_ttlm, 8017 u8 *direction) 8018 { 8019 u8 control, link_map_presence, map_size, tid; 8020 u8 *pos; 8021 8022 /* The element size was already validated in 8023 * ieee80211_tid_to_link_map_size_ok() 8024 */ 8025 pos = (void *)ttlm->optional; 8026 8027 control = ttlm->control; 8028 8029 /* mapping switch time and expected duration fields are not expected 8030 * in case of negotiated TTLM 8031 */ 8032 if (control & (IEEE80211_TTLM_CONTROL_SWITCH_TIME_PRESENT | 8033 IEEE80211_TTLM_CONTROL_EXPECTED_DUR_PRESENT)) { 8034 mlme_dbg(sdata, 8035 "Invalid TTLM element in negotiated TTLM request\n"); 8036 return -EINVAL; 8037 } 8038 8039 if (control & IEEE80211_TTLM_CONTROL_DEF_LINK_MAP) { 8040 for (tid = 0; tid < IEEE80211_TTLM_NUM_TIDS; tid++) { 8041 neg_ttlm->downlink[tid] = sdata->vif.valid_links; 8042 neg_ttlm->uplink[tid] = sdata->vif.valid_links; 8043 } 8044 *direction = IEEE80211_TTLM_DIRECTION_BOTH; 8045 return 0; 8046 } 8047 8048 *direction = u8_get_bits(control, IEEE80211_TTLM_CONTROL_DIRECTION); 8049 if (*direction != IEEE80211_TTLM_DIRECTION_DOWN && 8050 *direction != IEEE80211_TTLM_DIRECTION_UP && 8051 *direction != IEEE80211_TTLM_DIRECTION_BOTH) 8052 return -EINVAL; 8053 8054 link_map_presence = *pos; 8055 pos++; 8056 8057 if (control & IEEE80211_TTLM_CONTROL_LINK_MAP_SIZE) 8058 map_size = 1; 8059 else 8060 map_size = 2; 8061 8062 for (tid = 0; tid < IEEE80211_TTLM_NUM_TIDS; tid++) { 8063 u16 map; 8064 8065 if (link_map_presence & BIT(tid)) { 8066 map = ieee80211_get_ttlm(map_size, pos); 8067 if (!map) { 8068 mlme_dbg(sdata, 8069 "No active links for TID %d", tid); 8070 return -EINVAL; 8071 } 8072 } else { 8073 map = 0; 8074 } 8075 8076 switch (*direction) { 8077 case IEEE80211_TTLM_DIRECTION_BOTH: 8078 neg_ttlm->downlink[tid] = map; 8079 neg_ttlm->uplink[tid] = map; 8080 break; 8081 case IEEE80211_TTLM_DIRECTION_DOWN: 8082 neg_ttlm->downlink[tid] = map; 8083 break; 8084 case IEEE80211_TTLM_DIRECTION_UP: 8085 neg_ttlm->uplink[tid] = map; 8086 break; 8087 default: 8088 return -EINVAL; 8089 } 8090 pos += map_size; 8091 } 8092 return 0; 8093 } 8094 8095 void ieee80211_process_neg_ttlm_req(struct ieee80211_sub_if_data *sdata, 8096 struct ieee80211_mgmt *mgmt, size_t len) 8097 { 8098 u8 dialog_token, direction[IEEE80211_TTLM_MAX_CNT] = {}, i; 8099 size_t ies_len; 8100 enum ieee80211_neg_ttlm_res ttlm_res = NEG_TTLM_RES_ACCEPT; 8101 struct ieee802_11_elems *elems = NULL; 8102 struct ieee80211_neg_ttlm neg_ttlm = {}; 8103 8104 BUILD_BUG_ON(ARRAY_SIZE(direction) != ARRAY_SIZE(elems->ttlm)); 8105 8106 if (!ieee80211_vif_is_mld(&sdata->vif)) 8107 return; 8108 8109 dialog_token = mgmt->u.action.u.ttlm_req.dialog_token; 8110 ies_len = len - offsetof(struct ieee80211_mgmt, 8111 u.action.u.ttlm_req.variable); 8112 elems = ieee802_11_parse_elems(mgmt->u.action.u.ttlm_req.variable, 8113 ies_len, 8114 IEEE80211_FTYPE_MGMT | 8115 IEEE80211_STYPE_ACTION, 8116 NULL); 8117 if (!elems) { 8118 ttlm_res = NEG_TTLM_RES_REJECT; 8119 goto out; 8120 } 8121 8122 for (i = 0; i < elems->ttlm_num; i++) { 8123 if (ieee80211_parse_neg_ttlm(sdata, elems->ttlm[i], 8124 &neg_ttlm, &direction[i]) || 8125 (direction[i] == IEEE80211_TTLM_DIRECTION_BOTH && 8126 elems->ttlm_num != 1)) { 8127 ttlm_res = NEG_TTLM_RES_REJECT; 8128 goto out; 8129 } 8130 } 8131 8132 if (!elems->ttlm_num || 8133 (elems->ttlm_num == 2 && direction[0] == direction[1])) { 8134 ttlm_res = NEG_TTLM_RES_REJECT; 8135 goto out; 8136 } 8137 8138 for (i = 0; i < IEEE80211_TTLM_NUM_TIDS; i++) { 8139 if ((neg_ttlm.downlink[i] && 8140 (neg_ttlm.downlink[i] & ~sdata->vif.valid_links)) || 8141 (neg_ttlm.uplink[i] && 8142 (neg_ttlm.uplink[i] & ~sdata->vif.valid_links))) { 8143 ttlm_res = NEG_TTLM_RES_REJECT; 8144 goto out; 8145 } 8146 } 8147 8148 ttlm_res = drv_can_neg_ttlm(sdata->local, sdata, &neg_ttlm); 8149 8150 if (ttlm_res != NEG_TTLM_RES_ACCEPT) 8151 goto out; 8152 8153 ieee80211_apply_neg_ttlm(sdata, neg_ttlm); 8154 out: 8155 kfree(elems); 8156 ieee80211_send_neg_ttlm_res(sdata, ttlm_res, dialog_token, &neg_ttlm); 8157 } 8158 8159 void ieee80211_process_neg_ttlm_res(struct ieee80211_sub_if_data *sdata, 8160 struct ieee80211_mgmt *mgmt, size_t len) 8161 { 8162 if (!ieee80211_vif_is_mld(&sdata->vif) || 8163 mgmt->u.action.u.ttlm_req.dialog_token != 8164 sdata->u.mgd.dialog_token_alloc) 8165 return; 8166 8167 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, 8168 &sdata->u.mgd.neg_ttlm_timeout_work); 8169 8170 /* MLD station sends a TID to link mapping request, mainly to handle 8171 * BTM (BSS transition management) request, in which case it needs to 8172 * restrict the active links set. 8173 * In this case it's not expected that the MLD AP will reject the 8174 * negotiated TTLM request. 8175 * This can be better implemented in the future, to handle request 8176 * rejections. 8177 */ 8178 if (le16_to_cpu(mgmt->u.action.u.ttlm_res.status_code) != WLAN_STATUS_SUCCESS) 8179 __ieee80211_disconnect(sdata); 8180 } 8181 8182 void ieee80211_process_ttlm_teardown(struct ieee80211_sub_if_data *sdata) 8183 { 8184 u16 new_dormant_links; 8185 8186 if (!sdata->vif.neg_ttlm.valid) 8187 return; 8188 8189 memset(&sdata->vif.neg_ttlm, 0, sizeof(sdata->vif.neg_ttlm)); 8190 new_dormant_links = 8191 sdata->vif.dormant_links & ~sdata->vif.suspended_links; 8192 sdata->vif.suspended_links = 0; 8193 ieee80211_vif_set_links(sdata, sdata->vif.valid_links, 8194 new_dormant_links); 8195 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_MLD_TTLM | 8196 BSS_CHANGED_MLD_VALID_LINKS); 8197 } 8198 8199 static void ieee80211_teardown_ttlm_work(struct wiphy *wiphy, 8200 struct wiphy_work *work) 8201 { 8202 struct ieee80211_sub_if_data *sdata = 8203 container_of(work, struct ieee80211_sub_if_data, 8204 u.mgd.teardown_ttlm_work); 8205 8206 ieee80211_process_ttlm_teardown(sdata); 8207 } 8208 8209 void ieee80211_send_teardown_neg_ttlm(struct ieee80211_vif *vif) 8210 { 8211 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 8212 struct ieee80211_local *local = sdata->local; 8213 struct ieee80211_mgmt *mgmt; 8214 struct sk_buff *skb; 8215 int frame_len = offsetofend(struct ieee80211_mgmt, 8216 u.action.u.ttlm_tear_down); 8217 struct ieee80211_tx_info *info; 8218 8219 skb = dev_alloc_skb(local->hw.extra_tx_headroom + frame_len); 8220 if (!skb) 8221 return; 8222 8223 skb_reserve(skb, local->hw.extra_tx_headroom); 8224 mgmt = skb_put_zero(skb, frame_len); 8225 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 8226 IEEE80211_STYPE_ACTION); 8227 memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN); 8228 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); 8229 memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN); 8230 8231 mgmt->u.action.category = WLAN_CATEGORY_PROTECTED_EHT; 8232 mgmt->u.action.u.ttlm_tear_down.action_code = 8233 WLAN_PROTECTED_EHT_ACTION_TTLM_TEARDOWN; 8234 8235 info = IEEE80211_SKB_CB(skb); 8236 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; 8237 info->status_data = IEEE80211_STATUS_TYPE_NEG_TTLM; 8238 ieee80211_tx_skb(sdata, skb); 8239 } 8240 EXPORT_SYMBOL(ieee80211_send_teardown_neg_ttlm); 8241 8242 void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data *sdata, 8243 struct sk_buff *skb) 8244 { 8245 struct ieee80211_link_data *link = &sdata->deflink; 8246 struct ieee80211_rx_status *rx_status; 8247 struct ieee80211_hdr *hdr; 8248 u16 fc; 8249 8250 lockdep_assert_wiphy(sdata->local->hw.wiphy); 8251 8252 rx_status = (struct ieee80211_rx_status *) skb->cb; 8253 hdr = (struct ieee80211_hdr *) skb->data; 8254 fc = le16_to_cpu(hdr->frame_control); 8255 8256 switch (fc & IEEE80211_FCTL_STYPE) { 8257 case IEEE80211_STYPE_S1G_BEACON: 8258 ieee80211_rx_mgmt_beacon(link, hdr, skb->len, rx_status); 8259 break; 8260 } 8261 } 8262 8263 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, 8264 struct sk_buff *skb) 8265 { 8266 struct ieee80211_link_data *link = &sdata->deflink; 8267 struct ieee80211_rx_status *rx_status; 8268 struct ieee802_11_elems *elems; 8269 struct ieee80211_mgmt *mgmt; 8270 u16 fc; 8271 int ies_len; 8272 8273 lockdep_assert_wiphy(sdata->local->hw.wiphy); 8274 8275 rx_status = (struct ieee80211_rx_status *) skb->cb; 8276 mgmt = (struct ieee80211_mgmt *) skb->data; 8277 fc = le16_to_cpu(mgmt->frame_control); 8278 8279 if (rx_status->link_valid) { 8280 link = sdata_dereference(sdata->link[rx_status->link_id], 8281 sdata); 8282 if (!link) 8283 return; 8284 } 8285 8286 switch (fc & IEEE80211_FCTL_STYPE) { 8287 case IEEE80211_STYPE_BEACON: 8288 ieee80211_rx_mgmt_beacon(link, (void *)mgmt, 8289 skb->len, rx_status); 8290 break; 8291 case IEEE80211_STYPE_PROBE_RESP: 8292 ieee80211_rx_mgmt_probe_resp(link, skb); 8293 break; 8294 case IEEE80211_STYPE_AUTH: 8295 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len); 8296 break; 8297 case IEEE80211_STYPE_DEAUTH: 8298 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len); 8299 break; 8300 case IEEE80211_STYPE_DISASSOC: 8301 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len); 8302 break; 8303 case IEEE80211_STYPE_ASSOC_RESP: 8304 case IEEE80211_STYPE_REASSOC_RESP: 8305 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len); 8306 break; 8307 case IEEE80211_STYPE_ACTION: 8308 if (!sdata->u.mgd.associated || 8309 !ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr)) 8310 break; 8311 8312 switch (mgmt->u.action.category) { 8313 case WLAN_CATEGORY_SPECTRUM_MGMT: 8314 ies_len = skb->len - 8315 offsetof(struct ieee80211_mgmt, 8316 u.action.u.chan_switch.variable); 8317 8318 if (ies_len < 0) 8319 break; 8320 8321 /* CSA IE cannot be overridden, no need for BSSID */ 8322 elems = ieee802_11_parse_elems(mgmt->u.action.u.chan_switch.variable, 8323 ies_len, 8324 IEEE80211_FTYPE_MGMT | 8325 IEEE80211_STYPE_ACTION, 8326 NULL); 8327 8328 if (elems && !elems->parse_error) { 8329 enum ieee80211_csa_source src = 8330 IEEE80211_CSA_SOURCE_PROT_ACTION; 8331 8332 ieee80211_sta_process_chanswitch(link, 8333 rx_status->mactime, 8334 rx_status->device_timestamp, 8335 elems, elems, 8336 src); 8337 } 8338 kfree(elems); 8339 break; 8340 case WLAN_CATEGORY_PUBLIC: 8341 case WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION: 8342 ies_len = skb->len - 8343 offsetof(struct ieee80211_mgmt, 8344 u.action.u.ext_chan_switch.variable); 8345 8346 if (ies_len < 0) 8347 break; 8348 8349 /* 8350 * extended CSA IE can't be overridden, no need for 8351 * BSSID 8352 */ 8353 elems = ieee802_11_parse_elems(mgmt->u.action.u.ext_chan_switch.variable, 8354 ies_len, 8355 IEEE80211_FTYPE_MGMT | 8356 IEEE80211_STYPE_ACTION, 8357 NULL); 8358 8359 if (elems && !elems->parse_error) { 8360 enum ieee80211_csa_source src; 8361 8362 if (mgmt->u.action.category == 8363 WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION) 8364 src = IEEE80211_CSA_SOURCE_PROT_ACTION; 8365 else 8366 src = IEEE80211_CSA_SOURCE_UNPROT_ACTION; 8367 8368 /* for the handling code pretend it was an IE */ 8369 elems->ext_chansw_ie = 8370 &mgmt->u.action.u.ext_chan_switch.data; 8371 8372 ieee80211_sta_process_chanswitch(link, 8373 rx_status->mactime, 8374 rx_status->device_timestamp, 8375 elems, elems, 8376 src); 8377 } 8378 8379 kfree(elems); 8380 break; 8381 } 8382 break; 8383 } 8384 } 8385 8386 static void ieee80211_sta_timer(struct timer_list *t) 8387 { 8388 struct ieee80211_sub_if_data *sdata = 8389 timer_container_of(sdata, t, u.mgd.timer); 8390 8391 wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work); 8392 } 8393 8394 void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata, 8395 u8 reason, bool tx) 8396 { 8397 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; 8398 8399 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason, 8400 tx, frame_buf); 8401 8402 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true, 8403 reason, false); 8404 } 8405 8406 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata) 8407 { 8408 struct ieee80211_local *local = sdata->local; 8409 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 8410 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data; 8411 u32 tx_flags = 0; 8412 u16 trans = 1; 8413 u16 status = 0; 8414 struct ieee80211_prep_tx_info info = { 8415 .subtype = IEEE80211_STYPE_AUTH, 8416 }; 8417 8418 lockdep_assert_wiphy(sdata->local->hw.wiphy); 8419 8420 if (WARN_ON_ONCE(!auth_data)) 8421 return -EINVAL; 8422 8423 if (auth_data->algorithm == WLAN_AUTH_EPPKE && 8424 ieee80211_vif_is_mld(&sdata->vif) && 8425 !cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_MULTI_LINK, 8426 auth_data->data, auth_data->data_len)) 8427 return -EINVAL; 8428 8429 auth_data->tries++; 8430 8431 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) { 8432 sdata_info(sdata, "authentication with %pM timed out\n", 8433 auth_data->ap_addr); 8434 8435 /* 8436 * Most likely AP is not in the range so remove the 8437 * bss struct for that AP. 8438 */ 8439 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss); 8440 8441 return -ETIMEDOUT; 8442 } 8443 8444 if (auth_data->algorithm == WLAN_AUTH_SAE) 8445 info.duration = jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE); 8446 8447 info.link_id = auth_data->link_id; 8448 drv_mgd_prepare_tx(local, sdata, &info); 8449 8450 sdata_info(sdata, "send auth to %pM (try %d/%d)\n", 8451 auth_data->ap_addr, auth_data->tries, 8452 IEEE80211_AUTH_MAX_TRIES); 8453 8454 auth_data->expected_transaction = 2; 8455 8456 if (auth_data->algorithm == WLAN_AUTH_SAE) { 8457 trans = auth_data->trans; 8458 status = auth_data->status; 8459 auth_data->expected_transaction = trans; 8460 } else if (auth_data->algorithm == WLAN_AUTH_EPPKE) { 8461 trans = auth_data->trans; 8462 status = auth_data->status; 8463 } 8464 8465 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) 8466 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS | 8467 IEEE80211_TX_INTFL_MLME_CONN_TX; 8468 8469 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status, 8470 auth_data->data, auth_data->data_len, 8471 auth_data->ap_addr, auth_data->ap_addr, 8472 NULL, 0, 0, tx_flags); 8473 8474 if (tx_flags == 0) { 8475 if (auth_data->algorithm == WLAN_AUTH_SAE) 8476 auth_data->timeout = jiffies + 8477 IEEE80211_AUTH_TIMEOUT_SAE; 8478 else 8479 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT; 8480 } else { 8481 auth_data->timeout = 8482 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG); 8483 } 8484 8485 auth_data->timeout_started = true; 8486 run_again(sdata, auth_data->timeout); 8487 8488 return 0; 8489 } 8490 8491 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata) 8492 { 8493 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data; 8494 struct ieee80211_local *local = sdata->local; 8495 int ret; 8496 8497 lockdep_assert_wiphy(sdata->local->hw.wiphy); 8498 8499 assoc_data->tries++; 8500 assoc_data->comeback = false; 8501 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) { 8502 sdata_info(sdata, "association with %pM timed out\n", 8503 assoc_data->ap_addr); 8504 8505 /* 8506 * Most likely AP is not in the range so remove the 8507 * bss struct for that AP. 8508 */ 8509 cfg80211_unlink_bss(local->hw.wiphy, 8510 assoc_data->link[assoc_data->assoc_link_id].bss); 8511 8512 return -ETIMEDOUT; 8513 } 8514 8515 sdata_info(sdata, "associate with %pM (try %d/%d)\n", 8516 assoc_data->ap_addr, assoc_data->tries, 8517 IEEE80211_ASSOC_MAX_TRIES); 8518 ret = ieee80211_send_assoc(sdata); 8519 if (ret) 8520 return ret; 8521 8522 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) { 8523 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT; 8524 assoc_data->timeout_started = true; 8525 run_again(sdata, assoc_data->timeout); 8526 } else { 8527 assoc_data->timeout = 8528 round_jiffies_up(jiffies + 8529 IEEE80211_ASSOC_TIMEOUT_LONG); 8530 assoc_data->timeout_started = true; 8531 run_again(sdata, assoc_data->timeout); 8532 } 8533 8534 return 0; 8535 } 8536 8537 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata, 8538 __le16 fc, bool acked) 8539 { 8540 struct ieee80211_local *local = sdata->local; 8541 8542 sdata->u.mgd.status_fc = fc; 8543 sdata->u.mgd.status_acked = acked; 8544 sdata->u.mgd.status_received = true; 8545 8546 wiphy_work_queue(local->hw.wiphy, &sdata->work); 8547 } 8548 8549 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata) 8550 { 8551 struct ieee80211_local *local = sdata->local; 8552 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 8553 8554 lockdep_assert_wiphy(sdata->local->hw.wiphy); 8555 8556 if (ifmgd->status_received) { 8557 __le16 fc = ifmgd->status_fc; 8558 bool status_acked = ifmgd->status_acked; 8559 8560 ifmgd->status_received = false; 8561 if (ifmgd->auth_data && ieee80211_is_auth(fc)) { 8562 if (status_acked) { 8563 if (ifmgd->auth_data->algorithm == 8564 WLAN_AUTH_SAE) 8565 ifmgd->auth_data->timeout = 8566 jiffies + 8567 IEEE80211_AUTH_TIMEOUT_SAE; 8568 else 8569 ifmgd->auth_data->timeout = 8570 jiffies + 8571 IEEE80211_AUTH_TIMEOUT_SHORT; 8572 run_again(sdata, ifmgd->auth_data->timeout); 8573 } else { 8574 ifmgd->auth_data->timeout = jiffies - 1; 8575 } 8576 ifmgd->auth_data->timeout_started = true; 8577 } else if (ifmgd->assoc_data && 8578 !ifmgd->assoc_data->comeback && 8579 (ieee80211_is_assoc_req(fc) || 8580 ieee80211_is_reassoc_req(fc))) { 8581 /* 8582 * Update association timeout based on the TX status 8583 * for the (Re)Association Request frame. Skip this if 8584 * we have already processed a (Re)Association Response 8585 * frame that indicated need for association comeback 8586 * at a specific time in the future. This could happen 8587 * if the TX status information is delayed enough for 8588 * the response to be received and processed first. 8589 */ 8590 if (status_acked) { 8591 ifmgd->assoc_data->timeout = 8592 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT; 8593 run_again(sdata, ifmgd->assoc_data->timeout); 8594 } else { 8595 ifmgd->assoc_data->timeout = jiffies - 1; 8596 } 8597 ifmgd->assoc_data->timeout_started = true; 8598 } 8599 } 8600 8601 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started && 8602 time_after(jiffies, ifmgd->auth_data->timeout)) { 8603 if (ifmgd->auth_data->done || ifmgd->auth_data->waiting) { 8604 /* 8605 * ok ... we waited for assoc or continuation but 8606 * userspace didn't do it, so kill the auth data 8607 */ 8608 ieee80211_destroy_auth_data(sdata, false); 8609 } else if (ieee80211_auth(sdata)) { 8610 u8 ap_addr[ETH_ALEN]; 8611 struct ieee80211_event event = { 8612 .type = MLME_EVENT, 8613 .u.mlme.data = AUTH_EVENT, 8614 .u.mlme.status = MLME_TIMEOUT, 8615 }; 8616 8617 memcpy(ap_addr, ifmgd->auth_data->ap_addr, ETH_ALEN); 8618 8619 ieee80211_destroy_auth_data(sdata, false); 8620 8621 cfg80211_auth_timeout(sdata->dev, ap_addr); 8622 drv_event_callback(sdata->local, sdata, &event); 8623 } 8624 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started) 8625 run_again(sdata, ifmgd->auth_data->timeout); 8626 8627 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started && 8628 time_after(jiffies, ifmgd->assoc_data->timeout)) { 8629 if ((ifmgd->assoc_data->need_beacon && 8630 !sdata->deflink.u.mgd.have_beacon) || 8631 ieee80211_do_assoc(sdata)) { 8632 struct ieee80211_event event = { 8633 .type = MLME_EVENT, 8634 .u.mlme.data = ASSOC_EVENT, 8635 .u.mlme.status = MLME_TIMEOUT, 8636 }; 8637 8638 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT); 8639 drv_event_callback(sdata->local, sdata, &event); 8640 } 8641 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started) 8642 run_again(sdata, ifmgd->assoc_data->timeout); 8643 8644 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL && 8645 ifmgd->associated) { 8646 u8 *bssid = sdata->deflink.u.mgd.bssid; 8647 int max_tries; 8648 8649 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) 8650 max_tries = max_nullfunc_tries; 8651 else 8652 max_tries = max_probe_tries; 8653 8654 /* ACK received for nullfunc probing frame */ 8655 if (!ifmgd->probe_send_count) 8656 ieee80211_reset_ap_probe(sdata); 8657 else if (ifmgd->nullfunc_failed) { 8658 if (ifmgd->probe_send_count < max_tries) { 8659 mlme_dbg(sdata, 8660 "No ack for nullfunc frame to AP %pM, try %d/%i\n", 8661 bssid, ifmgd->probe_send_count, 8662 max_tries); 8663 ieee80211_mgd_probe_ap_send(sdata); 8664 } else { 8665 mlme_dbg(sdata, 8666 "No ack for nullfunc frame to AP %pM, disconnecting.\n", 8667 bssid); 8668 ieee80211_sta_connection_lost(sdata, 8669 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, 8670 false); 8671 } 8672 } else if (time_is_after_jiffies(ifmgd->probe_timeout)) 8673 run_again(sdata, ifmgd->probe_timeout); 8674 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) { 8675 mlme_dbg(sdata, 8676 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n", 8677 bssid, probe_wait_ms); 8678 ieee80211_sta_connection_lost(sdata, 8679 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false); 8680 } else if (ifmgd->probe_send_count < max_tries) { 8681 mlme_dbg(sdata, 8682 "No probe response from AP %pM after %dms, try %d/%i\n", 8683 bssid, probe_wait_ms, 8684 ifmgd->probe_send_count, max_tries); 8685 ieee80211_mgd_probe_ap_send(sdata); 8686 } else { 8687 /* 8688 * We actually lost the connection ... or did we? 8689 * Let's make sure! 8690 */ 8691 mlme_dbg(sdata, 8692 "No probe response from AP %pM after %dms, disconnecting.\n", 8693 bssid, probe_wait_ms); 8694 8695 ieee80211_sta_connection_lost(sdata, 8696 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false); 8697 } 8698 } 8699 } 8700 8701 static bool 8702 ieee80211_is_csa_in_progress(struct ieee80211_sub_if_data *sdata) 8703 { 8704 /* 8705 * In MLO, check the CSA flags 'active' and 'waiting_bcn' for all 8706 * the links. 8707 */ 8708 struct ieee80211_link_data *link; 8709 8710 guard(rcu)(); 8711 8712 for_each_link_data_rcu(sdata, link) { 8713 if (!(link->conf->csa_active && 8714 !link->u.mgd.csa.waiting_bcn)) 8715 return false; 8716 } 8717 8718 return true; 8719 } 8720 8721 static void ieee80211_sta_bcn_mon_timer(struct timer_list *t) 8722 { 8723 struct ieee80211_sub_if_data *sdata = 8724 timer_container_of(sdata, t, u.mgd.bcn_mon_timer); 8725 8726 if (ieee80211_is_csa_in_progress(sdata)) 8727 return; 8728 8729 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER) 8730 return; 8731 8732 sdata->u.mgd.connection_loss = false; 8733 wiphy_work_queue(sdata->local->hw.wiphy, 8734 &sdata->u.mgd.beacon_connection_loss_work); 8735 } 8736 8737 static unsigned long 8738 ieee80211_latest_active_link_conn_timeout(struct ieee80211_sub_if_data *sdata) 8739 { 8740 unsigned long latest_timeout = jiffies; 8741 unsigned int link_id; 8742 struct sta_info *sta; 8743 8744 guard(rcu)(); 8745 8746 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr); 8747 if (!sta) 8748 return 0; 8749 8750 for (link_id = 0; link_id < ARRAY_SIZE(sta->link); 8751 link_id++) { 8752 struct link_sta_info *link_sta; 8753 unsigned long timeout; 8754 8755 link_sta = rcu_dereference(sta->link[link_id]); 8756 if (!link_sta) 8757 continue; 8758 8759 timeout = link_sta->status_stats.last_ack; 8760 if (time_before(timeout, link_sta->rx_stats.last_rx)) 8761 timeout = link_sta->rx_stats.last_rx; 8762 8763 timeout += IEEE80211_CONNECTION_IDLE_TIME; 8764 8765 /* 8766 * latest_timeout holds the timeout of the link 8767 * that will expire last among all links in an 8768 * non-AP MLD STA. This ensures that the connection 8769 * monitor timer is only reset if at least one link 8770 * is still active, and it is scheduled to fire at 8771 * the latest possible timeout. 8772 */ 8773 if (time_after(timeout, latest_timeout)) 8774 latest_timeout = timeout; 8775 } 8776 8777 return latest_timeout; 8778 } 8779 8780 static void ieee80211_sta_conn_mon_timer(struct timer_list *t) 8781 { 8782 struct ieee80211_sub_if_data *sdata = 8783 timer_container_of(sdata, t, u.mgd.conn_mon_timer); 8784 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 8785 struct ieee80211_local *local = sdata->local; 8786 unsigned long latest_timeout; 8787 8788 if (ieee80211_is_csa_in_progress(sdata)) 8789 return; 8790 8791 latest_timeout = ieee80211_latest_active_link_conn_timeout(sdata); 8792 8793 /* 8794 * If latest timeout is after now, then update timer to fire at 8795 * the later date, but do not actually probe at this time. 8796 */ 8797 if (time_is_after_jiffies(latest_timeout)) { 8798 mod_timer(&ifmgd->conn_mon_timer, 8799 round_jiffies_up(latest_timeout)); 8800 return; 8801 } 8802 8803 wiphy_work_queue(local->hw.wiphy, &sdata->u.mgd.monitor_work); 8804 } 8805 8806 static void ieee80211_sta_monitor_work(struct wiphy *wiphy, 8807 struct wiphy_work *work) 8808 { 8809 struct ieee80211_sub_if_data *sdata = 8810 container_of(work, struct ieee80211_sub_if_data, 8811 u.mgd.monitor_work); 8812 8813 ieee80211_mgd_probe_ap(sdata, false); 8814 } 8815 8816 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata) 8817 { 8818 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 8819 __ieee80211_stop_poll(sdata); 8820 8821 /* let's probe the connection once */ 8822 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR)) 8823 wiphy_work_queue(sdata->local->hw.wiphy, 8824 &sdata->u.mgd.monitor_work); 8825 } 8826 } 8827 8828 #ifdef CONFIG_PM 8829 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata) 8830 { 8831 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 8832 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; 8833 8834 lockdep_assert_wiphy(sdata->local->hw.wiphy); 8835 8836 if (ifmgd->auth_data || ifmgd->assoc_data) { 8837 const u8 *ap_addr = ifmgd->auth_data ? 8838 ifmgd->auth_data->ap_addr : 8839 ifmgd->assoc_data->ap_addr; 8840 8841 /* 8842 * If we are trying to authenticate / associate while suspending, 8843 * cfg80211 won't know and won't actually abort those attempts, 8844 * thus we need to do that ourselves. 8845 */ 8846 ieee80211_send_deauth_disassoc(sdata, ap_addr, ap_addr, 8847 IEEE80211_STYPE_DEAUTH, 8848 WLAN_REASON_DEAUTH_LEAVING, 8849 false, frame_buf); 8850 if (ifmgd->assoc_data) 8851 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON); 8852 if (ifmgd->auth_data) 8853 ieee80211_destroy_auth_data(sdata, false); 8854 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf, 8855 IEEE80211_DEAUTH_FRAME_LEN, 8856 false); 8857 } 8858 8859 /* This is a bit of a hack - we should find a better and more generic 8860 * solution to this. Normally when suspending, cfg80211 will in fact 8861 * deauthenticate. However, it doesn't (and cannot) stop an ongoing 8862 * auth (not so important) or assoc (this is the problem) process. 8863 * 8864 * As a consequence, it can happen that we are in the process of both 8865 * associating and suspending, and receive an association response 8866 * after cfg80211 has checked if it needs to disconnect, but before 8867 * we actually set the flag to drop incoming frames. This will then 8868 * cause the workqueue flush to process the association response in 8869 * the suspend, resulting in a successful association just before it 8870 * tries to remove the interface from the driver, which now though 8871 * has a channel context assigned ... this results in issues. 8872 * 8873 * To work around this (for now) simply deauth here again if we're 8874 * now connected. 8875 */ 8876 if (ifmgd->associated && !sdata->local->wowlan) { 8877 u8 bssid[ETH_ALEN]; 8878 struct cfg80211_deauth_request req = { 8879 .reason_code = WLAN_REASON_DEAUTH_LEAVING, 8880 .bssid = bssid, 8881 }; 8882 8883 memcpy(bssid, sdata->vif.cfg.ap_addr, ETH_ALEN); 8884 ieee80211_mgd_deauth(sdata, &req); 8885 } 8886 } 8887 #endif 8888 8889 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata) 8890 { 8891 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 8892 8893 lockdep_assert_wiphy(sdata->local->hw.wiphy); 8894 8895 if (!ifmgd->associated) 8896 return; 8897 8898 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) { 8899 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME; 8900 mlme_dbg(sdata, "driver requested disconnect after resume\n"); 8901 ieee80211_sta_connection_lost(sdata, 8902 WLAN_REASON_UNSPECIFIED, 8903 true); 8904 return; 8905 } 8906 8907 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_HW_RESTART) { 8908 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_HW_RESTART; 8909 mlme_dbg(sdata, "driver requested disconnect after hardware restart\n"); 8910 ieee80211_sta_connection_lost(sdata, 8911 WLAN_REASON_UNSPECIFIED, 8912 true); 8913 return; 8914 } 8915 } 8916 8917 static void ieee80211_request_smps_mgd_work(struct wiphy *wiphy, 8918 struct wiphy_work *work) 8919 { 8920 struct ieee80211_link_data *link = 8921 container_of(work, struct ieee80211_link_data, 8922 u.mgd.request_smps_work); 8923 8924 __ieee80211_request_smps_mgd(link->sdata, link, 8925 link->u.mgd.driver_smps_mode); 8926 } 8927 8928 static void ieee80211_ml_sta_reconf_timeout(struct wiphy *wiphy, 8929 struct wiphy_work *work) 8930 { 8931 struct ieee80211_sub_if_data *sdata = 8932 container_of(work, struct ieee80211_sub_if_data, 8933 u.mgd.reconf.wk.work); 8934 8935 if (!sdata->u.mgd.reconf.added_links && 8936 !sdata->u.mgd.reconf.removed_links) 8937 return; 8938 8939 sdata_info(sdata, 8940 "mlo: reconf: timeout: added=0x%x, removed=0x%x\n", 8941 sdata->u.mgd.reconf.added_links, 8942 sdata->u.mgd.reconf.removed_links); 8943 8944 __ieee80211_disconnect(sdata); 8945 } 8946 8947 /* interface setup */ 8948 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata) 8949 { 8950 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 8951 8952 wiphy_work_init(&ifmgd->monitor_work, ieee80211_sta_monitor_work); 8953 wiphy_work_init(&ifmgd->beacon_connection_loss_work, 8954 ieee80211_beacon_connection_loss_work); 8955 wiphy_work_init(&ifmgd->csa_connection_drop_work, 8956 ieee80211_csa_connection_drop_work); 8957 wiphy_delayed_work_init(&ifmgd->tdls_peer_del_work, 8958 ieee80211_tdls_peer_del_work); 8959 wiphy_hrtimer_work_init(&ifmgd->ml_reconf_work, 8960 ieee80211_ml_reconf_work); 8961 wiphy_delayed_work_init(&ifmgd->reconf.wk, 8962 ieee80211_ml_sta_reconf_timeout); 8963 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0); 8964 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0); 8965 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0); 8966 wiphy_delayed_work_init(&ifmgd->tx_tspec_wk, 8967 ieee80211_sta_handle_tspec_ac_params_wk); 8968 wiphy_hrtimer_work_init(&ifmgd->ttlm_work, 8969 ieee80211_tid_to_link_map_work); 8970 wiphy_delayed_work_init(&ifmgd->neg_ttlm_timeout_work, 8971 ieee80211_neg_ttlm_timeout_work); 8972 wiphy_work_init(&ifmgd->teardown_ttlm_work, 8973 ieee80211_teardown_ttlm_work); 8974 8975 ifmgd->flags = 0; 8976 ifmgd->powersave = sdata->wdev.ps; 8977 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues; 8978 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len; 8979 /* Setup TDLS data */ 8980 spin_lock_init(&ifmgd->teardown_lock); 8981 ifmgd->teardown_skb = NULL; 8982 ifmgd->orig_teardown_skb = NULL; 8983 ifmgd->mcast_seq_last = IEEE80211_SN_MODULO; 8984 } 8985 8986 static void ieee80211_recalc_smps_work(struct wiphy *wiphy, 8987 struct wiphy_work *work) 8988 { 8989 struct ieee80211_link_data *link = 8990 container_of(work, struct ieee80211_link_data, 8991 u.mgd.recalc_smps); 8992 8993 ieee80211_recalc_smps(link->sdata, link); 8994 } 8995 8996 void ieee80211_mgd_setup_link(struct ieee80211_link_data *link) 8997 { 8998 struct ieee80211_sub_if_data *sdata = link->sdata; 8999 struct ieee80211_local *local = sdata->local; 9000 unsigned int link_id = link->link_id; 9001 9002 link->u.mgd.p2p_noa_index = -1; 9003 link->conf->bssid = link->u.mgd.bssid; 9004 link->smps_mode = IEEE80211_SMPS_OFF; 9005 9006 wiphy_work_init(&link->u.mgd.request_smps_work, 9007 ieee80211_request_smps_mgd_work); 9008 wiphy_work_init(&link->u.mgd.recalc_smps, 9009 ieee80211_recalc_smps_work); 9010 if (local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS) 9011 link->u.mgd.req_smps = IEEE80211_SMPS_AUTOMATIC; 9012 else 9013 link->u.mgd.req_smps = IEEE80211_SMPS_OFF; 9014 9015 wiphy_hrtimer_work_init(&link->u.mgd.csa.switch_work, 9016 ieee80211_csa_switch_work); 9017 9018 ieee80211_clear_tpe(&link->conf->tpe); 9019 9020 if (sdata->u.mgd.assoc_data) 9021 ether_addr_copy(link->conf->addr, 9022 sdata->u.mgd.assoc_data->link[link_id].addr); 9023 else if (sdata->u.mgd.reconf.add_links_data) 9024 ether_addr_copy(link->conf->addr, 9025 sdata->u.mgd.reconf.add_links_data->link[link_id].addr); 9026 else if (!is_valid_ether_addr(link->conf->addr)) 9027 eth_random_addr(link->conf->addr); 9028 } 9029 9030 /* scan finished notification */ 9031 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local) 9032 { 9033 struct ieee80211_sub_if_data *sdata; 9034 9035 /* Restart STA timers */ 9036 rcu_read_lock(); 9037 list_for_each_entry_rcu(sdata, &local->interfaces, list) { 9038 if (ieee80211_sdata_running(sdata)) 9039 ieee80211_restart_sta_timer(sdata); 9040 } 9041 rcu_read_unlock(); 9042 } 9043 9044 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata, 9045 struct cfg80211_bss *cbss, s8 link_id, 9046 const u8 *ap_mld_addr, bool assoc, 9047 struct ieee80211_conn_settings *conn, 9048 bool override, 9049 unsigned long *userspace_selectors) 9050 { 9051 struct ieee80211_local *local = sdata->local; 9052 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 9053 struct ieee80211_bss *bss = (void *)cbss->priv; 9054 struct sta_info *new_sta = NULL; 9055 struct ieee80211_link_data *link; 9056 bool have_sta = false; 9057 bool mlo; 9058 int err; 9059 u16 new_links; 9060 9061 if (link_id >= 0) { 9062 mlo = true; 9063 if (WARN_ON(!ap_mld_addr)) 9064 return -EINVAL; 9065 new_links = BIT(link_id); 9066 } else { 9067 if (WARN_ON(ap_mld_addr)) 9068 return -EINVAL; 9069 ap_mld_addr = cbss->bssid; 9070 new_links = 0; 9071 link_id = 0; 9072 mlo = false; 9073 } 9074 9075 if (assoc) { 9076 rcu_read_lock(); 9077 have_sta = sta_info_get(sdata, ap_mld_addr); 9078 rcu_read_unlock(); 9079 } 9080 9081 if (mlo && !have_sta && 9082 WARN_ON(sdata->vif.valid_links || sdata->vif.active_links)) 9083 return -EINVAL; 9084 9085 err = ieee80211_vif_set_links(sdata, new_links, 0); 9086 if (err) 9087 return err; 9088 9089 link = sdata_dereference(sdata->link[link_id], sdata); 9090 if (WARN_ON(!link)) { 9091 err = -ENOLINK; 9092 goto out_err; 9093 } 9094 9095 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data)) { 9096 err = -EINVAL; 9097 goto out_err; 9098 } 9099 9100 /* If a reconfig is happening, bail out */ 9101 if (local->in_reconfig) { 9102 err = -EBUSY; 9103 goto out_err; 9104 } 9105 9106 if (!have_sta) { 9107 if (mlo) 9108 new_sta = sta_info_alloc_with_link(sdata, ap_mld_addr, 9109 link_id, cbss->bssid, 9110 GFP_KERNEL); 9111 else 9112 new_sta = sta_info_alloc(sdata, ap_mld_addr, GFP_KERNEL); 9113 9114 if (!new_sta) { 9115 err = -ENOMEM; 9116 goto out_err; 9117 } 9118 9119 if (ifmgd->auth_data && 9120 ifmgd->auth_data->algorithm == WLAN_AUTH_EPPKE) 9121 new_sta->sta.epp_peer = true; 9122 9123 new_sta->sta.mlo = mlo; 9124 } 9125 9126 /* 9127 * Set up the information for the new channel before setting the 9128 * new channel. We can't - completely race-free - change the basic 9129 * rates bitmap and the channel (sband) that it refers to, but if 9130 * we set it up before we at least avoid calling into the driver's 9131 * bss_info_changed() method with invalid information (since we do 9132 * call that from changing the channel - only for IDLE and perhaps 9133 * some others, but ...). 9134 * 9135 * So to avoid that, just set up all the new information before the 9136 * channel, but tell the driver to apply it only afterwards, since 9137 * it might need the new channel for that. 9138 */ 9139 if (new_sta) { 9140 const struct cfg80211_bss_ies *ies; 9141 struct link_sta_info *link_sta; 9142 9143 rcu_read_lock(); 9144 link_sta = rcu_dereference(new_sta->link[link_id]); 9145 if (WARN_ON(!link_sta)) { 9146 rcu_read_unlock(); 9147 sta_info_free(local, new_sta); 9148 err = -EINVAL; 9149 goto out_err; 9150 } 9151 9152 err = ieee80211_mgd_setup_link_sta(link, new_sta, 9153 link_sta, cbss); 9154 if (err) { 9155 rcu_read_unlock(); 9156 sta_info_free(local, new_sta); 9157 goto out_err; 9158 } 9159 9160 memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN); 9161 9162 /* set timing information */ 9163 link->conf->beacon_int = cbss->beacon_interval; 9164 ies = rcu_dereference(cbss->beacon_ies); 9165 if (ies) { 9166 link->conf->sync_tsf = ies->tsf; 9167 link->conf->sync_device_ts = 9168 bss->device_ts_beacon; 9169 9170 ieee80211_get_dtim(ies, 9171 &link->conf->sync_dtim_count, 9172 NULL); 9173 } else if (!ieee80211_hw_check(&sdata->local->hw, 9174 TIMING_BEACON_ONLY)) { 9175 ies = rcu_dereference(cbss->proberesp_ies); 9176 /* must be non-NULL since beacon IEs were NULL */ 9177 link->conf->sync_tsf = ies->tsf; 9178 link->conf->sync_device_ts = 9179 bss->device_ts_presp; 9180 link->conf->sync_dtim_count = 0; 9181 } else { 9182 link->conf->sync_tsf = 0; 9183 link->conf->sync_device_ts = 0; 9184 link->conf->sync_dtim_count = 0; 9185 } 9186 rcu_read_unlock(); 9187 } 9188 9189 if (new_sta || override) { 9190 /* 9191 * Only set this if we're also going to calculate the AP 9192 * settings etc., otherwise this was set before in a 9193 * previous call. Note override is set to %true in assoc 9194 * if the settings were changed. 9195 */ 9196 link->u.mgd.conn = *conn; 9197 err = ieee80211_prep_channel(sdata, link, link->link_id, cbss, 9198 mlo, &link->u.mgd.conn, 9199 userspace_selectors); 9200 if (err) { 9201 if (new_sta) 9202 sta_info_free(local, new_sta); 9203 goto out_err; 9204 } 9205 /* pass out for use in assoc */ 9206 *conn = link->u.mgd.conn; 9207 } 9208 9209 if (new_sta) { 9210 /* 9211 * tell driver about BSSID, basic rates and timing 9212 * this was set up above, before setting the channel 9213 */ 9214 ieee80211_link_info_change_notify(sdata, link, 9215 BSS_CHANGED_BSSID | 9216 BSS_CHANGED_BASIC_RATES | 9217 BSS_CHANGED_BEACON_INT); 9218 9219 if (assoc) 9220 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH); 9221 9222 err = sta_info_insert(new_sta); 9223 new_sta = NULL; 9224 if (err) { 9225 sdata_info(sdata, 9226 "failed to insert STA entry for the AP (error %d)\n", 9227 err); 9228 goto out_release_chan; 9229 } 9230 } else 9231 WARN_ON_ONCE(!ether_addr_equal(link->u.mgd.bssid, cbss->bssid)); 9232 9233 /* Cancel scan to ensure that nothing interferes with connection */ 9234 if (local->scanning) 9235 ieee80211_scan_cancel(local); 9236 9237 return 0; 9238 9239 out_release_chan: 9240 ieee80211_link_release_channel(link); 9241 out_err: 9242 ieee80211_vif_set_links(sdata, 0, 0); 9243 return err; 9244 } 9245 9246 static bool ieee80211_mgd_csa_present(struct ieee80211_sub_if_data *sdata, 9247 const struct cfg80211_bss_ies *ies, 9248 u8 cur_channel, bool ignore_ecsa) 9249 { 9250 const struct element *csa_elem, *ecsa_elem; 9251 struct ieee80211_channel_sw_ie *csa = NULL; 9252 struct ieee80211_ext_chansw_ie *ecsa = NULL; 9253 9254 if (!ies) 9255 return false; 9256 9257 csa_elem = cfg80211_find_elem(WLAN_EID_CHANNEL_SWITCH, 9258 ies->data, ies->len); 9259 if (csa_elem && csa_elem->datalen == sizeof(*csa)) 9260 csa = (void *)csa_elem->data; 9261 9262 ecsa_elem = cfg80211_find_elem(WLAN_EID_EXT_CHANSWITCH_ANN, 9263 ies->data, ies->len); 9264 if (ecsa_elem && ecsa_elem->datalen == sizeof(*ecsa)) 9265 ecsa = (void *)ecsa_elem->data; 9266 9267 if (csa && csa->count == 0) 9268 csa = NULL; 9269 if (csa && !csa->mode && csa->new_ch_num == cur_channel) 9270 csa = NULL; 9271 9272 if (ecsa && ecsa->count == 0) 9273 ecsa = NULL; 9274 if (ecsa && !ecsa->mode && ecsa->new_ch_num == cur_channel) 9275 ecsa = NULL; 9276 9277 if (ignore_ecsa && ecsa) { 9278 sdata_info(sdata, 9279 "Ignoring ECSA in probe response - was considered stuck!\n"); 9280 return csa; 9281 } 9282 9283 return csa || ecsa; 9284 } 9285 9286 static bool ieee80211_mgd_csa_in_process(struct ieee80211_sub_if_data *sdata, 9287 struct cfg80211_bss *bss) 9288 { 9289 u8 cur_channel; 9290 bool ret; 9291 9292 cur_channel = ieee80211_frequency_to_channel(bss->channel->center_freq); 9293 9294 rcu_read_lock(); 9295 if (ieee80211_mgd_csa_present(sdata, 9296 rcu_dereference(bss->beacon_ies), 9297 cur_channel, false)) { 9298 ret = true; 9299 goto out; 9300 } 9301 9302 if (ieee80211_mgd_csa_present(sdata, 9303 rcu_dereference(bss->proberesp_ies), 9304 cur_channel, bss->proberesp_ecsa_stuck)) { 9305 ret = true; 9306 goto out; 9307 } 9308 9309 ret = false; 9310 out: 9311 rcu_read_unlock(); 9312 return ret; 9313 } 9314 9315 static void ieee80211_parse_cfg_selectors(unsigned long *userspace_selectors, 9316 const u8 *supported_selectors, 9317 u8 supported_selectors_len) 9318 { 9319 if (supported_selectors) { 9320 for (int i = 0; i < supported_selectors_len; i++) { 9321 set_bit(supported_selectors[i], 9322 userspace_selectors); 9323 } 9324 } else { 9325 /* Assume SAE_H2E support for backward compatibility. */ 9326 set_bit(BSS_MEMBERSHIP_SELECTOR_SAE_H2E, 9327 userspace_selectors); 9328 } 9329 } 9330 9331 /* config hooks */ 9332 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata, 9333 struct cfg80211_auth_request *req) 9334 { 9335 struct ieee80211_local *local = sdata->local; 9336 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 9337 struct ieee80211_mgd_auth_data *auth_data; 9338 struct ieee80211_conn_settings conn; 9339 struct ieee80211_link_data *link; 9340 struct ieee80211_supported_band *sband; 9341 struct ieee80211_bss *bss; 9342 u16 auth_alg; 9343 int err; 9344 bool cont_auth, wmm_used; 9345 9346 lockdep_assert_wiphy(sdata->local->hw.wiphy); 9347 9348 /* prepare auth data structure */ 9349 9350 switch (req->auth_type) { 9351 case NL80211_AUTHTYPE_OPEN_SYSTEM: 9352 auth_alg = WLAN_AUTH_OPEN; 9353 break; 9354 case NL80211_AUTHTYPE_SHARED_KEY: 9355 if (fips_enabled) 9356 return -EOPNOTSUPP; 9357 auth_alg = WLAN_AUTH_SHARED_KEY; 9358 break; 9359 case NL80211_AUTHTYPE_FT: 9360 auth_alg = WLAN_AUTH_FT; 9361 break; 9362 case NL80211_AUTHTYPE_NETWORK_EAP: 9363 auth_alg = WLAN_AUTH_LEAP; 9364 break; 9365 case NL80211_AUTHTYPE_SAE: 9366 auth_alg = WLAN_AUTH_SAE; 9367 break; 9368 case NL80211_AUTHTYPE_FILS_SK: 9369 auth_alg = WLAN_AUTH_FILS_SK; 9370 break; 9371 case NL80211_AUTHTYPE_FILS_SK_PFS: 9372 auth_alg = WLAN_AUTH_FILS_SK_PFS; 9373 break; 9374 case NL80211_AUTHTYPE_FILS_PK: 9375 auth_alg = WLAN_AUTH_FILS_PK; 9376 break; 9377 case NL80211_AUTHTYPE_EPPKE: 9378 auth_alg = WLAN_AUTH_EPPKE; 9379 break; 9380 default: 9381 return -EOPNOTSUPP; 9382 } 9383 9384 if (ifmgd->assoc_data) 9385 return -EBUSY; 9386 9387 if (ieee80211_mgd_csa_in_process(sdata, req->bss)) { 9388 sdata_info(sdata, "AP is in CSA process, reject auth\n"); 9389 return -EINVAL; 9390 } 9391 9392 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len + 9393 req->ie_len, GFP_KERNEL); 9394 if (!auth_data) 9395 return -ENOMEM; 9396 9397 memcpy(auth_data->ap_addr, 9398 req->ap_mld_addr ?: req->bss->bssid, 9399 ETH_ALEN); 9400 auth_data->bss = req->bss; 9401 auth_data->link_id = req->link_id; 9402 9403 if (req->auth_data_len >= 4) { 9404 if (req->auth_type == NL80211_AUTHTYPE_SAE || 9405 req->auth_type == NL80211_AUTHTYPE_EPPKE) { 9406 __le16 *pos = (__le16 *) req->auth_data; 9407 9408 auth_data->trans = le16_to_cpu(pos[0]); 9409 auth_data->status = le16_to_cpu(pos[1]); 9410 } 9411 9412 memcpy(auth_data->data, req->auth_data + 4, 9413 req->auth_data_len - 4); 9414 auth_data->data_len += req->auth_data_len - 4; 9415 } 9416 9417 /* Check if continuing authentication or trying to authenticate with the 9418 * same BSS that we were in the process of authenticating with and avoid 9419 * removal and re-addition of the STA entry in 9420 * ieee80211_prep_connection(). 9421 */ 9422 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss && 9423 ifmgd->auth_data->link_id == req->link_id; 9424 9425 if (req->ie && req->ie_len) { 9426 memcpy(&auth_data->data[auth_data->data_len], 9427 req->ie, req->ie_len); 9428 auth_data->data_len += req->ie_len; 9429 } 9430 9431 if (req->key && req->key_len) { 9432 auth_data->key_len = req->key_len; 9433 auth_data->key_idx = req->key_idx; 9434 memcpy(auth_data->key, req->key, req->key_len); 9435 } 9436 9437 ieee80211_parse_cfg_selectors(auth_data->userspace_selectors, 9438 req->supported_selectors, 9439 req->supported_selectors_len); 9440 9441 auth_data->algorithm = auth_alg; 9442 9443 /* try to authenticate/probe */ 9444 9445 if (ifmgd->auth_data) { 9446 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) { 9447 auth_data->peer_confirmed = 9448 ifmgd->auth_data->peer_confirmed; 9449 } 9450 ieee80211_destroy_auth_data(sdata, cont_auth); 9451 } 9452 9453 /* prep auth_data so we don't go into idle on disassoc */ 9454 ifmgd->auth_data = auth_data; 9455 9456 /* If this is continuation of an ongoing SAE authentication exchange 9457 * (i.e., request to send SAE Confirm) and the peer has already 9458 * confirmed, mark authentication completed since we are about to send 9459 * out SAE Confirm. 9460 */ 9461 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE && 9462 auth_data->peer_confirmed && auth_data->trans == 2) 9463 ieee80211_mark_sta_auth(sdata); 9464 9465 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_EPPKE && 9466 auth_data->trans == 3) 9467 ieee80211_mark_sta_auth(sdata); 9468 9469 if (ifmgd->associated) { 9470 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; 9471 9472 sdata_info(sdata, 9473 "disconnect from AP %pM for new auth to %pM\n", 9474 sdata->vif.cfg.ap_addr, auth_data->ap_addr); 9475 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, 9476 WLAN_REASON_UNSPECIFIED, 9477 false, frame_buf); 9478 9479 ieee80211_report_disconnect(sdata, frame_buf, 9480 sizeof(frame_buf), true, 9481 WLAN_REASON_UNSPECIFIED, 9482 false); 9483 } 9484 9485 /* needed for transmitting the auth frame(s) properly */ 9486 memcpy(sdata->vif.cfg.ap_addr, auth_data->ap_addr, ETH_ALEN); 9487 9488 bss = (void *)req->bss->priv; 9489 wmm_used = bss->wmm_used && (local->hw.queues >= IEEE80211_NUM_ACS); 9490 9491 sband = local->hw.wiphy->bands[req->bss->channel->band]; 9492 9493 ieee80211_determine_our_sta_mode_auth(sdata, sband, req, wmm_used, 9494 &conn); 9495 9496 err = ieee80211_prep_connection(sdata, req->bss, req->link_id, 9497 req->ap_mld_addr, cont_auth, 9498 &conn, false, 9499 auth_data->userspace_selectors); 9500 if (err) 9501 goto err_clear; 9502 9503 if (req->link_id >= 0) 9504 link = sdata_dereference(sdata->link[req->link_id], sdata); 9505 else 9506 link = &sdata->deflink; 9507 9508 if (WARN_ON(!link)) { 9509 err = -ENOLINK; 9510 goto err_clear; 9511 } 9512 9513 sdata_info(sdata, "authenticate with %pM (local address=%pM)\n", 9514 auth_data->ap_addr, link->conf->addr); 9515 9516 err = ieee80211_auth(sdata); 9517 if (err) { 9518 sta_info_destroy_addr(sdata, auth_data->ap_addr); 9519 goto err_clear; 9520 } 9521 9522 /* hold our own reference */ 9523 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss); 9524 return 0; 9525 9526 err_clear: 9527 if (!ieee80211_vif_is_mld(&sdata->vif)) { 9528 eth_zero_addr(sdata->deflink.u.mgd.bssid); 9529 ieee80211_link_info_change_notify(sdata, &sdata->deflink, 9530 BSS_CHANGED_BSSID); 9531 ieee80211_link_release_channel(&sdata->deflink); 9532 } 9533 ifmgd->auth_data = NULL; 9534 kfree(auth_data); 9535 return err; 9536 } 9537 9538 static void 9539 ieee80211_setup_assoc_link(struct ieee80211_sub_if_data *sdata, 9540 struct ieee80211_mgd_assoc_data *assoc_data, 9541 struct cfg80211_assoc_request *req, 9542 struct ieee80211_conn_settings *conn, 9543 unsigned int link_id) 9544 { 9545 struct ieee80211_local *local = sdata->local; 9546 const struct cfg80211_bss_ies *bss_ies; 9547 struct ieee80211_supported_band *sband; 9548 struct ieee80211_link_data *link; 9549 struct cfg80211_bss *cbss; 9550 struct ieee80211_bss *bss; 9551 9552 cbss = assoc_data->link[link_id].bss; 9553 if (WARN_ON(!cbss)) 9554 return; 9555 9556 bss = (void *)cbss->priv; 9557 9558 sband = local->hw.wiphy->bands[cbss->channel->band]; 9559 if (WARN_ON(!sband)) 9560 return; 9561 9562 link = sdata_dereference(sdata->link[link_id], sdata); 9563 if (WARN_ON(!link)) 9564 return; 9565 9566 /* for MLO connections assume advertising all rates is OK */ 9567 if (!req->ap_mld_addr) { 9568 assoc_data->supp_rates = bss->supp_rates; 9569 assoc_data->supp_rates_len = bss->supp_rates_len; 9570 } 9571 9572 /* copy and link elems for the STA profile */ 9573 if (req->links[link_id].elems_len) { 9574 memcpy(assoc_data->ie_pos, req->links[link_id].elems, 9575 req->links[link_id].elems_len); 9576 assoc_data->link[link_id].elems = assoc_data->ie_pos; 9577 assoc_data->link[link_id].elems_len = req->links[link_id].elems_len; 9578 assoc_data->ie_pos += req->links[link_id].elems_len; 9579 } 9580 9581 link->u.mgd.beacon_crc_valid = false; 9582 link->u.mgd.dtim_period = 0; 9583 link->u.mgd.have_beacon = false; 9584 9585 /* override HT configuration only if the AP and we support it */ 9586 if (conn->mode >= IEEE80211_CONN_MODE_HT) { 9587 struct ieee80211_sta_ht_cap sta_ht_cap; 9588 9589 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap)); 9590 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap); 9591 } 9592 9593 rcu_read_lock(); 9594 bss_ies = rcu_dereference(cbss->beacon_ies); 9595 if (bss_ies) { 9596 u8 dtim_count = 0; 9597 9598 ieee80211_get_dtim(bss_ies, &dtim_count, 9599 &link->u.mgd.dtim_period); 9600 9601 sdata->deflink.u.mgd.have_beacon = true; 9602 9603 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) { 9604 link->conf->sync_tsf = bss_ies->tsf; 9605 link->conf->sync_device_ts = bss->device_ts_beacon; 9606 link->conf->sync_dtim_count = dtim_count; 9607 } 9608 } else { 9609 bss_ies = rcu_dereference(cbss->ies); 9610 } 9611 9612 if (bss_ies) { 9613 const struct element *elem; 9614 9615 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION, 9616 bss_ies->data, bss_ies->len); 9617 if (elem && elem->datalen >= 3) 9618 link->conf->profile_periodicity = elem->data[2]; 9619 else 9620 link->conf->profile_periodicity = 0; 9621 9622 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, 9623 bss_ies->data, bss_ies->len); 9624 if (elem && elem->datalen >= 11 && 9625 (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT)) 9626 link->conf->ema_ap = true; 9627 else 9628 link->conf->ema_ap = false; 9629 } 9630 rcu_read_unlock(); 9631 9632 if (bss->corrupt_data) { 9633 char *corrupt_type = "data"; 9634 9635 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) { 9636 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP) 9637 corrupt_type = "beacon and probe response"; 9638 else 9639 corrupt_type = "beacon"; 9640 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP) { 9641 corrupt_type = "probe response"; 9642 } 9643 sdata_info(sdata, "associating to AP %pM with corrupt %s\n", 9644 cbss->bssid, corrupt_type); 9645 } 9646 9647 if (link->u.mgd.req_smps == IEEE80211_SMPS_AUTOMATIC) { 9648 if (sdata->u.mgd.powersave) 9649 link->smps_mode = IEEE80211_SMPS_DYNAMIC; 9650 else 9651 link->smps_mode = IEEE80211_SMPS_OFF; 9652 } else { 9653 link->smps_mode = link->u.mgd.req_smps; 9654 } 9655 } 9656 9657 static int 9658 ieee80211_mgd_get_ap_ht_vht_capa(struct ieee80211_sub_if_data *sdata, 9659 struct ieee80211_mgd_assoc_data *assoc_data, 9660 int link_id) 9661 { 9662 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss; 9663 enum nl80211_band band = cbss->channel->band; 9664 struct ieee80211_supported_band *sband; 9665 const struct element *elem; 9666 int err; 9667 9668 /* neither HT nor VHT elements used on 6 GHz */ 9669 if (band == NL80211_BAND_6GHZ) 9670 return 0; 9671 9672 if (assoc_data->link[link_id].conn.mode < IEEE80211_CONN_MODE_HT) 9673 return 0; 9674 9675 rcu_read_lock(); 9676 elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_OPERATION); 9677 if (!elem || elem->datalen < sizeof(struct ieee80211_ht_operation)) { 9678 mlme_link_id_dbg(sdata, link_id, "no HT operation on BSS %pM\n", 9679 cbss->bssid); 9680 err = -EINVAL; 9681 goto out_rcu; 9682 } 9683 assoc_data->link[link_id].ap_ht_param = 9684 ((struct ieee80211_ht_operation *)(elem->data))->ht_param; 9685 rcu_read_unlock(); 9686 9687 if (assoc_data->link[link_id].conn.mode < IEEE80211_CONN_MODE_VHT) 9688 return 0; 9689 9690 /* some drivers want to support VHT on 2.4 GHz even */ 9691 sband = sdata->local->hw.wiphy->bands[band]; 9692 if (!sband->vht_cap.vht_supported) 9693 return 0; 9694 9695 rcu_read_lock(); 9696 elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY); 9697 /* but even then accept it not being present on the AP */ 9698 if (!elem && band == NL80211_BAND_2GHZ) { 9699 err = 0; 9700 goto out_rcu; 9701 } 9702 if (!elem || elem->datalen < sizeof(struct ieee80211_vht_cap)) { 9703 mlme_link_id_dbg(sdata, link_id, "no VHT capa on BSS %pM\n", 9704 cbss->bssid); 9705 err = -EINVAL; 9706 goto out_rcu; 9707 } 9708 memcpy(&assoc_data->link[link_id].ap_vht_cap, elem->data, 9709 sizeof(struct ieee80211_vht_cap)); 9710 rcu_read_unlock(); 9711 9712 return 0; 9713 out_rcu: 9714 rcu_read_unlock(); 9715 return err; 9716 } 9717 9718 static bool 9719 ieee80211_mgd_assoc_bss_has_mld_ext_capa_ops(struct cfg80211_assoc_request *req) 9720 { 9721 const struct cfg80211_bss_ies *ies; 9722 struct cfg80211_bss *bss; 9723 const struct element *ml; 9724 9725 /* not an MLO connection if link_id < 0, so irrelevant */ 9726 if (req->link_id < 0) 9727 return false; 9728 9729 bss = req->links[req->link_id].bss; 9730 9731 guard(rcu)(); 9732 ies = rcu_dereference(bss->ies); 9733 for_each_element_extid(ml, WLAN_EID_EXT_EHT_MULTI_LINK, 9734 ies->data, ies->len) { 9735 const struct ieee80211_multi_link_elem *mle; 9736 9737 if (!ieee80211_mle_type_ok(ml->data + 1, 9738 IEEE80211_ML_CONTROL_TYPE_BASIC, 9739 ml->datalen - 1)) 9740 continue; 9741 9742 mle = (void *)(ml->data + 1); 9743 if (mle->control & cpu_to_le16(IEEE80211_MLC_BASIC_PRES_EXT_MLD_CAPA_OP)) 9744 return true; 9745 } 9746 9747 return false; 9748 9749 } 9750 9751 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, 9752 struct cfg80211_assoc_request *req) 9753 { 9754 unsigned int assoc_link_id = req->link_id < 0 ? 0 : req->link_id; 9755 struct ieee80211_local *local = sdata->local; 9756 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 9757 struct ieee80211_mgd_assoc_data *assoc_data; 9758 const struct element *ssid_elem; 9759 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg; 9760 struct ieee80211_link_data *link; 9761 struct cfg80211_bss *cbss; 9762 bool override, uapsd_supported; 9763 bool match_auth; 9764 int i, err; 9765 size_t size = sizeof(*assoc_data) + req->ie_len; 9766 9767 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) 9768 size += req->links[i].elems_len; 9769 9770 /* FIXME: no support for 4-addr MLO yet */ 9771 if (sdata->u.mgd.use_4addr && req->link_id >= 0) 9772 return -EOPNOTSUPP; 9773 9774 assoc_data = kzalloc(size, GFP_KERNEL); 9775 if (!assoc_data) 9776 return -ENOMEM; 9777 9778 cbss = req->link_id < 0 ? req->bss : req->links[req->link_id].bss; 9779 9780 if (ieee80211_mgd_csa_in_process(sdata, cbss)) { 9781 sdata_info(sdata, "AP is in CSA process, reject assoc\n"); 9782 err = -EINVAL; 9783 goto err_free; 9784 } 9785 9786 rcu_read_lock(); 9787 ssid_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID); 9788 if (!ssid_elem || ssid_elem->datalen > sizeof(assoc_data->ssid)) { 9789 rcu_read_unlock(); 9790 err = -EINVAL; 9791 goto err_free; 9792 } 9793 9794 memcpy(assoc_data->ssid, ssid_elem->data, ssid_elem->datalen); 9795 assoc_data->ssid_len = ssid_elem->datalen; 9796 rcu_read_unlock(); 9797 9798 if (req->ap_mld_addr) 9799 memcpy(assoc_data->ap_addr, req->ap_mld_addr, ETH_ALEN); 9800 else 9801 memcpy(assoc_data->ap_addr, cbss->bssid, ETH_ALEN); 9802 9803 /* 9804 * Many APs have broken parsing of the extended MLD capa/ops field, 9805 * dropping (re-)association request frames or replying with association 9806 * response with a failure status if it's present. 9807 * Set our value from the userspace request only in strict mode or if 9808 * the AP also had that field present. 9809 */ 9810 if (ieee80211_hw_check(&local->hw, STRICT) || 9811 ieee80211_mgd_assoc_bss_has_mld_ext_capa_ops(req)) 9812 assoc_data->ext_mld_capa_ops = 9813 cpu_to_le16(req->ext_mld_capa_ops); 9814 9815 if (ifmgd->associated) { 9816 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; 9817 9818 sdata_info(sdata, 9819 "disconnect from AP %pM for new assoc to %pM\n", 9820 sdata->vif.cfg.ap_addr, assoc_data->ap_addr); 9821 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, 9822 WLAN_REASON_UNSPECIFIED, 9823 false, frame_buf); 9824 9825 ieee80211_report_disconnect(sdata, frame_buf, 9826 sizeof(frame_buf), true, 9827 WLAN_REASON_UNSPECIFIED, 9828 false); 9829 } 9830 9831 memset(sdata->u.mgd.userspace_selectors, 0, 9832 sizeof(sdata->u.mgd.userspace_selectors)); 9833 ieee80211_parse_cfg_selectors(sdata->u.mgd.userspace_selectors, 9834 req->supported_selectors, 9835 req->supported_selectors_len); 9836 9837 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa)); 9838 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask, 9839 sizeof(ifmgd->ht_capa_mask)); 9840 9841 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa)); 9842 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask, 9843 sizeof(ifmgd->vht_capa_mask)); 9844 9845 memcpy(&ifmgd->s1g_capa, &req->s1g_capa, sizeof(ifmgd->s1g_capa)); 9846 memcpy(&ifmgd->s1g_capa_mask, &req->s1g_capa_mask, 9847 sizeof(ifmgd->s1g_capa_mask)); 9848 9849 /* keep some setup (AP STA, channel, ...) if matching */ 9850 match_auth = ifmgd->auth_data && 9851 ether_addr_equal(ifmgd->auth_data->ap_addr, 9852 assoc_data->ap_addr) && 9853 ifmgd->auth_data->link_id == req->link_id; 9854 9855 if (req->ap_mld_addr) { 9856 uapsd_supported = true; 9857 9858 if (req->flags & (ASSOC_REQ_DISABLE_HT | 9859 ASSOC_REQ_DISABLE_VHT | 9860 ASSOC_REQ_DISABLE_HE | 9861 ASSOC_REQ_DISABLE_EHT)) { 9862 err = -EINVAL; 9863 goto err_free; 9864 } 9865 9866 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) { 9867 struct ieee80211_supported_band *sband; 9868 struct cfg80211_bss *link_cbss = req->links[i].bss; 9869 struct ieee80211_bss *bss; 9870 9871 if (!link_cbss) 9872 continue; 9873 9874 bss = (void *)link_cbss->priv; 9875 9876 if (!bss->wmm_used) { 9877 err = -EINVAL; 9878 req->links[i].error = err; 9879 goto err_free; 9880 } 9881 9882 if (link_cbss->channel->band == NL80211_BAND_S1GHZ) { 9883 err = -EINVAL; 9884 req->links[i].error = err; 9885 goto err_free; 9886 } 9887 9888 link = sdata_dereference(sdata->link[i], sdata); 9889 if (link) 9890 ether_addr_copy(assoc_data->link[i].addr, 9891 link->conf->addr); 9892 else 9893 eth_random_addr(assoc_data->link[i].addr); 9894 sband = local->hw.wiphy->bands[link_cbss->channel->band]; 9895 9896 if (match_auth && i == assoc_link_id && link) 9897 assoc_data->link[i].conn = link->u.mgd.conn; 9898 else 9899 assoc_data->link[i].conn = 9900 ieee80211_conn_settings_unlimited; 9901 ieee80211_determine_our_sta_mode_assoc(sdata, sband, 9902 req, true, i, 9903 &assoc_data->link[i].conn); 9904 assoc_data->link[i].bss = link_cbss; 9905 9906 if (!bss->uapsd_supported) 9907 uapsd_supported = false; 9908 9909 if (assoc_data->link[i].conn.mode < IEEE80211_CONN_MODE_EHT) { 9910 err = -EINVAL; 9911 req->links[i].error = err; 9912 goto err_free; 9913 } 9914 9915 err = ieee80211_mgd_get_ap_ht_vht_capa(sdata, 9916 assoc_data, i); 9917 if (err) { 9918 err = -EINVAL; 9919 req->links[i].error = err; 9920 goto err_free; 9921 } 9922 } 9923 9924 assoc_data->wmm = true; 9925 } else { 9926 struct ieee80211_supported_band *sband; 9927 struct ieee80211_bss *bss = (void *)cbss->priv; 9928 9929 memcpy(assoc_data->link[0].addr, sdata->vif.addr, ETH_ALEN); 9930 assoc_data->s1g = cbss->channel->band == NL80211_BAND_S1GHZ; 9931 9932 assoc_data->wmm = bss->wmm_used && 9933 (local->hw.queues >= IEEE80211_NUM_ACS); 9934 9935 if (cbss->channel->band == NL80211_BAND_6GHZ && 9936 req->flags & (ASSOC_REQ_DISABLE_HT | 9937 ASSOC_REQ_DISABLE_VHT | 9938 ASSOC_REQ_DISABLE_HE)) { 9939 err = -EINVAL; 9940 goto err_free; 9941 } 9942 9943 sband = local->hw.wiphy->bands[cbss->channel->band]; 9944 9945 assoc_data->link[0].bss = cbss; 9946 9947 if (match_auth) 9948 assoc_data->link[0].conn = sdata->deflink.u.mgd.conn; 9949 else 9950 assoc_data->link[0].conn = 9951 ieee80211_conn_settings_unlimited; 9952 ieee80211_determine_our_sta_mode_assoc(sdata, sband, req, 9953 assoc_data->wmm, 0, 9954 &assoc_data->link[0].conn); 9955 9956 uapsd_supported = bss->uapsd_supported; 9957 9958 err = ieee80211_mgd_get_ap_ht_vht_capa(sdata, assoc_data, 0); 9959 if (err) 9960 goto err_free; 9961 } 9962 9963 assoc_data->spp_amsdu = req->flags & ASSOC_REQ_SPP_AMSDU; 9964 9965 if (ifmgd->auth_data && !ifmgd->auth_data->done) { 9966 err = -EBUSY; 9967 goto err_free; 9968 } 9969 9970 if (ifmgd->assoc_data) { 9971 err = -EBUSY; 9972 goto err_free; 9973 } 9974 9975 /* Cleanup is delayed if auth_data matches */ 9976 if (ifmgd->auth_data && !match_auth) 9977 ieee80211_destroy_auth_data(sdata, false); 9978 9979 if (req->ie && req->ie_len) { 9980 memcpy(assoc_data->ie, req->ie, req->ie_len); 9981 assoc_data->ie_len = req->ie_len; 9982 assoc_data->ie_pos = assoc_data->ie + assoc_data->ie_len; 9983 } else { 9984 assoc_data->ie_pos = assoc_data->ie; 9985 } 9986 9987 if (req->fils_kek) { 9988 /* should already be checked in cfg80211 - so warn */ 9989 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) { 9990 err = -EINVAL; 9991 goto err_free; 9992 } 9993 memcpy(assoc_data->fils_kek, req->fils_kek, 9994 req->fils_kek_len); 9995 assoc_data->fils_kek_len = req->fils_kek_len; 9996 } 9997 9998 if (req->fils_nonces) 9999 memcpy(assoc_data->fils_nonces, req->fils_nonces, 10000 2 * FILS_NONCE_LEN); 10001 10002 /* default timeout */ 10003 assoc_data->timeout = jiffies; 10004 assoc_data->timeout_started = true; 10005 10006 assoc_data->assoc_link_id = assoc_link_id; 10007 10008 if (req->ap_mld_addr) { 10009 /* if there was no authentication, set up the link */ 10010 err = ieee80211_vif_set_links(sdata, BIT(assoc_link_id), 0); 10011 if (err) 10012 goto err_clear; 10013 } 10014 10015 link = sdata_dereference(sdata->link[assoc_link_id], sdata); 10016 if (WARN_ON(!link)) { 10017 err = -EINVAL; 10018 goto err_clear; 10019 } 10020 10021 override = link->u.mgd.conn.mode != 10022 assoc_data->link[assoc_link_id].conn.mode || 10023 link->u.mgd.conn.bw_limit != 10024 assoc_data->link[assoc_link_id].conn.bw_limit; 10025 link->u.mgd.conn = assoc_data->link[assoc_link_id].conn; 10026 10027 ieee80211_setup_assoc_link(sdata, assoc_data, req, &link->u.mgd.conn, 10028 assoc_link_id); 10029 10030 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) && 10031 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK), 10032 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n")) 10033 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 10034 10035 if (assoc_data->wmm && uapsd_supported && 10036 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) { 10037 assoc_data->uapsd = true; 10038 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED; 10039 } else { 10040 assoc_data->uapsd = false; 10041 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED; 10042 } 10043 10044 if (req->prev_bssid) 10045 memcpy(assoc_data->prev_ap_addr, req->prev_bssid, ETH_ALEN); 10046 10047 if (req->use_mfp) { 10048 ifmgd->mfp = IEEE80211_MFP_REQUIRED; 10049 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED; 10050 } else { 10051 ifmgd->mfp = IEEE80211_MFP_DISABLED; 10052 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED; 10053 } 10054 10055 if (req->flags & ASSOC_REQ_USE_RRM) 10056 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM; 10057 else 10058 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM; 10059 10060 if (req->crypto.control_port) 10061 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT; 10062 else 10063 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT; 10064 10065 sdata->control_port_protocol = req->crypto.control_port_ethertype; 10066 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt; 10067 sdata->control_port_over_nl80211 = 10068 req->crypto.control_port_over_nl80211; 10069 sdata->control_port_no_preauth = req->crypto.control_port_no_preauth; 10070 10071 /* kick off associate process */ 10072 ifmgd->assoc_data = assoc_data; 10073 10074 for (i = 0; i < ARRAY_SIZE(assoc_data->link); i++) { 10075 if (!assoc_data->link[i].bss) 10076 continue; 10077 if (i == assoc_data->assoc_link_id) 10078 continue; 10079 /* only calculate the mode, hence link == NULL */ 10080 err = ieee80211_prep_channel(sdata, NULL, i, 10081 assoc_data->link[i].bss, true, 10082 &assoc_data->link[i].conn, 10083 sdata->u.mgd.userspace_selectors); 10084 if (err) { 10085 req->links[i].error = err; 10086 goto err_clear; 10087 } 10088 } 10089 10090 memcpy(vif_cfg->ssid, assoc_data->ssid, assoc_data->ssid_len); 10091 vif_cfg->ssid_len = assoc_data->ssid_len; 10092 10093 /* needed for transmitting the assoc frames properly */ 10094 memcpy(sdata->vif.cfg.ap_addr, assoc_data->ap_addr, ETH_ALEN); 10095 10096 err = ieee80211_prep_connection(sdata, cbss, req->link_id, 10097 req->ap_mld_addr, true, 10098 &assoc_data->link[assoc_link_id].conn, 10099 override, 10100 sdata->u.mgd.userspace_selectors); 10101 if (err) 10102 goto err_clear; 10103 10104 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC)) { 10105 const struct cfg80211_bss_ies *beacon_ies; 10106 10107 rcu_read_lock(); 10108 beacon_ies = rcu_dereference(req->bss->beacon_ies); 10109 if (!beacon_ies) { 10110 /* 10111 * Wait up to one beacon interval ... 10112 * should this be more if we miss one? 10113 */ 10114 sdata_info(sdata, "waiting for beacon from %pM\n", 10115 link->u.mgd.bssid); 10116 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval); 10117 assoc_data->timeout_started = true; 10118 assoc_data->need_beacon = true; 10119 } 10120 rcu_read_unlock(); 10121 } 10122 10123 run_again(sdata, assoc_data->timeout); 10124 10125 /* We are associating, clean up auth_data */ 10126 if (ifmgd->auth_data) 10127 ieee80211_destroy_auth_data(sdata, true); 10128 10129 return 0; 10130 err_clear: 10131 if (!ifmgd->auth_data) { 10132 eth_zero_addr(sdata->deflink.u.mgd.bssid); 10133 ieee80211_link_info_change_notify(sdata, &sdata->deflink, 10134 BSS_CHANGED_BSSID); 10135 } 10136 ifmgd->assoc_data = NULL; 10137 err_free: 10138 kfree(assoc_data); 10139 return err; 10140 } 10141 10142 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata, 10143 struct cfg80211_deauth_request *req) 10144 { 10145 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 10146 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; 10147 bool tx = !req->local_state_change; 10148 struct ieee80211_prep_tx_info info = { 10149 .subtype = IEEE80211_STYPE_DEAUTH, 10150 }; 10151 10152 if (ifmgd->auth_data && 10153 ether_addr_equal(ifmgd->auth_data->ap_addr, req->bssid)) { 10154 sdata_info(sdata, 10155 "aborting authentication with %pM by local choice (Reason: %u=%s)\n", 10156 req->bssid, req->reason_code, 10157 ieee80211_get_reason_code_string(req->reason_code)); 10158 10159 info.link_id = ifmgd->auth_data->link_id; 10160 drv_mgd_prepare_tx(sdata->local, sdata, &info); 10161 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid, 10162 IEEE80211_STYPE_DEAUTH, 10163 req->reason_code, tx, 10164 frame_buf); 10165 ieee80211_destroy_auth_data(sdata, false); 10166 ieee80211_report_disconnect(sdata, frame_buf, 10167 sizeof(frame_buf), true, 10168 req->reason_code, false); 10169 drv_mgd_complete_tx(sdata->local, sdata, &info); 10170 return 0; 10171 } 10172 10173 if (ifmgd->assoc_data && 10174 ether_addr_equal(ifmgd->assoc_data->ap_addr, req->bssid)) { 10175 sdata_info(sdata, 10176 "aborting association with %pM by local choice (Reason: %u=%s)\n", 10177 req->bssid, req->reason_code, 10178 ieee80211_get_reason_code_string(req->reason_code)); 10179 10180 info.link_id = ifmgd->assoc_data->assoc_link_id; 10181 drv_mgd_prepare_tx(sdata->local, sdata, &info); 10182 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid, 10183 IEEE80211_STYPE_DEAUTH, 10184 req->reason_code, tx, 10185 frame_buf); 10186 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON); 10187 ieee80211_report_disconnect(sdata, frame_buf, 10188 sizeof(frame_buf), true, 10189 req->reason_code, false); 10190 drv_mgd_complete_tx(sdata->local, sdata, &info); 10191 return 0; 10192 } 10193 10194 if (ifmgd->associated && 10195 ether_addr_equal(sdata->vif.cfg.ap_addr, req->bssid)) { 10196 sdata_info(sdata, 10197 "deauthenticating from %pM by local choice (Reason: %u=%s)\n", 10198 req->bssid, req->reason_code, 10199 ieee80211_get_reason_code_string(req->reason_code)); 10200 10201 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, 10202 req->reason_code, tx, frame_buf); 10203 ieee80211_report_disconnect(sdata, frame_buf, 10204 sizeof(frame_buf), true, 10205 req->reason_code, false); 10206 return 0; 10207 } 10208 10209 return -ENOTCONN; 10210 } 10211 10212 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata, 10213 struct cfg80211_disassoc_request *req) 10214 { 10215 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; 10216 10217 if (!sdata->u.mgd.associated || 10218 memcmp(sdata->vif.cfg.ap_addr, req->ap_addr, ETH_ALEN)) 10219 return -ENOTCONN; 10220 10221 sdata_info(sdata, 10222 "disassociating from %pM by local choice (Reason: %u=%s)\n", 10223 req->ap_addr, req->reason_code, 10224 ieee80211_get_reason_code_string(req->reason_code)); 10225 10226 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC, 10227 req->reason_code, !req->local_state_change, 10228 frame_buf); 10229 10230 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true, 10231 req->reason_code, false); 10232 10233 return 0; 10234 } 10235 10236 void ieee80211_mgd_stop_link(struct ieee80211_link_data *link) 10237 { 10238 wiphy_work_cancel(link->sdata->local->hw.wiphy, 10239 &link->u.mgd.request_smps_work); 10240 wiphy_work_cancel(link->sdata->local->hw.wiphy, 10241 &link->u.mgd.recalc_smps); 10242 wiphy_hrtimer_work_cancel(link->sdata->local->hw.wiphy, 10243 &link->u.mgd.csa.switch_work); 10244 } 10245 10246 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata) 10247 { 10248 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 10249 10250 /* 10251 * Make sure some work items will not run after this, 10252 * they will not do anything but might not have been 10253 * cancelled when disconnecting. 10254 */ 10255 wiphy_work_cancel(sdata->local->hw.wiphy, 10256 &ifmgd->monitor_work); 10257 wiphy_work_cancel(sdata->local->hw.wiphy, 10258 &ifmgd->beacon_connection_loss_work); 10259 wiphy_work_cancel(sdata->local->hw.wiphy, 10260 &ifmgd->csa_connection_drop_work); 10261 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, 10262 &ifmgd->tdls_peer_del_work); 10263 10264 if (ifmgd->assoc_data) 10265 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT); 10266 if (ifmgd->auth_data) 10267 ieee80211_destroy_auth_data(sdata, false); 10268 spin_lock_bh(&ifmgd->teardown_lock); 10269 if (ifmgd->teardown_skb) { 10270 kfree_skb(ifmgd->teardown_skb); 10271 ifmgd->teardown_skb = NULL; 10272 ifmgd->orig_teardown_skb = NULL; 10273 } 10274 kfree(ifmgd->assoc_req_ies); 10275 ifmgd->assoc_req_ies = NULL; 10276 ifmgd->assoc_req_ies_len = 0; 10277 spin_unlock_bh(&ifmgd->teardown_lock); 10278 timer_delete_sync(&ifmgd->timer); 10279 } 10280 10281 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif, 10282 enum nl80211_cqm_rssi_threshold_event rssi_event, 10283 s32 rssi_level, 10284 gfp_t gfp) 10285 { 10286 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 10287 10288 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level); 10289 10290 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp); 10291 } 10292 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify); 10293 10294 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp) 10295 { 10296 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 10297 10298 trace_api_cqm_beacon_loss_notify(sdata->local, sdata); 10299 10300 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp); 10301 } 10302 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify); 10303 10304 static void _ieee80211_enable_rssi_reports(struct ieee80211_sub_if_data *sdata, 10305 int rssi_min_thold, 10306 int rssi_max_thold) 10307 { 10308 trace_api_enable_rssi_reports(sdata, rssi_min_thold, rssi_max_thold); 10309 10310 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) 10311 return; 10312 10313 /* 10314 * Scale up threshold values before storing it, as the RSSI averaging 10315 * algorithm uses a scaled up value as well. Change this scaling 10316 * factor if the RSSI averaging algorithm changes. 10317 */ 10318 sdata->u.mgd.rssi_min_thold = rssi_min_thold*16; 10319 sdata->u.mgd.rssi_max_thold = rssi_max_thold*16; 10320 } 10321 10322 void ieee80211_enable_rssi_reports(struct ieee80211_vif *vif, 10323 int rssi_min_thold, 10324 int rssi_max_thold) 10325 { 10326 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 10327 10328 WARN_ON(rssi_min_thold == rssi_max_thold || 10329 rssi_min_thold > rssi_max_thold); 10330 10331 _ieee80211_enable_rssi_reports(sdata, rssi_min_thold, 10332 rssi_max_thold); 10333 } 10334 EXPORT_SYMBOL(ieee80211_enable_rssi_reports); 10335 10336 void ieee80211_disable_rssi_reports(struct ieee80211_vif *vif) 10337 { 10338 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 10339 10340 _ieee80211_enable_rssi_reports(sdata, 0, 0); 10341 } 10342 EXPORT_SYMBOL(ieee80211_disable_rssi_reports); 10343 10344 void ieee80211_process_ml_reconf_resp(struct ieee80211_sub_if_data *sdata, 10345 struct ieee80211_mgmt *mgmt, size_t len) 10346 { 10347 struct ieee80211_local *local = sdata->local; 10348 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 10349 struct ieee80211_mgd_assoc_data *add_links_data = 10350 ifmgd->reconf.add_links_data; 10351 struct sta_info *sta; 10352 struct cfg80211_mlo_reconf_done_data done_data = {}; 10353 u16 sta_changed_links = sdata->u.mgd.reconf.added_links | 10354 sdata->u.mgd.reconf.removed_links; 10355 u16 link_mask, valid_links; 10356 unsigned int link_id; 10357 size_t orig_len = len; 10358 u8 i, group_key_data_len; 10359 u8 *pos; 10360 10361 if (!ieee80211_vif_is_mld(&sdata->vif) || 10362 len < offsetofend(typeof(*mgmt), u.action.u.ml_reconf_resp) || 10363 mgmt->u.action.u.ml_reconf_resp.dialog_token != 10364 sdata->u.mgd.reconf.dialog_token || 10365 !sta_changed_links) 10366 return; 10367 10368 pos = mgmt->u.action.u.ml_reconf_resp.variable; 10369 len -= offsetofend(typeof(*mgmt), u.action.u.ml_reconf_resp); 10370 10371 /* each status duple is 3 octets */ 10372 if (len < mgmt->u.action.u.ml_reconf_resp.count * 3) { 10373 sdata_info(sdata, 10374 "mlo: reconf: unexpected len=%zu, count=%u\n", 10375 len, mgmt->u.action.u.ml_reconf_resp.count); 10376 goto disconnect; 10377 } 10378 10379 link_mask = sta_changed_links; 10380 for (i = 0; i < mgmt->u.action.u.ml_reconf_resp.count; i++) { 10381 u16 status = get_unaligned_le16(pos + 1); 10382 10383 link_id = *pos; 10384 10385 if (!(link_mask & BIT(link_id))) { 10386 sdata_info(sdata, 10387 "mlo: reconf: unexpected link: %u, changed=0x%x\n", 10388 link_id, sta_changed_links); 10389 goto disconnect; 10390 } 10391 10392 /* clear the corresponding link, to detect the case that 10393 * the same link was included more than one time 10394 */ 10395 link_mask &= ~BIT(link_id); 10396 10397 /* Handle failure to remove links here. Failure to remove added 10398 * links will be done later in the flow. 10399 */ 10400 if (status != WLAN_STATUS_SUCCESS) { 10401 sdata_info(sdata, 10402 "mlo: reconf: failed on link=%u, status=%u\n", 10403 link_id, status); 10404 10405 /* The AP MLD failed to remove a link that was already 10406 * removed locally. As this is not expected behavior, 10407 * disconnect 10408 */ 10409 if (sdata->u.mgd.reconf.removed_links & BIT(link_id)) 10410 goto disconnect; 10411 10412 /* The AP MLD failed to add a link. Remove it from the 10413 * added links. 10414 */ 10415 sdata->u.mgd.reconf.added_links &= ~BIT(link_id); 10416 } 10417 10418 pos += 3; 10419 len -= 3; 10420 } 10421 10422 if (link_mask) { 10423 sdata_info(sdata, 10424 "mlo: reconf: no response for links=0x%x\n", 10425 link_mask); 10426 goto disconnect; 10427 } 10428 10429 if (!sdata->u.mgd.reconf.added_links) 10430 goto out; 10431 10432 if (len < 1 || len < 1 + *pos) { 10433 sdata_info(sdata, 10434 "mlo: reconf: invalid group key data length"); 10435 goto disconnect; 10436 } 10437 10438 /* The Group Key Data field must be present when links are added. This 10439 * field should be processed by userland. 10440 */ 10441 group_key_data_len = *pos++; 10442 10443 pos += group_key_data_len; 10444 len -= group_key_data_len + 1; 10445 10446 /* Process the information for the added links */ 10447 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr); 10448 if (WARN_ON(!sta)) 10449 goto disconnect; 10450 10451 valid_links = sdata->vif.valid_links; 10452 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { 10453 if (!add_links_data->link[link_id].bss || 10454 !(sdata->u.mgd.reconf.added_links & BIT(link_id))) 10455 continue; 10456 10457 valid_links |= BIT(link_id); 10458 if (ieee80211_sta_allocate_link(sta, link_id)) 10459 goto disconnect; 10460 } 10461 10462 ieee80211_vif_set_links(sdata, valid_links, sdata->vif.dormant_links); 10463 link_mask = 0; 10464 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { 10465 struct cfg80211_bss *cbss = add_links_data->link[link_id].bss; 10466 struct ieee80211_link_data *link; 10467 struct link_sta_info *link_sta; 10468 u64 changed = 0; 10469 10470 if (!cbss) 10471 continue; 10472 10473 link = sdata_dereference(sdata->link[link_id], sdata); 10474 if (WARN_ON(!link)) 10475 goto disconnect; 10476 10477 link_info(link, 10478 "mlo: reconf: local address %pM, AP link address %pM\n", 10479 add_links_data->link[link_id].addr, 10480 add_links_data->link[link_id].bss->bssid); 10481 10482 link_sta = rcu_dereference_protected(sta->link[link_id], 10483 lockdep_is_held(&local->hw.wiphy->mtx)); 10484 if (WARN_ON(!link_sta)) 10485 goto disconnect; 10486 10487 if (!link->u.mgd.have_beacon) { 10488 const struct cfg80211_bss_ies *ies; 10489 10490 rcu_read_lock(); 10491 ies = rcu_dereference(cbss->beacon_ies); 10492 if (ies) 10493 link->u.mgd.have_beacon = true; 10494 else 10495 ies = rcu_dereference(cbss->ies); 10496 ieee80211_get_dtim(ies, 10497 &link->conf->sync_dtim_count, 10498 &link->u.mgd.dtim_period); 10499 link->conf->beacon_int = cbss->beacon_interval; 10500 rcu_read_unlock(); 10501 } 10502 10503 link->conf->dtim_period = link->u.mgd.dtim_period ?: 1; 10504 10505 link->u.mgd.conn = add_links_data->link[link_id].conn; 10506 if (ieee80211_prep_channel(sdata, link, link_id, cbss, 10507 true, &link->u.mgd.conn, 10508 sdata->u.mgd.userspace_selectors)) { 10509 link_info(link, "mlo: reconf: prep_channel failed\n"); 10510 goto disconnect; 10511 } 10512 10513 if (ieee80211_mgd_setup_link_sta(link, sta, link_sta, 10514 add_links_data->link[link_id].bss)) 10515 goto disconnect; 10516 10517 if (!ieee80211_assoc_config_link(link, link_sta, 10518 add_links_data->link[link_id].bss, 10519 mgmt, pos, len, 10520 &changed)) 10521 goto disconnect; 10522 10523 /* The AP MLD indicated success for this link, but the station 10524 * profile status indicated otherwise. Since there is an 10525 * inconsistency in the ML reconfiguration response, disconnect 10526 */ 10527 if (add_links_data->link[link_id].status != WLAN_STATUS_SUCCESS) 10528 goto disconnect; 10529 10530 ieee80211_sta_init_nss(link_sta); 10531 if (ieee80211_sta_activate_link(sta, link_id)) 10532 goto disconnect; 10533 10534 changed |= ieee80211_link_set_associated(link, cbss); 10535 ieee80211_link_info_change_notify(sdata, link, changed); 10536 10537 ieee80211_recalc_smps(sdata, link); 10538 link_mask |= BIT(link_id); 10539 } 10540 10541 sdata_info(sdata, 10542 "mlo: reconf: current valid_links=0x%x, added=0x%x\n", 10543 valid_links, link_mask); 10544 10545 /* links might have changed due to rejected ones, set them again */ 10546 ieee80211_vif_set_links(sdata, valid_links, sdata->vif.dormant_links); 10547 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_MLD_VALID_LINKS); 10548 10549 ieee80211_recalc_ps(local); 10550 ieee80211_recalc_ps_vif(sdata); 10551 10552 done_data.buf = (const u8 *)mgmt; 10553 done_data.len = orig_len; 10554 done_data.added_links = link_mask; 10555 10556 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { 10557 done_data.links[link_id].bss = add_links_data->link[link_id].bss; 10558 done_data.links[link_id].addr = 10559 add_links_data->link[link_id].addr; 10560 } 10561 10562 cfg80211_mlo_reconf_add_done(sdata->dev, &done_data); 10563 kfree(sdata->u.mgd.reconf.add_links_data); 10564 sdata->u.mgd.reconf.add_links_data = NULL; 10565 out: 10566 ieee80211_ml_reconf_reset(sdata); 10567 return; 10568 10569 disconnect: 10570 __ieee80211_disconnect(sdata); 10571 } 10572 10573 static struct sk_buff * 10574 ieee80211_build_ml_reconf_req(struct ieee80211_sub_if_data *sdata, 10575 struct ieee80211_mgd_assoc_data *add_links_data, 10576 u16 removed_links, __le16 ext_mld_capa_ops) 10577 { 10578 struct ieee80211_local *local = sdata->local; 10579 struct ieee80211_mgmt *mgmt; 10580 struct ieee80211_multi_link_elem *ml_elem; 10581 struct ieee80211_mle_basic_common_info *common; 10582 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif); 10583 struct sk_buff *skb; 10584 size_t size; 10585 unsigned int link_id; 10586 __le16 eml_capa = 0, mld_capa_ops = 0; 10587 struct ieee80211_tx_info *info; 10588 u8 common_size, var_common_size; 10589 u8 *ml_elem_len; 10590 u16 capab = 0; 10591 10592 size = local->hw.extra_tx_headroom + sizeof(*mgmt); 10593 10594 /* Consider the maximal length of the reconfiguration ML element */ 10595 size += sizeof(struct ieee80211_multi_link_elem); 10596 10597 /* The Basic ML element and the Reconfiguration ML element have the same 10598 * fixed common information fields in the context of ML reconfiguration 10599 * action frame. The AP MLD MAC address must always be present 10600 */ 10601 common_size = sizeof(*common); 10602 10603 /* when adding links, the MLD capabilities must be present */ 10604 var_common_size = 0; 10605 if (add_links_data) { 10606 const struct wiphy_iftype_ext_capab *ift_ext_capa = 10607 cfg80211_get_iftype_ext_capa(local->hw.wiphy, 10608 ieee80211_vif_type_p2p(&sdata->vif)); 10609 10610 if (ift_ext_capa) { 10611 eml_capa = cpu_to_le16(ift_ext_capa->eml_capabilities); 10612 mld_capa_ops = 10613 cpu_to_le16(ift_ext_capa->mld_capa_and_ops); 10614 } 10615 10616 /* MLD capabilities and operation */ 10617 var_common_size += 2; 10618 10619 /* EML capabilities */ 10620 if (eml_capa & cpu_to_le16((IEEE80211_EML_CAP_EMLSR_SUPP | 10621 IEEE80211_EML_CAP_EMLMR_SUPPORT))) 10622 var_common_size += 2; 10623 } 10624 10625 if (ext_mld_capa_ops) 10626 var_common_size += 2; 10627 10628 /* Add the common information length */ 10629 size += common_size + var_common_size; 10630 10631 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { 10632 struct cfg80211_bss *cbss; 10633 size_t elems_len; 10634 10635 if (removed_links & BIT(link_id)) { 10636 size += sizeof(struct ieee80211_mle_per_sta_profile) + 10637 ETH_ALEN; 10638 continue; 10639 } 10640 10641 if (!add_links_data || !add_links_data->link[link_id].bss) 10642 continue; 10643 10644 elems_len = add_links_data->link[link_id].elems_len; 10645 cbss = add_links_data->link[link_id].bss; 10646 10647 /* should be the same across all BSSes */ 10648 if (cbss->capability & WLAN_CAPABILITY_PRIVACY) 10649 capab |= WLAN_CAPABILITY_PRIVACY; 10650 10651 size += 2 + sizeof(struct ieee80211_mle_per_sta_profile) + 10652 ETH_ALEN; 10653 10654 /* WMM */ 10655 size += 9; 10656 size += ieee80211_link_common_elems_size(sdata, iftype, cbss, 10657 elems_len); 10658 } 10659 10660 skb = alloc_skb(size, GFP_KERNEL); 10661 if (!skb) 10662 return NULL; 10663 10664 skb_reserve(skb, local->hw.extra_tx_headroom); 10665 mgmt = skb_put_zero(skb, offsetofend(struct ieee80211_mgmt, 10666 u.action.u.ml_reconf_req)); 10667 10668 /* Add the MAC header */ 10669 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 10670 IEEE80211_STYPE_ACTION); 10671 memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN); 10672 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); 10673 memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN); 10674 10675 /* Add the action frame fixed fields */ 10676 mgmt->u.action.category = WLAN_CATEGORY_PROTECTED_EHT; 10677 mgmt->u.action.u.ml_reconf_req.action_code = 10678 WLAN_PROTECTED_EHT_ACTION_LINK_RECONFIG_REQ; 10679 10680 /* allocate a dialog token and store it */ 10681 sdata->u.mgd.reconf.dialog_token = ++sdata->u.mgd.dialog_token_alloc; 10682 mgmt->u.action.u.ml_reconf_req.dialog_token = 10683 sdata->u.mgd.reconf.dialog_token; 10684 10685 /* Add the ML reconfiguration element and the common information */ 10686 skb_put_u8(skb, WLAN_EID_EXTENSION); 10687 ml_elem_len = skb_put(skb, 1); 10688 skb_put_u8(skb, WLAN_EID_EXT_EHT_MULTI_LINK); 10689 ml_elem = skb_put(skb, sizeof(*ml_elem)); 10690 ml_elem->control = 10691 cpu_to_le16(IEEE80211_ML_CONTROL_TYPE_RECONF | 10692 IEEE80211_MLC_RECONF_PRES_MLD_MAC_ADDR); 10693 common = skb_put(skb, common_size); 10694 common->len = common_size + var_common_size; 10695 memcpy(common->mld_mac_addr, sdata->vif.addr, ETH_ALEN); 10696 10697 if (add_links_data) { 10698 if (eml_capa & 10699 cpu_to_le16((IEEE80211_EML_CAP_EMLSR_SUPP | 10700 IEEE80211_EML_CAP_EMLMR_SUPPORT))) { 10701 ml_elem->control |= 10702 cpu_to_le16(IEEE80211_MLC_RECONF_PRES_EML_CAPA); 10703 skb_put_data(skb, &eml_capa, sizeof(eml_capa)); 10704 } 10705 10706 ml_elem->control |= 10707 cpu_to_le16(IEEE80211_MLC_RECONF_PRES_MLD_CAPA_OP); 10708 10709 skb_put_data(skb, &mld_capa_ops, sizeof(mld_capa_ops)); 10710 } 10711 10712 if (ext_mld_capa_ops) { 10713 ml_elem->control |= 10714 cpu_to_le16(IEEE80211_MLC_RECONF_PRES_EXT_MLD_CAPA_OP); 10715 skb_put_data(skb, &ext_mld_capa_ops, sizeof(ext_mld_capa_ops)); 10716 } 10717 10718 if (sdata->u.mgd.flags & IEEE80211_STA_ENABLE_RRM) 10719 capab |= WLAN_CAPABILITY_RADIO_MEASURE; 10720 10721 /* Add the per station profile */ 10722 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { 10723 u8 *subelem_len = NULL; 10724 u16 ctrl; 10725 const u8 *addr; 10726 10727 /* Skip links that are not changing */ 10728 if (!(removed_links & BIT(link_id)) && 10729 (!add_links_data || !add_links_data->link[link_id].bss)) 10730 continue; 10731 10732 ctrl = link_id | 10733 IEEE80211_MLE_STA_RECONF_CONTROL_STA_MAC_ADDR_PRESENT; 10734 10735 if (removed_links & BIT(link_id)) { 10736 struct ieee80211_bss_conf *conf = 10737 sdata_dereference(sdata->vif.link_conf[link_id], 10738 sdata); 10739 if (!conf) 10740 continue; 10741 10742 addr = conf->addr; 10743 ctrl |= u16_encode_bits(IEEE80211_MLE_STA_RECONF_CONTROL_OPERATION_TYPE_DEL_LINK, 10744 IEEE80211_MLE_STA_RECONF_CONTROL_OPERATION_TYPE); 10745 } else { 10746 addr = add_links_data->link[link_id].addr; 10747 ctrl |= IEEE80211_MLE_STA_RECONF_CONTROL_COMPLETE_PROFILE | 10748 u16_encode_bits(IEEE80211_MLE_STA_RECONF_CONTROL_OPERATION_TYPE_ADD_LINK, 10749 IEEE80211_MLE_STA_RECONF_CONTROL_OPERATION_TYPE); 10750 } 10751 10752 skb_put_u8(skb, IEEE80211_MLE_SUBELEM_PER_STA_PROFILE); 10753 subelem_len = skb_put(skb, 1); 10754 10755 put_unaligned_le16(ctrl, skb_put(skb, sizeof(ctrl))); 10756 skb_put_u8(skb, 1 + ETH_ALEN); 10757 skb_put_data(skb, addr, ETH_ALEN); 10758 10759 if (!(removed_links & BIT(link_id))) { 10760 u16 link_present_elems[PRESENT_ELEMS_MAX] = {}; 10761 size_t extra_used; 10762 void *capab_pos; 10763 u8 qos_info; 10764 10765 capab_pos = skb_put(skb, 2); 10766 10767 extra_used = 10768 ieee80211_add_link_elems(sdata, skb, &capab, NULL, 10769 add_links_data->link[link_id].elems, 10770 add_links_data->link[link_id].elems_len, 10771 link_id, NULL, 10772 link_present_elems, 10773 add_links_data); 10774 10775 if (add_links_data->link[link_id].elems) 10776 skb_put_data(skb, 10777 add_links_data->link[link_id].elems + 10778 extra_used, 10779 add_links_data->link[link_id].elems_len - 10780 extra_used); 10781 if (sdata->u.mgd.flags & IEEE80211_STA_UAPSD_ENABLED) { 10782 qos_info = sdata->u.mgd.uapsd_queues; 10783 qos_info |= (sdata->u.mgd.uapsd_max_sp_len << 10784 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT); 10785 } else { 10786 qos_info = 0; 10787 } 10788 10789 ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info); 10790 put_unaligned_le16(capab, capab_pos); 10791 } 10792 10793 ieee80211_fragment_element(skb, subelem_len, 10794 IEEE80211_MLE_SUBELEM_FRAGMENT); 10795 } 10796 10797 ieee80211_fragment_element(skb, ml_elem_len, WLAN_EID_FRAGMENT); 10798 10799 info = IEEE80211_SKB_CB(skb); 10800 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; 10801 10802 return skb; 10803 } 10804 10805 int ieee80211_mgd_assoc_ml_reconf(struct ieee80211_sub_if_data *sdata, 10806 struct cfg80211_ml_reconf_req *req) 10807 { 10808 struct ieee80211_local *local = sdata->local; 10809 struct ieee80211_mgd_assoc_data *data = NULL; 10810 struct sta_info *sta; 10811 struct sk_buff *skb; 10812 u16 added_links, new_valid_links; 10813 int link_id, err; 10814 10815 if (!ieee80211_vif_is_mld(&sdata->vif) || 10816 !(sdata->vif.cfg.mld_capa_op & 10817 IEEE80211_MLD_CAP_OP_LINK_RECONF_SUPPORT)) 10818 return -EINVAL; 10819 10820 /* No support for concurrent ML reconfiguration operation */ 10821 if (sdata->u.mgd.reconf.added_links || 10822 sdata->u.mgd.reconf.removed_links) 10823 return -EBUSY; 10824 10825 added_links = 0; 10826 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { 10827 if (!req->add_links[link_id].bss) 10828 continue; 10829 10830 added_links |= BIT(link_id); 10831 } 10832 10833 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr); 10834 if (WARN_ON(!sta)) 10835 return -ENOLINK; 10836 10837 /* Adding links to the set of valid link is done only after a successful 10838 * ML reconfiguration frame exchange. Here prepare the data for the ML 10839 * reconfiguration frame construction and allocate the required 10840 * resources 10841 */ 10842 if (added_links) { 10843 bool uapsd_supported; 10844 10845 data = kzalloc_obj(*data); 10846 if (!data) 10847 return -ENOMEM; 10848 10849 data->assoc_link_id = -1; 10850 data->wmm = true; 10851 10852 uapsd_supported = true; 10853 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; 10854 link_id++) { 10855 struct ieee80211_supported_band *sband; 10856 struct cfg80211_bss *link_cbss = 10857 req->add_links[link_id].bss; 10858 struct ieee80211_bss *bss; 10859 10860 if (!link_cbss) 10861 continue; 10862 10863 bss = (void *)link_cbss->priv; 10864 10865 if (!bss->wmm_used) { 10866 err = -EINVAL; 10867 goto err_free; 10868 } 10869 10870 if (link_cbss->channel->band == NL80211_BAND_S1GHZ) { 10871 err = -EINVAL; 10872 goto err_free; 10873 } 10874 10875 eth_random_addr(data->link[link_id].addr); 10876 data->link[link_id].conn = 10877 ieee80211_conn_settings_unlimited; 10878 sband = 10879 local->hw.wiphy->bands[link_cbss->channel->band]; 10880 10881 ieee80211_determine_our_sta_mode(sdata, sband, 10882 NULL, true, link_id, 10883 &data->link[link_id].conn); 10884 10885 data->link[link_id].bss = link_cbss; 10886 data->link[link_id].elems = 10887 (u8 *)req->add_links[link_id].elems; 10888 data->link[link_id].elems_len = 10889 req->add_links[link_id].elems_len; 10890 10891 if (!bss->uapsd_supported) 10892 uapsd_supported = false; 10893 10894 if (data->link[link_id].conn.mode < 10895 IEEE80211_CONN_MODE_EHT) { 10896 err = -EINVAL; 10897 goto err_free; 10898 } 10899 10900 err = ieee80211_mgd_get_ap_ht_vht_capa(sdata, data, 10901 link_id); 10902 if (err) { 10903 err = -EINVAL; 10904 goto err_free; 10905 } 10906 } 10907 10908 /* Require U-APSD support if we enabled it */ 10909 if (sdata->u.mgd.flags & IEEE80211_STA_UAPSD_ENABLED && 10910 !uapsd_supported) { 10911 err = -EINVAL; 10912 sdata_info(sdata, "U-APSD on but not available on (all) new links\n"); 10913 goto err_free; 10914 } 10915 10916 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; 10917 link_id++) { 10918 if (!data->link[link_id].bss) 10919 continue; 10920 10921 /* only used to verify the mode, nothing is allocated */ 10922 err = ieee80211_prep_channel(sdata, NULL, link_id, 10923 data->link[link_id].bss, 10924 true, 10925 &data->link[link_id].conn, 10926 sdata->u.mgd.userspace_selectors); 10927 if (err) 10928 goto err_free; 10929 } 10930 } 10931 10932 /* link removal is done before the ML reconfiguration frame exchange so 10933 * that these links will not be used between their removal by the AP MLD 10934 * and before the station got the ML reconfiguration response. Based on 10935 * Section 35.3.6.4 in Draft P802.11be_D7.0 the AP MLD should accept the 10936 * link removal request. 10937 */ 10938 if (req->rem_links) { 10939 u16 new_active_links = 10940 sdata->vif.active_links & ~req->rem_links; 10941 10942 new_valid_links = sdata->vif.valid_links & ~req->rem_links; 10943 10944 /* Should not be left with no valid links to perform the 10945 * ML reconfiguration 10946 */ 10947 if (!new_valid_links || 10948 !(new_valid_links & ~sdata->vif.dormant_links)) { 10949 sdata_info(sdata, "mlo: reconf: no valid links\n"); 10950 err = -EINVAL; 10951 goto err_free; 10952 } 10953 10954 if (new_active_links != sdata->vif.active_links) { 10955 if (!new_active_links) 10956 new_active_links = 10957 BIT(__ffs(new_valid_links & 10958 ~sdata->vif.dormant_links)); 10959 10960 err = ieee80211_set_active_links(&sdata->vif, 10961 new_active_links); 10962 if (err) { 10963 sdata_info(sdata, 10964 "mlo: reconf: failed set active links\n"); 10965 goto err_free; 10966 } 10967 } 10968 } 10969 10970 /* Build the SKB before the link removal as the construction of the 10971 * station info for removed links requires the local address. 10972 * Invalidate the removed links, so that the transmission of the ML 10973 * reconfiguration request frame would not be done using them, as the AP 10974 * is expected to send the ML reconfiguration response frame on the link 10975 * on which the request was received. 10976 */ 10977 skb = ieee80211_build_ml_reconf_req(sdata, data, req->rem_links, 10978 cpu_to_le16(req->ext_mld_capa_ops)); 10979 if (!skb) { 10980 err = -ENOMEM; 10981 goto err_free; 10982 } 10983 10984 if (req->rem_links) { 10985 u16 new_dormant_links = 10986 sdata->vif.dormant_links & ~req->rem_links; 10987 10988 err = ieee80211_vif_set_links(sdata, new_valid_links, 10989 new_dormant_links); 10990 if (err) { 10991 sdata_info(sdata, 10992 "mlo: reconf: failed set valid links\n"); 10993 kfree_skb(skb); 10994 goto err_free; 10995 } 10996 10997 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; 10998 link_id++) { 10999 if (!(req->rem_links & BIT(link_id))) 11000 continue; 11001 11002 ieee80211_sta_remove_link(sta, link_id); 11003 } 11004 11005 /* notify the driver and upper layers */ 11006 ieee80211_vif_cfg_change_notify(sdata, 11007 BSS_CHANGED_MLD_VALID_LINKS); 11008 cfg80211_links_removed(sdata->dev, req->rem_links); 11009 } 11010 11011 sdata_info(sdata, "mlo: reconf: adding=0x%x, removed=0x%x\n", 11012 added_links, req->rem_links); 11013 11014 ieee80211_tx_skb(sdata, skb); 11015 11016 sdata->u.mgd.reconf.added_links = added_links; 11017 sdata->u.mgd.reconf.add_links_data = data; 11018 sdata->u.mgd.reconf.removed_links = req->rem_links; 11019 wiphy_delayed_work_queue(sdata->local->hw.wiphy, 11020 &sdata->u.mgd.reconf.wk, 11021 IEEE80211_ASSOC_TIMEOUT_SHORT); 11022 return 0; 11023 11024 err_free: 11025 kfree(data); 11026 return err; 11027 } 11028 11029 static bool ieee80211_mgd_epcs_supp(struct ieee80211_sub_if_data *sdata) 11030 { 11031 unsigned long valid_links = sdata->vif.valid_links; 11032 u8 link_id; 11033 11034 lockdep_assert_wiphy(sdata->local->hw.wiphy); 11035 11036 if (!ieee80211_vif_is_mld(&sdata->vif)) 11037 return false; 11038 11039 for_each_set_bit(link_id, &valid_links, IEEE80211_MLD_MAX_NUM_LINKS) { 11040 struct ieee80211_bss_conf *bss_conf = 11041 sdata_dereference(sdata->vif.link_conf[link_id], sdata); 11042 11043 if (WARN_ON(!bss_conf) || !bss_conf->epcs_support) 11044 return false; 11045 } 11046 11047 return true; 11048 } 11049 11050 int ieee80211_mgd_set_epcs(struct ieee80211_sub_if_data *sdata, bool enable) 11051 { 11052 struct ieee80211_local *local = sdata->local; 11053 struct ieee80211_mgmt *mgmt; 11054 struct sk_buff *skb; 11055 int frame_len = offsetofend(struct ieee80211_mgmt, 11056 u.action.u.epcs) + (enable ? 1 : 0); 11057 11058 if (!ieee80211_mgd_epcs_supp(sdata)) 11059 return -EINVAL; 11060 11061 if (sdata->u.mgd.epcs.enabled == enable && 11062 !sdata->u.mgd.epcs.dialog_token) 11063 return 0; 11064 11065 /* Do not allow enabling EPCS if the AP didn't respond yet. 11066 * However, allow disabling EPCS in such a case. 11067 */ 11068 if (sdata->u.mgd.epcs.dialog_token && enable) 11069 return -EALREADY; 11070 11071 skb = dev_alloc_skb(local->hw.extra_tx_headroom + frame_len); 11072 if (!skb) 11073 return -ENOBUFS; 11074 11075 skb_reserve(skb, local->hw.extra_tx_headroom); 11076 mgmt = skb_put_zero(skb, frame_len); 11077 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 11078 IEEE80211_STYPE_ACTION); 11079 memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN); 11080 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); 11081 memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN); 11082 11083 mgmt->u.action.category = WLAN_CATEGORY_PROTECTED_EHT; 11084 if (enable) { 11085 u8 *pos = mgmt->u.action.u.epcs.variable; 11086 11087 mgmt->u.action.u.epcs.action_code = 11088 WLAN_PROTECTED_EHT_ACTION_EPCS_ENABLE_REQ; 11089 11090 *pos = ++sdata->u.mgd.dialog_token_alloc; 11091 sdata->u.mgd.epcs.dialog_token = *pos; 11092 } else { 11093 mgmt->u.action.u.epcs.action_code = 11094 WLAN_PROTECTED_EHT_ACTION_EPCS_ENABLE_TEARDOWN; 11095 11096 ieee80211_epcs_teardown(sdata); 11097 ieee80211_epcs_changed(sdata, false); 11098 } 11099 11100 ieee80211_tx_skb(sdata, skb); 11101 return 0; 11102 } 11103 11104 static void ieee80211_ml_epcs(struct ieee80211_sub_if_data *sdata, 11105 struct ieee802_11_elems *elems) 11106 { 11107 const struct element *sub; 11108 size_t scratch_len = elems->ml_epcs_len; 11109 u8 *scratch __free(kfree) = kzalloc(scratch_len, GFP_KERNEL); 11110 11111 lockdep_assert_wiphy(sdata->local->hw.wiphy); 11112 11113 if (!ieee80211_vif_is_mld(&sdata->vif) || !elems->ml_epcs) 11114 return; 11115 11116 if (WARN_ON(!scratch)) 11117 return; 11118 11119 /* Directly parse the sub elements as the common information doesn't 11120 * hold any useful information. 11121 */ 11122 for_each_mle_subelement(sub, (const u8 *)elems->ml_epcs, 11123 elems->ml_epcs_len) { 11124 struct ieee802_11_elems *link_elems __free(kfree) = NULL; 11125 struct ieee80211_link_data *link; 11126 u8 *pos = (void *)sub->data; 11127 u16 control; 11128 ssize_t len; 11129 u8 link_id; 11130 11131 if (sub->id != IEEE80211_MLE_SUBELEM_PER_STA_PROFILE) 11132 continue; 11133 11134 if (sub->datalen < sizeof(control)) 11135 break; 11136 11137 control = get_unaligned_le16(pos); 11138 link_id = control & IEEE80211_MLE_STA_EPCS_CONTROL_LINK_ID; 11139 11140 link = sdata_dereference(sdata->link[link_id], sdata); 11141 if (!link) 11142 continue; 11143 11144 len = cfg80211_defragment_element(sub, (u8 *)elems->ml_epcs, 11145 elems->ml_epcs_len, 11146 scratch, scratch_len, 11147 IEEE80211_MLE_SUBELEM_FRAGMENT); 11148 if (len < (ssize_t)sizeof(control)) 11149 continue; 11150 11151 pos = scratch + sizeof(control); 11152 len -= sizeof(control); 11153 11154 link_elems = ieee802_11_parse_elems(pos, len, 11155 IEEE80211_FTYPE_MGMT | 11156 IEEE80211_STYPE_ACTION, 11157 NULL); 11158 if (!link_elems) 11159 continue; 11160 11161 if (ieee80211_sta_wmm_params(sdata->local, link, 11162 link_elems->wmm_param, 11163 link_elems->wmm_param_len, 11164 link_elems->mu_edca_param_set)) 11165 ieee80211_link_info_change_notify(sdata, link, 11166 BSS_CHANGED_QOS); 11167 } 11168 } 11169 11170 void ieee80211_process_epcs_ena_resp(struct ieee80211_sub_if_data *sdata, 11171 struct ieee80211_mgmt *mgmt, size_t len) 11172 { 11173 struct ieee802_11_elems *elems __free(kfree) = NULL; 11174 size_t ies_len; 11175 u16 status_code; 11176 u8 *pos, dialog_token; 11177 11178 if (!ieee80211_mgd_epcs_supp(sdata)) 11179 return; 11180 11181 /* Handle dialog token and status code */ 11182 pos = mgmt->u.action.u.epcs.variable; 11183 dialog_token = *pos; 11184 status_code = get_unaligned_le16(pos + 1); 11185 11186 /* An EPCS enable response with dialog token == 0 is an unsolicited 11187 * notification from the AP MLD. In such a case, EPCS should already be 11188 * enabled and status must be success 11189 */ 11190 if (!dialog_token && 11191 (!sdata->u.mgd.epcs.enabled || 11192 status_code != WLAN_STATUS_SUCCESS)) 11193 return; 11194 11195 if (sdata->u.mgd.epcs.dialog_token != dialog_token) 11196 return; 11197 11198 sdata->u.mgd.epcs.dialog_token = 0; 11199 11200 if (status_code != WLAN_STATUS_SUCCESS) 11201 return; 11202 11203 pos += IEEE80211_EPCS_ENA_RESP_BODY_LEN; 11204 ies_len = len - offsetof(struct ieee80211_mgmt, 11205 u.action.u.epcs.variable) - 11206 IEEE80211_EPCS_ENA_RESP_BODY_LEN; 11207 11208 elems = ieee802_11_parse_elems(pos, ies_len, 11209 IEEE80211_FTYPE_MGMT | 11210 IEEE80211_STYPE_ACTION, 11211 NULL); 11212 if (!elems) 11213 return; 11214 11215 ieee80211_ml_epcs(sdata, elems); 11216 ieee80211_epcs_changed(sdata, true); 11217 } 11218 11219 void ieee80211_process_epcs_teardown(struct ieee80211_sub_if_data *sdata, 11220 struct ieee80211_mgmt *mgmt, size_t len) 11221 { 11222 if (!ieee80211_vif_is_mld(&sdata->vif) || 11223 !sdata->u.mgd.epcs.enabled) 11224 return; 11225 11226 ieee80211_epcs_teardown(sdata); 11227 ieee80211_epcs_changed(sdata, false); 11228 } 11229