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