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;
701 txrc.rate_idx_mask = tx->sdata->rc_rateidx_mask[info->band];
703 if (tx->sdata->rc_has_mcs_mask[info->band])
704 txrc.rate_idx_mcs_mask =
705 tx->sdata->rc_rateidx_mcs_mask[info->band];
707 txrc.bss = (tx->sdata->vif.type == NL80211_IFTYPE_AP ||
708 tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
709 tx->sdata->vif.type == NL80211_IFTYPE_ADHOC ||
710 tx->sdata->vif.type == NL80211_IFTYPE_OCB);
712 /* set up RTS protection if desired */
713 if (len > tx->local->hw.wiphy->rts_threshold) {
717 info->control.use_rts = txrc.rts;
718 info->control.use_cts_prot = tx->sdata->vif.bss_conf.use_cts_prot;
721 * Use short preamble if the BSS can handle it, but not for
722 * management frames unless we know the receiver can handle
723 * that -- the management frame might be to a station that
724 * just wants a probe response.
726 if (tx->sdata->vif.bss_conf.use_short_preamble &&
727 (ieee80211_is_tx_data(tx->skb) ||
728 (tx->sta && test_sta_flag(tx->sta, WLAN_STA_SHORT_PREAMBLE))))
729 txrc.short_preamble = true;
731 info->control.short_preamble = txrc.short_preamble;
733 /* don't ask rate control when rate already injected via radiotap */
734 if (info->control.flags & IEEE80211_TX_CTRL_RATE_INJECT)
738 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
741 * Lets not bother rate control if we're associated and cannot
742 * talk to the sta. This should not happen.
744 if (WARN(test_bit(SCAN_SW_SCANNING, &tx->local->scanning) && assoc &&
745 !rate_usable_index_exists(sband, &tx->sta->sta),
746 "%s: Dropped data frame as no usable bitrate found while "
747 "scanning and associated. Target station: "
748 "%pM on %d GHz band\n",
750 encap ? ((struct ethhdr *)hdr)->h_dest : hdr->addr1,
755 * If we're associated with the sta at this point we know we can at
756 * least send the frame at the lowest bit rate.
758 rate_control_get_rate(tx->sdata, tx->sta, &txrc);
760 if (tx->sta && !info->control.skip_table)
761 ratetbl = rcu_dereference(tx->sta->sta.rates);
763 if (unlikely(info->control.rates[0].idx < 0)) {
765 struct ieee80211_tx_rate rate = {
766 .idx = ratetbl->rate[0].idx,
767 .flags = ratetbl->rate[0].flags,
768 .count = ratetbl->rate[0].count
771 if (ratetbl->rate[0].idx < 0)
779 tx->rate = info->control.rates[0];
782 if (txrc.reported_rate.idx < 0) {
783 txrc.reported_rate = tx->rate;
784 if (tx->sta && ieee80211_is_tx_data(tx->skb))
785 tx->sta->deflink.tx_stats.last_rate = txrc.reported_rate;
787 tx->sta->deflink.tx_stats.last_rate = txrc.reported_rate;
792 if (unlikely(!info->control.rates[0].count))
793 info->control.rates[0].count = 1;
795 if (WARN_ON_ONCE((info->control.rates[0].count > 1) &&
796 (info->flags & IEEE80211_TX_CTL_NO_ACK)))
797 info->control.rates[0].count = 1;
802 static __le16 ieee80211_tx_next_seq(struct sta_info *sta, int tid)
804 u16 *seq = &sta->tid_seq[tid];
805 __le16 ret = cpu_to_le16(*seq);
807 /* Increase the sequence number. */
808 *seq = (*seq + 0x10) & IEEE80211_SCTL_SEQ;
813 static ieee80211_tx_result debug_noinline
814 ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx)
816 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
817 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
821 * Packet injection may want to control the sequence
822 * number, if we have no matching interface then we
823 * neither assign one ourselves nor ask the driver to.
825 if (unlikely(info->control.vif->type == NL80211_IFTYPE_MONITOR))
828 if (unlikely(ieee80211_is_ctl(hdr->frame_control)))
831 if (ieee80211_hdrlen(hdr->frame_control) < 24)
834 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
837 if (info->control.flags & IEEE80211_TX_CTRL_NO_SEQNO)
840 /* SNS11 from 802.11be 10.3.2.14 */
841 if (unlikely(is_multicast_ether_addr(hdr->addr1) &&
842 ieee80211_vif_is_mld(info->control.vif) &&
843 info->control.vif->type == NL80211_IFTYPE_AP)) {
844 if (info->control.flags & IEEE80211_TX_CTRL_MCAST_MLO_FIRST_TX)
845 tx->sdata->mld_mcast_seq += 0x10;
846 hdr->seq_ctrl = cpu_to_le16(tx->sdata->mld_mcast_seq);
851 * Anything but QoS data that has a sequence number field
852 * (is long enough) gets a sequence number from the global
853 * counter. QoS data frames with a multicast destination
854 * also use the global counter (802.11-2012 9.3.2.10).
856 if (!ieee80211_is_data_qos(hdr->frame_control) ||
857 is_multicast_ether_addr(hdr->addr1)) {
858 /* driver should assign sequence number */
859 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
860 /* for pure STA mode without beacons, we can do it */
861 hdr->seq_ctrl = cpu_to_le16(tx->sdata->sequence_number);
862 tx->sdata->sequence_number += 0x10;
864 tx->sta->deflink.tx_stats.msdu[IEEE80211_NUM_TIDS]++;
869 * This should be true for injected/management frames only, for
870 * management frames we have set the IEEE80211_TX_CTL_ASSIGN_SEQ
871 * above since they are not QoS-data frames.
876 /* include per-STA, per-TID sequence counter */
877 tid = ieee80211_get_tid(hdr);
878 tx->sta->deflink.tx_stats.msdu[tid]++;
880 hdr->seq_ctrl = ieee80211_tx_next_seq(tx->sta, tid);
885 static int ieee80211_fragment(struct ieee80211_tx_data *tx,
886 struct sk_buff *skb, int hdrlen,
889 struct ieee80211_local *local = tx->local;
890 struct ieee80211_tx_info *info;
892 int per_fragm = frag_threshold - hdrlen - FCS_LEN;
893 int pos = hdrlen + per_fragm;
894 int rem = skb->len - hdrlen - per_fragm;
896 if (WARN_ON(rem < 0))
899 /* first fragment was already added to queue by caller */
902 int fraglen = per_fragm;
907 tmp = dev_alloc_skb(local->tx_headroom +
909 IEEE80211_ENCRYPT_HEADROOM +
910 IEEE80211_ENCRYPT_TAILROOM);
914 __skb_queue_tail(&tx->skbs, tmp);
917 local->tx_headroom + IEEE80211_ENCRYPT_HEADROOM);
919 /* copy control information */
920 memcpy(tmp->cb, skb->cb, sizeof(tmp->cb));
922 info = IEEE80211_SKB_CB(tmp);
923 info->flags &= ~(IEEE80211_TX_CTL_CLEAR_PS_FILT |
924 IEEE80211_TX_CTL_FIRST_FRAGMENT);
927 info->flags |= IEEE80211_TX_CTL_MORE_FRAMES;
929 skb_copy_queue_mapping(tmp, skb);
930 tmp->priority = skb->priority;
933 /* copy header and data */
934 skb_put_data(tmp, skb->data, hdrlen);
935 skb_put_data(tmp, skb->data + pos, fraglen);
940 /* adjust first fragment's length */
941 skb_trim(skb, hdrlen + per_fragm);
945 static ieee80211_tx_result debug_noinline
946 ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
948 struct sk_buff *skb = tx->skb;
949 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
950 struct ieee80211_hdr *hdr = (void *)skb->data;
951 int frag_threshold = tx->local->hw.wiphy->frag_threshold;
955 /* no matter what happens, tx->skb moves to tx->skbs */
956 __skb_queue_tail(&tx->skbs, skb);
959 if (info->flags & IEEE80211_TX_CTL_DONTFRAG)
962 if (ieee80211_hw_check(&tx->local->hw, SUPPORTS_TX_FRAG))
966 * Warn when submitting a fragmented A-MPDU frame and drop it.
967 * This scenario is handled in ieee80211_tx_prepare but extra
968 * caution taken here as fragmented ampdu may cause Tx stop.
970 if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU))
973 hdrlen = ieee80211_hdrlen(hdr->frame_control);
975 /* internal error, why isn't DONTFRAG set? */
976 if (WARN_ON(skb->len + FCS_LEN <= frag_threshold))
980 * Now fragment the frame. This will allocate all the fragments and
981 * chain them (using skb as the first fragment) to skb->next.
982 * During transmission, we will remove the successfully transmitted
983 * fragments from this list. When the low-level driver rejects one
984 * of the fragments then we will simply pretend to accept the skb
985 * but store it away as pending.
987 if (ieee80211_fragment(tx, skb, hdrlen, frag_threshold))
990 /* update duration/seq/flags of fragments */
993 skb_queue_walk(&tx->skbs, skb) {
994 const __le16 morefrags = cpu_to_le16(IEEE80211_FCTL_MOREFRAGS);
996 hdr = (void *)skb->data;
997 info = IEEE80211_SKB_CB(skb);
999 if (!skb_queue_is_last(&tx->skbs, skb)) {
1000 hdr->frame_control |= morefrags;
1002 * No multi-rate retries for fragmented frames, that
1003 * would completely throw off the NAV at other STAs.
1005 info->control.rates[1].idx = -1;
1006 info->control.rates[2].idx = -1;
1007 info->control.rates[3].idx = -1;
1008 BUILD_BUG_ON(IEEE80211_TX_MAX_RATES != 4);
1009 info->flags &= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE;
1011 hdr->frame_control &= ~morefrags;
1013 hdr->seq_ctrl |= cpu_to_le16(fragnum & IEEE80211_SCTL_FRAG);
1020 static ieee80211_tx_result debug_noinline
1021 ieee80211_tx_h_stats(struct ieee80211_tx_data *tx)
1023 struct sk_buff *skb;
1029 skb_queue_walk(&tx->skbs, skb) {
1030 ac = skb_get_queue_mapping(skb);
1031 tx->sta->deflink.tx_stats.bytes[ac] += skb->len;
1034 tx->sta->deflink.tx_stats.packets[ac]++;
1039 static ieee80211_tx_result debug_noinline
1040 ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx)
1045 switch (tx->key->conf.cipher) {
1046 case WLAN_CIPHER_SUITE_WEP40:
1047 case WLAN_CIPHER_SUITE_WEP104:
1048 return ieee80211_crypto_wep_encrypt(tx);
1049 case WLAN_CIPHER_SUITE_TKIP:
1050 return ieee80211_crypto_tkip_encrypt(tx);
1051 case WLAN_CIPHER_SUITE_CCMP:
1052 return ieee80211_crypto_ccmp_encrypt(
1053 tx, IEEE80211_CCMP_MIC_LEN);
1054 case WLAN_CIPHER_SUITE_CCMP_256:
1055 return ieee80211_crypto_ccmp_encrypt(
1056 tx, IEEE80211_CCMP_256_MIC_LEN);
1057 case WLAN_CIPHER_SUITE_AES_CMAC:
1058 return ieee80211_crypto_aes_cmac_encrypt(tx);
1059 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
1060 return ieee80211_crypto_aes_cmac_256_encrypt(tx);
1061 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
1062 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
1063 return ieee80211_crypto_aes_gmac_encrypt(tx);
1064 case WLAN_CIPHER_SUITE_GCMP:
1065 case WLAN_CIPHER_SUITE_GCMP_256:
1066 return ieee80211_crypto_gcmp_encrypt(tx);
1072 static ieee80211_tx_result debug_noinline
1073 ieee80211_tx_h_calculate_duration(struct ieee80211_tx_data *tx)
1075 struct sk_buff *skb;
1076 struct ieee80211_hdr *hdr;
1080 skb_queue_walk(&tx->skbs, skb) {
1081 hdr = (void *) skb->data;
1082 if (unlikely(ieee80211_is_pspoll(hdr->frame_control)))
1083 break; /* must not overwrite AID */
1084 if (!skb_queue_is_last(&tx->skbs, skb)) {
1085 struct sk_buff *next = skb_queue_next(&tx->skbs, skb);
1086 next_len = next->len;
1089 group_addr = is_multicast_ether_addr(hdr->addr1);
1092 ieee80211_duration(tx, skb, group_addr, next_len);
1098 /* actual transmit path */
1100 static bool ieee80211_tx_prep_agg(struct ieee80211_tx_data *tx,
1101 struct sk_buff *skb,
1102 struct ieee80211_tx_info *info,
1103 struct tid_ampdu_tx *tid_tx,
1106 bool queued = false;
1107 bool reset_agg_timer = false;
1108 struct sk_buff *purge_skb = NULL;
1110 if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
1111 reset_agg_timer = true;
1112 } else if (test_bit(HT_AGG_STATE_WANT_START, &tid_tx->state)) {
1114 * nothing -- this aggregation session is being started
1115 * but that might still fail with the driver
1117 } else if (!tx->sta->sta.txq[tid]) {
1118 spin_lock(&tx->sta->lock);
1120 * Need to re-check now, because we may get here
1122 * 1) in the window during which the setup is actually
1123 * already done, but not marked yet because not all
1124 * packets are spliced over to the driver pending
1125 * queue yet -- if this happened we acquire the lock
1126 * either before or after the splice happens, but
1127 * need to recheck which of these cases happened.
1129 * 2) during session teardown, if the OPERATIONAL bit
1130 * was cleared due to the teardown but the pointer
1131 * hasn't been assigned NULL yet (or we loaded it
1132 * before it was assigned) -- in this case it may
1133 * now be NULL which means we should just let the
1134 * packet pass through because splicing the frames
1135 * back is already done.
1137 tid_tx = rcu_dereference_protected_tid_tx(tx->sta, tid);
1140 /* do nothing, let packet pass through */
1141 } else if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
1142 reset_agg_timer = true;
1145 if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER) {
1146 clear_sta_flag(tx->sta, WLAN_STA_SP);
1147 ps_dbg(tx->sta->sdata,
1148 "STA %pM aid %d: SP frame queued, close the SP w/o telling the peer\n",
1149 tx->sta->sta.addr, tx->sta->sta.aid);
1151 info->control.vif = &tx->sdata->vif;
1152 info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
1153 info->flags &= ~IEEE80211_TX_TEMPORARY_FLAGS;
1154 __skb_queue_tail(&tid_tx->pending, skb);
1155 if (skb_queue_len(&tid_tx->pending) > STA_MAX_TX_BUFFER)
1156 purge_skb = __skb_dequeue(&tid_tx->pending);
1158 spin_unlock(&tx->sta->lock);
1161 ieee80211_free_txskb(&tx->local->hw, purge_skb);
1164 /* reset session timer */
1165 if (reset_agg_timer)
1166 tid_tx->last_tx = jiffies;
1171 void ieee80211_aggr_check(struct ieee80211_sub_if_data *sdata,
1172 struct sta_info *sta, struct sk_buff *skb)
1174 struct rate_control_ref *ref = sdata->local->rate_ctrl;
1177 if (!ref || !(ref->ops->capa & RATE_CTRL_CAPA_AMPDU_TRIGGER))
1180 if (!sta || !sta->sta.deflink.ht_cap.ht_supported ||
1181 !sta->sta.wme || skb_get_queue_mapping(skb) == IEEE80211_AC_VO ||
1182 skb->protocol == sdata->control_port_protocol)
1185 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
1186 if (likely(sta->ampdu_mlme.tid_tx[tid]))
1189 ieee80211_start_tx_ba_session(&sta->sta, tid, 0);
1194 * pass %NULL for the station if unknown, a valid pointer if known
1195 * or an ERR_PTR() if the station is known not to exist
1197 static ieee80211_tx_result
1198 ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata,
1199 struct ieee80211_tx_data *tx,
1200 struct sta_info *sta, struct sk_buff *skb)
1202 struct ieee80211_local *local = sdata->local;
1203 struct ieee80211_hdr *hdr;
1204 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1205 bool aggr_check = false;
1208 memset(tx, 0, sizeof(*tx));
1212 __skb_queue_head_init(&tx->skbs);
1215 * If this flag is set to true anywhere, and we get here,
1216 * we are doing the needed processing, so remove the flag
1219 info->control.flags &= ~IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
1221 hdr = (struct ieee80211_hdr *) skb->data;
1227 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
1228 tx->sta = rcu_dereference(sdata->u.vlan.sta);
1229 if (!tx->sta && sdata->wdev.use_4addr)
1231 } else if (tx->sdata->control_port_protocol == tx->skb->protocol) {
1232 tx->sta = sta_info_get_bss(sdata, hdr->addr1);
1234 if (!tx->sta && !is_multicast_ether_addr(hdr->addr1)) {
1235 tx->sta = sta_info_get(sdata, hdr->addr1);
1240 if (tx->sta && ieee80211_is_data_qos(hdr->frame_control) &&
1241 !ieee80211_is_qos_nullfunc(hdr->frame_control) &&
1242 ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
1243 !ieee80211_hw_check(&local->hw, TX_AMPDU_SETUP_IN_HW)) {
1244 struct tid_ampdu_tx *tid_tx;
1246 tid = ieee80211_get_tid(hdr);
1247 tid_tx = rcu_dereference(tx->sta->ampdu_mlme.tid_tx[tid]);
1248 if (!tid_tx && aggr_check) {
1249 ieee80211_aggr_check(sdata, tx->sta, skb);
1250 tid_tx = rcu_dereference(tx->sta->ampdu_mlme.tid_tx[tid]);
1256 queued = ieee80211_tx_prep_agg(tx, skb, info,
1259 if (unlikely(queued))
1264 if (is_multicast_ether_addr(hdr->addr1)) {
1265 tx->flags &= ~IEEE80211_TX_UNICAST;
1266 info->flags |= IEEE80211_TX_CTL_NO_ACK;
1268 tx->flags |= IEEE80211_TX_UNICAST;
1270 if (!(info->flags & IEEE80211_TX_CTL_DONTFRAG)) {
1271 if (!(tx->flags & IEEE80211_TX_UNICAST) ||
1272 skb->len + FCS_LEN <= local->hw.wiphy->frag_threshold ||
1273 info->flags & IEEE80211_TX_CTL_AMPDU)
1274 info->flags |= IEEE80211_TX_CTL_DONTFRAG;
1278 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
1279 else if (test_and_clear_sta_flag(tx->sta, WLAN_STA_CLEAR_PS_FILT)) {
1280 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
1281 ieee80211_check_fast_xmit(tx->sta);
1284 info->flags |= IEEE80211_TX_CTL_FIRST_FRAGMENT;
1289 static struct txq_info *ieee80211_get_txq(struct ieee80211_local *local,
1290 struct ieee80211_vif *vif,
1291 struct sta_info *sta,
1292 struct sk_buff *skb)
1294 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1295 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1296 struct ieee80211_txq *txq = NULL;
1298 if ((info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) ||
1299 (info->control.flags & IEEE80211_TX_CTRL_PS_RESPONSE))
1302 if (!(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) &&
1303 unlikely(!ieee80211_is_data_present(hdr->frame_control))) {
1304 if ((!ieee80211_is_mgmt(hdr->frame_control) ||
1305 ieee80211_is_bufferable_mmpdu(skb) ||
1306 vif->type == NL80211_IFTYPE_STATION) &&
1307 sta && sta->uploaded) {
1309 * This will be NULL if the driver didn't set the
1310 * opt-in hardware flag.
1312 txq = sta->sta.txq[IEEE80211_NUM_TIDS];
1315 u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
1320 txq = sta->sta.txq[tid];
1328 return to_txq_info(txq);
1331 static void ieee80211_set_skb_enqueue_time(struct sk_buff *skb)
1333 struct sk_buff *next;
1334 codel_time_t now = codel_get_time();
1336 skb_list_walk_safe(skb, skb, next)
1337 IEEE80211_SKB_CB(skb)->control.enqueue_time = now;
1340 static u32 codel_skb_len_func(const struct sk_buff *skb)
1345 static codel_time_t codel_skb_time_func(const struct sk_buff *skb)
1347 const struct ieee80211_tx_info *info;
1349 info = (const struct ieee80211_tx_info *)skb->cb;
1350 return info->control.enqueue_time;
1353 static struct sk_buff *codel_dequeue_func(struct codel_vars *cvars,
1356 struct ieee80211_local *local;
1357 struct txq_info *txqi;
1359 struct fq_flow *flow;
1362 local = vif_to_sdata(txqi->txq.vif)->local;
1365 if (cvars == &txqi->def_cvars)
1366 flow = &txqi->tin.default_flow;
1368 flow = &fq->flows[cvars - local->cvars];
1370 return fq_flow_dequeue(fq, flow);
1373 static void codel_drop_func(struct sk_buff *skb,
1376 struct ieee80211_local *local;
1377 struct ieee80211_hw *hw;
1378 struct txq_info *txqi;
1381 local = vif_to_sdata(txqi->txq.vif)->local;
1384 ieee80211_free_txskb(hw, skb);
1387 static struct sk_buff *fq_tin_dequeue_func(struct fq *fq,
1389 struct fq_flow *flow)
1391 struct ieee80211_local *local;
1392 struct txq_info *txqi;
1393 struct codel_vars *cvars;
1394 struct codel_params *cparams;
1395 struct codel_stats *cstats;
1397 local = container_of(fq, struct ieee80211_local, fq);
1398 txqi = container_of(tin, struct txq_info, tin);
1399 cstats = &txqi->cstats;
1401 if (txqi->txq.sta) {
1402 struct sta_info *sta = container_of(txqi->txq.sta,
1403 struct sta_info, sta);
1404 cparams = &sta->cparams;
1406 cparams = &local->cparams;
1409 if (flow == &tin->default_flow)
1410 cvars = &txqi->def_cvars;
1412 cvars = &local->cvars[flow - fq->flows];
1414 return codel_dequeue(txqi,
1420 codel_skb_time_func,
1422 codel_dequeue_func);
1425 static void fq_skb_free_func(struct fq *fq,
1427 struct fq_flow *flow,
1428 struct sk_buff *skb)
1430 struct ieee80211_local *local;
1432 local = container_of(fq, struct ieee80211_local, fq);
1433 ieee80211_free_txskb(&local->hw, skb);
1436 static void ieee80211_txq_enqueue(struct ieee80211_local *local,
1437 struct txq_info *txqi,
1438 struct sk_buff *skb)
1440 struct fq *fq = &local->fq;
1441 struct fq_tin *tin = &txqi->tin;
1442 u32 flow_idx = fq_flow_idx(fq, skb);
1444 ieee80211_set_skb_enqueue_time(skb);
1446 spin_lock_bh(&fq->lock);
1448 * For management frames, don't really apply codel etc.,
1449 * we don't want to apply any shaping or anything we just
1450 * want to simplify the driver API by having them on the
1453 if (unlikely(txqi->txq.tid == IEEE80211_NUM_TIDS)) {
1454 IEEE80211_SKB_CB(skb)->control.flags |=
1455 IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
1456 __skb_queue_tail(&txqi->frags, skb);
1458 fq_tin_enqueue(fq, tin, flow_idx, skb,
1461 spin_unlock_bh(&fq->lock);
1464 static bool fq_vlan_filter_func(struct fq *fq, struct fq_tin *tin,
1465 struct fq_flow *flow, struct sk_buff *skb,
1468 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1470 return info->control.vif == data;
1473 void ieee80211_txq_remove_vlan(struct ieee80211_local *local,
1474 struct ieee80211_sub_if_data *sdata)
1476 struct fq *fq = &local->fq;
1477 struct txq_info *txqi;
1479 struct ieee80211_sub_if_data *ap;
1481 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_AP_VLAN))
1484 ap = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap);
1489 txqi = to_txq_info(ap->vif.txq);
1492 spin_lock_bh(&fq->lock);
1493 fq_tin_filter(fq, tin, fq_vlan_filter_func, &sdata->vif,
1495 spin_unlock_bh(&fq->lock);
1498 void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata,
1499 struct sta_info *sta,
1500 struct txq_info *txqi, int tid)
1502 fq_tin_init(&txqi->tin);
1503 codel_vars_init(&txqi->def_cvars);
1504 codel_stats_init(&txqi->cstats);
1505 __skb_queue_head_init(&txqi->frags);
1506 INIT_LIST_HEAD(&txqi->schedule_order);
1508 txqi->txq.vif = &sdata->vif;
1511 sdata->vif.txq = &txqi->txq;
1513 txqi->txq.ac = IEEE80211_AC_BE;
1518 if (tid == IEEE80211_NUM_TIDS) {
1519 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
1520 /* Drivers need to opt in to the management MPDU TXQ */
1521 if (!ieee80211_hw_check(&sdata->local->hw,
1524 } else if (!ieee80211_hw_check(&sdata->local->hw,
1526 /* Drivers need to opt in to the bufferable MMPDU TXQ */
1529 txqi->txq.ac = IEEE80211_AC_VO;
1531 txqi->txq.ac = ieee80211_ac_from_tid(tid);
1534 txqi->txq.sta = &sta->sta;
1535 txqi->txq.tid = tid;
1536 sta->sta.txq[tid] = &txqi->txq;
1539 void ieee80211_txq_purge(struct ieee80211_local *local,
1540 struct txq_info *txqi)
1542 struct fq *fq = &local->fq;
1543 struct fq_tin *tin = &txqi->tin;
1545 spin_lock_bh(&fq->lock);
1546 fq_tin_reset(fq, tin, fq_skb_free_func);
1547 ieee80211_purge_tx_queue(&local->hw, &txqi->frags);
1548 spin_unlock_bh(&fq->lock);
1550 spin_lock_bh(&local->active_txq_lock[txqi->txq.ac]);
1551 list_del_init(&txqi->schedule_order);
1552 spin_unlock_bh(&local->active_txq_lock[txqi->txq.ac]);
1555 void ieee80211_txq_set_params(struct ieee80211_local *local)
1557 if (local->hw.wiphy->txq_limit)
1558 local->fq.limit = local->hw.wiphy->txq_limit;
1560 local->hw.wiphy->txq_limit = local->fq.limit;
1562 if (local->hw.wiphy->txq_memory_limit)
1563 local->fq.memory_limit = local->hw.wiphy->txq_memory_limit;
1565 local->hw.wiphy->txq_memory_limit = local->fq.memory_limit;
1567 if (local->hw.wiphy->txq_quantum)
1568 local->fq.quantum = local->hw.wiphy->txq_quantum;
1570 local->hw.wiphy->txq_quantum = local->fq.quantum;
1573 int ieee80211_txq_setup_flows(struct ieee80211_local *local)
1575 struct fq *fq = &local->fq;
1578 bool supp_vht = false;
1579 enum nl80211_band band;
1581 ret = fq_init(fq, 4096);
1586 * If the hardware doesn't support VHT, it is safe to limit the maximum
1587 * queue size. 4 Mbytes is 64 max-size aggregates in 802.11n.
1589 for (band = 0; band < NUM_NL80211_BANDS; band++) {
1590 struct ieee80211_supported_band *sband;
1592 sband = local->hw.wiphy->bands[band];
1596 supp_vht = supp_vht || sband->vht_cap.vht_supported;
1600 fq->memory_limit = 4 << 20; /* 4 Mbytes */
1602 codel_params_init(&local->cparams);
1603 local->cparams.interval = MS2TIME(100);
1604 local->cparams.target = MS2TIME(20);
1605 local->cparams.ecn = true;
1607 local->cvars = kcalloc(fq->flows_cnt, sizeof(local->cvars[0]),
1609 if (!local->cvars) {
1610 spin_lock_bh(&fq->lock);
1611 fq_reset(fq, fq_skb_free_func);
1612 spin_unlock_bh(&fq->lock);
1616 for (i = 0; i < fq->flows_cnt; i++)
1617 codel_vars_init(&local->cvars[i]);
1619 ieee80211_txq_set_params(local);
1624 void ieee80211_txq_teardown_flows(struct ieee80211_local *local)
1626 struct fq *fq = &local->fq;
1628 kfree(local->cvars);
1629 local->cvars = NULL;
1631 spin_lock_bh(&fq->lock);
1632 fq_reset(fq, fq_skb_free_func);
1633 spin_unlock_bh(&fq->lock);
1636 static bool ieee80211_queue_skb(struct ieee80211_local *local,
1637 struct ieee80211_sub_if_data *sdata,
1638 struct sta_info *sta,
1639 struct sk_buff *skb)
1641 struct ieee80211_vif *vif;
1642 struct txq_info *txqi;
1644 if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
1647 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1648 sdata = container_of(sdata->bss,
1649 struct ieee80211_sub_if_data, u.ap);
1652 txqi = ieee80211_get_txq(local, vif, sta, skb);
1657 ieee80211_txq_enqueue(local, txqi, skb);
1659 schedule_and_wake_txq(local, txqi);
1664 static bool ieee80211_tx_frags(struct ieee80211_local *local,
1665 struct ieee80211_vif *vif,
1666 struct sta_info *sta,
1667 struct sk_buff_head *skbs,
1670 struct ieee80211_tx_control control = {};
1671 struct sk_buff *skb, *tmp;
1672 unsigned long flags;
1674 skb_queue_walk_safe(skbs, skb, tmp) {
1675 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1676 int q = info->hw_queue;
1678 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1679 if (WARN_ON_ONCE(q >= local->hw.queues)) {
1680 __skb_unlink(skb, skbs);
1681 ieee80211_free_txskb(&local->hw, skb);
1686 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1687 if (local->queue_stop_reasons[q] ||
1688 (!txpending && !skb_queue_empty(&local->pending[q]))) {
1689 if (unlikely(info->flags &
1690 IEEE80211_TX_INTFL_OFFCHAN_TX_OK)) {
1691 if (local->queue_stop_reasons[q] &
1692 ~BIT(IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL)) {
1694 * Drop off-channel frames if queues
1695 * are stopped for any reason other
1696 * than off-channel operation. Never
1699 spin_unlock_irqrestore(
1700 &local->queue_stop_reason_lock,
1702 ieee80211_purge_tx_queue(&local->hw,
1709 * Since queue is stopped, queue up frames for
1710 * later transmission from the tx-pending
1711 * tasklet when the queue is woken again.
1714 skb_queue_splice_init(skbs,
1715 &local->pending[q]);
1717 skb_queue_splice_tail_init(skbs,
1718 &local->pending[q]);
1720 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1725 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1727 info->control.vif = vif;
1728 control.sta = sta ? &sta->sta : NULL;
1730 __skb_unlink(skb, skbs);
1731 drv_tx(local, &control, skb);
1738 * Returns false if the frame couldn't be transmitted but was queued instead.
1740 static bool __ieee80211_tx(struct ieee80211_local *local,
1741 struct sk_buff_head *skbs, struct sta_info *sta,
1744 struct ieee80211_tx_info *info;
1745 struct ieee80211_sub_if_data *sdata;
1746 struct ieee80211_vif *vif;
1747 struct sk_buff *skb;
1750 if (WARN_ON(skb_queue_empty(skbs)))
1753 skb = skb_peek(skbs);
1754 info = IEEE80211_SKB_CB(skb);
1755 sdata = vif_to_sdata(info->control.vif);
1756 if (sta && !sta->uploaded)
1759 switch (sdata->vif.type) {
1760 case NL80211_IFTYPE_MONITOR:
1761 if (sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) {
1765 sdata = rcu_dereference(local->monitor_sdata);
1769 vif->hw_queue[skb_get_queue_mapping(skb)];
1770 } else if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) {
1771 ieee80211_purge_tx_queue(&local->hw, skbs);
1776 case NL80211_IFTYPE_AP_VLAN:
1777 sdata = container_of(sdata->bss,
1778 struct ieee80211_sub_if_data, u.ap);
1785 result = ieee80211_tx_frags(local, vif, sta, skbs, txpending);
1787 WARN_ON_ONCE(!skb_queue_empty(skbs));
1793 * Invoke TX handlers, return 0 on success and non-zero if the
1794 * frame was dropped or queued.
1796 * The handlers are split into an early and late part. The latter is everything
1797 * that can be sensitive to reordering, and will be deferred to after packets
1798 * are dequeued from the intermediate queues (when they are enabled).
1800 static int invoke_tx_handlers_early(struct ieee80211_tx_data *tx)
1802 ieee80211_tx_result res = TX_DROP;
1804 #define CALL_TXH(txh) \
1807 if (res != TX_CONTINUE) \
1811 CALL_TXH(ieee80211_tx_h_dynamic_ps);
1812 CALL_TXH(ieee80211_tx_h_check_assoc);
1813 CALL_TXH(ieee80211_tx_h_ps_buf);
1814 CALL_TXH(ieee80211_tx_h_check_control_port_protocol);
1815 CALL_TXH(ieee80211_tx_h_select_key);
1818 if (unlikely(res == TX_DROP)) {
1819 I802_DEBUG_INC(tx->local->tx_handlers_drop);
1821 ieee80211_free_txskb(&tx->local->hw, tx->skb);
1823 ieee80211_purge_tx_queue(&tx->local->hw, &tx->skbs);
1825 } else if (unlikely(res == TX_QUEUED)) {
1826 I802_DEBUG_INC(tx->local->tx_handlers_queued);
1834 * Late handlers can be called while the sta lock is held. Handlers that can
1835 * cause packets to be generated will cause deadlock!
1837 static int invoke_tx_handlers_late(struct ieee80211_tx_data *tx)
1839 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
1840 ieee80211_tx_result res = TX_CONTINUE;
1842 if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL))
1843 CALL_TXH(ieee80211_tx_h_rate_ctrl);
1845 if (unlikely(info->flags & IEEE80211_TX_INTFL_RETRANSMISSION)) {
1846 __skb_queue_tail(&tx->skbs, tx->skb);
1851 CALL_TXH(ieee80211_tx_h_michael_mic_add);
1852 CALL_TXH(ieee80211_tx_h_sequence);
1853 CALL_TXH(ieee80211_tx_h_fragment);
1854 /* handlers after fragment must be aware of tx info fragmentation! */
1855 CALL_TXH(ieee80211_tx_h_stats);
1856 CALL_TXH(ieee80211_tx_h_encrypt);
1857 if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL))
1858 CALL_TXH(ieee80211_tx_h_calculate_duration);
1862 if (unlikely(res == TX_DROP)) {
1863 I802_DEBUG_INC(tx->local->tx_handlers_drop);
1865 ieee80211_free_txskb(&tx->local->hw, tx->skb);
1867 ieee80211_purge_tx_queue(&tx->local->hw, &tx->skbs);
1869 } else if (unlikely(res == TX_QUEUED)) {
1870 I802_DEBUG_INC(tx->local->tx_handlers_queued);
1877 static int invoke_tx_handlers(struct ieee80211_tx_data *tx)
1879 int r = invoke_tx_handlers_early(tx);
1883 return invoke_tx_handlers_late(tx);
1886 bool ieee80211_tx_prepare_skb(struct ieee80211_hw *hw,
1887 struct ieee80211_vif *vif, struct sk_buff *skb,
1888 int band, struct ieee80211_sta **sta)
1890 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1891 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1892 struct ieee80211_tx_data tx;
1893 struct sk_buff *skb2;
1895 if (ieee80211_tx_prepare(sdata, &tx, NULL, skb) == TX_DROP)
1899 info->control.vif = vif;
1900 info->hw_queue = vif->hw_queue[skb_get_queue_mapping(skb)];
1902 if (invoke_tx_handlers(&tx))
1907 *sta = &tx.sta->sta;
1912 /* this function isn't suitable for fragmented data frames */
1913 skb2 = __skb_dequeue(&tx.skbs);
1914 if (WARN_ON(skb2 != skb || !skb_queue_empty(&tx.skbs))) {
1915 ieee80211_free_txskb(hw, skb2);
1916 ieee80211_purge_tx_queue(hw, &tx.skbs);
1922 EXPORT_SYMBOL(ieee80211_tx_prepare_skb);
1925 * Returns false if the frame couldn't be transmitted but was queued instead.
1927 static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata,
1928 struct sta_info *sta, struct sk_buff *skb,
1931 struct ieee80211_local *local = sdata->local;
1932 struct ieee80211_tx_data tx;
1933 ieee80211_tx_result res_prepare;
1934 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1937 if (unlikely(skb->len < 10)) {
1942 /* initialises tx */
1943 res_prepare = ieee80211_tx_prepare(sdata, &tx, sta, skb);
1945 if (unlikely(res_prepare == TX_DROP)) {
1946 ieee80211_free_txskb(&local->hw, skb);
1948 } else if (unlikely(res_prepare == TX_QUEUED)) {
1952 /* set up hw_queue value early */
1953 if (!(info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) ||
1954 !ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
1956 sdata->vif.hw_queue[skb_get_queue_mapping(skb)];
1958 if (invoke_tx_handlers_early(&tx))
1961 if (ieee80211_queue_skb(local, sdata, tx.sta, tx.skb))
1964 if (!invoke_tx_handlers_late(&tx))
1965 result = __ieee80211_tx(local, &tx.skbs, tx.sta, txpending);
1970 /* device xmit handlers */
1972 enum ieee80211_encrypt {
1978 static int ieee80211_skb_resize(struct ieee80211_sub_if_data *sdata,
1979 struct sk_buff *skb,
1981 enum ieee80211_encrypt encrypt)
1983 struct ieee80211_local *local = sdata->local;
1987 enc_tailroom = encrypt == ENCRYPT_MGMT ||
1988 (encrypt == ENCRYPT_DATA &&
1989 sdata->crypto_tx_tailroom_needed_cnt);
1992 tail_need = IEEE80211_ENCRYPT_TAILROOM;
1993 tail_need -= skb_tailroom(skb);
1994 tail_need = max_t(int, tail_need, 0);
1997 if (skb_cloned(skb) &&
1998 (!ieee80211_hw_check(&local->hw, SUPPORTS_CLONED_SKBS) ||
1999 !skb_clone_writable(skb, ETH_HLEN) || enc_tailroom))
2000 I802_DEBUG_INC(local->tx_expand_skb_head_cloned);
2001 else if (head_need || tail_need)
2002 I802_DEBUG_INC(local->tx_expand_skb_head);
2006 if (pskb_expand_head(skb, head_need, tail_need, GFP_ATOMIC)) {
2007 wiphy_debug(local->hw.wiphy,
2008 "failed to reallocate TX buffer\n");
2015 void ieee80211_xmit(struct ieee80211_sub_if_data *sdata,
2016 struct sta_info *sta, struct sk_buff *skb)
2018 struct ieee80211_local *local = sdata->local;
2019 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2020 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2022 enum ieee80211_encrypt encrypt;
2024 if (info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)
2025 encrypt = ENCRYPT_NO;
2026 else if (ieee80211_is_mgmt(hdr->frame_control))
2027 encrypt = ENCRYPT_MGMT;
2029 encrypt = ENCRYPT_DATA;
2031 headroom = local->tx_headroom;
2032 if (encrypt != ENCRYPT_NO)
2033 headroom += IEEE80211_ENCRYPT_HEADROOM;
2034 headroom -= skb_headroom(skb);
2035 headroom = max_t(int, 0, headroom);
2037 if (ieee80211_skb_resize(sdata, skb, headroom, encrypt)) {
2038 ieee80211_free_txskb(&local->hw, skb);
2042 /* reload after potential resize */
2043 hdr = (struct ieee80211_hdr *) skb->data;
2044 info->control.vif = &sdata->vif;
2046 if (ieee80211_vif_is_mesh(&sdata->vif)) {
2047 if (ieee80211_is_data(hdr->frame_control) &&
2048 is_unicast_ether_addr(hdr->addr1)) {
2049 if (mesh_nexthop_resolve(sdata, skb))
2050 return; /* skb queued: don't free */
2052 ieee80211_mps_set_frame_flags(sdata, NULL, hdr);
2056 ieee80211_set_qos_hdr(sdata, skb);
2057 ieee80211_tx(sdata, sta, skb, false);
2060 static bool ieee80211_validate_radiotap_len(struct sk_buff *skb)
2062 struct ieee80211_radiotap_header *rthdr =
2063 (struct ieee80211_radiotap_header *)skb->data;
2065 /* check for not even having the fixed radiotap header part */
2066 if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
2067 return false; /* too short to be possibly valid */
2069 /* is it a header version we can trust to find length from? */
2070 if (unlikely(rthdr->it_version))
2071 return false; /* only version 0 is supported */
2073 /* does the skb contain enough to deliver on the alleged length? */
2074 if (unlikely(skb->len < ieee80211_get_radiotap_len(skb->data)))
2075 return false; /* skb too short for claimed rt header extent */
2080 bool ieee80211_parse_tx_radiotap(struct sk_buff *skb,
2081 struct net_device *dev)
2083 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2084 struct ieee80211_radiotap_iterator iterator;
2085 struct ieee80211_radiotap_header *rthdr =
2086 (struct ieee80211_radiotap_header *) skb->data;
2087 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2088 int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len,
2092 bool rate_found = false;
2093 u8 rate_retries = 0;
2095 u8 mcs_known, mcs_flags, mcs_bw;
2097 u8 vht_mcs = 0, vht_nss = 0;
2100 if (!ieee80211_validate_radiotap_len(skb))
2103 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
2104 IEEE80211_TX_CTL_DONTFRAG;
2107 * for every radiotap entry that is present
2108 * (ieee80211_radiotap_iterator_next returns -ENOENT when no more
2109 * entries present, or -EINVAL on error)
2113 ret = ieee80211_radiotap_iterator_next(&iterator);
2118 /* see if this argument is something we can use */
2119 switch (iterator.this_arg_index) {
2121 * You must take care when dereferencing iterator.this_arg
2122 * for multibyte types... the pointer is not aligned. Use
2123 * get_unaligned((type *)iterator.this_arg) to dereference
2124 * iterator.this_arg for type "type" safely on all arches.
2126 case IEEE80211_RADIOTAP_FLAGS:
2127 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) {
2129 * this indicates that the skb we have been
2130 * handed has the 32-bit FCS CRC at the end...
2131 * we should react to that by snipping it off
2132 * because it will be recomputed and added
2135 if (skb->len < (iterator._max_length + FCS_LEN))
2138 skb_trim(skb, skb->len - FCS_LEN);
2140 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_WEP)
2141 info->flags &= ~IEEE80211_TX_INTFL_DONT_ENCRYPT;
2142 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG)
2143 info->flags &= ~IEEE80211_TX_CTL_DONTFRAG;
2146 case IEEE80211_RADIOTAP_TX_FLAGS:
2147 txflags = get_unaligned_le16(iterator.this_arg);
2148 if (txflags & IEEE80211_RADIOTAP_F_TX_NOACK)
2149 info->flags |= IEEE80211_TX_CTL_NO_ACK;
2150 if (txflags & IEEE80211_RADIOTAP_F_TX_NOSEQNO)
2151 info->control.flags |= IEEE80211_TX_CTRL_NO_SEQNO;
2152 if (txflags & IEEE80211_RADIOTAP_F_TX_ORDER)
2153 info->control.flags |=
2154 IEEE80211_TX_CTRL_DONT_REORDER;
2157 case IEEE80211_RADIOTAP_RATE:
2158 rate = *iterator.this_arg;
2163 case IEEE80211_RADIOTAP_ANTENNA:
2164 /* this can appear multiple times, keep a bitmap */
2165 info->control.antennas |= BIT(*iterator.this_arg);
2168 case IEEE80211_RADIOTAP_DATA_RETRIES:
2169 rate_retries = *iterator.this_arg;
2172 case IEEE80211_RADIOTAP_MCS:
2173 mcs_known = iterator.this_arg[0];
2174 mcs_flags = iterator.this_arg[1];
2175 if (!(mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_MCS))
2179 rate = iterator.this_arg[2];
2180 rate_flags = IEEE80211_TX_RC_MCS;
2182 if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_GI &&
2183 mcs_flags & IEEE80211_RADIOTAP_MCS_SGI)
2184 rate_flags |= IEEE80211_TX_RC_SHORT_GI;
2186 mcs_bw = mcs_flags & IEEE80211_RADIOTAP_MCS_BW_MASK;
2187 if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_BW &&
2188 mcs_bw == IEEE80211_RADIOTAP_MCS_BW_40)
2189 rate_flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
2191 if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_FEC &&
2192 mcs_flags & IEEE80211_RADIOTAP_MCS_FEC_LDPC)
2193 info->flags |= IEEE80211_TX_CTL_LDPC;
2195 if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_STBC) {
2196 u8 stbc = u8_get_bits(mcs_flags,
2197 IEEE80211_RADIOTAP_MCS_STBC_MASK);
2200 u32_encode_bits(stbc,
2201 IEEE80211_TX_CTL_STBC);
2205 case IEEE80211_RADIOTAP_VHT:
2206 vht_known = get_unaligned_le16(iterator.this_arg);
2209 rate_flags = IEEE80211_TX_RC_VHT_MCS;
2210 if ((vht_known & IEEE80211_RADIOTAP_VHT_KNOWN_GI) &&
2211 (iterator.this_arg[2] &
2212 IEEE80211_RADIOTAP_VHT_FLAG_SGI))
2213 rate_flags |= IEEE80211_TX_RC_SHORT_GI;
2215 IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH) {
2216 if (iterator.this_arg[3] == 1)
2218 IEEE80211_TX_RC_40_MHZ_WIDTH;
2219 else if (iterator.this_arg[3] == 4)
2221 IEEE80211_TX_RC_80_MHZ_WIDTH;
2222 else if (iterator.this_arg[3] == 11)
2224 IEEE80211_TX_RC_160_MHZ_WIDTH;
2227 vht_mcs = iterator.this_arg[4] >> 4;
2230 vht_nss = iterator.this_arg[4] & 0xF;
2231 if (!vht_nss || vht_nss > 8)
2236 * Please update the file
2237 * Documentation/networking/mac80211-injection.rst
2238 * when parsing new fields here.
2246 if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */
2250 struct ieee80211_supported_band *sband =
2251 local->hw.wiphy->bands[info->band];
2253 info->control.flags |= IEEE80211_TX_CTRL_RATE_INJECT;
2255 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
2256 info->control.rates[i].idx = -1;
2257 info->control.rates[i].flags = 0;
2258 info->control.rates[i].count = 0;
2261 if (rate_flags & IEEE80211_TX_RC_MCS) {
2262 /* reset antennas if not enough */
2263 if (IEEE80211_HT_MCS_CHAINS(rate) >
2264 hweight8(info->control.antennas))
2265 info->control.antennas = 0;
2267 info->control.rates[0].idx = rate;
2268 } else if (rate_flags & IEEE80211_TX_RC_VHT_MCS) {
2269 /* reset antennas if not enough */
2270 if (vht_nss > hweight8(info->control.antennas))
2271 info->control.antennas = 0;
2273 ieee80211_rate_set_vht(info->control.rates, vht_mcs,
2276 for (i = 0; i < sband->n_bitrates; i++) {
2277 if (rate * 5 != sband->bitrates[i].bitrate)
2280 info->control.rates[0].idx = i;
2285 if (info->control.rates[0].idx < 0)
2286 info->control.flags &= ~IEEE80211_TX_CTRL_RATE_INJECT;
2288 info->control.rates[0].flags = rate_flags;
2289 info->control.rates[0].count = min_t(u8, rate_retries + 1,
2290 local->hw.max_rate_tries);
2296 netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
2297 struct net_device *dev)
2299 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2300 struct ieee80211_chanctx_conf *chanctx_conf;
2301 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2302 struct ieee80211_hdr *hdr;
2303 struct ieee80211_sub_if_data *tmp_sdata, *sdata;
2304 struct cfg80211_chan_def *chandef;
2308 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2309 if (unlikely(!ieee80211_sdata_running(sdata)))
2312 memset(info, 0, sizeof(*info));
2313 info->flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2314 IEEE80211_TX_CTL_INJECTED;
2316 /* Sanity-check the length of the radiotap header */
2317 if (!ieee80211_validate_radiotap_len(skb))
2320 /* we now know there is a radiotap header with a length we can use */
2321 len_rthdr = ieee80211_get_radiotap_len(skb->data);
2324 * fix up the pointers accounting for the radiotap
2325 * header still being in there. We are being given
2326 * a precooked IEEE80211 header so no need for
2329 skb_set_mac_header(skb, len_rthdr);
2331 * these are just fixed to the end of the rt area since we
2332 * don't have any better information and at this point, nobody cares
2334 skb_set_network_header(skb, len_rthdr);
2335 skb_set_transport_header(skb, len_rthdr);
2337 if (skb->len < len_rthdr + 2)
2340 hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
2341 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2343 if (skb->len < len_rthdr + hdrlen)
2347 * Initialize skb->protocol if the injected frame is a data frame
2348 * carrying a rfc1042 header
2350 if (ieee80211_is_data(hdr->frame_control) &&
2351 skb->len >= len_rthdr + hdrlen + sizeof(rfc1042_header) + 2) {
2352 u8 *payload = (u8 *)hdr + hdrlen;
2354 if (ether_addr_equal(payload, rfc1042_header))
2355 skb->protocol = cpu_to_be16((payload[6] << 8) |
2362 * We process outgoing injected frames that have a local address
2363 * we handle as though they are non-injected frames.
2364 * This code here isn't entirely correct, the local MAC address
2365 * isn't always enough to find the interface to use; for proper
2366 * VLAN support we have an nl80211-based mechanism.
2368 * This is necessary, for example, for old hostapd versions that
2369 * don't use nl80211-based management TX/RX.
2371 list_for_each_entry_rcu(tmp_sdata, &local->interfaces, list) {
2372 if (!ieee80211_sdata_running(tmp_sdata))
2374 if (tmp_sdata->vif.type == NL80211_IFTYPE_MONITOR ||
2375 tmp_sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
2377 if (ether_addr_equal(tmp_sdata->vif.addr, hdr->addr2)) {
2383 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
2384 if (!chanctx_conf) {
2385 tmp_sdata = rcu_dereference(local->monitor_sdata);
2388 rcu_dereference(tmp_sdata->vif.bss_conf.chanctx_conf);
2392 chandef = &chanctx_conf->def;
2397 * If driver/HW supports IEEE80211_CHAN_CAN_MONITOR we still
2398 * shouldn't transmit on disabled channels.
2400 if (!cfg80211_chandef_usable(local->hw.wiphy, chandef,
2401 IEEE80211_CHAN_DISABLED))
2405 * Frame injection is not allowed if beaconing is not allowed
2406 * or if we need radar detection. Beaconing is usually not allowed when
2407 * the mode or operation (Adhoc, AP, Mesh) does not support DFS.
2408 * Passive scan is also used in world regulatory domains where
2409 * your country is not known and as such it should be treated as
2410 * NO TX unless the channel is explicitly allowed in which case
2411 * your current regulatory domain would not have the passive scan
2414 * Since AP mode uses monitor interfaces to inject/TX management
2415 * frames we can make AP mode the exception to this rule once it
2416 * supports radar detection as its implementation can deal with
2417 * radar detection by itself. We can do that later by adding a
2418 * monitor flag interfaces used for AP support.
2420 if (!cfg80211_reg_can_beacon(local->hw.wiphy, chandef,
2424 info->band = chandef->chan->band;
2426 /* Initialize skb->priority according to frame type and TID class,
2427 * with respect to the sub interface that the frame will actually
2428 * be transmitted on. If the DONT_REORDER flag is set, the original
2429 * skb-priority is preserved to assure frames injected with this
2430 * flag are not reordered relative to each other.
2432 ieee80211_select_queue_80211(sdata, skb, hdr);
2433 skb_set_queue_mapping(skb, ieee80211_ac_from_tid(skb->priority));
2436 * Process the radiotap header. This will now take into account the
2437 * selected chandef above to accurately set injection rates and
2440 if (!ieee80211_parse_tx_radiotap(skb, dev))
2443 /* remove the injection radiotap header */
2444 skb_pull(skb, len_rthdr);
2446 ieee80211_xmit(sdata, NULL, skb);
2449 return NETDEV_TX_OK;
2455 return NETDEV_TX_OK; /* meaning, we dealt with the skb */
2458 static inline bool ieee80211_is_tdls_setup(struct sk_buff *skb)
2460 u16 ethertype = (skb->data[12] << 8) | skb->data[13];
2462 return ethertype == ETH_P_TDLS &&
2464 skb->data[14] == WLAN_TDLS_SNAP_RFTYPE;
2467 int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata,
2468 struct sk_buff *skb,
2469 struct sta_info **sta_out)
2471 struct sta_info *sta;
2473 switch (sdata->vif.type) {
2474 case NL80211_IFTYPE_AP_VLAN:
2475 sta = rcu_dereference(sdata->u.vlan.sta);
2479 } else if (sdata->wdev.use_4addr) {
2483 case NL80211_IFTYPE_AP:
2484 case NL80211_IFTYPE_OCB:
2485 case NL80211_IFTYPE_ADHOC:
2486 if (is_multicast_ether_addr(skb->data)) {
2487 *sta_out = ERR_PTR(-ENOENT);
2490 sta = sta_info_get_bss(sdata, skb->data);
2492 #ifdef CONFIG_MAC80211_MESH
2493 case NL80211_IFTYPE_MESH_POINT:
2494 /* determined much later */
2498 case NL80211_IFTYPE_STATION:
2499 if (sdata->wdev.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) {
2500 sta = sta_info_get(sdata, skb->data);
2501 if (sta && test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
2502 if (test_sta_flag(sta,
2503 WLAN_STA_TDLS_PEER_AUTH)) {
2509 * TDLS link during setup - throw out frames to
2510 * peer. Allow TDLS-setup frames to unauthorized
2511 * peers for the special case of a link teardown
2512 * after a TDLS sta is removed due to being
2515 if (!ieee80211_is_tdls_setup(skb))
2521 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
2529 *sta_out = sta ?: ERR_PTR(-ENOENT);
2533 static u16 ieee80211_store_ack_skb(struct ieee80211_local *local,
2534 struct sk_buff *skb,
2538 struct sk_buff *ack_skb;
2542 ack_skb = skb_clone_sk(skb);
2544 ack_skb = skb_clone(skb, GFP_ATOMIC);
2547 unsigned long flags;
2550 spin_lock_irqsave(&local->ack_status_lock, flags);
2551 id = idr_alloc(&local->ack_status_frames, ack_skb,
2552 1, 0x2000, GFP_ATOMIC);
2553 spin_unlock_irqrestore(&local->ack_status_lock, flags);
2557 *info_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
2559 *cookie = ieee80211_mgmt_tx_cookie(local);
2560 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
2571 * ieee80211_build_hdr - build 802.11 header in the given frame
2572 * @sdata: virtual interface to build the header for
2573 * @skb: the skb to build the header in
2574 * @info_flags: skb flags to set
2575 * @sta: the station pointer
2576 * @ctrl_flags: info control flags to set
2577 * @cookie: cookie pointer to fill (if not %NULL)
2579 * This function takes the skb with 802.3 header and reformats the header to
2580 * the appropriate IEEE 802.11 header based on which interface the packet is
2581 * being transmitted on.
2583 * Note that this function also takes care of the TX status request and
2584 * potential unsharing of the SKB - this needs to be interleaved with the
2587 * The function requires the read-side RCU lock held
2589 * Returns: the (possibly reallocated) skb or an ERR_PTR() code
2591 static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata,
2592 struct sk_buff *skb, u32 info_flags,
2593 struct sta_info *sta, u32 ctrl_flags,
2596 struct ieee80211_local *local = sdata->local;
2597 struct ieee80211_tx_info *info;
2599 u16 ethertype, hdrlen, meshhdrlen = 0;
2601 struct ieee80211_hdr hdr;
2602 struct ieee80211s_hdr mesh_hdr __maybe_unused;
2603 struct mesh_path __maybe_unused *mppath = NULL, *mpath = NULL;
2604 const u8 *encaps_data;
2605 int encaps_len, skip_header_bytes;
2606 bool wme_sta = false, authorized = false;
2610 struct ieee80211_chanctx_conf *chanctx_conf = NULL;
2611 enum nl80211_band band;
2613 u8 link_id = u32_get_bits(ctrl_flags, IEEE80211_TX_CTRL_MLO_LINK);
2618 #ifdef CONFIG_MAC80211_DEBUGFS
2619 if (local->force_tx_status)
2620 info_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
2623 /* convert Ethernet header to proper 802.11 header (based on
2624 * operation mode) */
2625 ethertype = (skb->data[12] << 8) | skb->data[13];
2626 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
2628 if (!ieee80211_vif_is_mld(&sdata->vif))
2630 rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
2632 switch (sdata->vif.type) {
2633 case NL80211_IFTYPE_AP_VLAN:
2634 if (sdata->wdev.use_4addr) {
2635 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
2637 memcpy(hdr.addr1, sta->sta.addr, ETH_ALEN);
2638 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
2639 memcpy(hdr.addr3, skb->data, ETH_ALEN);
2640 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
2642 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
2643 wme_sta = sta->sta.wme;
2645 if (!ieee80211_vif_is_mld(&sdata->vif)) {
2646 struct ieee80211_sub_if_data *ap_sdata;
2648 /* override chanctx_conf from AP (we don't have one) */
2649 ap_sdata = container_of(sdata->bss,
2650 struct ieee80211_sub_if_data,
2653 rcu_dereference(ap_sdata->vif.bss_conf.chanctx_conf);
2655 if (sdata->wdev.use_4addr)
2658 case NL80211_IFTYPE_AP:
2659 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
2661 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2663 if (ieee80211_vif_is_mld(&sdata->vif) && sta && !sta->sta.mlo) {
2664 struct ieee80211_link_data *link;
2666 link_id = sta->deflink.link_id;
2667 link = rcu_dereference(sdata->link[link_id]);
2668 if (WARN_ON(!link)) {
2672 memcpy(hdr.addr2, link->conf->addr, ETH_ALEN);
2673 } else if (link_id == IEEE80211_LINK_UNSPECIFIED ||
2674 (sta && sta->sta.mlo)) {
2675 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
2677 struct ieee80211_bss_conf *conf;
2679 conf = rcu_dereference(sdata->vif.link_conf[link_id]);
2680 if (unlikely(!conf)) {
2685 memcpy(hdr.addr2, conf->addr, ETH_ALEN);
2688 memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
2691 #ifdef CONFIG_MAC80211_MESH
2692 case NL80211_IFTYPE_MESH_POINT:
2693 if (!is_multicast_ether_addr(skb->data)) {
2694 struct sta_info *next_hop;
2695 bool mpp_lookup = true;
2697 mpath = mesh_path_lookup(sdata, skb->data);
2700 next_hop = rcu_dereference(mpath->next_hop);
2702 !(mpath->flags & (MESH_PATH_ACTIVE |
2703 MESH_PATH_RESOLVING)))
2708 mppath = mpp_path_lookup(sdata, skb->data);
2710 mppath->exp_time = jiffies;
2713 if (mppath && mpath)
2714 mesh_path_del(sdata, mpath->dst);
2718 * Use address extension if it is a packet from
2719 * another interface or if we know the destination
2720 * is being proxied by a portal (i.e. portal address
2721 * differs from proxied address)
2723 if (ether_addr_equal(sdata->vif.addr, skb->data + ETH_ALEN) &&
2724 !(mppath && !ether_addr_equal(mppath->mpp, skb->data))) {
2725 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
2726 skb->data, skb->data + ETH_ALEN);
2727 meshhdrlen = ieee80211_new_mesh_header(sdata, &mesh_hdr,
2730 /* DS -> MBSS (802.11-2012 13.11.3.3).
2731 * For unicast with unknown forwarding information,
2732 * destination might be in the MBSS or if that fails
2733 * forwarded to another mesh gate. In either case
2734 * resolution will be handled in ieee80211_xmit(), so
2735 * leave the original DA. This also works for mcast */
2736 const u8 *mesh_da = skb->data;
2739 mesh_da = mppath->mpp;
2741 mesh_da = mpath->dst;
2743 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
2744 mesh_da, sdata->vif.addr);
2745 if (is_multicast_ether_addr(mesh_da))
2746 /* DA TA mSA AE:SA */
2747 meshhdrlen = ieee80211_new_mesh_header(
2749 skb->data + ETH_ALEN, NULL);
2751 /* RA TA mDA mSA AE:DA SA */
2752 meshhdrlen = ieee80211_new_mesh_header(
2753 sdata, &mesh_hdr, skb->data,
2754 skb->data + ETH_ALEN);
2758 /* For injected frames, fill RA right away as nexthop lookup
2761 if ((ctrl_flags & IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP) &&
2762 is_zero_ether_addr(hdr.addr1))
2763 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2766 case NL80211_IFTYPE_STATION:
2767 /* we already did checks when looking up the RA STA */
2768 tdls_peer = test_sta_flag(sta, WLAN_STA_TDLS_PEER);
2771 /* For TDLS only one link can be valid with peer STA */
2772 int tdls_link_id = sta->sta.valid_links ?
2773 __ffs(sta->sta.valid_links) : 0;
2774 struct ieee80211_link_data *link;
2777 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2778 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2779 link = rcu_dereference(sdata->link[tdls_link_id]);
2780 if (WARN_ON_ONCE(!link)) {
2784 memcpy(hdr.addr3, link->u.mgd.bssid, ETH_ALEN);
2786 } else if (sdata->u.mgd.use_4addr &&
2787 cpu_to_be16(ethertype) != sdata->control_port_protocol) {
2788 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
2789 IEEE80211_FCTL_TODS);
2791 memcpy(hdr.addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN);
2792 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
2793 memcpy(hdr.addr3, skb->data, ETH_ALEN);
2794 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
2797 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
2799 memcpy(hdr.addr1, sdata->vif.cfg.ap_addr, ETH_ALEN);
2800 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2801 memcpy(hdr.addr3, skb->data, ETH_ALEN);
2805 case NL80211_IFTYPE_OCB:
2807 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2808 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2809 eth_broadcast_addr(hdr.addr3);
2812 case NL80211_IFTYPE_ADHOC:
2814 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2815 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2816 memcpy(hdr.addr3, sdata->u.ibss.bssid, ETH_ALEN);
2824 if (!chanctx_conf) {
2825 if (!ieee80211_vif_is_mld(&sdata->vif)) {
2829 /* MLD transmissions must not rely on the band */
2832 band = chanctx_conf->def.chan->band;
2835 multicast = is_multicast_ether_addr(hdr.addr1);
2837 /* sta is always NULL for mesh */
2839 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
2840 wme_sta = sta->sta.wme;
2841 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
2842 /* For mesh, the use of the QoS header is mandatory */
2846 /* receiver does QoS (which also means we do) use it */
2848 fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
2853 * Drop unicast frames to unauthorised stations unless they are
2854 * EAPOL frames from the local station.
2856 if (unlikely(!ieee80211_vif_is_mesh(&sdata->vif) &&
2857 (sdata->vif.type != NL80211_IFTYPE_OCB) &&
2858 !multicast && !authorized &&
2859 (cpu_to_be16(ethertype) != sdata->control_port_protocol ||
2860 !ieee80211_is_our_addr(sdata, skb->data + ETH_ALEN, NULL)))) {
2861 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2862 net_info_ratelimited("%s: dropped frame to %pM (unauthorized port)\n",
2863 sdata->name, hdr.addr1);
2866 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
2872 if (unlikely(!multicast &&
2874 skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS) ||
2875 ctrl_flags & IEEE80211_TX_CTL_REQ_TX_STATUS)))
2876 info_id = ieee80211_store_ack_skb(local, skb, &info_flags,
2880 * If the skb is shared we need to obtain our own copy.
2882 skb = skb_share_check(skb, GFP_ATOMIC);
2883 if (unlikely(!skb)) {
2888 hdr.frame_control = fc;
2889 hdr.duration_id = 0;
2892 skip_header_bytes = ETH_HLEN;
2893 if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
2894 encaps_data = bridge_tunnel_header;
2895 encaps_len = sizeof(bridge_tunnel_header);
2896 skip_header_bytes -= 2;
2897 } else if (ethertype >= ETH_P_802_3_MIN) {
2898 encaps_data = rfc1042_header;
2899 encaps_len = sizeof(rfc1042_header);
2900 skip_header_bytes -= 2;
2906 skb_pull(skb, skip_header_bytes);
2907 head_need = hdrlen + encaps_len + meshhdrlen - skb_headroom(skb);
2910 * So we need to modify the skb header and hence need a copy of
2911 * that. The head_need variable above doesn't, so far, include
2912 * the needed header space that we don't need right away. If we
2913 * can, then we don't reallocate right now but only after the
2914 * frame arrives at the master device (if it does...)
2916 * If we cannot, however, then we will reallocate to include all
2917 * the ever needed space. Also, if we need to reallocate it anyway,
2918 * make it big enough for everything we may ever need.
2921 if (head_need > 0 || skb_cloned(skb)) {
2922 head_need += IEEE80211_ENCRYPT_HEADROOM;
2923 head_need += local->tx_headroom;
2924 head_need = max_t(int, 0, head_need);
2925 if (ieee80211_skb_resize(sdata, skb, head_need, ENCRYPT_DATA)) {
2926 ieee80211_free_txskb(&local->hw, skb);
2928 return ERR_PTR(-ENOMEM);
2933 memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
2935 #ifdef CONFIG_MAC80211_MESH
2937 memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen);
2940 if (ieee80211_is_data_qos(fc)) {
2941 __le16 *qos_control;
2943 qos_control = skb_push(skb, 2);
2944 memcpy(skb_push(skb, hdrlen - 2), &hdr, hdrlen - 2);
2946 * Maybe we could actually set some fields here, for now just
2947 * initialise to zero to indicate no special operation.
2951 memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
2953 skb_reset_mac_header(skb);
2955 info = IEEE80211_SKB_CB(skb);
2956 memset(info, 0, sizeof(*info));
2958 info->flags = info_flags;
2960 info->status_data = info_id;
2961 info->status_data_idr = 1;
2965 if (likely(!cookie)) {
2966 ctrl_flags |= u32_encode_bits(link_id,
2967 IEEE80211_TX_CTRL_MLO_LINK);
2969 unsigned int pre_conf_link_id;
2972 * ctrl_flags already have been set by
2973 * ieee80211_tx_control_port(), here
2974 * we just sanity check that
2977 pre_conf_link_id = u32_get_bits(ctrl_flags,
2978 IEEE80211_TX_CTRL_MLO_LINK);
2980 if (pre_conf_link_id != link_id &&
2981 link_id != IEEE80211_LINK_UNSPECIFIED) {
2982 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2983 net_info_ratelimited("%s: dropped frame to %pM with bad link ID request (%d vs. %d)\n",
2984 sdata->name, hdr.addr1,
2985 pre_conf_link_id, link_id);
2992 info->control.flags = ctrl_flags;
2997 return ERR_PTR(ret);
3001 * fast-xmit overview
3003 * The core idea of this fast-xmit is to remove per-packet checks by checking
3004 * them out of band. ieee80211_check_fast_xmit() implements the out-of-band
3005 * checks that are needed to get the sta->fast_tx pointer assigned, after which
3006 * much less work can be done per packet. For example, fragmentation must be
3007 * disabled or the fast_tx pointer will not be set. All the conditions are seen
3010 * Once assigned, the fast_tx data structure also caches the per-packet 802.11
3011 * header and other data to aid packet processing in ieee80211_xmit_fast().
3013 * The most difficult part of this is that when any of these assumptions
3014 * change, an external trigger (i.e. a call to ieee80211_clear_fast_xmit(),
3015 * ieee80211_check_fast_xmit() or friends) is required to reset the data,
3016 * since the per-packet code no longer checks the conditions. This is reflected
3017 * by the calls to these functions throughout the rest of the code, and must be
3018 * maintained if any of the TX path checks change.
3021 void ieee80211_check_fast_xmit(struct sta_info *sta)
3023 struct ieee80211_fast_tx build = {}, *fast_tx = NULL, *old;
3024 struct ieee80211_local *local = sta->local;
3025 struct ieee80211_sub_if_data *sdata = sta->sdata;
3026 struct ieee80211_hdr *hdr = (void *)build.hdr;
3027 struct ieee80211_chanctx_conf *chanctx_conf;
3030 if (!ieee80211_hw_check(&local->hw, SUPPORT_FAST_XMIT))
3033 if (ieee80211_vif_is_mesh(&sdata->vif))
3034 mesh_fast_tx_flush_sta(sdata, sta);
3036 /* Locking here protects both the pointer itself, and against concurrent
3037 * invocations winning data access races to, e.g., the key pointer that
3039 * Without it, the invocation of this function right after the key
3040 * pointer changes wouldn't be sufficient, as another CPU could access
3041 * the pointer, then stall, and then do the cache update after the CPU
3042 * that invalidated the key.
3043 * With the locking, such scenarios cannot happen as the check for the
3044 * key and the fast-tx assignment are done atomically, so the CPU that
3045 * modifies the key will either wait or other one will see the key
3046 * cleared/changed already.
3048 spin_lock_bh(&sta->lock);
3049 if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
3050 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
3051 sdata->vif.type == NL80211_IFTYPE_STATION)
3054 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED) || !sta->uploaded)
3057 if (test_sta_flag(sta, WLAN_STA_PS_STA) ||
3058 test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
3059 test_sta_flag(sta, WLAN_STA_PS_DELIVER) ||
3060 test_sta_flag(sta, WLAN_STA_CLEAR_PS_FILT))
3063 if (sdata->noack_map)
3066 /* fast-xmit doesn't handle fragmentation at all */
3067 if (local->hw.wiphy->frag_threshold != (u32)-1 &&
3068 !ieee80211_hw_check(&local->hw, SUPPORTS_TX_FRAG))
3071 if (!ieee80211_vif_is_mld(&sdata->vif)) {
3074 rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
3075 if (!chanctx_conf) {
3079 build.band = chanctx_conf->def.chan->band;
3082 /* MLD transmissions must not rely on the band */
3086 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
3088 switch (sdata->vif.type) {
3089 case NL80211_IFTYPE_ADHOC:
3091 build.da_offs = offsetof(struct ieee80211_hdr, addr1);
3092 build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3093 memcpy(hdr->addr3, sdata->u.ibss.bssid, ETH_ALEN);
3096 case NL80211_IFTYPE_STATION:
3097 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
3098 /* For TDLS only one link can be valid with peer STA */
3099 int tdls_link_id = sta->sta.valid_links ?
3100 __ffs(sta->sta.valid_links) : 0;
3101 struct ieee80211_link_data *link;
3104 build.da_offs = offsetof(struct ieee80211_hdr, addr1);
3105 build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3107 link = rcu_dereference(sdata->link[tdls_link_id]);
3108 if (!WARN_ON_ONCE(!link))
3109 memcpy(hdr->addr3, link->u.mgd.bssid, ETH_ALEN);
3115 if (sdata->u.mgd.use_4addr) {
3116 /* non-regular ethertype cannot use the fastpath */
3117 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
3118 IEEE80211_FCTL_TODS);
3120 memcpy(hdr->addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN);
3121 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
3122 build.da_offs = offsetof(struct ieee80211_hdr, addr3);
3123 build.sa_offs = offsetof(struct ieee80211_hdr, addr4);
3127 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
3129 memcpy(hdr->addr1, sdata->vif.cfg.ap_addr, ETH_ALEN);
3130 build.da_offs = offsetof(struct ieee80211_hdr, addr3);
3131 build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3134 case NL80211_IFTYPE_AP_VLAN:
3135 if (sdata->wdev.use_4addr) {
3136 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
3137 IEEE80211_FCTL_TODS);
3139 memcpy(hdr->addr1, sta->sta.addr, ETH_ALEN);
3140 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
3141 build.da_offs = offsetof(struct ieee80211_hdr, addr3);
3142 build.sa_offs = offsetof(struct ieee80211_hdr, addr4);
3147 case NL80211_IFTYPE_AP:
3148 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
3150 build.da_offs = offsetof(struct ieee80211_hdr, addr1);
3151 if (sta->sta.mlo || !ieee80211_vif_is_mld(&sdata->vif)) {
3152 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
3154 unsigned int link_id = sta->deflink.link_id;
3155 struct ieee80211_link_data *link;
3158 link = rcu_dereference(sdata->link[link_id]);
3159 if (WARN_ON(!link)) {
3163 memcpy(hdr->addr2, link->conf->addr, ETH_ALEN);
3166 build.sa_offs = offsetof(struct ieee80211_hdr, addr3);
3170 /* not handled on fast-xmit */
3176 fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3179 /* We store the key here so there's no point in using rcu_dereference()
3180 * but that's fine because the code that changes the pointers will call
3181 * this function after doing so. For a single CPU that would be enough,
3182 * for multiple see the comment above.
3184 build.key = rcu_access_pointer(sta->ptk[sta->ptk_idx]);
3186 build.key = rcu_access_pointer(sdata->default_unicast_key);
3188 bool gen_iv, iv_spc, mmic;
3190 gen_iv = build.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV;
3191 iv_spc = build.key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3192 mmic = build.key->conf.flags &
3193 (IEEE80211_KEY_FLAG_GENERATE_MMIC |
3194 IEEE80211_KEY_FLAG_PUT_MIC_SPACE);
3196 /* don't handle software crypto */
3197 if (!(build.key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
3200 /* Key is being removed */
3201 if (build.key->flags & KEY_FLAG_TAINTED)
3204 switch (build.key->conf.cipher) {
3205 case WLAN_CIPHER_SUITE_CCMP:
3206 case WLAN_CIPHER_SUITE_CCMP_256:
3208 build.pn_offs = build.hdr_len;
3209 if (gen_iv || iv_spc)
3210 build.hdr_len += IEEE80211_CCMP_HDR_LEN;
3212 case WLAN_CIPHER_SUITE_GCMP:
3213 case WLAN_CIPHER_SUITE_GCMP_256:
3215 build.pn_offs = build.hdr_len;
3216 if (gen_iv || iv_spc)
3217 build.hdr_len += IEEE80211_GCMP_HDR_LEN;
3219 case WLAN_CIPHER_SUITE_TKIP:
3220 /* cannot handle MMIC or IV generation in xmit-fast */
3224 build.hdr_len += IEEE80211_TKIP_IV_LEN;
3226 case WLAN_CIPHER_SUITE_WEP40:
3227 case WLAN_CIPHER_SUITE_WEP104:
3228 /* cannot handle IV generation in fast-xmit */
3232 build.hdr_len += IEEE80211_WEP_IV_LEN;
3234 case WLAN_CIPHER_SUITE_AES_CMAC:
3235 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
3236 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3237 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3239 "management cipher suite 0x%x enabled for data\n",
3240 build.key->conf.cipher);
3243 /* we don't know how to generate IVs for this at all */
3244 if (WARN_ON(gen_iv))
3248 fc |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
3251 hdr->frame_control = fc;
3253 memcpy(build.hdr + build.hdr_len,
3254 rfc1042_header, sizeof(rfc1042_header));
3255 build.hdr_len += sizeof(rfc1042_header);
3257 fast_tx = kmemdup(&build, sizeof(build), GFP_ATOMIC);
3258 /* if the kmemdup fails, continue w/o fast_tx */
3261 /* we might have raced against another call to this function */
3262 old = rcu_dereference_protected(sta->fast_tx,
3263 lockdep_is_held(&sta->lock));
3264 rcu_assign_pointer(sta->fast_tx, fast_tx);
3266 kfree_rcu(old, rcu_head);
3267 spin_unlock_bh(&sta->lock);
3270 void ieee80211_check_fast_xmit_all(struct ieee80211_local *local)
3272 struct sta_info *sta;
3275 list_for_each_entry_rcu(sta, &local->sta_list, list)
3276 ieee80211_check_fast_xmit(sta);
3280 void ieee80211_check_fast_xmit_iface(struct ieee80211_sub_if_data *sdata)
3282 struct ieee80211_local *local = sdata->local;
3283 struct sta_info *sta;
3287 list_for_each_entry_rcu(sta, &local->sta_list, list) {
3288 if (sdata != sta->sdata &&
3289 (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
3291 ieee80211_check_fast_xmit(sta);
3297 void ieee80211_clear_fast_xmit(struct sta_info *sta)
3299 struct ieee80211_fast_tx *fast_tx;
3301 spin_lock_bh(&sta->lock);
3302 fast_tx = rcu_dereference_protected(sta->fast_tx,
3303 lockdep_is_held(&sta->lock));
3304 RCU_INIT_POINTER(sta->fast_tx, NULL);
3305 spin_unlock_bh(&sta->lock);
3308 kfree_rcu(fast_tx, rcu_head);
3311 static bool ieee80211_amsdu_realloc_pad(struct ieee80211_local *local,
3312 struct sk_buff *skb, int headroom)
3314 if (skb_headroom(skb) < headroom) {
3315 I802_DEBUG_INC(local->tx_expand_skb_head);
3317 if (pskb_expand_head(skb, headroom, 0, GFP_ATOMIC)) {
3318 wiphy_debug(local->hw.wiphy,
3319 "failed to reallocate TX buffer\n");
3327 static bool ieee80211_amsdu_prepare_head(struct ieee80211_sub_if_data *sdata,
3328 struct ieee80211_fast_tx *fast_tx,
3329 struct sk_buff *skb)
3331 struct ieee80211_local *local = sdata->local;
3332 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3333 struct ieee80211_hdr *hdr;
3334 struct ethhdr *amsdu_hdr;
3335 int hdr_len = fast_tx->hdr_len - sizeof(rfc1042_header);
3336 int subframe_len = skb->len - hdr_len;
3338 u8 *qc, *h_80211_src, *h_80211_dst;
3341 if (info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE)
3344 if (info->control.flags & IEEE80211_TX_CTRL_AMSDU)
3347 if (!ieee80211_amsdu_realloc_pad(local, skb,
3348 sizeof(*amsdu_hdr) +
3349 local->hw.extra_tx_headroom))
3352 data = skb_push(skb, sizeof(*amsdu_hdr));
3353 memmove(data, data + sizeof(*amsdu_hdr), hdr_len);
3355 amsdu_hdr = data + hdr_len;
3356 /* h_80211_src/dst is addr* field within hdr */
3357 h_80211_src = data + fast_tx->sa_offs;
3358 h_80211_dst = data + fast_tx->da_offs;
3360 amsdu_hdr->h_proto = cpu_to_be16(subframe_len);
3361 ether_addr_copy(amsdu_hdr->h_source, h_80211_src);
3362 ether_addr_copy(amsdu_hdr->h_dest, h_80211_dst);
3364 /* according to IEEE 802.11-2012 8.3.2 table 8-19, the outer SA/DA
3365 * fields needs to be changed to BSSID for A-MSDU frames depending
3366 * on FromDS/ToDS values.
3368 switch (sdata->vif.type) {
3369 case NL80211_IFTYPE_STATION:
3370 bssid = sdata->vif.cfg.ap_addr;
3372 case NL80211_IFTYPE_AP:
3373 case NL80211_IFTYPE_AP_VLAN:
3374 bssid = sdata->vif.addr;
3380 if (bssid && ieee80211_has_fromds(hdr->frame_control))
3381 ether_addr_copy(h_80211_src, bssid);
3383 if (bssid && ieee80211_has_tods(hdr->frame_control))
3384 ether_addr_copy(h_80211_dst, bssid);
3386 qc = ieee80211_get_qos_ctl(hdr);
3387 *qc |= IEEE80211_QOS_CTL_A_MSDU_PRESENT;
3389 info->control.flags |= IEEE80211_TX_CTRL_AMSDU;
3394 static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,
3395 struct sta_info *sta,
3396 struct ieee80211_fast_tx *fast_tx,
3397 struct sk_buff *skb,
3398 const u8 *da, const u8 *sa)
3400 struct ieee80211_local *local = sdata->local;
3401 struct fq *fq = &local->fq;
3403 struct fq_flow *flow;
3404 u8 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
3405 struct ieee80211_txq *txq = sta->sta.txq[tid];
3406 struct txq_info *txqi;
3407 struct sk_buff **frag_tail, *head;
3408 int subframe_len = skb->len - ETH_ALEN;
3409 u8 max_subframes = sta->sta.max_amsdu_subframes;
3410 int max_frags = local->hw.max_tx_fragments;
3411 int max_amsdu_len = sta->sta.cur->max_amsdu_len;
3417 unsigned int orig_len;
3418 int n = 2, nfrags, pad = 0;
3421 if (!ieee80211_hw_check(&local->hw, TX_AMSDU))
3424 if (sdata->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED)
3427 if (ieee80211_vif_is_mesh(&sdata->vif))
3430 if (skb_is_gso(skb))
3436 txqi = to_txq_info(txq);
3437 if (test_bit(IEEE80211_TXQ_NO_AMSDU, &txqi->flags))
3440 if (sta->sta.cur->max_rc_amsdu_len)
3441 max_amsdu_len = min_t(int, max_amsdu_len,
3442 sta->sta.cur->max_rc_amsdu_len);
3444 if (sta->sta.cur->max_tid_amsdu_len[tid])
3445 max_amsdu_len = min_t(int, max_amsdu_len,
3446 sta->sta.cur->max_tid_amsdu_len[tid]);
3448 flow_idx = fq_flow_idx(fq, skb);
3450 spin_lock_bh(&fq->lock);
3452 /* TODO: Ideally aggregation should be done on dequeue to remain
3453 * responsive to environment changes.
3457 flow = fq_flow_classify(fq, tin, flow_idx, skb);
3458 head = skb_peek_tail(&flow->queue);
3459 if (!head || skb_is_gso(head))
3462 orig_truesize = head->truesize;
3463 orig_len = head->len;
3465 if (skb->len + head->len > max_amsdu_len)
3468 nfrags = 1 + skb_shinfo(skb)->nr_frags;
3469 nfrags += 1 + skb_shinfo(head)->nr_frags;
3470 frag_tail = &skb_shinfo(head)->frag_list;
3471 while (*frag_tail) {
3472 nfrags += 1 + skb_shinfo(*frag_tail)->nr_frags;
3473 frag_tail = &(*frag_tail)->next;
3477 if (max_subframes && n > max_subframes)
3480 if (max_frags && nfrags > max_frags)
3483 if (!drv_can_aggregate_in_amsdu(local, head, skb))
3486 if (!ieee80211_amsdu_prepare_head(sdata, fast_tx, head))
3489 /* If n == 2, the "while (*frag_tail)" loop above didn't execute
3490 * and frag_tail should be &skb_shinfo(head)->frag_list.
3491 * However, ieee80211_amsdu_prepare_head() can reallocate it.
3492 * Reload frag_tail to have it pointing to the correct place.
3495 frag_tail = &skb_shinfo(head)->frag_list;
3498 * Pad out the previous subframe to a multiple of 4 by adding the
3499 * padding to the next one, that's being added. Note that head->len
3500 * is the length of the full A-MSDU, but that works since each time
3501 * we add a new subframe we pad out the previous one to a multiple
3502 * of 4 and thus it no longer matters in the next round.
3504 hdrlen = fast_tx->hdr_len - sizeof(rfc1042_header);
3505 if ((head->len - hdrlen) & 3)
3506 pad = 4 - ((head->len - hdrlen) & 3);
3508 if (!ieee80211_amsdu_realloc_pad(local, skb, sizeof(rfc1042_header) +
3513 data = skb_push(skb, ETH_ALEN + 2);
3514 ether_addr_copy(data, da);
3515 ether_addr_copy(data + ETH_ALEN, sa);
3517 data += 2 * ETH_ALEN;
3518 len = cpu_to_be16(subframe_len);
3519 memcpy(data, &len, 2);
3520 memcpy(data + 2, rfc1042_header, sizeof(rfc1042_header));
3522 memset(skb_push(skb, pad), 0, pad);
3524 head->len += skb->len;
3525 head->data_len += skb->len;
3529 fq->memory_usage += head->truesize - orig_truesize;
3530 if (head->len != orig_len) {
3531 flow->backlog += head->len - orig_len;
3532 tin->backlog_bytes += head->len - orig_len;
3535 spin_unlock_bh(&fq->lock);
3541 * Can be called while the sta lock is held. Anything that can cause packets to
3542 * be generated will cause deadlock!
3544 static ieee80211_tx_result
3545 ieee80211_xmit_fast_finish(struct ieee80211_sub_if_data *sdata,
3546 struct sta_info *sta, u8 pn_offs,
3547 struct ieee80211_key *key,
3548 struct ieee80211_tx_data *tx)
3550 struct sk_buff *skb = tx->skb;
3551 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3552 struct ieee80211_hdr *hdr = (void *)skb->data;
3553 u8 tid = IEEE80211_NUM_TIDS;
3555 if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL) &&
3556 ieee80211_tx_h_rate_ctrl(tx) != TX_CONTINUE)
3560 info->control.hw_key = &key->conf;
3562 dev_sw_netstats_tx_add(skb->dev, 1, skb->len);
3564 if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
3565 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
3566 hdr->seq_ctrl = ieee80211_tx_next_seq(sta, tid);
3568 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
3569 hdr->seq_ctrl = cpu_to_le16(sdata->sequence_number);
3570 sdata->sequence_number += 0x10;
3573 if (skb_shinfo(skb)->gso_size)
3574 sta->deflink.tx_stats.msdu[tid] +=
3575 DIV_ROUND_UP(skb->len, skb_shinfo(skb)->gso_size);
3577 sta->deflink.tx_stats.msdu[tid]++;
3579 info->hw_queue = sdata->vif.hw_queue[skb_get_queue_mapping(skb)];
3581 /* statistics normally done by ieee80211_tx_h_stats (but that
3582 * has to consider fragmentation, so is more complex)
3584 sta->deflink.tx_stats.bytes[skb_get_queue_mapping(skb)] += skb->len;
3585 sta->deflink.tx_stats.packets[skb_get_queue_mapping(skb)]++;
3589 u8 *crypto_hdr = skb->data + pn_offs;
3591 switch (key->conf.cipher) {
3592 case WLAN_CIPHER_SUITE_CCMP:
3593 case WLAN_CIPHER_SUITE_CCMP_256:
3594 case WLAN_CIPHER_SUITE_GCMP:
3595 case WLAN_CIPHER_SUITE_GCMP_256:
3596 pn = atomic64_inc_return(&key->conf.tx_pn);
3598 crypto_hdr[1] = pn >> 8;
3599 crypto_hdr[3] = 0x20 | (key->conf.keyidx << 6);
3600 crypto_hdr[4] = pn >> 16;
3601 crypto_hdr[5] = pn >> 24;
3602 crypto_hdr[6] = pn >> 32;
3603 crypto_hdr[7] = pn >> 40;
3611 static netdev_features_t
3612 ieee80211_sdata_netdev_features(struct ieee80211_sub_if_data *sdata)
3614 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
3615 return sdata->vif.netdev_features;
3620 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap);
3621 return sdata->vif.netdev_features;
3624 static struct sk_buff *
3625 ieee80211_tx_skb_fixup(struct sk_buff *skb, netdev_features_t features)
3627 if (skb_is_gso(skb)) {
3628 struct sk_buff *segs;
3630 segs = skb_gso_segment(skb, features);
3640 if (skb_needs_linearize(skb, features) && __skb_linearize(skb))
3643 if (skb->ip_summed == CHECKSUM_PARTIAL) {
3644 int ofs = skb_checksum_start_offset(skb);
3646 if (skb->encapsulation)
3647 skb_set_inner_transport_header(skb, ofs);
3649 skb_set_transport_header(skb, ofs);
3651 if (skb_csum_hwoffload_help(skb, features))
3655 skb_mark_not_on_list(skb);
3663 void __ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
3664 struct sta_info *sta,
3665 struct ieee80211_fast_tx *fast_tx,
3666 struct sk_buff *skb, bool ampdu,
3667 const u8 *da, const u8 *sa)
3669 struct ieee80211_local *local = sdata->local;
3670 struct ieee80211_hdr *hdr = (void *)fast_tx->hdr;
3671 struct ieee80211_tx_info *info;
3672 struct ieee80211_tx_data tx;
3673 ieee80211_tx_result r;
3674 int hw_headroom = sdata->local->hw.extra_tx_headroom;
3675 int extra_head = fast_tx->hdr_len - (ETH_HLEN - 2);
3677 skb = skb_share_check(skb, GFP_ATOMIC);
3681 if ((hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) &&
3682 ieee80211_amsdu_aggregate(sdata, sta, fast_tx, skb, da, sa))
3685 /* will not be crypto-handled beyond what we do here, so use false
3686 * as the may-encrypt argument for the resize to not account for
3687 * more room than we already have in 'extra_head'
3689 if (unlikely(ieee80211_skb_resize(sdata, skb,
3690 max_t(int, extra_head + hw_headroom -
3691 skb_headroom(skb), 0),
3695 hdr = skb_push(skb, extra_head);
3696 memcpy(skb->data, fast_tx->hdr, fast_tx->hdr_len);
3697 memcpy(skb->data + fast_tx->da_offs, da, ETH_ALEN);
3698 memcpy(skb->data + fast_tx->sa_offs, sa, ETH_ALEN);
3700 info = IEEE80211_SKB_CB(skb);
3701 memset(info, 0, sizeof(*info));
3702 info->band = fast_tx->band;
3703 info->control.vif = &sdata->vif;
3704 info->flags = IEEE80211_TX_CTL_FIRST_FRAGMENT |
3705 IEEE80211_TX_CTL_DONTFRAG;
3706 info->control.flags = IEEE80211_TX_CTRL_FAST_XMIT |
3707 u32_encode_bits(IEEE80211_LINK_UNSPECIFIED,
3708 IEEE80211_TX_CTRL_MLO_LINK);
3710 #ifdef CONFIG_MAC80211_DEBUGFS
3711 if (local->force_tx_status)
3712 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
3715 if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
3716 u8 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
3718 *ieee80211_get_qos_ctl(hdr) = tid;
3721 __skb_queue_head_init(&tx.skbs);
3723 tx.flags = IEEE80211_TX_UNICAST;
3727 tx.key = fast_tx->key;
3729 if (ieee80211_queue_skb(local, sdata, sta, skb))
3733 r = ieee80211_xmit_fast_finish(sdata, sta, fast_tx->pn_offs,
3739 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
3740 sdata = container_of(sdata->bss,
3741 struct ieee80211_sub_if_data, u.ap);
3743 __skb_queue_tail(&tx.skbs, skb);
3744 ieee80211_tx_frags(local, &sdata->vif, sta, &tx.skbs, false);
3751 static bool ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
3752 struct sta_info *sta,
3753 struct ieee80211_fast_tx *fast_tx,
3754 struct sk_buff *skb)
3756 u16 ethertype = (skb->data[12] << 8) | skb->data[13];
3757 struct ieee80211_hdr *hdr = (void *)fast_tx->hdr;
3758 struct tid_ampdu_tx *tid_tx = NULL;
3759 struct sk_buff *next;
3761 u8 tid = IEEE80211_NUM_TIDS;
3763 /* control port protocol needs a lot of special handling */
3764 if (cpu_to_be16(ethertype) == sdata->control_port_protocol)
3767 /* only RFC 1042 SNAP */
3768 if (ethertype < ETH_P_802_3_MIN)
3771 /* don't handle TX status request here either */
3772 if (skb->sk && skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS)
3775 if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
3776 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
3777 tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
3779 if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state))
3781 if (tid_tx->timeout)
3782 tid_tx->last_tx = jiffies;
3786 memcpy(ð, skb->data, ETH_HLEN - 2);
3788 /* after this point (skb is modified) we cannot return false */
3789 skb = ieee80211_tx_skb_fixup(skb, ieee80211_sdata_netdev_features(sdata));
3793 skb_list_walk_safe(skb, skb, next) {
3794 skb_mark_not_on_list(skb);
3795 __ieee80211_xmit_fast(sdata, sta, fast_tx, skb, tid_tx,
3796 eth.h_dest, eth.h_source);
3802 struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,
3803 struct ieee80211_txq *txq)
3805 struct ieee80211_local *local = hw_to_local(hw);
3806 struct txq_info *txqi = container_of(txq, struct txq_info, txq);
3807 struct ieee80211_hdr *hdr;
3808 struct sk_buff *skb = NULL;
3809 struct fq *fq = &local->fq;
3810 struct fq_tin *tin = &txqi->tin;
3811 struct ieee80211_tx_info *info;
3812 struct ieee80211_tx_data tx;
3813 ieee80211_tx_result r;
3814 struct ieee80211_vif *vif = txq->vif;
3815 int q = vif->hw_queue[txq->ac];
3816 unsigned long flags;
3819 WARN_ON_ONCE(softirq_count() == 0);
3821 if (!ieee80211_txq_airtime_check(hw, txq))
3825 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
3826 q_stopped = local->queue_stop_reasons[q];
3827 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
3829 if (unlikely(q_stopped)) {
3830 /* mark for waking later */
3831 set_bit(IEEE80211_TXQ_DIRTY, &txqi->flags);
3835 spin_lock_bh(&fq->lock);
3837 /* Make sure fragments stay together. */
3838 skb = __skb_dequeue(&txqi->frags);
3839 if (unlikely(skb)) {
3840 if (!(IEEE80211_SKB_CB(skb)->control.flags &
3841 IEEE80211_TX_INTCFL_NEED_TXPROCESSING))
3843 IEEE80211_SKB_CB(skb)->control.flags &=
3844 ~IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
3846 if (unlikely(test_bit(IEEE80211_TXQ_STOP, &txqi->flags)))
3849 skb = fq_tin_dequeue(fq, tin, fq_tin_dequeue_func);
3855 spin_unlock_bh(&fq->lock);
3857 hdr = (struct ieee80211_hdr *)skb->data;
3858 info = IEEE80211_SKB_CB(skb);
3860 memset(&tx, 0, sizeof(tx));
3861 __skb_queue_head_init(&tx.skbs);
3864 tx.sdata = vif_to_sdata(info->control.vif);
3867 tx.sta = container_of(txq->sta, struct sta_info, sta);
3869 * Drop unicast frames to unauthorised stations unless they are
3870 * injected frames or EAPOL frames from the local station.
3872 if (unlikely(!(info->flags & IEEE80211_TX_CTL_INJECTED) &&
3873 ieee80211_is_data(hdr->frame_control) &&
3874 !ieee80211_vif_is_mesh(&tx.sdata->vif) &&
3875 tx.sdata->vif.type != NL80211_IFTYPE_OCB &&
3876 !is_multicast_ether_addr(hdr->addr1) &&
3877 !test_sta_flag(tx.sta, WLAN_STA_AUTHORIZED) &&
3878 (!(info->control.flags &
3879 IEEE80211_TX_CTRL_PORT_CTRL_PROTO) ||
3880 !ieee80211_is_our_addr(tx.sdata, hdr->addr2,
3882 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
3883 ieee80211_free_txskb(&local->hw, skb);
3889 * The key can be removed while the packet was queued, so need to call
3890 * this here to get the current key.
3892 r = ieee80211_tx_h_select_key(&tx);
3893 if (r != TX_CONTINUE) {
3894 ieee80211_free_txskb(&local->hw, skb);
3898 if (test_bit(IEEE80211_TXQ_AMPDU, &txqi->flags))
3899 info->flags |= (IEEE80211_TX_CTL_AMPDU |
3900 IEEE80211_TX_CTL_DONTFRAG);
3902 if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) {
3903 if (!ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
3904 r = ieee80211_tx_h_rate_ctrl(&tx);
3905 if (r != TX_CONTINUE) {
3906 ieee80211_free_txskb(&local->hw, skb);
3913 if (info->control.flags & IEEE80211_TX_CTRL_FAST_XMIT) {
3914 struct sta_info *sta = container_of(txq->sta, struct sta_info,
3919 (tx.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
3920 pn_offs = ieee80211_hdrlen(hdr->frame_control);
3922 r = ieee80211_xmit_fast_finish(sta->sdata, sta, pn_offs,
3924 if (r != TX_CONTINUE) {
3925 ieee80211_free_txskb(&local->hw, skb);
3929 if (invoke_tx_handlers_late(&tx))
3932 skb = __skb_dequeue(&tx.skbs);
3933 info = IEEE80211_SKB_CB(skb);
3935 if (!skb_queue_empty(&tx.skbs)) {
3936 spin_lock_bh(&fq->lock);
3937 skb_queue_splice_tail(&tx.skbs, &txqi->frags);
3938 spin_unlock_bh(&fq->lock);
3942 if (skb_has_frag_list(skb) &&
3943 !ieee80211_hw_check(&local->hw, TX_FRAG_LIST)) {
3944 if (skb_linearize(skb)) {
3945 ieee80211_free_txskb(&local->hw, skb);
3950 switch (tx.sdata->vif.type) {
3951 case NL80211_IFTYPE_MONITOR:
3952 if (tx.sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) {
3953 vif = &tx.sdata->vif;
3956 tx.sdata = rcu_dereference(local->monitor_sdata);
3958 vif = &tx.sdata->vif;
3960 vif->hw_queue[skb_get_queue_mapping(skb)];
3961 } else if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) {
3962 ieee80211_free_txskb(&local->hw, skb);
3965 info->control.vif = NULL;
3969 case NL80211_IFTYPE_AP_VLAN:
3970 tx.sdata = container_of(tx.sdata->bss,
3971 struct ieee80211_sub_if_data, u.ap);
3974 vif = &tx.sdata->vif;
3979 info->control.vif = vif;
3982 wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL)) {
3983 bool ampdu = txq->ac != IEEE80211_AC_VO;
3986 airtime = ieee80211_calc_expected_tx_airtime(hw, vif, txq->sta,
3989 airtime = ieee80211_info_set_tx_time_est(info, airtime);
3990 ieee80211_sta_update_pending_airtime(local, tx.sta,
4000 spin_unlock_bh(&fq->lock);
4004 EXPORT_SYMBOL(ieee80211_tx_dequeue);
4006 static inline s32 ieee80211_sta_deficit(struct sta_info *sta, u8 ac)
4008 struct airtime_info *air_info = &sta->airtime[ac];
4010 return air_info->deficit - atomic_read(&air_info->aql_tx_pending);
4014 ieee80211_txq_set_active(struct txq_info *txqi)
4016 struct sta_info *sta;
4021 sta = container_of(txqi->txq.sta, struct sta_info, sta);
4022 sta->airtime[txqi->txq.ac].last_active = jiffies;
4026 ieee80211_txq_keep_active(struct txq_info *txqi)
4028 struct sta_info *sta;
4033 sta = container_of(txqi->txq.sta, struct sta_info, sta);
4034 if (ieee80211_sta_deficit(sta, txqi->txq.ac) >= 0)
4037 return ieee80211_sta_keep_active(sta, txqi->txq.ac);
4040 struct ieee80211_txq *ieee80211_next_txq(struct ieee80211_hw *hw, u8 ac)
4042 struct ieee80211_local *local = hw_to_local(hw);
4043 struct ieee80211_txq *ret = NULL;
4044 struct txq_info *txqi = NULL, *head = NULL;
4045 bool found_eligible_txq = false;
4047 spin_lock_bh(&local->active_txq_lock[ac]);
4049 if (!local->schedule_round[ac])
4053 txqi = list_first_entry_or_null(&local->active_txqs[ac],
4060 if (!found_eligible_txq)
4063 found_eligible_txq = false;
4069 if (txqi->txq.sta) {
4070 struct sta_info *sta = container_of(txqi->txq.sta,
4071 struct sta_info, sta);
4072 bool aql_check = ieee80211_txq_airtime_check(hw, &txqi->txq);
4073 s32 deficit = ieee80211_sta_deficit(sta, txqi->txq.ac);
4076 found_eligible_txq = true;
4079 sta->airtime[txqi->txq.ac].deficit +=
4080 sta->airtime_weight;
4082 if (deficit < 0 || !aql_check) {
4083 list_move_tail(&txqi->schedule_order,
4084 &local->active_txqs[txqi->txq.ac]);
4089 if (txqi->schedule_round == local->schedule_round[ac])
4092 list_del_init(&txqi->schedule_order);
4093 txqi->schedule_round = local->schedule_round[ac];
4097 spin_unlock_bh(&local->active_txq_lock[ac]);
4100 EXPORT_SYMBOL(ieee80211_next_txq);
4102 void __ieee80211_schedule_txq(struct ieee80211_hw *hw,
4103 struct ieee80211_txq *txq,
4106 struct ieee80211_local *local = hw_to_local(hw);
4107 struct txq_info *txqi = to_txq_info(txq);
4110 spin_lock_bh(&local->active_txq_lock[txq->ac]);
4112 has_queue = force || txq_has_queue(txq);
4113 if (list_empty(&txqi->schedule_order) &&
4114 (has_queue || ieee80211_txq_keep_active(txqi))) {
4115 /* If airtime accounting is active, always enqueue STAs at the
4116 * head of the list to ensure that they only get moved to the
4117 * back by the airtime DRR scheduler once they have a negative
4118 * deficit. A station that already has a negative deficit will
4119 * get immediately moved to the back of the list on the next
4120 * call to ieee80211_next_txq().
4122 if (txqi->txq.sta && local->airtime_flags && has_queue &&
4123 wiphy_ext_feature_isset(local->hw.wiphy,
4124 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
4125 list_add(&txqi->schedule_order,
4126 &local->active_txqs[txq->ac]);
4128 list_add_tail(&txqi->schedule_order,
4129 &local->active_txqs[txq->ac]);
4131 ieee80211_txq_set_active(txqi);
4134 spin_unlock_bh(&local->active_txq_lock[txq->ac]);
4136 EXPORT_SYMBOL(__ieee80211_schedule_txq);
4138 DEFINE_STATIC_KEY_FALSE(aql_disable);
4140 bool ieee80211_txq_airtime_check(struct ieee80211_hw *hw,
4141 struct ieee80211_txq *txq)
4143 struct sta_info *sta;
4144 struct ieee80211_local *local = hw_to_local(hw);
4146 if (!wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL))
4149 if (static_branch_unlikely(&aql_disable))
4155 if (unlikely(txq->tid == IEEE80211_NUM_TIDS))
4158 sta = container_of(txq->sta, struct sta_info, sta);
4159 if (atomic_read(&sta->airtime[txq->ac].aql_tx_pending) <
4160 sta->airtime[txq->ac].aql_limit_low)
4163 if (atomic_read(&local->aql_total_pending_airtime) <
4164 local->aql_threshold &&
4165 atomic_read(&sta->airtime[txq->ac].aql_tx_pending) <
4166 sta->airtime[txq->ac].aql_limit_high)
4171 EXPORT_SYMBOL(ieee80211_txq_airtime_check);
4174 ieee80211_txq_schedule_airtime_check(struct ieee80211_local *local, u8 ac)
4176 unsigned int num_txq = 0;
4177 struct txq_info *txq;
4180 if (!wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL))
4183 list_for_each_entry(txq, &local->active_txqs[ac], schedule_order)
4186 aql_limit = (num_txq - 1) * local->aql_txq_limit_low[ac] / 2 +
4187 local->aql_txq_limit_high[ac];
4189 return atomic_read(&local->aql_ac_pending_airtime[ac]) < aql_limit;
4192 bool ieee80211_txq_may_transmit(struct ieee80211_hw *hw,
4193 struct ieee80211_txq *txq)
4195 struct ieee80211_local *local = hw_to_local(hw);
4196 struct txq_info *iter, *tmp, *txqi = to_txq_info(txq);
4197 struct sta_info *sta;
4200 spin_lock_bh(&local->active_txq_lock[ac]);
4205 if (list_empty(&txqi->schedule_order))
4208 if (!ieee80211_txq_schedule_airtime_check(local, ac))
4211 list_for_each_entry_safe(iter, tmp, &local->active_txqs[ac],
4216 if (!iter->txq.sta) {
4217 list_move_tail(&iter->schedule_order,
4218 &local->active_txqs[ac]);
4221 sta = container_of(iter->txq.sta, struct sta_info, sta);
4222 if (ieee80211_sta_deficit(sta, ac) < 0)
4223 sta->airtime[ac].deficit += sta->airtime_weight;
4224 list_move_tail(&iter->schedule_order, &local->active_txqs[ac]);
4227 sta = container_of(txqi->txq.sta, struct sta_info, sta);
4228 if (sta->airtime[ac].deficit >= 0)
4231 sta->airtime[ac].deficit += sta->airtime_weight;
4232 list_move_tail(&txqi->schedule_order, &local->active_txqs[ac]);
4233 spin_unlock_bh(&local->active_txq_lock[ac]);
4237 if (!list_empty(&txqi->schedule_order))
4238 list_del_init(&txqi->schedule_order);
4239 spin_unlock_bh(&local->active_txq_lock[ac]);
4243 EXPORT_SYMBOL(ieee80211_txq_may_transmit);
4245 void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac)
4247 struct ieee80211_local *local = hw_to_local(hw);
4249 spin_lock_bh(&local->active_txq_lock[ac]);
4251 if (ieee80211_txq_schedule_airtime_check(local, ac)) {
4252 local->schedule_round[ac]++;
4253 if (!local->schedule_round[ac])
4254 local->schedule_round[ac]++;
4256 local->schedule_round[ac] = 0;
4259 spin_unlock_bh(&local->active_txq_lock[ac]);
4261 EXPORT_SYMBOL(ieee80211_txq_schedule_start);
4263 void __ieee80211_subif_start_xmit(struct sk_buff *skb,
4264 struct net_device *dev,
4269 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4270 struct ieee80211_local *local = sdata->local;
4271 struct sta_info *sta;
4272 struct sk_buff *next;
4275 if (unlikely(!ieee80211_sdata_running(sdata) || skb->len < ETH_HLEN)) {
4280 sk_pacing_shift_update(skb->sk, sdata->local->hw.tx_sk_pacing_shift);
4284 if (ieee80211_vif_is_mesh(&sdata->vif) &&
4285 ieee80211_hw_check(&local->hw, SUPPORT_FAST_XMIT) &&
4286 ieee80211_mesh_xmit_fast(sdata, skb, ctrl_flags))
4289 if (ieee80211_lookup_ra_sta(sdata, skb, &sta))
4295 skb_set_queue_mapping(skb, ieee80211_select_queue(sdata, sta, skb));
4296 ieee80211_aggr_check(sdata, sta, skb);
4299 struct ieee80211_fast_tx *fast_tx;
4301 fast_tx = rcu_dereference(sta->fast_tx);
4304 ieee80211_xmit_fast(sdata, sta, fast_tx, skb))
4308 /* the frame could be fragmented, software-encrypted, and other
4309 * things so we cannot really handle checksum or GSO offload.
4310 * fix it up in software before we handle anything else.
4312 skb = ieee80211_tx_skb_fixup(skb, 0);
4318 skb_list_walk_safe(skb, skb, next) {
4319 skb_mark_not_on_list(skb);
4321 if (skb->protocol == sdata->control_port_protocol)
4322 ctrl_flags |= IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP;
4324 skb = ieee80211_build_hdr(sdata, skb, info_flags,
4325 sta, ctrl_flags, cookie);
4327 kfree_skb_list(next);
4331 dev_sw_netstats_tx_add(dev, 1, skb->len);
4333 ieee80211_xmit(sdata, sta, skb);
4341 ieee80211_tpt_led_trig_tx(local, len);
4345 static int ieee80211_change_da(struct sk_buff *skb, struct sta_info *sta)
4350 err = skb_ensure_writable(skb, ETH_HLEN);
4354 eth = (void *)skb->data;
4355 ether_addr_copy(eth->h_dest, sta->sta.addr);
4360 static bool ieee80211_multicast_to_unicast(struct sk_buff *skb,
4361 struct net_device *dev)
4363 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4364 const struct ethhdr *eth = (void *)skb->data;
4365 const struct vlan_ethhdr *ethvlan = (void *)skb->data;
4368 switch (sdata->vif.type) {
4369 case NL80211_IFTYPE_AP_VLAN:
4370 if (sdata->u.vlan.sta)
4372 if (sdata->wdev.use_4addr)
4375 case NL80211_IFTYPE_AP:
4376 /* check runtime toggle for this bss */
4377 if (!sdata->bss->multicast_to_unicast)
4384 /* multicast to unicast conversion only for some payload */
4385 ethertype = eth->h_proto;
4386 if (ethertype == htons(ETH_P_8021Q) && skb->len >= VLAN_ETH_HLEN)
4387 ethertype = ethvlan->h_vlan_encapsulated_proto;
4388 switch (ethertype) {
4389 case htons(ETH_P_ARP):
4390 case htons(ETH_P_IP):
4391 case htons(ETH_P_IPV6):
4401 ieee80211_convert_to_unicast(struct sk_buff *skb, struct net_device *dev,
4402 struct sk_buff_head *queue)
4404 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4405 struct ieee80211_local *local = sdata->local;
4406 const struct ethhdr *eth = (struct ethhdr *)skb->data;
4407 struct sta_info *sta, *first = NULL;
4408 struct sk_buff *cloned_skb;
4412 list_for_each_entry_rcu(sta, &local->sta_list, list) {
4413 if (sdata != sta->sdata)
4414 /* AP-VLAN mismatch */
4416 if (unlikely(ether_addr_equal(eth->h_source, sta->sta.addr)))
4417 /* do not send back to source */
4423 cloned_skb = skb_clone(skb, GFP_ATOMIC);
4426 if (unlikely(ieee80211_change_da(cloned_skb, sta))) {
4427 dev_kfree_skb(cloned_skb);
4430 __skb_queue_tail(queue, cloned_skb);
4433 if (likely(first)) {
4434 if (unlikely(ieee80211_change_da(skb, first)))
4436 __skb_queue_tail(queue, skb);
4438 /* no STA connected, drop */
4445 __skb_queue_purge(queue);
4446 __skb_queue_tail(queue, skb);
4451 static void ieee80211_mlo_multicast_tx_one(struct ieee80211_sub_if_data *sdata,
4452 struct sk_buff *skb, u32 ctrl_flags,
4453 unsigned int link_id)
4455 struct sk_buff *out;
4457 out = skb_copy(skb, GFP_ATOMIC);
4461 ctrl_flags |= u32_encode_bits(link_id, IEEE80211_TX_CTRL_MLO_LINK);
4462 __ieee80211_subif_start_xmit(out, sdata->dev, 0, ctrl_flags, NULL);
4465 static void ieee80211_mlo_multicast_tx(struct net_device *dev,
4466 struct sk_buff *skb)
4468 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4469 unsigned long links = sdata->vif.active_links;
4471 u32 ctrl_flags = IEEE80211_TX_CTRL_MCAST_MLO_FIRST_TX;
4473 if (hweight16(links) == 1) {
4474 ctrl_flags |= u32_encode_bits(__ffs(links),
4475 IEEE80211_TX_CTRL_MLO_LINK);
4477 __ieee80211_subif_start_xmit(skb, sdata->dev, 0, ctrl_flags,
4482 for_each_set_bit(link, &links, IEEE80211_MLD_MAX_NUM_LINKS) {
4483 ieee80211_mlo_multicast_tx_one(sdata, skb, ctrl_flags, link);
4490 * ieee80211_subif_start_xmit - netif start_xmit function for 802.3 vifs
4491 * @skb: packet to be sent
4492 * @dev: incoming interface
4494 * On failure skb will be freed.
4496 * Returns: the netdev TX status (but really only %NETDEV_TX_OK)
4498 netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
4499 struct net_device *dev)
4501 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4502 const struct ethhdr *eth = (void *)skb->data;
4504 if (likely(!is_multicast_ether_addr(eth->h_dest)))
4507 if (unlikely(!ieee80211_sdata_running(sdata))) {
4509 return NETDEV_TX_OK;
4512 if (unlikely(ieee80211_multicast_to_unicast(skb, dev))) {
4513 struct sk_buff_head queue;
4515 __skb_queue_head_init(&queue);
4516 ieee80211_convert_to_unicast(skb, dev, &queue);
4517 while ((skb = __skb_dequeue(&queue)))
4518 __ieee80211_subif_start_xmit(skb, dev, 0,
4519 IEEE80211_TX_CTRL_MLO_LINK_UNSPEC,
4521 } else if (ieee80211_vif_is_mld(&sdata->vif) &&
4522 sdata->vif.type == NL80211_IFTYPE_AP &&
4523 !ieee80211_hw_check(&sdata->local->hw, MLO_MCAST_MULTI_LINK_TX)) {
4524 ieee80211_mlo_multicast_tx(dev, skb);
4527 __ieee80211_subif_start_xmit(skb, dev, 0,
4528 IEEE80211_TX_CTRL_MLO_LINK_UNSPEC,
4532 return NETDEV_TX_OK;
4537 static bool __ieee80211_tx_8023(struct ieee80211_sub_if_data *sdata,
4538 struct sk_buff *skb, struct sta_info *sta,
4541 struct ieee80211_local *local = sdata->local;
4542 struct ieee80211_tx_control control = {};
4543 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4544 struct ieee80211_sta *pubsta = NULL;
4545 unsigned long flags;
4546 int q = info->hw_queue;
4548 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
4550 if (local->queue_stop_reasons[q] ||
4551 (!txpending && !skb_queue_empty(&local->pending[q]))) {
4553 skb_queue_head(&local->pending[q], skb);
4555 skb_queue_tail(&local->pending[q], skb);
4557 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
4562 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
4564 if (sta && sta->uploaded)
4567 control.sta = pubsta;
4569 drv_tx(local, &control, skb);
4574 static bool ieee80211_tx_8023(struct ieee80211_sub_if_data *sdata,
4575 struct sk_buff *skb, struct sta_info *sta,
4578 struct ieee80211_local *local = sdata->local;
4579 struct sk_buff *next;
4582 if (ieee80211_queue_skb(local, sdata, sta, skb))
4585 skb_list_walk_safe(skb, skb, next) {
4586 skb_mark_not_on_list(skb);
4587 if (!__ieee80211_tx_8023(sdata, skb, sta, txpending))
4594 static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata,
4595 struct net_device *dev, struct sta_info *sta,
4596 struct ieee80211_key *key, struct sk_buff *skb)
4598 struct ieee80211_tx_info *info;
4599 struct ieee80211_local *local = sdata->local;
4600 struct tid_ampdu_tx *tid_tx;
4601 struct sk_buff *seg, *next;
4602 unsigned int skbs = 0, len = 0;
4606 queue = ieee80211_select_queue(sdata, sta, skb);
4607 skb_set_queue_mapping(skb, queue);
4609 if (unlikely(test_bit(SCAN_SW_SCANNING, &local->scanning)) &&
4610 test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))
4613 skb = skb_share_check(skb, GFP_ATOMIC);
4617 ieee80211_aggr_check(sdata, sta, skb);
4619 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
4620 tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
4622 if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
4623 /* fall back to non-offload slow path */
4624 __ieee80211_subif_start_xmit(skb, dev, 0,
4625 IEEE80211_TX_CTRL_MLO_LINK_UNSPEC,
4630 if (tid_tx->timeout)
4631 tid_tx->last_tx = jiffies;
4634 skb = ieee80211_tx_skb_fixup(skb, ieee80211_sdata_netdev_features(sdata));
4638 info = IEEE80211_SKB_CB(skb);
4639 memset(info, 0, sizeof(*info));
4641 info->hw_queue = sdata->vif.hw_queue[queue];
4643 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
4644 sdata = container_of(sdata->bss,
4645 struct ieee80211_sub_if_data, u.ap);
4647 info->flags |= IEEE80211_TX_CTL_HW_80211_ENCAP;
4648 info->control.vif = &sdata->vif;
4651 info->control.hw_key = &key->conf;
4653 skb_list_walk_safe(skb, seg, next) {
4657 memcpy(IEEE80211_SKB_CB(seg), info, sizeof(*info));
4660 if (unlikely(skb->sk &&
4661 skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS)) {
4662 info->status_data = ieee80211_store_ack_skb(local, skb,
4663 &info->flags, NULL);
4664 if (info->status_data)
4665 info->status_data_idr = 1;
4668 dev_sw_netstats_tx_add(dev, skbs, len);
4669 sta->deflink.tx_stats.packets[queue] += skbs;
4670 sta->deflink.tx_stats.bytes[queue] += len;
4672 ieee80211_tpt_led_trig_tx(local, len);
4674 ieee80211_tx_8023(sdata, skb, sta, false);
4682 netdev_tx_t ieee80211_subif_start_xmit_8023(struct sk_buff *skb,
4683 struct net_device *dev)
4685 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4686 struct ethhdr *ehdr = (struct ethhdr *)skb->data;
4687 struct ieee80211_key *key;
4688 struct sta_info *sta;
4690 if (unlikely(!ieee80211_sdata_running(sdata) || skb->len < ETH_HLEN)) {
4692 return NETDEV_TX_OK;
4697 if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) {
4702 if (unlikely(IS_ERR_OR_NULL(sta) || !sta->uploaded ||
4703 !test_sta_flag(sta, WLAN_STA_AUTHORIZED) ||
4704 sdata->control_port_protocol == ehdr->h_proto))
4707 key = rcu_dereference(sta->ptk[sta->ptk_idx]);
4709 key = rcu_dereference(sdata->default_unicast_key);
4711 if (key && (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) ||
4712 key->conf.cipher == WLAN_CIPHER_SUITE_TKIP))
4715 sk_pacing_shift_update(skb->sk, sdata->local->hw.tx_sk_pacing_shift);
4716 ieee80211_8023_xmit(sdata, dev, sta, key, skb);
4720 ieee80211_subif_start_xmit(skb, dev);
4724 return NETDEV_TX_OK;
4728 ieee80211_build_data_template(struct ieee80211_sub_if_data *sdata,
4729 struct sk_buff *skb, u32 info_flags)
4731 struct ieee80211_hdr *hdr;
4732 struct ieee80211_tx_data tx = {
4733 .local = sdata->local,
4736 struct sta_info *sta;
4740 if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) {
4742 skb = ERR_PTR(-EINVAL);
4746 skb = ieee80211_build_hdr(sdata, skb, info_flags, sta,
4747 IEEE80211_TX_CTRL_MLO_LINK_UNSPEC, NULL);
4751 hdr = (void *)skb->data;
4752 tx.sta = sta_info_get(sdata, hdr->addr1);
4755 if (ieee80211_tx_h_select_key(&tx) != TX_CONTINUE) {
4758 return ERR_PTR(-EINVAL);
4767 * ieee80211_clear_tx_pending may not be called in a context where
4768 * it is possible that it packets could come in again.
4770 void ieee80211_clear_tx_pending(struct ieee80211_local *local)
4772 struct sk_buff *skb;
4775 for (i = 0; i < local->hw.queues; i++) {
4776 while ((skb = skb_dequeue(&local->pending[i])) != NULL)
4777 ieee80211_free_txskb(&local->hw, skb);
4782 * Returns false if the frame couldn't be transmitted but was queued instead,
4783 * which in this case means re-queued -- take as an indication to stop sending
4784 * more pending frames.
4786 static bool ieee80211_tx_pending_skb(struct ieee80211_local *local,
4787 struct sk_buff *skb)
4789 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4790 struct ieee80211_sub_if_data *sdata;
4791 struct sta_info *sta;
4792 struct ieee80211_hdr *hdr;
4794 struct ieee80211_chanctx_conf *chanctx_conf;
4796 sdata = vif_to_sdata(info->control.vif);
4798 if (info->control.flags & IEEE80211_TX_INTCFL_NEED_TXPROCESSING) {
4799 /* update band only for non-MLD */
4800 if (!ieee80211_vif_is_mld(&sdata->vif)) {
4802 rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
4803 if (unlikely(!chanctx_conf)) {
4807 info->band = chanctx_conf->def.chan->band;
4809 result = ieee80211_tx(sdata, NULL, skb, true);
4810 } else if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) {
4811 if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) {
4816 if (IS_ERR(sta) || (sta && !sta->uploaded))
4819 result = ieee80211_tx_8023(sdata, skb, sta, true);
4821 struct sk_buff_head skbs;
4823 __skb_queue_head_init(&skbs);
4824 __skb_queue_tail(&skbs, skb);
4826 hdr = (struct ieee80211_hdr *)skb->data;
4827 sta = sta_info_get(sdata, hdr->addr1);
4829 result = __ieee80211_tx(local, &skbs, sta, true);
4836 * Transmit all pending packets. Called from tasklet.
4838 void ieee80211_tx_pending(struct tasklet_struct *t)
4840 struct ieee80211_local *local = from_tasklet(local, t,
4841 tx_pending_tasklet);
4842 unsigned long flags;
4848 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
4849 for (i = 0; i < local->hw.queues; i++) {
4851 * If queue is stopped by something other than due to pending
4852 * frames, or we have no pending frames, proceed to next queue.
4854 if (local->queue_stop_reasons[i] ||
4855 skb_queue_empty(&local->pending[i]))
4858 while (!skb_queue_empty(&local->pending[i])) {
4859 struct sk_buff *skb = __skb_dequeue(&local->pending[i]);
4860 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4862 if (WARN_ON(!info->control.vif)) {
4863 ieee80211_free_txskb(&local->hw, skb);
4867 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
4870 txok = ieee80211_tx_pending_skb(local, skb);
4871 spin_lock_irqsave(&local->queue_stop_reason_lock,
4877 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
4882 /* functions for drivers to get certain frames */
4884 static void __ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
4885 struct ieee80211_link_data *link,
4886 struct ps_data *ps, struct sk_buff *skb,
4891 int i, have_bits = 0, n1, n2;
4892 struct ieee80211_bss_conf *link_conf = link->conf;
4894 /* Generate bitmap for TIM only if there are any STAs in power save
4896 if (atomic_read(&ps->num_sta_ps) > 0)
4897 /* in the hope that this is faster than
4898 * checking byte-for-byte */
4899 have_bits = !bitmap_empty((unsigned long *)ps->tim,
4900 IEEE80211_MAX_AID+1);
4902 if (ps->dtim_count == 0)
4903 ps->dtim_count = link_conf->dtim_period - 1;
4908 tim = pos = skb_put(skb, 5);
4909 *pos++ = WLAN_EID_TIM;
4911 *pos++ = ps->dtim_count;
4912 *pos++ = link_conf->dtim_period;
4914 if (ps->dtim_count == 0 && !skb_queue_empty(&ps->bc_buf))
4917 ps->dtim_bc_mc = aid0 == 1;
4920 /* Find largest even number N1 so that bits numbered 1 through
4921 * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits
4922 * (N2 + 1) x 8 through 2007 are 0. */
4924 for (i = 0; i < IEEE80211_MAX_TIM_LEN; i++) {
4931 for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) {
4938 /* Bitmap control */
4940 /* Part Virt Bitmap */
4941 skb_put_data(skb, ps->tim + n1, n2 - n1 + 1);
4943 tim[1] = n2 - n1 + 4;
4945 *pos++ = aid0; /* Bitmap control */
4947 if (ieee80211_get_link_sband(link)->band != NL80211_BAND_S1GHZ) {
4949 /* Part Virt Bitmap */
4955 static int ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
4956 struct ieee80211_link_data *link,
4957 struct ps_data *ps, struct sk_buff *skb,
4960 struct ieee80211_local *local = sdata->local;
4963 * Not very nice, but we want to allow the driver to call
4964 * ieee80211_beacon_get() as a response to the set_tim()
4965 * callback. That, however, is already invoked under the
4966 * sta_lock to guarantee consistent and race-free update
4967 * of the tim bitmap in mac80211 and the driver.
4969 if (local->tim_in_locked_section) {
4970 __ieee80211_beacon_add_tim(sdata, link, ps, skb, is_template);
4972 spin_lock_bh(&local->tim_lock);
4973 __ieee80211_beacon_add_tim(sdata, link, ps, skb, is_template);
4974 spin_unlock_bh(&local->tim_lock);
4980 static void ieee80211_set_beacon_cntdwn(struct ieee80211_sub_if_data *sdata,
4981 struct beacon_data *beacon,
4982 struct ieee80211_link_data *link)
4984 u8 *beacon_data, count, max_count = 1;
4985 struct probe_resp *resp;
4986 size_t beacon_data_len;
4990 switch (sdata->vif.type) {
4991 case NL80211_IFTYPE_AP:
4992 beacon_data = beacon->tail;
4993 beacon_data_len = beacon->tail_len;
4995 case NL80211_IFTYPE_ADHOC:
4996 beacon_data = beacon->head;
4997 beacon_data_len = beacon->head_len;
4999 case NL80211_IFTYPE_MESH_POINT:
5000 beacon_data = beacon->head;
5001 beacon_data_len = beacon->head_len;
5007 resp = rcu_dereference(link->u.ap.probe_resp);
5009 bcn_offsets = beacon->cntdwn_counter_offsets;
5010 count = beacon->cntdwn_current_counter;
5011 if (link->conf->csa_active)
5012 max_count = IEEE80211_MAX_CNTDWN_COUNTERS_NUM;
5014 for (i = 0; i < max_count; ++i) {
5015 if (bcn_offsets[i]) {
5016 if (WARN_ON_ONCE(bcn_offsets[i] >= beacon_data_len))
5018 beacon_data[bcn_offsets[i]] = count;
5021 if (sdata->vif.type == NL80211_IFTYPE_AP && resp) {
5022 u16 *resp_offsets = resp->cntdwn_counter_offsets;
5024 resp->data[resp_offsets[i]] = count;
5029 static u8 __ieee80211_beacon_update_cntdwn(struct beacon_data *beacon)
5031 beacon->cntdwn_current_counter--;
5033 /* the counter should never reach 0 */
5034 WARN_ON_ONCE(!beacon->cntdwn_current_counter);
5036 return beacon->cntdwn_current_counter;
5039 u8 ieee80211_beacon_update_cntdwn(struct ieee80211_vif *vif, unsigned int link_id)
5041 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5042 struct ieee80211_link_data *link;
5043 struct beacon_data *beacon = NULL;
5046 if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
5051 link = rcu_dereference(sdata->link[link_id]);
5055 if (sdata->vif.type == NL80211_IFTYPE_AP)
5056 beacon = rcu_dereference(link->u.ap.beacon);
5057 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
5058 beacon = rcu_dereference(sdata->u.ibss.presp);
5059 else if (ieee80211_vif_is_mesh(&sdata->vif))
5060 beacon = rcu_dereference(sdata->u.mesh.beacon);
5065 count = __ieee80211_beacon_update_cntdwn(beacon);
5071 EXPORT_SYMBOL(ieee80211_beacon_update_cntdwn);
5073 void ieee80211_beacon_set_cntdwn(struct ieee80211_vif *vif, u8 counter)
5075 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5076 struct beacon_data *beacon = NULL;
5080 if (sdata->vif.type == NL80211_IFTYPE_AP)
5081 beacon = rcu_dereference(sdata->deflink.u.ap.beacon);
5082 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
5083 beacon = rcu_dereference(sdata->u.ibss.presp);
5084 else if (ieee80211_vif_is_mesh(&sdata->vif))
5085 beacon = rcu_dereference(sdata->u.mesh.beacon);
5090 if (counter < beacon->cntdwn_current_counter)
5091 beacon->cntdwn_current_counter = counter;
5096 EXPORT_SYMBOL(ieee80211_beacon_set_cntdwn);
5098 bool ieee80211_beacon_cntdwn_is_complete(struct ieee80211_vif *vif,
5099 unsigned int link_id)
5101 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5102 struct ieee80211_link_data *link;
5103 struct beacon_data *beacon = NULL;
5105 size_t beacon_data_len;
5108 if (!ieee80211_sdata_running(sdata))
5111 if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
5116 link = rcu_dereference(sdata->link[link_id]);
5120 if (vif->type == NL80211_IFTYPE_AP) {
5121 beacon = rcu_dereference(link->u.ap.beacon);
5122 if (WARN_ON(!beacon || !beacon->tail))
5124 beacon_data = beacon->tail;
5125 beacon_data_len = beacon->tail_len;
5126 } else if (vif->type == NL80211_IFTYPE_ADHOC) {
5127 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
5129 beacon = rcu_dereference(ifibss->presp);
5133 beacon_data = beacon->head;
5134 beacon_data_len = beacon->head_len;
5135 } else if (vif->type == NL80211_IFTYPE_MESH_POINT) {
5136 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
5138 beacon = rcu_dereference(ifmsh->beacon);
5142 beacon_data = beacon->head;
5143 beacon_data_len = beacon->head_len;
5149 if (!beacon->cntdwn_counter_offsets[0])
5152 if (WARN_ON_ONCE(beacon->cntdwn_counter_offsets[0] > beacon_data_len))
5155 if (beacon_data[beacon->cntdwn_counter_offsets[0]] == 1)
5163 EXPORT_SYMBOL(ieee80211_beacon_cntdwn_is_complete);
5165 static int ieee80211_beacon_protect(struct sk_buff *skb,
5166 struct ieee80211_local *local,
5167 struct ieee80211_sub_if_data *sdata,
5168 struct ieee80211_link_data *link)
5170 ieee80211_tx_result res;
5171 struct ieee80211_tx_data tx;
5172 struct sk_buff *check_skb;
5174 memset(&tx, 0, sizeof(tx));
5175 tx.key = rcu_dereference(link->default_beacon_key);
5179 if (unlikely(tx.key->flags & KEY_FLAG_TAINTED)) {
5184 if (!(tx.key->conf.flags & IEEE80211_KEY_FLAG_SW_MGMT_TX) &&
5185 tx.key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
5186 IEEE80211_SKB_CB(skb)->control.hw_key = &tx.key->conf;
5190 __skb_queue_head_init(&tx.skbs);
5191 __skb_queue_tail(&tx.skbs, skb);
5192 res = ieee80211_tx_h_encrypt(&tx);
5193 check_skb = __skb_dequeue(&tx.skbs);
5194 /* we may crash after this, but it'd be a bug in crypto */
5195 WARN_ON(check_skb != skb);
5196 if (WARN_ON_ONCE(res != TX_CONTINUE))
5203 ieee80211_beacon_get_finish(struct ieee80211_hw *hw,
5204 struct ieee80211_vif *vif,
5205 struct ieee80211_link_data *link,
5206 struct ieee80211_mutable_offsets *offs,
5207 struct beacon_data *beacon,
5208 struct sk_buff *skb,
5209 struct ieee80211_chanctx_conf *chanctx_conf,
5212 struct ieee80211_local *local = hw_to_local(hw);
5213 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5214 struct ieee80211_tx_info *info;
5215 enum nl80211_band band;
5216 struct ieee80211_tx_rate_control txrc;
5219 if (offs && beacon) {
5222 for (i = 0; i < IEEE80211_MAX_CNTDWN_COUNTERS_NUM; i++) {
5223 u16 csa_off = beacon->cntdwn_counter_offsets[i];
5228 offs->cntdwn_counter_offs[i] = csa_off_base + csa_off;
5232 band = chanctx_conf->def.chan->band;
5233 info = IEEE80211_SKB_CB(skb);
5234 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
5235 info->flags |= IEEE80211_TX_CTL_NO_ACK;
5238 memset(&txrc, 0, sizeof(txrc));
5240 txrc.sband = local->hw.wiphy->bands[band];
5241 txrc.bss_conf = link->conf;
5243 txrc.reported_rate.idx = -1;
5244 if (sdata->beacon_rate_set && sdata->beacon_rateidx_mask[band])
5245 txrc.rate_idx_mask = sdata->beacon_rateidx_mask[band];
5247 txrc.rate_idx_mask = sdata->rc_rateidx_mask[band];
5249 rate_control_get_rate(sdata, NULL, &txrc);
5251 info->control.vif = vif;
5252 info->control.flags |= u32_encode_bits(link->link_id,
5253 IEEE80211_TX_CTRL_MLO_LINK);
5254 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT |
5255 IEEE80211_TX_CTL_ASSIGN_SEQ |
5256 IEEE80211_TX_CTL_FIRST_FRAGMENT;
5260 ieee80211_beacon_add_mbssid(struct sk_buff *skb, struct beacon_data *beacon,
5263 if (!beacon->mbssid_ies || !beacon->mbssid_ies->cnt ||
5264 i > beacon->mbssid_ies->cnt)
5267 if (i < beacon->mbssid_ies->cnt) {
5268 skb_put_data(skb, beacon->mbssid_ies->elem[i].data,
5269 beacon->mbssid_ies->elem[i].len);
5271 if (beacon->rnr_ies && beacon->rnr_ies->cnt) {
5272 skb_put_data(skb, beacon->rnr_ies->elem[i].data,
5273 beacon->rnr_ies->elem[i].len);
5275 for (i = beacon->mbssid_ies->cnt; i < beacon->rnr_ies->cnt; i++)
5276 skb_put_data(skb, beacon->rnr_ies->elem[i].data,
5277 beacon->rnr_ies->elem[i].len);
5282 /* i == beacon->mbssid_ies->cnt, include all MBSSID elements */
5283 for (i = 0; i < beacon->mbssid_ies->cnt; i++)
5284 skb_put_data(skb, beacon->mbssid_ies->elem[i].data,
5285 beacon->mbssid_ies->elem[i].len);
5288 static struct sk_buff *
5289 ieee80211_beacon_get_ap(struct ieee80211_hw *hw,
5290 struct ieee80211_vif *vif,
5291 struct ieee80211_link_data *link,
5292 struct ieee80211_mutable_offsets *offs,
5294 struct beacon_data *beacon,
5295 struct ieee80211_chanctx_conf *chanctx_conf,
5298 struct ieee80211_local *local = hw_to_local(hw);
5299 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5300 struct ieee80211_if_ap *ap = &sdata->u.ap;
5301 struct sk_buff *skb = NULL;
5302 u16 csa_off_base = 0;
5305 if (beacon->cntdwn_counter_offsets[0]) {
5307 ieee80211_beacon_update_cntdwn(vif, link->link_id);
5309 ieee80211_set_beacon_cntdwn(sdata, beacon, link);
5312 /* headroom, head length,
5313 * tail length, maximum TIM length and multiple BSSID length
5315 mbssid_len = ieee80211_get_mbssid_beacon_len(beacon->mbssid_ies,
5319 skb = dev_alloc_skb(local->tx_headroom + beacon->head_len +
5320 beacon->tail_len + 256 +
5321 local->hw.extra_beacon_tailroom + mbssid_len);
5325 skb_reserve(skb, local->tx_headroom);
5326 skb_put_data(skb, beacon->head, beacon->head_len);
5328 ieee80211_beacon_add_tim(sdata, link, &ap->ps, skb, is_template);
5331 offs->tim_offset = beacon->head_len;
5332 offs->tim_length = skb->len - beacon->head_len;
5333 offs->cntdwn_counter_offs[0] = beacon->cntdwn_counter_offsets[0];
5336 ieee80211_beacon_add_mbssid(skb, beacon, ema_index);
5337 offs->mbssid_off = skb->len - mbssid_len;
5340 /* for AP the csa offsets are from tail */
5341 csa_off_base = skb->len;
5345 skb_put_data(skb, beacon->tail, beacon->tail_len);
5347 if (ieee80211_beacon_protect(skb, local, sdata, link) < 0)
5350 ieee80211_beacon_get_finish(hw, vif, link, offs, beacon, skb,
5351 chanctx_conf, csa_off_base);
5355 static struct ieee80211_ema_beacons *
5356 ieee80211_beacon_get_ap_ema_list(struct ieee80211_hw *hw,
5357 struct ieee80211_vif *vif,
5358 struct ieee80211_link_data *link,
5359 struct ieee80211_mutable_offsets *offs,
5360 bool is_template, struct beacon_data *beacon,
5361 struct ieee80211_chanctx_conf *chanctx_conf)
5363 struct ieee80211_ema_beacons *ema = NULL;
5365 if (!beacon->mbssid_ies || !beacon->mbssid_ies->cnt)
5368 ema = kzalloc(struct_size(ema, bcn, beacon->mbssid_ies->cnt),
5373 for (ema->cnt = 0; ema->cnt < beacon->mbssid_ies->cnt; ema->cnt++) {
5374 ema->bcn[ema->cnt].skb =
5375 ieee80211_beacon_get_ap(hw, vif, link,
5376 &ema->bcn[ema->cnt].offs,
5377 is_template, beacon,
5378 chanctx_conf, ema->cnt);
5379 if (!ema->bcn[ema->cnt].skb)
5383 if (ema->cnt == beacon->mbssid_ies->cnt)
5386 ieee80211_beacon_free_ema_list(ema);
5390 #define IEEE80211_INCLUDE_ALL_MBSSID_ELEMS -1
5392 static struct sk_buff *
5393 __ieee80211_beacon_get(struct ieee80211_hw *hw,
5394 struct ieee80211_vif *vif,
5395 struct ieee80211_mutable_offsets *offs,
5397 unsigned int link_id,
5399 struct ieee80211_ema_beacons **ema_beacons)
5401 struct ieee80211_local *local = hw_to_local(hw);
5402 struct beacon_data *beacon = NULL;
5403 struct sk_buff *skb = NULL;
5404 struct ieee80211_sub_if_data *sdata = NULL;
5405 struct ieee80211_chanctx_conf *chanctx_conf;
5406 struct ieee80211_link_data *link;
5410 sdata = vif_to_sdata(vif);
5411 link = rcu_dereference(sdata->link[link_id]);
5415 rcu_dereference(link->conf->chanctx_conf);
5417 if (!ieee80211_sdata_running(sdata) || !chanctx_conf)
5421 memset(offs, 0, sizeof(*offs));
5423 if (sdata->vif.type == NL80211_IFTYPE_AP) {
5424 beacon = rcu_dereference(link->u.ap.beacon);
5430 ieee80211_beacon_get_ap_ema_list(hw, vif, link,
5436 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) {
5437 if (ema_index >= beacon->mbssid_ies->cnt)
5438 goto out; /* End of MBSSID elements */
5440 if (ema_index <= IEEE80211_INCLUDE_ALL_MBSSID_ELEMS)
5441 ema_index = beacon->mbssid_ies->cnt;
5446 skb = ieee80211_beacon_get_ap(hw, vif, link, offs,
5447 is_template, beacon,
5451 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
5452 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
5453 struct ieee80211_hdr *hdr;
5455 beacon = rcu_dereference(ifibss->presp);
5459 if (beacon->cntdwn_counter_offsets[0]) {
5461 __ieee80211_beacon_update_cntdwn(beacon);
5463 ieee80211_set_beacon_cntdwn(sdata, beacon, link);
5466 skb = dev_alloc_skb(local->tx_headroom + beacon->head_len +
5467 local->hw.extra_beacon_tailroom);
5470 skb_reserve(skb, local->tx_headroom);
5471 skb_put_data(skb, beacon->head, beacon->head_len);
5473 hdr = (struct ieee80211_hdr *) skb->data;
5474 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
5475 IEEE80211_STYPE_BEACON);
5477 ieee80211_beacon_get_finish(hw, vif, link, offs, beacon, skb,
5479 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
5480 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
5482 beacon = rcu_dereference(ifmsh->beacon);
5486 if (beacon->cntdwn_counter_offsets[0]) {
5488 /* TODO: For mesh csa_counter is in TU, so
5489 * decrementing it by one isn't correct, but
5490 * for now we leave it consistent with overall
5491 * mac80211's behavior.
5493 __ieee80211_beacon_update_cntdwn(beacon);
5495 ieee80211_set_beacon_cntdwn(sdata, beacon, link);
5498 if (ifmsh->sync_ops)
5499 ifmsh->sync_ops->adjust_tsf(sdata, beacon);
5501 skb = dev_alloc_skb(local->tx_headroom +
5505 local->hw.extra_beacon_tailroom);
5508 skb_reserve(skb, local->tx_headroom);
5509 skb_put_data(skb, beacon->head, beacon->head_len);
5510 ieee80211_beacon_add_tim(sdata, link, &ifmsh->ps, skb,
5514 offs->tim_offset = beacon->head_len;
5515 offs->tim_length = skb->len - beacon->head_len;
5518 skb_put_data(skb, beacon->tail, beacon->tail_len);
5519 ieee80211_beacon_get_finish(hw, vif, link, offs, beacon, skb,
5533 ieee80211_beacon_get_template(struct ieee80211_hw *hw,
5534 struct ieee80211_vif *vif,
5535 struct ieee80211_mutable_offsets *offs,
5536 unsigned int link_id)
5538 return __ieee80211_beacon_get(hw, vif, offs, true, link_id,
5539 IEEE80211_INCLUDE_ALL_MBSSID_ELEMS, NULL);
5541 EXPORT_SYMBOL(ieee80211_beacon_get_template);
5544 ieee80211_beacon_get_template_ema_index(struct ieee80211_hw *hw,
5545 struct ieee80211_vif *vif,
5546 struct ieee80211_mutable_offsets *offs,
5547 unsigned int link_id, u8 ema_index)
5549 return __ieee80211_beacon_get(hw, vif, offs, true, link_id, ema_index,
5552 EXPORT_SYMBOL(ieee80211_beacon_get_template_ema_index);
5554 void ieee80211_beacon_free_ema_list(struct ieee80211_ema_beacons *ema_beacons)
5561 for (i = 0; i < ema_beacons->cnt; i++)
5562 kfree_skb(ema_beacons->bcn[i].skb);
5566 EXPORT_SYMBOL(ieee80211_beacon_free_ema_list);
5568 struct ieee80211_ema_beacons *
5569 ieee80211_beacon_get_template_ema_list(struct ieee80211_hw *hw,
5570 struct ieee80211_vif *vif,
5571 unsigned int link_id)
5573 struct ieee80211_ema_beacons *ema_beacons = NULL;
5575 WARN_ON(__ieee80211_beacon_get(hw, vif, NULL, true, link_id, 0,
5580 EXPORT_SYMBOL(ieee80211_beacon_get_template_ema_list);
5582 struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
5583 struct ieee80211_vif *vif,
5584 u16 *tim_offset, u16 *tim_length,
5585 unsigned int link_id)
5587 struct ieee80211_mutable_offsets offs = {};
5588 struct sk_buff *bcn = __ieee80211_beacon_get(hw, vif, &offs, false,
5590 IEEE80211_INCLUDE_ALL_MBSSID_ELEMS,
5592 struct sk_buff *copy;
5598 *tim_offset = offs.tim_offset;
5601 *tim_length = offs.tim_length;
5603 if (ieee80211_hw_check(hw, BEACON_TX_STATUS) ||
5604 !hw_to_local(hw)->monitors)
5607 /* send a copy to monitor interfaces */
5608 copy = skb_copy(bcn, GFP_ATOMIC);
5612 ieee80211_tx_monitor(hw_to_local(hw), copy, 1, false, NULL);
5616 EXPORT_SYMBOL(ieee80211_beacon_get_tim);
5618 struct sk_buff *ieee80211_proberesp_get(struct ieee80211_hw *hw,
5619 struct ieee80211_vif *vif)
5621 struct sk_buff *skb = NULL;
5622 struct probe_resp *presp = NULL;
5623 struct ieee80211_hdr *hdr;
5624 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5626 if (sdata->vif.type != NL80211_IFTYPE_AP)
5630 presp = rcu_dereference(sdata->deflink.u.ap.probe_resp);
5634 skb = dev_alloc_skb(presp->len);
5638 skb_put_data(skb, presp->data, presp->len);
5640 hdr = (struct ieee80211_hdr *) skb->data;
5641 memset(hdr->addr1, 0, sizeof(hdr->addr1));
5647 EXPORT_SYMBOL(ieee80211_proberesp_get);
5649 struct sk_buff *ieee80211_get_fils_discovery_tmpl(struct ieee80211_hw *hw,
5650 struct ieee80211_vif *vif)
5652 struct sk_buff *skb = NULL;
5653 struct fils_discovery_data *tmpl = NULL;
5654 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5656 if (sdata->vif.type != NL80211_IFTYPE_AP)
5660 tmpl = rcu_dereference(sdata->deflink.u.ap.fils_discovery);
5666 skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom + tmpl->len);
5668 skb_reserve(skb, sdata->local->hw.extra_tx_headroom);
5669 skb_put_data(skb, tmpl->data, tmpl->len);
5675 EXPORT_SYMBOL(ieee80211_get_fils_discovery_tmpl);
5678 ieee80211_get_unsol_bcast_probe_resp_tmpl(struct ieee80211_hw *hw,
5679 struct ieee80211_vif *vif)
5681 struct sk_buff *skb = NULL;
5682 struct unsol_bcast_probe_resp_data *tmpl = NULL;
5683 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5685 if (sdata->vif.type != NL80211_IFTYPE_AP)
5689 tmpl = rcu_dereference(sdata->deflink.u.ap.unsol_bcast_probe_resp);
5695 skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom + tmpl->len);
5697 skb_reserve(skb, sdata->local->hw.extra_tx_headroom);
5698 skb_put_data(skb, tmpl->data, tmpl->len);
5704 EXPORT_SYMBOL(ieee80211_get_unsol_bcast_probe_resp_tmpl);
5706 struct sk_buff *ieee80211_pspoll_get(struct ieee80211_hw *hw,
5707 struct ieee80211_vif *vif)
5709 struct ieee80211_sub_if_data *sdata;
5710 struct ieee80211_pspoll *pspoll;
5711 struct ieee80211_local *local;
5712 struct sk_buff *skb;
5714 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
5717 sdata = vif_to_sdata(vif);
5718 local = sdata->local;
5720 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll));
5724 skb_reserve(skb, local->hw.extra_tx_headroom);
5726 pspoll = skb_put_zero(skb, sizeof(*pspoll));
5727 pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
5728 IEEE80211_STYPE_PSPOLL);
5729 pspoll->aid = cpu_to_le16(sdata->vif.cfg.aid);
5731 /* aid in PS-Poll has its two MSBs each set to 1 */
5732 pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
5734 memcpy(pspoll->bssid, sdata->deflink.u.mgd.bssid, ETH_ALEN);
5735 memcpy(pspoll->ta, vif->addr, ETH_ALEN);
5739 EXPORT_SYMBOL(ieee80211_pspoll_get);
5741 struct sk_buff *ieee80211_nullfunc_get(struct ieee80211_hw *hw,
5742 struct ieee80211_vif *vif,
5743 int link_id, bool qos_ok)
5745 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5746 struct ieee80211_local *local = sdata->local;
5747 struct ieee80211_link_data *link = NULL;
5748 struct ieee80211_hdr_3addr *nullfunc;
5749 struct sk_buff *skb;
5752 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
5755 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
5756 sizeof(*nullfunc) + 2);
5762 struct sta_info *sta;
5764 sta = sta_info_get(sdata, vif->cfg.ap_addr);
5765 qos = sta && sta->sta.wme;
5769 link = rcu_dereference(sdata->link[link_id]);
5770 if (WARN_ON_ONCE(!link)) {
5777 skb_reserve(skb, local->hw.extra_tx_headroom);
5779 nullfunc = skb_put_zero(skb, sizeof(*nullfunc));
5780 nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
5781 IEEE80211_STYPE_NULLFUNC |
5782 IEEE80211_FCTL_TODS);
5784 __le16 qoshdr = cpu_to_le16(7);
5786 BUILD_BUG_ON((IEEE80211_STYPE_QOS_NULLFUNC |
5787 IEEE80211_STYPE_NULLFUNC) !=
5788 IEEE80211_STYPE_QOS_NULLFUNC);
5789 nullfunc->frame_control |=
5790 cpu_to_le16(IEEE80211_STYPE_QOS_NULLFUNC);
5792 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
5793 skb_put_data(skb, &qoshdr, sizeof(qoshdr));
5797 memcpy(nullfunc->addr1, link->conf->bssid, ETH_ALEN);
5798 memcpy(nullfunc->addr2, link->conf->addr, ETH_ALEN);
5799 memcpy(nullfunc->addr3, link->conf->bssid, ETH_ALEN);
5801 memcpy(nullfunc->addr1, vif->cfg.ap_addr, ETH_ALEN);
5802 memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
5803 memcpy(nullfunc->addr3, vif->cfg.ap_addr, ETH_ALEN);
5809 EXPORT_SYMBOL(ieee80211_nullfunc_get);
5811 struct sk_buff *ieee80211_probereq_get(struct ieee80211_hw *hw,
5813 const u8 *ssid, size_t ssid_len,
5816 struct ieee80211_local *local = hw_to_local(hw);
5817 struct ieee80211_hdr_3addr *hdr;
5818 struct sk_buff *skb;
5822 ie_ssid_len = 2 + ssid_len;
5824 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*hdr) +
5825 ie_ssid_len + tailroom);
5829 skb_reserve(skb, local->hw.extra_tx_headroom);
5831 hdr = skb_put_zero(skb, sizeof(*hdr));
5832 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
5833 IEEE80211_STYPE_PROBE_REQ);
5834 eth_broadcast_addr(hdr->addr1);
5835 memcpy(hdr->addr2, src_addr, ETH_ALEN);
5836 eth_broadcast_addr(hdr->addr3);
5838 pos = skb_put(skb, ie_ssid_len);
5839 *pos++ = WLAN_EID_SSID;
5842 memcpy(pos, ssid, ssid_len);
5847 EXPORT_SYMBOL(ieee80211_probereq_get);
5849 void ieee80211_rts_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5850 const void *frame, size_t frame_len,
5851 const struct ieee80211_tx_info *frame_txctl,
5852 struct ieee80211_rts *rts)
5854 const struct ieee80211_hdr *hdr = frame;
5856 rts->frame_control =
5857 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
5858 rts->duration = ieee80211_rts_duration(hw, vif, frame_len,
5860 memcpy(rts->ra, hdr->addr1, sizeof(rts->ra));
5861 memcpy(rts->ta, hdr->addr2, sizeof(rts->ta));
5863 EXPORT_SYMBOL(ieee80211_rts_get);
5865 void ieee80211_ctstoself_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5866 const void *frame, size_t frame_len,
5867 const struct ieee80211_tx_info *frame_txctl,
5868 struct ieee80211_cts *cts)
5870 const struct ieee80211_hdr *hdr = frame;
5872 cts->frame_control =
5873 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
5874 cts->duration = ieee80211_ctstoself_duration(hw, vif,
5875 frame_len, frame_txctl);
5876 memcpy(cts->ra, hdr->addr1, sizeof(cts->ra));
5878 EXPORT_SYMBOL(ieee80211_ctstoself_get);
5881 ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
5882 struct ieee80211_vif *vif)
5884 struct ieee80211_local *local = hw_to_local(hw);
5885 struct sk_buff *skb = NULL;
5886 struct ieee80211_tx_data tx;
5887 struct ieee80211_sub_if_data *sdata;
5889 struct ieee80211_tx_info *info;
5890 struct ieee80211_chanctx_conf *chanctx_conf;
5892 sdata = vif_to_sdata(vif);
5895 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
5900 if (sdata->vif.type == NL80211_IFTYPE_AP) {
5901 struct beacon_data *beacon =
5902 rcu_dereference(sdata->deflink.u.ap.beacon);
5904 if (!beacon || !beacon->head)
5907 ps = &sdata->u.ap.ps;
5908 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
5909 ps = &sdata->u.mesh.ps;
5914 if (ps->dtim_count != 0 || !ps->dtim_bc_mc)
5915 goto out; /* send buffered bc/mc only after DTIM beacon */
5918 skb = skb_dequeue(&ps->bc_buf);
5921 local->total_ps_buffered--;
5923 if (!skb_queue_empty(&ps->bc_buf) && skb->len >= 2) {
5924 struct ieee80211_hdr *hdr =
5925 (struct ieee80211_hdr *) skb->data;
5926 /* more buffered multicast/broadcast frames ==> set
5927 * MoreData flag in IEEE 802.11 header to inform PS
5929 hdr->frame_control |=
5930 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
5933 if (sdata->vif.type == NL80211_IFTYPE_AP)
5934 sdata = IEEE80211_DEV_TO_SUB_IF(skb->dev);
5935 if (!ieee80211_tx_prepare(sdata, &tx, NULL, skb))
5937 ieee80211_free_txskb(hw, skb);
5940 info = IEEE80211_SKB_CB(skb);
5942 tx.flags |= IEEE80211_TX_PS_BUFFERED;
5943 info->band = chanctx_conf->def.chan->band;
5945 if (invoke_tx_handlers(&tx))
5952 EXPORT_SYMBOL(ieee80211_get_buffered_bc);
5954 int ieee80211_reserve_tid(struct ieee80211_sta *pubsta, u8 tid)
5956 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
5957 struct ieee80211_sub_if_data *sdata = sta->sdata;
5958 struct ieee80211_local *local = sdata->local;
5962 lockdep_assert_wiphy(local->hw.wiphy);
5964 /* only some cases are supported right now */
5965 switch (sdata->vif.type) {
5966 case NL80211_IFTYPE_STATION:
5967 case NL80211_IFTYPE_AP:
5968 case NL80211_IFTYPE_AP_VLAN:
5975 if (WARN_ON(tid >= IEEE80211_NUM_UPS))
5978 if (sta->reserved_tid == tid) {
5983 if (sta->reserved_tid != IEEE80211_TID_UNRESERVED) {
5984 sdata_err(sdata, "TID reservation already active\n");
5989 ieee80211_stop_vif_queues(sdata->local, sdata,
5990 IEEE80211_QUEUE_STOP_REASON_RESERVE_TID);
5994 /* Tear down BA sessions so we stop aggregating on this TID */
5995 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION)) {
5996 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
5997 __ieee80211_stop_tx_ba_session(sta, tid,
5998 AGG_STOP_LOCAL_REQUEST);
6001 queues = BIT(sdata->vif.hw_queue[ieee802_1d_to_ac[tid]]);
6002 __ieee80211_flush_queues(local, sdata, queues, false);
6004 sta->reserved_tid = tid;
6006 ieee80211_wake_vif_queues(local, sdata,
6007 IEEE80211_QUEUE_STOP_REASON_RESERVE_TID);
6009 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION))
6010 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
6016 EXPORT_SYMBOL(ieee80211_reserve_tid);
6018 void ieee80211_unreserve_tid(struct ieee80211_sta *pubsta, u8 tid)
6020 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
6021 struct ieee80211_sub_if_data *sdata = sta->sdata;
6023 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6025 /* only some cases are supported right now */
6026 switch (sdata->vif.type) {
6027 case NL80211_IFTYPE_STATION:
6028 case NL80211_IFTYPE_AP:
6029 case NL80211_IFTYPE_AP_VLAN:
6036 if (tid != sta->reserved_tid) {
6037 sdata_err(sdata, "TID to unreserve (%d) isn't reserved\n", tid);
6041 sta->reserved_tid = IEEE80211_TID_UNRESERVED;
6043 EXPORT_SYMBOL(ieee80211_unreserve_tid);
6045 void __ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata,
6046 struct sk_buff *skb, int tid, int link_id,
6047 enum nl80211_band band)
6049 const struct ieee80211_hdr *hdr = (void *)skb->data;
6050 int ac = ieee80211_ac_from_tid(tid);
6053 skb_reset_mac_header(skb);
6054 skb_set_queue_mapping(skb, ac);
6055 skb->priority = tid;
6057 skb->dev = sdata->dev;
6059 BUILD_BUG_ON(IEEE80211_LINK_UNSPECIFIED < IEEE80211_MLD_MAX_NUM_LINKS);
6060 BUILD_BUG_ON(!FIELD_FIT(IEEE80211_TX_CTRL_MLO_LINK,
6061 IEEE80211_LINK_UNSPECIFIED));
6063 if (!ieee80211_vif_is_mld(&sdata->vif)) {
6065 } else if (link_id >= 0) {
6067 } else if (memcmp(sdata->vif.addr, hdr->addr2, ETH_ALEN) == 0) {
6068 /* address from the MLD */
6069 link = IEEE80211_LINK_UNSPECIFIED;
6071 /* otherwise must be addressed from a link */
6073 for (link = 0; link < ARRAY_SIZE(sdata->vif.link_conf); link++) {
6074 struct ieee80211_bss_conf *link_conf;
6076 link_conf = rcu_dereference(sdata->vif.link_conf[link]);
6079 if (memcmp(link_conf->addr, hdr->addr2, ETH_ALEN) == 0)
6084 if (WARN_ON_ONCE(link == ARRAY_SIZE(sdata->vif.link_conf)))
6085 link = ffs(sdata->vif.active_links) - 1;
6088 IEEE80211_SKB_CB(skb)->control.flags |=
6089 u32_encode_bits(link, IEEE80211_TX_CTRL_MLO_LINK);
6092 * The other path calling ieee80211_xmit is from the tasklet,
6093 * and while we can handle concurrent transmissions locking
6094 * requirements are that we do not come into tx with bhs on.
6097 IEEE80211_SKB_CB(skb)->band = band;
6098 ieee80211_xmit(sdata, NULL, skb);
6102 void ieee80211_tx_skb_tid(struct ieee80211_sub_if_data *sdata,
6103 struct sk_buff *skb, int tid, int link_id)
6105 struct ieee80211_chanctx_conf *chanctx_conf;
6106 enum nl80211_band band;
6109 if (!ieee80211_vif_is_mld(&sdata->vif)) {
6110 WARN_ON(link_id >= 0);
6112 rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
6113 if (WARN_ON(!chanctx_conf)) {
6118 band = chanctx_conf->def.chan->band;
6120 WARN_ON(link_id >= 0 &&
6121 !(sdata->vif.active_links & BIT(link_id)));
6122 /* MLD transmissions must not rely on the band */
6126 __ieee80211_tx_skb_tid_band(sdata, skb, tid, link_id, band);
6130 int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev,
6131 const u8 *buf, size_t len,
6132 const u8 *dest, __be16 proto, bool unencrypted,
6133 int link_id, u64 *cookie)
6135 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
6136 struct ieee80211_local *local = sdata->local;
6137 struct sta_info *sta;
6138 struct sk_buff *skb;
6139 struct ethhdr *ehdr;
6144 /* mutex lock is only needed for incrementing the cookie counter */
6145 lockdep_assert_wiphy(local->hw.wiphy);
6147 /* Only accept CONTROL_PORT_PROTOCOL configured in CONNECT/ASSOCIATE
6148 * or Pre-Authentication
6150 if (proto != sdata->control_port_protocol &&
6151 proto != cpu_to_be16(ETH_P_PREAUTH))
6154 if (proto == sdata->control_port_protocol)
6155 ctrl_flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO |
6156 IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP;
6159 flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
6162 ctrl_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
6164 flags |= IEEE80211_TX_INTFL_NL80211_FRAME_TX;
6166 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
6167 sizeof(struct ethhdr) + len);
6171 skb_reserve(skb, local->hw.extra_tx_headroom + sizeof(struct ethhdr));
6173 skb_put_data(skb, buf, len);
6175 ehdr = skb_push(skb, sizeof(struct ethhdr));
6176 memcpy(ehdr->h_dest, dest, ETH_ALEN);
6178 /* we may override the SA for MLO STA later */
6180 ctrl_flags |= u32_encode_bits(IEEE80211_LINK_UNSPECIFIED,
6181 IEEE80211_TX_CTRL_MLO_LINK);
6182 memcpy(ehdr->h_source, sdata->vif.addr, ETH_ALEN);
6184 struct ieee80211_bss_conf *link_conf;
6186 ctrl_flags |= u32_encode_bits(link_id,
6187 IEEE80211_TX_CTRL_MLO_LINK);
6190 link_conf = rcu_dereference(sdata->vif.link_conf[link_id]);
6196 memcpy(ehdr->h_source, link_conf->addr, ETH_ALEN);
6200 ehdr->h_proto = proto;
6203 skb->protocol = proto;
6204 skb_reset_network_header(skb);
6205 skb_reset_mac_header(skb);
6207 if (local->hw.queues < IEEE80211_NUM_ACS)
6210 /* update QoS header to prioritize control port frames if possible,
6211 * priorization also happens for control port frames send over
6215 err = ieee80211_lookup_ra_sta(sdata, skb, &sta);
6223 u16 queue = ieee80211_select_queue(sdata, sta, skb);
6225 skb_set_queue_mapping(skb, queue);
6228 * for MLO STA, the SA should be the AP MLD address, but
6229 * the link ID has been selected already
6231 if (sta && sta->sta.mlo)
6232 memcpy(ehdr->h_source, sdata->vif.addr, ETH_ALEN);
6238 __ieee80211_subif_start_xmit(skb, skb->dev, flags, ctrl_flags, cookie);
6244 int ieee80211_probe_mesh_link(struct wiphy *wiphy, struct net_device *dev,
6245 const u8 *buf, size_t len)
6247 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
6248 struct ieee80211_local *local = sdata->local;
6249 struct sk_buff *skb;
6251 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len +
6252 30 + /* header size */
6253 18); /* 11s header size */
6257 skb_reserve(skb, local->hw.extra_tx_headroom);
6258 skb_put_data(skb, buf, len);
6261 skb->protocol = htons(ETH_P_802_3);
6262 skb_reset_network_header(skb);
6263 skb_reset_mac_header(skb);
6266 __ieee80211_subif_start_xmit(skb, skb->dev, 0,
6267 IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP,