1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright 2002-2005, Instant802 Networks, Inc. 4 * Copyright 2005-2006, Devicescape Software, Inc. 5 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> 6 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> 7 * Copyright 2013-2014 Intel Mobile Communications GmbH 8 * Copyright (C) 2018-2026 Intel Corporation 9 * 10 * Transmit and frame generation functions. 11 */ 12 13 #include <linux/kernel.h> 14 #include <linux/slab.h> 15 #include <linux/skbuff.h> 16 #include <linux/if_vlan.h> 17 #include <linux/etherdevice.h> 18 #include <linux/bitmap.h> 19 #include <linux/rcupdate.h> 20 #include <linux/export.h> 21 #include <net/net_namespace.h> 22 #include <net/ieee80211_radiotap.h> 23 #include <net/cfg80211.h> 24 #include <net/mac80211.h> 25 #include <net/codel.h> 26 #include <net/codel_impl.h> 27 #include <linux/unaligned.h> 28 #include <net/fq_impl.h> 29 #include <net/sock.h> 30 #include <net/gso.h> 31 32 #include "ieee80211_i.h" 33 #include "driver-ops.h" 34 #include "led.h" 35 #include "mesh.h" 36 #include "wep.h" 37 #include "wpa.h" 38 #include "wme.h" 39 #include "rate.h" 40 41 /* misc utils */ 42 43 static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, 44 struct sk_buff *skb, int group_addr, 45 int next_frag_len) 46 { 47 int rate, mrate, erp, dur, i; 48 struct ieee80211_rate *txrate; 49 struct ieee80211_local *local = tx->local; 50 struct ieee80211_supported_band *sband; 51 struct ieee80211_hdr *hdr; 52 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 53 54 /* assume HW handles this */ 55 if (tx->rate.flags & (IEEE80211_TX_RC_MCS | IEEE80211_TX_RC_VHT_MCS)) 56 return 0; 57 58 /* uh huh? */ 59 if (WARN_ON_ONCE(tx->rate.idx < 0)) 60 return 0; 61 62 if (info->band >= NUM_NL80211_BANDS) 63 return 0; 64 65 sband = local->hw.wiphy->bands[info->band]; 66 txrate = &sband->bitrates[tx->rate.idx]; 67 68 erp = txrate->flags & IEEE80211_RATE_ERP_G; 69 70 /* device is expected to do this */ 71 if (sband->band == NL80211_BAND_S1GHZ) 72 return 0; 73 74 /* 75 * data and mgmt (except PS Poll): 76 * - during CFP: 32768 77 * - during contention period: 78 * if addr1 is group address: 0 79 * if more fragments = 0 and addr1 is individual address: time to 80 * transmit one ACK plus SIFS 81 * if more fragments = 1 and addr1 is individual address: time to 82 * transmit next fragment plus 2 x ACK plus 3 x SIFS 83 * 84 * IEEE 802.11, 9.6: 85 * - control response frame (CTS or ACK) shall be transmitted using the 86 * same rate as the immediately previous frame in the frame exchange 87 * sequence, if this rate belongs to the PHY mandatory rates, or else 88 * at the highest possible rate belonging to the PHY rates in the 89 * BSSBasicRateSet 90 */ 91 hdr = (struct ieee80211_hdr *)skb->data; 92 if (ieee80211_is_ctl(hdr->frame_control)) { 93 /* TODO: These control frames are not currently sent by 94 * mac80211, but should they be implemented, this function 95 * needs to be updated to support duration field calculation. 96 * 97 * RTS: time needed to transmit pending data/mgmt frame plus 98 * one CTS frame plus one ACK frame plus 3 x SIFS 99 * CTS: duration of immediately previous RTS minus time 100 * required to transmit CTS and its SIFS 101 * ACK: 0 if immediately previous directed data/mgmt had 102 * more=0, with more=1 duration in ACK frame is duration 103 * from previous frame minus time needed to transmit ACK 104 * and its SIFS 105 * PS Poll: BIT(15) | BIT(14) | aid 106 */ 107 return 0; 108 } 109 110 /* data/mgmt */ 111 if (0 /* FIX: data/mgmt during CFP */) 112 return cpu_to_le16(32768); 113 114 if (group_addr) /* Group address as the destination - no ACK */ 115 return 0; 116 117 /* Individual destination address: 118 * IEEE 802.11, Ch. 9.6 (after IEEE 802.11g changes) 119 * CTS and ACK frames shall be transmitted using the highest rate in 120 * basic rate set that is less than or equal to the rate of the 121 * immediately previous frame and that is using the same modulation 122 * (CCK or OFDM). If no basic rate set matches with these requirements, 123 * the highest mandatory rate of the PHY that is less than or equal to 124 * the rate of the previous frame is used. 125 * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps 126 */ 127 rate = -1; 128 /* use lowest available if everything fails */ 129 mrate = sband->bitrates[0].bitrate; 130 for (i = 0; i < sband->n_bitrates; i++) { 131 struct ieee80211_rate *r = &sband->bitrates[i]; 132 u32 flag; 133 134 if (r->bitrate > txrate->bitrate) 135 break; 136 137 if (tx->sdata->vif.bss_conf.basic_rates & BIT(i)) 138 rate = r->bitrate; 139 140 switch (sband->band) { 141 case NL80211_BAND_2GHZ: 142 case NL80211_BAND_LC: 143 if (tx->sdata->deflink.operating_11g_mode) 144 flag = IEEE80211_RATE_MANDATORY_G; 145 else 146 flag = IEEE80211_RATE_MANDATORY_B; 147 break; 148 case NL80211_BAND_5GHZ: 149 case NL80211_BAND_6GHZ: 150 flag = IEEE80211_RATE_MANDATORY_A; 151 break; 152 default: 153 flag = 0; 154 WARN_ON(1); 155 break; 156 } 157 158 if (r->flags & flag) 159 mrate = r->bitrate; 160 } 161 if (rate == -1) { 162 /* No matching basic rate found; use highest suitable mandatory 163 * PHY rate */ 164 rate = mrate; 165 } 166 167 /* Don't calculate ACKs for QoS Frames with NoAck Policy set */ 168 if (ieee80211_is_data_qos(hdr->frame_control) && 169 *(ieee80211_get_qos_ctl(hdr)) & IEEE80211_QOS_CTL_ACK_POLICY_NOACK) 170 dur = 0; 171 else 172 /* Time needed to transmit ACK 173 * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up 174 * to closest integer */ 175 dur = ieee80211_frame_duration(sband->band, 10, rate, erp, 176 tx->sdata->vif.bss_conf.use_short_preamble); 177 178 if (next_frag_len) { 179 /* Frame is fragmented: duration increases with time needed to 180 * transmit next fragment plus ACK and 2 x SIFS. */ 181 dur *= 2; /* ACK + SIFS */ 182 /* next fragment */ 183 dur += ieee80211_frame_duration(sband->band, next_frag_len, 184 txrate->bitrate, erp, 185 tx->sdata->vif.bss_conf.use_short_preamble); 186 } 187 188 return cpu_to_le16(dur); 189 } 190 191 /* tx handlers */ 192 static ieee80211_tx_result debug_noinline 193 ieee80211_tx_h_dynamic_ps(struct ieee80211_tx_data *tx) 194 { 195 struct ieee80211_local *local = tx->local; 196 struct ieee80211_if_managed *ifmgd; 197 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 198 199 /* driver doesn't support power save */ 200 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) 201 return TX_CONTINUE; 202 203 /* hardware does dynamic power save */ 204 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) 205 return TX_CONTINUE; 206 207 /* dynamic power save disabled */ 208 if (local->hw.conf.dynamic_ps_timeout <= 0) 209 return TX_CONTINUE; 210 211 /* we are scanning, don't enable power save */ 212 if (local->scanning) 213 return TX_CONTINUE; 214 215 if (!local->ps_sdata) 216 return TX_CONTINUE; 217 218 /* No point if we're going to suspend */ 219 if (local->quiescing) 220 return TX_CONTINUE; 221 222 /* dynamic ps is supported only in managed mode */ 223 if (tx->sdata->vif.type != NL80211_IFTYPE_STATION) 224 return TX_CONTINUE; 225 226 if (unlikely(info->flags & IEEE80211_TX_INTFL_OFFCHAN_TX_OK)) 227 return TX_CONTINUE; 228 229 ifmgd = &tx->sdata->u.mgd; 230 231 /* 232 * Don't wakeup from power save if u-apsd is enabled, voip ac has 233 * u-apsd enabled and the frame is in voip class. This effectively 234 * means that even if all access categories have u-apsd enabled, in 235 * practise u-apsd is only used with the voip ac. This is a 236 * workaround for the case when received voip class packets do not 237 * have correct qos tag for some reason, due the network or the 238 * peer application. 239 * 240 * Note: ifmgd->uapsd_queues access is racy here. If the value is 241 * changed via debugfs, user needs to reassociate manually to have 242 * everything in sync. 243 */ 244 if ((ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED) && 245 (ifmgd->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) && 246 skb_get_queue_mapping(tx->skb) == IEEE80211_AC_VO) 247 return TX_CONTINUE; 248 249 if (local->hw.conf.flags & IEEE80211_CONF_PS) { 250 ieee80211_stop_queues_by_reason(&local->hw, 251 IEEE80211_MAX_QUEUE_MAP, 252 IEEE80211_QUEUE_STOP_REASON_PS, 253 false); 254 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED; 255 wiphy_work_queue(local->hw.wiphy, 256 &local->dynamic_ps_disable_work); 257 } 258 259 /* Don't restart the timer if we're not disassociated */ 260 if (!ifmgd->associated) 261 return TX_CONTINUE; 262 263 mod_timer(&local->dynamic_ps_timer, jiffies + 264 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout)); 265 266 return TX_CONTINUE; 267 } 268 269 static ieee80211_tx_result debug_noinline 270 ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx) 271 { 272 273 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; 274 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 275 bool assoc = false; 276 277 if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED)) 278 return TX_CONTINUE; 279 280 if (unlikely(test_bit(SCAN_SW_SCANNING, &tx->local->scanning)) && 281 test_bit(SDATA_STATE_OFFCHANNEL, &tx->sdata->state) && 282 !ieee80211_is_probe_req(hdr->frame_control) && 283 !ieee80211_is_any_nullfunc(hdr->frame_control)) 284 /* 285 * When software scanning only nullfunc frames (to notify 286 * the sleep state to the AP) and probe requests (for the 287 * active scan) are allowed, all other frames should not be 288 * sent and we should not get here, but if we do 289 * nonetheless, drop them to avoid sending them 290 * off-channel. See __ieee80211_start_scan() for more. 291 */ 292 return TX_DROP; 293 294 if (tx->sdata->vif.type == NL80211_IFTYPE_OCB) 295 return TX_CONTINUE; 296 297 if (tx->flags & IEEE80211_TX_PS_BUFFERED) 298 return TX_CONTINUE; 299 300 if (tx->sta) 301 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC); 302 303 if (likely(tx->flags & IEEE80211_TX_UNICAST)) { 304 if (unlikely(!assoc && 305 ieee80211_is_data(hdr->frame_control))) { 306 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG 307 sdata_info(tx->sdata, 308 "dropped data frame to not associated station %pM\n", 309 hdr->addr1); 310 #endif 311 I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc); 312 return TX_DROP; 313 } 314 } else if (unlikely(ieee80211_is_data(hdr->frame_control) && 315 ieee80211_vif_get_num_mcast_if(tx->sdata) == 0)) { 316 /* 317 * No associated STAs - no need to send multicast 318 * frames. 319 */ 320 return TX_DROP; 321 } 322 323 return TX_CONTINUE; 324 } 325 326 /* This function is called whenever the AP is about to exceed the maximum limit 327 * of buffered frames for power saving STAs. This situation should not really 328 * happen often during normal operation, so dropping the oldest buffered packet 329 * from each queue should be OK to make some room for new frames. */ 330 static void purge_old_ps_buffers(struct ieee80211_local *local) 331 { 332 int total = 0, purged = 0; 333 struct sk_buff *skb; 334 struct ieee80211_sub_if_data *sdata; 335 struct sta_info *sta; 336 337 list_for_each_entry_rcu(sdata, &local->interfaces, list) { 338 struct ps_data *ps; 339 340 if (sdata->vif.type == NL80211_IFTYPE_AP) 341 ps = &sdata->u.ap.ps; 342 else if (ieee80211_vif_is_mesh(&sdata->vif)) 343 ps = &sdata->u.mesh.ps; 344 else 345 continue; 346 347 skb = skb_dequeue(&ps->bc_buf); 348 if (skb) { 349 purged++; 350 ieee80211_free_txskb(&local->hw, skb); 351 } 352 total += skb_queue_len(&ps->bc_buf); 353 } 354 355 /* 356 * Drop one frame from each station from the lowest-priority 357 * AC that has frames at all. 358 */ 359 list_for_each_entry_rcu(sta, &local->sta_list, list) { 360 int ac; 361 362 for (ac = IEEE80211_AC_BK; ac >= IEEE80211_AC_VO; ac--) { 363 skb = skb_dequeue(&sta->ps_tx_buf[ac]); 364 total += skb_queue_len(&sta->ps_tx_buf[ac]); 365 if (skb) { 366 purged++; 367 ieee80211_free_txskb(&local->hw, skb); 368 break; 369 } 370 } 371 } 372 373 local->total_ps_buffered = total; 374 ps_dbg_hw(&local->hw, "PS buffers full - purged %d frames\n", purged); 375 } 376 377 static ieee80211_tx_result 378 ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx) 379 { 380 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 381 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; 382 struct ps_data *ps; 383 384 /* 385 * broadcast/multicast frame 386 * 387 * If any of the associated/peer stations is in power save mode, 388 * the frame is buffered to be sent after DTIM beacon frame. 389 * This is done either by the hardware or us. 390 */ 391 392 /* powersaving STAs currently only in AP/VLAN/mesh mode */ 393 if (tx->sdata->vif.type == NL80211_IFTYPE_AP || 394 tx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) { 395 if (!tx->sdata->bss) 396 return TX_CONTINUE; 397 398 ps = &tx->sdata->bss->ps; 399 } else if (ieee80211_vif_is_mesh(&tx->sdata->vif)) { 400 ps = &tx->sdata->u.mesh.ps; 401 } else { 402 return TX_CONTINUE; 403 } 404 405 406 /* no buffering for ordered frames */ 407 if (ieee80211_has_order(hdr->frame_control)) 408 return TX_CONTINUE; 409 410 if (ieee80211_is_probe_req(hdr->frame_control)) 411 return TX_CONTINUE; 412 413 if (ieee80211_hw_check(&tx->local->hw, QUEUE_CONTROL)) 414 info->hw_queue = tx->sdata->vif.cab_queue; 415 416 /* no stations in PS mode and no buffered packets */ 417 if (!atomic_read(&ps->num_sta_ps) && skb_queue_empty(&ps->bc_buf)) 418 return TX_CONTINUE; 419 420 info->flags |= IEEE80211_TX_CTL_SEND_AFTER_DTIM; 421 422 /* device releases frame after DTIM beacon */ 423 if (!ieee80211_hw_check(&tx->local->hw, HOST_BROADCAST_PS_BUFFERING)) 424 return TX_CONTINUE; 425 426 /* buffered in mac80211 */ 427 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER) 428 purge_old_ps_buffers(tx->local); 429 430 if (skb_queue_len(&ps->bc_buf) >= AP_MAX_BC_BUFFER) { 431 ps_dbg(tx->sdata, 432 "BC TX buffer full - dropping the oldest frame\n"); 433 ieee80211_free_txskb(&tx->local->hw, skb_dequeue(&ps->bc_buf)); 434 } else 435 tx->local->total_ps_buffered++; 436 437 skb_queue_tail(&ps->bc_buf, tx->skb); 438 439 return TX_QUEUED; 440 } 441 442 static int ieee80211_use_mfp(__le16 fc, struct sta_info *sta, 443 struct sk_buff *skb) 444 { 445 if (!ieee80211_is_mgmt(fc)) 446 return 0; 447 448 if (sta == NULL || !test_sta_flag(sta, WLAN_STA_MFP)) 449 return 0; 450 451 if (!ieee80211_is_robust_mgmt_frame(skb)) 452 return 0; 453 454 return 1; 455 } 456 457 static ieee80211_tx_result 458 ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx) 459 { 460 struct sta_info *sta = tx->sta; 461 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 462 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; 463 struct ieee80211_local *local = tx->local; 464 465 if (unlikely(!sta)) 466 return TX_CONTINUE; 467 468 if (unlikely((test_sta_flag(sta, WLAN_STA_PS_STA) || 469 test_sta_flag(sta, WLAN_STA_PS_DRIVER) || 470 test_sta_flag(sta, WLAN_STA_PS_DELIVER)) && 471 !(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER))) { 472 int ac = skb_get_queue_mapping(tx->skb); 473 474 if (ieee80211_is_mgmt(hdr->frame_control) && 475 !ieee80211_is_bufferable_mmpdu(tx->skb)) { 476 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER; 477 return TX_CONTINUE; 478 } 479 480 ps_dbg(sta->sdata, "STA %pM aid %d: PS buffer for AC %d\n", 481 sta->sta.addr, sta->sta.aid, ac); 482 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER) 483 purge_old_ps_buffers(tx->local); 484 485 /* sync with ieee80211_sta_ps_deliver_wakeup */ 486 spin_lock(&sta->ps_lock); 487 /* 488 * STA woke up the meantime and all the frames on ps_tx_buf have 489 * been queued to pending queue. No reordering can happen, go 490 * ahead and Tx the packet. 491 */ 492 if (!test_sta_flag(sta, WLAN_STA_PS_STA) && 493 !test_sta_flag(sta, WLAN_STA_PS_DRIVER) && 494 !test_sta_flag(sta, WLAN_STA_PS_DELIVER)) { 495 spin_unlock(&sta->ps_lock); 496 return TX_CONTINUE; 497 } 498 499 if (skb_queue_len(&sta->ps_tx_buf[ac]) >= STA_MAX_TX_BUFFER) { 500 struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf[ac]); 501 ps_dbg(tx->sdata, 502 "STA %pM TX buffer for AC %d full - dropping oldest frame\n", 503 sta->sta.addr, ac); 504 ieee80211_free_txskb(&local->hw, old); 505 } else 506 tx->local->total_ps_buffered++; 507 508 info->control.jiffies = jiffies; 509 info->control.vif = &tx->sdata->vif; 510 info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING; 511 info->flags &= ~IEEE80211_TX_TEMPORARY_FLAGS; 512 skb_queue_tail(&sta->ps_tx_buf[ac], tx->skb); 513 spin_unlock(&sta->ps_lock); 514 515 if (!timer_pending(&local->sta_cleanup)) 516 mod_timer(&local->sta_cleanup, 517 round_jiffies(jiffies + 518 STA_INFO_CLEANUP_INTERVAL)); 519 520 /* 521 * We queued up some frames, so the TIM bit might 522 * need to be set, recalculate it. 523 */ 524 sta_info_recalc_tim(sta); 525 526 return TX_QUEUED; 527 } else if (unlikely(test_sta_flag(sta, WLAN_STA_PS_STA))) { 528 ps_dbg(tx->sdata, 529 "STA %pM in PS mode, but polling/in SP -> send frame\n", 530 sta->sta.addr); 531 } 532 533 return TX_CONTINUE; 534 } 535 536 static ieee80211_tx_result debug_noinline 537 ieee80211_tx_h_ps_buf(struct ieee80211_tx_data *tx) 538 { 539 if (unlikely(tx->flags & IEEE80211_TX_PS_BUFFERED)) 540 return TX_CONTINUE; 541 542 if (tx->flags & IEEE80211_TX_UNICAST) 543 return ieee80211_tx_h_unicast_ps_buf(tx); 544 else 545 return ieee80211_tx_h_multicast_ps_buf(tx); 546 } 547 548 static ieee80211_tx_result debug_noinline 549 ieee80211_tx_h_check_control_port_protocol(struct ieee80211_tx_data *tx) 550 { 551 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 552 553 if (unlikely(tx->sdata->control_port_protocol == tx->skb->protocol)) { 554 if (tx->sdata->control_port_no_encrypt) 555 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; 556 info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO; 557 info->flags |= IEEE80211_TX_CTL_USE_MINRATE; 558 } 559 560 return TX_CONTINUE; 561 } 562 563 static struct ieee80211_key * 564 ieee80211_select_link_key(struct ieee80211_tx_data *tx) 565 { 566 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; 567 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 568 struct ieee80211_link_data *link; 569 unsigned int link_id; 570 571 link_id = u32_get_bits(info->control.flags, IEEE80211_TX_CTRL_MLO_LINK); 572 if (link_id == IEEE80211_LINK_UNSPECIFIED) { 573 link = &tx->sdata->deflink; 574 } else { 575 link = rcu_dereference(tx->sdata->link[link_id]); 576 if (!link) 577 return NULL; 578 } 579 580 if (ieee80211_is_group_privacy_action(tx->skb)) 581 return rcu_dereference(link->default_multicast_key); 582 else if (ieee80211_is_mgmt(hdr->frame_control) && 583 is_multicast_ether_addr(hdr->addr1) && 584 ieee80211_is_robust_mgmt_frame(tx->skb)) 585 return rcu_dereference(link->default_mgmt_key); 586 else if (is_multicast_ether_addr(hdr->addr1)) 587 return rcu_dereference(link->default_multicast_key); 588 589 return NULL; 590 } 591 592 static ieee80211_tx_result debug_noinline 593 ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx) 594 { 595 struct ieee80211_key *key; 596 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 597 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; 598 599 if (unlikely(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)) { 600 tx->key = NULL; 601 return TX_CONTINUE; 602 } 603 604 if (tx->sta && 605 (key = rcu_dereference(tx->sta->ptk[tx->sta->ptk_idx]))) 606 tx->key = key; 607 else if ((key = ieee80211_select_link_key(tx))) 608 tx->key = key; 609 else if (!is_multicast_ether_addr(hdr->addr1) && 610 (key = rcu_dereference(tx->sdata->default_unicast_key))) 611 tx->key = key; 612 else 613 tx->key = NULL; 614 615 if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) { 616 if (tx->key && tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) 617 info->control.hw_key = &tx->key->conf; 618 return TX_CONTINUE; 619 } 620 621 if (tx->key) { 622 bool skip_hw = false; 623 624 /* TODO: add threshold stuff again */ 625 626 switch (tx->key->conf.cipher) { 627 case WLAN_CIPHER_SUITE_WEP40: 628 case WLAN_CIPHER_SUITE_WEP104: 629 case WLAN_CIPHER_SUITE_TKIP: 630 if (!ieee80211_is_data_present(hdr->frame_control)) 631 tx->key = NULL; 632 break; 633 case WLAN_CIPHER_SUITE_CCMP: 634 case WLAN_CIPHER_SUITE_CCMP_256: 635 case WLAN_CIPHER_SUITE_GCMP: 636 case WLAN_CIPHER_SUITE_GCMP_256: 637 if (!ieee80211_is_data_present(hdr->frame_control) && 638 !ieee80211_use_mfp(hdr->frame_control, tx->sta, 639 tx->skb) && 640 !ieee80211_is_group_privacy_action(tx->skb) && 641 !ieee80211_require_encrypted_assoc(hdr->frame_control, 642 tx->sta)) 643 tx->key = NULL; 644 else 645 skip_hw = (tx->key->conf.flags & 646 IEEE80211_KEY_FLAG_SW_MGMT_TX) && 647 ieee80211_is_mgmt(hdr->frame_control); 648 break; 649 case WLAN_CIPHER_SUITE_AES_CMAC: 650 case WLAN_CIPHER_SUITE_BIP_CMAC_256: 651 case WLAN_CIPHER_SUITE_BIP_GMAC_128: 652 case WLAN_CIPHER_SUITE_BIP_GMAC_256: 653 if (!ieee80211_is_mgmt(hdr->frame_control)) 654 tx->key = NULL; 655 break; 656 } 657 658 if (unlikely(tx->key && tx->key->flags & KEY_FLAG_TAINTED && 659 !ieee80211_is_deauth(hdr->frame_control)) && 660 tx->skb->protocol != tx->sdata->control_port_protocol) 661 return TX_DROP; 662 663 if (!skip_hw && tx->key && 664 tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) 665 info->control.hw_key = &tx->key->conf; 666 } else if (ieee80211_is_data_present(hdr->frame_control) && tx->sta && 667 test_sta_flag(tx->sta, WLAN_STA_USES_ENCRYPTION)) { 668 return TX_DROP; 669 } 670 671 return TX_CONTINUE; 672 } 673 674 static ieee80211_tx_result debug_noinline 675 ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx) 676 { 677 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 678 struct ieee80211_hdr *hdr = (void *)tx->skb->data; 679 struct ieee80211_supported_band *sband; 680 u32 len; 681 struct ieee80211_tx_rate_control txrc; 682 struct ieee80211_sta_rates *ratetbl = NULL; 683 bool encap = info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP; 684 bool assoc = false; 685 686 memset(&txrc, 0, sizeof(txrc)); 687 688 if (info->band < NUM_NL80211_BANDS) 689 sband = tx->local->hw.wiphy->bands[info->band]; 690 else 691 return TX_CONTINUE; 692 693 len = min_t(u32, tx->skb->len + FCS_LEN, 694 tx->local->hw.wiphy->frag_threshold); 695 696 /* set up the tx rate control struct we give the RC algo */ 697 txrc.hw = &tx->local->hw; 698 txrc.sband = sband; 699 txrc.bss_conf = &tx->sdata->vif.bss_conf; 700 txrc.skb = tx->skb; 701 txrc.reported_rate.idx = -1; 702 703 if (unlikely(info->control.flags & IEEE80211_TX_CTRL_DONT_USE_RATE_MASK)) { 704 txrc.rate_idx_mask = ~0; 705 } else { 706 txrc.rate_idx_mask = tx->sdata->rc_rateidx_mask[info->band]; 707 708 if (tx->sdata->rc_has_mcs_mask[info->band]) 709 txrc.rate_idx_mcs_mask = 710 tx->sdata->rc_rateidx_mcs_mask[info->band]; 711 } 712 713 txrc.bss = (tx->sdata->vif.type == NL80211_IFTYPE_AP || 714 tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT || 715 tx->sdata->vif.type == NL80211_IFTYPE_ADHOC || 716 tx->sdata->vif.type == NL80211_IFTYPE_OCB); 717 718 /* set up RTS protection if desired */ 719 if (len > tx->local->hw.wiphy->rts_threshold) { 720 txrc.rts = true; 721 } 722 723 info->control.use_rts = txrc.rts; 724 info->control.use_cts_prot = tx->sdata->vif.bss_conf.use_cts_prot; 725 726 /* 727 * Use short preamble if the BSS can handle it, but not for 728 * management frames unless we know the receiver can handle 729 * that -- the management frame might be to a station that 730 * just wants a probe response. 731 */ 732 if (tx->sdata->vif.bss_conf.use_short_preamble && 733 (ieee80211_is_tx_data(tx->skb) || 734 (tx->sta && test_sta_flag(tx->sta, WLAN_STA_SHORT_PREAMBLE)))) 735 txrc.short_preamble = true; 736 737 info->control.short_preamble = txrc.short_preamble; 738 739 /* don't ask rate control when rate already injected via radiotap */ 740 if (info->control.flags & IEEE80211_TX_CTRL_RATE_INJECT) 741 return TX_CONTINUE; 742 743 if (tx->sta) 744 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC); 745 746 /* 747 * Lets not bother rate control if we're associated and cannot 748 * talk to the sta. This should not happen. 749 */ 750 if (WARN(test_bit(SCAN_SW_SCANNING, &tx->local->scanning) && assoc && 751 !rate_usable_index_exists(sband, &tx->sta->sta), 752 "%s: Dropped data frame as no usable bitrate found while " 753 "scanning and associated. Target station: " 754 "%pM on %d GHz band\n", 755 tx->sdata->name, 756 encap ? ((struct ethhdr *)hdr)->h_dest : hdr->addr1, 757 info->band ? 5 : 2)) 758 return TX_DROP; 759 760 /* 761 * If we're associated with the sta at this point we know we can at 762 * least send the frame at the lowest bit rate. 763 */ 764 rate_control_get_rate(tx->sdata, tx->sta, &txrc); 765 766 if (tx->sta && !info->control.skip_table) 767 ratetbl = rcu_dereference(tx->sta->sta.rates); 768 769 if (unlikely(info->control.rates[0].idx < 0)) { 770 if (ratetbl) { 771 struct ieee80211_tx_rate rate = { 772 .idx = ratetbl->rate[0].idx, 773 .flags = ratetbl->rate[0].flags, 774 .count = ratetbl->rate[0].count 775 }; 776 777 if (ratetbl->rate[0].idx < 0) 778 return TX_DROP; 779 780 tx->rate = rate; 781 } else { 782 return TX_DROP; 783 } 784 } else { 785 tx->rate = info->control.rates[0]; 786 } 787 788 if (txrc.reported_rate.idx < 0) { 789 txrc.reported_rate = tx->rate; 790 if (tx->sta && ieee80211_is_tx_data(tx->skb)) 791 tx->sta->deflink.tx_stats.last_rate = txrc.reported_rate; 792 } else if (tx->sta) 793 tx->sta->deflink.tx_stats.last_rate = txrc.reported_rate; 794 795 if (ratetbl) 796 return TX_CONTINUE; 797 798 if (unlikely(!info->control.rates[0].count)) 799 info->control.rates[0].count = 1; 800 801 if (WARN_ON_ONCE((info->control.rates[0].count > 1) && 802 (info->flags & IEEE80211_TX_CTL_NO_ACK))) 803 info->control.rates[0].count = 1; 804 805 return TX_CONTINUE; 806 } 807 808 static __le16 ieee80211_tx_next_seq(struct sta_info *sta, int tid) 809 { 810 u16 *seq = &sta->tid_seq[tid]; 811 __le16 ret = cpu_to_le16(*seq); 812 813 /* Increase the sequence number. */ 814 *seq = (*seq + 0x10) & IEEE80211_SCTL_SEQ; 815 816 return ret; 817 } 818 819 static ieee80211_tx_result debug_noinline 820 ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx) 821 { 822 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 823 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; 824 int tid; 825 826 /* 827 * Packet injection may want to control the sequence 828 * number, if we have no matching interface then we 829 * neither assign one ourselves nor ask the driver to. 830 */ 831 if (unlikely(info->control.vif->type == NL80211_IFTYPE_MONITOR)) 832 return TX_CONTINUE; 833 834 if (unlikely(ieee80211_is_ctl(hdr->frame_control))) 835 return TX_CONTINUE; 836 837 if (ieee80211_hdrlen(hdr->frame_control) < 24) 838 return TX_CONTINUE; 839 840 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) 841 return TX_CONTINUE; 842 843 if (info->control.flags & IEEE80211_TX_CTRL_NO_SEQNO) 844 return TX_CONTINUE; 845 846 /* SNS11 from 802.11be 10.3.2.14 */ 847 if (unlikely(is_multicast_ether_addr(hdr->addr1) && 848 ieee80211_vif_is_mld(info->control.vif) && 849 info->control.vif->type == NL80211_IFTYPE_AP)) { 850 if (info->control.flags & IEEE80211_TX_CTRL_MCAST_MLO_FIRST_TX) 851 tx->sdata->mld_mcast_seq += 0x10; 852 hdr->seq_ctrl = cpu_to_le16(tx->sdata->mld_mcast_seq); 853 return TX_CONTINUE; 854 } 855 856 /* 857 * Anything but QoS data that has a sequence number field 858 * (is long enough) gets a sequence number from the global 859 * counter. QoS data frames with a multicast destination 860 * also use the global counter (802.11-2012 9.3.2.10). 861 */ 862 if (!ieee80211_is_data_qos(hdr->frame_control) || 863 is_multicast_ether_addr(hdr->addr1)) { 864 /* driver should assign sequence number */ 865 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ; 866 /* for pure STA mode without beacons, we can do it */ 867 hdr->seq_ctrl = cpu_to_le16(tx->sdata->sequence_number); 868 tx->sdata->sequence_number += 0x10; 869 if (tx->sta) 870 tx->sta->deflink.tx_stats.msdu[IEEE80211_NUM_TIDS]++; 871 return TX_CONTINUE; 872 } 873 874 /* 875 * This should be true for injected/management frames only, for 876 * management frames we have set the IEEE80211_TX_CTL_ASSIGN_SEQ 877 * above since they are not QoS-data frames. 878 */ 879 if (!tx->sta) 880 return TX_CONTINUE; 881 882 /* include per-STA, per-TID sequence counter */ 883 tid = ieee80211_get_tid(hdr); 884 tx->sta->deflink.tx_stats.msdu[tid]++; 885 886 hdr->seq_ctrl = ieee80211_tx_next_seq(tx->sta, tid); 887 888 return TX_CONTINUE; 889 } 890 891 static int ieee80211_fragment(struct ieee80211_tx_data *tx, 892 struct sk_buff *skb, int hdrlen, 893 int frag_threshold) 894 { 895 struct ieee80211_local *local = tx->local; 896 struct ieee80211_tx_info *info; 897 struct sk_buff *tmp; 898 int per_fragm = frag_threshold - hdrlen - FCS_LEN; 899 int pos = hdrlen + per_fragm; 900 int rem = skb->len - hdrlen - per_fragm; 901 902 if (WARN_ON(rem < 0)) 903 return -EINVAL; 904 905 /* first fragment was already added to queue by caller */ 906 907 while (rem) { 908 int fraglen = per_fragm; 909 910 if (fraglen > rem) 911 fraglen = rem; 912 rem -= fraglen; 913 tmp = dev_alloc_skb(local->tx_headroom + 914 frag_threshold + 915 IEEE80211_ENCRYPT_HEADROOM + 916 IEEE80211_ENCRYPT_TAILROOM); 917 if (!tmp) 918 return -ENOMEM; 919 920 __skb_queue_tail(&tx->skbs, tmp); 921 922 skb_reserve(tmp, 923 local->tx_headroom + IEEE80211_ENCRYPT_HEADROOM); 924 925 /* copy control information */ 926 memcpy(tmp->cb, skb->cb, sizeof(tmp->cb)); 927 928 info = IEEE80211_SKB_CB(tmp); 929 info->flags &= ~(IEEE80211_TX_CTL_CLEAR_PS_FILT | 930 IEEE80211_TX_CTL_FIRST_FRAGMENT); 931 932 if (rem) 933 info->flags |= IEEE80211_TX_CTL_MORE_FRAMES; 934 935 skb_copy_queue_mapping(tmp, skb); 936 tmp->priority = skb->priority; 937 tmp->dev = skb->dev; 938 939 /* copy header and data */ 940 skb_put_data(tmp, skb->data, hdrlen); 941 skb_put_data(tmp, skb->data + pos, fraglen); 942 943 pos += fraglen; 944 } 945 946 /* adjust first fragment's length */ 947 skb_trim(skb, hdrlen + per_fragm); 948 return 0; 949 } 950 951 static ieee80211_tx_result debug_noinline 952 ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx) 953 { 954 struct sk_buff *skb = tx->skb; 955 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 956 struct ieee80211_hdr *hdr = (void *)skb->data; 957 int frag_threshold = tx->local->hw.wiphy->frag_threshold; 958 int hdrlen; 959 int fragnum; 960 961 /* no matter what happens, tx->skb moves to tx->skbs */ 962 __skb_queue_tail(&tx->skbs, skb); 963 tx->skb = NULL; 964 965 if (info->flags & IEEE80211_TX_CTL_DONTFRAG) 966 return TX_CONTINUE; 967 968 if (ieee80211_hw_check(&tx->local->hw, SUPPORTS_TX_FRAG)) 969 return TX_CONTINUE; 970 971 /* 972 * Warn when submitting a fragmented A-MPDU frame and drop it. 973 * This scenario is handled in ieee80211_tx_prepare but extra 974 * caution taken here as fragmented ampdu may cause Tx stop. 975 */ 976 if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU)) 977 return TX_DROP; 978 979 hdrlen = ieee80211_hdrlen(hdr->frame_control); 980 981 /* internal error, why isn't DONTFRAG set? */ 982 if (WARN_ON(skb->len + FCS_LEN <= frag_threshold)) 983 return TX_DROP; 984 985 /* 986 * Now fragment the frame. This will allocate all the fragments and 987 * chain them (using skb as the first fragment) to skb->next. 988 * During transmission, we will remove the successfully transmitted 989 * fragments from this list. When the low-level driver rejects one 990 * of the fragments then we will simply pretend to accept the skb 991 * but store it away as pending. 992 */ 993 if (ieee80211_fragment(tx, skb, hdrlen, frag_threshold)) 994 return TX_DROP; 995 996 /* update duration/seq/flags of fragments */ 997 fragnum = 0; 998 999 skb_queue_walk(&tx->skbs, skb) { 1000 const __le16 morefrags = cpu_to_le16(IEEE80211_FCTL_MOREFRAGS); 1001 1002 hdr = (void *)skb->data; 1003 info = IEEE80211_SKB_CB(skb); 1004 1005 if (!skb_queue_is_last(&tx->skbs, skb)) { 1006 hdr->frame_control |= morefrags; 1007 /* 1008 * No multi-rate retries for fragmented frames, that 1009 * would completely throw off the NAV at other STAs. 1010 */ 1011 info->control.rates[1].idx = -1; 1012 info->control.rates[2].idx = -1; 1013 info->control.rates[3].idx = -1; 1014 BUILD_BUG_ON(IEEE80211_TX_MAX_RATES != 4); 1015 info->flags &= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE; 1016 } else { 1017 hdr->frame_control &= ~morefrags; 1018 } 1019 hdr->seq_ctrl |= cpu_to_le16(fragnum & IEEE80211_SCTL_FRAG); 1020 fragnum++; 1021 } 1022 1023 return TX_CONTINUE; 1024 } 1025 1026 static ieee80211_tx_result debug_noinline 1027 ieee80211_tx_h_stats(struct ieee80211_tx_data *tx) 1028 { 1029 struct sk_buff *skb; 1030 int ac = -1; 1031 1032 if (!tx->sta) 1033 return TX_CONTINUE; 1034 1035 skb_queue_walk(&tx->skbs, skb) { 1036 ac = skb_get_queue_mapping(skb); 1037 tx->sta->deflink.tx_stats.bytes[ac] += skb->len; 1038 } 1039 if (ac >= 0) 1040 tx->sta->deflink.tx_stats.packets[ac]++; 1041 1042 return TX_CONTINUE; 1043 } 1044 1045 static ieee80211_tx_result debug_noinline 1046 ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx) 1047 { 1048 if (!tx->key) 1049 return TX_CONTINUE; 1050 1051 switch (tx->key->conf.cipher) { 1052 case WLAN_CIPHER_SUITE_WEP40: 1053 case WLAN_CIPHER_SUITE_WEP104: 1054 return ieee80211_crypto_wep_encrypt(tx); 1055 case WLAN_CIPHER_SUITE_TKIP: 1056 return ieee80211_crypto_tkip_encrypt(tx); 1057 case WLAN_CIPHER_SUITE_CCMP: 1058 return ieee80211_crypto_ccmp_encrypt( 1059 tx, IEEE80211_CCMP_MIC_LEN); 1060 case WLAN_CIPHER_SUITE_CCMP_256: 1061 return ieee80211_crypto_ccmp_encrypt( 1062 tx, IEEE80211_CCMP_256_MIC_LEN); 1063 case WLAN_CIPHER_SUITE_AES_CMAC: 1064 return ieee80211_crypto_aes_cmac_encrypt( 1065 tx, IEEE80211_CMAC_128_MIC_LEN); 1066 case WLAN_CIPHER_SUITE_BIP_CMAC_256: 1067 return ieee80211_crypto_aes_cmac_encrypt( 1068 tx, IEEE80211_CMAC_256_MIC_LEN); 1069 case WLAN_CIPHER_SUITE_BIP_GMAC_128: 1070 case WLAN_CIPHER_SUITE_BIP_GMAC_256: 1071 return ieee80211_crypto_aes_gmac_encrypt(tx); 1072 case WLAN_CIPHER_SUITE_GCMP: 1073 case WLAN_CIPHER_SUITE_GCMP_256: 1074 return ieee80211_crypto_gcmp_encrypt(tx); 1075 } 1076 1077 return TX_DROP; 1078 } 1079 1080 static ieee80211_tx_result debug_noinline 1081 ieee80211_tx_h_calculate_duration(struct ieee80211_tx_data *tx) 1082 { 1083 struct sk_buff *skb; 1084 struct ieee80211_hdr *hdr; 1085 int next_len; 1086 bool group_addr; 1087 1088 skb_queue_walk(&tx->skbs, skb) { 1089 hdr = (void *) skb->data; 1090 if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) 1091 break; /* must not overwrite AID */ 1092 if (!skb_queue_is_last(&tx->skbs, skb)) { 1093 struct sk_buff *next = skb_queue_next(&tx->skbs, skb); 1094 next_len = next->len; 1095 } else 1096 next_len = 0; 1097 group_addr = is_multicast_ether_addr(hdr->addr1); 1098 1099 hdr->duration_id = 1100 ieee80211_duration(tx, skb, group_addr, next_len); 1101 } 1102 1103 return TX_CONTINUE; 1104 } 1105 1106 /* actual transmit path */ 1107 1108 static bool ieee80211_tx_prep_agg(struct ieee80211_tx_data *tx, 1109 struct sk_buff *skb, 1110 struct ieee80211_tx_info *info, 1111 struct tid_ampdu_tx *tid_tx, 1112 int tid) 1113 { 1114 bool queued = false; 1115 bool reset_agg_timer = false; 1116 struct sk_buff *purge_skb = NULL; 1117 1118 if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) { 1119 reset_agg_timer = true; 1120 } else if (test_bit(HT_AGG_STATE_WANT_START, &tid_tx->state)) { 1121 /* 1122 * nothing -- this aggregation session is being started 1123 * but that might still fail with the driver 1124 */ 1125 } else if (!tx->sta->sta.txq[tid]) { 1126 spin_lock(&tx->sta->lock); 1127 /* 1128 * Need to re-check now, because we may get here 1129 * 1130 * 1) in the window during which the setup is actually 1131 * already done, but not marked yet because not all 1132 * packets are spliced over to the driver pending 1133 * queue yet -- if this happened we acquire the lock 1134 * either before or after the splice happens, but 1135 * need to recheck which of these cases happened. 1136 * 1137 * 2) during session teardown, if the OPERATIONAL bit 1138 * was cleared due to the teardown but the pointer 1139 * hasn't been assigned NULL yet (or we loaded it 1140 * before it was assigned) -- in this case it may 1141 * now be NULL which means we should just let the 1142 * packet pass through because splicing the frames 1143 * back is already done. 1144 */ 1145 tid_tx = rcu_dereference_protected_tid_tx(tx->sta, tid); 1146 1147 if (!tid_tx) { 1148 /* do nothing, let packet pass through */ 1149 } else if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) { 1150 reset_agg_timer = true; 1151 } else { 1152 queued = true; 1153 if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER) { 1154 clear_sta_flag(tx->sta, WLAN_STA_SP); 1155 ps_dbg(tx->sta->sdata, 1156 "STA %pM aid %d: SP frame queued, close the SP w/o telling the peer\n", 1157 tx->sta->sta.addr, tx->sta->sta.aid); 1158 } 1159 info->control.vif = &tx->sdata->vif; 1160 info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING; 1161 info->flags &= ~IEEE80211_TX_TEMPORARY_FLAGS; 1162 __skb_queue_tail(&tid_tx->pending, skb); 1163 if (skb_queue_len(&tid_tx->pending) > STA_MAX_TX_BUFFER) 1164 purge_skb = __skb_dequeue(&tid_tx->pending); 1165 } 1166 spin_unlock(&tx->sta->lock); 1167 1168 if (purge_skb) 1169 ieee80211_free_txskb(&tx->local->hw, purge_skb); 1170 } 1171 1172 /* reset session timer */ 1173 if (reset_agg_timer) 1174 tid_tx->last_tx = jiffies; 1175 1176 return queued; 1177 } 1178 1179 void ieee80211_aggr_check(struct ieee80211_sub_if_data *sdata, 1180 struct sta_info *sta, struct sk_buff *skb) 1181 { 1182 struct rate_control_ref *ref = sdata->local->rate_ctrl; 1183 u16 tid; 1184 1185 if (!ref || !(ref->ops->capa & RATE_CTRL_CAPA_AMPDU_TRIGGER)) 1186 return; 1187 1188 if (!sta || 1189 (!sta->sta.valid_links && !sta->sta.deflink.ht_cap.ht_supported && 1190 !sta->sta.deflink.s1g_cap.s1g) || 1191 !sta->sta.wme || skb_get_queue_mapping(skb) == IEEE80211_AC_VO || 1192 skb->protocol == sdata->control_port_protocol) 1193 return; 1194 1195 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK; 1196 if (likely(sta->ampdu_mlme.tid_tx[tid])) 1197 return; 1198 1199 ieee80211_start_tx_ba_session(&sta->sta, tid, 0); 1200 } 1201 1202 /* 1203 * initialises @tx 1204 * pass %NULL for the station if unknown, a valid pointer if known 1205 * or an ERR_PTR() if the station is known not to exist 1206 */ 1207 static ieee80211_tx_result 1208 ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata, 1209 struct ieee80211_tx_data *tx, 1210 struct sta_info *sta, struct sk_buff *skb) 1211 { 1212 struct ieee80211_local *local = sdata->local; 1213 struct ieee80211_hdr *hdr; 1214 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1215 bool aggr_check = false; 1216 int tid; 1217 1218 memset(tx, 0, sizeof(*tx)); 1219 tx->skb = skb; 1220 tx->local = local; 1221 tx->sdata = sdata; 1222 __skb_queue_head_init(&tx->skbs); 1223 1224 /* 1225 * If this flag is set to true anywhere, and we get here, 1226 * we are doing the needed processing, so remove the flag 1227 * now. 1228 */ 1229 info->control.flags &= ~IEEE80211_TX_INTCFL_NEED_TXPROCESSING; 1230 1231 hdr = (struct ieee80211_hdr *) skb->data; 1232 1233 if (likely(sta)) { 1234 if (!IS_ERR(sta)) 1235 tx->sta = sta; 1236 } else { 1237 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) { 1238 tx->sta = rcu_dereference(sdata->u.vlan.sta); 1239 if (!tx->sta && sdata->wdev.use_4addr) 1240 return TX_DROP; 1241 } else if (tx->sdata->control_port_protocol == tx->skb->protocol) { 1242 tx->sta = sta_info_get_bss(sdata, hdr->addr1); 1243 } 1244 if (!tx->sta && !is_multicast_ether_addr(hdr->addr1)) { 1245 tx->sta = sta_info_get(sdata, hdr->addr1); 1246 aggr_check = true; 1247 } 1248 } 1249 1250 if (tx->sta && ieee80211_is_data_qos(hdr->frame_control) && 1251 !ieee80211_is_qos_nullfunc(hdr->frame_control) && 1252 ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) && 1253 !ieee80211_hw_check(&local->hw, TX_AMPDU_SETUP_IN_HW)) { 1254 struct tid_ampdu_tx *tid_tx; 1255 1256 tid = ieee80211_get_tid(hdr); 1257 tid_tx = rcu_dereference(tx->sta->ampdu_mlme.tid_tx[tid]); 1258 if (!tid_tx && aggr_check) { 1259 ieee80211_aggr_check(sdata, tx->sta, skb); 1260 tid_tx = rcu_dereference(tx->sta->ampdu_mlme.tid_tx[tid]); 1261 } 1262 1263 if (tid_tx) { 1264 bool queued; 1265 1266 queued = ieee80211_tx_prep_agg(tx, skb, info, 1267 tid_tx, tid); 1268 1269 if (unlikely(queued)) 1270 return TX_QUEUED; 1271 } 1272 } 1273 1274 if (is_multicast_ether_addr(hdr->addr1)) { 1275 tx->flags &= ~IEEE80211_TX_UNICAST; 1276 info->flags |= IEEE80211_TX_CTL_NO_ACK; 1277 } else 1278 tx->flags |= IEEE80211_TX_UNICAST; 1279 1280 if (!(info->flags & IEEE80211_TX_CTL_DONTFRAG)) { 1281 if (!(tx->flags & IEEE80211_TX_UNICAST) || 1282 skb->len + FCS_LEN <= local->hw.wiphy->frag_threshold || 1283 info->flags & IEEE80211_TX_CTL_AMPDU) 1284 info->flags |= IEEE80211_TX_CTL_DONTFRAG; 1285 } 1286 1287 if (!tx->sta) 1288 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT; 1289 else if (test_and_clear_sta_flag(tx->sta, WLAN_STA_CLEAR_PS_FILT)) { 1290 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT; 1291 ieee80211_check_fast_xmit(tx->sta); 1292 } 1293 1294 info->flags |= IEEE80211_TX_CTL_FIRST_FRAGMENT; 1295 1296 return TX_CONTINUE; 1297 } 1298 1299 static struct txq_info *ieee80211_get_txq(struct ieee80211_local *local, 1300 struct ieee80211_vif *vif, 1301 struct sta_info *sta, 1302 struct sk_buff *skb) 1303 { 1304 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 1305 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1306 struct ieee80211_txq *txq = NULL; 1307 1308 if ((info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) || 1309 (info->control.flags & IEEE80211_TX_CTRL_PS_RESPONSE)) 1310 return NULL; 1311 1312 /* 1313 * While (re)association request/response frames are not considered 1314 * bufferable MMPDUs, use the TXQ abstraction for the transmission of 1315 * these frames. This is specifically useful for drivers that might 1316 * associate other resources with the TXQ, e.g., encryption keys etc. 1317 */ 1318 if (!(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) && 1319 unlikely(!ieee80211_is_data_present(hdr->frame_control))) { 1320 if ((!ieee80211_is_mgmt(hdr->frame_control) || 1321 ieee80211_is_bufferable_mmpdu(skb) || 1322 ieee80211_is_assoc(hdr->frame_control) || 1323 vif->type == NL80211_IFTYPE_STATION || 1324 vif->type == NL80211_IFTYPE_NAN || 1325 vif->type == NL80211_IFTYPE_NAN_DATA) && 1326 sta && sta->uploaded) { 1327 /* 1328 * This will be NULL if the driver didn't set the 1329 * opt-in hardware flag. 1330 */ 1331 txq = sta->sta.txq[IEEE80211_NUM_TIDS]; 1332 } else if ((!ieee80211_is_mgmt(hdr->frame_control) || 1333 ieee80211_is_bufferable_mmpdu(skb)) && 1334 !sta) { 1335 txq = vif->txq_mgmt; 1336 } 1337 } else if (sta) { 1338 u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK; 1339 1340 if (!sta->uploaded) 1341 return NULL; 1342 1343 txq = sta->sta.txq[tid]; 1344 } else { 1345 txq = vif->txq; 1346 } 1347 1348 if (!txq) 1349 return NULL; 1350 1351 return to_txq_info(txq); 1352 } 1353 1354 static void ieee80211_set_skb_enqueue_time(struct sk_buff *skb) 1355 { 1356 struct sk_buff *next; 1357 codel_time_t now = codel_get_time(); 1358 1359 skb_list_walk_safe(skb, skb, next) 1360 IEEE80211_SKB_CB(skb)->control.enqueue_time = now; 1361 } 1362 1363 static u32 codel_skb_len_func(const struct sk_buff *skb) 1364 { 1365 return skb->len; 1366 } 1367 1368 static codel_time_t codel_skb_time_func(const struct sk_buff *skb) 1369 { 1370 const struct ieee80211_tx_info *info; 1371 1372 info = (const struct ieee80211_tx_info *)skb->cb; 1373 return info->control.enqueue_time; 1374 } 1375 1376 static struct sk_buff *codel_dequeue_func(struct codel_vars *cvars, 1377 void *ctx) 1378 { 1379 struct ieee80211_local *local; 1380 struct txq_info *txqi; 1381 struct fq *fq; 1382 struct fq_flow *flow; 1383 1384 txqi = ctx; 1385 local = vif_to_sdata(txqi->txq.vif)->local; 1386 fq = &local->fq; 1387 1388 if (cvars == &txqi->def_cvars) 1389 flow = &txqi->tin.default_flow; 1390 else 1391 flow = &fq->flows[cvars - local->cvars]; 1392 1393 return fq_flow_dequeue(fq, flow); 1394 } 1395 1396 static void codel_drop_func(struct sk_buff *skb, 1397 void *ctx) 1398 { 1399 struct ieee80211_local *local; 1400 struct ieee80211_hw *hw; 1401 struct txq_info *txqi; 1402 1403 txqi = ctx; 1404 local = vif_to_sdata(txqi->txq.vif)->local; 1405 hw = &local->hw; 1406 1407 ieee80211_free_txskb(hw, skb); 1408 } 1409 1410 static struct sk_buff *fq_tin_dequeue_func(struct fq *fq, 1411 struct fq_tin *tin, 1412 struct fq_flow *flow) 1413 { 1414 struct ieee80211_local *local; 1415 struct txq_info *txqi; 1416 struct codel_vars *cvars; 1417 struct codel_params *cparams; 1418 struct codel_stats *cstats; 1419 1420 local = container_of(fq, struct ieee80211_local, fq); 1421 txqi = container_of(tin, struct txq_info, tin); 1422 cparams = &local->cparams; 1423 cstats = &txqi->cstats; 1424 1425 if (flow == &tin->default_flow) 1426 cvars = &txqi->def_cvars; 1427 else 1428 cvars = &local->cvars[flow - fq->flows]; 1429 1430 return codel_dequeue(txqi, 1431 &flow->backlog, 1432 cparams, 1433 cvars, 1434 cstats, 1435 codel_skb_len_func, 1436 codel_skb_time_func, 1437 codel_drop_func, 1438 codel_dequeue_func); 1439 } 1440 1441 static void fq_skb_free_func(struct fq *fq, 1442 struct fq_tin *tin, 1443 struct fq_flow *flow, 1444 struct sk_buff *skb) 1445 { 1446 struct ieee80211_local *local; 1447 1448 local = container_of(fq, struct ieee80211_local, fq); 1449 ieee80211_free_txskb(&local->hw, skb); 1450 } 1451 1452 static void ieee80211_txq_enqueue(struct ieee80211_local *local, 1453 struct txq_info *txqi, 1454 struct sk_buff *skb) 1455 { 1456 struct fq *fq = &local->fq; 1457 struct fq_tin *tin = &txqi->tin; 1458 u32 flow_idx; 1459 1460 ieee80211_set_skb_enqueue_time(skb); 1461 1462 spin_lock_bh(&fq->lock); 1463 /* 1464 * For management frames, don't really apply codel etc., 1465 * we don't want to apply any shaping or anything we just 1466 * want to simplify the driver API by having them on the 1467 * txqi. 1468 */ 1469 if (unlikely(txqi->txq.tid == IEEE80211_NUM_TIDS)) { 1470 IEEE80211_SKB_CB(skb)->control.flags |= 1471 IEEE80211_TX_INTCFL_NEED_TXPROCESSING; 1472 __skb_queue_tail(&txqi->frags, skb); 1473 } else { 1474 flow_idx = fq_flow_idx(fq, skb); 1475 fq_tin_enqueue(fq, tin, flow_idx, skb, 1476 fq_skb_free_func); 1477 } 1478 spin_unlock_bh(&fq->lock); 1479 } 1480 1481 static bool fq_vlan_filter_func(struct fq *fq, struct fq_tin *tin, 1482 struct fq_flow *flow, struct sk_buff *skb, 1483 void *data) 1484 { 1485 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1486 1487 return info->control.vif == data; 1488 } 1489 1490 void ieee80211_txq_remove_vlan(struct ieee80211_local *local, 1491 struct ieee80211_sub_if_data *sdata) 1492 { 1493 struct fq *fq = &local->fq; 1494 struct txq_info *txqi; 1495 struct fq_tin *tin; 1496 struct ieee80211_sub_if_data *ap; 1497 1498 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_AP_VLAN)) 1499 return; 1500 1501 ap = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap); 1502 1503 if (!ap->vif.txq) 1504 return; 1505 1506 txqi = to_txq_info(ap->vif.txq); 1507 tin = &txqi->tin; 1508 1509 spin_lock_bh(&fq->lock); 1510 fq_tin_filter(fq, tin, fq_vlan_filter_func, &sdata->vif, 1511 fq_skb_free_func); 1512 spin_unlock_bh(&fq->lock); 1513 } 1514 1515 void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata, 1516 struct sta_info *sta, 1517 struct txq_info *txqi, int tid) 1518 { 1519 fq_tin_init(&txqi->tin); 1520 codel_vars_init(&txqi->def_cvars); 1521 codel_stats_init(&txqi->cstats); 1522 __skb_queue_head_init(&txqi->frags); 1523 INIT_LIST_HEAD(&txqi->schedule_order); 1524 1525 txqi->txq.vif = &sdata->vif; 1526 1527 if (!sta) { 1528 txqi->txq.tid = tid; 1529 1530 if (tid == IEEE80211_NUM_TIDS) { 1531 sdata->vif.txq_mgmt = &txqi->txq; 1532 txqi->txq.ac = IEEE80211_AC_VO; 1533 } else { 1534 sdata->vif.txq = &txqi->txq; 1535 txqi->txq.ac = IEEE80211_AC_BE; 1536 } 1537 1538 return; 1539 } 1540 1541 if (tid == IEEE80211_NUM_TIDS) { 1542 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 1543 /* Drivers need to opt in to the management MPDU TXQ */ 1544 if (!ieee80211_hw_check(&sdata->local->hw, 1545 STA_MMPDU_TXQ)) 1546 return; 1547 } else if (!ieee80211_hw_check(&sdata->local->hw, 1548 BUFF_MMPDU_TXQ)) { 1549 /* Drivers need to opt in to the bufferable MMPDU TXQ */ 1550 return; 1551 } 1552 txqi->txq.ac = IEEE80211_AC_VO; 1553 } else { 1554 txqi->txq.ac = ieee80211_ac_from_tid(tid); 1555 } 1556 1557 txqi->txq.sta = &sta->sta; 1558 txqi->txq.tid = tid; 1559 sta->sta.txq[tid] = &txqi->txq; 1560 } 1561 1562 void ieee80211_txq_purge(struct ieee80211_local *local, 1563 struct txq_info *txqi) 1564 { 1565 struct fq *fq = &local->fq; 1566 struct fq_tin *tin = &txqi->tin; 1567 1568 spin_lock_bh(&fq->lock); 1569 fq_tin_reset(fq, tin, fq_skb_free_func); 1570 ieee80211_purge_tx_queue(&local->hw, &txqi->frags); 1571 spin_unlock_bh(&fq->lock); 1572 1573 spin_lock_bh(&local->active_txq_lock[txqi->txq.ac]); 1574 list_del_init(&txqi->schedule_order); 1575 spin_unlock_bh(&local->active_txq_lock[txqi->txq.ac]); 1576 } 1577 1578 void ieee80211_txq_set_params(struct ieee80211_local *local, int radio_idx) 1579 { 1580 if (local->hw.wiphy->txq_limit) 1581 local->fq.limit = local->hw.wiphy->txq_limit; 1582 else 1583 local->hw.wiphy->txq_limit = local->fq.limit; 1584 1585 if (local->hw.wiphy->txq_memory_limit) 1586 local->fq.memory_limit = local->hw.wiphy->txq_memory_limit; 1587 else 1588 local->hw.wiphy->txq_memory_limit = local->fq.memory_limit; 1589 1590 if (local->hw.wiphy->txq_quantum) 1591 local->fq.quantum = local->hw.wiphy->txq_quantum; 1592 else 1593 local->hw.wiphy->txq_quantum = local->fq.quantum; 1594 } 1595 1596 int ieee80211_txq_setup_flows(struct ieee80211_local *local) 1597 { 1598 struct fq *fq = &local->fq; 1599 int ret; 1600 int i; 1601 bool supp_vht = false; 1602 enum nl80211_band band; 1603 1604 ret = fq_init(fq, 4096); 1605 if (ret) 1606 return ret; 1607 1608 /* 1609 * If the hardware doesn't support VHT, it is safe to limit the maximum 1610 * queue size. 4 Mbytes is 64 max-size aggregates in 802.11n. 1611 */ 1612 for (band = 0; band < NUM_NL80211_BANDS; band++) { 1613 struct ieee80211_supported_band *sband; 1614 1615 sband = local->hw.wiphy->bands[band]; 1616 if (!sband) 1617 continue; 1618 1619 supp_vht = supp_vht || sband->vht_cap.vht_supported; 1620 } 1621 1622 if (!supp_vht) 1623 fq->memory_limit = 4 << 20; /* 4 Mbytes */ 1624 1625 codel_params_init(&local->cparams); 1626 local->cparams.interval = MS2TIME(100); 1627 local->cparams.target = MS2TIME(20); 1628 local->cparams.ecn = true; 1629 1630 local->cvars = kvzalloc_objs(local->cvars[0], fq->flows_cnt); 1631 if (!local->cvars) { 1632 spin_lock_bh(&fq->lock); 1633 fq_reset(fq, fq_skb_free_func); 1634 spin_unlock_bh(&fq->lock); 1635 return -ENOMEM; 1636 } 1637 1638 for (i = 0; i < fq->flows_cnt; i++) 1639 codel_vars_init(&local->cvars[i]); 1640 1641 ieee80211_txq_set_params(local, -1); 1642 1643 return 0; 1644 } 1645 1646 void ieee80211_txq_teardown_flows(struct ieee80211_local *local) 1647 { 1648 struct fq *fq = &local->fq; 1649 1650 kvfree(local->cvars); 1651 local->cvars = NULL; 1652 1653 spin_lock_bh(&fq->lock); 1654 fq_reset(fq, fq_skb_free_func); 1655 spin_unlock_bh(&fq->lock); 1656 } 1657 1658 static bool ieee80211_queue_skb(struct ieee80211_local *local, 1659 struct ieee80211_sub_if_data *sdata, 1660 struct sta_info *sta, 1661 struct sk_buff *skb) 1662 { 1663 struct ieee80211_vif *vif; 1664 struct txq_info *txqi; 1665 1666 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) 1667 return false; 1668 1669 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) 1670 sdata = container_of(sdata->bss, 1671 struct ieee80211_sub_if_data, u.ap); 1672 1673 vif = &sdata->vif; 1674 txqi = ieee80211_get_txq(local, vif, sta, skb); 1675 1676 if (!txqi) 1677 return false; 1678 1679 ieee80211_txq_enqueue(local, txqi, skb); 1680 1681 schedule_and_wake_txq(local, txqi); 1682 1683 return true; 1684 } 1685 1686 static bool ieee80211_tx_frags(struct ieee80211_local *local, 1687 struct ieee80211_vif *vif, 1688 struct sta_info *sta, 1689 struct sk_buff_head *skbs, 1690 bool txpending) 1691 { 1692 struct ieee80211_tx_control control = {}; 1693 struct sk_buff *skb, *tmp; 1694 unsigned long flags; 1695 1696 skb_queue_walk_safe(skbs, skb, tmp) { 1697 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1698 int q = info->hw_queue; 1699 1700 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG 1701 if (WARN_ON_ONCE(q >= local->hw.queues)) { 1702 __skb_unlink(skb, skbs); 1703 ieee80211_free_txskb(&local->hw, skb); 1704 continue; 1705 } 1706 #endif 1707 1708 spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 1709 if (local->queue_stop_reasons[q] || 1710 (!txpending && !skb_queue_empty(&local->pending[q]))) { 1711 if (unlikely(info->flags & 1712 IEEE80211_TX_INTFL_OFFCHAN_TX_OK)) { 1713 if (local->queue_stop_reasons[q] & 1714 ~BIT(IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL)) { 1715 /* 1716 * Drop off-channel frames if queues 1717 * are stopped for any reason other 1718 * than off-channel operation. Never 1719 * queue them. 1720 */ 1721 spin_unlock_irqrestore( 1722 &local->queue_stop_reason_lock, 1723 flags); 1724 ieee80211_purge_tx_queue(&local->hw, 1725 skbs); 1726 return true; 1727 } 1728 } else { 1729 1730 /* 1731 * Since queue is stopped, queue up frames for 1732 * later transmission from the tx-pending 1733 * tasklet when the queue is woken again. 1734 */ 1735 if (txpending) 1736 skb_queue_splice_init(skbs, 1737 &local->pending[q]); 1738 else 1739 skb_queue_splice_tail_init(skbs, 1740 &local->pending[q]); 1741 1742 spin_unlock_irqrestore(&local->queue_stop_reason_lock, 1743 flags); 1744 return false; 1745 } 1746 } 1747 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 1748 1749 info->control.vif = vif; 1750 control.sta = sta ? &sta->sta : NULL; 1751 1752 __skb_unlink(skb, skbs); 1753 drv_tx(local, &control, skb); 1754 } 1755 1756 return true; 1757 } 1758 1759 /* 1760 * Returns false if the frame couldn't be transmitted but was queued instead. 1761 */ 1762 static bool __ieee80211_tx(struct ieee80211_local *local, 1763 struct sk_buff_head *skbs, struct sta_info *sta, 1764 bool txpending) 1765 { 1766 struct ieee80211_tx_info *info; 1767 struct ieee80211_sub_if_data *sdata; 1768 struct ieee80211_vif *vif; 1769 struct sk_buff *skb; 1770 bool result; 1771 1772 if (WARN_ON(skb_queue_empty(skbs))) 1773 return true; 1774 1775 skb = skb_peek(skbs); 1776 info = IEEE80211_SKB_CB(skb); 1777 sdata = vif_to_sdata(info->control.vif); 1778 if (sta && !sta->uploaded) 1779 sta = NULL; 1780 1781 switch (sdata->vif.type) { 1782 case NL80211_IFTYPE_MONITOR: 1783 if ((sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) || 1784 ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR)) { 1785 vif = &sdata->vif; 1786 break; 1787 } 1788 sdata = rcu_dereference(local->monitor_sdata); 1789 if (sdata && ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF)) { 1790 vif = &sdata->vif; 1791 info->hw_queue = 1792 vif->hw_queue[skb_get_queue_mapping(skb)]; 1793 } else if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) { 1794 ieee80211_purge_tx_queue(&local->hw, skbs); 1795 return true; 1796 } else 1797 vif = NULL; 1798 break; 1799 case NL80211_IFTYPE_AP_VLAN: 1800 sdata = container_of(sdata->bss, 1801 struct ieee80211_sub_if_data, u.ap); 1802 fallthrough; 1803 default: 1804 vif = &sdata->vif; 1805 break; 1806 } 1807 1808 result = ieee80211_tx_frags(local, vif, sta, skbs, txpending); 1809 1810 WARN_ON_ONCE(!skb_queue_empty(skbs)); 1811 1812 return result; 1813 } 1814 1815 /* 1816 * Invoke TX handlers, return 0 on success and non-zero if the 1817 * frame was dropped or queued. 1818 * 1819 * The handlers are split into an early and late part. The latter is everything 1820 * that can be sensitive to reordering, and will be deferred to after packets 1821 * are dequeued from the intermediate queues (when they are enabled). 1822 */ 1823 static int invoke_tx_handlers_early(struct ieee80211_tx_data *tx) 1824 { 1825 ieee80211_tx_result res = TX_DROP; 1826 1827 #define CALL_TXH(txh) \ 1828 do { \ 1829 res = txh(tx); \ 1830 if (res != TX_CONTINUE) \ 1831 goto txh_done; \ 1832 } while (0) 1833 1834 CALL_TXH(ieee80211_tx_h_dynamic_ps); 1835 CALL_TXH(ieee80211_tx_h_check_assoc); 1836 CALL_TXH(ieee80211_tx_h_ps_buf); 1837 CALL_TXH(ieee80211_tx_h_check_control_port_protocol); 1838 CALL_TXH(ieee80211_tx_h_select_key); 1839 1840 txh_done: 1841 if (unlikely(res == TX_DROP)) { 1842 tx->sdata->tx_handlers_drop++; 1843 if (tx->skb) 1844 ieee80211_free_txskb(&tx->local->hw, tx->skb); 1845 else 1846 ieee80211_purge_tx_queue(&tx->local->hw, &tx->skbs); 1847 return -1; 1848 } else if (unlikely(res == TX_QUEUED)) { 1849 I802_DEBUG_INC(tx->local->tx_handlers_queued); 1850 return -1; 1851 } 1852 1853 return 0; 1854 } 1855 1856 /* 1857 * Late handlers can be called while the sta lock is held. Handlers that can 1858 * cause packets to be generated will cause deadlock! 1859 */ 1860 static int invoke_tx_handlers_late(struct ieee80211_tx_data *tx) 1861 { 1862 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 1863 ieee80211_tx_result res = TX_CONTINUE; 1864 1865 if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL)) 1866 CALL_TXH(ieee80211_tx_h_rate_ctrl); 1867 1868 if (unlikely(info->flags & IEEE80211_TX_INTFL_RETRANSMISSION)) { 1869 __skb_queue_tail(&tx->skbs, tx->skb); 1870 tx->skb = NULL; 1871 goto txh_done; 1872 } 1873 1874 CALL_TXH(ieee80211_tx_h_michael_mic_add); 1875 CALL_TXH(ieee80211_tx_h_sequence); 1876 CALL_TXH(ieee80211_tx_h_fragment); 1877 /* handlers after fragment must be aware of tx info fragmentation! */ 1878 CALL_TXH(ieee80211_tx_h_stats); 1879 CALL_TXH(ieee80211_tx_h_encrypt); 1880 if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL)) 1881 CALL_TXH(ieee80211_tx_h_calculate_duration); 1882 #undef CALL_TXH 1883 1884 txh_done: 1885 if (unlikely(res == TX_DROP)) { 1886 tx->sdata->tx_handlers_drop++; 1887 if (tx->skb) 1888 ieee80211_free_txskb(&tx->local->hw, tx->skb); 1889 else 1890 ieee80211_purge_tx_queue(&tx->local->hw, &tx->skbs); 1891 return -1; 1892 } else if (unlikely(res == TX_QUEUED)) { 1893 I802_DEBUG_INC(tx->local->tx_handlers_queued); 1894 return -1; 1895 } 1896 1897 return 0; 1898 } 1899 1900 static int invoke_tx_handlers(struct ieee80211_tx_data *tx) 1901 { 1902 int r = invoke_tx_handlers_early(tx); 1903 1904 if (r) 1905 return r; 1906 return invoke_tx_handlers_late(tx); 1907 } 1908 1909 bool ieee80211_tx_prepare_skb(struct ieee80211_hw *hw, 1910 struct ieee80211_vif *vif, struct sk_buff *skb, 1911 int band, struct ieee80211_sta **sta) 1912 { 1913 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 1914 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1915 struct ieee80211_tx_data tx; 1916 struct sk_buff *skb2; 1917 1918 if (ieee80211_tx_prepare(sdata, &tx, NULL, skb) == TX_DROP) { 1919 kfree_skb(skb); 1920 return false; 1921 } 1922 1923 info->band = band; 1924 info->control.vif = vif; 1925 info->hw_queue = vif->hw_queue[skb_get_queue_mapping(skb)]; 1926 1927 if (invoke_tx_handlers(&tx)) 1928 return false; 1929 1930 if (sta) { 1931 if (tx.sta) 1932 *sta = &tx.sta->sta; 1933 else 1934 *sta = NULL; 1935 } 1936 1937 /* this function isn't suitable for fragmented data frames */ 1938 skb2 = __skb_dequeue(&tx.skbs); 1939 if (WARN_ON(skb2 != skb || !skb_queue_empty(&tx.skbs))) { 1940 ieee80211_free_txskb(hw, skb2); 1941 ieee80211_purge_tx_queue(hw, &tx.skbs); 1942 return false; 1943 } 1944 1945 return true; 1946 } 1947 EXPORT_SYMBOL(ieee80211_tx_prepare_skb); 1948 1949 /* 1950 * Returns false if the frame couldn't be transmitted but was queued instead. 1951 */ 1952 static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata, 1953 struct sta_info *sta, struct sk_buff *skb, 1954 bool txpending) 1955 { 1956 struct ieee80211_local *local = sdata->local; 1957 struct ieee80211_tx_data tx; 1958 ieee80211_tx_result res_prepare; 1959 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1960 bool result = true; 1961 1962 if (unlikely(skb->len < 10)) { 1963 dev_kfree_skb(skb); 1964 return true; 1965 } 1966 1967 /* initialises tx */ 1968 res_prepare = ieee80211_tx_prepare(sdata, &tx, sta, skb); 1969 1970 if (unlikely(res_prepare == TX_DROP)) { 1971 ieee80211_free_txskb(&local->hw, skb); 1972 tx.sdata->tx_handlers_drop++; 1973 return true; 1974 } else if (unlikely(res_prepare == TX_QUEUED)) { 1975 return true; 1976 } 1977 1978 /* set up hw_queue value early */ 1979 if (!(info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) || 1980 !ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) 1981 info->hw_queue = 1982 sdata->vif.hw_queue[skb_get_queue_mapping(skb)]; 1983 1984 if (invoke_tx_handlers_early(&tx)) 1985 return true; 1986 1987 if (ieee80211_queue_skb(local, sdata, tx.sta, tx.skb)) 1988 return true; 1989 1990 if (!invoke_tx_handlers_late(&tx)) 1991 result = __ieee80211_tx(local, &tx.skbs, tx.sta, txpending); 1992 1993 return result; 1994 } 1995 1996 /* device xmit handlers */ 1997 1998 enum ieee80211_encrypt { 1999 ENCRYPT_NO, 2000 ENCRYPT_MGMT, 2001 ENCRYPT_DATA, 2002 }; 2003 2004 static int ieee80211_skb_resize(struct ieee80211_sub_if_data *sdata, 2005 struct sk_buff *skb, 2006 int head_need, 2007 enum ieee80211_encrypt encrypt) 2008 { 2009 struct ieee80211_local *local = sdata->local; 2010 bool enc_tailroom; 2011 int tail_need = 0; 2012 2013 enc_tailroom = encrypt == ENCRYPT_MGMT || 2014 (encrypt == ENCRYPT_DATA && 2015 sdata->crypto_tx_tailroom_needed_cnt); 2016 2017 if (enc_tailroom) { 2018 tail_need = IEEE80211_ENCRYPT_TAILROOM; 2019 tail_need -= skb_tailroom(skb); 2020 tail_need = max_t(int, tail_need, 0); 2021 } 2022 2023 if (skb_cloned(skb) && 2024 (!ieee80211_hw_check(&local->hw, SUPPORTS_CLONED_SKBS) || 2025 !skb_clone_writable(skb, ETH_HLEN) || enc_tailroom)) 2026 I802_DEBUG_INC(local->tx_expand_skb_head_cloned); 2027 else if (head_need || tail_need) 2028 I802_DEBUG_INC(local->tx_expand_skb_head); 2029 else 2030 return 0; 2031 2032 if (pskb_expand_head(skb, head_need, tail_need, GFP_ATOMIC)) { 2033 wiphy_debug(local->hw.wiphy, 2034 "failed to reallocate TX buffer\n"); 2035 return -ENOMEM; 2036 } 2037 2038 return 0; 2039 } 2040 2041 void ieee80211_xmit(struct ieee80211_sub_if_data *sdata, 2042 struct sta_info *sta, struct sk_buff *skb) 2043 { 2044 struct ieee80211_local *local = sdata->local; 2045 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 2046 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 2047 int headroom; 2048 enum ieee80211_encrypt encrypt; 2049 2050 if (info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT) 2051 encrypt = ENCRYPT_NO; 2052 else if (ieee80211_is_mgmt(hdr->frame_control)) 2053 encrypt = ENCRYPT_MGMT; 2054 else 2055 encrypt = ENCRYPT_DATA; 2056 2057 headroom = local->tx_headroom; 2058 if (encrypt != ENCRYPT_NO) 2059 headroom += IEEE80211_ENCRYPT_HEADROOM; 2060 headroom -= skb_headroom(skb); 2061 headroom = max_t(int, 0, headroom); 2062 2063 if (ieee80211_skb_resize(sdata, skb, headroom, encrypt)) { 2064 ieee80211_free_txskb(&local->hw, skb); 2065 return; 2066 } 2067 2068 /* reload after potential resize */ 2069 hdr = (struct ieee80211_hdr *) skb->data; 2070 info->control.vif = &sdata->vif; 2071 2072 if (ieee80211_vif_is_mesh(&sdata->vif)) { 2073 if (ieee80211_is_data(hdr->frame_control) && 2074 is_unicast_ether_addr(hdr->addr1)) { 2075 if (mesh_nexthop_resolve(sdata, skb)) 2076 return; /* skb queued: don't free */ 2077 } else { 2078 ieee80211_mps_set_frame_flags(sdata, NULL, hdr); 2079 } 2080 } 2081 2082 ieee80211_set_qos_hdr(sdata, skb); 2083 ieee80211_tx(sdata, sta, skb, false); 2084 } 2085 2086 static bool ieee80211_validate_radiotap_len(struct sk_buff *skb) 2087 { 2088 struct ieee80211_radiotap_header *rthdr = 2089 (struct ieee80211_radiotap_header *)skb->data; 2090 2091 /* check for not even having the fixed radiotap header part */ 2092 if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header))) 2093 return false; /* too short to be possibly valid */ 2094 2095 /* is it a header version we can trust to find length from? */ 2096 if (unlikely(rthdr->it_version)) 2097 return false; /* only version 0 is supported */ 2098 2099 /* does the skb contain enough to deliver on the alleged length? */ 2100 if (unlikely(skb->len < ieee80211_get_radiotap_len(skb->data))) 2101 return false; /* skb too short for claimed rt header extent */ 2102 2103 return true; 2104 } 2105 2106 bool ieee80211_parse_tx_radiotap(struct sk_buff *skb, 2107 struct net_device *dev) 2108 { 2109 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 2110 struct ieee80211_radiotap_iterator iterator; 2111 struct ieee80211_radiotap_header *rthdr = 2112 (struct ieee80211_radiotap_header *) skb->data; 2113 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 2114 int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len, 2115 NULL); 2116 u16 txflags; 2117 u16 rate = 0; 2118 bool rate_found = false; 2119 u8 rate_retries = 0; 2120 u16 rate_flags = 0; 2121 u8 mcs_known, mcs_flags, mcs_bw; 2122 u16 vht_known; 2123 u8 vht_mcs = 0, vht_nss = 0; 2124 int i; 2125 2126 if (!ieee80211_validate_radiotap_len(skb)) 2127 return false; 2128 2129 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT | 2130 IEEE80211_TX_CTL_DONTFRAG; 2131 2132 /* 2133 * for every radiotap entry that is present 2134 * (ieee80211_radiotap_iterator_next returns -ENOENT when no more 2135 * entries present, or -EINVAL on error) 2136 */ 2137 2138 while (!ret) { 2139 ret = ieee80211_radiotap_iterator_next(&iterator); 2140 2141 if (ret) 2142 continue; 2143 2144 /* see if this argument is something we can use */ 2145 switch (iterator.this_arg_index) { 2146 /* 2147 * You must take care when dereferencing iterator.this_arg 2148 * for multibyte types... the pointer is not aligned. Use 2149 * get_unaligned((type *)iterator.this_arg) to dereference 2150 * iterator.this_arg for type "type" safely on all arches. 2151 */ 2152 case IEEE80211_RADIOTAP_FLAGS: 2153 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) { 2154 /* 2155 * this indicates that the skb we have been 2156 * handed has the 32-bit FCS CRC at the end... 2157 * we should react to that by snipping it off 2158 * because it will be recomputed and added 2159 * on transmission 2160 */ 2161 if (skb->len < (iterator._max_length + FCS_LEN)) 2162 return false; 2163 2164 skb_trim(skb, skb->len - FCS_LEN); 2165 } 2166 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_WEP) 2167 info->flags &= ~IEEE80211_TX_INTFL_DONT_ENCRYPT; 2168 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG) 2169 info->flags &= ~IEEE80211_TX_CTL_DONTFRAG; 2170 break; 2171 2172 case IEEE80211_RADIOTAP_TX_FLAGS: 2173 txflags = get_unaligned_le16(iterator.this_arg); 2174 if (txflags & IEEE80211_RADIOTAP_F_TX_NOACK) 2175 info->flags |= IEEE80211_TX_CTL_NO_ACK; 2176 if (txflags & IEEE80211_RADIOTAP_F_TX_NOSEQNO) 2177 info->control.flags |= IEEE80211_TX_CTRL_NO_SEQNO; 2178 if (txflags & IEEE80211_RADIOTAP_F_TX_ORDER) 2179 info->control.flags |= 2180 IEEE80211_TX_CTRL_DONT_REORDER; 2181 break; 2182 2183 case IEEE80211_RADIOTAP_RATE: 2184 rate = *iterator.this_arg; 2185 rate_flags = 0; 2186 rate_found = true; 2187 break; 2188 2189 case IEEE80211_RADIOTAP_ANTENNA: 2190 /* this can appear multiple times, keep a bitmap */ 2191 /* control.antennas is only a 2-bit bitmap */ 2192 if (*iterator.this_arg < 2) 2193 info->control.antennas |= BIT(*iterator.this_arg); 2194 break; 2195 2196 case IEEE80211_RADIOTAP_DATA_RETRIES: 2197 rate_retries = *iterator.this_arg; 2198 break; 2199 2200 case IEEE80211_RADIOTAP_MCS: 2201 mcs_known = iterator.this_arg[0]; 2202 mcs_flags = iterator.this_arg[1]; 2203 if (!(mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_MCS)) 2204 break; 2205 2206 rate_found = true; 2207 rate = iterator.this_arg[2]; 2208 rate_flags = IEEE80211_TX_RC_MCS; 2209 2210 if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_GI && 2211 mcs_flags & IEEE80211_RADIOTAP_MCS_SGI) 2212 rate_flags |= IEEE80211_TX_RC_SHORT_GI; 2213 2214 mcs_bw = mcs_flags & IEEE80211_RADIOTAP_MCS_BW_MASK; 2215 if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_BW && 2216 mcs_bw == IEEE80211_RADIOTAP_MCS_BW_40) 2217 rate_flags |= IEEE80211_TX_RC_40_MHZ_WIDTH; 2218 2219 if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_FEC && 2220 mcs_flags & IEEE80211_RADIOTAP_MCS_FEC_LDPC) 2221 info->flags |= IEEE80211_TX_CTL_LDPC; 2222 2223 if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_STBC) { 2224 u8 stbc = u8_get_bits(mcs_flags, 2225 IEEE80211_RADIOTAP_MCS_STBC_MASK); 2226 2227 info->flags |= 2228 u32_encode_bits(stbc, 2229 IEEE80211_TX_CTL_STBC); 2230 } 2231 break; 2232 2233 case IEEE80211_RADIOTAP_VHT: 2234 vht_known = get_unaligned_le16(iterator.this_arg); 2235 rate_found = true; 2236 2237 rate_flags = IEEE80211_TX_RC_VHT_MCS; 2238 if ((vht_known & IEEE80211_RADIOTAP_VHT_KNOWN_GI) && 2239 (iterator.this_arg[2] & 2240 IEEE80211_RADIOTAP_VHT_FLAG_SGI)) 2241 rate_flags |= IEEE80211_TX_RC_SHORT_GI; 2242 if (vht_known & 2243 IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH) { 2244 if (iterator.this_arg[3] == 1) 2245 rate_flags |= 2246 IEEE80211_TX_RC_40_MHZ_WIDTH; 2247 else if (iterator.this_arg[3] == 4) 2248 rate_flags |= 2249 IEEE80211_TX_RC_80_MHZ_WIDTH; 2250 else if (iterator.this_arg[3] == 11) 2251 rate_flags |= 2252 IEEE80211_TX_RC_160_MHZ_WIDTH; 2253 } 2254 2255 vht_mcs = iterator.this_arg[4] >> 4; 2256 if (vht_mcs > 11) 2257 vht_mcs = 0; 2258 vht_nss = iterator.this_arg[4] & 0xF; 2259 if (!vht_nss || vht_nss > 8) 2260 vht_nss = 1; 2261 break; 2262 2263 /* 2264 * Please update the file 2265 * Documentation/networking/mac80211-injection.rst 2266 * when parsing new fields here. 2267 */ 2268 2269 default: 2270 break; 2271 } 2272 } 2273 2274 if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */ 2275 return false; 2276 2277 if (rate_found) { 2278 struct ieee80211_supported_band *sband = 2279 local->hw.wiphy->bands[info->band]; 2280 2281 info->control.flags |= IEEE80211_TX_CTRL_RATE_INJECT; 2282 2283 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) { 2284 info->control.rates[i].idx = -1; 2285 info->control.rates[i].flags = 0; 2286 info->control.rates[i].count = 0; 2287 } 2288 2289 if (rate_flags & IEEE80211_TX_RC_MCS) { 2290 /* reset antennas if not enough */ 2291 if (IEEE80211_HT_MCS_CHAINS(rate) > 2292 hweight8(info->control.antennas)) 2293 info->control.antennas = 0; 2294 2295 info->control.rates[0].idx = rate; 2296 } else if (rate_flags & IEEE80211_TX_RC_VHT_MCS) { 2297 /* reset antennas if not enough */ 2298 if (vht_nss > hweight8(info->control.antennas)) 2299 info->control.antennas = 0; 2300 2301 ieee80211_rate_set_vht(info->control.rates, vht_mcs, 2302 vht_nss); 2303 } else if (sband) { 2304 for (i = 0; i < sband->n_bitrates; i++) { 2305 if (rate * 5 != sband->bitrates[i].bitrate) 2306 continue; 2307 2308 info->control.rates[0].idx = i; 2309 break; 2310 } 2311 } 2312 2313 if (info->control.rates[0].idx < 0) 2314 info->control.flags &= ~IEEE80211_TX_CTRL_RATE_INJECT; 2315 2316 info->control.rates[0].flags = rate_flags; 2317 info->control.rates[0].count = min_t(u8, rate_retries + 1, 2318 local->hw.max_rate_tries); 2319 } 2320 2321 return true; 2322 } 2323 2324 netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb, 2325 struct net_device *dev) 2326 { 2327 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 2328 struct ieee80211_chanctx_conf *chanctx_conf; 2329 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 2330 struct ieee80211_hdr *hdr; 2331 struct ieee80211_sub_if_data *tmp_sdata, *sdata; 2332 struct cfg80211_chan_def *chandef; 2333 u16 len_rthdr; 2334 int hdrlen; 2335 2336 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2337 if (unlikely(!ieee80211_sdata_running(sdata))) 2338 goto fail; 2339 2340 memset(info, 0, sizeof(*info)); 2341 info->flags = IEEE80211_TX_CTL_REQ_TX_STATUS | 2342 IEEE80211_TX_CTL_INJECTED; 2343 2344 /* Sanity-check the length of the radiotap header */ 2345 if (!ieee80211_validate_radiotap_len(skb)) 2346 goto fail; 2347 2348 /* we now know there is a radiotap header with a length we can use */ 2349 len_rthdr = ieee80211_get_radiotap_len(skb->data); 2350 2351 /* 2352 * fix up the pointers accounting for the radiotap 2353 * header still being in there. We are being given 2354 * a precooked IEEE80211 header so no need for 2355 * normal processing 2356 */ 2357 skb_set_mac_header(skb, len_rthdr); 2358 /* 2359 * these are just fixed to the end of the rt area since we 2360 * don't have any better information and at this point, nobody cares 2361 */ 2362 skb_set_network_header(skb, len_rthdr); 2363 skb_set_transport_header(skb, len_rthdr); 2364 2365 if (skb->len < len_rthdr + 2) 2366 goto fail; 2367 2368 hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr); 2369 hdrlen = ieee80211_hdrlen(hdr->frame_control); 2370 2371 if (skb->len < len_rthdr + hdrlen) 2372 goto fail; 2373 2374 /* 2375 * Initialize skb->protocol if the injected frame is a data frame 2376 * carrying a rfc1042 header 2377 */ 2378 if (ieee80211_is_data(hdr->frame_control) && 2379 skb->len >= len_rthdr + hdrlen + sizeof(rfc1042_header) + 2) { 2380 u8 *payload = (u8 *)hdr + hdrlen; 2381 2382 if (ether_addr_equal(payload, rfc1042_header)) 2383 skb->protocol = cpu_to_be16((payload[6] << 8) | 2384 payload[7]); 2385 } 2386 2387 rcu_read_lock(); 2388 2389 /* 2390 * We process outgoing injected frames that have a local address 2391 * we handle as though they are non-injected frames. 2392 * This code here isn't entirely correct, the local MAC address 2393 * isn't always enough to find the interface to use; for proper 2394 * VLAN support we have an nl80211-based mechanism. 2395 * 2396 * This is necessary, for example, for old hostapd versions that 2397 * don't use nl80211-based management TX/RX. 2398 */ 2399 list_for_each_entry_rcu(tmp_sdata, &local->interfaces, list) { 2400 if (!ieee80211_sdata_running(tmp_sdata)) 2401 continue; 2402 if (tmp_sdata->vif.type == NL80211_IFTYPE_MONITOR || 2403 tmp_sdata->vif.type == NL80211_IFTYPE_AP_VLAN) 2404 continue; 2405 if (ether_addr_equal(tmp_sdata->vif.addr, hdr->addr2)) { 2406 sdata = tmp_sdata; 2407 break; 2408 } 2409 } 2410 2411 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf); 2412 if (!chanctx_conf) { 2413 tmp_sdata = rcu_dereference(local->monitor_sdata); 2414 if (tmp_sdata) 2415 chanctx_conf = 2416 rcu_dereference(tmp_sdata->vif.bss_conf.chanctx_conf); 2417 } 2418 2419 if (!chanctx_conf) { 2420 struct ieee80211_chanctx *ctx; 2421 bool first = true; 2422 2423 list_for_each_entry_rcu(ctx, &local->chanctx_list, list) { 2424 if (!first) 2425 goto fail_rcu; 2426 chanctx_conf = &ctx->conf; 2427 first = false; 2428 } 2429 } 2430 2431 if (chanctx_conf) 2432 chandef = &chanctx_conf->def; 2433 else 2434 goto fail_rcu; 2435 2436 /* 2437 * If driver/HW supports IEEE80211_CHAN_CAN_MONITOR we still 2438 * shouldn't transmit on disabled channels. 2439 */ 2440 if (!cfg80211_chandef_usable(local->hw.wiphy, chandef, 2441 IEEE80211_CHAN_DISABLED)) 2442 goto fail_rcu; 2443 2444 /* 2445 * Frame injection is not allowed if beaconing is not allowed 2446 * or if we need radar detection. Beaconing is usually not allowed when 2447 * the mode or operation (Adhoc, AP, Mesh) does not support DFS. 2448 * Passive scan is also used in world regulatory domains where 2449 * your country is not known and as such it should be treated as 2450 * NO TX unless the channel is explicitly allowed in which case 2451 * your current regulatory domain would not have the passive scan 2452 * flag. 2453 * 2454 * Since AP mode uses monitor interfaces to inject/TX management 2455 * frames we can make AP mode the exception to this rule once it 2456 * supports radar detection as its implementation can deal with 2457 * radar detection by itself. We can do that later by adding a 2458 * monitor flag interfaces used for AP support. 2459 */ 2460 if (!cfg80211_reg_can_beacon(local->hw.wiphy, chandef, 2461 sdata->vif.type)) 2462 goto fail_rcu; 2463 2464 info->band = chandef->chan->band; 2465 2466 /* Initialize skb->priority according to frame type and TID class, 2467 * with respect to the sub interface that the frame will actually 2468 * be transmitted on. If the DONT_REORDER flag is set, the original 2469 * skb-priority is preserved to assure frames injected with this 2470 * flag are not reordered relative to each other. 2471 */ 2472 ieee80211_select_queue_80211(sdata, skb, hdr); 2473 skb_set_queue_mapping(skb, ieee80211_ac_from_tid(skb->priority)); 2474 2475 /* 2476 * Process the radiotap header. This will now take into account the 2477 * selected chandef above to accurately set injection rates and 2478 * retransmissions. 2479 */ 2480 if (!ieee80211_parse_tx_radiotap(skb, dev)) 2481 goto fail_rcu; 2482 2483 /* remove the injection radiotap header */ 2484 skb_pull(skb, len_rthdr); 2485 2486 ieee80211_xmit(sdata, NULL, skb); 2487 rcu_read_unlock(); 2488 2489 return NETDEV_TX_OK; 2490 2491 fail_rcu: 2492 rcu_read_unlock(); 2493 fail: 2494 dev_kfree_skb(skb); 2495 return NETDEV_TX_OK; /* meaning, we dealt with the skb */ 2496 } 2497 2498 static inline bool ieee80211_is_tdls_setup(struct sk_buff *skb) 2499 { 2500 u16 ethertype = (skb->data[12] << 8) | skb->data[13]; 2501 2502 return ethertype == ETH_P_TDLS && 2503 skb->len > 14 && 2504 skb->data[14] == WLAN_TDLS_SNAP_RFTYPE; 2505 } 2506 2507 int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata, 2508 struct sk_buff *skb, 2509 struct sta_info **sta_out) 2510 { 2511 struct sta_info *sta; 2512 2513 switch (sdata->vif.type) { 2514 case NL80211_IFTYPE_AP_VLAN: 2515 sta = rcu_dereference(sdata->u.vlan.sta); 2516 if (sta) { 2517 *sta_out = sta; 2518 return 0; 2519 } else if (sdata->wdev.use_4addr) { 2520 return -ENOLINK; 2521 } 2522 fallthrough; 2523 case NL80211_IFTYPE_AP: 2524 case NL80211_IFTYPE_OCB: 2525 case NL80211_IFTYPE_ADHOC: 2526 if (is_multicast_ether_addr(skb->data)) { 2527 *sta_out = ERR_PTR(-ENOENT); 2528 return 0; 2529 } 2530 sta = sta_info_get_bss(sdata, skb->data); 2531 break; 2532 #ifdef CONFIG_MAC80211_MESH 2533 case NL80211_IFTYPE_MESH_POINT: 2534 /* determined much later */ 2535 *sta_out = NULL; 2536 return 0; 2537 #endif 2538 case NL80211_IFTYPE_STATION: 2539 if (sdata->wdev.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) { 2540 sta = sta_info_get(sdata, skb->data); 2541 if (sta && test_sta_flag(sta, WLAN_STA_TDLS_PEER)) { 2542 if (test_sta_flag(sta, 2543 WLAN_STA_TDLS_PEER_AUTH)) { 2544 *sta_out = sta; 2545 return 0; 2546 } 2547 2548 /* 2549 * TDLS link during setup - throw out frames to 2550 * peer. Allow TDLS-setup frames to unauthorized 2551 * peers for the special case of a link teardown 2552 * after a TDLS sta is removed due to being 2553 * unreachable. 2554 */ 2555 if (!ieee80211_is_tdls_setup(skb)) 2556 return -EINVAL; 2557 } 2558 2559 } 2560 2561 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr); 2562 if (!sta) 2563 return -ENOLINK; 2564 break; 2565 case NL80211_IFTYPE_NAN_DATA: 2566 if (is_multicast_ether_addr(skb->data)) { 2567 *sta_out = ERR_PTR(-ENOENT); 2568 return 0; 2569 } 2570 sta = sta_info_get(sdata, skb->data); 2571 break; 2572 default: 2573 return -EINVAL; 2574 } 2575 2576 *sta_out = sta ?: ERR_PTR(-ENOENT); 2577 return 0; 2578 } 2579 2580 static u16 ieee80211_store_ack_skb(struct ieee80211_local *local, 2581 struct sk_buff *skb, 2582 u32 *info_flags, 2583 u64 cookie) 2584 { 2585 struct sk_buff *ack_skb; 2586 u16 info_id = 0; 2587 2588 if (skb->sk) 2589 ack_skb = skb_clone_sk(skb); 2590 else 2591 ack_skb = skb_clone(skb, GFP_ATOMIC); 2592 2593 if (ack_skb) { 2594 unsigned long flags; 2595 int id; 2596 2597 spin_lock_irqsave(&local->ack_status_lock, flags); 2598 id = idr_alloc(&local->ack_status_frames, ack_skb, 2599 1, 0x2000, GFP_ATOMIC); 2600 spin_unlock_irqrestore(&local->ack_status_lock, flags); 2601 2602 if (id >= 0) { 2603 info_id = id; 2604 *info_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; 2605 if (cookie) 2606 IEEE80211_SKB_CB(ack_skb)->ack.cookie = cookie; 2607 } else { 2608 kfree_skb(ack_skb); 2609 } 2610 } 2611 2612 return info_id; 2613 } 2614 2615 static void ieee80211_remove_ack_skb(struct ieee80211_local *local, u16 info_id) 2616 { 2617 struct sk_buff *ack_skb; 2618 unsigned long flags; 2619 2620 spin_lock_irqsave(&local->ack_status_lock, flags); 2621 ack_skb = idr_remove(&local->ack_status_frames, info_id); 2622 spin_unlock_irqrestore(&local->ack_status_lock, flags); 2623 2624 kfree_skb(ack_skb); 2625 } 2626 2627 /** 2628 * ieee80211_build_hdr - build 802.11 header in the given frame 2629 * @sdata: virtual interface to build the header for 2630 * @skb: the skb to build the header in 2631 * @info_flags: skb flags to set 2632 * @sta: the station pointer 2633 * @ctrl_flags: info control flags to set 2634 * @cookie: cookie pointer to fill (if not %NULL) 2635 * 2636 * This function takes the skb with 802.3 header and reformats the header to 2637 * the appropriate IEEE 802.11 header based on which interface the packet is 2638 * being transmitted on. 2639 * 2640 * Note that this function also takes care of the TX status request and 2641 * potential unsharing of the SKB - this needs to be interleaved with the 2642 * header building. 2643 * 2644 * The function requires the read-side RCU lock held 2645 * 2646 * Returns: the (possibly reallocated) skb or an ERR_PTR() code 2647 */ 2648 static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, 2649 struct sk_buff *skb, u32 info_flags, 2650 struct sta_info *sta, u32 ctrl_flags, 2651 u64 cookie) 2652 { 2653 struct ieee80211_local *local = sdata->local; 2654 struct ieee80211_tx_info *info; 2655 int head_need; 2656 u16 ethertype, hdrlen, meshhdrlen = 0; 2657 __le16 fc; 2658 struct ieee80211_hdr hdr; 2659 struct ieee80211s_hdr mesh_hdr __maybe_unused; 2660 struct mesh_path __maybe_unused *mppath = NULL, *mpath = NULL; 2661 const u8 *encaps_data; 2662 int encaps_len, skip_header_bytes; 2663 bool wme_sta = false, authorized = false; 2664 bool tdls_peer; 2665 bool multicast; 2666 u16 info_id = 0; 2667 struct ieee80211_chanctx_conf *chanctx_conf = NULL; 2668 enum nl80211_band band; 2669 int ret; 2670 u8 link_id = u32_get_bits(ctrl_flags, IEEE80211_TX_CTRL_MLO_LINK); 2671 2672 if (IS_ERR(sta)) 2673 sta = NULL; 2674 2675 #ifdef CONFIG_MAC80211_DEBUGFS 2676 if (local->force_tx_status) 2677 info_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; 2678 #endif 2679 2680 /* convert Ethernet header to proper 802.11 header (based on 2681 * operation mode) */ 2682 ethertype = (skb->data[12] << 8) | skb->data[13]; 2683 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA); 2684 2685 if (!ieee80211_vif_is_mld(&sdata->vif)) 2686 chanctx_conf = 2687 rcu_dereference(sdata->vif.bss_conf.chanctx_conf); 2688 2689 switch (sdata->vif.type) { 2690 case NL80211_IFTYPE_AP_VLAN: 2691 if (sdata->wdev.use_4addr) { 2692 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); 2693 /* RA TA DA SA */ 2694 memcpy(hdr.addr1, sta->sta.addr, ETH_ALEN); 2695 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN); 2696 memcpy(hdr.addr3, skb->data, ETH_ALEN); 2697 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN); 2698 hdrlen = 30; 2699 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED); 2700 wme_sta = sta->sta.wme; 2701 } 2702 if (!ieee80211_vif_is_mld(&sdata->vif)) { 2703 struct ieee80211_sub_if_data *ap_sdata; 2704 2705 /* override chanctx_conf from AP (we don't have one) */ 2706 ap_sdata = container_of(sdata->bss, 2707 struct ieee80211_sub_if_data, 2708 u.ap); 2709 chanctx_conf = 2710 rcu_dereference(ap_sdata->vif.bss_conf.chanctx_conf); 2711 } 2712 if (sdata->wdev.use_4addr) 2713 break; 2714 fallthrough; 2715 case NL80211_IFTYPE_AP: 2716 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS); 2717 /* DA BSSID SA */ 2718 memcpy(hdr.addr1, skb->data, ETH_ALEN); 2719 2720 if (ieee80211_vif_is_mld(&sdata->vif) && sta && !sta->sta.mlo) { 2721 struct ieee80211_link_data *link; 2722 2723 link_id = sta->deflink.link_id; 2724 link = rcu_dereference(sdata->link[link_id]); 2725 if (WARN_ON(!link)) { 2726 ret = -ENOLINK; 2727 goto free; 2728 } 2729 memcpy(hdr.addr2, link->conf->addr, ETH_ALEN); 2730 } else if (link_id == IEEE80211_LINK_UNSPECIFIED || 2731 (sta && sta->sta.mlo)) { 2732 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN); 2733 } else { 2734 struct ieee80211_bss_conf *conf; 2735 2736 conf = rcu_dereference(sdata->vif.link_conf[link_id]); 2737 if (unlikely(!conf)) { 2738 ret = -ENOLINK; 2739 goto free; 2740 } 2741 2742 memcpy(hdr.addr2, conf->addr, ETH_ALEN); 2743 } 2744 2745 memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN); 2746 hdrlen = 24; 2747 break; 2748 #ifdef CONFIG_MAC80211_MESH 2749 case NL80211_IFTYPE_MESH_POINT: 2750 if (!is_multicast_ether_addr(skb->data)) { 2751 struct sta_info *next_hop; 2752 bool mpp_lookup = true; 2753 2754 mpath = mesh_path_lookup(sdata, skb->data); 2755 if (mpath) { 2756 mpp_lookup = false; 2757 next_hop = rcu_dereference(mpath->next_hop); 2758 if (!next_hop || 2759 !(mpath->flags & (MESH_PATH_ACTIVE | 2760 MESH_PATH_RESOLVING))) 2761 mpp_lookup = true; 2762 } 2763 2764 if (mpp_lookup) { 2765 mppath = mpp_path_lookup(sdata, skb->data); 2766 if (mppath) 2767 mppath->exp_time = jiffies; 2768 } 2769 2770 if (mppath && mpath) 2771 mesh_path_del(sdata, mpath->dst); 2772 } 2773 2774 /* 2775 * Use address extension if it is a packet from 2776 * another interface or if we know the destination 2777 * is being proxied by a portal (i.e. portal address 2778 * differs from proxied address) 2779 */ 2780 if (ether_addr_equal(sdata->vif.addr, skb->data + ETH_ALEN) && 2781 !(mppath && !ether_addr_equal(mppath->mpp, skb->data))) { 2782 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc, 2783 skb->data, skb->data + ETH_ALEN); 2784 meshhdrlen = ieee80211_new_mesh_header(sdata, &mesh_hdr, 2785 NULL, NULL); 2786 } else { 2787 /* DS -> MBSS (802.11-2012 13.11.3.3). 2788 * For unicast with unknown forwarding information, 2789 * destination might be in the MBSS or if that fails 2790 * forwarded to another mesh gate. In either case 2791 * resolution will be handled in ieee80211_xmit(), so 2792 * leave the original DA. This also works for mcast */ 2793 const u8 *mesh_da = skb->data; 2794 2795 if (mppath) 2796 mesh_da = mppath->mpp; 2797 else if (mpath) 2798 mesh_da = mpath->dst; 2799 2800 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc, 2801 mesh_da, sdata->vif.addr); 2802 if (is_multicast_ether_addr(mesh_da)) 2803 /* DA TA mSA AE:SA */ 2804 meshhdrlen = ieee80211_new_mesh_header( 2805 sdata, &mesh_hdr, 2806 skb->data + ETH_ALEN, NULL); 2807 else 2808 /* RA TA mDA mSA AE:DA SA */ 2809 meshhdrlen = ieee80211_new_mesh_header( 2810 sdata, &mesh_hdr, skb->data, 2811 skb->data + ETH_ALEN); 2812 2813 } 2814 2815 /* For injected frames, fill RA right away as nexthop lookup 2816 * will be skipped. 2817 */ 2818 if ((ctrl_flags & IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP) && 2819 is_zero_ether_addr(hdr.addr1)) 2820 memcpy(hdr.addr1, skb->data, ETH_ALEN); 2821 break; 2822 #endif 2823 case NL80211_IFTYPE_STATION: 2824 /* we already did checks when looking up the RA STA */ 2825 tdls_peer = test_sta_flag(sta, WLAN_STA_TDLS_PEER); 2826 2827 if (tdls_peer) { 2828 /* For TDLS only one link can be valid with peer STA */ 2829 int tdls_link_id = ieee80211_tdls_sta_link_id(sta); 2830 struct ieee80211_link_data *link; 2831 2832 /* DA SA BSSID */ 2833 memcpy(hdr.addr1, skb->data, ETH_ALEN); 2834 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); 2835 link = rcu_dereference(sdata->link[tdls_link_id]); 2836 if (WARN_ON_ONCE(!link)) { 2837 ret = -EINVAL; 2838 goto free; 2839 } 2840 memcpy(hdr.addr3, link->u.mgd.bssid, ETH_ALEN); 2841 hdrlen = 24; 2842 } else if (sdata->u.mgd.use_4addr && 2843 cpu_to_be16(ethertype) != sdata->control_port_protocol) { 2844 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | 2845 IEEE80211_FCTL_TODS); 2846 /* RA TA DA SA */ 2847 memcpy(hdr.addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN); 2848 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN); 2849 memcpy(hdr.addr3, skb->data, ETH_ALEN); 2850 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN); 2851 hdrlen = 30; 2852 } else { 2853 fc |= cpu_to_le16(IEEE80211_FCTL_TODS); 2854 /* BSSID SA DA */ 2855 memcpy(hdr.addr1, sdata->vif.cfg.ap_addr, ETH_ALEN); 2856 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); 2857 memcpy(hdr.addr3, skb->data, ETH_ALEN); 2858 hdrlen = 24; 2859 } 2860 break; 2861 case NL80211_IFTYPE_OCB: 2862 /* DA SA BSSID */ 2863 memcpy(hdr.addr1, skb->data, ETH_ALEN); 2864 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); 2865 eth_broadcast_addr(hdr.addr3); 2866 hdrlen = 24; 2867 break; 2868 case NL80211_IFTYPE_ADHOC: 2869 /* DA SA BSSID */ 2870 memcpy(hdr.addr1, skb->data, ETH_ALEN); 2871 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); 2872 memcpy(hdr.addr3, sdata->u.ibss.bssid, ETH_ALEN); 2873 hdrlen = 24; 2874 break; 2875 case NL80211_IFTYPE_NAN_DATA: { 2876 struct ieee80211_sub_if_data *nmi; 2877 2878 /* DA SA Cluster ID */ 2879 memcpy(hdr.addr1, skb->data, ETH_ALEN); 2880 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); 2881 nmi = rcu_dereference(sdata->u.nan_data.nmi); 2882 if (!nmi) { 2883 ret = -ENOTCONN; 2884 goto free; 2885 } 2886 memcpy(hdr.addr3, nmi->u.nan.conf.cluster_id, ETH_ALEN); 2887 hdrlen = 24; 2888 break; 2889 } 2890 default: 2891 ret = -EINVAL; 2892 goto free; 2893 } 2894 2895 if (!chanctx_conf) { 2896 if (sdata->vif.type == NL80211_IFTYPE_NAN_DATA) { 2897 /* NAN operates on multiple bands */ 2898 band = NUM_NL80211_BANDS; 2899 } else if (!ieee80211_vif_is_mld(&sdata->vif)) { 2900 ret = -ENOTCONN; 2901 goto free; 2902 } else { 2903 /* MLD transmissions must not rely on the band */ 2904 band = 0; 2905 } 2906 } else { 2907 band = chanctx_conf->def.chan->band; 2908 } 2909 2910 multicast = is_multicast_ether_addr(hdr.addr1); 2911 2912 /* sta is always NULL for mesh */ 2913 if (sta) { 2914 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED); 2915 wme_sta = sta->sta.wme; 2916 } else if (ieee80211_vif_is_mesh(&sdata->vif)) { 2917 /* For mesh, the use of the QoS header is mandatory */ 2918 wme_sta = true; 2919 } 2920 2921 /* receiver does QoS (which also means we do) use it */ 2922 if (wme_sta) { 2923 fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA); 2924 hdrlen += 2; 2925 } 2926 2927 /* 2928 * Drop unicast frames to unauthorised stations unless they are 2929 * EAPOL frames from the local station. 2930 */ 2931 if (unlikely(!ieee80211_vif_is_mesh(&sdata->vif) && 2932 (sdata->vif.type != NL80211_IFTYPE_OCB) && 2933 !multicast && !authorized && 2934 (cpu_to_be16(ethertype) != sdata->control_port_protocol || 2935 !ieee80211_is_our_addr(sdata, skb->data + ETH_ALEN, NULL)))) { 2936 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG 2937 net_info_ratelimited("%s: dropped frame to %pM (unauthorized port)\n", 2938 sdata->name, hdr.addr1); 2939 #endif 2940 2941 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port); 2942 2943 ret = -EPERM; 2944 goto free; 2945 } 2946 2947 if (unlikely(!multicast && 2948 (sk_requests_wifi_status(skb->sk) || 2949 ctrl_flags & IEEE80211_TX_CTL_REQ_TX_STATUS))) 2950 info_id = ieee80211_store_ack_skb(local, skb, &info_flags, 2951 cookie); 2952 2953 /* 2954 * If the skb is shared we need to obtain our own copy. 2955 */ 2956 skb = skb_share_check(skb, GFP_ATOMIC); 2957 if (unlikely(!skb)) { 2958 ret = -ENOMEM; 2959 goto free; 2960 } 2961 2962 hdr.frame_control = fc; 2963 hdr.duration_id = 0; 2964 hdr.seq_ctrl = 0; 2965 2966 skip_header_bytes = ETH_HLEN; 2967 if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) { 2968 encaps_data = bridge_tunnel_header; 2969 encaps_len = sizeof(bridge_tunnel_header); 2970 skip_header_bytes -= 2; 2971 } else if (ethertype >= ETH_P_802_3_MIN) { 2972 encaps_data = rfc1042_header; 2973 encaps_len = sizeof(rfc1042_header); 2974 skip_header_bytes -= 2; 2975 } else { 2976 encaps_data = NULL; 2977 encaps_len = 0; 2978 } 2979 2980 skb_pull(skb, skip_header_bytes); 2981 head_need = hdrlen + encaps_len + meshhdrlen - skb_headroom(skb); 2982 2983 /* 2984 * So we need to modify the skb header and hence need a copy of 2985 * that. The head_need variable above doesn't, so far, include 2986 * the needed header space that we don't need right away. If we 2987 * can, then we don't reallocate right now but only after the 2988 * frame arrives at the master device (if it does...) 2989 * 2990 * If we cannot, however, then we will reallocate to include all 2991 * the ever needed space. Also, if we need to reallocate it anyway, 2992 * make it big enough for everything we may ever need. 2993 */ 2994 2995 if (head_need > 0 || skb_cloned(skb)) { 2996 head_need += IEEE80211_ENCRYPT_HEADROOM; 2997 head_need += local->tx_headroom; 2998 head_need = max_t(int, 0, head_need); 2999 if (ieee80211_skb_resize(sdata, skb, head_need, ENCRYPT_DATA)) { 3000 ieee80211_free_txskb(&local->hw, skb); 3001 skb = NULL; 3002 ret = -ENOMEM; 3003 goto free; 3004 } 3005 } 3006 3007 if (encaps_data) 3008 memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len); 3009 3010 #ifdef CONFIG_MAC80211_MESH 3011 if (meshhdrlen > 0) 3012 memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen); 3013 #endif 3014 3015 if (ieee80211_is_data_qos(fc)) { 3016 __le16 *qos_control; 3017 3018 qos_control = skb_push(skb, 2); 3019 memcpy(skb_push(skb, hdrlen - 2), &hdr, hdrlen - 2); 3020 /* 3021 * Maybe we could actually set some fields here, for now just 3022 * initialise to zero to indicate no special operation. 3023 */ 3024 *qos_control = 0; 3025 } else 3026 memcpy(skb_push(skb, hdrlen), &hdr, hdrlen); 3027 3028 skb_reset_mac_header(skb); 3029 3030 info = IEEE80211_SKB_CB(skb); 3031 memset(info, 0, sizeof(*info)); 3032 3033 info->flags = info_flags; 3034 if (info_id) { 3035 info->status_data = info_id; 3036 info->status_data_idr = 1; 3037 } 3038 info->band = band; 3039 3040 if (likely(!cookie)) { 3041 ctrl_flags |= u32_encode_bits(link_id, 3042 IEEE80211_TX_CTRL_MLO_LINK); 3043 } else { 3044 unsigned int pre_conf_link_id; 3045 3046 /* 3047 * ctrl_flags already have been set by 3048 * ieee80211_tx_control_port(), here 3049 * we just sanity check that 3050 */ 3051 3052 pre_conf_link_id = u32_get_bits(ctrl_flags, 3053 IEEE80211_TX_CTRL_MLO_LINK); 3054 3055 if (pre_conf_link_id != link_id && 3056 link_id != IEEE80211_LINK_UNSPECIFIED) { 3057 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG 3058 net_info_ratelimited("%s: dropped frame to %pM with bad link ID request (%d vs. %d)\n", 3059 sdata->name, hdr.addr1, 3060 pre_conf_link_id, link_id); 3061 #endif 3062 ret = -EINVAL; 3063 goto free; 3064 } 3065 } 3066 3067 info->control.flags = ctrl_flags; 3068 3069 return skb; 3070 free: 3071 if (info_id) 3072 ieee80211_remove_ack_skb(local, info_id); 3073 kfree_skb(skb); 3074 return ERR_PTR(ret); 3075 } 3076 3077 /* 3078 * fast-xmit overview 3079 * 3080 * The core idea of this fast-xmit is to remove per-packet checks by checking 3081 * them out of band. ieee80211_check_fast_xmit() implements the out-of-band 3082 * checks that are needed to get the sta->fast_tx pointer assigned, after which 3083 * much less work can be done per packet. For example, fragmentation must be 3084 * disabled or the fast_tx pointer will not be set. All the conditions are seen 3085 * in the code here. 3086 * 3087 * Once assigned, the fast_tx data structure also caches the per-packet 802.11 3088 * header and other data to aid packet processing in ieee80211_xmit_fast(). 3089 * 3090 * The most difficult part of this is that when any of these assumptions 3091 * change, an external trigger (i.e. a call to ieee80211_clear_fast_xmit(), 3092 * ieee80211_check_fast_xmit() or friends) is required to reset the data, 3093 * since the per-packet code no longer checks the conditions. This is reflected 3094 * by the calls to these functions throughout the rest of the code, and must be 3095 * maintained if any of the TX path checks change. 3096 */ 3097 3098 void ieee80211_check_fast_xmit(struct sta_info *sta) 3099 { 3100 struct ieee80211_fast_tx build = {}, *fast_tx = NULL, *old; 3101 struct ieee80211_local *local = sta->local; 3102 struct ieee80211_sub_if_data *sdata = sta->sdata; 3103 struct ieee80211_hdr *hdr = (void *)build.hdr; 3104 struct ieee80211_chanctx_conf *chanctx_conf; 3105 __le16 fc; 3106 3107 if (!ieee80211_hw_check(&local->hw, SUPPORT_FAST_XMIT)) 3108 return; 3109 3110 if (ieee80211_vif_is_mesh(&sdata->vif)) 3111 mesh_fast_tx_flush_sta(sdata, sta); 3112 3113 /* Locking here protects both the pointer itself, and against concurrent 3114 * invocations winning data access races to, e.g., the key pointer that 3115 * is used. 3116 * Without it, the invocation of this function right after the key 3117 * pointer changes wouldn't be sufficient, as another CPU could access 3118 * the pointer, then stall, and then do the cache update after the CPU 3119 * that invalidated the key. 3120 * With the locking, such scenarios cannot happen as the check for the 3121 * key and the fast-tx assignment are done atomically, so the CPU that 3122 * modifies the key will either wait or other one will see the key 3123 * cleared/changed already. 3124 */ 3125 spin_lock_bh(&sta->lock); 3126 if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) && 3127 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) && 3128 sdata->vif.type == NL80211_IFTYPE_STATION) 3129 goto out; 3130 3131 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED) || !sta->uploaded) 3132 goto out; 3133 3134 if (test_sta_flag(sta, WLAN_STA_PS_STA) || 3135 test_sta_flag(sta, WLAN_STA_PS_DRIVER) || 3136 test_sta_flag(sta, WLAN_STA_PS_DELIVER) || 3137 test_sta_flag(sta, WLAN_STA_CLEAR_PS_FILT)) 3138 goto out; 3139 3140 if (sdata->noack_map) 3141 goto out; 3142 3143 /* fast-xmit doesn't handle fragmentation at all */ 3144 if (local->hw.wiphy->frag_threshold != (u32)-1 && 3145 !ieee80211_hw_check(&local->hw, SUPPORTS_TX_FRAG)) 3146 goto out; 3147 3148 if (!ieee80211_vif_is_mld(&sdata->vif)) { 3149 rcu_read_lock(); 3150 chanctx_conf = 3151 rcu_dereference(sdata->vif.bss_conf.chanctx_conf); 3152 if (!chanctx_conf) { 3153 rcu_read_unlock(); 3154 goto out; 3155 } 3156 build.band = chanctx_conf->def.chan->band; 3157 rcu_read_unlock(); 3158 } else { 3159 /* MLD transmissions must not rely on the band */ 3160 build.band = 0; 3161 } 3162 3163 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA); 3164 3165 switch (sdata->vif.type) { 3166 case NL80211_IFTYPE_ADHOC: 3167 /* DA SA BSSID */ 3168 build.da_offs = offsetof(struct ieee80211_hdr, addr1); 3169 build.sa_offs = offsetof(struct ieee80211_hdr, addr2); 3170 memcpy(hdr->addr3, sdata->u.ibss.bssid, ETH_ALEN); 3171 build.hdr_len = 24; 3172 break; 3173 case NL80211_IFTYPE_STATION: 3174 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) { 3175 /* For TDLS only one link can be valid with peer STA */ 3176 int tdls_link_id = ieee80211_tdls_sta_link_id(sta); 3177 struct ieee80211_link_data *link; 3178 3179 /* DA SA BSSID */ 3180 build.da_offs = offsetof(struct ieee80211_hdr, addr1); 3181 build.sa_offs = offsetof(struct ieee80211_hdr, addr2); 3182 rcu_read_lock(); 3183 link = rcu_dereference(sdata->link[tdls_link_id]); 3184 if (!WARN_ON_ONCE(!link)) 3185 memcpy(hdr->addr3, link->u.mgd.bssid, ETH_ALEN); 3186 rcu_read_unlock(); 3187 build.hdr_len = 24; 3188 break; 3189 } 3190 3191 if (sdata->u.mgd.use_4addr) { 3192 /* non-regular ethertype cannot use the fastpath */ 3193 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | 3194 IEEE80211_FCTL_TODS); 3195 /* RA TA DA SA */ 3196 memcpy(hdr->addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN); 3197 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN); 3198 build.da_offs = offsetof(struct ieee80211_hdr, addr3); 3199 build.sa_offs = offsetof(struct ieee80211_hdr, addr4); 3200 build.hdr_len = 30; 3201 break; 3202 } 3203 fc |= cpu_to_le16(IEEE80211_FCTL_TODS); 3204 /* BSSID SA DA */ 3205 memcpy(hdr->addr1, sdata->vif.cfg.ap_addr, ETH_ALEN); 3206 build.da_offs = offsetof(struct ieee80211_hdr, addr3); 3207 build.sa_offs = offsetof(struct ieee80211_hdr, addr2); 3208 build.hdr_len = 24; 3209 break; 3210 case NL80211_IFTYPE_AP_VLAN: 3211 if (sdata->wdev.use_4addr) { 3212 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | 3213 IEEE80211_FCTL_TODS); 3214 /* RA TA DA SA */ 3215 memcpy(hdr->addr1, sta->sta.addr, ETH_ALEN); 3216 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN); 3217 build.da_offs = offsetof(struct ieee80211_hdr, addr3); 3218 build.sa_offs = offsetof(struct ieee80211_hdr, addr4); 3219 build.hdr_len = 30; 3220 break; 3221 } 3222 fallthrough; 3223 case NL80211_IFTYPE_AP: 3224 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS); 3225 /* DA BSSID SA */ 3226 build.da_offs = offsetof(struct ieee80211_hdr, addr1); 3227 if (sta->sta.mlo || !ieee80211_vif_is_mld(&sdata->vif)) { 3228 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN); 3229 } else { 3230 unsigned int link_id = sta->deflink.link_id; 3231 struct ieee80211_link_data *link; 3232 3233 rcu_read_lock(); 3234 link = rcu_dereference(sdata->link[link_id]); 3235 if (WARN_ON(!link)) { 3236 rcu_read_unlock(); 3237 goto out; 3238 } 3239 memcpy(hdr->addr2, link->conf->addr, ETH_ALEN); 3240 rcu_read_unlock(); 3241 } 3242 build.sa_offs = offsetof(struct ieee80211_hdr, addr3); 3243 build.hdr_len = 24; 3244 break; 3245 default: 3246 /* not handled on fast-xmit */ 3247 goto out; 3248 } 3249 3250 if (sta->sta.wme) { 3251 build.hdr_len += 2; 3252 fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA); 3253 } 3254 3255 /* We store the key here so there's no point in using rcu_dereference() 3256 * but that's fine because the code that changes the pointers will call 3257 * this function after doing so. For a single CPU that would be enough, 3258 * for multiple see the comment above. 3259 */ 3260 build.key = rcu_access_pointer(sta->ptk[sta->ptk_idx]); 3261 if (!build.key) 3262 build.key = rcu_access_pointer(sdata->default_unicast_key); 3263 if (build.key) { 3264 bool gen_iv, iv_spc, mmic; 3265 3266 gen_iv = build.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV; 3267 iv_spc = build.key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE; 3268 mmic = build.key->conf.flags & 3269 (IEEE80211_KEY_FLAG_GENERATE_MMIC | 3270 IEEE80211_KEY_FLAG_PUT_MIC_SPACE); 3271 3272 /* don't handle software crypto */ 3273 if (!(build.key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) 3274 goto out; 3275 3276 /* Key is being removed */ 3277 if (build.key->flags & KEY_FLAG_TAINTED) 3278 goto out; 3279 3280 switch (build.key->conf.cipher) { 3281 case WLAN_CIPHER_SUITE_CCMP: 3282 case WLAN_CIPHER_SUITE_CCMP_256: 3283 if (gen_iv) 3284 build.pn_offs = build.hdr_len; 3285 if (gen_iv || iv_spc) 3286 build.hdr_len += IEEE80211_CCMP_HDR_LEN; 3287 break; 3288 case WLAN_CIPHER_SUITE_GCMP: 3289 case WLAN_CIPHER_SUITE_GCMP_256: 3290 if (gen_iv) 3291 build.pn_offs = build.hdr_len; 3292 if (gen_iv || iv_spc) 3293 build.hdr_len += IEEE80211_GCMP_HDR_LEN; 3294 break; 3295 case WLAN_CIPHER_SUITE_TKIP: 3296 /* cannot handle MMIC or IV generation in xmit-fast */ 3297 if (mmic || gen_iv) 3298 goto out; 3299 if (iv_spc) 3300 build.hdr_len += IEEE80211_TKIP_IV_LEN; 3301 break; 3302 case WLAN_CIPHER_SUITE_WEP40: 3303 case WLAN_CIPHER_SUITE_WEP104: 3304 /* cannot handle IV generation in fast-xmit */ 3305 if (gen_iv) 3306 goto out; 3307 if (iv_spc) 3308 build.hdr_len += IEEE80211_WEP_IV_LEN; 3309 break; 3310 case WLAN_CIPHER_SUITE_AES_CMAC: 3311 case WLAN_CIPHER_SUITE_BIP_CMAC_256: 3312 case WLAN_CIPHER_SUITE_BIP_GMAC_128: 3313 case WLAN_CIPHER_SUITE_BIP_GMAC_256: 3314 WARN(1, 3315 "management cipher suite 0x%x enabled for data\n", 3316 build.key->conf.cipher); 3317 goto out; 3318 default: 3319 /* we don't know how to generate IVs for this at all */ 3320 if (WARN_ON(gen_iv)) 3321 goto out; 3322 } 3323 3324 fc |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); 3325 } 3326 3327 hdr->frame_control = fc; 3328 3329 memcpy(build.hdr + build.hdr_len, 3330 rfc1042_header, sizeof(rfc1042_header)); 3331 build.hdr_len += sizeof(rfc1042_header); 3332 3333 fast_tx = kmemdup(&build, sizeof(build), GFP_ATOMIC); 3334 /* if the kmemdup fails, continue w/o fast_tx */ 3335 3336 out: 3337 /* we might have raced against another call to this function */ 3338 old = rcu_dereference_protected(sta->fast_tx, 3339 lockdep_is_held(&sta->lock)); 3340 rcu_assign_pointer(sta->fast_tx, fast_tx); 3341 if (old) 3342 kfree_rcu(old, rcu_head); 3343 spin_unlock_bh(&sta->lock); 3344 } 3345 3346 void ieee80211_check_fast_xmit_all(struct ieee80211_local *local) 3347 { 3348 struct sta_info *sta; 3349 3350 rcu_read_lock(); 3351 list_for_each_entry_rcu(sta, &local->sta_list, list) 3352 ieee80211_check_fast_xmit(sta); 3353 rcu_read_unlock(); 3354 } 3355 3356 void ieee80211_check_fast_xmit_iface(struct ieee80211_sub_if_data *sdata) 3357 { 3358 struct ieee80211_local *local = sdata->local; 3359 struct sta_info *sta; 3360 3361 rcu_read_lock(); 3362 3363 list_for_each_entry_rcu(sta, &local->sta_list, list) { 3364 if (sdata != sta->sdata && 3365 (!sta->sdata->bss || sta->sdata->bss != sdata->bss)) 3366 continue; 3367 ieee80211_check_fast_xmit(sta); 3368 } 3369 3370 rcu_read_unlock(); 3371 } 3372 3373 void ieee80211_clear_fast_xmit(struct sta_info *sta) 3374 { 3375 struct ieee80211_fast_tx *fast_tx; 3376 3377 spin_lock_bh(&sta->lock); 3378 fast_tx = rcu_dereference_protected(sta->fast_tx, 3379 lockdep_is_held(&sta->lock)); 3380 RCU_INIT_POINTER(sta->fast_tx, NULL); 3381 spin_unlock_bh(&sta->lock); 3382 3383 if (fast_tx) 3384 kfree_rcu(fast_tx, rcu_head); 3385 } 3386 3387 static bool ieee80211_amsdu_realloc_pad(struct ieee80211_local *local, 3388 struct sk_buff *skb, int headroom) 3389 { 3390 if (skb_headroom(skb) < headroom) { 3391 I802_DEBUG_INC(local->tx_expand_skb_head); 3392 3393 if (pskb_expand_head(skb, headroom, 0, GFP_ATOMIC)) { 3394 wiphy_debug(local->hw.wiphy, 3395 "failed to reallocate TX buffer\n"); 3396 return false; 3397 } 3398 } 3399 3400 return true; 3401 } 3402 3403 static bool ieee80211_amsdu_prepare_head(struct ieee80211_sub_if_data *sdata, 3404 struct ieee80211_fast_tx *fast_tx, 3405 struct sk_buff *skb) 3406 { 3407 struct ieee80211_local *local = sdata->local; 3408 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 3409 struct ieee80211_hdr *hdr; 3410 struct ethhdr *amsdu_hdr; 3411 int hdr_len = fast_tx->hdr_len - sizeof(rfc1042_header); 3412 int subframe_len = skb->len - hdr_len; 3413 void *data; 3414 u8 *qc, *h_80211_src, *h_80211_dst; 3415 const u8 *bssid; 3416 3417 if (info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE) 3418 return false; 3419 3420 if (info->control.flags & IEEE80211_TX_CTRL_AMSDU) 3421 return true; 3422 3423 if (!ieee80211_amsdu_realloc_pad(local, skb, 3424 sizeof(*amsdu_hdr) + 3425 local->hw.extra_tx_headroom)) 3426 return false; 3427 3428 data = skb_push(skb, sizeof(*amsdu_hdr)); 3429 memmove(data, data + sizeof(*amsdu_hdr), hdr_len); 3430 hdr = data; 3431 amsdu_hdr = data + hdr_len; 3432 /* h_80211_src/dst is addr* field within hdr */ 3433 h_80211_src = data + fast_tx->sa_offs; 3434 h_80211_dst = data + fast_tx->da_offs; 3435 3436 amsdu_hdr->h_proto = cpu_to_be16(subframe_len); 3437 ether_addr_copy(amsdu_hdr->h_source, h_80211_src); 3438 ether_addr_copy(amsdu_hdr->h_dest, h_80211_dst); 3439 3440 /* according to IEEE 802.11-2012 8.3.2 table 8-19, the outer SA/DA 3441 * fields needs to be changed to BSSID for A-MSDU frames depending 3442 * on FromDS/ToDS values. 3443 */ 3444 switch (sdata->vif.type) { 3445 case NL80211_IFTYPE_STATION: 3446 bssid = sdata->vif.cfg.ap_addr; 3447 break; 3448 case NL80211_IFTYPE_AP: 3449 case NL80211_IFTYPE_AP_VLAN: 3450 bssid = sdata->vif.addr; 3451 break; 3452 default: 3453 bssid = NULL; 3454 } 3455 3456 if (bssid && ieee80211_has_fromds(hdr->frame_control)) 3457 ether_addr_copy(h_80211_src, bssid); 3458 3459 if (bssid && ieee80211_has_tods(hdr->frame_control)) 3460 ether_addr_copy(h_80211_dst, bssid); 3461 3462 qc = ieee80211_get_qos_ctl(hdr); 3463 *qc |= IEEE80211_QOS_CTL_A_MSDU_PRESENT; 3464 3465 info->control.flags |= IEEE80211_TX_CTRL_AMSDU; 3466 3467 return true; 3468 } 3469 3470 static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata, 3471 struct sta_info *sta, 3472 struct ieee80211_fast_tx *fast_tx, 3473 struct sk_buff *skb, 3474 const u8 *da, const u8 *sa) 3475 { 3476 struct ieee80211_local *local = sdata->local; 3477 struct fq *fq = &local->fq; 3478 struct fq_tin *tin; 3479 struct fq_flow *flow; 3480 u8 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK; 3481 struct ieee80211_txq *txq = sta->sta.txq[tid]; 3482 struct txq_info *txqi; 3483 struct sk_buff **frag_tail, *head; 3484 int subframe_len = skb->len - ETH_ALEN; 3485 u8 max_subframes = sta->sta.max_amsdu_subframes; 3486 int max_frags = local->hw.max_tx_fragments; 3487 int max_amsdu_len = sta->sta.cur->max_amsdu_len; 3488 int orig_truesize; 3489 u32 flow_idx; 3490 __be16 len; 3491 void *data; 3492 bool ret = false; 3493 unsigned int orig_len; 3494 int n = 2, nfrags, pad = 0; 3495 u16 hdrlen; 3496 3497 if (!ieee80211_hw_check(&local->hw, TX_AMSDU)) 3498 return false; 3499 3500 if (sdata->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED) 3501 return false; 3502 3503 if (ieee80211_vif_is_mesh(&sdata->vif)) 3504 return false; 3505 3506 if (skb_is_gso(skb)) 3507 return false; 3508 3509 if (!txq) 3510 return false; 3511 3512 txqi = to_txq_info(txq); 3513 if (test_bit(IEEE80211_TXQ_NO_AMSDU, &txqi->flags)) 3514 return false; 3515 3516 if (sta->sta.cur->max_rc_amsdu_len) 3517 max_amsdu_len = min_t(int, max_amsdu_len, 3518 sta->sta.cur->max_rc_amsdu_len); 3519 3520 if (sta->sta.cur->max_tid_amsdu_len[tid]) 3521 max_amsdu_len = min_t(int, max_amsdu_len, 3522 sta->sta.cur->max_tid_amsdu_len[tid]); 3523 3524 flow_idx = fq_flow_idx(fq, skb); 3525 3526 spin_lock_bh(&fq->lock); 3527 3528 /* TODO: Ideally aggregation should be done on dequeue to remain 3529 * responsive to environment changes. 3530 */ 3531 3532 tin = &txqi->tin; 3533 flow = fq_flow_classify(fq, tin, flow_idx, skb); 3534 head = skb_peek_tail(&flow->queue); 3535 if (!head || skb_is_gso(head)) 3536 goto out; 3537 3538 orig_truesize = head->truesize; 3539 orig_len = head->len; 3540 3541 if (skb->len + head->len > max_amsdu_len) 3542 goto out; 3543 3544 nfrags = 1 + skb_shinfo(skb)->nr_frags; 3545 nfrags += 1 + skb_shinfo(head)->nr_frags; 3546 frag_tail = &skb_shinfo(head)->frag_list; 3547 while (*frag_tail) { 3548 nfrags += 1 + skb_shinfo(*frag_tail)->nr_frags; 3549 frag_tail = &(*frag_tail)->next; 3550 n++; 3551 } 3552 3553 if (max_subframes && n > max_subframes) 3554 goto out; 3555 3556 if (max_frags && nfrags > max_frags) 3557 goto out; 3558 3559 if (!drv_can_aggregate_in_amsdu(local, head, skb)) 3560 goto out; 3561 3562 if (!ieee80211_amsdu_prepare_head(sdata, fast_tx, head)) 3563 goto out; 3564 3565 /* If n == 2, the "while (*frag_tail)" loop above didn't execute 3566 * and frag_tail should be &skb_shinfo(head)->frag_list. 3567 * However, ieee80211_amsdu_prepare_head() can reallocate it. 3568 * Reload frag_tail to have it pointing to the correct place. 3569 */ 3570 if (n == 2) 3571 frag_tail = &skb_shinfo(head)->frag_list; 3572 3573 /* 3574 * Pad out the previous subframe to a multiple of 4 by adding the 3575 * padding to the next one, that's being added. Note that head->len 3576 * is the length of the full A-MSDU, but that works since each time 3577 * we add a new subframe we pad out the previous one to a multiple 3578 * of 4 and thus it no longer matters in the next round. 3579 */ 3580 hdrlen = fast_tx->hdr_len - sizeof(rfc1042_header); 3581 if ((head->len - hdrlen) & 3) 3582 pad = 4 - ((head->len - hdrlen) & 3); 3583 3584 if (!ieee80211_amsdu_realloc_pad(local, skb, sizeof(rfc1042_header) + 3585 2 + pad)) 3586 goto out_recalc; 3587 3588 ret = true; 3589 data = skb_push(skb, ETH_ALEN + 2); 3590 ether_addr_copy(data, da); 3591 ether_addr_copy(data + ETH_ALEN, sa); 3592 3593 data += 2 * ETH_ALEN; 3594 len = cpu_to_be16(subframe_len); 3595 memcpy(data, &len, 2); 3596 memcpy(data + 2, rfc1042_header, sizeof(rfc1042_header)); 3597 3598 memset(skb_push(skb, pad), 0, pad); 3599 3600 head->len += skb->len; 3601 head->data_len += skb->len; 3602 *frag_tail = skb; 3603 3604 out_recalc: 3605 fq->memory_usage += head->truesize - orig_truesize; 3606 if (head->len != orig_len) { 3607 flow->backlog += head->len - orig_len; 3608 tin->backlog_bytes += head->len - orig_len; 3609 } 3610 out: 3611 spin_unlock_bh(&fq->lock); 3612 3613 return ret; 3614 } 3615 3616 /* 3617 * Can be called while the sta lock is held. Anything that can cause packets to 3618 * be generated will cause deadlock! 3619 */ 3620 static ieee80211_tx_result 3621 ieee80211_xmit_fast_finish(struct ieee80211_sub_if_data *sdata, 3622 struct sta_info *sta, u8 pn_offs, 3623 struct ieee80211_key *key, 3624 struct ieee80211_tx_data *tx) 3625 { 3626 struct sk_buff *skb = tx->skb; 3627 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 3628 struct ieee80211_hdr *hdr = (void *)skb->data; 3629 u8 tid = IEEE80211_NUM_TIDS; 3630 3631 if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL) && 3632 ieee80211_tx_h_rate_ctrl(tx) != TX_CONTINUE) 3633 return TX_DROP; 3634 3635 if (key) 3636 info->control.hw_key = &key->conf; 3637 3638 dev_sw_netstats_tx_add(skb->dev, 1, skb->len); 3639 3640 if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) { 3641 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK; 3642 hdr->seq_ctrl = ieee80211_tx_next_seq(sta, tid); 3643 } else { 3644 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ; 3645 hdr->seq_ctrl = cpu_to_le16(sdata->sequence_number); 3646 sdata->sequence_number += 0x10; 3647 } 3648 3649 if (skb_shinfo(skb)->gso_size) 3650 sta->deflink.tx_stats.msdu[tid] += 3651 DIV_ROUND_UP(skb->len, skb_shinfo(skb)->gso_size); 3652 else 3653 sta->deflink.tx_stats.msdu[tid]++; 3654 3655 info->hw_queue = sdata->vif.hw_queue[skb_get_queue_mapping(skb)]; 3656 3657 /* statistics normally done by ieee80211_tx_h_stats (but that 3658 * has to consider fragmentation, so is more complex) 3659 */ 3660 sta->deflink.tx_stats.bytes[skb_get_queue_mapping(skb)] += skb->len; 3661 sta->deflink.tx_stats.packets[skb_get_queue_mapping(skb)]++; 3662 3663 if (pn_offs) { 3664 u64 pn; 3665 u8 *crypto_hdr = skb->data + pn_offs; 3666 3667 switch (key->conf.cipher) { 3668 case WLAN_CIPHER_SUITE_CCMP: 3669 case WLAN_CIPHER_SUITE_CCMP_256: 3670 case WLAN_CIPHER_SUITE_GCMP: 3671 case WLAN_CIPHER_SUITE_GCMP_256: 3672 pn = atomic64_inc_return(&key->conf.tx_pn); 3673 crypto_hdr[0] = pn; 3674 crypto_hdr[1] = pn >> 8; 3675 crypto_hdr[3] = 0x20 | (key->conf.keyidx << 6); 3676 crypto_hdr[4] = pn >> 16; 3677 crypto_hdr[5] = pn >> 24; 3678 crypto_hdr[6] = pn >> 32; 3679 crypto_hdr[7] = pn >> 40; 3680 break; 3681 } 3682 } 3683 3684 return TX_CONTINUE; 3685 } 3686 3687 static netdev_features_t 3688 ieee80211_sdata_netdev_features(struct ieee80211_sub_if_data *sdata) 3689 { 3690 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN) 3691 return sdata->vif.netdev_features; 3692 3693 if (!sdata->bss) 3694 return 0; 3695 3696 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap); 3697 return sdata->vif.netdev_features; 3698 } 3699 3700 static struct sk_buff * 3701 ieee80211_tx_skb_fixup(struct sk_buff *skb, netdev_features_t features) 3702 { 3703 if (skb_is_gso(skb)) { 3704 struct sk_buff *segs; 3705 3706 segs = skb_gso_segment(skb, features); 3707 if (!segs) 3708 return skb; 3709 if (IS_ERR(segs)) 3710 goto free; 3711 3712 consume_skb(skb); 3713 return segs; 3714 } 3715 3716 if (skb_needs_linearize(skb, features) && __skb_linearize(skb)) 3717 goto free; 3718 3719 if (skb->ip_summed == CHECKSUM_PARTIAL) { 3720 int ofs = skb_checksum_start_offset(skb); 3721 3722 if (skb->encapsulation) 3723 skb_set_inner_transport_header(skb, ofs); 3724 else 3725 skb_set_transport_header(skb, ofs); 3726 3727 if (skb_csum_hwoffload_help(skb, features)) 3728 goto free; 3729 } 3730 3731 skb_mark_not_on_list(skb); 3732 return skb; 3733 3734 free: 3735 kfree_skb(skb); 3736 return NULL; 3737 } 3738 3739 void __ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata, 3740 struct sta_info *sta, 3741 struct ieee80211_fast_tx *fast_tx, 3742 struct sk_buff *skb, bool ampdu, 3743 const u8 *da, const u8 *sa) 3744 { 3745 struct ieee80211_local *local = sdata->local; 3746 struct ieee80211_hdr *hdr = (void *)fast_tx->hdr; 3747 struct ieee80211_tx_info *info; 3748 struct ieee80211_tx_data tx; 3749 ieee80211_tx_result r; 3750 int hw_headroom = sdata->local->hw.extra_tx_headroom; 3751 int extra_head = fast_tx->hdr_len - (ETH_HLEN - 2); 3752 3753 skb = skb_share_check(skb, GFP_ATOMIC); 3754 if (unlikely(!skb)) 3755 return; 3756 3757 if ((hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) && 3758 ieee80211_amsdu_aggregate(sdata, sta, fast_tx, skb, da, sa)) 3759 return; 3760 3761 /* will not be crypto-handled beyond what we do here, so use false 3762 * as the may-encrypt argument for the resize to not account for 3763 * more room than we already have in 'extra_head' 3764 */ 3765 if (unlikely(ieee80211_skb_resize(sdata, skb, 3766 max_t(int, extra_head + hw_headroom - 3767 skb_headroom(skb), 0), 3768 ENCRYPT_NO))) 3769 goto free; 3770 3771 hdr = skb_push(skb, extra_head); 3772 memcpy(skb->data, fast_tx->hdr, fast_tx->hdr_len); 3773 memcpy(skb->data + fast_tx->da_offs, da, ETH_ALEN); 3774 memcpy(skb->data + fast_tx->sa_offs, sa, ETH_ALEN); 3775 3776 info = IEEE80211_SKB_CB(skb); 3777 memset(info, 0, sizeof(*info)); 3778 info->band = fast_tx->band; 3779 info->control.vif = &sdata->vif; 3780 info->flags = IEEE80211_TX_CTL_FIRST_FRAGMENT | 3781 IEEE80211_TX_CTL_DONTFRAG; 3782 info->control.flags = IEEE80211_TX_CTRL_FAST_XMIT | 3783 u32_encode_bits(IEEE80211_LINK_UNSPECIFIED, 3784 IEEE80211_TX_CTRL_MLO_LINK); 3785 3786 #ifdef CONFIG_MAC80211_DEBUGFS 3787 if (local->force_tx_status) 3788 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; 3789 #endif 3790 3791 if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) { 3792 u8 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK; 3793 3794 *ieee80211_get_qos_ctl(hdr) = tid; 3795 } 3796 3797 __skb_queue_head_init(&tx.skbs); 3798 3799 tx.flags = IEEE80211_TX_UNICAST; 3800 tx.local = local; 3801 tx.sdata = sdata; 3802 tx.sta = sta; 3803 tx.key = fast_tx->key; 3804 3805 if (ieee80211_queue_skb(local, sdata, sta, skb)) 3806 return; 3807 3808 tx.skb = skb; 3809 r = ieee80211_xmit_fast_finish(sdata, sta, fast_tx->pn_offs, 3810 fast_tx->key, &tx); 3811 tx.skb = NULL; 3812 if (r == TX_DROP) { 3813 tx.sdata->tx_handlers_drop++; 3814 goto free; 3815 } 3816 3817 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) 3818 sdata = container_of(sdata->bss, 3819 struct ieee80211_sub_if_data, u.ap); 3820 3821 __skb_queue_tail(&tx.skbs, skb); 3822 ieee80211_tx_frags(local, &sdata->vif, sta, &tx.skbs, false); 3823 return; 3824 3825 free: 3826 kfree_skb(skb); 3827 } 3828 3829 static bool ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata, 3830 struct sta_info *sta, 3831 struct ieee80211_fast_tx *fast_tx, 3832 struct sk_buff *skb) 3833 { 3834 u16 ethertype = (skb->data[12] << 8) | skb->data[13]; 3835 struct ieee80211_hdr *hdr = (void *)fast_tx->hdr; 3836 struct tid_ampdu_tx *tid_tx = NULL; 3837 struct sk_buff *next; 3838 struct ethhdr eth; 3839 u8 tid = IEEE80211_NUM_TIDS; 3840 3841 /* control port protocol needs a lot of special handling */ 3842 if (cpu_to_be16(ethertype) == sdata->control_port_protocol) 3843 return false; 3844 3845 /* only RFC 1042 SNAP */ 3846 if (ethertype < ETH_P_802_3_MIN) 3847 return false; 3848 3849 /* don't handle TX status request here either */ 3850 if (sk_requests_wifi_status(skb->sk)) 3851 return false; 3852 3853 if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) { 3854 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK; 3855 tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]); 3856 if (tid_tx) { 3857 if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) 3858 return false; 3859 if (tid_tx->timeout) 3860 tid_tx->last_tx = jiffies; 3861 } 3862 } 3863 3864 memcpy(ð, skb->data, ETH_HLEN - 2); 3865 3866 /* after this point (skb is modified) we cannot return false */ 3867 skb = ieee80211_tx_skb_fixup(skb, ieee80211_sdata_netdev_features(sdata)); 3868 if (!skb) 3869 return true; 3870 3871 skb_list_walk_safe(skb, skb, next) { 3872 skb_mark_not_on_list(skb); 3873 __ieee80211_xmit_fast(sdata, sta, fast_tx, skb, tid_tx, 3874 eth.h_dest, eth.h_source); 3875 } 3876 3877 return true; 3878 } 3879 3880 struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw, 3881 struct ieee80211_txq *txq) 3882 { 3883 struct ieee80211_local *local = hw_to_local(hw); 3884 struct txq_info *txqi = container_of(txq, struct txq_info, txq); 3885 struct ieee80211_hdr *hdr; 3886 struct sk_buff *skb = NULL; 3887 struct fq *fq = &local->fq; 3888 struct fq_tin *tin = &txqi->tin; 3889 struct ieee80211_tx_info *info; 3890 struct ieee80211_tx_data tx; 3891 ieee80211_tx_result r; 3892 struct ieee80211_vif *vif = txq->vif; 3893 int q = vif->hw_queue[txq->ac]; 3894 unsigned long flags; 3895 bool q_stopped; 3896 3897 WARN_ON_ONCE(softirq_count() == 0); 3898 3899 if (!ieee80211_txq_airtime_check(hw, txq)) 3900 return NULL; 3901 3902 begin: 3903 spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 3904 q_stopped = local->queue_stop_reasons[q]; 3905 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 3906 3907 if (unlikely(q_stopped)) { 3908 /* mark for waking later */ 3909 set_bit(IEEE80211_TXQ_DIRTY, &txqi->flags); 3910 return NULL; 3911 } 3912 3913 spin_lock_bh(&fq->lock); 3914 3915 /* Make sure fragments stay together. */ 3916 skb = __skb_dequeue(&txqi->frags); 3917 if (unlikely(skb)) { 3918 if (!(IEEE80211_SKB_CB(skb)->control.flags & 3919 IEEE80211_TX_INTCFL_NEED_TXPROCESSING)) 3920 goto out; 3921 IEEE80211_SKB_CB(skb)->control.flags &= 3922 ~IEEE80211_TX_INTCFL_NEED_TXPROCESSING; 3923 } else { 3924 if (unlikely(test_bit(IEEE80211_TXQ_STOP, &txqi->flags))) 3925 goto out; 3926 3927 skb = fq_tin_dequeue(fq, tin, fq_tin_dequeue_func); 3928 } 3929 3930 if (!skb) 3931 goto out; 3932 3933 spin_unlock_bh(&fq->lock); 3934 3935 hdr = (struct ieee80211_hdr *)skb->data; 3936 info = IEEE80211_SKB_CB(skb); 3937 3938 memset(&tx, 0, sizeof(tx)); 3939 __skb_queue_head_init(&tx.skbs); 3940 tx.local = local; 3941 tx.skb = skb; 3942 tx.sdata = vif_to_sdata(info->control.vif); 3943 3944 if (txq->sta) { 3945 tx.sta = container_of(txq->sta, struct sta_info, sta); 3946 /* 3947 * Drop unicast frames to unauthorised stations unless they are 3948 * injected frames or EAPOL frames from the local station. 3949 */ 3950 if (unlikely(!(info->flags & IEEE80211_TX_CTL_INJECTED) && 3951 ieee80211_is_data_present(hdr->frame_control) && 3952 !ieee80211_vif_is_mesh(&tx.sdata->vif) && 3953 tx.sdata->vif.type != NL80211_IFTYPE_OCB && 3954 !is_multicast_ether_addr(hdr->addr1) && 3955 !test_sta_flag(tx.sta, WLAN_STA_AUTHORIZED) && 3956 (!(info->control.flags & 3957 IEEE80211_TX_CTRL_PORT_CTRL_PROTO) || 3958 !ieee80211_is_our_addr(tx.sdata, hdr->addr2, 3959 NULL)))) { 3960 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port); 3961 ieee80211_free_txskb(&local->hw, skb); 3962 goto begin; 3963 } 3964 } 3965 3966 /* 3967 * The key can be removed while the packet was queued, so need to call 3968 * this here to get the current key. 3969 */ 3970 info->control.hw_key = NULL; 3971 r = ieee80211_tx_h_select_key(&tx); 3972 if (r != TX_CONTINUE) { 3973 ieee80211_free_txskb(&local->hw, skb); 3974 goto begin; 3975 } 3976 3977 if (test_bit(IEEE80211_TXQ_AMPDU, &txqi->flags)) 3978 info->flags |= (IEEE80211_TX_CTL_AMPDU | 3979 IEEE80211_TX_CTL_DONTFRAG); 3980 3981 if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) { 3982 if (!ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) { 3983 r = ieee80211_tx_h_rate_ctrl(&tx); 3984 if (r != TX_CONTINUE) { 3985 ieee80211_free_txskb(&local->hw, skb); 3986 goto begin; 3987 } 3988 } 3989 goto encap_out; 3990 } 3991 3992 if (info->control.flags & IEEE80211_TX_CTRL_FAST_XMIT) { 3993 struct sta_info *sta = container_of(txq->sta, struct sta_info, 3994 sta); 3995 u8 pn_offs = 0; 3996 3997 if (tx.key && 3998 (tx.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) 3999 pn_offs = ieee80211_hdrlen(hdr->frame_control); 4000 4001 r = ieee80211_xmit_fast_finish(sta->sdata, sta, pn_offs, 4002 tx.key, &tx); 4003 if (r != TX_CONTINUE) { 4004 ieee80211_free_txskb(&local->hw, skb); 4005 goto begin; 4006 } 4007 } else { 4008 if (invoke_tx_handlers_late(&tx)) 4009 goto begin; 4010 4011 skb = __skb_dequeue(&tx.skbs); 4012 info = IEEE80211_SKB_CB(skb); 4013 4014 if (!skb_queue_empty(&tx.skbs)) { 4015 spin_lock_bh(&fq->lock); 4016 skb_queue_splice_tail(&tx.skbs, &txqi->frags); 4017 spin_unlock_bh(&fq->lock); 4018 } 4019 } 4020 4021 if (skb_has_frag_list(skb) && 4022 !ieee80211_hw_check(&local->hw, TX_FRAG_LIST)) { 4023 if (skb_linearize(skb)) { 4024 ieee80211_free_txskb(&local->hw, skb); 4025 goto begin; 4026 } 4027 } 4028 4029 switch (tx.sdata->vif.type) { 4030 case NL80211_IFTYPE_MONITOR: 4031 if ((tx.sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) || 4032 ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR)) { 4033 vif = &tx.sdata->vif; 4034 break; 4035 } 4036 tx.sdata = rcu_dereference(local->monitor_sdata); 4037 if (tx.sdata && 4038 ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF)) { 4039 vif = &tx.sdata->vif; 4040 info->hw_queue = 4041 vif->hw_queue[skb_get_queue_mapping(skb)]; 4042 } else if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) { 4043 ieee80211_free_txskb(&local->hw, skb); 4044 goto begin; 4045 } else { 4046 info->control.vif = NULL; 4047 return skb; 4048 } 4049 break; 4050 case NL80211_IFTYPE_AP_VLAN: 4051 tx.sdata = container_of(tx.sdata->bss, 4052 struct ieee80211_sub_if_data, u.ap); 4053 fallthrough; 4054 default: 4055 vif = &tx.sdata->vif; 4056 break; 4057 } 4058 4059 encap_out: 4060 info->control.vif = vif; 4061 4062 if (wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL)) { 4063 bool ampdu = txq->sta && txq->ac != IEEE80211_AC_VO; 4064 u32 airtime; 4065 4066 airtime = ieee80211_calc_expected_tx_airtime(hw, vif, txq->sta, 4067 skb->len, ampdu); 4068 if (!airtime) 4069 return skb; 4070 4071 airtime = ieee80211_info_set_tx_time_est(info, airtime); 4072 info->tx_time_mc = !tx.sta; 4073 ieee80211_sta_update_pending_airtime(local, tx.sta, txq->ac, 4074 airtime, false, 4075 info->tx_time_mc); 4076 } 4077 4078 return skb; 4079 4080 out: 4081 spin_unlock_bh(&fq->lock); 4082 4083 return skb; 4084 } 4085 EXPORT_SYMBOL(ieee80211_tx_dequeue); 4086 4087 static inline s32 ieee80211_sta_deficit(struct sta_info *sta, u8 ac) 4088 { 4089 struct airtime_info *air_info = &sta->airtime[ac]; 4090 4091 return air_info->deficit - atomic_read(&air_info->aql_tx_pending); 4092 } 4093 4094 static void 4095 ieee80211_txq_set_active(struct txq_info *txqi) 4096 { 4097 struct sta_info *sta; 4098 4099 if (!txqi->txq.sta) 4100 return; 4101 4102 sta = container_of(txqi->txq.sta, struct sta_info, sta); 4103 sta->airtime[txqi->txq.ac].last_active = jiffies; 4104 } 4105 4106 static bool 4107 ieee80211_txq_keep_active(struct txq_info *txqi) 4108 { 4109 struct sta_info *sta; 4110 4111 if (!txqi->txq.sta) 4112 return false; 4113 4114 sta = container_of(txqi->txq.sta, struct sta_info, sta); 4115 if (ieee80211_sta_deficit(sta, txqi->txq.ac) >= 0) 4116 return false; 4117 4118 return ieee80211_sta_keep_active(sta, txqi->txq.ac); 4119 } 4120 4121 struct ieee80211_txq *ieee80211_next_txq(struct ieee80211_hw *hw, u8 ac) 4122 { 4123 struct ieee80211_local *local = hw_to_local(hw); 4124 struct ieee80211_txq *ret = NULL; 4125 struct txq_info *txqi = NULL, *head = NULL; 4126 bool found_eligible_txq = false; 4127 bool aql_check; 4128 4129 spin_lock_bh(&local->active_txq_lock[ac]); 4130 4131 if (!local->schedule_round[ac]) 4132 goto out; 4133 4134 begin: 4135 txqi = list_first_entry_or_null(&local->active_txqs[ac], 4136 struct txq_info, 4137 schedule_order); 4138 if (!txqi) 4139 goto out; 4140 4141 if (txqi == head) { 4142 if (!found_eligible_txq) 4143 goto out; 4144 else 4145 found_eligible_txq = false; 4146 } 4147 4148 if (!head) 4149 head = txqi; 4150 4151 aql_check = ieee80211_txq_airtime_check(hw, &txqi->txq); 4152 if (aql_check) 4153 found_eligible_txq = true; 4154 4155 if (txqi->txq.sta) { 4156 struct sta_info *sta = container_of(txqi->txq.sta, 4157 struct sta_info, sta); 4158 4159 if (ieee80211_sta_deficit(sta, txqi->txq.ac) < 0) { 4160 sta->airtime[txqi->txq.ac].deficit += 4161 sta->airtime_weight; 4162 4163 aql_check = false; 4164 } 4165 } 4166 4167 if (!aql_check) { 4168 list_move_tail(&txqi->schedule_order, 4169 &local->active_txqs[txqi->txq.ac]); 4170 goto begin; 4171 } 4172 4173 if (txqi->schedule_round == local->schedule_round[ac]) 4174 goto out; 4175 4176 list_del_init(&txqi->schedule_order); 4177 txqi->schedule_round = local->schedule_round[ac]; 4178 ret = &txqi->txq; 4179 4180 out: 4181 spin_unlock_bh(&local->active_txq_lock[ac]); 4182 return ret; 4183 } 4184 EXPORT_SYMBOL(ieee80211_next_txq); 4185 4186 void __ieee80211_schedule_txq(struct ieee80211_hw *hw, 4187 struct ieee80211_txq *txq, 4188 bool force) 4189 { 4190 struct ieee80211_local *local = hw_to_local(hw); 4191 struct txq_info *txqi = to_txq_info(txq); 4192 bool has_queue; 4193 4194 spin_lock_bh(&local->active_txq_lock[txq->ac]); 4195 4196 has_queue = force || 4197 (!test_bit(IEEE80211_TXQ_STOP, &txqi->flags) && 4198 txq_has_queue(txq)); 4199 if (list_empty(&txqi->schedule_order) && 4200 (has_queue || ieee80211_txq_keep_active(txqi))) { 4201 /* If airtime accounting is active, always enqueue STAs at the 4202 * head of the list to ensure that they only get moved to the 4203 * back by the airtime DRR scheduler once they have a negative 4204 * deficit. A station that already has a negative deficit will 4205 * get immediately moved to the back of the list on the next 4206 * call to ieee80211_next_txq(). 4207 */ 4208 if (txqi->txq.sta && local->airtime_flags && has_queue && 4209 wiphy_ext_feature_isset(local->hw.wiphy, 4210 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) 4211 list_add(&txqi->schedule_order, 4212 &local->active_txqs[txq->ac]); 4213 else 4214 list_add_tail(&txqi->schedule_order, 4215 &local->active_txqs[txq->ac]); 4216 if (has_queue) 4217 ieee80211_txq_set_active(txqi); 4218 } 4219 4220 spin_unlock_bh(&local->active_txq_lock[txq->ac]); 4221 } 4222 EXPORT_SYMBOL(__ieee80211_schedule_txq); 4223 4224 DEFINE_STATIC_KEY_FALSE(aql_disable); 4225 4226 bool ieee80211_txq_airtime_check(struct ieee80211_hw *hw, 4227 struct ieee80211_txq *txq) 4228 { 4229 struct sta_info *sta; 4230 struct ieee80211_local *local = hw_to_local(hw); 4231 4232 if (!wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL)) 4233 return true; 4234 4235 if (static_branch_unlikely(&aql_disable)) 4236 return true; 4237 4238 if (!txq->sta) 4239 return atomic_read(&local->aql_mc_pending_airtime) < 4240 local->aql_txq_limit_mc; 4241 4242 if (unlikely(txq->tid == IEEE80211_NUM_TIDS)) 4243 return true; 4244 4245 sta = container_of(txq->sta, struct sta_info, sta); 4246 if (atomic_read(&sta->airtime[txq->ac].aql_tx_pending) < 4247 sta->airtime[txq->ac].aql_limit_low) 4248 return true; 4249 4250 if (atomic_read(&local->aql_total_pending_airtime) < 4251 local->aql_threshold && 4252 atomic_read(&sta->airtime[txq->ac].aql_tx_pending) < 4253 sta->airtime[txq->ac].aql_limit_high) 4254 return true; 4255 4256 return false; 4257 } 4258 EXPORT_SYMBOL(ieee80211_txq_airtime_check); 4259 4260 u32 ieee80211_txq_aql_pending(struct ieee80211_hw *hw, 4261 struct ieee80211_txq *txq) 4262 { 4263 struct ieee80211_local *local = hw_to_local(hw); 4264 struct sta_info *sta; 4265 4266 if (unlikely(txq->tid == IEEE80211_NUM_TIDS)) 4267 return 0; 4268 4269 if (!txq->sta) 4270 return atomic_read(&local->aql_mc_pending_airtime); 4271 4272 sta = container_of(txq->sta, struct sta_info, sta); 4273 4274 return atomic_read(&sta->airtime[txq->ac].aql_tx_pending); 4275 } 4276 EXPORT_SYMBOL(ieee80211_txq_aql_pending); 4277 4278 static bool 4279 ieee80211_txq_schedule_airtime_check(struct ieee80211_local *local, u8 ac) 4280 { 4281 unsigned int num_txq = 0; 4282 struct txq_info *txq; 4283 u32 aql_limit; 4284 4285 if (!wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL)) 4286 return true; 4287 4288 list_for_each_entry(txq, &local->active_txqs[ac], schedule_order) 4289 num_txq++; 4290 4291 aql_limit = (num_txq - 1) * local->aql_txq_limit_low[ac] / 2 + 4292 local->aql_txq_limit_high[ac]; 4293 4294 return atomic_read(&local->aql_ac_pending_airtime[ac]) < aql_limit; 4295 } 4296 4297 bool ieee80211_txq_may_transmit(struct ieee80211_hw *hw, 4298 struct ieee80211_txq *txq) 4299 { 4300 struct ieee80211_local *local = hw_to_local(hw); 4301 struct txq_info *iter, *tmp, *txqi = to_txq_info(txq); 4302 struct sta_info *sta; 4303 u8 ac = txq->ac; 4304 4305 spin_lock_bh(&local->active_txq_lock[ac]); 4306 4307 if (list_empty(&txqi->schedule_order)) 4308 goto out; 4309 4310 if (!ieee80211_txq_schedule_airtime_check(local, ac)) 4311 goto out; 4312 4313 if (!txqi->txq.sta) 4314 goto out; 4315 4316 list_for_each_entry_safe(iter, tmp, &local->active_txqs[ac], 4317 schedule_order) { 4318 if (iter == txqi) 4319 break; 4320 4321 if (!iter->txq.sta) { 4322 list_move_tail(&iter->schedule_order, 4323 &local->active_txqs[ac]); 4324 continue; 4325 } 4326 sta = container_of(iter->txq.sta, struct sta_info, sta); 4327 if (ieee80211_sta_deficit(sta, ac) < 0) 4328 sta->airtime[ac].deficit += sta->airtime_weight; 4329 list_move_tail(&iter->schedule_order, &local->active_txqs[ac]); 4330 } 4331 4332 sta = container_of(txqi->txq.sta, struct sta_info, sta); 4333 if (sta->airtime[ac].deficit >= 0) 4334 goto out; 4335 4336 sta->airtime[ac].deficit += sta->airtime_weight; 4337 list_move_tail(&txqi->schedule_order, &local->active_txqs[ac]); 4338 spin_unlock_bh(&local->active_txq_lock[ac]); 4339 4340 return false; 4341 out: 4342 if (!list_empty(&txqi->schedule_order)) 4343 list_del_init(&txqi->schedule_order); 4344 spin_unlock_bh(&local->active_txq_lock[ac]); 4345 4346 return true; 4347 } 4348 EXPORT_SYMBOL(ieee80211_txq_may_transmit); 4349 4350 void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac) 4351 { 4352 struct ieee80211_local *local = hw_to_local(hw); 4353 4354 spin_lock_bh(&local->active_txq_lock[ac]); 4355 4356 if (ieee80211_txq_schedule_airtime_check(local, ac)) { 4357 local->schedule_round[ac]++; 4358 if (!local->schedule_round[ac]) 4359 local->schedule_round[ac]++; 4360 } else { 4361 local->schedule_round[ac] = 0; 4362 } 4363 4364 spin_unlock_bh(&local->active_txq_lock[ac]); 4365 } 4366 EXPORT_SYMBOL(ieee80211_txq_schedule_start); 4367 4368 void __ieee80211_subif_start_xmit(struct sk_buff *skb, 4369 struct net_device *dev, 4370 u32 info_flags, 4371 u32 ctrl_flags, 4372 u64 cookie) 4373 { 4374 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4375 struct ieee80211_local *local = sdata->local; 4376 struct sta_info *sta; 4377 struct sk_buff *next; 4378 int len = skb->len; 4379 4380 if (unlikely(!ieee80211_sdata_running(sdata) || skb->len < ETH_HLEN)) { 4381 kfree_skb(skb); 4382 return; 4383 } 4384 4385 sk_pacing_shift_update(skb->sk, sdata->local->hw.tx_sk_pacing_shift); 4386 4387 rcu_read_lock(); 4388 4389 if (ieee80211_vif_is_mesh(&sdata->vif) && 4390 ieee80211_hw_check(&local->hw, SUPPORT_FAST_XMIT) && 4391 ieee80211_mesh_xmit_fast(sdata, skb, ctrl_flags)) 4392 goto out; 4393 4394 if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) 4395 goto out_free; 4396 4397 if (IS_ERR(sta)) 4398 sta = NULL; 4399 4400 skb_set_queue_mapping(skb, ieee80211_select_queue(sdata, sta, skb)); 4401 ieee80211_aggr_check(sdata, sta, skb); 4402 4403 if (sta) { 4404 struct ieee80211_fast_tx *fast_tx; 4405 4406 fast_tx = rcu_dereference(sta->fast_tx); 4407 4408 if (fast_tx && 4409 ieee80211_xmit_fast(sdata, sta, fast_tx, skb)) 4410 goto out; 4411 } 4412 4413 /* the frame could be fragmented, software-encrypted, and other 4414 * things so we cannot really handle checksum or GSO offload. 4415 * fix it up in software before we handle anything else. 4416 */ 4417 skb = ieee80211_tx_skb_fixup(skb, 0); 4418 if (!skb) { 4419 len = 0; 4420 goto out; 4421 } 4422 4423 skb_list_walk_safe(skb, skb, next) { 4424 skb_mark_not_on_list(skb); 4425 4426 if (skb->protocol == sdata->control_port_protocol) 4427 ctrl_flags |= IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP; 4428 4429 skb = ieee80211_build_hdr(sdata, skb, info_flags, 4430 sta, ctrl_flags, cookie); 4431 if (IS_ERR(skb)) { 4432 kfree_skb_list(next); 4433 goto out; 4434 } 4435 4436 dev_sw_netstats_tx_add(dev, 1, skb->len); 4437 4438 ieee80211_xmit(sdata, sta, skb); 4439 } 4440 goto out; 4441 out_free: 4442 kfree_skb(skb); 4443 len = 0; 4444 out: 4445 if (len) 4446 ieee80211_tpt_led_trig_tx(local, len); 4447 rcu_read_unlock(); 4448 } 4449 4450 static int ieee80211_change_da(struct sk_buff *skb, struct sta_info *sta) 4451 { 4452 struct ethhdr *eth; 4453 int err; 4454 4455 err = skb_ensure_writable(skb, ETH_HLEN); 4456 if (unlikely(err)) 4457 return err; 4458 4459 eth = (void *)skb->data; 4460 ether_addr_copy(eth->h_dest, sta->sta.addr); 4461 4462 return 0; 4463 } 4464 4465 static bool ieee80211_multicast_to_unicast(struct sk_buff *skb, 4466 struct net_device *dev) 4467 { 4468 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4469 const struct ethhdr *eth = (void *)skb->data; 4470 const struct vlan_ethhdr *ethvlan = (void *)skb->data; 4471 __be16 ethertype; 4472 4473 switch (sdata->vif.type) { 4474 case NL80211_IFTYPE_AP_VLAN: 4475 if (sdata->u.vlan.sta) 4476 return false; 4477 if (sdata->wdev.use_4addr) 4478 return false; 4479 fallthrough; 4480 case NL80211_IFTYPE_AP: 4481 /* check runtime toggle for this bss */ 4482 if (!sdata->bss->multicast_to_unicast) 4483 return false; 4484 break; 4485 default: 4486 return false; 4487 } 4488 4489 /* multicast to unicast conversion only for some payload */ 4490 ethertype = eth->h_proto; 4491 if (ethertype == htons(ETH_P_8021Q) && skb->len >= VLAN_ETH_HLEN) 4492 ethertype = ethvlan->h_vlan_encapsulated_proto; 4493 switch (ethertype) { 4494 case htons(ETH_P_ARP): 4495 case htons(ETH_P_IP): 4496 case htons(ETH_P_IPV6): 4497 break; 4498 default: 4499 return false; 4500 } 4501 4502 return true; 4503 } 4504 4505 static void 4506 ieee80211_convert_to_unicast(struct sk_buff *skb, struct net_device *dev, 4507 struct sk_buff_head *queue) 4508 { 4509 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4510 struct ieee80211_local *local = sdata->local; 4511 const struct ethhdr *eth = (struct ethhdr *)skb->data; 4512 struct sta_info *sta, *first = NULL; 4513 struct sk_buff *cloned_skb; 4514 4515 rcu_read_lock(); 4516 4517 list_for_each_entry_rcu(sta, &local->sta_list, list) { 4518 if (sdata != sta->sdata) 4519 /* AP-VLAN mismatch */ 4520 continue; 4521 if (unlikely(ether_addr_equal(eth->h_source, sta->sta.addr))) 4522 /* do not send back to source */ 4523 continue; 4524 if (!first) { 4525 first = sta; 4526 continue; 4527 } 4528 cloned_skb = skb_clone(skb, GFP_ATOMIC); 4529 if (!cloned_skb) 4530 goto multicast; 4531 if (unlikely(ieee80211_change_da(cloned_skb, sta))) { 4532 dev_kfree_skb(cloned_skb); 4533 goto multicast; 4534 } 4535 __skb_queue_tail(queue, cloned_skb); 4536 } 4537 4538 if (likely(first)) { 4539 if (unlikely(ieee80211_change_da(skb, first))) 4540 goto multicast; 4541 __skb_queue_tail(queue, skb); 4542 } else { 4543 /* no STA connected, drop */ 4544 kfree_skb(skb); 4545 skb = NULL; 4546 } 4547 4548 goto out; 4549 multicast: 4550 __skb_queue_purge(queue); 4551 __skb_queue_tail(queue, skb); 4552 out: 4553 rcu_read_unlock(); 4554 } 4555 4556 static void ieee80211_mlo_multicast_tx_one(struct ieee80211_sub_if_data *sdata, 4557 struct sk_buff *skb, u32 ctrl_flags, 4558 unsigned int link_id) 4559 { 4560 struct sk_buff *out; 4561 4562 out = skb_copy(skb, GFP_ATOMIC); 4563 if (!out) 4564 return; 4565 4566 ctrl_flags |= u32_encode_bits(link_id, IEEE80211_TX_CTRL_MLO_LINK); 4567 __ieee80211_subif_start_xmit(out, sdata->dev, 0, ctrl_flags, 0); 4568 } 4569 4570 static void ieee80211_mlo_multicast_tx(struct net_device *dev, 4571 struct sk_buff *skb) 4572 { 4573 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4574 unsigned long links = sdata->vif.active_links; 4575 unsigned int link; 4576 u32 ctrl_flags = IEEE80211_TX_CTRL_MCAST_MLO_FIRST_TX; 4577 4578 if (hweight16(links) == 1) { 4579 ctrl_flags |= u32_encode_bits(__ffs(links), 4580 IEEE80211_TX_CTRL_MLO_LINK); 4581 4582 __ieee80211_subif_start_xmit(skb, sdata->dev, 0, ctrl_flags, 0); 4583 return; 4584 } 4585 4586 for_each_set_bit(link, &links, IEEE80211_MLD_MAX_NUM_LINKS) { 4587 ieee80211_mlo_multicast_tx_one(sdata, skb, ctrl_flags, link); 4588 ctrl_flags = 0; 4589 } 4590 kfree_skb(skb); 4591 } 4592 4593 /** 4594 * ieee80211_subif_start_xmit - netif start_xmit function for 802.3 vifs 4595 * @skb: packet to be sent 4596 * @dev: incoming interface 4597 * 4598 * On failure skb will be freed. 4599 * 4600 * Returns: the netdev TX status (but really only %NETDEV_TX_OK) 4601 */ 4602 netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb, 4603 struct net_device *dev) 4604 { 4605 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4606 const struct ethhdr *eth = (void *)skb->data; 4607 4608 if (likely(!is_multicast_ether_addr(eth->h_dest))) 4609 goto normal; 4610 4611 if (unlikely(!ieee80211_sdata_running(sdata))) { 4612 kfree_skb(skb); 4613 return NETDEV_TX_OK; 4614 } 4615 4616 if (unlikely(ieee80211_multicast_to_unicast(skb, dev))) { 4617 struct sk_buff_head queue; 4618 4619 __skb_queue_head_init(&queue); 4620 ieee80211_convert_to_unicast(skb, dev, &queue); 4621 while ((skb = __skb_dequeue(&queue))) 4622 __ieee80211_subif_start_xmit(skb, dev, 0, 4623 IEEE80211_TX_CTRL_MLO_LINK_UNSPEC, 4624 0); 4625 } else if (ieee80211_vif_is_mld(&sdata->vif) && 4626 ((sdata->vif.type == NL80211_IFTYPE_AP && 4627 !ieee80211_hw_check(&sdata->local->hw, MLO_MCAST_MULTI_LINK_TX)) || 4628 (sdata->vif.type == NL80211_IFTYPE_AP_VLAN && 4629 !sdata->wdev.use_4addr))) { 4630 ieee80211_mlo_multicast_tx(dev, skb); 4631 } else { 4632 normal: 4633 __ieee80211_subif_start_xmit(skb, dev, 0, 4634 IEEE80211_TX_CTRL_MLO_LINK_UNSPEC, 4635 0); 4636 } 4637 4638 return NETDEV_TX_OK; 4639 } 4640 4641 4642 4643 static bool __ieee80211_tx_8023(struct ieee80211_sub_if_data *sdata, 4644 struct sk_buff *skb, struct sta_info *sta, 4645 bool txpending) 4646 { 4647 struct ieee80211_local *local = sdata->local; 4648 struct ieee80211_tx_control control = {}; 4649 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 4650 struct ieee80211_sta *pubsta = NULL; 4651 unsigned long flags; 4652 int q = info->hw_queue; 4653 4654 spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 4655 4656 if (local->queue_stop_reasons[q] || 4657 (!txpending && !skb_queue_empty(&local->pending[q]))) { 4658 if (txpending) 4659 skb_queue_head(&local->pending[q], skb); 4660 else 4661 skb_queue_tail(&local->pending[q], skb); 4662 4663 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 4664 4665 return false; 4666 } 4667 4668 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 4669 4670 if (sta && sta->uploaded) 4671 pubsta = &sta->sta; 4672 4673 control.sta = pubsta; 4674 4675 drv_tx(local, &control, skb); 4676 4677 return true; 4678 } 4679 4680 static bool ieee80211_tx_8023(struct ieee80211_sub_if_data *sdata, 4681 struct sk_buff *skb, struct sta_info *sta, 4682 bool txpending) 4683 { 4684 struct ieee80211_local *local = sdata->local; 4685 struct sk_buff *next; 4686 bool ret = true; 4687 4688 if (ieee80211_queue_skb(local, sdata, sta, skb)) 4689 return true; 4690 4691 skb_list_walk_safe(skb, skb, next) { 4692 skb_mark_not_on_list(skb); 4693 if (!__ieee80211_tx_8023(sdata, skb, sta, txpending)) 4694 ret = false; 4695 } 4696 4697 return ret; 4698 } 4699 4700 static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata, 4701 struct net_device *dev, struct sta_info *sta, 4702 struct ieee80211_key *key, struct sk_buff *skb) 4703 { 4704 struct ieee80211_tx_info *info; 4705 struct ieee80211_local *local = sdata->local; 4706 struct tid_ampdu_tx *tid_tx = NULL; 4707 struct sk_buff *seg, *next; 4708 unsigned int skbs = 0, len = 0; 4709 u16 queue; 4710 u8 tid; 4711 4712 queue = ieee80211_select_queue(sdata, sta, skb); 4713 skb_set_queue_mapping(skb, queue); 4714 4715 if (unlikely(test_bit(SCAN_SW_SCANNING, &local->scanning)) && 4716 test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)) 4717 goto out_free; 4718 4719 skb = skb_share_check(skb, GFP_ATOMIC); 4720 if (unlikely(!skb)) 4721 return; 4722 4723 ieee80211_aggr_check(sdata, sta, skb); 4724 4725 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK; 4726 4727 if (sta) 4728 tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]); 4729 if (tid_tx) { 4730 if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) { 4731 /* fall back to non-offload slow path */ 4732 __ieee80211_subif_start_xmit(skb, dev, 0, 4733 IEEE80211_TX_CTRL_MLO_LINK_UNSPEC, 4734 0); 4735 return; 4736 } 4737 4738 if (tid_tx->timeout) 4739 tid_tx->last_tx = jiffies; 4740 } 4741 4742 skb = ieee80211_tx_skb_fixup(skb, ieee80211_sdata_netdev_features(sdata)); 4743 if (!skb) 4744 return; 4745 4746 info = IEEE80211_SKB_CB(skb); 4747 memset(info, 0, sizeof(*info)); 4748 4749 info->hw_queue = sdata->vif.hw_queue[queue]; 4750 4751 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) 4752 sdata = container_of(sdata->bss, 4753 struct ieee80211_sub_if_data, u.ap); 4754 4755 info->flags |= IEEE80211_TX_CTL_HW_80211_ENCAP; 4756 info->control.vif = &sdata->vif; 4757 4758 if (key) 4759 info->control.hw_key = &key->conf; 4760 4761 skb_list_walk_safe(skb, seg, next) { 4762 skbs++; 4763 len += seg->len; 4764 if (seg != skb) 4765 memcpy(IEEE80211_SKB_CB(seg), info, sizeof(*info)); 4766 } 4767 4768 if (unlikely(sk_requests_wifi_status(skb->sk))) { 4769 info->status_data = ieee80211_store_ack_skb(local, skb, 4770 &info->flags, 0); 4771 if (info->status_data) 4772 info->status_data_idr = 1; 4773 } 4774 4775 dev_sw_netstats_tx_add(dev, skbs, len); 4776 4777 if (sta) { 4778 sta->deflink.tx_stats.packets[queue] += skbs; 4779 sta->deflink.tx_stats.bytes[queue] += len; 4780 } 4781 4782 ieee80211_tpt_led_trig_tx(local, len); 4783 4784 ieee80211_tx_8023(sdata, skb, sta, false); 4785 4786 return; 4787 4788 out_free: 4789 kfree_skb(skb); 4790 } 4791 4792 static bool ieee80211_check_mcast_offload(struct ieee80211_sub_if_data *sdata, 4793 struct sk_buff *skb) 4794 { 4795 struct ethhdr *ehdr = (struct ethhdr *)skb->data; 4796 4797 if ((ieee80211_vif_is_mld(&sdata->vif) && 4798 (sdata->vif.type == NL80211_IFTYPE_AP && 4799 !ieee80211_hw_check(&sdata->local->hw, MLO_MCAST_MULTI_LINK_TX))) || 4800 (sdata->vif.type == NL80211_IFTYPE_AP_VLAN && 4801 !sdata->wdev.use_4addr)) 4802 return false; 4803 4804 if (!is_multicast_ether_addr(skb->data) || 4805 !(sdata->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_MCAST) || 4806 sdata->control_port_protocol == ehdr->h_proto) 4807 return false; 4808 4809 return true; 4810 } 4811 4812 static void __ieee80211_subif_start_xmit_8023(struct sk_buff *skb, 4813 struct net_device *dev) 4814 { 4815 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4816 struct ethhdr *ehdr = (struct ethhdr *)skb->data; 4817 struct ieee80211_link_data *link; 4818 struct ieee80211_key *key; 4819 struct sta_info *sta; 4820 4821 rcu_read_lock(); 4822 4823 if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) { 4824 kfree_skb(skb); 4825 goto out; 4826 } 4827 4828 /* 4829 * If STA is invalid, use the multicast offload path when applicable. 4830 * In AP mode, drop the frame if there are no associated stations; 4831 * otherwise use the default link and multicast key for transmission. 4832 */ 4833 if (unlikely(IS_ERR_OR_NULL(sta) && 4834 ieee80211_check_mcast_offload(sdata, skb))) { 4835 sta = NULL; 4836 if (ieee80211_vif_get_num_mcast_if(sdata) <= 0) { 4837 /* No associated STAs - no need to send multicast frames. */ 4838 kfree_skb(skb); 4839 goto out; 4840 } 4841 link = &sdata->deflink; 4842 key = rcu_dereference(link->default_multicast_key); 4843 } else if (unlikely(IS_ERR_OR_NULL(sta) || !sta->uploaded || 4844 !test_sta_flag(sta, WLAN_STA_AUTHORIZED) || 4845 sdata->control_port_protocol == ehdr->h_proto)) { 4846 goto skip_offload; 4847 } else { 4848 key = rcu_dereference(sta->ptk[sta->ptk_idx]); 4849 if (!key) 4850 key = rcu_dereference(sdata->default_unicast_key); 4851 } 4852 4853 if (key && (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) || 4854 key->conf.cipher == WLAN_CIPHER_SUITE_TKIP)) 4855 goto skip_offload; 4856 4857 sk_pacing_shift_update(skb->sk, sdata->local->hw.tx_sk_pacing_shift); 4858 ieee80211_8023_xmit(sdata, dev, sta, key, skb); 4859 goto out; 4860 4861 skip_offload: 4862 ieee80211_subif_start_xmit(skb, dev); 4863 out: 4864 rcu_read_unlock(); 4865 } 4866 4867 netdev_tx_t ieee80211_subif_start_xmit_8023(struct sk_buff *skb, 4868 struct net_device *dev) 4869 { 4870 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4871 struct ethhdr *ehdr = (struct ethhdr *)skb->data; 4872 4873 if (unlikely(!ieee80211_sdata_running(sdata) || skb->len < ETH_HLEN)) { 4874 kfree_skb(skb); 4875 return NETDEV_TX_OK; 4876 } 4877 4878 if (unlikely(is_multicast_ether_addr(ehdr->h_dest) && 4879 ieee80211_multicast_to_unicast(skb, dev))) { 4880 struct sk_buff_head queue; 4881 4882 __skb_queue_head_init(&queue); 4883 ieee80211_convert_to_unicast(skb, dev, &queue); 4884 while ((skb = __skb_dequeue(&queue))) 4885 __ieee80211_subif_start_xmit_8023(skb, dev); 4886 } else { 4887 __ieee80211_subif_start_xmit_8023(skb, dev); 4888 } 4889 4890 return NETDEV_TX_OK; 4891 } 4892 4893 struct sk_buff * 4894 ieee80211_build_data_template(struct ieee80211_sub_if_data *sdata, 4895 struct sk_buff *skb, u32 info_flags) 4896 { 4897 struct ieee80211_hdr *hdr; 4898 struct ieee80211_tx_data tx = { 4899 .local = sdata->local, 4900 .sdata = sdata, 4901 }; 4902 struct sta_info *sta; 4903 4904 rcu_read_lock(); 4905 4906 if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) { 4907 kfree_skb(skb); 4908 skb = ERR_PTR(-EINVAL); 4909 goto out; 4910 } 4911 4912 skb = ieee80211_build_hdr(sdata, skb, info_flags, sta, 4913 IEEE80211_TX_CTRL_MLO_LINK_UNSPEC, 0); 4914 if (IS_ERR(skb)) 4915 goto out; 4916 4917 hdr = (void *)skb->data; 4918 tx.sta = sta_info_get(sdata, hdr->addr1); 4919 tx.skb = skb; 4920 4921 if (ieee80211_tx_h_select_key(&tx) != TX_CONTINUE) { 4922 rcu_read_unlock(); 4923 kfree_skb(skb); 4924 return ERR_PTR(-EINVAL); 4925 } 4926 4927 out: 4928 rcu_read_unlock(); 4929 return skb; 4930 } 4931 4932 /* 4933 * ieee80211_clear_tx_pending may not be called in a context where 4934 * it is possible that it packets could come in again. 4935 */ 4936 void ieee80211_clear_tx_pending(struct ieee80211_local *local) 4937 { 4938 struct sk_buff *skb; 4939 int i; 4940 4941 for (i = 0; i < local->hw.queues; i++) { 4942 while ((skb = skb_dequeue(&local->pending[i])) != NULL) 4943 ieee80211_free_txskb(&local->hw, skb); 4944 } 4945 } 4946 4947 /* 4948 * Returns false if the frame couldn't be transmitted but was queued instead, 4949 * which in this case means re-queued -- take as an indication to stop sending 4950 * more pending frames. 4951 */ 4952 static bool ieee80211_tx_pending_skb(struct ieee80211_local *local, 4953 struct sk_buff *skb) 4954 { 4955 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 4956 struct ieee80211_sub_if_data *sdata; 4957 struct sta_info *sta; 4958 struct ieee80211_hdr *hdr; 4959 bool result; 4960 struct ieee80211_chanctx_conf *chanctx_conf; 4961 4962 sdata = vif_to_sdata(info->control.vif); 4963 4964 if (info->control.flags & IEEE80211_TX_INTCFL_NEED_TXPROCESSING) { 4965 /* update band only for non-MLD */ 4966 if (!ieee80211_vif_is_mld(&sdata->vif)) { 4967 chanctx_conf = 4968 rcu_dereference(sdata->vif.bss_conf.chanctx_conf); 4969 if (unlikely(!chanctx_conf)) { 4970 dev_kfree_skb(skb); 4971 return true; 4972 } 4973 info->band = chanctx_conf->def.chan->band; 4974 } 4975 result = ieee80211_tx(sdata, NULL, skb, true); 4976 } else if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) { 4977 if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) { 4978 dev_kfree_skb(skb); 4979 return true; 4980 } 4981 4982 if (IS_ERR(sta) || (sta && !sta->uploaded)) 4983 sta = NULL; 4984 4985 result = ieee80211_tx_8023(sdata, skb, sta, true); 4986 } else { 4987 struct sk_buff_head skbs; 4988 4989 __skb_queue_head_init(&skbs); 4990 __skb_queue_tail(&skbs, skb); 4991 4992 hdr = (struct ieee80211_hdr *)skb->data; 4993 sta = sta_info_get(sdata, hdr->addr1); 4994 4995 result = __ieee80211_tx(local, &skbs, sta, true); 4996 } 4997 4998 return result; 4999 } 5000 5001 /* 5002 * Transmit all pending packets. Called from tasklet. 5003 */ 5004 void ieee80211_tx_pending(struct tasklet_struct *t) 5005 { 5006 struct ieee80211_local *local = from_tasklet(local, t, 5007 tx_pending_tasklet); 5008 unsigned long flags; 5009 int i; 5010 bool txok; 5011 5012 rcu_read_lock(); 5013 5014 spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 5015 for (i = 0; i < local->hw.queues; i++) { 5016 /* 5017 * If queue is stopped by something other than due to pending 5018 * frames, or we have no pending frames, proceed to next queue. 5019 */ 5020 if (local->queue_stop_reasons[i] || 5021 skb_queue_empty(&local->pending[i])) 5022 continue; 5023 5024 while (!skb_queue_empty(&local->pending[i])) { 5025 struct sk_buff *skb = __skb_dequeue(&local->pending[i]); 5026 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 5027 5028 if (WARN_ON(!info->control.vif)) { 5029 ieee80211_free_txskb(&local->hw, skb); 5030 continue; 5031 } 5032 5033 spin_unlock_irqrestore(&local->queue_stop_reason_lock, 5034 flags); 5035 5036 txok = ieee80211_tx_pending_skb(local, skb); 5037 spin_lock_irqsave(&local->queue_stop_reason_lock, 5038 flags); 5039 if (!txok) 5040 break; 5041 } 5042 } 5043 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 5044 5045 rcu_read_unlock(); 5046 } 5047 5048 /* functions for drivers to get certain frames */ 5049 5050 static void ieee80211_beacon_add_tim_pvb(struct ps_data *ps, 5051 struct sk_buff *skb, 5052 bool mcast_traffic) 5053 { 5054 int i, n1 = 0, n2; 5055 5056 /* 5057 * Find largest even number N1 so that bits numbered 1 through 5058 * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits 5059 * (N2 + 1) x 8 through 2007 are 0. 5060 */ 5061 for (i = 0; i < IEEE80211_MAX_TIM_LEN; i++) { 5062 if (ps->tim[i]) { 5063 n1 = i & 0xfe; 5064 break; 5065 } 5066 } 5067 n2 = n1; 5068 for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) { 5069 if (ps->tim[i]) { 5070 n2 = i; 5071 break; 5072 } 5073 } 5074 5075 /* Bitmap control */ 5076 skb_put_u8(skb, n1 | mcast_traffic); 5077 /* Part Virt Bitmap */ 5078 skb_put_data(skb, ps->tim + n1, n2 - n1 + 1); 5079 } 5080 5081 /* 5082 * mac80211 currently supports encoding using block bitmap mode, non 5083 * inversed. The current implementation supports up to 1600 AIDs. 5084 * 5085 * Block bitmap encoding breaks down the AID bitmap into blocks of 64 5086 * AIDs. Each block contains between 0 and 8 subblocks. Each subblock 5087 * describes 8 AIDs and the presence of a subblock is determined by 5088 * the block bitmap. 5089 */ 5090 static void ieee80211_s1g_beacon_add_tim_pvb(struct ps_data *ps, 5091 struct sk_buff *skb, 5092 bool mcast_traffic) 5093 { 5094 int blk; 5095 5096 /* 5097 * Emit a bitmap control block with a page slice number of 31 and a 5098 * page index of 0 which indicates as per IEEE80211-2024 9.4.2.5.1 5099 * that the entire page (2048 bits) indicated by the page index 5100 * is encoded in the partial virtual bitmap. 5101 */ 5102 skb_put_u8(skb, mcast_traffic | (31 << 1)); 5103 5104 /* Emit an encoded block for each non-zero sub-block */ 5105 for (blk = 0; blk < IEEE80211_MAX_SUPPORTED_S1G_TIM_BLOCKS; blk++) { 5106 u8 blk_bmap = 0; 5107 int sblk; 5108 5109 for (sblk = 0; sblk < 8; sblk++) { 5110 int sblk_idx = blk * 8 + sblk; 5111 5112 /* 5113 * If the current subblock is non-zero, increase the 5114 * number of subblocks to emit for the current block. 5115 */ 5116 if (ps->tim[sblk_idx]) 5117 blk_bmap |= BIT(sblk); 5118 } 5119 5120 /* If the current block contains no non-zero sublocks */ 5121 if (!blk_bmap) 5122 continue; 5123 5124 /* 5125 * Emit a block control byte for the current encoded block 5126 * with an encoding mode of block bitmap (0x0), not inverse 5127 * (0x0) and the current block offset (5 bits) 5128 */ 5129 skb_put_u8(skb, blk << 3); 5130 5131 /* 5132 * Emit the block bitmap for the current encoded block which 5133 * contains the present subblocks. 5134 */ 5135 skb_put_u8(skb, blk_bmap); 5136 5137 /* Emit the present subblocks */ 5138 for (sblk = 0; sblk < 8; sblk++) { 5139 int sblk_idx = blk * 8 + sblk; 5140 5141 if (!(blk_bmap & BIT(sblk))) 5142 continue; 5143 5144 skb_put_u8(skb, ps->tim[sblk_idx]); 5145 } 5146 } 5147 } 5148 5149 static void __ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata, 5150 struct ieee80211_link_data *link, 5151 struct ps_data *ps, struct sk_buff *skb, 5152 bool is_template) 5153 { 5154 struct element *tim; 5155 bool mcast_traffic = false, have_bits = false; 5156 struct ieee80211_bss_conf *link_conf = link->conf; 5157 bool s1g = ieee80211_get_link_sband(link)->band == NL80211_BAND_S1GHZ; 5158 5159 /* Generate bitmap for TIM only if there are any STAs in power save 5160 * mode. */ 5161 if (atomic_read(&ps->num_sta_ps) > 0) 5162 /* in the hope that this is faster than 5163 * checking byte-for-byte */ 5164 have_bits = !bitmap_empty((unsigned long *)ps->tim, 5165 IEEE80211_MAX_AID + 1); 5166 5167 if (!is_template) { 5168 if (ps->dtim_count == 0) 5169 ps->dtim_count = link_conf->dtim_period - 1; 5170 else 5171 ps->dtim_count--; 5172 } 5173 5174 /* Length is set after parsing the AID bitmap */ 5175 tim = skb_put(skb, sizeof(struct element)); 5176 tim->id = WLAN_EID_TIM; 5177 skb_put_u8(skb, ps->dtim_count); 5178 skb_put_u8(skb, link_conf->dtim_period); 5179 5180 if (ps->dtim_count == 0 && !skb_queue_empty(&ps->bc_buf)) 5181 mcast_traffic = true; 5182 5183 ps->dtim_bc_mc = mcast_traffic; 5184 5185 if (have_bits) { 5186 if (s1g) 5187 ieee80211_s1g_beacon_add_tim_pvb(ps, skb, 5188 mcast_traffic); 5189 else 5190 ieee80211_beacon_add_tim_pvb(ps, skb, mcast_traffic); 5191 } else { 5192 /* 5193 * If there is no buffered unicast traffic for an S1G 5194 * interface, we can exclude the bitmap control. This is in 5195 * contrast to other phy types as they do include the bitmap 5196 * control and pvb even when there is no buffered traffic. 5197 */ 5198 if (!s1g) { 5199 /* Bitmap control */ 5200 skb_put_u8(skb, mcast_traffic); 5201 /* Part Virt Bitmap */ 5202 skb_put_u8(skb, 0); 5203 } 5204 } 5205 5206 tim->datalen = skb_tail_pointer(skb) - tim->data; 5207 } 5208 5209 static int ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata, 5210 struct ieee80211_link_data *link, 5211 struct ps_data *ps, struct sk_buff *skb, 5212 bool is_template) 5213 { 5214 struct ieee80211_local *local = sdata->local; 5215 5216 /* 5217 * Not very nice, but we want to allow the driver to call 5218 * ieee80211_beacon_get() as a response to the set_tim() 5219 * callback. That, however, is already invoked under the 5220 * sta_lock to guarantee consistent and race-free update 5221 * of the tim bitmap in mac80211 and the driver. 5222 */ 5223 if (local->tim_in_locked_section) { 5224 __ieee80211_beacon_add_tim(sdata, link, ps, skb, is_template); 5225 } else { 5226 spin_lock_bh(&local->tim_lock); 5227 __ieee80211_beacon_add_tim(sdata, link, ps, skb, is_template); 5228 spin_unlock_bh(&local->tim_lock); 5229 } 5230 5231 return 0; 5232 } 5233 5234 static void ieee80211_set_beacon_cntdwn(struct ieee80211_sub_if_data *sdata, 5235 struct beacon_data *beacon, 5236 struct ieee80211_link_data *link) 5237 { 5238 u8 *beacon_data, count, max_count = 1; 5239 struct probe_resp *resp; 5240 size_t beacon_data_len; 5241 u16 *bcn_offsets; 5242 int i; 5243 5244 switch (sdata->vif.type) { 5245 case NL80211_IFTYPE_AP: 5246 beacon_data = beacon->tail; 5247 beacon_data_len = beacon->tail_len; 5248 break; 5249 case NL80211_IFTYPE_ADHOC: 5250 beacon_data = beacon->head; 5251 beacon_data_len = beacon->head_len; 5252 break; 5253 case NL80211_IFTYPE_MESH_POINT: 5254 beacon_data = beacon->head; 5255 beacon_data_len = beacon->head_len; 5256 break; 5257 default: 5258 return; 5259 } 5260 5261 resp = rcu_dereference(link->u.ap.probe_resp); 5262 5263 bcn_offsets = beacon->cntdwn_counter_offsets; 5264 count = beacon->cntdwn_current_counter; 5265 if (link->conf->csa_active) 5266 max_count = IEEE80211_MAX_CNTDWN_COUNTERS_NUM; 5267 5268 for (i = 0; i < max_count; ++i) { 5269 if (bcn_offsets[i]) { 5270 if (WARN_ON_ONCE(bcn_offsets[i] >= beacon_data_len)) 5271 return; 5272 beacon_data[bcn_offsets[i]] = count; 5273 } 5274 5275 if (sdata->vif.type == NL80211_IFTYPE_AP && resp) { 5276 u16 *resp_offsets = resp->cntdwn_counter_offsets; 5277 5278 if (resp_offsets[i]) 5279 resp->data[resp_offsets[i]] = count; 5280 } 5281 } 5282 } 5283 5284 static u8 __ieee80211_beacon_update_cntdwn(struct ieee80211_link_data *link, 5285 struct beacon_data *beacon) 5286 { 5287 if (beacon->cntdwn_current_counter == 1) { 5288 /* 5289 * Channel switch handling is done by a worker thread while 5290 * beacons get pulled from hardware timers. It's therefore 5291 * possible that software threads are slow enough to not be 5292 * able to complete CSA handling in a single beacon interval, 5293 * in which case we get here. There isn't much to do about 5294 * it, other than letting the user know that the AP isn't 5295 * behaving correctly. 5296 */ 5297 link_err_once(link, 5298 "beacon TX faster than countdown (channel/color switch) completion\n"); 5299 return 0; 5300 } 5301 5302 beacon->cntdwn_current_counter--; 5303 5304 return beacon->cntdwn_current_counter; 5305 } 5306 5307 u8 ieee80211_beacon_update_cntdwn(struct ieee80211_vif *vif, unsigned int link_id) 5308 { 5309 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 5310 struct ieee80211_link_data *link; 5311 struct beacon_data *beacon = NULL; 5312 u8 count = 0; 5313 5314 if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS)) 5315 return 0; 5316 5317 rcu_read_lock(); 5318 5319 link = rcu_dereference(sdata->link[link_id]); 5320 if (!link) 5321 goto unlock; 5322 5323 if (sdata->vif.type == NL80211_IFTYPE_AP) 5324 beacon = rcu_dereference(link->u.ap.beacon); 5325 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) 5326 beacon = rcu_dereference(sdata->u.ibss.presp); 5327 else if (ieee80211_vif_is_mesh(&sdata->vif)) 5328 beacon = rcu_dereference(sdata->u.mesh.beacon); 5329 5330 if (!beacon) 5331 goto unlock; 5332 5333 count = __ieee80211_beacon_update_cntdwn(link, beacon); 5334 5335 unlock: 5336 rcu_read_unlock(); 5337 return count; 5338 } 5339 EXPORT_SYMBOL(ieee80211_beacon_update_cntdwn); 5340 5341 void ieee80211_beacon_set_cntdwn(struct ieee80211_vif *vif, u8 counter) 5342 { 5343 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 5344 struct beacon_data *beacon = NULL; 5345 5346 rcu_read_lock(); 5347 5348 if (sdata->vif.type == NL80211_IFTYPE_AP) 5349 beacon = rcu_dereference(sdata->deflink.u.ap.beacon); 5350 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) 5351 beacon = rcu_dereference(sdata->u.ibss.presp); 5352 else if (ieee80211_vif_is_mesh(&sdata->vif)) 5353 beacon = rcu_dereference(sdata->u.mesh.beacon); 5354 5355 if (!beacon) 5356 goto unlock; 5357 5358 if (counter < beacon->cntdwn_current_counter) 5359 beacon->cntdwn_current_counter = counter; 5360 5361 unlock: 5362 rcu_read_unlock(); 5363 } 5364 EXPORT_SYMBOL(ieee80211_beacon_set_cntdwn); 5365 5366 bool ieee80211_beacon_cntdwn_is_complete(struct ieee80211_vif *vif, 5367 unsigned int link_id) 5368 { 5369 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 5370 struct ieee80211_link_data *link; 5371 struct beacon_data *beacon = NULL; 5372 u8 *beacon_data; 5373 size_t beacon_data_len; 5374 int ret = false; 5375 5376 if (!ieee80211_sdata_running(sdata)) 5377 return false; 5378 5379 if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS)) 5380 return 0; 5381 5382 rcu_read_lock(); 5383 5384 link = rcu_dereference(sdata->link[link_id]); 5385 if (!link) 5386 goto out; 5387 5388 if (vif->type == NL80211_IFTYPE_AP) { 5389 beacon = rcu_dereference(link->u.ap.beacon); 5390 if (WARN_ON(!beacon || !beacon->tail)) 5391 goto out; 5392 beacon_data = beacon->tail; 5393 beacon_data_len = beacon->tail_len; 5394 } else if (vif->type == NL80211_IFTYPE_ADHOC) { 5395 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 5396 5397 beacon = rcu_dereference(ifibss->presp); 5398 if (!beacon) 5399 goto out; 5400 5401 beacon_data = beacon->head; 5402 beacon_data_len = beacon->head_len; 5403 } else if (vif->type == NL80211_IFTYPE_MESH_POINT) { 5404 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 5405 5406 beacon = rcu_dereference(ifmsh->beacon); 5407 if (!beacon) 5408 goto out; 5409 5410 beacon_data = beacon->head; 5411 beacon_data_len = beacon->head_len; 5412 } else { 5413 WARN_ON(1); 5414 goto out; 5415 } 5416 5417 if (!beacon->cntdwn_counter_offsets[0]) 5418 goto out; 5419 5420 if (WARN_ON_ONCE(beacon->cntdwn_counter_offsets[0] > beacon_data_len)) 5421 goto out; 5422 5423 if (beacon_data[beacon->cntdwn_counter_offsets[0]] == 1) 5424 ret = true; 5425 5426 out: 5427 rcu_read_unlock(); 5428 5429 return ret; 5430 } 5431 EXPORT_SYMBOL(ieee80211_beacon_cntdwn_is_complete); 5432 5433 static int ieee80211_beacon_protect(struct sk_buff *skb, 5434 struct ieee80211_local *local, 5435 struct ieee80211_sub_if_data *sdata, 5436 struct ieee80211_link_data *link) 5437 { 5438 ieee80211_tx_result res; 5439 struct ieee80211_tx_data tx; 5440 struct sk_buff *check_skb; 5441 5442 memset(&tx, 0, sizeof(tx)); 5443 tx.key = rcu_dereference(link->default_beacon_key); 5444 if (!tx.key) 5445 return 0; 5446 5447 if (unlikely(tx.key->flags & KEY_FLAG_TAINTED)) { 5448 tx.key = NULL; 5449 return -EINVAL; 5450 } 5451 5452 if (!(tx.key->conf.flags & IEEE80211_KEY_FLAG_SW_MGMT_TX) && 5453 tx.key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) 5454 IEEE80211_SKB_CB(skb)->control.hw_key = &tx.key->conf; 5455 5456 tx.local = local; 5457 tx.sdata = sdata; 5458 __skb_queue_head_init(&tx.skbs); 5459 __skb_queue_tail(&tx.skbs, skb); 5460 res = ieee80211_tx_h_encrypt(&tx); 5461 check_skb = __skb_dequeue(&tx.skbs); 5462 /* we may crash after this, but it'd be a bug in crypto */ 5463 WARN_ON(check_skb != skb); 5464 if (WARN_ON_ONCE(res != TX_CONTINUE)) 5465 return -EINVAL; 5466 5467 return 0; 5468 } 5469 5470 int ieee80211_encrypt_tx_skb(struct sk_buff *skb) 5471 { 5472 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 5473 struct ieee80211_sub_if_data *sdata = NULL; 5474 struct sk_buff *check_skb; 5475 struct ieee80211_tx_data tx; 5476 ieee80211_tx_result res; 5477 5478 if (!info->control.hw_key) 5479 return 0; 5480 5481 memset(&tx, 0, sizeof(tx)); 5482 tx.key = container_of(info->control.hw_key, struct ieee80211_key, conf); 5483 /* NULL it out now so we do full SW crypto */ 5484 info->control.hw_key = NULL; 5485 __skb_queue_head_init(&tx.skbs); 5486 __skb_queue_tail(&tx.skbs, skb); 5487 5488 if (skb->dev) 5489 sdata = IEEE80211_DEV_TO_SUB_IF(skb->dev); 5490 else if (info->control.vif) 5491 sdata = vif_to_sdata(info->control.vif); 5492 5493 if (WARN_ON(!sdata)) 5494 return -EINVAL; 5495 5496 tx.sdata = sdata; 5497 tx.local = sdata->local; 5498 res = ieee80211_tx_h_encrypt(&tx); 5499 check_skb = __skb_dequeue(&tx.skbs); 5500 /* we may crash after this, but it'd be a bug in crypto */ 5501 WARN_ON(check_skb != skb); 5502 if (WARN_ON_ONCE(res != TX_CONTINUE)) 5503 return -EINVAL; 5504 5505 return 0; 5506 } 5507 EXPORT_SYMBOL_GPL(ieee80211_encrypt_tx_skb); 5508 5509 static void 5510 ieee80211_beacon_get_finish(struct ieee80211_hw *hw, 5511 struct ieee80211_vif *vif, 5512 struct ieee80211_link_data *link, 5513 struct ieee80211_mutable_offsets *offs, 5514 struct beacon_data *beacon, 5515 struct sk_buff *skb, 5516 struct ieee80211_chanctx_conf *chanctx_conf, 5517 u16 csa_off_base) 5518 { 5519 struct ieee80211_local *local = hw_to_local(hw); 5520 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 5521 struct ieee80211_tx_info *info; 5522 enum nl80211_band band; 5523 struct ieee80211_tx_rate_control txrc; 5524 5525 /* CSA offsets */ 5526 if (offs && beacon) { 5527 u16 i; 5528 5529 for (i = 0; i < IEEE80211_MAX_CNTDWN_COUNTERS_NUM; i++) { 5530 u16 csa_off = beacon->cntdwn_counter_offsets[i]; 5531 5532 if (!csa_off) 5533 continue; 5534 5535 offs->cntdwn_counter_offs[i] = csa_off_base + csa_off; 5536 } 5537 } 5538 5539 band = chanctx_conf->def.chan->band; 5540 info = IEEE80211_SKB_CB(skb); 5541 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; 5542 info->flags |= IEEE80211_TX_CTL_NO_ACK; 5543 info->band = band; 5544 5545 memset(&txrc, 0, sizeof(txrc)); 5546 txrc.hw = hw; 5547 txrc.sband = local->hw.wiphy->bands[band]; 5548 txrc.bss_conf = link->conf; 5549 txrc.skb = skb; 5550 txrc.reported_rate.idx = -1; 5551 if (sdata->beacon_rate_set && sdata->beacon_rateidx_mask[band]) 5552 txrc.rate_idx_mask = sdata->beacon_rateidx_mask[band]; 5553 else 5554 txrc.rate_idx_mask = sdata->rc_rateidx_mask[band]; 5555 txrc.bss = true; 5556 rate_control_get_rate(sdata, NULL, &txrc); 5557 5558 info->control.vif = vif; 5559 info->control.flags |= u32_encode_bits(link->link_id, 5560 IEEE80211_TX_CTRL_MLO_LINK); 5561 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT | 5562 IEEE80211_TX_CTL_ASSIGN_SEQ | 5563 IEEE80211_TX_CTL_FIRST_FRAGMENT; 5564 } 5565 5566 static void 5567 ieee80211_beacon_add_mbssid(struct sk_buff *skb, struct beacon_data *beacon, 5568 u8 i) 5569 { 5570 if (!beacon->mbssid_ies || !beacon->mbssid_ies->cnt || 5571 i > beacon->mbssid_ies->cnt) 5572 return; 5573 5574 if (i < beacon->mbssid_ies->cnt) { 5575 skb_put_data(skb, beacon->mbssid_ies->elem[i].data, 5576 beacon->mbssid_ies->elem[i].len); 5577 5578 if (beacon->rnr_ies && beacon->rnr_ies->cnt) { 5579 skb_put_data(skb, beacon->rnr_ies->elem[i].data, 5580 beacon->rnr_ies->elem[i].len); 5581 5582 for (i = beacon->mbssid_ies->cnt; i < beacon->rnr_ies->cnt; i++) 5583 skb_put_data(skb, beacon->rnr_ies->elem[i].data, 5584 beacon->rnr_ies->elem[i].len); 5585 } 5586 return; 5587 } 5588 5589 /* i == beacon->mbssid_ies->cnt, include all MBSSID elements */ 5590 for (i = 0; i < beacon->mbssid_ies->cnt; i++) 5591 skb_put_data(skb, beacon->mbssid_ies->elem[i].data, 5592 beacon->mbssid_ies->elem[i].len); 5593 } 5594 5595 static struct sk_buff * 5596 __ieee80211_beacon_get_ap(struct ieee80211_hw *hw, 5597 struct ieee80211_vif *vif, 5598 struct ieee80211_link_data *link, 5599 struct ieee80211_mutable_offsets *offs, 5600 bool is_template, 5601 struct beacon_data *beacon, 5602 struct ieee80211_chanctx_conf *chanctx_conf, 5603 u8 ema_index) 5604 { 5605 struct ieee80211_local *local = hw_to_local(hw); 5606 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 5607 struct ieee80211_if_ap *ap = &sdata->u.ap; 5608 struct sk_buff *skb = NULL; 5609 u16 csa_off_base = 0; 5610 int mbssid_len; 5611 5612 if (beacon->cntdwn_counter_offsets[0]) { 5613 if (!is_template) 5614 ieee80211_beacon_update_cntdwn(vif, link->link_id); 5615 5616 ieee80211_set_beacon_cntdwn(sdata, beacon, link); 5617 } 5618 5619 /* headroom, head length, 5620 * tail length, maximum TIM length and multiple BSSID length 5621 */ 5622 mbssid_len = ieee80211_get_mbssid_beacon_len(beacon->mbssid_ies, 5623 beacon->rnr_ies, 5624 ema_index); 5625 5626 skb = dev_alloc_skb(local->tx_headroom + beacon->head_len + 5627 beacon->tail_len + 256 + 5628 local->hw.extra_beacon_tailroom + mbssid_len); 5629 if (!skb) 5630 return NULL; 5631 5632 skb_reserve(skb, local->tx_headroom); 5633 skb_put_data(skb, beacon->head, beacon->head_len); 5634 5635 ieee80211_beacon_add_tim(sdata, link, &ap->ps, skb, is_template); 5636 5637 if (offs) { 5638 offs->tim_offset = beacon->head_len; 5639 offs->tim_length = skb->len - beacon->head_len; 5640 offs->cntdwn_counter_offs[0] = beacon->cntdwn_counter_offsets[0]; 5641 5642 if (mbssid_len) { 5643 ieee80211_beacon_add_mbssid(skb, beacon, ema_index); 5644 offs->mbssid_off = skb->len - mbssid_len; 5645 } 5646 5647 /* for AP the csa offsets are from tail */ 5648 csa_off_base = skb->len; 5649 } 5650 5651 if (beacon->tail) 5652 skb_put_data(skb, beacon->tail, beacon->tail_len); 5653 5654 if (ieee80211_beacon_protect(skb, local, sdata, link) < 0) { 5655 dev_kfree_skb(skb); 5656 return NULL; 5657 } 5658 5659 ieee80211_beacon_get_finish(hw, vif, link, offs, beacon, skb, 5660 chanctx_conf, csa_off_base); 5661 return skb; 5662 } 5663 5664 static bool ieee80211_s1g_need_long_beacon(struct ieee80211_sub_if_data *sdata, 5665 struct ieee80211_link_data *link) 5666 { 5667 struct ps_data *ps = &sdata->u.ap.ps; 5668 5669 if (ps->sb_count == 0) 5670 ps->sb_count = link->conf->s1g_long_beacon_period - 1; 5671 else 5672 ps->sb_count--; 5673 5674 return ps->sb_count == 0; 5675 } 5676 5677 static struct sk_buff * 5678 ieee80211_s1g_short_beacon_get(struct ieee80211_hw *hw, 5679 struct ieee80211_vif *vif, 5680 struct ieee80211_link_data *link, 5681 struct ieee80211_chanctx_conf *chanctx_conf, 5682 struct s1g_short_beacon_data *sb, 5683 bool is_template) 5684 { 5685 struct ieee80211_local *local = hw_to_local(hw); 5686 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 5687 struct ieee80211_if_ap *ap = &sdata->u.ap; 5688 struct sk_buff *skb; 5689 5690 skb = dev_alloc_skb(local->tx_headroom + sb->short_head_len + 5691 sb->short_tail_len + 256 + 5692 local->hw.extra_beacon_tailroom); 5693 if (!skb) 5694 return NULL; 5695 5696 skb_reserve(skb, local->tx_headroom); 5697 skb_put_data(skb, sb->short_head, sb->short_head_len); 5698 5699 ieee80211_beacon_add_tim(sdata, link, &ap->ps, skb, is_template); 5700 5701 if (sb->short_tail) 5702 skb_put_data(skb, sb->short_tail, sb->short_tail_len); 5703 5704 ieee80211_beacon_get_finish(hw, vif, link, NULL, NULL, skb, 5705 chanctx_conf, 0); 5706 return skb; 5707 } 5708 5709 static struct sk_buff * 5710 ieee80211_beacon_get_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 5711 struct ieee80211_link_data *link, 5712 struct ieee80211_mutable_offsets *offs, 5713 bool is_template, struct beacon_data *beacon, 5714 struct ieee80211_chanctx_conf *chanctx_conf, 5715 u8 ema_index, struct s1g_short_beacon_data *s1g_sb) 5716 { 5717 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 5718 5719 if (!sdata->vif.cfg.s1g || !s1g_sb || 5720 ieee80211_s1g_need_long_beacon(sdata, link)) 5721 return __ieee80211_beacon_get_ap(hw, vif, link, offs, 5722 is_template, beacon, 5723 chanctx_conf, ema_index); 5724 5725 return ieee80211_s1g_short_beacon_get(hw, vif, link, chanctx_conf, 5726 s1g_sb, is_template); 5727 } 5728 5729 static struct ieee80211_ema_beacons * 5730 ieee80211_beacon_get_ap_ema_list(struct ieee80211_hw *hw, 5731 struct ieee80211_vif *vif, 5732 struct ieee80211_link_data *link, 5733 struct ieee80211_mutable_offsets *offs, 5734 bool is_template, struct beacon_data *beacon, 5735 struct ieee80211_chanctx_conf *chanctx_conf) 5736 { 5737 struct ieee80211_ema_beacons *ema = NULL; 5738 5739 if (!beacon->mbssid_ies || !beacon->mbssid_ies->cnt) 5740 return NULL; 5741 5742 ema = kzalloc_flex(*ema, bcn, beacon->mbssid_ies->cnt, GFP_ATOMIC); 5743 if (!ema) 5744 return NULL; 5745 5746 for (ema->cnt = 0; ema->cnt < beacon->mbssid_ies->cnt; ema->cnt++) { 5747 ema->bcn[ema->cnt].skb = 5748 ieee80211_beacon_get_ap(hw, vif, link, 5749 &ema->bcn[ema->cnt].offs, 5750 is_template, beacon, 5751 chanctx_conf, ema->cnt, NULL); 5752 if (!ema->bcn[ema->cnt].skb) 5753 break; 5754 } 5755 5756 if (ema->cnt == beacon->mbssid_ies->cnt) 5757 return ema; 5758 5759 ieee80211_beacon_free_ema_list(ema); 5760 return NULL; 5761 } 5762 5763 #define IEEE80211_INCLUDE_ALL_MBSSID_ELEMS -1 5764 5765 static struct sk_buff * 5766 __ieee80211_beacon_get(struct ieee80211_hw *hw, 5767 struct ieee80211_vif *vif, 5768 struct ieee80211_mutable_offsets *offs, 5769 bool is_template, 5770 unsigned int link_id, 5771 int ema_index, 5772 struct ieee80211_ema_beacons **ema_beacons) 5773 { 5774 struct ieee80211_local *local = hw_to_local(hw); 5775 struct beacon_data *beacon = NULL; 5776 struct sk_buff *skb = NULL; 5777 struct ieee80211_sub_if_data *sdata = NULL; 5778 struct ieee80211_chanctx_conf *chanctx_conf; 5779 struct ieee80211_link_data *link; 5780 struct s1g_short_beacon_data *s1g_short_bcn = NULL; 5781 5782 rcu_read_lock(); 5783 5784 sdata = vif_to_sdata(vif); 5785 link = rcu_dereference(sdata->link[link_id]); 5786 if (!link) 5787 goto out; 5788 chanctx_conf = 5789 rcu_dereference(link->conf->chanctx_conf); 5790 5791 if (!ieee80211_sdata_running(sdata) || !chanctx_conf) 5792 goto out; 5793 5794 if (offs) 5795 memset(offs, 0, sizeof(*offs)); 5796 5797 if (sdata->vif.type == NL80211_IFTYPE_AP) { 5798 beacon = rcu_dereference(link->u.ap.beacon); 5799 if (!beacon) 5800 goto out; 5801 5802 if (vif->cfg.s1g && link->u.ap.s1g_short_beacon) { 5803 s1g_short_bcn = 5804 rcu_dereference(link->u.ap.s1g_short_beacon); 5805 if (!s1g_short_bcn) 5806 goto out; 5807 } 5808 5809 if (ema_beacons) { 5810 *ema_beacons = 5811 ieee80211_beacon_get_ap_ema_list(hw, vif, link, 5812 offs, 5813 is_template, 5814 beacon, 5815 chanctx_conf); 5816 } else { 5817 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) { 5818 if (ema_index >= beacon->mbssid_ies->cnt) 5819 goto out; /* End of MBSSID elements */ 5820 5821 if (ema_index <= IEEE80211_INCLUDE_ALL_MBSSID_ELEMS) 5822 ema_index = beacon->mbssid_ies->cnt; 5823 } else { 5824 ema_index = 0; 5825 } 5826 5827 skb = ieee80211_beacon_get_ap(hw, vif, link, offs, 5828 is_template, beacon, 5829 chanctx_conf, ema_index, 5830 s1g_short_bcn); 5831 } 5832 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { 5833 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 5834 struct ieee80211_hdr *hdr; 5835 5836 beacon = rcu_dereference(ifibss->presp); 5837 if (!beacon) 5838 goto out; 5839 5840 if (beacon->cntdwn_counter_offsets[0]) { 5841 if (!is_template) 5842 __ieee80211_beacon_update_cntdwn(link, beacon); 5843 5844 ieee80211_set_beacon_cntdwn(sdata, beacon, link); 5845 } 5846 5847 skb = dev_alloc_skb(local->tx_headroom + beacon->head_len + 5848 local->hw.extra_beacon_tailroom); 5849 if (!skb) 5850 goto out; 5851 skb_reserve(skb, local->tx_headroom); 5852 skb_put_data(skb, beacon->head, beacon->head_len); 5853 5854 hdr = (struct ieee80211_hdr *) skb->data; 5855 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 5856 IEEE80211_STYPE_BEACON); 5857 5858 ieee80211_beacon_get_finish(hw, vif, link, offs, beacon, skb, 5859 chanctx_conf, 0); 5860 } else if (ieee80211_vif_is_mesh(&sdata->vif)) { 5861 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 5862 5863 beacon = rcu_dereference(ifmsh->beacon); 5864 if (!beacon) 5865 goto out; 5866 5867 if (beacon->cntdwn_counter_offsets[0]) { 5868 if (!is_template) 5869 /* TODO: For mesh csa_counter is in TU, so 5870 * decrementing it by one isn't correct, but 5871 * for now we leave it consistent with overall 5872 * mac80211's behavior. 5873 */ 5874 __ieee80211_beacon_update_cntdwn(link, beacon); 5875 5876 ieee80211_set_beacon_cntdwn(sdata, beacon, link); 5877 } 5878 5879 if (ifmsh->sync_ops) 5880 ifmsh->sync_ops->adjust_tsf(sdata, beacon); 5881 5882 skb = dev_alloc_skb(local->tx_headroom + 5883 beacon->head_len + 5884 256 + /* TIM IE */ 5885 beacon->tail_len + 5886 local->hw.extra_beacon_tailroom); 5887 if (!skb) 5888 goto out; 5889 skb_reserve(skb, local->tx_headroom); 5890 skb_put_data(skb, beacon->head, beacon->head_len); 5891 ieee80211_beacon_add_tim(sdata, link, &ifmsh->ps, skb, 5892 is_template); 5893 5894 if (offs) { 5895 offs->tim_offset = beacon->head_len; 5896 offs->tim_length = skb->len - beacon->head_len; 5897 } 5898 5899 skb_put_data(skb, beacon->tail, beacon->tail_len); 5900 ieee80211_beacon_get_finish(hw, vif, link, offs, beacon, skb, 5901 chanctx_conf, 0); 5902 } else { 5903 WARN_ON(1); 5904 goto out; 5905 } 5906 5907 out: 5908 rcu_read_unlock(); 5909 return skb; 5910 5911 } 5912 5913 struct sk_buff * 5914 ieee80211_beacon_get_template(struct ieee80211_hw *hw, 5915 struct ieee80211_vif *vif, 5916 struct ieee80211_mutable_offsets *offs, 5917 unsigned int link_id) 5918 { 5919 return __ieee80211_beacon_get(hw, vif, offs, true, link_id, 5920 IEEE80211_INCLUDE_ALL_MBSSID_ELEMS, NULL); 5921 } 5922 EXPORT_SYMBOL(ieee80211_beacon_get_template); 5923 5924 struct sk_buff * 5925 ieee80211_beacon_get_template_ema_index(struct ieee80211_hw *hw, 5926 struct ieee80211_vif *vif, 5927 struct ieee80211_mutable_offsets *offs, 5928 unsigned int link_id, u8 ema_index) 5929 { 5930 return __ieee80211_beacon_get(hw, vif, offs, true, link_id, ema_index, 5931 NULL); 5932 } 5933 EXPORT_SYMBOL(ieee80211_beacon_get_template_ema_index); 5934 5935 void ieee80211_beacon_free_ema_list(struct ieee80211_ema_beacons *ema_beacons) 5936 { 5937 u8 i; 5938 5939 if (!ema_beacons) 5940 return; 5941 5942 for (i = 0; i < ema_beacons->cnt; i++) 5943 kfree_skb(ema_beacons->bcn[i].skb); 5944 5945 kfree(ema_beacons); 5946 } 5947 EXPORT_SYMBOL(ieee80211_beacon_free_ema_list); 5948 5949 struct ieee80211_ema_beacons * 5950 ieee80211_beacon_get_template_ema_list(struct ieee80211_hw *hw, 5951 struct ieee80211_vif *vif, 5952 unsigned int link_id) 5953 { 5954 struct ieee80211_ema_beacons *ema_beacons = NULL; 5955 5956 WARN_ON(__ieee80211_beacon_get(hw, vif, NULL, true, link_id, 0, 5957 &ema_beacons)); 5958 5959 return ema_beacons; 5960 } 5961 EXPORT_SYMBOL(ieee80211_beacon_get_template_ema_list); 5962 5963 struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw, 5964 struct ieee80211_vif *vif, 5965 u16 *tim_offset, u16 *tim_length, 5966 unsigned int link_id) 5967 { 5968 struct ieee80211_mutable_offsets offs = {}; 5969 struct sk_buff *bcn = __ieee80211_beacon_get(hw, vif, &offs, false, 5970 link_id, 5971 IEEE80211_INCLUDE_ALL_MBSSID_ELEMS, 5972 NULL); 5973 struct sk_buff *copy; 5974 5975 if (!bcn) 5976 return bcn; 5977 5978 if (tim_offset) 5979 *tim_offset = offs.tim_offset; 5980 5981 if (tim_length) 5982 *tim_length = offs.tim_length; 5983 5984 if (ieee80211_hw_check(hw, BEACON_TX_STATUS) || 5985 !hw_to_local(hw)->monitors) 5986 return bcn; 5987 5988 /* send a copy to monitor interfaces */ 5989 copy = skb_copy(bcn, GFP_ATOMIC); 5990 if (!copy) 5991 return bcn; 5992 5993 ieee80211_tx_monitor(hw_to_local(hw), copy, 1, NULL); 5994 5995 return bcn; 5996 } 5997 EXPORT_SYMBOL(ieee80211_beacon_get_tim); 5998 5999 struct sk_buff *ieee80211_proberesp_get(struct ieee80211_hw *hw, 6000 struct ieee80211_vif *vif) 6001 { 6002 struct sk_buff *skb = NULL; 6003 struct probe_resp *presp = NULL; 6004 struct ieee80211_hdr *hdr; 6005 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 6006 6007 if (sdata->vif.type != NL80211_IFTYPE_AP) 6008 return NULL; 6009 6010 rcu_read_lock(); 6011 presp = rcu_dereference(sdata->deflink.u.ap.probe_resp); 6012 if (!presp) 6013 goto out; 6014 6015 skb = dev_alloc_skb(presp->len); 6016 if (!skb) 6017 goto out; 6018 6019 skb_put_data(skb, presp->data, presp->len); 6020 6021 hdr = (struct ieee80211_hdr *) skb->data; 6022 memset(hdr->addr1, 0, sizeof(hdr->addr1)); 6023 6024 out: 6025 rcu_read_unlock(); 6026 return skb; 6027 } 6028 EXPORT_SYMBOL(ieee80211_proberesp_get); 6029 6030 struct sk_buff *ieee80211_get_fils_discovery_tmpl(struct ieee80211_hw *hw, 6031 struct ieee80211_vif *vif, 6032 unsigned int link_id) 6033 { 6034 struct sk_buff *skb = NULL; 6035 struct fils_discovery_data *tmpl = NULL; 6036 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 6037 struct ieee80211_link_data *link; 6038 6039 if (sdata->vif.type != NL80211_IFTYPE_AP) 6040 return NULL; 6041 6042 if (link_id >= IEEE80211_MLD_MAX_NUM_LINKS) 6043 return NULL; 6044 6045 guard(rcu)(); 6046 link = rcu_dereference(sdata->link[link_id]); 6047 if (!link) 6048 return NULL; 6049 6050 tmpl = rcu_dereference(link->u.ap.fils_discovery); 6051 if (!tmpl) 6052 return NULL; 6053 6054 skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom + tmpl->len); 6055 if (skb) { 6056 skb_reserve(skb, sdata->local->hw.extra_tx_headroom); 6057 skb_put_data(skb, tmpl->data, tmpl->len); 6058 } 6059 6060 return skb; 6061 } 6062 EXPORT_SYMBOL(ieee80211_get_fils_discovery_tmpl); 6063 6064 struct sk_buff * 6065 ieee80211_get_unsol_bcast_probe_resp_tmpl(struct ieee80211_hw *hw, 6066 struct ieee80211_vif *vif, 6067 unsigned int link_id) 6068 { 6069 struct sk_buff *skb = NULL; 6070 struct unsol_bcast_probe_resp_data *tmpl = NULL; 6071 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 6072 struct ieee80211_link_data *link; 6073 6074 if (sdata->vif.type != NL80211_IFTYPE_AP) 6075 return NULL; 6076 6077 if (link_id >= IEEE80211_MLD_MAX_NUM_LINKS) 6078 return NULL; 6079 6080 guard(rcu)(); 6081 link = rcu_dereference(sdata->link[link_id]); 6082 if (!link) 6083 return NULL; 6084 6085 tmpl = rcu_dereference(link->u.ap.unsol_bcast_probe_resp); 6086 if (!tmpl) 6087 return NULL; 6088 6089 skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom + tmpl->len); 6090 if (skb) { 6091 skb_reserve(skb, sdata->local->hw.extra_tx_headroom); 6092 skb_put_data(skb, tmpl->data, tmpl->len); 6093 } 6094 6095 return skb; 6096 } 6097 EXPORT_SYMBOL(ieee80211_get_unsol_bcast_probe_resp_tmpl); 6098 6099 struct sk_buff *ieee80211_pspoll_get(struct ieee80211_hw *hw, 6100 struct ieee80211_vif *vif) 6101 { 6102 struct ieee80211_sub_if_data *sdata; 6103 struct ieee80211_pspoll *pspoll; 6104 struct ieee80211_local *local; 6105 struct sk_buff *skb; 6106 6107 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION)) 6108 return NULL; 6109 6110 sdata = vif_to_sdata(vif); 6111 local = sdata->local; 6112 6113 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll)); 6114 if (!skb) 6115 return NULL; 6116 6117 skb_reserve(skb, local->hw.extra_tx_headroom); 6118 6119 pspoll = skb_put_zero(skb, sizeof(*pspoll)); 6120 pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL | 6121 IEEE80211_STYPE_PSPOLL); 6122 pspoll->aid = cpu_to_le16(sdata->vif.cfg.aid); 6123 6124 /* aid in PS-Poll has its two MSBs each set to 1 */ 6125 pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14); 6126 6127 memcpy(pspoll->bssid, sdata->deflink.u.mgd.bssid, ETH_ALEN); 6128 memcpy(pspoll->ta, vif->addr, ETH_ALEN); 6129 6130 return skb; 6131 } 6132 EXPORT_SYMBOL(ieee80211_pspoll_get); 6133 6134 struct sk_buff *ieee80211_nullfunc_get(struct ieee80211_hw *hw, 6135 struct ieee80211_vif *vif, 6136 int link_id, bool qos_ok) 6137 { 6138 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 6139 struct ieee80211_local *local = sdata->local; 6140 struct ieee80211_link_data *link = NULL; 6141 struct ieee80211_hdr_3addr *nullfunc; 6142 struct sk_buff *skb; 6143 bool qos = false; 6144 6145 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION)) 6146 return NULL; 6147 6148 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 6149 sizeof(*nullfunc) + 2); 6150 if (!skb) 6151 return NULL; 6152 6153 rcu_read_lock(); 6154 if (qos_ok) { 6155 struct sta_info *sta; 6156 6157 sta = sta_info_get(sdata, vif->cfg.ap_addr); 6158 qos = sta && sta->sta.wme; 6159 } 6160 6161 if (link_id >= 0) { 6162 link = rcu_dereference(sdata->link[link_id]); 6163 if (WARN_ON_ONCE(!link)) { 6164 rcu_read_unlock(); 6165 kfree_skb(skb); 6166 return NULL; 6167 } 6168 } 6169 6170 skb_reserve(skb, local->hw.extra_tx_headroom); 6171 6172 nullfunc = skb_put_zero(skb, sizeof(*nullfunc)); 6173 nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | 6174 IEEE80211_STYPE_NULLFUNC | 6175 IEEE80211_FCTL_TODS); 6176 if (qos) { 6177 __le16 qoshdr = cpu_to_le16(7); 6178 6179 BUILD_BUG_ON((IEEE80211_STYPE_QOS_NULLFUNC | 6180 IEEE80211_STYPE_NULLFUNC) != 6181 IEEE80211_STYPE_QOS_NULLFUNC); 6182 nullfunc->frame_control |= 6183 cpu_to_le16(IEEE80211_STYPE_QOS_NULLFUNC); 6184 skb->priority = 7; 6185 skb_set_queue_mapping(skb, IEEE80211_AC_VO); 6186 skb_put_data(skb, &qoshdr, sizeof(qoshdr)); 6187 } 6188 6189 if (link) { 6190 memcpy(nullfunc->addr1, link->conf->bssid, ETH_ALEN); 6191 memcpy(nullfunc->addr2, link->conf->addr, ETH_ALEN); 6192 memcpy(nullfunc->addr3, link->conf->bssid, ETH_ALEN); 6193 } else { 6194 memcpy(nullfunc->addr1, vif->cfg.ap_addr, ETH_ALEN); 6195 memcpy(nullfunc->addr2, vif->addr, ETH_ALEN); 6196 memcpy(nullfunc->addr3, vif->cfg.ap_addr, ETH_ALEN); 6197 } 6198 rcu_read_unlock(); 6199 6200 return skb; 6201 } 6202 EXPORT_SYMBOL(ieee80211_nullfunc_get); 6203 6204 struct sk_buff *ieee80211_probereq_get(struct ieee80211_hw *hw, 6205 const u8 *src_addr, 6206 const u8 *ssid, size_t ssid_len, 6207 size_t tailroom) 6208 { 6209 struct ieee80211_local *local = hw_to_local(hw); 6210 struct ieee80211_hdr_3addr *hdr; 6211 struct sk_buff *skb; 6212 size_t ie_ssid_len; 6213 u8 *pos; 6214 6215 ie_ssid_len = 2 + ssid_len; 6216 6217 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*hdr) + 6218 ie_ssid_len + tailroom); 6219 if (!skb) 6220 return NULL; 6221 6222 skb_reserve(skb, local->hw.extra_tx_headroom); 6223 6224 hdr = skb_put_zero(skb, sizeof(*hdr)); 6225 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 6226 IEEE80211_STYPE_PROBE_REQ); 6227 eth_broadcast_addr(hdr->addr1); 6228 memcpy(hdr->addr2, src_addr, ETH_ALEN); 6229 eth_broadcast_addr(hdr->addr3); 6230 6231 pos = skb_put(skb, ie_ssid_len); 6232 *pos++ = WLAN_EID_SSID; 6233 *pos++ = ssid_len; 6234 if (ssid_len) 6235 memcpy(pos, ssid, ssid_len); 6236 pos += ssid_len; 6237 6238 return skb; 6239 } 6240 EXPORT_SYMBOL(ieee80211_probereq_get); 6241 6242 void ieee80211_rts_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 6243 const void *frame, size_t frame_len, 6244 const struct ieee80211_tx_info *frame_txctl, 6245 struct ieee80211_rts *rts) 6246 { 6247 const struct ieee80211_hdr *hdr = frame; 6248 6249 rts->frame_control = 6250 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS); 6251 rts->duration = ieee80211_rts_duration(hw, vif, frame_len, 6252 frame_txctl); 6253 memcpy(rts->ra, hdr->addr1, sizeof(rts->ra)); 6254 memcpy(rts->ta, hdr->addr2, sizeof(rts->ta)); 6255 } 6256 EXPORT_SYMBOL(ieee80211_rts_get); 6257 6258 void ieee80211_ctstoself_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 6259 const void *frame, size_t frame_len, 6260 const struct ieee80211_tx_info *frame_txctl, 6261 struct ieee80211_cts *cts) 6262 { 6263 const struct ieee80211_hdr *hdr = frame; 6264 6265 cts->frame_control = 6266 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS); 6267 cts->duration = ieee80211_ctstoself_duration(hw, vif, 6268 frame_len, frame_txctl); 6269 memcpy(cts->ra, hdr->addr1, sizeof(cts->ra)); 6270 } 6271 EXPORT_SYMBOL(ieee80211_ctstoself_get); 6272 6273 struct sk_buff * 6274 ieee80211_get_buffered_bc(struct ieee80211_hw *hw, 6275 struct ieee80211_vif *vif) 6276 { 6277 struct ieee80211_local *local = hw_to_local(hw); 6278 struct sk_buff *skb = NULL; 6279 struct ieee80211_tx_data tx; 6280 struct ieee80211_sub_if_data *sdata; 6281 struct ps_data *ps; 6282 struct ieee80211_tx_info *info; 6283 struct ieee80211_chanctx_conf *chanctx_conf; 6284 6285 sdata = vif_to_sdata(vif); 6286 6287 rcu_read_lock(); 6288 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf); 6289 6290 if (!chanctx_conf) 6291 goto out; 6292 6293 if (sdata->vif.type == NL80211_IFTYPE_AP) { 6294 struct beacon_data *beacon = 6295 rcu_dereference(sdata->deflink.u.ap.beacon); 6296 6297 if (!beacon || !beacon->head) 6298 goto out; 6299 6300 ps = &sdata->u.ap.ps; 6301 } else if (ieee80211_vif_is_mesh(&sdata->vif)) { 6302 ps = &sdata->u.mesh.ps; 6303 } else { 6304 goto out; 6305 } 6306 6307 if (ps->dtim_count != 0 || !ps->dtim_bc_mc) 6308 goto out; /* send buffered bc/mc only after DTIM beacon */ 6309 6310 while (1) { 6311 skb = skb_dequeue(&ps->bc_buf); 6312 if (!skb) 6313 goto out; 6314 local->total_ps_buffered--; 6315 6316 if (!skb_queue_empty(&ps->bc_buf) && skb->len >= 2) { 6317 struct ieee80211_hdr *hdr = 6318 (struct ieee80211_hdr *) skb->data; 6319 /* more buffered multicast/broadcast frames ==> set 6320 * MoreData flag in IEEE 802.11 header to inform PS 6321 * STAs */ 6322 hdr->frame_control |= 6323 cpu_to_le16(IEEE80211_FCTL_MOREDATA); 6324 } 6325 6326 if (sdata->vif.type == NL80211_IFTYPE_AP) 6327 sdata = IEEE80211_DEV_TO_SUB_IF(skb->dev); 6328 if (!ieee80211_tx_prepare(sdata, &tx, NULL, skb)) 6329 break; 6330 ieee80211_free_txskb(hw, skb); 6331 } 6332 6333 info = IEEE80211_SKB_CB(skb); 6334 6335 tx.flags |= IEEE80211_TX_PS_BUFFERED; 6336 info->band = chanctx_conf->def.chan->band; 6337 6338 if (invoke_tx_handlers(&tx)) 6339 skb = NULL; 6340 out: 6341 rcu_read_unlock(); 6342 6343 return skb; 6344 } 6345 EXPORT_SYMBOL(ieee80211_get_buffered_bc); 6346 6347 int ieee80211_reserve_tid(struct ieee80211_sta *pubsta, u8 tid) 6348 { 6349 struct sta_info *sta = container_of(pubsta, struct sta_info, sta); 6350 struct ieee80211_sub_if_data *sdata = sta->sdata; 6351 struct ieee80211_local *local = sdata->local; 6352 int ret; 6353 u32 queues; 6354 6355 lockdep_assert_wiphy(local->hw.wiphy); 6356 6357 /* only some cases are supported right now */ 6358 switch (sdata->vif.type) { 6359 case NL80211_IFTYPE_STATION: 6360 case NL80211_IFTYPE_AP: 6361 case NL80211_IFTYPE_AP_VLAN: 6362 break; 6363 default: 6364 WARN_ON(1); 6365 return -EINVAL; 6366 } 6367 6368 if (WARN_ON(tid >= IEEE80211_NUM_UPS)) 6369 return -EINVAL; 6370 6371 if (sta->reserved_tid == tid) { 6372 ret = 0; 6373 goto out; 6374 } 6375 6376 if (sta->reserved_tid != IEEE80211_TID_UNRESERVED) { 6377 sdata_err(sdata, "TID reservation already active\n"); 6378 ret = -EALREADY; 6379 goto out; 6380 } 6381 6382 ieee80211_stop_vif_queues(sdata->local, sdata, 6383 IEEE80211_QUEUE_STOP_REASON_RESERVE_TID); 6384 6385 synchronize_net(); 6386 6387 /* Tear down BA sessions so we stop aggregating on this TID */ 6388 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION)) { 6389 set_sta_flag(sta, WLAN_STA_BLOCK_BA); 6390 __ieee80211_stop_tx_ba_session(sta, tid, 6391 AGG_STOP_LOCAL_REQUEST); 6392 } 6393 6394 queues = BIT(sdata->vif.hw_queue[ieee802_1d_to_ac[tid]]); 6395 __ieee80211_flush_queues(local, sdata, queues, false); 6396 6397 sta->reserved_tid = tid; 6398 6399 ieee80211_wake_vif_queues(local, sdata, 6400 IEEE80211_QUEUE_STOP_REASON_RESERVE_TID); 6401 6402 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION)) 6403 clear_sta_flag(sta, WLAN_STA_BLOCK_BA); 6404 6405 ret = 0; 6406 out: 6407 return ret; 6408 } 6409 EXPORT_SYMBOL(ieee80211_reserve_tid); 6410 6411 void ieee80211_unreserve_tid(struct ieee80211_sta *pubsta, u8 tid) 6412 { 6413 struct sta_info *sta = container_of(pubsta, struct sta_info, sta); 6414 struct ieee80211_sub_if_data *sdata = sta->sdata; 6415 6416 lockdep_assert_wiphy(sdata->local->hw.wiphy); 6417 6418 /* only some cases are supported right now */ 6419 switch (sdata->vif.type) { 6420 case NL80211_IFTYPE_STATION: 6421 case NL80211_IFTYPE_AP: 6422 case NL80211_IFTYPE_AP_VLAN: 6423 break; 6424 default: 6425 WARN_ON(1); 6426 return; 6427 } 6428 6429 if (tid != sta->reserved_tid) { 6430 sdata_err(sdata, "TID to unreserve (%d) isn't reserved\n", tid); 6431 return; 6432 } 6433 6434 sta->reserved_tid = IEEE80211_TID_UNRESERVED; 6435 } 6436 EXPORT_SYMBOL(ieee80211_unreserve_tid); 6437 6438 void __ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata, 6439 struct sk_buff *skb, int tid, int link_id, 6440 enum nl80211_band band) 6441 { 6442 const struct ieee80211_hdr *hdr = (void *)skb->data; 6443 int ac = ieee80211_ac_from_tid(tid); 6444 unsigned int link; 6445 6446 skb_reset_mac_header(skb); 6447 skb_set_queue_mapping(skb, ac); 6448 skb->priority = tid; 6449 6450 skb->dev = sdata->dev; 6451 6452 BUILD_BUG_ON(IEEE80211_LINK_UNSPECIFIED < IEEE80211_MLD_MAX_NUM_LINKS); 6453 BUILD_BUG_ON(!FIELD_FIT(IEEE80211_TX_CTRL_MLO_LINK, 6454 IEEE80211_LINK_UNSPECIFIED)); 6455 6456 if (!ieee80211_vif_is_mld(&sdata->vif)) { 6457 link = 0; 6458 } else if (link_id >= 0) { 6459 link = link_id; 6460 } else if (memcmp(sdata->vif.addr, hdr->addr2, ETH_ALEN) == 0) { 6461 /* address from the MLD */ 6462 link = IEEE80211_LINK_UNSPECIFIED; 6463 } else { 6464 /* otherwise must be addressed from a link */ 6465 rcu_read_lock(); 6466 for (link = 0; link < ARRAY_SIZE(sdata->vif.link_conf); link++) { 6467 struct ieee80211_bss_conf *link_conf; 6468 6469 link_conf = rcu_dereference(sdata->vif.link_conf[link]); 6470 if (!link_conf) 6471 continue; 6472 if (memcmp(link_conf->addr, hdr->addr2, ETH_ALEN) == 0) 6473 break; 6474 } 6475 rcu_read_unlock(); 6476 6477 if (WARN_ON_ONCE(link == ARRAY_SIZE(sdata->vif.link_conf))) 6478 link = ffs(sdata->vif.active_links) - 1; 6479 } 6480 6481 IEEE80211_SKB_CB(skb)->control.flags |= 6482 u32_encode_bits(link, IEEE80211_TX_CTRL_MLO_LINK); 6483 6484 /* 6485 * The other path calling ieee80211_xmit is from the tasklet, 6486 * and while we can handle concurrent transmissions locking 6487 * requirements are that we do not come into tx with bhs on. 6488 */ 6489 local_bh_disable(); 6490 IEEE80211_SKB_CB(skb)->band = band; 6491 ieee80211_xmit(sdata, NULL, skb); 6492 local_bh_enable(); 6493 } 6494 6495 void ieee80211_tx_skb_tid(struct ieee80211_sub_if_data *sdata, 6496 struct sk_buff *skb, int tid, int link_id) 6497 { 6498 struct ieee80211_chanctx_conf *chanctx_conf; 6499 enum nl80211_band band; 6500 6501 rcu_read_lock(); 6502 if (sdata->vif.type == NL80211_IFTYPE_NAN || 6503 sdata->vif.type == NL80211_IFTYPE_NAN_DATA) { 6504 band = NUM_NL80211_BANDS; 6505 } else if (!ieee80211_vif_is_mld(&sdata->vif)) { 6506 WARN_ON(link_id >= 0); 6507 chanctx_conf = 6508 rcu_dereference(sdata->vif.bss_conf.chanctx_conf); 6509 if (WARN_ON(!chanctx_conf)) { 6510 rcu_read_unlock(); 6511 kfree_skb(skb); 6512 return; 6513 } 6514 band = chanctx_conf->def.chan->band; 6515 } else { 6516 WARN_ON(link_id >= 0 && 6517 !(sdata->vif.active_links & BIT(link_id))); 6518 /* MLD transmissions must not rely on the band */ 6519 band = 0; 6520 } 6521 6522 __ieee80211_tx_skb_tid_band(sdata, skb, tid, link_id, band); 6523 rcu_read_unlock(); 6524 } 6525 6526 int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev, 6527 const u8 *buf, size_t len, 6528 const u8 *dest, __be16 proto, bool unencrypted, 6529 int link_id, u64 cookie) 6530 { 6531 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 6532 struct ieee80211_local *local = sdata->local; 6533 struct sta_info *sta; 6534 struct sk_buff *skb; 6535 struct ethhdr *ehdr; 6536 u32 ctrl_flags = 0; 6537 u32 flags = 0; 6538 int err; 6539 6540 /* mutex lock is only needed for incrementing the cookie counter */ 6541 lockdep_assert_wiphy(local->hw.wiphy); 6542 6543 /* Only accept CONTROL_PORT_PROTOCOL configured in CONNECT/ASSOCIATE 6544 * or Pre-Authentication 6545 */ 6546 if (proto != sdata->control_port_protocol && 6547 proto != cpu_to_be16(ETH_P_PREAUTH)) 6548 return -EINVAL; 6549 6550 if (proto == sdata->control_port_protocol) 6551 ctrl_flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO | 6552 IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP; 6553 6554 if (unencrypted) 6555 flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; 6556 6557 if (cookie) 6558 ctrl_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; 6559 6560 flags |= IEEE80211_TX_INTFL_NL80211_FRAME_TX; 6561 6562 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 6563 sizeof(struct ethhdr) + len); 6564 if (!skb) 6565 return -ENOMEM; 6566 6567 skb_reserve(skb, local->hw.extra_tx_headroom + sizeof(struct ethhdr)); 6568 6569 skb_put_data(skb, buf, len); 6570 6571 ehdr = skb_push(skb, sizeof(struct ethhdr)); 6572 memcpy(ehdr->h_dest, dest, ETH_ALEN); 6573 6574 /* we may override the SA for MLO STA later */ 6575 if (link_id < 0) { 6576 ctrl_flags |= u32_encode_bits(IEEE80211_LINK_UNSPECIFIED, 6577 IEEE80211_TX_CTRL_MLO_LINK); 6578 memcpy(ehdr->h_source, sdata->vif.addr, ETH_ALEN); 6579 } else { 6580 struct ieee80211_bss_conf *link_conf; 6581 6582 ctrl_flags |= u32_encode_bits(link_id, 6583 IEEE80211_TX_CTRL_MLO_LINK); 6584 6585 rcu_read_lock(); 6586 link_conf = rcu_dereference(sdata->vif.link_conf[link_id]); 6587 if (!link_conf) { 6588 dev_kfree_skb(skb); 6589 rcu_read_unlock(); 6590 return -ENOLINK; 6591 } 6592 memcpy(ehdr->h_source, link_conf->addr, ETH_ALEN); 6593 rcu_read_unlock(); 6594 } 6595 6596 ehdr->h_proto = proto; 6597 6598 skb->dev = dev; 6599 skb->protocol = proto; 6600 skb_reset_network_header(skb); 6601 skb_reset_mac_header(skb); 6602 6603 if (local->hw.queues < IEEE80211_NUM_ACS) 6604 goto start_xmit; 6605 6606 /* update QoS header to prioritize control port frames if possible, 6607 * prioritization also happens for control port frames send over 6608 * AF_PACKET 6609 */ 6610 rcu_read_lock(); 6611 err = ieee80211_lookup_ra_sta(sdata, skb, &sta); 6612 if (err) { 6613 dev_kfree_skb(skb); 6614 rcu_read_unlock(); 6615 return err; 6616 } 6617 6618 if (!IS_ERR(sta)) { 6619 u16 queue = ieee80211_select_queue(sdata, sta, skb); 6620 6621 skb_set_queue_mapping(skb, queue); 6622 6623 /* 6624 * for MLO STA, the SA should be the AP MLD address, but 6625 * the link ID has been selected already 6626 */ 6627 if (sta && sta->sta.mlo) 6628 memcpy(ehdr->h_source, sdata->vif.addr, ETH_ALEN); 6629 } 6630 rcu_read_unlock(); 6631 6632 start_xmit: 6633 local_bh_disable(); 6634 __ieee80211_subif_start_xmit(skb, skb->dev, flags, ctrl_flags, cookie); 6635 local_bh_enable(); 6636 6637 return 0; 6638 } 6639 6640 int ieee80211_probe_mesh_link(struct wiphy *wiphy, struct net_device *dev, 6641 const u8 *buf, size_t len) 6642 { 6643 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 6644 struct ieee80211_local *local = sdata->local; 6645 struct sk_buff *skb; 6646 6647 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len + 6648 30 + /* header size */ 6649 18); /* 11s header size */ 6650 if (!skb) 6651 return -ENOMEM; 6652 6653 skb_reserve(skb, local->hw.extra_tx_headroom); 6654 skb_put_data(skb, buf, len); 6655 6656 skb->dev = dev; 6657 skb->protocol = htons(ETH_P_802_3); 6658 skb_reset_network_header(skb); 6659 skb_reset_mac_header(skb); 6660 6661 local_bh_disable(); 6662 __ieee80211_subif_start_xmit(skb, skb->dev, 0, 6663 IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP, 6664 0); 6665 local_bh_enable(); 6666 6667 return 0; 6668 } 6669