1 // SPDX-License-Identifier: GPL-2.0-only
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-2024 Intel Corporation
10 * Transmit and frame generation functions.
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 <asm/unaligned.h>
28 #include <net/fq_impl.h>
31 #include "ieee80211_i.h"
32 #include "driver-ops.h"
42 static __le16 ieee80211_duration(struct ieee80211_tx_data *tx,
43 struct sk_buff *skb, int group_addr,
46 int rate, mrate, erp, dur, i;
47 struct ieee80211_rate *txrate;
48 struct ieee80211_local *local = tx->local;
49 struct ieee80211_supported_band *sband;
50 struct ieee80211_hdr *hdr;
51 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
52 struct ieee80211_chanctx_conf *chanctx_conf;
55 /* assume HW handles this */
56 if (tx->rate.flags & (IEEE80211_TX_RC_MCS | IEEE80211_TX_RC_VHT_MCS))
60 chanctx_conf = rcu_dereference(tx->sdata->vif.bss_conf.chanctx_conf);
62 rate_flags = ieee80211_chandef_rate_flags(&chanctx_conf->def);
66 if (WARN_ON_ONCE(tx->rate.idx < 0))
69 sband = local->hw.wiphy->bands[info->band];
70 txrate = &sband->bitrates[tx->rate.idx];
72 erp = txrate->flags & IEEE80211_RATE_ERP_G;
74 /* device is expected to do this */
75 if (sband->band == NL80211_BAND_S1GHZ)
79 * data and mgmt (except PS Poll):
81 * - during contention period:
82 * if addr1 is group address: 0
83 * if more fragments = 0 and addr1 is individual address: time to
84 * transmit one ACK plus SIFS
85 * if more fragments = 1 and addr1 is individual address: time to
86 * transmit next fragment plus 2 x ACK plus 3 x SIFS
89 * - control response frame (CTS or ACK) shall be transmitted using the
90 * same rate as the immediately previous frame in the frame exchange
91 * sequence, if this rate belongs to the PHY mandatory rates, or else
92 * at the highest possible rate belonging to the PHY rates in the
95 hdr = (struct ieee80211_hdr *)skb->data;
96 if (ieee80211_is_ctl(hdr->frame_control)) {
97 /* TODO: These control frames are not currently sent by
98 * mac80211, but should they be implemented, this function
99 * needs to be updated to support duration field calculation.
101 * RTS: time needed to transmit pending data/mgmt frame plus
102 * one CTS frame plus one ACK frame plus 3 x SIFS
103 * CTS: duration of immediately previous RTS minus time
104 * required to transmit CTS and its SIFS
105 * ACK: 0 if immediately previous directed data/mgmt had
106 * more=0, with more=1 duration in ACK frame is duration
107 * from previous frame minus time needed to transmit ACK
109 * PS Poll: BIT(15) | BIT(14) | aid
115 if (0 /* FIX: data/mgmt during CFP */)
116 return cpu_to_le16(32768);
118 if (group_addr) /* Group address as the destination - no ACK */
121 /* Individual destination address:
122 * IEEE 802.11, Ch. 9.6 (after IEEE 802.11g changes)
123 * CTS and ACK frames shall be transmitted using the highest rate in
124 * basic rate set that is less than or equal to the rate of the
125 * immediately previous frame and that is using the same modulation
126 * (CCK or OFDM). If no basic rate set matches with these requirements,
127 * the highest mandatory rate of the PHY that is less than or equal to
128 * the rate of the previous frame is used.
129 * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps
132 /* use lowest available if everything fails */
133 mrate = sband->bitrates[0].bitrate;
134 for (i = 0; i < sband->n_bitrates; i++) {
135 struct ieee80211_rate *r = &sband->bitrates[i];
138 if (r->bitrate > txrate->bitrate)
141 if ((rate_flags & r->flags) != rate_flags)
144 if (tx->sdata->vif.bss_conf.basic_rates & BIT(i))
147 switch (sband->band) {
148 case NL80211_BAND_2GHZ:
149 case NL80211_BAND_LC:
150 if (tx->sdata->deflink.operating_11g_mode)
151 flag = IEEE80211_RATE_MANDATORY_G;
153 flag = IEEE80211_RATE_MANDATORY_B;
155 case NL80211_BAND_5GHZ:
156 case NL80211_BAND_6GHZ:
157 flag = IEEE80211_RATE_MANDATORY_A;
169 /* No matching basic rate found; use highest suitable mandatory
174 /* Don't calculate ACKs for QoS Frames with NoAck Policy set */
175 if (ieee80211_is_data_qos(hdr->frame_control) &&
176 *(ieee80211_get_qos_ctl(hdr)) & IEEE80211_QOS_CTL_ACK_POLICY_NOACK)
179 /* Time needed to transmit ACK
180 * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up
181 * to closest integer */
182 dur = ieee80211_frame_duration(sband->band, 10, rate, erp,
183 tx->sdata->vif.bss_conf.use_short_preamble);
186 /* Frame is fragmented: duration increases with time needed to
187 * transmit next fragment plus ACK and 2 x SIFS. */
188 dur *= 2; /* ACK + SIFS */
190 dur += ieee80211_frame_duration(sband->band, next_frag_len,
191 txrate->bitrate, erp,
192 tx->sdata->vif.bss_conf.use_short_preamble);
195 return cpu_to_le16(dur);
199 static ieee80211_tx_result debug_noinline
200 ieee80211_tx_h_dynamic_ps(struct ieee80211_tx_data *tx)
202 struct ieee80211_local *local = tx->local;
203 struct ieee80211_if_managed *ifmgd;
204 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
206 /* driver doesn't support power save */
207 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
210 /* hardware does dynamic power save */
211 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
214 /* dynamic power save disabled */
215 if (local->hw.conf.dynamic_ps_timeout <= 0)
218 /* we are scanning, don't enable power save */
222 if (!local->ps_sdata)
225 /* No point if we're going to suspend */
226 if (local->quiescing)
229 /* dynamic ps is supported only in managed mode */
230 if (tx->sdata->vif.type != NL80211_IFTYPE_STATION)
233 if (unlikely(info->flags & IEEE80211_TX_INTFL_OFFCHAN_TX_OK))
236 ifmgd = &tx->sdata->u.mgd;
239 * Don't wakeup from power save if u-apsd is enabled, voip ac has
240 * u-apsd enabled and the frame is in voip class. This effectively
241 * means that even if all access categories have u-apsd enabled, in
242 * practise u-apsd is only used with the voip ac. This is a
243 * workaround for the case when received voip class packets do not
244 * have correct qos tag for some reason, due the network or the
247 * Note: ifmgd->uapsd_queues access is racy here. If the value is
248 * changed via debugfs, user needs to reassociate manually to have
249 * everything in sync.
251 if ((ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED) &&
252 (ifmgd->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) &&
253 skb_get_queue_mapping(tx->skb) == IEEE80211_AC_VO)
256 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
257 ieee80211_stop_queues_by_reason(&local->hw,
258 IEEE80211_MAX_QUEUE_MAP,
259 IEEE80211_QUEUE_STOP_REASON_PS,
261 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
262 wiphy_work_queue(local->hw.wiphy,
263 &local->dynamic_ps_disable_work);
266 /* Don't restart the timer if we're not disassociated */
267 if (!ifmgd->associated)
270 mod_timer(&local->dynamic_ps_timer, jiffies +
271 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
276 static ieee80211_tx_result debug_noinline
277 ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
280 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
281 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
284 if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED))
287 if (unlikely(test_bit(SCAN_SW_SCANNING, &tx->local->scanning)) &&
288 test_bit(SDATA_STATE_OFFCHANNEL, &tx->sdata->state) &&
289 !ieee80211_is_probe_req(hdr->frame_control) &&
290 !ieee80211_is_any_nullfunc(hdr->frame_control))
292 * When software scanning only nullfunc frames (to notify
293 * the sleep state to the AP) and probe requests (for the
294 * active scan) are allowed, all other frames should not be
295 * sent and we should not get here, but if we do
296 * nonetheless, drop them to avoid sending them
297 * off-channel. See the link below and
298 * ieee80211_start_scan() for more.
300 * http://article.gmane.org/gmane.linux.kernel.wireless.general/30089
304 if (tx->sdata->vif.type == NL80211_IFTYPE_OCB)
307 if (tx->flags & IEEE80211_TX_PS_BUFFERED)
311 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
313 if (likely(tx->flags & IEEE80211_TX_UNICAST)) {
314 if (unlikely(!assoc &&
315 ieee80211_is_data(hdr->frame_control))) {
316 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
317 sdata_info(tx->sdata,
318 "dropped data frame to not associated station %pM\n",
321 I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
324 } else if (unlikely(ieee80211_is_data(hdr->frame_control) &&
325 ieee80211_vif_get_num_mcast_if(tx->sdata) == 0)) {
327 * No associated STAs - no need to send multicast
336 /* This function is called whenever the AP is about to exceed the maximum limit
337 * of buffered frames for power saving STAs. This situation should not really
338 * happen often during normal operation, so dropping the oldest buffered packet
339 * from each queue should be OK to make some room for new frames. */
340 static void purge_old_ps_buffers(struct ieee80211_local *local)
342 int total = 0, purged = 0;
344 struct ieee80211_sub_if_data *sdata;
345 struct sta_info *sta;
347 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
350 if (sdata->vif.type == NL80211_IFTYPE_AP)
351 ps = &sdata->u.ap.ps;
352 else if (ieee80211_vif_is_mesh(&sdata->vif))
353 ps = &sdata->u.mesh.ps;
357 skb = skb_dequeue(&ps->bc_buf);
360 ieee80211_free_txskb(&local->hw, skb);
362 total += skb_queue_len(&ps->bc_buf);
366 * Drop one frame from each station from the lowest-priority
367 * AC that has frames at all.
369 list_for_each_entry_rcu(sta, &local->sta_list, list) {
372 for (ac = IEEE80211_AC_BK; ac >= IEEE80211_AC_VO; ac--) {
373 skb = skb_dequeue(&sta->ps_tx_buf[ac]);
374 total += skb_queue_len(&sta->ps_tx_buf[ac]);
377 ieee80211_free_txskb(&local->hw, skb);
383 local->total_ps_buffered = total;
384 ps_dbg_hw(&local->hw, "PS buffers full - purged %d frames\n", purged);
387 static ieee80211_tx_result
388 ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx)
390 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
391 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
395 * broadcast/multicast frame
397 * If any of the associated/peer stations is in power save mode,
398 * the frame is buffered to be sent after DTIM beacon frame.
399 * This is done either by the hardware or us.
402 /* powersaving STAs currently only in AP/VLAN/mesh mode */
403 if (tx->sdata->vif.type == NL80211_IFTYPE_AP ||
404 tx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
408 ps = &tx->sdata->bss->ps;
409 } else if (ieee80211_vif_is_mesh(&tx->sdata->vif)) {
410 ps = &tx->sdata->u.mesh.ps;
416 /* no buffering for ordered frames */
417 if (ieee80211_has_order(hdr->frame_control))
420 if (ieee80211_is_probe_req(hdr->frame_control))
423 if (ieee80211_hw_check(&tx->local->hw, QUEUE_CONTROL))
424 info->hw_queue = tx->sdata->vif.cab_queue;
426 /* no stations in PS mode and no buffered packets */
427 if (!atomic_read(&ps->num_sta_ps) && skb_queue_empty(&ps->bc_buf))
430 info->flags |= IEEE80211_TX_CTL_SEND_AFTER_DTIM;
432 /* device releases frame after DTIM beacon */
433 if (!ieee80211_hw_check(&tx->local->hw, HOST_BROADCAST_PS_BUFFERING))
436 /* buffered in mac80211 */
437 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
438 purge_old_ps_buffers(tx->local);
440 if (skb_queue_len(&ps->bc_buf) >= AP_MAX_BC_BUFFER) {
442 "BC TX buffer full - dropping the oldest frame\n");
443 ieee80211_free_txskb(&tx->local->hw, skb_dequeue(&ps->bc_buf));
445 tx->local->total_ps_buffered++;
447 skb_queue_tail(&ps->bc_buf, tx->skb);
452 static int ieee80211_use_mfp(__le16 fc, struct sta_info *sta,
455 if (!ieee80211_is_mgmt(fc))
458 if (sta == NULL || !test_sta_flag(sta, WLAN_STA_MFP))
461 if (!ieee80211_is_robust_mgmt_frame(skb))
467 static ieee80211_tx_result
468 ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
470 struct sta_info *sta = tx->sta;
471 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
472 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
473 struct ieee80211_local *local = tx->local;
478 if (unlikely((test_sta_flag(sta, WLAN_STA_PS_STA) ||
479 test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
480 test_sta_flag(sta, WLAN_STA_PS_DELIVER)) &&
481 !(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER))) {
482 int ac = skb_get_queue_mapping(tx->skb);
484 if (ieee80211_is_mgmt(hdr->frame_control) &&
485 !ieee80211_is_bufferable_mmpdu(tx->skb)) {
486 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER;
490 ps_dbg(sta->sdata, "STA %pM aid %d: PS buffer for AC %d\n",
491 sta->sta.addr, sta->sta.aid, ac);
492 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
493 purge_old_ps_buffers(tx->local);
495 /* sync with ieee80211_sta_ps_deliver_wakeup */
496 spin_lock(&sta->ps_lock);
498 * STA woke up the meantime and all the frames on ps_tx_buf have
499 * been queued to pending queue. No reordering can happen, go
500 * ahead and Tx the packet.
502 if (!test_sta_flag(sta, WLAN_STA_PS_STA) &&
503 !test_sta_flag(sta, WLAN_STA_PS_DRIVER) &&
504 !test_sta_flag(sta, WLAN_STA_PS_DELIVER)) {
505 spin_unlock(&sta->ps_lock);
509 if (skb_queue_len(&sta->ps_tx_buf[ac]) >= STA_MAX_TX_BUFFER) {
510 struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf[ac]);
512 "STA %pM TX buffer for AC %d full - dropping oldest frame\n",
514 ieee80211_free_txskb(&local->hw, old);
516 tx->local->total_ps_buffered++;
518 info->control.jiffies = jiffies;
519 info->control.vif = &tx->sdata->vif;
520 info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
521 info->flags &= ~IEEE80211_TX_TEMPORARY_FLAGS;
522 skb_queue_tail(&sta->ps_tx_buf[ac], tx->skb);
523 spin_unlock(&sta->ps_lock);
525 if (!timer_pending(&local->sta_cleanup))
526 mod_timer(&local->sta_cleanup,
527 round_jiffies(jiffies +
528 STA_INFO_CLEANUP_INTERVAL));
531 * We queued up some frames, so the TIM bit might
532 * need to be set, recalculate it.
534 sta_info_recalc_tim(sta);
537 } else if (unlikely(test_sta_flag(sta, WLAN_STA_PS_STA))) {
539 "STA %pM in PS mode, but polling/in SP -> send frame\n",
546 static ieee80211_tx_result debug_noinline
547 ieee80211_tx_h_ps_buf(struct ieee80211_tx_data *tx)
549 if (unlikely(tx->flags & IEEE80211_TX_PS_BUFFERED))
552 if (tx->flags & IEEE80211_TX_UNICAST)
553 return ieee80211_tx_h_unicast_ps_buf(tx);
555 return ieee80211_tx_h_multicast_ps_buf(tx);
558 static ieee80211_tx_result debug_noinline
559 ieee80211_tx_h_check_control_port_protocol(struct ieee80211_tx_data *tx)
561 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
563 if (unlikely(tx->sdata->control_port_protocol == tx->skb->protocol)) {
564 if (tx->sdata->control_port_no_encrypt)
565 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
566 info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO;
567 info->flags |= IEEE80211_TX_CTL_USE_MINRATE;
573 static struct ieee80211_key *
574 ieee80211_select_link_key(struct ieee80211_tx_data *tx)
576 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
577 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
578 struct ieee80211_link_data *link;
579 unsigned int link_id;
581 link_id = u32_get_bits(info->control.flags, IEEE80211_TX_CTRL_MLO_LINK);
582 if (link_id == IEEE80211_LINK_UNSPECIFIED) {
583 link = &tx->sdata->deflink;
585 link = rcu_dereference(tx->sdata->link[link_id]);
590 if (ieee80211_is_group_privacy_action(tx->skb))
591 return rcu_dereference(link->default_multicast_key);
592 else if (ieee80211_is_mgmt(hdr->frame_control) &&
593 is_multicast_ether_addr(hdr->addr1) &&
594 ieee80211_is_robust_mgmt_frame(tx->skb))
595 return rcu_dereference(link->default_mgmt_key);
596 else if (is_multicast_ether_addr(hdr->addr1))
597 return rcu_dereference(link->default_multicast_key);
602 static ieee80211_tx_result debug_noinline
603 ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
605 struct ieee80211_key *key;
606 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
607 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
609 if (unlikely(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)) {
615 (key = rcu_dereference(tx->sta->ptk[tx->sta->ptk_idx])))
617 else if ((key = ieee80211_select_link_key(tx)))
619 else if (!is_multicast_ether_addr(hdr->addr1) &&
620 (key = rcu_dereference(tx->sdata->default_unicast_key)))
626 bool skip_hw = false;
628 /* TODO: add threshold stuff again */
630 switch (tx->key->conf.cipher) {
631 case WLAN_CIPHER_SUITE_WEP40:
632 case WLAN_CIPHER_SUITE_WEP104:
633 case WLAN_CIPHER_SUITE_TKIP:
634 if (!ieee80211_is_data_present(hdr->frame_control))
637 case WLAN_CIPHER_SUITE_CCMP:
638 case WLAN_CIPHER_SUITE_CCMP_256:
639 case WLAN_CIPHER_SUITE_GCMP:
640 case WLAN_CIPHER_SUITE_GCMP_256:
641 if (!ieee80211_is_data_present(hdr->frame_control) &&
642 !ieee80211_use_mfp(hdr->frame_control, tx->sta,
644 !ieee80211_is_group_privacy_action(tx->skb))
647 skip_hw = (tx->key->conf.flags &
648 IEEE80211_KEY_FLAG_SW_MGMT_TX) &&
649 ieee80211_is_mgmt(hdr->frame_control);
651 case WLAN_CIPHER_SUITE_AES_CMAC:
652 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
653 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
654 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
655 if (!ieee80211_is_mgmt(hdr->frame_control))
660 if (unlikely(tx->key && tx->key->flags & KEY_FLAG_TAINTED &&
661 !ieee80211_is_deauth(hdr->frame_control)) &&
662 tx->skb->protocol != tx->sdata->control_port_protocol)
665 if (!skip_hw && tx->key &&
666 tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
667 info->control.hw_key = &tx->key->conf;
668 } else if (ieee80211_is_data_present(hdr->frame_control) && tx->sta &&
669 test_sta_flag(tx->sta, WLAN_STA_USES_ENCRYPTION)) {
676 static ieee80211_tx_result debug_noinline
677 ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
679 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
680 struct ieee80211_hdr *hdr = (void *)tx->skb->data;
681 struct ieee80211_supported_band *sband;
683 struct ieee80211_tx_rate_control txrc;
684 struct ieee80211_sta_rates *ratetbl = NULL;
685 bool encap = info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP;
688 memset(&txrc, 0, sizeof(txrc));
690 sband = tx->local->hw.wiphy->bands[info->band];
692 len = min_t(u32, tx->skb->len + FCS_LEN,
693 tx->local->hw.wiphy->frag_threshold);
695 /* set up the tx rate control struct we give the RC algo */
696 txrc.hw = &tx->local->hw;
698 txrc.bss_conf = &tx->sdata->vif.bss_conf;
700 txrc.reported_rate.idx = -1;
702 if (unlikely(info->control.flags & IEEE80211_TX_CTRL_SCAN_TX)) {
703 txrc.rate_idx_mask = ~0;
705 txrc.rate_idx_mask = tx->sdata->rc_rateidx_mask[info->band];
707 if (tx->sdata->rc_has_mcs_mask[info->band])
708 txrc.rate_idx_mcs_mask =
709 tx->sdata->rc_rateidx_mcs_mask[info->band];
712 txrc.bss = (tx->sdata->vif.type == NL80211_IFTYPE_AP ||
713 tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
714 tx->sdata->vif.type == NL80211_IFTYPE_ADHOC ||
715 tx->sdata->vif.type == NL80211_IFTYPE_OCB);
717 /* set up RTS protection if desired */
718 if (len > tx->local->hw.wiphy->rts_threshold) {
722 info->control.use_rts = txrc.rts;
723 info->control.use_cts_prot = tx->sdata->vif.bss_conf.use_cts_prot;
726 * Use short preamble if the BSS can handle it, but not for
727 * management frames unless we know the receiver can handle
728 * that -- the management frame might be to a station that
729 * just wants a probe response.
731 if (tx->sdata->vif.bss_conf.use_short_preamble &&
732 (ieee80211_is_tx_data(tx->skb) ||
733 (tx->sta && test_sta_flag(tx->sta, WLAN_STA_SHORT_PREAMBLE))))
734 txrc.short_preamble = true;
736 info->control.short_preamble = txrc.short_preamble;
738 /* don't ask rate control when rate already injected via radiotap */
739 if (info->control.flags & IEEE80211_TX_CTRL_RATE_INJECT)
743 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
746 * Lets not bother rate control if we're associated and cannot
747 * talk to the sta. This should not happen.
749 if (WARN(test_bit(SCAN_SW_SCANNING, &tx->local->scanning) && assoc &&
750 !rate_usable_index_exists(sband, &tx->sta->sta),
751 "%s: Dropped data frame as no usable bitrate found while "
752 "scanning and associated. Target station: "
753 "%pM on %d GHz band\n",
755 encap ? ((struct ethhdr *)hdr)->h_dest : hdr->addr1,
760 * If we're associated with the sta at this point we know we can at
761 * least send the frame at the lowest bit rate.
763 rate_control_get_rate(tx->sdata, tx->sta, &txrc);
765 if (tx->sta && !info->control.skip_table)
766 ratetbl = rcu_dereference(tx->sta->sta.rates);
768 if (unlikely(info->control.rates[0].idx < 0)) {
770 struct ieee80211_tx_rate rate = {
771 .idx = ratetbl->rate[0].idx,
772 .flags = ratetbl->rate[0].flags,
773 .count = ratetbl->rate[0].count
776 if (ratetbl->rate[0].idx < 0)
784 tx->rate = info->control.rates[0];
787 if (txrc.reported_rate.idx < 0) {
788 txrc.reported_rate = tx->rate;
789 if (tx->sta && ieee80211_is_tx_data(tx->skb))
790 tx->sta->deflink.tx_stats.last_rate = txrc.reported_rate;
792 tx->sta->deflink.tx_stats.last_rate = txrc.reported_rate;
797 if (unlikely(!info->control.rates[0].count))
798 info->control.rates[0].count = 1;
800 if (WARN_ON_ONCE((info->control.rates[0].count > 1) &&
801 (info->flags & IEEE80211_TX_CTL_NO_ACK)))
802 info->control.rates[0].count = 1;
807 static __le16 ieee80211_tx_next_seq(struct sta_info *sta, int tid)
809 u16 *seq = &sta->tid_seq[tid];
810 __le16 ret = cpu_to_le16(*seq);
812 /* Increase the sequence number. */
813 *seq = (*seq + 0x10) & IEEE80211_SCTL_SEQ;
818 static ieee80211_tx_result debug_noinline
819 ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx)
821 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
822 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
826 * Packet injection may want to control the sequence
827 * number, if we have no matching interface then we
828 * neither assign one ourselves nor ask the driver to.
830 if (unlikely(info->control.vif->type == NL80211_IFTYPE_MONITOR))
833 if (unlikely(ieee80211_is_ctl(hdr->frame_control)))
836 if (ieee80211_hdrlen(hdr->frame_control) < 24)
839 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
842 if (info->control.flags & IEEE80211_TX_CTRL_NO_SEQNO)
845 /* SNS11 from 802.11be 10.3.2.14 */
846 if (unlikely(is_multicast_ether_addr(hdr->addr1) &&
847 ieee80211_vif_is_mld(info->control.vif) &&
848 info->control.vif->type == NL80211_IFTYPE_AP)) {
849 if (info->control.flags & IEEE80211_TX_CTRL_MCAST_MLO_FIRST_TX)
850 tx->sdata->mld_mcast_seq += 0x10;
851 hdr->seq_ctrl = cpu_to_le16(tx->sdata->mld_mcast_seq);
856 * Anything but QoS data that has a sequence number field
857 * (is long enough) gets a sequence number from the global
858 * counter. QoS data frames with a multicast destination
859 * also use the global counter (802.11-2012 9.3.2.10).
861 if (!ieee80211_is_data_qos(hdr->frame_control) ||
862 is_multicast_ether_addr(hdr->addr1)) {
863 /* driver should assign sequence number */
864 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
865 /* for pure STA mode without beacons, we can do it */
866 hdr->seq_ctrl = cpu_to_le16(tx->sdata->sequence_number);
867 tx->sdata->sequence_number += 0x10;
869 tx->sta->deflink.tx_stats.msdu[IEEE80211_NUM_TIDS]++;
874 * This should be true for injected/management frames only, for
875 * management frames we have set the IEEE80211_TX_CTL_ASSIGN_SEQ
876 * above since they are not QoS-data frames.
881 /* include per-STA, per-TID sequence counter */
882 tid = ieee80211_get_tid(hdr);
883 tx->sta->deflink.tx_stats.msdu[tid]++;
885 hdr->seq_ctrl = ieee80211_tx_next_seq(tx->sta, tid);
890 static int ieee80211_fragment(struct ieee80211_tx_data *tx,
891 struct sk_buff *skb, int hdrlen,
894 struct ieee80211_local *local = tx->local;
895 struct ieee80211_tx_info *info;
897 int per_fragm = frag_threshold - hdrlen - FCS_LEN;
898 int pos = hdrlen + per_fragm;
899 int rem = skb->len - hdrlen - per_fragm;
901 if (WARN_ON(rem < 0))
904 /* first fragment was already added to queue by caller */
907 int fraglen = per_fragm;
912 tmp = dev_alloc_skb(local->tx_headroom +
914 IEEE80211_ENCRYPT_HEADROOM +
915 IEEE80211_ENCRYPT_TAILROOM);
919 __skb_queue_tail(&tx->skbs, tmp);
922 local->tx_headroom + IEEE80211_ENCRYPT_HEADROOM);
924 /* copy control information */
925 memcpy(tmp->cb, skb->cb, sizeof(tmp->cb));
927 info = IEEE80211_SKB_CB(tmp);
928 info->flags &= ~(IEEE80211_TX_CTL_CLEAR_PS_FILT |
929 IEEE80211_TX_CTL_FIRST_FRAGMENT);
932 info->flags |= IEEE80211_TX_CTL_MORE_FRAMES;
934 skb_copy_queue_mapping(tmp, skb);
935 tmp->priority = skb->priority;
938 /* copy header and data */
939 skb_put_data(tmp, skb->data, hdrlen);
940 skb_put_data(tmp, skb->data + pos, fraglen);
945 /* adjust first fragment's length */
946 skb_trim(skb, hdrlen + per_fragm);
950 static ieee80211_tx_result debug_noinline
951 ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
953 struct sk_buff *skb = tx->skb;
954 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
955 struct ieee80211_hdr *hdr = (void *)skb->data;
956 int frag_threshold = tx->local->hw.wiphy->frag_threshold;
960 /* no matter what happens, tx->skb moves to tx->skbs */
961 __skb_queue_tail(&tx->skbs, skb);
964 if (info->flags & IEEE80211_TX_CTL_DONTFRAG)
967 if (ieee80211_hw_check(&tx->local->hw, SUPPORTS_TX_FRAG))
971 * Warn when submitting a fragmented A-MPDU frame and drop it.
972 * This scenario is handled in ieee80211_tx_prepare but extra
973 * caution taken here as fragmented ampdu may cause Tx stop.
975 if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU))
978 hdrlen = ieee80211_hdrlen(hdr->frame_control);
980 /* internal error, why isn't DONTFRAG set? */
981 if (WARN_ON(skb->len + FCS_LEN <= frag_threshold))
985 * Now fragment the frame. This will allocate all the fragments and
986 * chain them (using skb as the first fragment) to skb->next.
987 * During transmission, we will remove the successfully transmitted
988 * fragments from this list. When the low-level driver rejects one
989 * of the fragments then we will simply pretend to accept the skb
990 * but store it away as pending.
992 if (ieee80211_fragment(tx, skb, hdrlen, frag_threshold))
995 /* update duration/seq/flags of fragments */
998 skb_queue_walk(&tx->skbs, skb) {
999 const __le16 morefrags = cpu_to_le16(IEEE80211_FCTL_MOREFRAGS);
1001 hdr = (void *)skb->data;
1002 info = IEEE80211_SKB_CB(skb);
1004 if (!skb_queue_is_last(&tx->skbs, skb)) {
1005 hdr->frame_control |= morefrags;
1007 * No multi-rate retries for fragmented frames, that
1008 * would completely throw off the NAV at other STAs.
1010 info->control.rates[1].idx = -1;
1011 info->control.rates[2].idx = -1;
1012 info->control.rates[3].idx = -1;
1013 BUILD_BUG_ON(IEEE80211_TX_MAX_RATES != 4);
1014 info->flags &= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE;
1016 hdr->frame_control &= ~morefrags;
1018 hdr->seq_ctrl |= cpu_to_le16(fragnum & IEEE80211_SCTL_FRAG);
1025 static ieee80211_tx_result debug_noinline
1026 ieee80211_tx_h_stats(struct ieee80211_tx_data *tx)
1028 struct sk_buff *skb;
1034 skb_queue_walk(&tx->skbs, skb) {
1035 ac = skb_get_queue_mapping(skb);
1036 tx->sta->deflink.tx_stats.bytes[ac] += skb->len;
1039 tx->sta->deflink.tx_stats.packets[ac]++;
1044 static ieee80211_tx_result debug_noinline
1045 ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx)
1050 switch (tx->key->conf.cipher) {
1051 case WLAN_CIPHER_SUITE_WEP40:
1052 case WLAN_CIPHER_SUITE_WEP104:
1053 return ieee80211_crypto_wep_encrypt(tx);
1054 case WLAN_CIPHER_SUITE_TKIP:
1055 return ieee80211_crypto_tkip_encrypt(tx);
1056 case WLAN_CIPHER_SUITE_CCMP:
1057 return ieee80211_crypto_ccmp_encrypt(
1058 tx, IEEE80211_CCMP_MIC_LEN);
1059 case WLAN_CIPHER_SUITE_CCMP_256:
1060 return ieee80211_crypto_ccmp_encrypt(
1061 tx, IEEE80211_CCMP_256_MIC_LEN);
1062 case WLAN_CIPHER_SUITE_AES_CMAC:
1063 return ieee80211_crypto_aes_cmac_encrypt(tx);
1064 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
1065 return ieee80211_crypto_aes_cmac_256_encrypt(tx);
1066 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
1067 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
1068 return ieee80211_crypto_aes_gmac_encrypt(tx);
1069 case WLAN_CIPHER_SUITE_GCMP:
1070 case WLAN_CIPHER_SUITE_GCMP_256:
1071 return ieee80211_crypto_gcmp_encrypt(tx);
1077 static ieee80211_tx_result debug_noinline
1078 ieee80211_tx_h_calculate_duration(struct ieee80211_tx_data *tx)
1080 struct sk_buff *skb;
1081 struct ieee80211_hdr *hdr;
1085 skb_queue_walk(&tx->skbs, skb) {
1086 hdr = (void *) skb->data;
1087 if (unlikely(ieee80211_is_pspoll(hdr->frame_control)))
1088 break; /* must not overwrite AID */
1089 if (!skb_queue_is_last(&tx->skbs, skb)) {
1090 struct sk_buff *next = skb_queue_next(&tx->skbs, skb);
1091 next_len = next->len;
1094 group_addr = is_multicast_ether_addr(hdr->addr1);
1097 ieee80211_duration(tx, skb, group_addr, next_len);
1103 /* actual transmit path */
1105 static bool ieee80211_tx_prep_agg(struct ieee80211_tx_data *tx,
1106 struct sk_buff *skb,
1107 struct ieee80211_tx_info *info,
1108 struct tid_ampdu_tx *tid_tx,
1111 bool queued = false;
1112 bool reset_agg_timer = false;
1113 struct sk_buff *purge_skb = NULL;
1115 if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
1116 reset_agg_timer = true;
1117 } else if (test_bit(HT_AGG_STATE_WANT_START, &tid_tx->state)) {
1119 * nothing -- this aggregation session is being started
1120 * but that might still fail with the driver
1122 } else if (!tx->sta->sta.txq[tid]) {
1123 spin_lock(&tx->sta->lock);
1125 * Need to re-check now, because we may get here
1127 * 1) in the window during which the setup is actually
1128 * already done, but not marked yet because not all
1129 * packets are spliced over to the driver pending
1130 * queue yet -- if this happened we acquire the lock
1131 * either before or after the splice happens, but
1132 * need to recheck which of these cases happened.
1134 * 2) during session teardown, if the OPERATIONAL bit
1135 * was cleared due to the teardown but the pointer
1136 * hasn't been assigned NULL yet (or we loaded it
1137 * before it was assigned) -- in this case it may
1138 * now be NULL which means we should just let the
1139 * packet pass through because splicing the frames
1140 * back is already done.
1142 tid_tx = rcu_dereference_protected_tid_tx(tx->sta, tid);
1145 /* do nothing, let packet pass through */
1146 } else if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
1147 reset_agg_timer = true;
1150 if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER) {
1151 clear_sta_flag(tx->sta, WLAN_STA_SP);
1152 ps_dbg(tx->sta->sdata,
1153 "STA %pM aid %d: SP frame queued, close the SP w/o telling the peer\n",
1154 tx->sta->sta.addr, tx->sta->sta.aid);
1156 info->control.vif = &tx->sdata->vif;
1157 info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
1158 info->flags &= ~IEEE80211_TX_TEMPORARY_FLAGS;
1159 __skb_queue_tail(&tid_tx->pending, skb);
1160 if (skb_queue_len(&tid_tx->pending) > STA_MAX_TX_BUFFER)
1161 purge_skb = __skb_dequeue(&tid_tx->pending);
1163 spin_unlock(&tx->sta->lock);
1166 ieee80211_free_txskb(&tx->local->hw, purge_skb);
1169 /* reset session timer */
1170 if (reset_agg_timer)
1171 tid_tx->last_tx = jiffies;
1176 void ieee80211_aggr_check(struct ieee80211_sub_if_data *sdata,
1177 struct sta_info *sta, struct sk_buff *skb)
1179 struct rate_control_ref *ref = sdata->local->rate_ctrl;
1182 if (!ref || !(ref->ops->capa & RATE_CTRL_CAPA_AMPDU_TRIGGER))
1185 if (!sta || !sta->sta.deflink.ht_cap.ht_supported ||
1186 !sta->sta.wme || skb_get_queue_mapping(skb) == IEEE80211_AC_VO ||
1187 skb->protocol == sdata->control_port_protocol)
1190 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
1191 if (likely(sta->ampdu_mlme.tid_tx[tid]))
1194 ieee80211_start_tx_ba_session(&sta->sta, tid, 0);
1199 * pass %NULL for the station if unknown, a valid pointer if known
1200 * or an ERR_PTR() if the station is known not to exist
1202 static ieee80211_tx_result
1203 ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata,
1204 struct ieee80211_tx_data *tx,
1205 struct sta_info *sta, struct sk_buff *skb)
1207 struct ieee80211_local *local = sdata->local;
1208 struct ieee80211_hdr *hdr;
1209 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1210 bool aggr_check = false;
1213 memset(tx, 0, sizeof(*tx));
1217 __skb_queue_head_init(&tx->skbs);
1220 * If this flag is set to true anywhere, and we get here,
1221 * we are doing the needed processing, so remove the flag
1224 info->control.flags &= ~IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
1226 hdr = (struct ieee80211_hdr *) skb->data;
1232 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
1233 tx->sta = rcu_dereference(sdata->u.vlan.sta);
1234 if (!tx->sta && sdata->wdev.use_4addr)
1236 } else if (tx->sdata->control_port_protocol == tx->skb->protocol) {
1237 tx->sta = sta_info_get_bss(sdata, hdr->addr1);
1239 if (!tx->sta && !is_multicast_ether_addr(hdr->addr1)) {
1240 tx->sta = sta_info_get(sdata, hdr->addr1);
1245 if (tx->sta && ieee80211_is_data_qos(hdr->frame_control) &&
1246 !ieee80211_is_qos_nullfunc(hdr->frame_control) &&
1247 ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
1248 !ieee80211_hw_check(&local->hw, TX_AMPDU_SETUP_IN_HW)) {
1249 struct tid_ampdu_tx *tid_tx;
1251 tid = ieee80211_get_tid(hdr);
1252 tid_tx = rcu_dereference(tx->sta->ampdu_mlme.tid_tx[tid]);
1253 if (!tid_tx && aggr_check) {
1254 ieee80211_aggr_check(sdata, tx->sta, skb);
1255 tid_tx = rcu_dereference(tx->sta->ampdu_mlme.tid_tx[tid]);
1261 queued = ieee80211_tx_prep_agg(tx, skb, info,
1264 if (unlikely(queued))
1269 if (is_multicast_ether_addr(hdr->addr1)) {
1270 tx->flags &= ~IEEE80211_TX_UNICAST;
1271 info->flags |= IEEE80211_TX_CTL_NO_ACK;
1273 tx->flags |= IEEE80211_TX_UNICAST;
1275 if (!(info->flags & IEEE80211_TX_CTL_DONTFRAG)) {
1276 if (!(tx->flags & IEEE80211_TX_UNICAST) ||
1277 skb->len + FCS_LEN <= local->hw.wiphy->frag_threshold ||
1278 info->flags & IEEE80211_TX_CTL_AMPDU)
1279 info->flags |= IEEE80211_TX_CTL_DONTFRAG;
1283 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
1284 else if (test_and_clear_sta_flag(tx->sta, WLAN_STA_CLEAR_PS_FILT)) {
1285 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
1286 ieee80211_check_fast_xmit(tx->sta);
1289 info->flags |= IEEE80211_TX_CTL_FIRST_FRAGMENT;
1294 static struct txq_info *ieee80211_get_txq(struct ieee80211_local *local,
1295 struct ieee80211_vif *vif,
1296 struct sta_info *sta,
1297 struct sk_buff *skb)
1299 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1300 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1301 struct ieee80211_txq *txq = NULL;
1303 if ((info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) ||
1304 (info->control.flags & IEEE80211_TX_CTRL_PS_RESPONSE))
1307 if (!(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) &&
1308 unlikely(!ieee80211_is_data_present(hdr->frame_control))) {
1309 if ((!ieee80211_is_mgmt(hdr->frame_control) ||
1310 ieee80211_is_bufferable_mmpdu(skb) ||
1311 vif->type == NL80211_IFTYPE_STATION) &&
1312 sta && sta->uploaded) {
1314 * This will be NULL if the driver didn't set the
1315 * opt-in hardware flag.
1317 txq = sta->sta.txq[IEEE80211_NUM_TIDS];
1320 u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
1325 txq = sta->sta.txq[tid];
1333 return to_txq_info(txq);
1336 static void ieee80211_set_skb_enqueue_time(struct sk_buff *skb)
1338 struct sk_buff *next;
1339 codel_time_t now = codel_get_time();
1341 skb_list_walk_safe(skb, skb, next)
1342 IEEE80211_SKB_CB(skb)->control.enqueue_time = now;
1345 static u32 codel_skb_len_func(const struct sk_buff *skb)
1350 static codel_time_t codel_skb_time_func(const struct sk_buff *skb)
1352 const struct ieee80211_tx_info *info;
1354 info = (const struct ieee80211_tx_info *)skb->cb;
1355 return info->control.enqueue_time;
1358 static struct sk_buff *codel_dequeue_func(struct codel_vars *cvars,
1361 struct ieee80211_local *local;
1362 struct txq_info *txqi;
1364 struct fq_flow *flow;
1367 local = vif_to_sdata(txqi->txq.vif)->local;
1370 if (cvars == &txqi->def_cvars)
1371 flow = &txqi->tin.default_flow;
1373 flow = &fq->flows[cvars - local->cvars];
1375 return fq_flow_dequeue(fq, flow);
1378 static void codel_drop_func(struct sk_buff *skb,
1381 struct ieee80211_local *local;
1382 struct ieee80211_hw *hw;
1383 struct txq_info *txqi;
1386 local = vif_to_sdata(txqi->txq.vif)->local;
1389 ieee80211_free_txskb(hw, skb);
1392 static struct sk_buff *fq_tin_dequeue_func(struct fq *fq,
1394 struct fq_flow *flow)
1396 struct ieee80211_local *local;
1397 struct txq_info *txqi;
1398 struct codel_vars *cvars;
1399 struct codel_params *cparams;
1400 struct codel_stats *cstats;
1402 local = container_of(fq, struct ieee80211_local, fq);
1403 txqi = container_of(tin, struct txq_info, tin);
1404 cstats = &txqi->cstats;
1406 if (txqi->txq.sta) {
1407 struct sta_info *sta = container_of(txqi->txq.sta,
1408 struct sta_info, sta);
1409 cparams = &sta->cparams;
1411 cparams = &local->cparams;
1414 if (flow == &tin->default_flow)
1415 cvars = &txqi->def_cvars;
1417 cvars = &local->cvars[flow - fq->flows];
1419 return codel_dequeue(txqi,
1425 codel_skb_time_func,
1427 codel_dequeue_func);
1430 static void fq_skb_free_func(struct fq *fq,
1432 struct fq_flow *flow,
1433 struct sk_buff *skb)
1435 struct ieee80211_local *local;
1437 local = container_of(fq, struct ieee80211_local, fq);
1438 ieee80211_free_txskb(&local->hw, skb);
1441 static void ieee80211_txq_enqueue(struct ieee80211_local *local,
1442 struct txq_info *txqi,
1443 struct sk_buff *skb)
1445 struct fq *fq = &local->fq;
1446 struct fq_tin *tin = &txqi->tin;
1447 u32 flow_idx = fq_flow_idx(fq, skb);
1449 ieee80211_set_skb_enqueue_time(skb);
1451 spin_lock_bh(&fq->lock);
1453 * For management frames, don't really apply codel etc.,
1454 * we don't want to apply any shaping or anything we just
1455 * want to simplify the driver API by having them on the
1458 if (unlikely(txqi->txq.tid == IEEE80211_NUM_TIDS)) {
1459 IEEE80211_SKB_CB(skb)->control.flags |=
1460 IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
1461 __skb_queue_tail(&txqi->frags, skb);
1463 fq_tin_enqueue(fq, tin, flow_idx, skb,
1466 spin_unlock_bh(&fq->lock);
1469 static bool fq_vlan_filter_func(struct fq *fq, struct fq_tin *tin,
1470 struct fq_flow *flow, struct sk_buff *skb,
1473 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1475 return info->control.vif == data;
1478 void ieee80211_txq_remove_vlan(struct ieee80211_local *local,
1479 struct ieee80211_sub_if_data *sdata)
1481 struct fq *fq = &local->fq;
1482 struct txq_info *txqi;
1484 struct ieee80211_sub_if_data *ap;
1486 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_AP_VLAN))
1489 ap = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap);
1494 txqi = to_txq_info(ap->vif.txq);
1497 spin_lock_bh(&fq->lock);
1498 fq_tin_filter(fq, tin, fq_vlan_filter_func, &sdata->vif,
1500 spin_unlock_bh(&fq->lock);
1503 void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata,
1504 struct sta_info *sta,
1505 struct txq_info *txqi, int tid)
1507 fq_tin_init(&txqi->tin);
1508 codel_vars_init(&txqi->def_cvars);
1509 codel_stats_init(&txqi->cstats);
1510 __skb_queue_head_init(&txqi->frags);
1511 INIT_LIST_HEAD(&txqi->schedule_order);
1513 txqi->txq.vif = &sdata->vif;
1516 sdata->vif.txq = &txqi->txq;
1518 txqi->txq.ac = IEEE80211_AC_BE;
1523 if (tid == IEEE80211_NUM_TIDS) {
1524 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
1525 /* Drivers need to opt in to the management MPDU TXQ */
1526 if (!ieee80211_hw_check(&sdata->local->hw,
1529 } else if (!ieee80211_hw_check(&sdata->local->hw,
1531 /* Drivers need to opt in to the bufferable MMPDU TXQ */
1534 txqi->txq.ac = IEEE80211_AC_VO;
1536 txqi->txq.ac = ieee80211_ac_from_tid(tid);
1539 txqi->txq.sta = &sta->sta;
1540 txqi->txq.tid = tid;
1541 sta->sta.txq[tid] = &txqi->txq;
1544 void ieee80211_txq_purge(struct ieee80211_local *local,
1545 struct txq_info *txqi)
1547 struct fq *fq = &local->fq;
1548 struct fq_tin *tin = &txqi->tin;
1550 spin_lock_bh(&fq->lock);
1551 fq_tin_reset(fq, tin, fq_skb_free_func);
1552 ieee80211_purge_tx_queue(&local->hw, &txqi->frags);
1553 spin_unlock_bh(&fq->lock);
1555 spin_lock_bh(&local->active_txq_lock[txqi->txq.ac]);
1556 list_del_init(&txqi->schedule_order);
1557 spin_unlock_bh(&local->active_txq_lock[txqi->txq.ac]);
1560 void ieee80211_txq_set_params(struct ieee80211_local *local)
1562 if (local->hw.wiphy->txq_limit)
1563 local->fq.limit = local->hw.wiphy->txq_limit;
1565 local->hw.wiphy->txq_limit = local->fq.limit;
1567 if (local->hw.wiphy->txq_memory_limit)
1568 local->fq.memory_limit = local->hw.wiphy->txq_memory_limit;
1570 local->hw.wiphy->txq_memory_limit = local->fq.memory_limit;
1572 if (local->hw.wiphy->txq_quantum)
1573 local->fq.quantum = local->hw.wiphy->txq_quantum;
1575 local->hw.wiphy->txq_quantum = local->fq.quantum;
1578 int ieee80211_txq_setup_flows(struct ieee80211_local *local)
1580 struct fq *fq = &local->fq;
1583 bool supp_vht = false;
1584 enum nl80211_band band;
1586 ret = fq_init(fq, 4096);
1591 * If the hardware doesn't support VHT, it is safe to limit the maximum
1592 * queue size. 4 Mbytes is 64 max-size aggregates in 802.11n.
1594 for (band = 0; band < NUM_NL80211_BANDS; band++) {
1595 struct ieee80211_supported_band *sband;
1597 sband = local->hw.wiphy->bands[band];
1601 supp_vht = supp_vht || sband->vht_cap.vht_supported;
1605 fq->memory_limit = 4 << 20; /* 4 Mbytes */
1607 codel_params_init(&local->cparams);
1608 local->cparams.interval = MS2TIME(100);
1609 local->cparams.target = MS2TIME(20);
1610 local->cparams.ecn = true;
1612 local->cvars = kcalloc(fq->flows_cnt, sizeof(local->cvars[0]),
1614 if (!local->cvars) {
1615 spin_lock_bh(&fq->lock);
1616 fq_reset(fq, fq_skb_free_func);
1617 spin_unlock_bh(&fq->lock);
1621 for (i = 0; i < fq->flows_cnt; i++)
1622 codel_vars_init(&local->cvars[i]);
1624 ieee80211_txq_set_params(local);
1629 void ieee80211_txq_teardown_flows(struct ieee80211_local *local)
1631 struct fq *fq = &local->fq;
1633 kfree(local->cvars);
1634 local->cvars = NULL;
1636 spin_lock_bh(&fq->lock);
1637 fq_reset(fq, fq_skb_free_func);
1638 spin_unlock_bh(&fq->lock);
1641 static bool ieee80211_queue_skb(struct ieee80211_local *local,
1642 struct ieee80211_sub_if_data *sdata,
1643 struct sta_info *sta,
1644 struct sk_buff *skb)
1646 struct ieee80211_vif *vif;
1647 struct txq_info *txqi;
1649 if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
1652 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1653 sdata = container_of(sdata->bss,
1654 struct ieee80211_sub_if_data, u.ap);
1657 txqi = ieee80211_get_txq(local, vif, sta, skb);
1662 ieee80211_txq_enqueue(local, txqi, skb);
1664 schedule_and_wake_txq(local, txqi);
1669 static bool ieee80211_tx_frags(struct ieee80211_local *local,
1670 struct ieee80211_vif *vif,
1671 struct sta_info *sta,
1672 struct sk_buff_head *skbs,
1675 struct ieee80211_tx_control control = {};
1676 struct sk_buff *skb, *tmp;
1677 unsigned long flags;
1679 skb_queue_walk_safe(skbs, skb, tmp) {
1680 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1681 int q = info->hw_queue;
1683 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1684 if (WARN_ON_ONCE(q >= local->hw.queues)) {
1685 __skb_unlink(skb, skbs);
1686 ieee80211_free_txskb(&local->hw, skb);
1691 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1692 if (local->queue_stop_reasons[q] ||
1693 (!txpending && !skb_queue_empty(&local->pending[q]))) {
1694 if (unlikely(info->flags &
1695 IEEE80211_TX_INTFL_OFFCHAN_TX_OK)) {
1696 if (local->queue_stop_reasons[q] &
1697 ~BIT(IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL)) {
1699 * Drop off-channel frames if queues
1700 * are stopped for any reason other
1701 * than off-channel operation. Never
1704 spin_unlock_irqrestore(
1705 &local->queue_stop_reason_lock,
1707 ieee80211_purge_tx_queue(&local->hw,
1714 * Since queue is stopped, queue up frames for
1715 * later transmission from the tx-pending
1716 * tasklet when the queue is woken again.
1719 skb_queue_splice_init(skbs,
1720 &local->pending[q]);
1722 skb_queue_splice_tail_init(skbs,
1723 &local->pending[q]);
1725 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1730 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1732 info->control.vif = vif;
1733 control.sta = sta ? &sta->sta : NULL;
1735 __skb_unlink(skb, skbs);
1736 drv_tx(local, &control, skb);
1743 * Returns false if the frame couldn't be transmitted but was queued instead.
1745 static bool __ieee80211_tx(struct ieee80211_local *local,
1746 struct sk_buff_head *skbs, struct sta_info *sta,
1749 struct ieee80211_tx_info *info;
1750 struct ieee80211_sub_if_data *sdata;
1751 struct ieee80211_vif *vif;
1752 struct sk_buff *skb;
1755 if (WARN_ON(skb_queue_empty(skbs)))
1758 skb = skb_peek(skbs);
1759 info = IEEE80211_SKB_CB(skb);
1760 sdata = vif_to_sdata(info->control.vif);
1761 if (sta && !sta->uploaded)
1764 switch (sdata->vif.type) {
1765 case NL80211_IFTYPE_MONITOR:
1766 if (sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) {
1770 sdata = rcu_dereference(local->monitor_sdata);
1774 vif->hw_queue[skb_get_queue_mapping(skb)];
1775 } else if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) {
1776 ieee80211_purge_tx_queue(&local->hw, skbs);
1781 case NL80211_IFTYPE_AP_VLAN:
1782 sdata = container_of(sdata->bss,
1783 struct ieee80211_sub_if_data, u.ap);
1790 result = ieee80211_tx_frags(local, vif, sta, skbs, txpending);
1792 WARN_ON_ONCE(!skb_queue_empty(skbs));
1798 * Invoke TX handlers, return 0 on success and non-zero if the
1799 * frame was dropped or queued.
1801 * The handlers are split into an early and late part. The latter is everything
1802 * that can be sensitive to reordering, and will be deferred to after packets
1803 * are dequeued from the intermediate queues (when they are enabled).
1805 static int invoke_tx_handlers_early(struct ieee80211_tx_data *tx)
1807 ieee80211_tx_result res = TX_DROP;
1809 #define CALL_TXH(txh) \
1812 if (res != TX_CONTINUE) \
1816 CALL_TXH(ieee80211_tx_h_dynamic_ps);
1817 CALL_TXH(ieee80211_tx_h_check_assoc);
1818 CALL_TXH(ieee80211_tx_h_ps_buf);
1819 CALL_TXH(ieee80211_tx_h_check_control_port_protocol);
1820 CALL_TXH(ieee80211_tx_h_select_key);
1823 if (unlikely(res == TX_DROP)) {
1824 I802_DEBUG_INC(tx->local->tx_handlers_drop);
1826 ieee80211_free_txskb(&tx->local->hw, tx->skb);
1828 ieee80211_purge_tx_queue(&tx->local->hw, &tx->skbs);
1830 } else if (unlikely(res == TX_QUEUED)) {
1831 I802_DEBUG_INC(tx->local->tx_handlers_queued);
1839 * Late handlers can be called while the sta lock is held. Handlers that can
1840 * cause packets to be generated will cause deadlock!
1842 static int invoke_tx_handlers_late(struct ieee80211_tx_data *tx)
1844 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
1845 ieee80211_tx_result res = TX_CONTINUE;
1847 if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL))
1848 CALL_TXH(ieee80211_tx_h_rate_ctrl);
1850 if (unlikely(info->flags & IEEE80211_TX_INTFL_RETRANSMISSION)) {
1851 __skb_queue_tail(&tx->skbs, tx->skb);
1856 CALL_TXH(ieee80211_tx_h_michael_mic_add);
1857 CALL_TXH(ieee80211_tx_h_sequence);
1858 CALL_TXH(ieee80211_tx_h_fragment);
1859 /* handlers after fragment must be aware of tx info fragmentation! */
1860 CALL_TXH(ieee80211_tx_h_stats);
1861 CALL_TXH(ieee80211_tx_h_encrypt);
1862 if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL))
1863 CALL_TXH(ieee80211_tx_h_calculate_duration);
1867 if (unlikely(res == TX_DROP)) {
1868 I802_DEBUG_INC(tx->local->tx_handlers_drop);
1870 ieee80211_free_txskb(&tx->local->hw, tx->skb);
1872 ieee80211_purge_tx_queue(&tx->local->hw, &tx->skbs);
1874 } else if (unlikely(res == TX_QUEUED)) {
1875 I802_DEBUG_INC(tx->local->tx_handlers_queued);
1882 static int invoke_tx_handlers(struct ieee80211_tx_data *tx)
1884 int r = invoke_tx_handlers_early(tx);
1888 return invoke_tx_handlers_late(tx);
1891 bool ieee80211_tx_prepare_skb(struct ieee80211_hw *hw,
1892 struct ieee80211_vif *vif, struct sk_buff *skb,
1893 int band, struct ieee80211_sta **sta)
1895 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1896 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1897 struct ieee80211_tx_data tx;
1898 struct sk_buff *skb2;
1900 if (ieee80211_tx_prepare(sdata, &tx, NULL, skb) == TX_DROP)
1904 info->control.vif = vif;
1905 info->hw_queue = vif->hw_queue[skb_get_queue_mapping(skb)];
1907 if (invoke_tx_handlers(&tx))
1912 *sta = &tx.sta->sta;
1917 /* this function isn't suitable for fragmented data frames */
1918 skb2 = __skb_dequeue(&tx.skbs);
1919 if (WARN_ON(skb2 != skb || !skb_queue_empty(&tx.skbs))) {
1920 ieee80211_free_txskb(hw, skb2);
1921 ieee80211_purge_tx_queue(hw, &tx.skbs);
1927 EXPORT_SYMBOL(ieee80211_tx_prepare_skb);
1930 * Returns false if the frame couldn't be transmitted but was queued instead.
1932 static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata,
1933 struct sta_info *sta, struct sk_buff *skb,
1936 struct ieee80211_local *local = sdata->local;
1937 struct ieee80211_tx_data tx;
1938 ieee80211_tx_result res_prepare;
1939 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1942 if (unlikely(skb->len < 10)) {
1947 /* initialises tx */
1948 res_prepare = ieee80211_tx_prepare(sdata, &tx, sta, skb);
1950 if (unlikely(res_prepare == TX_DROP)) {
1951 ieee80211_free_txskb(&local->hw, skb);
1953 } else if (unlikely(res_prepare == TX_QUEUED)) {
1957 /* set up hw_queue value early */
1958 if (!(info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) ||
1959 !ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
1961 sdata->vif.hw_queue[skb_get_queue_mapping(skb)];
1963 if (invoke_tx_handlers_early(&tx))
1966 if (ieee80211_queue_skb(local, sdata, tx.sta, tx.skb))
1969 if (!invoke_tx_handlers_late(&tx))
1970 result = __ieee80211_tx(local, &tx.skbs, tx.sta, txpending);
1975 /* device xmit handlers */
1977 enum ieee80211_encrypt {
1983 static int ieee80211_skb_resize(struct ieee80211_sub_if_data *sdata,
1984 struct sk_buff *skb,
1986 enum ieee80211_encrypt encrypt)
1988 struct ieee80211_local *local = sdata->local;
1992 enc_tailroom = encrypt == ENCRYPT_MGMT ||
1993 (encrypt == ENCRYPT_DATA &&
1994 sdata->crypto_tx_tailroom_needed_cnt);
1997 tail_need = IEEE80211_ENCRYPT_TAILROOM;
1998 tail_need -= skb_tailroom(skb);
1999 tail_need = max_t(int, tail_need, 0);
2002 if (skb_cloned(skb) &&
2003 (!ieee80211_hw_check(&local->hw, SUPPORTS_CLONED_SKBS) ||
2004 !skb_clone_writable(skb, ETH_HLEN) || enc_tailroom))
2005 I802_DEBUG_INC(local->tx_expand_skb_head_cloned);
2006 else if (head_need || tail_need)
2007 I802_DEBUG_INC(local->tx_expand_skb_head);
2011 if (pskb_expand_head(skb, head_need, tail_need, GFP_ATOMIC)) {
2012 wiphy_debug(local->hw.wiphy,
2013 "failed to reallocate TX buffer\n");
2020 void ieee80211_xmit(struct ieee80211_sub_if_data *sdata,
2021 struct sta_info *sta, struct sk_buff *skb)
2023 struct ieee80211_local *local = sdata->local;
2024 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2025 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2027 enum ieee80211_encrypt encrypt;
2029 if (info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)
2030 encrypt = ENCRYPT_NO;
2031 else if (ieee80211_is_mgmt(hdr->frame_control))
2032 encrypt = ENCRYPT_MGMT;
2034 encrypt = ENCRYPT_DATA;
2036 headroom = local->tx_headroom;
2037 if (encrypt != ENCRYPT_NO)
2038 headroom += IEEE80211_ENCRYPT_HEADROOM;
2039 headroom -= skb_headroom(skb);
2040 headroom = max_t(int, 0, headroom);
2042 if (ieee80211_skb_resize(sdata, skb, headroom, encrypt)) {
2043 ieee80211_free_txskb(&local->hw, skb);
2047 /* reload after potential resize */
2048 hdr = (struct ieee80211_hdr *) skb->data;
2049 info->control.vif = &sdata->vif;
2051 if (ieee80211_vif_is_mesh(&sdata->vif)) {
2052 if (ieee80211_is_data(hdr->frame_control) &&
2053 is_unicast_ether_addr(hdr->addr1)) {
2054 if (mesh_nexthop_resolve(sdata, skb))
2055 return; /* skb queued: don't free */
2057 ieee80211_mps_set_frame_flags(sdata, NULL, hdr);
2061 ieee80211_set_qos_hdr(sdata, skb);
2062 ieee80211_tx(sdata, sta, skb, false);
2065 static bool ieee80211_validate_radiotap_len(struct sk_buff *skb)
2067 struct ieee80211_radiotap_header *rthdr =
2068 (struct ieee80211_radiotap_header *)skb->data;
2070 /* check for not even having the fixed radiotap header part */
2071 if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
2072 return false; /* too short to be possibly valid */
2074 /* is it a header version we can trust to find length from? */
2075 if (unlikely(rthdr->it_version))
2076 return false; /* only version 0 is supported */
2078 /* does the skb contain enough to deliver on the alleged length? */
2079 if (unlikely(skb->len < ieee80211_get_radiotap_len(skb->data)))
2080 return false; /* skb too short for claimed rt header extent */
2085 bool ieee80211_parse_tx_radiotap(struct sk_buff *skb,
2086 struct net_device *dev)
2088 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2089 struct ieee80211_radiotap_iterator iterator;
2090 struct ieee80211_radiotap_header *rthdr =
2091 (struct ieee80211_radiotap_header *) skb->data;
2092 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2093 int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len,
2097 bool rate_found = false;
2098 u8 rate_retries = 0;
2100 u8 mcs_known, mcs_flags, mcs_bw;
2102 u8 vht_mcs = 0, vht_nss = 0;
2105 if (!ieee80211_validate_radiotap_len(skb))
2108 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
2109 IEEE80211_TX_CTL_DONTFRAG;
2112 * for every radiotap entry that is present
2113 * (ieee80211_radiotap_iterator_next returns -ENOENT when no more
2114 * entries present, or -EINVAL on error)
2118 ret = ieee80211_radiotap_iterator_next(&iterator);
2123 /* see if this argument is something we can use */
2124 switch (iterator.this_arg_index) {
2126 * You must take care when dereferencing iterator.this_arg
2127 * for multibyte types... the pointer is not aligned. Use
2128 * get_unaligned((type *)iterator.this_arg) to dereference
2129 * iterator.this_arg for type "type" safely on all arches.
2131 case IEEE80211_RADIOTAP_FLAGS:
2132 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) {
2134 * this indicates that the skb we have been
2135 * handed has the 32-bit FCS CRC at the end...
2136 * we should react to that by snipping it off
2137 * because it will be recomputed and added
2140 if (skb->len < (iterator._max_length + FCS_LEN))
2143 skb_trim(skb, skb->len - FCS_LEN);
2145 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_WEP)
2146 info->flags &= ~IEEE80211_TX_INTFL_DONT_ENCRYPT;
2147 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG)
2148 info->flags &= ~IEEE80211_TX_CTL_DONTFRAG;
2151 case IEEE80211_RADIOTAP_TX_FLAGS:
2152 txflags = get_unaligned_le16(iterator.this_arg);
2153 if (txflags & IEEE80211_RADIOTAP_F_TX_NOACK)
2154 info->flags |= IEEE80211_TX_CTL_NO_ACK;
2155 if (txflags & IEEE80211_RADIOTAP_F_TX_NOSEQNO)
2156 info->control.flags |= IEEE80211_TX_CTRL_NO_SEQNO;
2157 if (txflags & IEEE80211_RADIOTAP_F_TX_ORDER)
2158 info->control.flags |=
2159 IEEE80211_TX_CTRL_DONT_REORDER;
2162 case IEEE80211_RADIOTAP_RATE:
2163 rate = *iterator.this_arg;
2168 case IEEE80211_RADIOTAP_ANTENNA:
2169 /* this can appear multiple times, keep a bitmap */
2170 info->control.antennas |= BIT(*iterator.this_arg);
2173 case IEEE80211_RADIOTAP_DATA_RETRIES:
2174 rate_retries = *iterator.this_arg;
2177 case IEEE80211_RADIOTAP_MCS:
2178 mcs_known = iterator.this_arg[0];
2179 mcs_flags = iterator.this_arg[1];
2180 if (!(mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_MCS))
2184 rate = iterator.this_arg[2];
2185 rate_flags = IEEE80211_TX_RC_MCS;
2187 if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_GI &&
2188 mcs_flags & IEEE80211_RADIOTAP_MCS_SGI)
2189 rate_flags |= IEEE80211_TX_RC_SHORT_GI;
2191 mcs_bw = mcs_flags & IEEE80211_RADIOTAP_MCS_BW_MASK;
2192 if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_BW &&
2193 mcs_bw == IEEE80211_RADIOTAP_MCS_BW_40)
2194 rate_flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
2196 if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_FEC &&
2197 mcs_flags & IEEE80211_RADIOTAP_MCS_FEC_LDPC)
2198 info->flags |= IEEE80211_TX_CTL_LDPC;
2200 if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_STBC) {
2201 u8 stbc = u8_get_bits(mcs_flags,
2202 IEEE80211_RADIOTAP_MCS_STBC_MASK);
2205 u32_encode_bits(stbc,
2206 IEEE80211_TX_CTL_STBC);
2210 case IEEE80211_RADIOTAP_VHT:
2211 vht_known = get_unaligned_le16(iterator.this_arg);
2214 rate_flags = IEEE80211_TX_RC_VHT_MCS;
2215 if ((vht_known & IEEE80211_RADIOTAP_VHT_KNOWN_GI) &&
2216 (iterator.this_arg[2] &
2217 IEEE80211_RADIOTAP_VHT_FLAG_SGI))
2218 rate_flags |= IEEE80211_TX_RC_SHORT_GI;
2220 IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH) {
2221 if (iterator.this_arg[3] == 1)
2223 IEEE80211_TX_RC_40_MHZ_WIDTH;
2224 else if (iterator.this_arg[3] == 4)
2226 IEEE80211_TX_RC_80_MHZ_WIDTH;
2227 else if (iterator.this_arg[3] == 11)
2229 IEEE80211_TX_RC_160_MHZ_WIDTH;
2232 vht_mcs = iterator.this_arg[4] >> 4;
2235 vht_nss = iterator.this_arg[4] & 0xF;
2236 if (!vht_nss || vht_nss > 8)
2241 * Please update the file
2242 * Documentation/networking/mac80211-injection.rst
2243 * when parsing new fields here.
2251 if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */
2255 struct ieee80211_supported_band *sband =
2256 local->hw.wiphy->bands[info->band];
2258 info->control.flags |= IEEE80211_TX_CTRL_RATE_INJECT;
2260 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
2261 info->control.rates[i].idx = -1;
2262 info->control.rates[i].flags = 0;
2263 info->control.rates[i].count = 0;
2266 if (rate_flags & IEEE80211_TX_RC_MCS) {
2267 /* reset antennas if not enough */
2268 if (IEEE80211_HT_MCS_CHAINS(rate) >
2269 hweight8(info->control.antennas))
2270 info->control.antennas = 0;
2272 info->control.rates[0].idx = rate;
2273 } else if (rate_flags & IEEE80211_TX_RC_VHT_MCS) {
2274 /* reset antennas if not enough */
2275 if (vht_nss > hweight8(info->control.antennas))
2276 info->control.antennas = 0;
2278 ieee80211_rate_set_vht(info->control.rates, vht_mcs,
2281 for (i = 0; i < sband->n_bitrates; i++) {
2282 if (rate * 5 != sband->bitrates[i].bitrate)
2285 info->control.rates[0].idx = i;
2290 if (info->control.rates[0].idx < 0)
2291 info->control.flags &= ~IEEE80211_TX_CTRL_RATE_INJECT;
2293 info->control.rates[0].flags = rate_flags;
2294 info->control.rates[0].count = min_t(u8, rate_retries + 1,
2295 local->hw.max_rate_tries);
2301 netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
2302 struct net_device *dev)
2304 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2305 struct ieee80211_chanctx_conf *chanctx_conf;
2306 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2307 struct ieee80211_hdr *hdr;
2308 struct ieee80211_sub_if_data *tmp_sdata, *sdata;
2309 struct cfg80211_chan_def *chandef;
2313 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2314 if (unlikely(!ieee80211_sdata_running(sdata)))
2317 memset(info, 0, sizeof(*info));
2318 info->flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2319 IEEE80211_TX_CTL_INJECTED;
2321 /* Sanity-check the length of the radiotap header */
2322 if (!ieee80211_validate_radiotap_len(skb))
2325 /* we now know there is a radiotap header with a length we can use */
2326 len_rthdr = ieee80211_get_radiotap_len(skb->data);
2329 * fix up the pointers accounting for the radiotap
2330 * header still being in there. We are being given
2331 * a precooked IEEE80211 header so no need for
2334 skb_set_mac_header(skb, len_rthdr);
2336 * these are just fixed to the end of the rt area since we
2337 * don't have any better information and at this point, nobody cares
2339 skb_set_network_header(skb, len_rthdr);
2340 skb_set_transport_header(skb, len_rthdr);
2342 if (skb->len < len_rthdr + 2)
2345 hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
2346 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2348 if (skb->len < len_rthdr + hdrlen)
2352 * Initialize skb->protocol if the injected frame is a data frame
2353 * carrying a rfc1042 header
2355 if (ieee80211_is_data(hdr->frame_control) &&
2356 skb->len >= len_rthdr + hdrlen + sizeof(rfc1042_header) + 2) {
2357 u8 *payload = (u8 *)hdr + hdrlen;
2359 if (ether_addr_equal(payload, rfc1042_header))
2360 skb->protocol = cpu_to_be16((payload[6] << 8) |
2367 * We process outgoing injected frames that have a local address
2368 * we handle as though they are non-injected frames.
2369 * This code here isn't entirely correct, the local MAC address
2370 * isn't always enough to find the interface to use; for proper
2371 * VLAN support we have an nl80211-based mechanism.
2373 * This is necessary, for example, for old hostapd versions that
2374 * don't use nl80211-based management TX/RX.
2376 list_for_each_entry_rcu(tmp_sdata, &local->interfaces, list) {
2377 if (!ieee80211_sdata_running(tmp_sdata))
2379 if (tmp_sdata->vif.type == NL80211_IFTYPE_MONITOR ||
2380 tmp_sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
2382 if (ether_addr_equal(tmp_sdata->vif.addr, hdr->addr2)) {
2388 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
2389 if (!chanctx_conf) {
2390 tmp_sdata = rcu_dereference(local->monitor_sdata);
2393 rcu_dereference(tmp_sdata->vif.bss_conf.chanctx_conf);
2397 chandef = &chanctx_conf->def;
2402 * If driver/HW supports IEEE80211_CHAN_CAN_MONITOR we still
2403 * shouldn't transmit on disabled channels.
2405 if (!cfg80211_chandef_usable(local->hw.wiphy, chandef,
2406 IEEE80211_CHAN_DISABLED))
2410 * Frame injection is not allowed if beaconing is not allowed
2411 * or if we need radar detection. Beaconing is usually not allowed when
2412 * the mode or operation (Adhoc, AP, Mesh) does not support DFS.
2413 * Passive scan is also used in world regulatory domains where
2414 * your country is not known and as such it should be treated as
2415 * NO TX unless the channel is explicitly allowed in which case
2416 * your current regulatory domain would not have the passive scan
2419 * Since AP mode uses monitor interfaces to inject/TX management
2420 * frames we can make AP mode the exception to this rule once it
2421 * supports radar detection as its implementation can deal with
2422 * radar detection by itself. We can do that later by adding a
2423 * monitor flag interfaces used for AP support.
2425 if (!cfg80211_reg_can_beacon(local->hw.wiphy, chandef,
2429 info->band = chandef->chan->band;
2431 /* Initialize skb->priority according to frame type and TID class,
2432 * with respect to the sub interface that the frame will actually
2433 * be transmitted on. If the DONT_REORDER flag is set, the original
2434 * skb-priority is preserved to assure frames injected with this
2435 * flag are not reordered relative to each other.
2437 ieee80211_select_queue_80211(sdata, skb, hdr);
2438 skb_set_queue_mapping(skb, ieee80211_ac_from_tid(skb->priority));
2441 * Process the radiotap header. This will now take into account the
2442 * selected chandef above to accurately set injection rates and
2445 if (!ieee80211_parse_tx_radiotap(skb, dev))
2448 /* remove the injection radiotap header */
2449 skb_pull(skb, len_rthdr);
2451 ieee80211_xmit(sdata, NULL, skb);
2454 return NETDEV_TX_OK;
2460 return NETDEV_TX_OK; /* meaning, we dealt with the skb */
2463 static inline bool ieee80211_is_tdls_setup(struct sk_buff *skb)
2465 u16 ethertype = (skb->data[12] << 8) | skb->data[13];
2467 return ethertype == ETH_P_TDLS &&
2469 skb->data[14] == WLAN_TDLS_SNAP_RFTYPE;
2472 int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata,
2473 struct sk_buff *skb,
2474 struct sta_info **sta_out)
2476 struct sta_info *sta;
2478 switch (sdata->vif.type) {
2479 case NL80211_IFTYPE_AP_VLAN:
2480 sta = rcu_dereference(sdata->u.vlan.sta);
2484 } else if (sdata->wdev.use_4addr) {
2488 case NL80211_IFTYPE_AP:
2489 case NL80211_IFTYPE_OCB:
2490 case NL80211_IFTYPE_ADHOC:
2491 if (is_multicast_ether_addr(skb->data)) {
2492 *sta_out = ERR_PTR(-ENOENT);
2495 sta = sta_info_get_bss(sdata, skb->data);
2497 #ifdef CONFIG_MAC80211_MESH
2498 case NL80211_IFTYPE_MESH_POINT:
2499 /* determined much later */
2503 case NL80211_IFTYPE_STATION:
2504 if (sdata->wdev.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) {
2505 sta = sta_info_get(sdata, skb->data);
2506 if (sta && test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
2507 if (test_sta_flag(sta,
2508 WLAN_STA_TDLS_PEER_AUTH)) {
2514 * TDLS link during setup - throw out frames to
2515 * peer. Allow TDLS-setup frames to unauthorized
2516 * peers for the special case of a link teardown
2517 * after a TDLS sta is removed due to being
2520 if (!ieee80211_is_tdls_setup(skb))
2526 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
2534 *sta_out = sta ?: ERR_PTR(-ENOENT);
2538 static u16 ieee80211_store_ack_skb(struct ieee80211_local *local,
2539 struct sk_buff *skb,
2543 struct sk_buff *ack_skb;
2547 ack_skb = skb_clone_sk(skb);
2549 ack_skb = skb_clone(skb, GFP_ATOMIC);
2552 unsigned long flags;
2555 spin_lock_irqsave(&local->ack_status_lock, flags);
2556 id = idr_alloc(&local->ack_status_frames, ack_skb,
2557 1, 0x2000, GFP_ATOMIC);
2558 spin_unlock_irqrestore(&local->ack_status_lock, flags);
2562 *info_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
2564 *cookie = ieee80211_mgmt_tx_cookie(local);
2565 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
2576 * ieee80211_build_hdr - build 802.11 header in the given frame
2577 * @sdata: virtual interface to build the header for
2578 * @skb: the skb to build the header in
2579 * @info_flags: skb flags to set
2580 * @sta: the station pointer
2581 * @ctrl_flags: info control flags to set
2582 * @cookie: cookie pointer to fill (if not %NULL)
2584 * This function takes the skb with 802.3 header and reformats the header to
2585 * the appropriate IEEE 802.11 header based on which interface the packet is
2586 * being transmitted on.
2588 * Note that this function also takes care of the TX status request and
2589 * potential unsharing of the SKB - this needs to be interleaved with the
2592 * The function requires the read-side RCU lock held
2594 * Returns: the (possibly reallocated) skb or an ERR_PTR() code
2596 static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata,
2597 struct sk_buff *skb, u32 info_flags,
2598 struct sta_info *sta, u32 ctrl_flags,
2601 struct ieee80211_local *local = sdata->local;
2602 struct ieee80211_tx_info *info;
2604 u16 ethertype, hdrlen, meshhdrlen = 0;
2606 struct ieee80211_hdr hdr;
2607 struct ieee80211s_hdr mesh_hdr __maybe_unused;
2608 struct mesh_path __maybe_unused *mppath = NULL, *mpath = NULL;
2609 const u8 *encaps_data;
2610 int encaps_len, skip_header_bytes;
2611 bool wme_sta = false, authorized = false;
2615 struct ieee80211_chanctx_conf *chanctx_conf = NULL;
2616 enum nl80211_band band;
2618 u8 link_id = u32_get_bits(ctrl_flags, IEEE80211_TX_CTRL_MLO_LINK);
2623 #ifdef CONFIG_MAC80211_DEBUGFS
2624 if (local->force_tx_status)
2625 info_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
2628 /* convert Ethernet header to proper 802.11 header (based on
2629 * operation mode) */
2630 ethertype = (skb->data[12] << 8) | skb->data[13];
2631 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
2633 if (!ieee80211_vif_is_mld(&sdata->vif))
2635 rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
2637 switch (sdata->vif.type) {
2638 case NL80211_IFTYPE_AP_VLAN:
2639 if (sdata->wdev.use_4addr) {
2640 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
2642 memcpy(hdr.addr1, sta->sta.addr, ETH_ALEN);
2643 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
2644 memcpy(hdr.addr3, skb->data, ETH_ALEN);
2645 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
2647 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
2648 wme_sta = sta->sta.wme;
2650 if (!ieee80211_vif_is_mld(&sdata->vif)) {
2651 struct ieee80211_sub_if_data *ap_sdata;
2653 /* override chanctx_conf from AP (we don't have one) */
2654 ap_sdata = container_of(sdata->bss,
2655 struct ieee80211_sub_if_data,
2658 rcu_dereference(ap_sdata->vif.bss_conf.chanctx_conf);
2660 if (sdata->wdev.use_4addr)
2663 case NL80211_IFTYPE_AP:
2664 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
2666 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2668 if (ieee80211_vif_is_mld(&sdata->vif) && sta && !sta->sta.mlo) {
2669 struct ieee80211_link_data *link;
2671 link_id = sta->deflink.link_id;
2672 link = rcu_dereference(sdata->link[link_id]);
2673 if (WARN_ON(!link)) {
2677 memcpy(hdr.addr2, link->conf->addr, ETH_ALEN);
2678 } else if (link_id == IEEE80211_LINK_UNSPECIFIED ||
2679 (sta && sta->sta.mlo)) {
2680 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
2682 struct ieee80211_bss_conf *conf;
2684 conf = rcu_dereference(sdata->vif.link_conf[link_id]);
2685 if (unlikely(!conf)) {
2690 memcpy(hdr.addr2, conf->addr, ETH_ALEN);
2693 memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
2696 #ifdef CONFIG_MAC80211_MESH
2697 case NL80211_IFTYPE_MESH_POINT:
2698 if (!is_multicast_ether_addr(skb->data)) {
2699 struct sta_info *next_hop;
2700 bool mpp_lookup = true;
2702 mpath = mesh_path_lookup(sdata, skb->data);
2705 next_hop = rcu_dereference(mpath->next_hop);
2707 !(mpath->flags & (MESH_PATH_ACTIVE |
2708 MESH_PATH_RESOLVING)))
2713 mppath = mpp_path_lookup(sdata, skb->data);
2715 mppath->exp_time = jiffies;
2718 if (mppath && mpath)
2719 mesh_path_del(sdata, mpath->dst);
2723 * Use address extension if it is a packet from
2724 * another interface or if we know the destination
2725 * is being proxied by a portal (i.e. portal address
2726 * differs from proxied address)
2728 if (ether_addr_equal(sdata->vif.addr, skb->data + ETH_ALEN) &&
2729 !(mppath && !ether_addr_equal(mppath->mpp, skb->data))) {
2730 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
2731 skb->data, skb->data + ETH_ALEN);
2732 meshhdrlen = ieee80211_new_mesh_header(sdata, &mesh_hdr,
2735 /* DS -> MBSS (802.11-2012 13.11.3.3).
2736 * For unicast with unknown forwarding information,
2737 * destination might be in the MBSS or if that fails
2738 * forwarded to another mesh gate. In either case
2739 * resolution will be handled in ieee80211_xmit(), so
2740 * leave the original DA. This also works for mcast */
2741 const u8 *mesh_da = skb->data;
2744 mesh_da = mppath->mpp;
2746 mesh_da = mpath->dst;
2748 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
2749 mesh_da, sdata->vif.addr);
2750 if (is_multicast_ether_addr(mesh_da))
2751 /* DA TA mSA AE:SA */
2752 meshhdrlen = ieee80211_new_mesh_header(
2754 skb->data + ETH_ALEN, NULL);
2756 /* RA TA mDA mSA AE:DA SA */
2757 meshhdrlen = ieee80211_new_mesh_header(
2758 sdata, &mesh_hdr, skb->data,
2759 skb->data + ETH_ALEN);
2763 /* For injected frames, fill RA right away as nexthop lookup
2766 if ((ctrl_flags & IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP) &&
2767 is_zero_ether_addr(hdr.addr1))
2768 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2771 case NL80211_IFTYPE_STATION:
2772 /* we already did checks when looking up the RA STA */
2773 tdls_peer = test_sta_flag(sta, WLAN_STA_TDLS_PEER);
2776 /* For TDLS only one link can be valid with peer STA */
2777 int tdls_link_id = sta->sta.valid_links ?
2778 __ffs(sta->sta.valid_links) : 0;
2779 struct ieee80211_link_data *link;
2782 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2783 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2784 link = rcu_dereference(sdata->link[tdls_link_id]);
2785 if (WARN_ON_ONCE(!link)) {
2789 memcpy(hdr.addr3, link->u.mgd.bssid, ETH_ALEN);
2791 } else if (sdata->u.mgd.use_4addr &&
2792 cpu_to_be16(ethertype) != sdata->control_port_protocol) {
2793 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
2794 IEEE80211_FCTL_TODS);
2796 memcpy(hdr.addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN);
2797 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
2798 memcpy(hdr.addr3, skb->data, ETH_ALEN);
2799 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
2802 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
2804 memcpy(hdr.addr1, sdata->vif.cfg.ap_addr, ETH_ALEN);
2805 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2806 memcpy(hdr.addr3, skb->data, ETH_ALEN);
2810 case NL80211_IFTYPE_OCB:
2812 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2813 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2814 eth_broadcast_addr(hdr.addr3);
2817 case NL80211_IFTYPE_ADHOC:
2819 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2820 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2821 memcpy(hdr.addr3, sdata->u.ibss.bssid, ETH_ALEN);
2829 if (!chanctx_conf) {
2830 if (!ieee80211_vif_is_mld(&sdata->vif)) {
2834 /* MLD transmissions must not rely on the band */
2837 band = chanctx_conf->def.chan->band;
2840 multicast = is_multicast_ether_addr(hdr.addr1);
2842 /* sta is always NULL for mesh */
2844 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
2845 wme_sta = sta->sta.wme;
2846 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
2847 /* For mesh, the use of the QoS header is mandatory */
2851 /* receiver does QoS (which also means we do) use it */
2853 fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
2858 * Drop unicast frames to unauthorised stations unless they are
2859 * EAPOL frames from the local station.
2861 if (unlikely(!ieee80211_vif_is_mesh(&sdata->vif) &&
2862 (sdata->vif.type != NL80211_IFTYPE_OCB) &&
2863 !multicast && !authorized &&
2864 (cpu_to_be16(ethertype) != sdata->control_port_protocol ||
2865 !ieee80211_is_our_addr(sdata, skb->data + ETH_ALEN, NULL)))) {
2866 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2867 net_info_ratelimited("%s: dropped frame to %pM (unauthorized port)\n",
2868 sdata->name, hdr.addr1);
2871 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
2877 if (unlikely(!multicast &&
2879 skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS) ||
2880 ctrl_flags & IEEE80211_TX_CTL_REQ_TX_STATUS)))
2881 info_id = ieee80211_store_ack_skb(local, skb, &info_flags,
2885 * If the skb is shared we need to obtain our own copy.
2887 skb = skb_share_check(skb, GFP_ATOMIC);
2888 if (unlikely(!skb)) {
2893 hdr.frame_control = fc;
2894 hdr.duration_id = 0;
2897 skip_header_bytes = ETH_HLEN;
2898 if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
2899 encaps_data = bridge_tunnel_header;
2900 encaps_len = sizeof(bridge_tunnel_header);
2901 skip_header_bytes -= 2;
2902 } else if (ethertype >= ETH_P_802_3_MIN) {
2903 encaps_data = rfc1042_header;
2904 encaps_len = sizeof(rfc1042_header);
2905 skip_header_bytes -= 2;
2911 skb_pull(skb, skip_header_bytes);
2912 head_need = hdrlen + encaps_len + meshhdrlen - skb_headroom(skb);
2915 * So we need to modify the skb header and hence need a copy of
2916 * that. The head_need variable above doesn't, so far, include
2917 * the needed header space that we don't need right away. If we
2918 * can, then we don't reallocate right now but only after the
2919 * frame arrives at the master device (if it does...)
2921 * If we cannot, however, then we will reallocate to include all
2922 * the ever needed space. Also, if we need to reallocate it anyway,
2923 * make it big enough for everything we may ever need.
2926 if (head_need > 0 || skb_cloned(skb)) {
2927 head_need += IEEE80211_ENCRYPT_HEADROOM;
2928 head_need += local->tx_headroom;
2929 head_need = max_t(int, 0, head_need);
2930 if (ieee80211_skb_resize(sdata, skb, head_need, ENCRYPT_DATA)) {
2931 ieee80211_free_txskb(&local->hw, skb);
2933 return ERR_PTR(-ENOMEM);
2938 memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
2940 #ifdef CONFIG_MAC80211_MESH
2942 memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen);
2945 if (ieee80211_is_data_qos(fc)) {
2946 __le16 *qos_control;
2948 qos_control = skb_push(skb, 2);
2949 memcpy(skb_push(skb, hdrlen - 2), &hdr, hdrlen - 2);
2951 * Maybe we could actually set some fields here, for now just
2952 * initialise to zero to indicate no special operation.
2956 memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
2958 skb_reset_mac_header(skb);
2960 info = IEEE80211_SKB_CB(skb);
2961 memset(info, 0, sizeof(*info));
2963 info->flags = info_flags;
2965 info->status_data = info_id;
2966 info->status_data_idr = 1;
2970 if (likely(!cookie)) {
2971 ctrl_flags |= u32_encode_bits(link_id,
2972 IEEE80211_TX_CTRL_MLO_LINK);
2974 unsigned int pre_conf_link_id;
2977 * ctrl_flags already have been set by
2978 * ieee80211_tx_control_port(), here
2979 * we just sanity check that
2982 pre_conf_link_id = u32_get_bits(ctrl_flags,
2983 IEEE80211_TX_CTRL_MLO_LINK);
2985 if (pre_conf_link_id != link_id &&
2986 link_id != IEEE80211_LINK_UNSPECIFIED) {
2987 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2988 net_info_ratelimited("%s: dropped frame to %pM with bad link ID request (%d vs. %d)\n",
2989 sdata->name, hdr.addr1,
2990 pre_conf_link_id, link_id);
2997 info->control.flags = ctrl_flags;
3002 return ERR_PTR(ret);
3006 * fast-xmit overview
3008 * The core idea of this fast-xmit is to remove per-packet checks by checking
3009 * them out of band. ieee80211_check_fast_xmit() implements the out-of-band
3010 * checks that are needed to get the sta->fast_tx pointer assigned, after which
3011 * much less work can be done per packet. For example, fragmentation must be
3012 * disabled or the fast_tx pointer will not be set. All the conditions are seen
3015 * Once assigned, the fast_tx data structure also caches the per-packet 802.11
3016 * header and other data to aid packet processing in ieee80211_xmit_fast().
3018 * The most difficult part of this is that when any of these assumptions
3019 * change, an external trigger (i.e. a call to ieee80211_clear_fast_xmit(),
3020 * ieee80211_check_fast_xmit() or friends) is required to reset the data,
3021 * since the per-packet code no longer checks the conditions. This is reflected
3022 * by the calls to these functions throughout the rest of the code, and must be
3023 * maintained if any of the TX path checks change.
3026 void ieee80211_check_fast_xmit(struct sta_info *sta)
3028 struct ieee80211_fast_tx build = {}, *fast_tx = NULL, *old;
3029 struct ieee80211_local *local = sta->local;
3030 struct ieee80211_sub_if_data *sdata = sta->sdata;
3031 struct ieee80211_hdr *hdr = (void *)build.hdr;
3032 struct ieee80211_chanctx_conf *chanctx_conf;
3035 if (!ieee80211_hw_check(&local->hw, SUPPORT_FAST_XMIT))
3038 if (ieee80211_vif_is_mesh(&sdata->vif))
3039 mesh_fast_tx_flush_sta(sdata, sta);
3041 /* Locking here protects both the pointer itself, and against concurrent
3042 * invocations winning data access races to, e.g., the key pointer that
3044 * Without it, the invocation of this function right after the key
3045 * pointer changes wouldn't be sufficient, as another CPU could access
3046 * the pointer, then stall, and then do the cache update after the CPU
3047 * that invalidated the key.
3048 * With the locking, such scenarios cannot happen as the check for the
3049 * key and the fast-tx assignment are done atomically, so the CPU that
3050 * modifies the key will either wait or other one will see the key
3051 * cleared/changed already.
3053 spin_lock_bh(&sta->lock);
3054 if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
3055 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
3056 sdata->vif.type == NL80211_IFTYPE_STATION)
3059 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED) || !sta->uploaded)
3062 if (test_sta_flag(sta, WLAN_STA_PS_STA) ||
3063 test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
3064 test_sta_flag(sta, WLAN_STA_PS_DELIVER) ||
3065 test_sta_flag(sta, WLAN_STA_CLEAR_PS_FILT))
3068 if (sdata->noack_map)
3071 /* fast-xmit doesn't handle fragmentation at all */
3072 if (local->hw.wiphy->frag_threshold != (u32)-1 &&
3073 !ieee80211_hw_check(&local->hw, SUPPORTS_TX_FRAG))
3076 if (!ieee80211_vif_is_mld(&sdata->vif)) {
3079 rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
3080 if (!chanctx_conf) {
3084 build.band = chanctx_conf->def.chan->band;
3087 /* MLD transmissions must not rely on the band */
3091 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
3093 switch (sdata->vif.type) {
3094 case NL80211_IFTYPE_ADHOC:
3096 build.da_offs = offsetof(struct ieee80211_hdr, addr1);
3097 build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3098 memcpy(hdr->addr3, sdata->u.ibss.bssid, ETH_ALEN);
3101 case NL80211_IFTYPE_STATION:
3102 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
3103 /* For TDLS only one link can be valid with peer STA */
3104 int tdls_link_id = sta->sta.valid_links ?
3105 __ffs(sta->sta.valid_links) : 0;
3106 struct ieee80211_link_data *link;
3109 build.da_offs = offsetof(struct ieee80211_hdr, addr1);
3110 build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3112 link = rcu_dereference(sdata->link[tdls_link_id]);
3113 if (!WARN_ON_ONCE(!link))
3114 memcpy(hdr->addr3, link->u.mgd.bssid, ETH_ALEN);
3120 if (sdata->u.mgd.use_4addr) {
3121 /* non-regular ethertype cannot use the fastpath */
3122 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
3123 IEEE80211_FCTL_TODS);
3125 memcpy(hdr->addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN);
3126 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
3127 build.da_offs = offsetof(struct ieee80211_hdr, addr3);
3128 build.sa_offs = offsetof(struct ieee80211_hdr, addr4);
3132 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
3134 memcpy(hdr->addr1, sdata->vif.cfg.ap_addr, ETH_ALEN);
3135 build.da_offs = offsetof(struct ieee80211_hdr, addr3);
3136 build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3139 case NL80211_IFTYPE_AP_VLAN:
3140 if (sdata->wdev.use_4addr) {
3141 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
3142 IEEE80211_FCTL_TODS);
3144 memcpy(hdr->addr1, sta->sta.addr, ETH_ALEN);
3145 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
3146 build.da_offs = offsetof(struct ieee80211_hdr, addr3);
3147 build.sa_offs = offsetof(struct ieee80211_hdr, addr4);
3152 case NL80211_IFTYPE_AP:
3153 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
3155 build.da_offs = offsetof(struct ieee80211_hdr, addr1);
3156 if (sta->sta.mlo || !ieee80211_vif_is_mld(&sdata->vif)) {
3157 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
3159 unsigned int link_id = sta->deflink.link_id;
3160 struct ieee80211_link_data *link;
3163 link = rcu_dereference(sdata->link[link_id]);
3164 if (WARN_ON(!link)) {
3168 memcpy(hdr->addr2, link->conf->addr, ETH_ALEN);
3171 build.sa_offs = offsetof(struct ieee80211_hdr, addr3);
3175 /* not handled on fast-xmit */
3181 fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3184 /* We store the key here so there's no point in using rcu_dereference()
3185 * but that's fine because the code that changes the pointers will call
3186 * this function after doing so. For a single CPU that would be enough,
3187 * for multiple see the comment above.
3189 build.key = rcu_access_pointer(sta->ptk[sta->ptk_idx]);
3191 build.key = rcu_access_pointer(sdata->default_unicast_key);
3193 bool gen_iv, iv_spc, mmic;
3195 gen_iv = build.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV;
3196 iv_spc = build.key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3197 mmic = build.key->conf.flags &
3198 (IEEE80211_KEY_FLAG_GENERATE_MMIC |
3199 IEEE80211_KEY_FLAG_PUT_MIC_SPACE);
3201 /* don't handle software crypto */
3202 if (!(build.key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
3205 /* Key is being removed */
3206 if (build.key->flags & KEY_FLAG_TAINTED)
3209 switch (build.key->conf.cipher) {
3210 case WLAN_CIPHER_SUITE_CCMP:
3211 case WLAN_CIPHER_SUITE_CCMP_256:
3213 build.pn_offs = build.hdr_len;
3214 if (gen_iv || iv_spc)
3215 build.hdr_len += IEEE80211_CCMP_HDR_LEN;
3217 case WLAN_CIPHER_SUITE_GCMP:
3218 case WLAN_CIPHER_SUITE_GCMP_256:
3220 build.pn_offs = build.hdr_len;
3221 if (gen_iv || iv_spc)
3222 build.hdr_len += IEEE80211_GCMP_HDR_LEN;
3224 case WLAN_CIPHER_SUITE_TKIP:
3225 /* cannot handle MMIC or IV generation in xmit-fast */
3229 build.hdr_len += IEEE80211_TKIP_IV_LEN;
3231 case WLAN_CIPHER_SUITE_WEP40:
3232 case WLAN_CIPHER_SUITE_WEP104:
3233 /* cannot handle IV generation in fast-xmit */
3237 build.hdr_len += IEEE80211_WEP_IV_LEN;
3239 case WLAN_CIPHER_SUITE_AES_CMAC:
3240 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
3241 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3242 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3244 "management cipher suite 0x%x enabled for data\n",
3245 build.key->conf.cipher);
3248 /* we don't know how to generate IVs for this at all */
3249 if (WARN_ON(gen_iv))
3253 fc |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
3256 hdr->frame_control = fc;
3258 memcpy(build.hdr + build.hdr_len,
3259 rfc1042_header, sizeof(rfc1042_header));
3260 build.hdr_len += sizeof(rfc1042_header);
3262 fast_tx = kmemdup(&build, sizeof(build), GFP_ATOMIC);
3263 /* if the kmemdup fails, continue w/o fast_tx */
3266 /* we might have raced against another call to this function */
3267 old = rcu_dereference_protected(sta->fast_tx,
3268 lockdep_is_held(&sta->lock));
3269 rcu_assign_pointer(sta->fast_tx, fast_tx);
3271 kfree_rcu(old, rcu_head);
3272 spin_unlock_bh(&sta->lock);
3275 void ieee80211_check_fast_xmit_all(struct ieee80211_local *local)
3277 struct sta_info *sta;
3280 list_for_each_entry_rcu(sta, &local->sta_list, list)
3281 ieee80211_check_fast_xmit(sta);
3285 void ieee80211_check_fast_xmit_iface(struct ieee80211_sub_if_data *sdata)
3287 struct ieee80211_local *local = sdata->local;
3288 struct sta_info *sta;
3292 list_for_each_entry_rcu(sta, &local->sta_list, list) {
3293 if (sdata != sta->sdata &&
3294 (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
3296 ieee80211_check_fast_xmit(sta);
3302 void ieee80211_clear_fast_xmit(struct sta_info *sta)
3304 struct ieee80211_fast_tx *fast_tx;
3306 spin_lock_bh(&sta->lock);
3307 fast_tx = rcu_dereference_protected(sta->fast_tx,
3308 lockdep_is_held(&sta->lock));
3309 RCU_INIT_POINTER(sta->fast_tx, NULL);
3310 spin_unlock_bh(&sta->lock);
3313 kfree_rcu(fast_tx, rcu_head);
3316 static bool ieee80211_amsdu_realloc_pad(struct ieee80211_local *local,
3317 struct sk_buff *skb, int headroom)
3319 if (skb_headroom(skb) < headroom) {
3320 I802_DEBUG_INC(local->tx_expand_skb_head);
3322 if (pskb_expand_head(skb, headroom, 0, GFP_ATOMIC)) {
3323 wiphy_debug(local->hw.wiphy,
3324 "failed to reallocate TX buffer\n");
3332 static bool ieee80211_amsdu_prepare_head(struct ieee80211_sub_if_data *sdata,
3333 struct ieee80211_fast_tx *fast_tx,
3334 struct sk_buff *skb)
3336 struct ieee80211_local *local = sdata->local;
3337 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3338 struct ieee80211_hdr *hdr;
3339 struct ethhdr *amsdu_hdr;
3340 int hdr_len = fast_tx->hdr_len - sizeof(rfc1042_header);
3341 int subframe_len = skb->len - hdr_len;
3343 u8 *qc, *h_80211_src, *h_80211_dst;
3346 if (info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE)
3349 if (info->control.flags & IEEE80211_TX_CTRL_AMSDU)
3352 if (!ieee80211_amsdu_realloc_pad(local, skb,
3353 sizeof(*amsdu_hdr) +
3354 local->hw.extra_tx_headroom))
3357 data = skb_push(skb, sizeof(*amsdu_hdr));
3358 memmove(data, data + sizeof(*amsdu_hdr), hdr_len);
3360 amsdu_hdr = data + hdr_len;
3361 /* h_80211_src/dst is addr* field within hdr */
3362 h_80211_src = data + fast_tx->sa_offs;
3363 h_80211_dst = data + fast_tx->da_offs;
3365 amsdu_hdr->h_proto = cpu_to_be16(subframe_len);
3366 ether_addr_copy(amsdu_hdr->h_source, h_80211_src);
3367 ether_addr_copy(amsdu_hdr->h_dest, h_80211_dst);
3369 /* according to IEEE 802.11-2012 8.3.2 table 8-19, the outer SA/DA
3370 * fields needs to be changed to BSSID for A-MSDU frames depending
3371 * on FromDS/ToDS values.
3373 switch (sdata->vif.type) {
3374 case NL80211_IFTYPE_STATION:
3375 bssid = sdata->vif.cfg.ap_addr;
3377 case NL80211_IFTYPE_AP:
3378 case NL80211_IFTYPE_AP_VLAN:
3379 bssid = sdata->vif.addr;
3385 if (bssid && ieee80211_has_fromds(hdr->frame_control))
3386 ether_addr_copy(h_80211_src, bssid);
3388 if (bssid && ieee80211_has_tods(hdr->frame_control))
3389 ether_addr_copy(h_80211_dst, bssid);
3391 qc = ieee80211_get_qos_ctl(hdr);
3392 *qc |= IEEE80211_QOS_CTL_A_MSDU_PRESENT;
3394 info->control.flags |= IEEE80211_TX_CTRL_AMSDU;
3399 static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,
3400 struct sta_info *sta,
3401 struct ieee80211_fast_tx *fast_tx,
3402 struct sk_buff *skb,
3403 const u8 *da, const u8 *sa)
3405 struct ieee80211_local *local = sdata->local;
3406 struct fq *fq = &local->fq;
3408 struct fq_flow *flow;
3409 u8 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
3410 struct ieee80211_txq *txq = sta->sta.txq[tid];
3411 struct txq_info *txqi;
3412 struct sk_buff **frag_tail, *head;
3413 int subframe_len = skb->len - ETH_ALEN;
3414 u8 max_subframes = sta->sta.max_amsdu_subframes;
3415 int max_frags = local->hw.max_tx_fragments;
3416 int max_amsdu_len = sta->sta.cur->max_amsdu_len;
3422 unsigned int orig_len;
3423 int n = 2, nfrags, pad = 0;
3426 if (!ieee80211_hw_check(&local->hw, TX_AMSDU))
3429 if (sdata->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED)
3432 if (ieee80211_vif_is_mesh(&sdata->vif))
3435 if (skb_is_gso(skb))
3441 txqi = to_txq_info(txq);
3442 if (test_bit(IEEE80211_TXQ_NO_AMSDU, &txqi->flags))
3445 if (sta->sta.cur->max_rc_amsdu_len)
3446 max_amsdu_len = min_t(int, max_amsdu_len,
3447 sta->sta.cur->max_rc_amsdu_len);
3449 if (sta->sta.cur->max_tid_amsdu_len[tid])
3450 max_amsdu_len = min_t(int, max_amsdu_len,
3451 sta->sta.cur->max_tid_amsdu_len[tid]);
3453 flow_idx = fq_flow_idx(fq, skb);
3455 spin_lock_bh(&fq->lock);
3457 /* TODO: Ideally aggregation should be done on dequeue to remain
3458 * responsive to environment changes.
3462 flow = fq_flow_classify(fq, tin, flow_idx, skb);
3463 head = skb_peek_tail(&flow->queue);
3464 if (!head || skb_is_gso(head))
3467 orig_truesize = head->truesize;
3468 orig_len = head->len;
3470 if (skb->len + head->len > max_amsdu_len)
3473 nfrags = 1 + skb_shinfo(skb)->nr_frags;
3474 nfrags += 1 + skb_shinfo(head)->nr_frags;
3475 frag_tail = &skb_shinfo(head)->frag_list;
3476 while (*frag_tail) {
3477 nfrags += 1 + skb_shinfo(*frag_tail)->nr_frags;
3478 frag_tail = &(*frag_tail)->next;
3482 if (max_subframes && n > max_subframes)
3485 if (max_frags && nfrags > max_frags)
3488 if (!drv_can_aggregate_in_amsdu(local, head, skb))
3491 if (!ieee80211_amsdu_prepare_head(sdata, fast_tx, head))
3494 /* If n == 2, the "while (*frag_tail)" loop above didn't execute
3495 * and frag_tail should be &skb_shinfo(head)->frag_list.
3496 * However, ieee80211_amsdu_prepare_head() can reallocate it.
3497 * Reload frag_tail to have it pointing to the correct place.
3500 frag_tail = &skb_shinfo(head)->frag_list;
3503 * Pad out the previous subframe to a multiple of 4 by adding the
3504 * padding to the next one, that's being added. Note that head->len
3505 * is the length of the full A-MSDU, but that works since each time
3506 * we add a new subframe we pad out the previous one to a multiple
3507 * of 4 and thus it no longer matters in the next round.
3509 hdrlen = fast_tx->hdr_len - sizeof(rfc1042_header);
3510 if ((head->len - hdrlen) & 3)
3511 pad = 4 - ((head->len - hdrlen) & 3);
3513 if (!ieee80211_amsdu_realloc_pad(local, skb, sizeof(rfc1042_header) +
3518 data = skb_push(skb, ETH_ALEN + 2);
3519 ether_addr_copy(data, da);
3520 ether_addr_copy(data + ETH_ALEN, sa);
3522 data += 2 * ETH_ALEN;
3523 len = cpu_to_be16(subframe_len);
3524 memcpy(data, &len, 2);
3525 memcpy(data + 2, rfc1042_header, sizeof(rfc1042_header));
3527 memset(skb_push(skb, pad), 0, pad);
3529 head->len += skb->len;
3530 head->data_len += skb->len;
3534 fq->memory_usage += head->truesize - orig_truesize;
3535 if (head->len != orig_len) {
3536 flow->backlog += head->len - orig_len;
3537 tin->backlog_bytes += head->len - orig_len;
3540 spin_unlock_bh(&fq->lock);
3546 * Can be called while the sta lock is held. Anything that can cause packets to
3547 * be generated will cause deadlock!
3549 static ieee80211_tx_result
3550 ieee80211_xmit_fast_finish(struct ieee80211_sub_if_data *sdata,
3551 struct sta_info *sta, u8 pn_offs,
3552 struct ieee80211_key *key,
3553 struct ieee80211_tx_data *tx)
3555 struct sk_buff *skb = tx->skb;
3556 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3557 struct ieee80211_hdr *hdr = (void *)skb->data;
3558 u8 tid = IEEE80211_NUM_TIDS;
3560 if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL) &&
3561 ieee80211_tx_h_rate_ctrl(tx) != TX_CONTINUE)
3565 info->control.hw_key = &key->conf;
3567 dev_sw_netstats_tx_add(skb->dev, 1, skb->len);
3569 if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
3570 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
3571 hdr->seq_ctrl = ieee80211_tx_next_seq(sta, tid);
3573 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
3574 hdr->seq_ctrl = cpu_to_le16(sdata->sequence_number);
3575 sdata->sequence_number += 0x10;
3578 if (skb_shinfo(skb)->gso_size)
3579 sta->deflink.tx_stats.msdu[tid] +=
3580 DIV_ROUND_UP(skb->len, skb_shinfo(skb)->gso_size);
3582 sta->deflink.tx_stats.msdu[tid]++;
3584 info->hw_queue = sdata->vif.hw_queue[skb_get_queue_mapping(skb)];
3586 /* statistics normally done by ieee80211_tx_h_stats (but that
3587 * has to consider fragmentation, so is more complex)
3589 sta->deflink.tx_stats.bytes[skb_get_queue_mapping(skb)] += skb->len;
3590 sta->deflink.tx_stats.packets[skb_get_queue_mapping(skb)]++;
3594 u8 *crypto_hdr = skb->data + pn_offs;
3596 switch (key->conf.cipher) {
3597 case WLAN_CIPHER_SUITE_CCMP:
3598 case WLAN_CIPHER_SUITE_CCMP_256:
3599 case WLAN_CIPHER_SUITE_GCMP:
3600 case WLAN_CIPHER_SUITE_GCMP_256:
3601 pn = atomic64_inc_return(&key->conf.tx_pn);
3603 crypto_hdr[1] = pn >> 8;
3604 crypto_hdr[3] = 0x20 | (key->conf.keyidx << 6);
3605 crypto_hdr[4] = pn >> 16;
3606 crypto_hdr[5] = pn >> 24;
3607 crypto_hdr[6] = pn >> 32;
3608 crypto_hdr[7] = pn >> 40;
3616 static netdev_features_t
3617 ieee80211_sdata_netdev_features(struct ieee80211_sub_if_data *sdata)
3619 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
3620 return sdata->vif.netdev_features;
3625 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap);
3626 return sdata->vif.netdev_features;
3629 static struct sk_buff *
3630 ieee80211_tx_skb_fixup(struct sk_buff *skb, netdev_features_t features)
3632 if (skb_is_gso(skb)) {
3633 struct sk_buff *segs;
3635 segs = skb_gso_segment(skb, features);
3645 if (skb_needs_linearize(skb, features) && __skb_linearize(skb))
3648 if (skb->ip_summed == CHECKSUM_PARTIAL) {
3649 int ofs = skb_checksum_start_offset(skb);
3651 if (skb->encapsulation)
3652 skb_set_inner_transport_header(skb, ofs);
3654 skb_set_transport_header(skb, ofs);
3656 if (skb_csum_hwoffload_help(skb, features))
3660 skb_mark_not_on_list(skb);
3668 void __ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
3669 struct sta_info *sta,
3670 struct ieee80211_fast_tx *fast_tx,
3671 struct sk_buff *skb, bool ampdu,
3672 const u8 *da, const u8 *sa)
3674 struct ieee80211_local *local = sdata->local;
3675 struct ieee80211_hdr *hdr = (void *)fast_tx->hdr;
3676 struct ieee80211_tx_info *info;
3677 struct ieee80211_tx_data tx;
3678 ieee80211_tx_result r;
3679 int hw_headroom = sdata->local->hw.extra_tx_headroom;
3680 int extra_head = fast_tx->hdr_len - (ETH_HLEN - 2);
3682 skb = skb_share_check(skb, GFP_ATOMIC);
3686 if ((hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) &&
3687 ieee80211_amsdu_aggregate(sdata, sta, fast_tx, skb, da, sa))
3690 /* will not be crypto-handled beyond what we do here, so use false
3691 * as the may-encrypt argument for the resize to not account for
3692 * more room than we already have in 'extra_head'
3694 if (unlikely(ieee80211_skb_resize(sdata, skb,
3695 max_t(int, extra_head + hw_headroom -
3696 skb_headroom(skb), 0),
3700 hdr = skb_push(skb, extra_head);
3701 memcpy(skb->data, fast_tx->hdr, fast_tx->hdr_len);
3702 memcpy(skb->data + fast_tx->da_offs, da, ETH_ALEN);
3703 memcpy(skb->data + fast_tx->sa_offs, sa, ETH_ALEN);
3705 info = IEEE80211_SKB_CB(skb);
3706 memset(info, 0, sizeof(*info));
3707 info->band = fast_tx->band;
3708 info->control.vif = &sdata->vif;
3709 info->flags = IEEE80211_TX_CTL_FIRST_FRAGMENT |
3710 IEEE80211_TX_CTL_DONTFRAG;
3711 info->control.flags = IEEE80211_TX_CTRL_FAST_XMIT |
3712 u32_encode_bits(IEEE80211_LINK_UNSPECIFIED,
3713 IEEE80211_TX_CTRL_MLO_LINK);
3715 #ifdef CONFIG_MAC80211_DEBUGFS
3716 if (local->force_tx_status)
3717 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
3720 if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
3721 u8 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
3723 *ieee80211_get_qos_ctl(hdr) = tid;
3726 __skb_queue_head_init(&tx.skbs);
3728 tx.flags = IEEE80211_TX_UNICAST;
3732 tx.key = fast_tx->key;
3734 if (ieee80211_queue_skb(local, sdata, sta, skb))
3738 r = ieee80211_xmit_fast_finish(sdata, sta, fast_tx->pn_offs,
3744 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
3745 sdata = container_of(sdata->bss,
3746 struct ieee80211_sub_if_data, u.ap);
3748 __skb_queue_tail(&tx.skbs, skb);
3749 ieee80211_tx_frags(local, &sdata->vif, sta, &tx.skbs, false);
3756 static bool ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
3757 struct sta_info *sta,
3758 struct ieee80211_fast_tx *fast_tx,
3759 struct sk_buff *skb)
3761 u16 ethertype = (skb->data[12] << 8) | skb->data[13];
3762 struct ieee80211_hdr *hdr = (void *)fast_tx->hdr;
3763 struct tid_ampdu_tx *tid_tx = NULL;
3764 struct sk_buff *next;
3766 u8 tid = IEEE80211_NUM_TIDS;
3768 /* control port protocol needs a lot of special handling */
3769 if (cpu_to_be16(ethertype) == sdata->control_port_protocol)
3772 /* only RFC 1042 SNAP */
3773 if (ethertype < ETH_P_802_3_MIN)
3776 /* don't handle TX status request here either */
3777 if (skb->sk && skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS)
3780 if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
3781 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
3782 tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
3784 if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state))
3786 if (tid_tx->timeout)
3787 tid_tx->last_tx = jiffies;
3791 memcpy(ð, skb->data, ETH_HLEN - 2);
3793 /* after this point (skb is modified) we cannot return false */
3794 skb = ieee80211_tx_skb_fixup(skb, ieee80211_sdata_netdev_features(sdata));
3798 skb_list_walk_safe(skb, skb, next) {
3799 skb_mark_not_on_list(skb);
3800 __ieee80211_xmit_fast(sdata, sta, fast_tx, skb, tid_tx,
3801 eth.h_dest, eth.h_source);
3807 struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,
3808 struct ieee80211_txq *txq)
3810 struct ieee80211_local *local = hw_to_local(hw);
3811 struct txq_info *txqi = container_of(txq, struct txq_info, txq);
3812 struct ieee80211_hdr *hdr;
3813 struct sk_buff *skb = NULL;
3814 struct fq *fq = &local->fq;
3815 struct fq_tin *tin = &txqi->tin;
3816 struct ieee80211_tx_info *info;
3817 struct ieee80211_tx_data tx;
3818 ieee80211_tx_result r;
3819 struct ieee80211_vif *vif = txq->vif;
3820 int q = vif->hw_queue[txq->ac];
3821 unsigned long flags;
3824 WARN_ON_ONCE(softirq_count() == 0);
3826 if (!ieee80211_txq_airtime_check(hw, txq))
3830 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
3831 q_stopped = local->queue_stop_reasons[q];
3832 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
3834 if (unlikely(q_stopped)) {
3835 /* mark for waking later */
3836 set_bit(IEEE80211_TXQ_DIRTY, &txqi->flags);
3840 spin_lock_bh(&fq->lock);
3842 /* Make sure fragments stay together. */
3843 skb = __skb_dequeue(&txqi->frags);
3844 if (unlikely(skb)) {
3845 if (!(IEEE80211_SKB_CB(skb)->control.flags &
3846 IEEE80211_TX_INTCFL_NEED_TXPROCESSING))
3848 IEEE80211_SKB_CB(skb)->control.flags &=
3849 ~IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
3851 if (unlikely(test_bit(IEEE80211_TXQ_STOP, &txqi->flags)))
3854 skb = fq_tin_dequeue(fq, tin, fq_tin_dequeue_func);
3860 spin_unlock_bh(&fq->lock);
3862 hdr = (struct ieee80211_hdr *)skb->data;
3863 info = IEEE80211_SKB_CB(skb);
3865 memset(&tx, 0, sizeof(tx));
3866 __skb_queue_head_init(&tx.skbs);
3869 tx.sdata = vif_to_sdata(info->control.vif);
3872 tx.sta = container_of(txq->sta, struct sta_info, sta);
3874 * Drop unicast frames to unauthorised stations unless they are
3875 * injected frames or EAPOL frames from the local station.
3877 if (unlikely(!(info->flags & IEEE80211_TX_CTL_INJECTED) &&
3878 ieee80211_is_data(hdr->frame_control) &&
3879 !ieee80211_vif_is_mesh(&tx.sdata->vif) &&
3880 tx.sdata->vif.type != NL80211_IFTYPE_OCB &&
3881 !is_multicast_ether_addr(hdr->addr1) &&
3882 !test_sta_flag(tx.sta, WLAN_STA_AUTHORIZED) &&
3883 (!(info->control.flags &
3884 IEEE80211_TX_CTRL_PORT_CTRL_PROTO) ||
3885 !ieee80211_is_our_addr(tx.sdata, hdr->addr2,
3887 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
3888 ieee80211_free_txskb(&local->hw, skb);
3894 * The key can be removed while the packet was queued, so need to call
3895 * this here to get the current key.
3897 r = ieee80211_tx_h_select_key(&tx);
3898 if (r != TX_CONTINUE) {
3899 ieee80211_free_txskb(&local->hw, skb);
3903 if (test_bit(IEEE80211_TXQ_AMPDU, &txqi->flags))
3904 info->flags |= (IEEE80211_TX_CTL_AMPDU |
3905 IEEE80211_TX_CTL_DONTFRAG);
3907 if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) {
3908 if (!ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
3909 r = ieee80211_tx_h_rate_ctrl(&tx);
3910 if (r != TX_CONTINUE) {
3911 ieee80211_free_txskb(&local->hw, skb);
3918 if (info->control.flags & IEEE80211_TX_CTRL_FAST_XMIT) {
3919 struct sta_info *sta = container_of(txq->sta, struct sta_info,
3924 (tx.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
3925 pn_offs = ieee80211_hdrlen(hdr->frame_control);
3927 r = ieee80211_xmit_fast_finish(sta->sdata, sta, pn_offs,
3929 if (r != TX_CONTINUE) {
3930 ieee80211_free_txskb(&local->hw, skb);
3934 if (invoke_tx_handlers_late(&tx))
3937 skb = __skb_dequeue(&tx.skbs);
3938 info = IEEE80211_SKB_CB(skb);
3940 if (!skb_queue_empty(&tx.skbs)) {
3941 spin_lock_bh(&fq->lock);
3942 skb_queue_splice_tail(&tx.skbs, &txqi->frags);
3943 spin_unlock_bh(&fq->lock);
3947 if (skb_has_frag_list(skb) &&
3948 !ieee80211_hw_check(&local->hw, TX_FRAG_LIST)) {
3949 if (skb_linearize(skb)) {
3950 ieee80211_free_txskb(&local->hw, skb);
3955 switch (tx.sdata->vif.type) {
3956 case NL80211_IFTYPE_MONITOR:
3957 if (tx.sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) {
3958 vif = &tx.sdata->vif;
3961 tx.sdata = rcu_dereference(local->monitor_sdata);
3963 vif = &tx.sdata->vif;
3965 vif->hw_queue[skb_get_queue_mapping(skb)];
3966 } else if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) {
3967 ieee80211_free_txskb(&local->hw, skb);
3970 info->control.vif = NULL;
3974 case NL80211_IFTYPE_AP_VLAN:
3975 tx.sdata = container_of(tx.sdata->bss,
3976 struct ieee80211_sub_if_data, u.ap);
3979 vif = &tx.sdata->vif;
3984 info->control.vif = vif;
3987 wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL)) {
3988 bool ampdu = txq->ac != IEEE80211_AC_VO;
3991 airtime = ieee80211_calc_expected_tx_airtime(hw, vif, txq->sta,
3994 airtime = ieee80211_info_set_tx_time_est(info, airtime);
3995 ieee80211_sta_update_pending_airtime(local, tx.sta,
4005 spin_unlock_bh(&fq->lock);
4009 EXPORT_SYMBOL(ieee80211_tx_dequeue);
4011 static inline s32 ieee80211_sta_deficit(struct sta_info *sta, u8 ac)
4013 struct airtime_info *air_info = &sta->airtime[ac];
4015 return air_info->deficit - atomic_read(&air_info->aql_tx_pending);
4019 ieee80211_txq_set_active(struct txq_info *txqi)
4021 struct sta_info *sta;
4026 sta = container_of(txqi->txq.sta, struct sta_info, sta);
4027 sta->airtime[txqi->txq.ac].last_active = jiffies;
4031 ieee80211_txq_keep_active(struct txq_info *txqi)
4033 struct sta_info *sta;
4038 sta = container_of(txqi->txq.sta, struct sta_info, sta);
4039 if (ieee80211_sta_deficit(sta, txqi->txq.ac) >= 0)
4042 return ieee80211_sta_keep_active(sta, txqi->txq.ac);
4045 struct ieee80211_txq *ieee80211_next_txq(struct ieee80211_hw *hw, u8 ac)
4047 struct ieee80211_local *local = hw_to_local(hw);
4048 struct ieee80211_txq *ret = NULL;
4049 struct txq_info *txqi = NULL, *head = NULL;
4050 bool found_eligible_txq = false;
4052 spin_lock_bh(&local->active_txq_lock[ac]);
4054 if (!local->schedule_round[ac])
4058 txqi = list_first_entry_or_null(&local->active_txqs[ac],
4065 if (!found_eligible_txq)
4068 found_eligible_txq = false;
4074 if (txqi->txq.sta) {
4075 struct sta_info *sta = container_of(txqi->txq.sta,
4076 struct sta_info, sta);
4077 bool aql_check = ieee80211_txq_airtime_check(hw, &txqi->txq);
4078 s32 deficit = ieee80211_sta_deficit(sta, txqi->txq.ac);
4081 found_eligible_txq = true;
4084 sta->airtime[txqi->txq.ac].deficit +=
4085 sta->airtime_weight;
4087 if (deficit < 0 || !aql_check) {
4088 list_move_tail(&txqi->schedule_order,
4089 &local->active_txqs[txqi->txq.ac]);
4094 if (txqi->schedule_round == local->schedule_round[ac])
4097 list_del_init(&txqi->schedule_order);
4098 txqi->schedule_round = local->schedule_round[ac];
4102 spin_unlock_bh(&local->active_txq_lock[ac]);
4105 EXPORT_SYMBOL(ieee80211_next_txq);
4107 void __ieee80211_schedule_txq(struct ieee80211_hw *hw,
4108 struct ieee80211_txq *txq,
4111 struct ieee80211_local *local = hw_to_local(hw);
4112 struct txq_info *txqi = to_txq_info(txq);
4115 spin_lock_bh(&local->active_txq_lock[txq->ac]);
4117 has_queue = force || txq_has_queue(txq);
4118 if (list_empty(&txqi->schedule_order) &&
4119 (has_queue || ieee80211_txq_keep_active(txqi))) {
4120 /* If airtime accounting is active, always enqueue STAs at the
4121 * head of the list to ensure that they only get moved to the
4122 * back by the airtime DRR scheduler once they have a negative
4123 * deficit. A station that already has a negative deficit will
4124 * get immediately moved to the back of the list on the next
4125 * call to ieee80211_next_txq().
4127 if (txqi->txq.sta && local->airtime_flags && has_queue &&
4128 wiphy_ext_feature_isset(local->hw.wiphy,
4129 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
4130 list_add(&txqi->schedule_order,
4131 &local->active_txqs[txq->ac]);
4133 list_add_tail(&txqi->schedule_order,
4134 &local->active_txqs[txq->ac]);
4136 ieee80211_txq_set_active(txqi);
4139 spin_unlock_bh(&local->active_txq_lock[txq->ac]);
4141 EXPORT_SYMBOL(__ieee80211_schedule_txq);
4143 DEFINE_STATIC_KEY_FALSE(aql_disable);
4145 bool ieee80211_txq_airtime_check(struct ieee80211_hw *hw,
4146 struct ieee80211_txq *txq)
4148 struct sta_info *sta;
4149 struct ieee80211_local *local = hw_to_local(hw);
4151 if (!wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL))
4154 if (static_branch_unlikely(&aql_disable))
4160 if (unlikely(txq->tid == IEEE80211_NUM_TIDS))
4163 sta = container_of(txq->sta, struct sta_info, sta);
4164 if (atomic_read(&sta->airtime[txq->ac].aql_tx_pending) <
4165 sta->airtime[txq->ac].aql_limit_low)
4168 if (atomic_read(&local->aql_total_pending_airtime) <
4169 local->aql_threshold &&
4170 atomic_read(&sta->airtime[txq->ac].aql_tx_pending) <
4171 sta->airtime[txq->ac].aql_limit_high)
4176 EXPORT_SYMBOL(ieee80211_txq_airtime_check);
4179 ieee80211_txq_schedule_airtime_check(struct ieee80211_local *local, u8 ac)
4181 unsigned int num_txq = 0;
4182 struct txq_info *txq;
4185 if (!wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL))
4188 list_for_each_entry(txq, &local->active_txqs[ac], schedule_order)
4191 aql_limit = (num_txq - 1) * local->aql_txq_limit_low[ac] / 2 +
4192 local->aql_txq_limit_high[ac];
4194 return atomic_read(&local->aql_ac_pending_airtime[ac]) < aql_limit;
4197 bool ieee80211_txq_may_transmit(struct ieee80211_hw *hw,
4198 struct ieee80211_txq *txq)
4200 struct ieee80211_local *local = hw_to_local(hw);
4201 struct txq_info *iter, *tmp, *txqi = to_txq_info(txq);
4202 struct sta_info *sta;
4205 spin_lock_bh(&local->active_txq_lock[ac]);
4210 if (list_empty(&txqi->schedule_order))
4213 if (!ieee80211_txq_schedule_airtime_check(local, ac))
4216 list_for_each_entry_safe(iter, tmp, &local->active_txqs[ac],
4221 if (!iter->txq.sta) {
4222 list_move_tail(&iter->schedule_order,
4223 &local->active_txqs[ac]);
4226 sta = container_of(iter->txq.sta, struct sta_info, sta);
4227 if (ieee80211_sta_deficit(sta, ac) < 0)
4228 sta->airtime[ac].deficit += sta->airtime_weight;
4229 list_move_tail(&iter->schedule_order, &local->active_txqs[ac]);
4232 sta = container_of(txqi->txq.sta, struct sta_info, sta);
4233 if (sta->airtime[ac].deficit >= 0)
4236 sta->airtime[ac].deficit += sta->airtime_weight;
4237 list_move_tail(&txqi->schedule_order, &local->active_txqs[ac]);
4238 spin_unlock_bh(&local->active_txq_lock[ac]);
4242 if (!list_empty(&txqi->schedule_order))
4243 list_del_init(&txqi->schedule_order);
4244 spin_unlock_bh(&local->active_txq_lock[ac]);
4248 EXPORT_SYMBOL(ieee80211_txq_may_transmit);
4250 void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac)
4252 struct ieee80211_local *local = hw_to_local(hw);
4254 spin_lock_bh(&local->active_txq_lock[ac]);
4256 if (ieee80211_txq_schedule_airtime_check(local, ac)) {
4257 local->schedule_round[ac]++;
4258 if (!local->schedule_round[ac])
4259 local->schedule_round[ac]++;
4261 local->schedule_round[ac] = 0;
4264 spin_unlock_bh(&local->active_txq_lock[ac]);
4266 EXPORT_SYMBOL(ieee80211_txq_schedule_start);
4268 void __ieee80211_subif_start_xmit(struct sk_buff *skb,
4269 struct net_device *dev,
4274 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4275 struct ieee80211_local *local = sdata->local;
4276 struct sta_info *sta;
4277 struct sk_buff *next;
4280 if (unlikely(!ieee80211_sdata_running(sdata) || skb->len < ETH_HLEN)) {
4285 sk_pacing_shift_update(skb->sk, sdata->local->hw.tx_sk_pacing_shift);
4289 if (ieee80211_vif_is_mesh(&sdata->vif) &&
4290 ieee80211_hw_check(&local->hw, SUPPORT_FAST_XMIT) &&
4291 ieee80211_mesh_xmit_fast(sdata, skb, ctrl_flags))
4294 if (ieee80211_lookup_ra_sta(sdata, skb, &sta))
4300 skb_set_queue_mapping(skb, ieee80211_select_queue(sdata, sta, skb));
4301 ieee80211_aggr_check(sdata, sta, skb);
4304 struct ieee80211_fast_tx *fast_tx;
4306 fast_tx = rcu_dereference(sta->fast_tx);
4309 ieee80211_xmit_fast(sdata, sta, fast_tx, skb))
4313 /* the frame could be fragmented, software-encrypted, and other
4314 * things so we cannot really handle checksum or GSO offload.
4315 * fix it up in software before we handle anything else.
4317 skb = ieee80211_tx_skb_fixup(skb, 0);
4323 skb_list_walk_safe(skb, skb, next) {
4324 skb_mark_not_on_list(skb);
4326 if (skb->protocol == sdata->control_port_protocol)
4327 ctrl_flags |= IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP;
4329 skb = ieee80211_build_hdr(sdata, skb, info_flags,
4330 sta, ctrl_flags, cookie);
4332 kfree_skb_list(next);
4336 dev_sw_netstats_tx_add(dev, 1, skb->len);
4338 ieee80211_xmit(sdata, sta, skb);
4346 ieee80211_tpt_led_trig_tx(local, len);
4350 static int ieee80211_change_da(struct sk_buff *skb, struct sta_info *sta)
4355 err = skb_ensure_writable(skb, ETH_HLEN);
4359 eth = (void *)skb->data;
4360 ether_addr_copy(eth->h_dest, sta->sta.addr);
4365 static bool ieee80211_multicast_to_unicast(struct sk_buff *skb,
4366 struct net_device *dev)
4368 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4369 const struct ethhdr *eth = (void *)skb->data;
4370 const struct vlan_ethhdr *ethvlan = (void *)skb->data;
4373 switch (sdata->vif.type) {
4374 case NL80211_IFTYPE_AP_VLAN:
4375 if (sdata->u.vlan.sta)
4377 if (sdata->wdev.use_4addr)
4380 case NL80211_IFTYPE_AP:
4381 /* check runtime toggle for this bss */
4382 if (!sdata->bss->multicast_to_unicast)
4389 /* multicast to unicast conversion only for some payload */
4390 ethertype = eth->h_proto;
4391 if (ethertype == htons(ETH_P_8021Q) && skb->len >= VLAN_ETH_HLEN)
4392 ethertype = ethvlan->h_vlan_encapsulated_proto;
4393 switch (ethertype) {
4394 case htons(ETH_P_ARP):
4395 case htons(ETH_P_IP):
4396 case htons(ETH_P_IPV6):
4406 ieee80211_convert_to_unicast(struct sk_buff *skb, struct net_device *dev,
4407 struct sk_buff_head *queue)
4409 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4410 struct ieee80211_local *local = sdata->local;
4411 const struct ethhdr *eth = (struct ethhdr *)skb->data;
4412 struct sta_info *sta, *first = NULL;
4413 struct sk_buff *cloned_skb;
4417 list_for_each_entry_rcu(sta, &local->sta_list, list) {
4418 if (sdata != sta->sdata)
4419 /* AP-VLAN mismatch */
4421 if (unlikely(ether_addr_equal(eth->h_source, sta->sta.addr)))
4422 /* do not send back to source */
4428 cloned_skb = skb_clone(skb, GFP_ATOMIC);
4431 if (unlikely(ieee80211_change_da(cloned_skb, sta))) {
4432 dev_kfree_skb(cloned_skb);
4435 __skb_queue_tail(queue, cloned_skb);
4438 if (likely(first)) {
4439 if (unlikely(ieee80211_change_da(skb, first)))
4441 __skb_queue_tail(queue, skb);
4443 /* no STA connected, drop */
4450 __skb_queue_purge(queue);
4451 __skb_queue_tail(queue, skb);
4456 static void ieee80211_mlo_multicast_tx_one(struct ieee80211_sub_if_data *sdata,
4457 struct sk_buff *skb, u32 ctrl_flags,
4458 unsigned int link_id)
4460 struct sk_buff *out;
4462 out = skb_copy(skb, GFP_ATOMIC);
4466 ctrl_flags |= u32_encode_bits(link_id, IEEE80211_TX_CTRL_MLO_LINK);
4467 __ieee80211_subif_start_xmit(out, sdata->dev, 0, ctrl_flags, NULL);
4470 static void ieee80211_mlo_multicast_tx(struct net_device *dev,
4471 struct sk_buff *skb)
4473 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4474 unsigned long links = sdata->vif.active_links;
4476 u32 ctrl_flags = IEEE80211_TX_CTRL_MCAST_MLO_FIRST_TX;
4478 if (hweight16(links) == 1) {
4479 ctrl_flags |= u32_encode_bits(__ffs(links),
4480 IEEE80211_TX_CTRL_MLO_LINK);
4482 __ieee80211_subif_start_xmit(skb, sdata->dev, 0, ctrl_flags,
4487 for_each_set_bit(link, &links, IEEE80211_MLD_MAX_NUM_LINKS) {
4488 ieee80211_mlo_multicast_tx_one(sdata, skb, ctrl_flags, link);
4495 * ieee80211_subif_start_xmit - netif start_xmit function for 802.3 vifs
4496 * @skb: packet to be sent
4497 * @dev: incoming interface
4499 * On failure skb will be freed.
4501 * Returns: the netdev TX status (but really only %NETDEV_TX_OK)
4503 netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
4504 struct net_device *dev)
4506 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4507 const struct ethhdr *eth = (void *)skb->data;
4509 if (likely(!is_multicast_ether_addr(eth->h_dest)))
4512 if (unlikely(!ieee80211_sdata_running(sdata))) {
4514 return NETDEV_TX_OK;
4517 if (unlikely(ieee80211_multicast_to_unicast(skb, dev))) {
4518 struct sk_buff_head queue;
4520 __skb_queue_head_init(&queue);
4521 ieee80211_convert_to_unicast(skb, dev, &queue);
4522 while ((skb = __skb_dequeue(&queue)))
4523 __ieee80211_subif_start_xmit(skb, dev, 0,
4524 IEEE80211_TX_CTRL_MLO_LINK_UNSPEC,
4526 } else if (ieee80211_vif_is_mld(&sdata->vif) &&
4527 sdata->vif.type == NL80211_IFTYPE_AP &&
4528 !ieee80211_hw_check(&sdata->local->hw, MLO_MCAST_MULTI_LINK_TX)) {
4529 ieee80211_mlo_multicast_tx(dev, skb);
4532 __ieee80211_subif_start_xmit(skb, dev, 0,
4533 IEEE80211_TX_CTRL_MLO_LINK_UNSPEC,
4537 return NETDEV_TX_OK;
4542 static bool __ieee80211_tx_8023(struct ieee80211_sub_if_data *sdata,
4543 struct sk_buff *skb, struct sta_info *sta,
4546 struct ieee80211_local *local = sdata->local;
4547 struct ieee80211_tx_control control = {};
4548 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4549 struct ieee80211_sta *pubsta = NULL;
4550 unsigned long flags;
4551 int q = info->hw_queue;
4553 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
4555 if (local->queue_stop_reasons[q] ||
4556 (!txpending && !skb_queue_empty(&local->pending[q]))) {
4558 skb_queue_head(&local->pending[q], skb);
4560 skb_queue_tail(&local->pending[q], skb);
4562 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
4567 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
4569 if (sta && sta->uploaded)
4572 control.sta = pubsta;
4574 drv_tx(local, &control, skb);
4579 static bool ieee80211_tx_8023(struct ieee80211_sub_if_data *sdata,
4580 struct sk_buff *skb, struct sta_info *sta,
4583 struct ieee80211_local *local = sdata->local;
4584 struct sk_buff *next;
4587 if (ieee80211_queue_skb(local, sdata, sta, skb))
4590 skb_list_walk_safe(skb, skb, next) {
4591 skb_mark_not_on_list(skb);
4592 if (!__ieee80211_tx_8023(sdata, skb, sta, txpending))
4599 static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata,
4600 struct net_device *dev, struct sta_info *sta,
4601 struct ieee80211_key *key, struct sk_buff *skb)
4603 struct ieee80211_tx_info *info;
4604 struct ieee80211_local *local = sdata->local;
4605 struct tid_ampdu_tx *tid_tx;
4606 struct sk_buff *seg, *next;
4607 unsigned int skbs = 0, len = 0;
4611 queue = ieee80211_select_queue(sdata, sta, skb);
4612 skb_set_queue_mapping(skb, queue);
4614 if (unlikely(test_bit(SCAN_SW_SCANNING, &local->scanning)) &&
4615 test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))
4618 skb = skb_share_check(skb, GFP_ATOMIC);
4622 ieee80211_aggr_check(sdata, sta, skb);
4624 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
4625 tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
4627 if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
4628 /* fall back to non-offload slow path */
4629 __ieee80211_subif_start_xmit(skb, dev, 0,
4630 IEEE80211_TX_CTRL_MLO_LINK_UNSPEC,
4635 if (tid_tx->timeout)
4636 tid_tx->last_tx = jiffies;
4639 skb = ieee80211_tx_skb_fixup(skb, ieee80211_sdata_netdev_features(sdata));
4643 info = IEEE80211_SKB_CB(skb);
4644 memset(info, 0, sizeof(*info));
4646 info->hw_queue = sdata->vif.hw_queue[queue];
4648 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
4649 sdata = container_of(sdata->bss,
4650 struct ieee80211_sub_if_data, u.ap);
4652 info->flags |= IEEE80211_TX_CTL_HW_80211_ENCAP;
4653 info->control.vif = &sdata->vif;
4656 info->control.hw_key = &key->conf;
4658 skb_list_walk_safe(skb, seg, next) {
4662 memcpy(IEEE80211_SKB_CB(seg), info, sizeof(*info));
4665 if (unlikely(skb->sk &&
4666 skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS)) {
4667 info->status_data = ieee80211_store_ack_skb(local, skb,
4668 &info->flags, NULL);
4669 if (info->status_data)
4670 info->status_data_idr = 1;
4673 dev_sw_netstats_tx_add(dev, skbs, len);
4674 sta->deflink.tx_stats.packets[queue] += skbs;
4675 sta->deflink.tx_stats.bytes[queue] += len;
4677 ieee80211_tpt_led_trig_tx(local, len);
4679 ieee80211_tx_8023(sdata, skb, sta, false);
4687 netdev_tx_t ieee80211_subif_start_xmit_8023(struct sk_buff *skb,
4688 struct net_device *dev)
4690 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4691 struct ethhdr *ehdr = (struct ethhdr *)skb->data;
4692 struct ieee80211_key *key;
4693 struct sta_info *sta;
4695 if (unlikely(!ieee80211_sdata_running(sdata) || skb->len < ETH_HLEN)) {
4697 return NETDEV_TX_OK;
4702 if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) {
4707 if (unlikely(IS_ERR_OR_NULL(sta) || !sta->uploaded ||
4708 !test_sta_flag(sta, WLAN_STA_AUTHORIZED) ||
4709 sdata->control_port_protocol == ehdr->h_proto))
4712 key = rcu_dereference(sta->ptk[sta->ptk_idx]);
4714 key = rcu_dereference(sdata->default_unicast_key);
4716 if (key && (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) ||
4717 key->conf.cipher == WLAN_CIPHER_SUITE_TKIP))
4720 sk_pacing_shift_update(skb->sk, sdata->local->hw.tx_sk_pacing_shift);
4721 ieee80211_8023_xmit(sdata, dev, sta, key, skb);
4725 ieee80211_subif_start_xmit(skb, dev);
4729 return NETDEV_TX_OK;
4733 ieee80211_build_data_template(struct ieee80211_sub_if_data *sdata,
4734 struct sk_buff *skb, u32 info_flags)
4736 struct ieee80211_hdr *hdr;
4737 struct ieee80211_tx_data tx = {
4738 .local = sdata->local,
4741 struct sta_info *sta;
4745 if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) {
4747 skb = ERR_PTR(-EINVAL);
4751 skb = ieee80211_build_hdr(sdata, skb, info_flags, sta,
4752 IEEE80211_TX_CTRL_MLO_LINK_UNSPEC, NULL);
4756 hdr = (void *)skb->data;
4757 tx.sta = sta_info_get(sdata, hdr->addr1);
4760 if (ieee80211_tx_h_select_key(&tx) != TX_CONTINUE) {
4763 return ERR_PTR(-EINVAL);
4772 * ieee80211_clear_tx_pending may not be called in a context where
4773 * it is possible that it packets could come in again.
4775 void ieee80211_clear_tx_pending(struct ieee80211_local *local)
4777 struct sk_buff *skb;
4780 for (i = 0; i < local->hw.queues; i++) {
4781 while ((skb = skb_dequeue(&local->pending[i])) != NULL)
4782 ieee80211_free_txskb(&local->hw, skb);
4787 * Returns false if the frame couldn't be transmitted but was queued instead,
4788 * which in this case means re-queued -- take as an indication to stop sending
4789 * more pending frames.
4791 static bool ieee80211_tx_pending_skb(struct ieee80211_local *local,
4792 struct sk_buff *skb)
4794 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4795 struct ieee80211_sub_if_data *sdata;
4796 struct sta_info *sta;
4797 struct ieee80211_hdr *hdr;
4799 struct ieee80211_chanctx_conf *chanctx_conf;
4801 sdata = vif_to_sdata(info->control.vif);
4803 if (info->control.flags & IEEE80211_TX_INTCFL_NEED_TXPROCESSING) {
4804 /* update band only for non-MLD */
4805 if (!ieee80211_vif_is_mld(&sdata->vif)) {
4807 rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
4808 if (unlikely(!chanctx_conf)) {
4812 info->band = chanctx_conf->def.chan->band;
4814 result = ieee80211_tx(sdata, NULL, skb, true);
4815 } else if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) {
4816 if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) {
4821 if (IS_ERR(sta) || (sta && !sta->uploaded))
4824 result = ieee80211_tx_8023(sdata, skb, sta, true);
4826 struct sk_buff_head skbs;
4828 __skb_queue_head_init(&skbs);
4829 __skb_queue_tail(&skbs, skb);
4831 hdr = (struct ieee80211_hdr *)skb->data;
4832 sta = sta_info_get(sdata, hdr->addr1);
4834 result = __ieee80211_tx(local, &skbs, sta, true);
4841 * Transmit all pending packets. Called from tasklet.
4843 void ieee80211_tx_pending(struct tasklet_struct *t)
4845 struct ieee80211_local *local = from_tasklet(local, t,
4846 tx_pending_tasklet);
4847 unsigned long flags;
4853 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
4854 for (i = 0; i < local->hw.queues; i++) {
4856 * If queue is stopped by something other than due to pending
4857 * frames, or we have no pending frames, proceed to next queue.
4859 if (local->queue_stop_reasons[i] ||
4860 skb_queue_empty(&local->pending[i]))
4863 while (!skb_queue_empty(&local->pending[i])) {
4864 struct sk_buff *skb = __skb_dequeue(&local->pending[i]);
4865 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4867 if (WARN_ON(!info->control.vif)) {
4868 ieee80211_free_txskb(&local->hw, skb);
4872 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
4875 txok = ieee80211_tx_pending_skb(local, skb);
4876 spin_lock_irqsave(&local->queue_stop_reason_lock,
4882 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
4887 /* functions for drivers to get certain frames */
4889 static void __ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
4890 struct ieee80211_link_data *link,
4891 struct ps_data *ps, struct sk_buff *skb,
4896 int i, have_bits = 0, n1, n2;
4897 struct ieee80211_bss_conf *link_conf = link->conf;
4899 /* Generate bitmap for TIM only if there are any STAs in power save
4901 if (atomic_read(&ps->num_sta_ps) > 0)
4902 /* in the hope that this is faster than
4903 * checking byte-for-byte */
4904 have_bits = !bitmap_empty((unsigned long *)ps->tim,
4905 IEEE80211_MAX_AID+1);
4907 if (ps->dtim_count == 0)
4908 ps->dtim_count = link_conf->dtim_period - 1;
4913 tim = pos = skb_put(skb, 5);
4914 *pos++ = WLAN_EID_TIM;
4916 *pos++ = ps->dtim_count;
4917 *pos++ = link_conf->dtim_period;
4919 if (ps->dtim_count == 0 && !skb_queue_empty(&ps->bc_buf))
4922 ps->dtim_bc_mc = aid0 == 1;
4925 /* Find largest even number N1 so that bits numbered 1 through
4926 * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits
4927 * (N2 + 1) x 8 through 2007 are 0. */
4929 for (i = 0; i < IEEE80211_MAX_TIM_LEN; i++) {
4936 for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) {
4943 /* Bitmap control */
4945 /* Part Virt Bitmap */
4946 skb_put_data(skb, ps->tim + n1, n2 - n1 + 1);
4948 tim[1] = n2 - n1 + 4;
4950 *pos++ = aid0; /* Bitmap control */
4952 if (ieee80211_get_link_sband(link)->band != NL80211_BAND_S1GHZ) {
4954 /* Part Virt Bitmap */
4960 static int ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
4961 struct ieee80211_link_data *link,
4962 struct ps_data *ps, struct sk_buff *skb,
4965 struct ieee80211_local *local = sdata->local;
4968 * Not very nice, but we want to allow the driver to call
4969 * ieee80211_beacon_get() as a response to the set_tim()
4970 * callback. That, however, is already invoked under the
4971 * sta_lock to guarantee consistent and race-free update
4972 * of the tim bitmap in mac80211 and the driver.
4974 if (local->tim_in_locked_section) {
4975 __ieee80211_beacon_add_tim(sdata, link, ps, skb, is_template);
4977 spin_lock_bh(&local->tim_lock);
4978 __ieee80211_beacon_add_tim(sdata, link, ps, skb, is_template);
4979 spin_unlock_bh(&local->tim_lock);
4985 static void ieee80211_set_beacon_cntdwn(struct ieee80211_sub_if_data *sdata,
4986 struct beacon_data *beacon,
4987 struct ieee80211_link_data *link)
4989 u8 *beacon_data, count, max_count = 1;
4990 struct probe_resp *resp;
4991 size_t beacon_data_len;
4995 switch (sdata->vif.type) {
4996 case NL80211_IFTYPE_AP:
4997 beacon_data = beacon->tail;
4998 beacon_data_len = beacon->tail_len;
5000 case NL80211_IFTYPE_ADHOC:
5001 beacon_data = beacon->head;
5002 beacon_data_len = beacon->head_len;
5004 case NL80211_IFTYPE_MESH_POINT:
5005 beacon_data = beacon->head;
5006 beacon_data_len = beacon->head_len;
5012 resp = rcu_dereference(link->u.ap.probe_resp);
5014 bcn_offsets = beacon->cntdwn_counter_offsets;
5015 count = beacon->cntdwn_current_counter;
5016 if (link->conf->csa_active)
5017 max_count = IEEE80211_MAX_CNTDWN_COUNTERS_NUM;
5019 for (i = 0; i < max_count; ++i) {
5020 if (bcn_offsets[i]) {
5021 if (WARN_ON_ONCE(bcn_offsets[i] >= beacon_data_len))
5023 beacon_data[bcn_offsets[i]] = count;
5026 if (sdata->vif.type == NL80211_IFTYPE_AP && resp) {
5027 u16 *resp_offsets = resp->cntdwn_counter_offsets;
5029 resp->data[resp_offsets[i]] = count;
5034 static u8 __ieee80211_beacon_update_cntdwn(struct beacon_data *beacon)
5036 beacon->cntdwn_current_counter--;
5038 /* the counter should never reach 0 */
5039 WARN_ON_ONCE(!beacon->cntdwn_current_counter);
5041 return beacon->cntdwn_current_counter;
5044 u8 ieee80211_beacon_update_cntdwn(struct ieee80211_vif *vif, unsigned int link_id)
5046 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5047 struct ieee80211_link_data *link;
5048 struct beacon_data *beacon = NULL;
5051 if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
5056 link = rcu_dereference(sdata->link[link_id]);
5060 if (sdata->vif.type == NL80211_IFTYPE_AP)
5061 beacon = rcu_dereference(link->u.ap.beacon);
5062 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
5063 beacon = rcu_dereference(sdata->u.ibss.presp);
5064 else if (ieee80211_vif_is_mesh(&sdata->vif))
5065 beacon = rcu_dereference(sdata->u.mesh.beacon);
5070 count = __ieee80211_beacon_update_cntdwn(beacon);
5076 EXPORT_SYMBOL(ieee80211_beacon_update_cntdwn);
5078 void ieee80211_beacon_set_cntdwn(struct ieee80211_vif *vif, u8 counter)
5080 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5081 struct beacon_data *beacon = NULL;
5085 if (sdata->vif.type == NL80211_IFTYPE_AP)
5086 beacon = rcu_dereference(sdata->deflink.u.ap.beacon);
5087 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
5088 beacon = rcu_dereference(sdata->u.ibss.presp);
5089 else if (ieee80211_vif_is_mesh(&sdata->vif))
5090 beacon = rcu_dereference(sdata->u.mesh.beacon);
5095 if (counter < beacon->cntdwn_current_counter)
5096 beacon->cntdwn_current_counter = counter;
5101 EXPORT_SYMBOL(ieee80211_beacon_set_cntdwn);
5103 bool ieee80211_beacon_cntdwn_is_complete(struct ieee80211_vif *vif,
5104 unsigned int link_id)
5106 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5107 struct ieee80211_link_data *link;
5108 struct beacon_data *beacon = NULL;
5110 size_t beacon_data_len;
5113 if (!ieee80211_sdata_running(sdata))
5116 if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
5121 link = rcu_dereference(sdata->link[link_id]);
5125 if (vif->type == NL80211_IFTYPE_AP) {
5126 beacon = rcu_dereference(link->u.ap.beacon);
5127 if (WARN_ON(!beacon || !beacon->tail))
5129 beacon_data = beacon->tail;
5130 beacon_data_len = beacon->tail_len;
5131 } else if (vif->type == NL80211_IFTYPE_ADHOC) {
5132 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
5134 beacon = rcu_dereference(ifibss->presp);
5138 beacon_data = beacon->head;
5139 beacon_data_len = beacon->head_len;
5140 } else if (vif->type == NL80211_IFTYPE_MESH_POINT) {
5141 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
5143 beacon = rcu_dereference(ifmsh->beacon);
5147 beacon_data = beacon->head;
5148 beacon_data_len = beacon->head_len;
5154 if (!beacon->cntdwn_counter_offsets[0])
5157 if (WARN_ON_ONCE(beacon->cntdwn_counter_offsets[0] > beacon_data_len))
5160 if (beacon_data[beacon->cntdwn_counter_offsets[0]] == 1)
5168 EXPORT_SYMBOL(ieee80211_beacon_cntdwn_is_complete);
5170 static int ieee80211_beacon_protect(struct sk_buff *skb,
5171 struct ieee80211_local *local,
5172 struct ieee80211_sub_if_data *sdata,
5173 struct ieee80211_link_data *link)
5175 ieee80211_tx_result res;
5176 struct ieee80211_tx_data tx;
5177 struct sk_buff *check_skb;
5179 memset(&tx, 0, sizeof(tx));
5180 tx.key = rcu_dereference(link->default_beacon_key);
5184 if (unlikely(tx.key->flags & KEY_FLAG_TAINTED)) {
5189 if (!(tx.key->conf.flags & IEEE80211_KEY_FLAG_SW_MGMT_TX) &&
5190 tx.key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
5191 IEEE80211_SKB_CB(skb)->control.hw_key = &tx.key->conf;
5195 __skb_queue_head_init(&tx.skbs);
5196 __skb_queue_tail(&tx.skbs, skb);
5197 res = ieee80211_tx_h_encrypt(&tx);
5198 check_skb = __skb_dequeue(&tx.skbs);
5199 /* we may crash after this, but it'd be a bug in crypto */
5200 WARN_ON(check_skb != skb);
5201 if (WARN_ON_ONCE(res != TX_CONTINUE))
5208 ieee80211_beacon_get_finish(struct ieee80211_hw *hw,
5209 struct ieee80211_vif *vif,
5210 struct ieee80211_link_data *link,
5211 struct ieee80211_mutable_offsets *offs,
5212 struct beacon_data *beacon,
5213 struct sk_buff *skb,
5214 struct ieee80211_chanctx_conf *chanctx_conf,
5217 struct ieee80211_local *local = hw_to_local(hw);
5218 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5219 struct ieee80211_tx_info *info;
5220 enum nl80211_band band;
5221 struct ieee80211_tx_rate_control txrc;
5224 if (offs && beacon) {
5227 for (i = 0; i < IEEE80211_MAX_CNTDWN_COUNTERS_NUM; i++) {
5228 u16 csa_off = beacon->cntdwn_counter_offsets[i];
5233 offs->cntdwn_counter_offs[i] = csa_off_base + csa_off;
5237 band = chanctx_conf->def.chan->band;
5238 info = IEEE80211_SKB_CB(skb);
5239 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
5240 info->flags |= IEEE80211_TX_CTL_NO_ACK;
5243 memset(&txrc, 0, sizeof(txrc));
5245 txrc.sband = local->hw.wiphy->bands[band];
5246 txrc.bss_conf = link->conf;
5248 txrc.reported_rate.idx = -1;
5249 if (sdata->beacon_rate_set && sdata->beacon_rateidx_mask[band])
5250 txrc.rate_idx_mask = sdata->beacon_rateidx_mask[band];
5252 txrc.rate_idx_mask = sdata->rc_rateidx_mask[band];
5254 rate_control_get_rate(sdata, NULL, &txrc);
5256 info->control.vif = vif;
5257 info->control.flags |= u32_encode_bits(link->link_id,
5258 IEEE80211_TX_CTRL_MLO_LINK);
5259 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT |
5260 IEEE80211_TX_CTL_ASSIGN_SEQ |
5261 IEEE80211_TX_CTL_FIRST_FRAGMENT;
5265 ieee80211_beacon_add_mbssid(struct sk_buff *skb, struct beacon_data *beacon,
5268 if (!beacon->mbssid_ies || !beacon->mbssid_ies->cnt ||
5269 i > beacon->mbssid_ies->cnt)
5272 if (i < beacon->mbssid_ies->cnt) {
5273 skb_put_data(skb, beacon->mbssid_ies->elem[i].data,
5274 beacon->mbssid_ies->elem[i].len);
5276 if (beacon->rnr_ies && beacon->rnr_ies->cnt) {
5277 skb_put_data(skb, beacon->rnr_ies->elem[i].data,
5278 beacon->rnr_ies->elem[i].len);
5280 for (i = beacon->mbssid_ies->cnt; i < beacon->rnr_ies->cnt; i++)
5281 skb_put_data(skb, beacon->rnr_ies->elem[i].data,
5282 beacon->rnr_ies->elem[i].len);
5287 /* i == beacon->mbssid_ies->cnt, include all MBSSID elements */
5288 for (i = 0; i < beacon->mbssid_ies->cnt; i++)
5289 skb_put_data(skb, beacon->mbssid_ies->elem[i].data,
5290 beacon->mbssid_ies->elem[i].len);
5293 static struct sk_buff *
5294 ieee80211_beacon_get_ap(struct ieee80211_hw *hw,
5295 struct ieee80211_vif *vif,
5296 struct ieee80211_link_data *link,
5297 struct ieee80211_mutable_offsets *offs,
5299 struct beacon_data *beacon,
5300 struct ieee80211_chanctx_conf *chanctx_conf,
5303 struct ieee80211_local *local = hw_to_local(hw);
5304 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5305 struct ieee80211_if_ap *ap = &sdata->u.ap;
5306 struct sk_buff *skb = NULL;
5307 u16 csa_off_base = 0;
5310 if (beacon->cntdwn_counter_offsets[0]) {
5312 ieee80211_beacon_update_cntdwn(vif, link->link_id);
5314 ieee80211_set_beacon_cntdwn(sdata, beacon, link);
5317 /* headroom, head length,
5318 * tail length, maximum TIM length and multiple BSSID length
5320 mbssid_len = ieee80211_get_mbssid_beacon_len(beacon->mbssid_ies,
5324 skb = dev_alloc_skb(local->tx_headroom + beacon->head_len +
5325 beacon->tail_len + 256 +
5326 local->hw.extra_beacon_tailroom + mbssid_len);
5330 skb_reserve(skb, local->tx_headroom);
5331 skb_put_data(skb, beacon->head, beacon->head_len);
5333 ieee80211_beacon_add_tim(sdata, link, &ap->ps, skb, is_template);
5336 offs->tim_offset = beacon->head_len;
5337 offs->tim_length = skb->len - beacon->head_len;
5338 offs->cntdwn_counter_offs[0] = beacon->cntdwn_counter_offsets[0];
5341 ieee80211_beacon_add_mbssid(skb, beacon, ema_index);
5342 offs->mbssid_off = skb->len - mbssid_len;
5345 /* for AP the csa offsets are from tail */
5346 csa_off_base = skb->len;
5350 skb_put_data(skb, beacon->tail, beacon->tail_len);
5352 if (ieee80211_beacon_protect(skb, local, sdata, link) < 0)
5355 ieee80211_beacon_get_finish(hw, vif, link, offs, beacon, skb,
5356 chanctx_conf, csa_off_base);
5360 static struct ieee80211_ema_beacons *
5361 ieee80211_beacon_get_ap_ema_list(struct ieee80211_hw *hw,
5362 struct ieee80211_vif *vif,
5363 struct ieee80211_link_data *link,
5364 struct ieee80211_mutable_offsets *offs,
5365 bool is_template, struct beacon_data *beacon,
5366 struct ieee80211_chanctx_conf *chanctx_conf)
5368 struct ieee80211_ema_beacons *ema = NULL;
5370 if (!beacon->mbssid_ies || !beacon->mbssid_ies->cnt)
5373 ema = kzalloc(struct_size(ema, bcn, beacon->mbssid_ies->cnt),
5378 for (ema->cnt = 0; ema->cnt < beacon->mbssid_ies->cnt; ema->cnt++) {
5379 ema->bcn[ema->cnt].skb =
5380 ieee80211_beacon_get_ap(hw, vif, link,
5381 &ema->bcn[ema->cnt].offs,
5382 is_template, beacon,
5383 chanctx_conf, ema->cnt);
5384 if (!ema->bcn[ema->cnt].skb)
5388 if (ema->cnt == beacon->mbssid_ies->cnt)
5391 ieee80211_beacon_free_ema_list(ema);
5395 #define IEEE80211_INCLUDE_ALL_MBSSID_ELEMS -1
5397 static struct sk_buff *
5398 __ieee80211_beacon_get(struct ieee80211_hw *hw,
5399 struct ieee80211_vif *vif,
5400 struct ieee80211_mutable_offsets *offs,
5402 unsigned int link_id,
5404 struct ieee80211_ema_beacons **ema_beacons)
5406 struct ieee80211_local *local = hw_to_local(hw);
5407 struct beacon_data *beacon = NULL;
5408 struct sk_buff *skb = NULL;
5409 struct ieee80211_sub_if_data *sdata = NULL;
5410 struct ieee80211_chanctx_conf *chanctx_conf;
5411 struct ieee80211_link_data *link;
5415 sdata = vif_to_sdata(vif);
5416 link = rcu_dereference(sdata->link[link_id]);
5420 rcu_dereference(link->conf->chanctx_conf);
5422 if (!ieee80211_sdata_running(sdata) || !chanctx_conf)
5426 memset(offs, 0, sizeof(*offs));
5428 if (sdata->vif.type == NL80211_IFTYPE_AP) {
5429 beacon = rcu_dereference(link->u.ap.beacon);
5435 ieee80211_beacon_get_ap_ema_list(hw, vif, link,
5441 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) {
5442 if (ema_index >= beacon->mbssid_ies->cnt)
5443 goto out; /* End of MBSSID elements */
5445 if (ema_index <= IEEE80211_INCLUDE_ALL_MBSSID_ELEMS)
5446 ema_index = beacon->mbssid_ies->cnt;
5451 skb = ieee80211_beacon_get_ap(hw, vif, link, offs,
5452 is_template, beacon,
5456 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
5457 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
5458 struct ieee80211_hdr *hdr;
5460 beacon = rcu_dereference(ifibss->presp);
5464 if (beacon->cntdwn_counter_offsets[0]) {
5466 __ieee80211_beacon_update_cntdwn(beacon);
5468 ieee80211_set_beacon_cntdwn(sdata, beacon, link);
5471 skb = dev_alloc_skb(local->tx_headroom + beacon->head_len +
5472 local->hw.extra_beacon_tailroom);
5475 skb_reserve(skb, local->tx_headroom);
5476 skb_put_data(skb, beacon->head, beacon->head_len);
5478 hdr = (struct ieee80211_hdr *) skb->data;
5479 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
5480 IEEE80211_STYPE_BEACON);
5482 ieee80211_beacon_get_finish(hw, vif, link, offs, beacon, skb,
5484 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
5485 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
5487 beacon = rcu_dereference(ifmsh->beacon);
5491 if (beacon->cntdwn_counter_offsets[0]) {
5493 /* TODO: For mesh csa_counter is in TU, so
5494 * decrementing it by one isn't correct, but
5495 * for now we leave it consistent with overall
5496 * mac80211's behavior.
5498 __ieee80211_beacon_update_cntdwn(beacon);
5500 ieee80211_set_beacon_cntdwn(sdata, beacon, link);
5503 if (ifmsh->sync_ops)
5504 ifmsh->sync_ops->adjust_tsf(sdata, beacon);
5506 skb = dev_alloc_skb(local->tx_headroom +
5510 local->hw.extra_beacon_tailroom);
5513 skb_reserve(skb, local->tx_headroom);
5514 skb_put_data(skb, beacon->head, beacon->head_len);
5515 ieee80211_beacon_add_tim(sdata, link, &ifmsh->ps, skb,
5519 offs->tim_offset = beacon->head_len;
5520 offs->tim_length = skb->len - beacon->head_len;
5523 skb_put_data(skb, beacon->tail, beacon->tail_len);
5524 ieee80211_beacon_get_finish(hw, vif, link, offs, beacon, skb,
5538 ieee80211_beacon_get_template(struct ieee80211_hw *hw,
5539 struct ieee80211_vif *vif,
5540 struct ieee80211_mutable_offsets *offs,
5541 unsigned int link_id)
5543 return __ieee80211_beacon_get(hw, vif, offs, true, link_id,
5544 IEEE80211_INCLUDE_ALL_MBSSID_ELEMS, NULL);
5546 EXPORT_SYMBOL(ieee80211_beacon_get_template);
5549 ieee80211_beacon_get_template_ema_index(struct ieee80211_hw *hw,
5550 struct ieee80211_vif *vif,
5551 struct ieee80211_mutable_offsets *offs,
5552 unsigned int link_id, u8 ema_index)
5554 return __ieee80211_beacon_get(hw, vif, offs, true, link_id, ema_index,
5557 EXPORT_SYMBOL(ieee80211_beacon_get_template_ema_index);
5559 void ieee80211_beacon_free_ema_list(struct ieee80211_ema_beacons *ema_beacons)
5566 for (i = 0; i < ema_beacons->cnt; i++)
5567 kfree_skb(ema_beacons->bcn[i].skb);
5571 EXPORT_SYMBOL(ieee80211_beacon_free_ema_list);
5573 struct ieee80211_ema_beacons *
5574 ieee80211_beacon_get_template_ema_list(struct ieee80211_hw *hw,
5575 struct ieee80211_vif *vif,
5576 unsigned int link_id)
5578 struct ieee80211_ema_beacons *ema_beacons = NULL;
5580 WARN_ON(__ieee80211_beacon_get(hw, vif, NULL, true, link_id, 0,
5585 EXPORT_SYMBOL(ieee80211_beacon_get_template_ema_list);
5587 struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
5588 struct ieee80211_vif *vif,
5589 u16 *tim_offset, u16 *tim_length,
5590 unsigned int link_id)
5592 struct ieee80211_mutable_offsets offs = {};
5593 struct sk_buff *bcn = __ieee80211_beacon_get(hw, vif, &offs, false,
5595 IEEE80211_INCLUDE_ALL_MBSSID_ELEMS,
5597 struct sk_buff *copy;
5603 *tim_offset = offs.tim_offset;
5606 *tim_length = offs.tim_length;
5608 if (ieee80211_hw_check(hw, BEACON_TX_STATUS) ||
5609 !hw_to_local(hw)->monitors)
5612 /* send a copy to monitor interfaces */
5613 copy = skb_copy(bcn, GFP_ATOMIC);
5617 ieee80211_tx_monitor(hw_to_local(hw), copy, 1, false, NULL);
5621 EXPORT_SYMBOL(ieee80211_beacon_get_tim);
5623 struct sk_buff *ieee80211_proberesp_get(struct ieee80211_hw *hw,
5624 struct ieee80211_vif *vif)
5626 struct sk_buff *skb = NULL;
5627 struct probe_resp *presp = NULL;
5628 struct ieee80211_hdr *hdr;
5629 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5631 if (sdata->vif.type != NL80211_IFTYPE_AP)
5635 presp = rcu_dereference(sdata->deflink.u.ap.probe_resp);
5639 skb = dev_alloc_skb(presp->len);
5643 skb_put_data(skb, presp->data, presp->len);
5645 hdr = (struct ieee80211_hdr *) skb->data;
5646 memset(hdr->addr1, 0, sizeof(hdr->addr1));
5652 EXPORT_SYMBOL(ieee80211_proberesp_get);
5654 struct sk_buff *ieee80211_get_fils_discovery_tmpl(struct ieee80211_hw *hw,
5655 struct ieee80211_vif *vif)
5657 struct sk_buff *skb = NULL;
5658 struct fils_discovery_data *tmpl = NULL;
5659 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5661 if (sdata->vif.type != NL80211_IFTYPE_AP)
5665 tmpl = rcu_dereference(sdata->deflink.u.ap.fils_discovery);
5671 skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom + tmpl->len);
5673 skb_reserve(skb, sdata->local->hw.extra_tx_headroom);
5674 skb_put_data(skb, tmpl->data, tmpl->len);
5680 EXPORT_SYMBOL(ieee80211_get_fils_discovery_tmpl);
5683 ieee80211_get_unsol_bcast_probe_resp_tmpl(struct ieee80211_hw *hw,
5684 struct ieee80211_vif *vif)
5686 struct sk_buff *skb = NULL;
5687 struct unsol_bcast_probe_resp_data *tmpl = NULL;
5688 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5690 if (sdata->vif.type != NL80211_IFTYPE_AP)
5694 tmpl = rcu_dereference(sdata->deflink.u.ap.unsol_bcast_probe_resp);
5700 skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom + tmpl->len);
5702 skb_reserve(skb, sdata->local->hw.extra_tx_headroom);
5703 skb_put_data(skb, tmpl->data, tmpl->len);
5709 EXPORT_SYMBOL(ieee80211_get_unsol_bcast_probe_resp_tmpl);
5711 struct sk_buff *ieee80211_pspoll_get(struct ieee80211_hw *hw,
5712 struct ieee80211_vif *vif)
5714 struct ieee80211_sub_if_data *sdata;
5715 struct ieee80211_pspoll *pspoll;
5716 struct ieee80211_local *local;
5717 struct sk_buff *skb;
5719 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
5722 sdata = vif_to_sdata(vif);
5723 local = sdata->local;
5725 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll));
5729 skb_reserve(skb, local->hw.extra_tx_headroom);
5731 pspoll = skb_put_zero(skb, sizeof(*pspoll));
5732 pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
5733 IEEE80211_STYPE_PSPOLL);
5734 pspoll->aid = cpu_to_le16(sdata->vif.cfg.aid);
5736 /* aid in PS-Poll has its two MSBs each set to 1 */
5737 pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
5739 memcpy(pspoll->bssid, sdata->deflink.u.mgd.bssid, ETH_ALEN);
5740 memcpy(pspoll->ta, vif->addr, ETH_ALEN);
5744 EXPORT_SYMBOL(ieee80211_pspoll_get);
5746 struct sk_buff *ieee80211_nullfunc_get(struct ieee80211_hw *hw,
5747 struct ieee80211_vif *vif,
5748 int link_id, bool qos_ok)
5750 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5751 struct ieee80211_local *local = sdata->local;
5752 struct ieee80211_link_data *link = NULL;
5753 struct ieee80211_hdr_3addr *nullfunc;
5754 struct sk_buff *skb;
5757 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
5760 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
5761 sizeof(*nullfunc) + 2);
5767 struct sta_info *sta;
5769 sta = sta_info_get(sdata, vif->cfg.ap_addr);
5770 qos = sta && sta->sta.wme;
5774 link = rcu_dereference(sdata->link[link_id]);
5775 if (WARN_ON_ONCE(!link)) {
5782 skb_reserve(skb, local->hw.extra_tx_headroom);
5784 nullfunc = skb_put_zero(skb, sizeof(*nullfunc));
5785 nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
5786 IEEE80211_STYPE_NULLFUNC |
5787 IEEE80211_FCTL_TODS);
5789 __le16 qoshdr = cpu_to_le16(7);
5791 BUILD_BUG_ON((IEEE80211_STYPE_QOS_NULLFUNC |
5792 IEEE80211_STYPE_NULLFUNC) !=
5793 IEEE80211_STYPE_QOS_NULLFUNC);
5794 nullfunc->frame_control |=
5795 cpu_to_le16(IEEE80211_STYPE_QOS_NULLFUNC);
5797 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
5798 skb_put_data(skb, &qoshdr, sizeof(qoshdr));
5802 memcpy(nullfunc->addr1, link->conf->bssid, ETH_ALEN);
5803 memcpy(nullfunc->addr2, link->conf->addr, ETH_ALEN);
5804 memcpy(nullfunc->addr3, link->conf->bssid, ETH_ALEN);
5806 memcpy(nullfunc->addr1, vif->cfg.ap_addr, ETH_ALEN);
5807 memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
5808 memcpy(nullfunc->addr3, vif->cfg.ap_addr, ETH_ALEN);
5814 EXPORT_SYMBOL(ieee80211_nullfunc_get);
5816 struct sk_buff *ieee80211_probereq_get(struct ieee80211_hw *hw,
5818 const u8 *ssid, size_t ssid_len,
5821 struct ieee80211_local *local = hw_to_local(hw);
5822 struct ieee80211_hdr_3addr *hdr;
5823 struct sk_buff *skb;
5827 ie_ssid_len = 2 + ssid_len;
5829 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*hdr) +
5830 ie_ssid_len + tailroom);
5834 skb_reserve(skb, local->hw.extra_tx_headroom);
5836 hdr = skb_put_zero(skb, sizeof(*hdr));
5837 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
5838 IEEE80211_STYPE_PROBE_REQ);
5839 eth_broadcast_addr(hdr->addr1);
5840 memcpy(hdr->addr2, src_addr, ETH_ALEN);
5841 eth_broadcast_addr(hdr->addr3);
5843 pos = skb_put(skb, ie_ssid_len);
5844 *pos++ = WLAN_EID_SSID;
5847 memcpy(pos, ssid, ssid_len);
5852 EXPORT_SYMBOL(ieee80211_probereq_get);
5854 void ieee80211_rts_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5855 const void *frame, size_t frame_len,
5856 const struct ieee80211_tx_info *frame_txctl,
5857 struct ieee80211_rts *rts)
5859 const struct ieee80211_hdr *hdr = frame;
5861 rts->frame_control =
5862 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
5863 rts->duration = ieee80211_rts_duration(hw, vif, frame_len,
5865 memcpy(rts->ra, hdr->addr1, sizeof(rts->ra));
5866 memcpy(rts->ta, hdr->addr2, sizeof(rts->ta));
5868 EXPORT_SYMBOL(ieee80211_rts_get);
5870 void ieee80211_ctstoself_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5871 const void *frame, size_t frame_len,
5872 const struct ieee80211_tx_info *frame_txctl,
5873 struct ieee80211_cts *cts)
5875 const struct ieee80211_hdr *hdr = frame;
5877 cts->frame_control =
5878 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
5879 cts->duration = ieee80211_ctstoself_duration(hw, vif,
5880 frame_len, frame_txctl);
5881 memcpy(cts->ra, hdr->addr1, sizeof(cts->ra));
5883 EXPORT_SYMBOL(ieee80211_ctstoself_get);
5886 ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
5887 struct ieee80211_vif *vif)
5889 struct ieee80211_local *local = hw_to_local(hw);
5890 struct sk_buff *skb = NULL;
5891 struct ieee80211_tx_data tx;
5892 struct ieee80211_sub_if_data *sdata;
5894 struct ieee80211_tx_info *info;
5895 struct ieee80211_chanctx_conf *chanctx_conf;
5897 sdata = vif_to_sdata(vif);
5900 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
5905 if (sdata->vif.type == NL80211_IFTYPE_AP) {
5906 struct beacon_data *beacon =
5907 rcu_dereference(sdata->deflink.u.ap.beacon);
5909 if (!beacon || !beacon->head)
5912 ps = &sdata->u.ap.ps;
5913 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
5914 ps = &sdata->u.mesh.ps;
5919 if (ps->dtim_count != 0 || !ps->dtim_bc_mc)
5920 goto out; /* send buffered bc/mc only after DTIM beacon */
5923 skb = skb_dequeue(&ps->bc_buf);
5926 local->total_ps_buffered--;
5928 if (!skb_queue_empty(&ps->bc_buf) && skb->len >= 2) {
5929 struct ieee80211_hdr *hdr =
5930 (struct ieee80211_hdr *) skb->data;
5931 /* more buffered multicast/broadcast frames ==> set
5932 * MoreData flag in IEEE 802.11 header to inform PS
5934 hdr->frame_control |=
5935 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
5938 if (sdata->vif.type == NL80211_IFTYPE_AP)
5939 sdata = IEEE80211_DEV_TO_SUB_IF(skb->dev);
5940 if (!ieee80211_tx_prepare(sdata, &tx, NULL, skb))
5942 ieee80211_free_txskb(hw, skb);
5945 info = IEEE80211_SKB_CB(skb);
5947 tx.flags |= IEEE80211_TX_PS_BUFFERED;
5948 info->band = chanctx_conf->def.chan->band;
5950 if (invoke_tx_handlers(&tx))
5957 EXPORT_SYMBOL(ieee80211_get_buffered_bc);
5959 int ieee80211_reserve_tid(struct ieee80211_sta *pubsta, u8 tid)
5961 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
5962 struct ieee80211_sub_if_data *sdata = sta->sdata;
5963 struct ieee80211_local *local = sdata->local;
5967 lockdep_assert_wiphy(local->hw.wiphy);
5969 /* only some cases are supported right now */
5970 switch (sdata->vif.type) {
5971 case NL80211_IFTYPE_STATION:
5972 case NL80211_IFTYPE_AP:
5973 case NL80211_IFTYPE_AP_VLAN:
5980 if (WARN_ON(tid >= IEEE80211_NUM_UPS))
5983 if (sta->reserved_tid == tid) {
5988 if (sta->reserved_tid != IEEE80211_TID_UNRESERVED) {
5989 sdata_err(sdata, "TID reservation already active\n");
5994 ieee80211_stop_vif_queues(sdata->local, sdata,
5995 IEEE80211_QUEUE_STOP_REASON_RESERVE_TID);
5999 /* Tear down BA sessions so we stop aggregating on this TID */
6000 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION)) {
6001 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
6002 __ieee80211_stop_tx_ba_session(sta, tid,
6003 AGG_STOP_LOCAL_REQUEST);
6006 queues = BIT(sdata->vif.hw_queue[ieee802_1d_to_ac[tid]]);
6007 __ieee80211_flush_queues(local, sdata, queues, false);
6009 sta->reserved_tid = tid;
6011 ieee80211_wake_vif_queues(local, sdata,
6012 IEEE80211_QUEUE_STOP_REASON_RESERVE_TID);
6014 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION))
6015 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
6021 EXPORT_SYMBOL(ieee80211_reserve_tid);
6023 void ieee80211_unreserve_tid(struct ieee80211_sta *pubsta, u8 tid)
6025 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
6026 struct ieee80211_sub_if_data *sdata = sta->sdata;
6028 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6030 /* only some cases are supported right now */
6031 switch (sdata->vif.type) {
6032 case NL80211_IFTYPE_STATION:
6033 case NL80211_IFTYPE_AP:
6034 case NL80211_IFTYPE_AP_VLAN:
6041 if (tid != sta->reserved_tid) {
6042 sdata_err(sdata, "TID to unreserve (%d) isn't reserved\n", tid);
6046 sta->reserved_tid = IEEE80211_TID_UNRESERVED;
6048 EXPORT_SYMBOL(ieee80211_unreserve_tid);
6050 void __ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata,
6051 struct sk_buff *skb, int tid, int link_id,
6052 enum nl80211_band band)
6054 const struct ieee80211_hdr *hdr = (void *)skb->data;
6055 int ac = ieee80211_ac_from_tid(tid);
6058 skb_reset_mac_header(skb);
6059 skb_set_queue_mapping(skb, ac);
6060 skb->priority = tid;
6062 skb->dev = sdata->dev;
6064 BUILD_BUG_ON(IEEE80211_LINK_UNSPECIFIED < IEEE80211_MLD_MAX_NUM_LINKS);
6065 BUILD_BUG_ON(!FIELD_FIT(IEEE80211_TX_CTRL_MLO_LINK,
6066 IEEE80211_LINK_UNSPECIFIED));
6068 if (!ieee80211_vif_is_mld(&sdata->vif)) {
6070 } else if (link_id >= 0) {
6072 } else if (memcmp(sdata->vif.addr, hdr->addr2, ETH_ALEN) == 0) {
6073 /* address from the MLD */
6074 link = IEEE80211_LINK_UNSPECIFIED;
6076 /* otherwise must be addressed from a link */
6078 for (link = 0; link < ARRAY_SIZE(sdata->vif.link_conf); link++) {
6079 struct ieee80211_bss_conf *link_conf;
6081 link_conf = rcu_dereference(sdata->vif.link_conf[link]);
6084 if (memcmp(link_conf->addr, hdr->addr2, ETH_ALEN) == 0)
6089 if (WARN_ON_ONCE(link == ARRAY_SIZE(sdata->vif.link_conf)))
6090 link = ffs(sdata->vif.active_links) - 1;
6093 IEEE80211_SKB_CB(skb)->control.flags |=
6094 u32_encode_bits(link, IEEE80211_TX_CTRL_MLO_LINK);
6097 * The other path calling ieee80211_xmit is from the tasklet,
6098 * and while we can handle concurrent transmissions locking
6099 * requirements are that we do not come into tx with bhs on.
6102 IEEE80211_SKB_CB(skb)->band = band;
6103 ieee80211_xmit(sdata, NULL, skb);
6107 void ieee80211_tx_skb_tid(struct ieee80211_sub_if_data *sdata,
6108 struct sk_buff *skb, int tid, int link_id)
6110 struct ieee80211_chanctx_conf *chanctx_conf;
6111 enum nl80211_band band;
6114 if (!ieee80211_vif_is_mld(&sdata->vif)) {
6115 WARN_ON(link_id >= 0);
6117 rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
6118 if (WARN_ON(!chanctx_conf)) {
6123 band = chanctx_conf->def.chan->band;
6125 WARN_ON(link_id >= 0 &&
6126 !(sdata->vif.active_links & BIT(link_id)));
6127 /* MLD transmissions must not rely on the band */
6131 __ieee80211_tx_skb_tid_band(sdata, skb, tid, link_id, band);
6135 int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev,
6136 const u8 *buf, size_t len,
6137 const u8 *dest, __be16 proto, bool unencrypted,
6138 int link_id, u64 *cookie)
6140 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
6141 struct ieee80211_local *local = sdata->local;
6142 struct sta_info *sta;
6143 struct sk_buff *skb;
6144 struct ethhdr *ehdr;
6149 /* mutex lock is only needed for incrementing the cookie counter */
6150 lockdep_assert_wiphy(local->hw.wiphy);
6152 /* Only accept CONTROL_PORT_PROTOCOL configured in CONNECT/ASSOCIATE
6153 * or Pre-Authentication
6155 if (proto != sdata->control_port_protocol &&
6156 proto != cpu_to_be16(ETH_P_PREAUTH))
6159 if (proto == sdata->control_port_protocol)
6160 ctrl_flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO |
6161 IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP;
6164 flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
6167 ctrl_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
6169 flags |= IEEE80211_TX_INTFL_NL80211_FRAME_TX;
6171 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
6172 sizeof(struct ethhdr) + len);
6176 skb_reserve(skb, local->hw.extra_tx_headroom + sizeof(struct ethhdr));
6178 skb_put_data(skb, buf, len);
6180 ehdr = skb_push(skb, sizeof(struct ethhdr));
6181 memcpy(ehdr->h_dest, dest, ETH_ALEN);
6183 /* we may override the SA for MLO STA later */
6185 ctrl_flags |= u32_encode_bits(IEEE80211_LINK_UNSPECIFIED,
6186 IEEE80211_TX_CTRL_MLO_LINK);
6187 memcpy(ehdr->h_source, sdata->vif.addr, ETH_ALEN);
6189 struct ieee80211_bss_conf *link_conf;
6191 ctrl_flags |= u32_encode_bits(link_id,
6192 IEEE80211_TX_CTRL_MLO_LINK);
6195 link_conf = rcu_dereference(sdata->vif.link_conf[link_id]);
6201 memcpy(ehdr->h_source, link_conf->addr, ETH_ALEN);
6205 ehdr->h_proto = proto;
6208 skb->protocol = proto;
6209 skb_reset_network_header(skb);
6210 skb_reset_mac_header(skb);
6212 if (local->hw.queues < IEEE80211_NUM_ACS)
6215 /* update QoS header to prioritize control port frames if possible,
6216 * priorization also happens for control port frames send over
6220 err = ieee80211_lookup_ra_sta(sdata, skb, &sta);
6228 u16 queue = ieee80211_select_queue(sdata, sta, skb);
6230 skb_set_queue_mapping(skb, queue);
6233 * for MLO STA, the SA should be the AP MLD address, but
6234 * the link ID has been selected already
6236 if (sta && sta->sta.mlo)
6237 memcpy(ehdr->h_source, sdata->vif.addr, ETH_ALEN);
6243 __ieee80211_subif_start_xmit(skb, skb->dev, flags, ctrl_flags, cookie);
6249 int ieee80211_probe_mesh_link(struct wiphy *wiphy, struct net_device *dev,
6250 const u8 *buf, size_t len)
6252 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
6253 struct ieee80211_local *local = sdata->local;
6254 struct sk_buff *skb;
6256 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len +
6257 30 + /* header size */
6258 18); /* 11s header size */
6262 skb_reserve(skb, local->hw.extra_tx_headroom);
6263 skb_put_data(skb, buf, len);
6266 skb->protocol = htons(ETH_P_802_3);
6267 skb_reset_network_header(skb);
6268 skb_reset_mac_header(skb);
6271 __ieee80211_subif_start_xmit(skb, skb->dev, 0,
6272 IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP,