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-2022 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>
30 #include "ieee80211_i.h"
31 #include "driver-ops.h"
41 static __le16 ieee80211_duration(struct ieee80211_tx_data *tx,
42 struct sk_buff *skb, int group_addr,
45 int rate, mrate, erp, dur, i, shift = 0;
46 struct ieee80211_rate *txrate;
47 struct ieee80211_local *local = tx->local;
48 struct ieee80211_supported_band *sband;
49 struct ieee80211_hdr *hdr;
50 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
51 struct ieee80211_chanctx_conf *chanctx_conf;
54 /* assume HW handles this */
55 if (tx->rate.flags & (IEEE80211_TX_RC_MCS | IEEE80211_TX_RC_VHT_MCS))
59 chanctx_conf = rcu_dereference(tx->sdata->vif.bss_conf.chanctx_conf);
61 shift = ieee80211_chandef_get_shift(&chanctx_conf->def);
62 rate_flags = ieee80211_chandef_rate_flags(&chanctx_conf->def);
67 if (WARN_ON_ONCE(tx->rate.idx < 0))
70 sband = local->hw.wiphy->bands[info->band];
71 txrate = &sband->bitrates[tx->rate.idx];
73 erp = txrate->flags & IEEE80211_RATE_ERP_G;
75 /* device is expected to do this */
76 if (sband->band == NL80211_BAND_S1GHZ)
80 * data and mgmt (except PS Poll):
82 * - during contention period:
83 * if addr1 is group address: 0
84 * if more fragments = 0 and addr1 is individual address: time to
85 * transmit one ACK plus SIFS
86 * if more fragments = 1 and addr1 is individual address: time to
87 * transmit next fragment plus 2 x ACK plus 3 x SIFS
90 * - control response frame (CTS or ACK) shall be transmitted using the
91 * same rate as the immediately previous frame in the frame exchange
92 * sequence, if this rate belongs to the PHY mandatory rates, or else
93 * at the highest possible rate belonging to the PHY rates in the
96 hdr = (struct ieee80211_hdr *)skb->data;
97 if (ieee80211_is_ctl(hdr->frame_control)) {
98 /* TODO: These control frames are not currently sent by
99 * mac80211, but should they be implemented, this function
100 * needs to be updated to support duration field calculation.
102 * RTS: time needed to transmit pending data/mgmt frame plus
103 * one CTS frame plus one ACK frame plus 3 x SIFS
104 * CTS: duration of immediately previous RTS minus time
105 * required to transmit CTS and its SIFS
106 * ACK: 0 if immediately previous directed data/mgmt had
107 * more=0, with more=1 duration in ACK frame is duration
108 * from previous frame minus time needed to transmit ACK
110 * PS Poll: BIT(15) | BIT(14) | aid
116 if (0 /* FIX: data/mgmt during CFP */)
117 return cpu_to_le16(32768);
119 if (group_addr) /* Group address as the destination - no ACK */
122 /* Individual destination address:
123 * IEEE 802.11, Ch. 9.6 (after IEEE 802.11g changes)
124 * CTS and ACK frames shall be transmitted using the highest rate in
125 * basic rate set that is less than or equal to the rate of the
126 * immediately previous frame and that is using the same modulation
127 * (CCK or OFDM). If no basic rate set matches with these requirements,
128 * the highest mandatory rate of the PHY that is less than or equal to
129 * the rate of the previous frame is used.
130 * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps
133 /* use lowest available if everything fails */
134 mrate = sband->bitrates[0].bitrate;
135 for (i = 0; i < sband->n_bitrates; i++) {
136 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))
145 rate = DIV_ROUND_UP(r->bitrate, 1 << shift);
147 switch (sband->band) {
148 case NL80211_BAND_2GHZ:
149 case NL80211_BAND_LC: {
151 if (tx->sdata->deflink.operating_11g_mode)
152 flag = IEEE80211_RATE_MANDATORY_G;
154 flag = IEEE80211_RATE_MANDATORY_B;
159 case NL80211_BAND_5GHZ:
160 case NL80211_BAND_6GHZ:
161 if (r->flags & IEEE80211_RATE_MANDATORY_A)
164 case NL80211_BAND_S1GHZ:
165 case NL80211_BAND_60GHZ:
166 /* TODO, for now fall through */
167 case NUM_NL80211_BANDS:
173 /* No matching basic rate found; use highest suitable mandatory
175 rate = DIV_ROUND_UP(mrate, 1 << shift);
178 /* Don't calculate ACKs for QoS Frames with NoAck Policy set */
179 if (ieee80211_is_data_qos(hdr->frame_control) &&
180 *(ieee80211_get_qos_ctl(hdr)) & IEEE80211_QOS_CTL_ACK_POLICY_NOACK)
183 /* Time needed to transmit ACK
184 * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up
185 * to closest integer */
186 dur = ieee80211_frame_duration(sband->band, 10, rate, erp,
187 tx->sdata->vif.bss_conf.use_short_preamble,
191 /* Frame is fragmented: duration increases with time needed to
192 * transmit next fragment plus ACK and 2 x SIFS. */
193 dur *= 2; /* ACK + SIFS */
195 dur += ieee80211_frame_duration(sband->band, next_frag_len,
196 txrate->bitrate, erp,
197 tx->sdata->vif.bss_conf.use_short_preamble,
201 return cpu_to_le16(dur);
205 static ieee80211_tx_result debug_noinline
206 ieee80211_tx_h_dynamic_ps(struct ieee80211_tx_data *tx)
208 struct ieee80211_local *local = tx->local;
209 struct ieee80211_if_managed *ifmgd;
210 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
212 /* driver doesn't support power save */
213 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
216 /* hardware does dynamic power save */
217 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
220 /* dynamic power save disabled */
221 if (local->hw.conf.dynamic_ps_timeout <= 0)
224 /* we are scanning, don't enable power save */
228 if (!local->ps_sdata)
231 /* No point if we're going to suspend */
232 if (local->quiescing)
235 /* dynamic ps is supported only in managed mode */
236 if (tx->sdata->vif.type != NL80211_IFTYPE_STATION)
239 if (unlikely(info->flags & IEEE80211_TX_INTFL_OFFCHAN_TX_OK))
242 ifmgd = &tx->sdata->u.mgd;
245 * Don't wakeup from power save if u-apsd is enabled, voip ac has
246 * u-apsd enabled and the frame is in voip class. This effectively
247 * means that even if all access categories have u-apsd enabled, in
248 * practise u-apsd is only used with the voip ac. This is a
249 * workaround for the case when received voip class packets do not
250 * have correct qos tag for some reason, due the network or the
253 * Note: ifmgd->uapsd_queues access is racy here. If the value is
254 * changed via debugfs, user needs to reassociate manually to have
255 * everything in sync.
257 if ((ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED) &&
258 (ifmgd->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) &&
259 skb_get_queue_mapping(tx->skb) == IEEE80211_AC_VO)
262 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
263 ieee80211_stop_queues_by_reason(&local->hw,
264 IEEE80211_MAX_QUEUE_MAP,
265 IEEE80211_QUEUE_STOP_REASON_PS,
267 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
268 ieee80211_queue_work(&local->hw,
269 &local->dynamic_ps_disable_work);
272 /* Don't restart the timer if we're not disassociated */
273 if (!ifmgd->associated)
276 mod_timer(&local->dynamic_ps_timer, jiffies +
277 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
282 static ieee80211_tx_result debug_noinline
283 ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
286 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
287 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
290 if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED))
293 if (unlikely(test_bit(SCAN_SW_SCANNING, &tx->local->scanning)) &&
294 test_bit(SDATA_STATE_OFFCHANNEL, &tx->sdata->state) &&
295 !ieee80211_is_probe_req(hdr->frame_control) &&
296 !ieee80211_is_any_nullfunc(hdr->frame_control))
298 * When software scanning only nullfunc frames (to notify
299 * the sleep state to the AP) and probe requests (for the
300 * active scan) are allowed, all other frames should not be
301 * sent and we should not get here, but if we do
302 * nonetheless, drop them to avoid sending them
303 * off-channel. See the link below and
304 * ieee80211_start_scan() for more.
306 * http://article.gmane.org/gmane.linux.kernel.wireless.general/30089
310 if (tx->sdata->vif.type == NL80211_IFTYPE_OCB)
313 if (tx->flags & IEEE80211_TX_PS_BUFFERED)
317 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
319 if (likely(tx->flags & IEEE80211_TX_UNICAST)) {
320 if (unlikely(!assoc &&
321 ieee80211_is_data(hdr->frame_control))) {
322 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
323 sdata_info(tx->sdata,
324 "dropped data frame to not associated station %pM\n",
327 I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
330 } else if (unlikely(ieee80211_is_data(hdr->frame_control) &&
331 ieee80211_vif_get_num_mcast_if(tx->sdata) == 0)) {
333 * No associated STAs - no need to send multicast
342 /* This function is called whenever the AP is about to exceed the maximum limit
343 * of buffered frames for power saving STAs. This situation should not really
344 * happen often during normal operation, so dropping the oldest buffered packet
345 * from each queue should be OK to make some room for new frames. */
346 static void purge_old_ps_buffers(struct ieee80211_local *local)
348 int total = 0, purged = 0;
350 struct ieee80211_sub_if_data *sdata;
351 struct sta_info *sta;
353 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
356 if (sdata->vif.type == NL80211_IFTYPE_AP)
357 ps = &sdata->u.ap.ps;
358 else if (ieee80211_vif_is_mesh(&sdata->vif))
359 ps = &sdata->u.mesh.ps;
363 skb = skb_dequeue(&ps->bc_buf);
366 ieee80211_free_txskb(&local->hw, skb);
368 total += skb_queue_len(&ps->bc_buf);
372 * Drop one frame from each station from the lowest-priority
373 * AC that has frames at all.
375 list_for_each_entry_rcu(sta, &local->sta_list, list) {
378 for (ac = IEEE80211_AC_BK; ac >= IEEE80211_AC_VO; ac--) {
379 skb = skb_dequeue(&sta->ps_tx_buf[ac]);
380 total += skb_queue_len(&sta->ps_tx_buf[ac]);
383 ieee80211_free_txskb(&local->hw, skb);
389 local->total_ps_buffered = total;
390 ps_dbg_hw(&local->hw, "PS buffers full - purged %d frames\n", purged);
393 static ieee80211_tx_result
394 ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx)
396 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
397 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
401 * broadcast/multicast frame
403 * If any of the associated/peer stations is in power save mode,
404 * the frame is buffered to be sent after DTIM beacon frame.
405 * This is done either by the hardware or us.
408 /* powersaving STAs currently only in AP/VLAN/mesh mode */
409 if (tx->sdata->vif.type == NL80211_IFTYPE_AP ||
410 tx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
414 ps = &tx->sdata->bss->ps;
415 } else if (ieee80211_vif_is_mesh(&tx->sdata->vif)) {
416 ps = &tx->sdata->u.mesh.ps;
422 /* no buffering for ordered frames */
423 if (ieee80211_has_order(hdr->frame_control))
426 if (ieee80211_is_probe_req(hdr->frame_control))
429 if (ieee80211_hw_check(&tx->local->hw, QUEUE_CONTROL))
430 info->hw_queue = tx->sdata->vif.cab_queue;
432 /* no stations in PS mode and no buffered packets */
433 if (!atomic_read(&ps->num_sta_ps) && skb_queue_empty(&ps->bc_buf))
436 info->flags |= IEEE80211_TX_CTL_SEND_AFTER_DTIM;
438 /* device releases frame after DTIM beacon */
439 if (!ieee80211_hw_check(&tx->local->hw, HOST_BROADCAST_PS_BUFFERING))
442 /* buffered in mac80211 */
443 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
444 purge_old_ps_buffers(tx->local);
446 if (skb_queue_len(&ps->bc_buf) >= AP_MAX_BC_BUFFER) {
448 "BC TX buffer full - dropping the oldest frame\n");
449 ieee80211_free_txskb(&tx->local->hw, skb_dequeue(&ps->bc_buf));
451 tx->local->total_ps_buffered++;
453 skb_queue_tail(&ps->bc_buf, tx->skb);
458 static int ieee80211_use_mfp(__le16 fc, struct sta_info *sta,
461 if (!ieee80211_is_mgmt(fc))
464 if (sta == NULL || !test_sta_flag(sta, WLAN_STA_MFP))
467 if (!ieee80211_is_robust_mgmt_frame(skb))
473 static ieee80211_tx_result
474 ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
476 struct sta_info *sta = tx->sta;
477 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
478 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
479 struct ieee80211_local *local = tx->local;
484 if (unlikely((test_sta_flag(sta, WLAN_STA_PS_STA) ||
485 test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
486 test_sta_flag(sta, WLAN_STA_PS_DELIVER)) &&
487 !(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER))) {
488 int ac = skb_get_queue_mapping(tx->skb);
490 if (ieee80211_is_mgmt(hdr->frame_control) &&
491 !ieee80211_is_bufferable_mmpdu(hdr->frame_control)) {
492 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER;
496 ps_dbg(sta->sdata, "STA %pM aid %d: PS buffer for AC %d\n",
497 sta->sta.addr, sta->sta.aid, ac);
498 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
499 purge_old_ps_buffers(tx->local);
501 /* sync with ieee80211_sta_ps_deliver_wakeup */
502 spin_lock(&sta->ps_lock);
504 * STA woke up the meantime and all the frames on ps_tx_buf have
505 * been queued to pending queue. No reordering can happen, go
506 * ahead and Tx the packet.
508 if (!test_sta_flag(sta, WLAN_STA_PS_STA) &&
509 !test_sta_flag(sta, WLAN_STA_PS_DRIVER) &&
510 !test_sta_flag(sta, WLAN_STA_PS_DELIVER)) {
511 spin_unlock(&sta->ps_lock);
515 if (skb_queue_len(&sta->ps_tx_buf[ac]) >= STA_MAX_TX_BUFFER) {
516 struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf[ac]);
518 "STA %pM TX buffer for AC %d full - dropping oldest frame\n",
520 ieee80211_free_txskb(&local->hw, old);
522 tx->local->total_ps_buffered++;
524 info->control.jiffies = jiffies;
525 info->control.vif = &tx->sdata->vif;
526 info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
527 info->flags &= ~IEEE80211_TX_TEMPORARY_FLAGS;
528 skb_queue_tail(&sta->ps_tx_buf[ac], tx->skb);
529 spin_unlock(&sta->ps_lock);
531 if (!timer_pending(&local->sta_cleanup))
532 mod_timer(&local->sta_cleanup,
533 round_jiffies(jiffies +
534 STA_INFO_CLEANUP_INTERVAL));
537 * We queued up some frames, so the TIM bit might
538 * need to be set, recalculate it.
540 sta_info_recalc_tim(sta);
543 } else if (unlikely(test_sta_flag(sta, WLAN_STA_PS_STA))) {
545 "STA %pM in PS mode, but polling/in SP -> send frame\n",
552 static ieee80211_tx_result debug_noinline
553 ieee80211_tx_h_ps_buf(struct ieee80211_tx_data *tx)
555 if (unlikely(tx->flags & IEEE80211_TX_PS_BUFFERED))
558 if (tx->flags & IEEE80211_TX_UNICAST)
559 return ieee80211_tx_h_unicast_ps_buf(tx);
561 return ieee80211_tx_h_multicast_ps_buf(tx);
564 static ieee80211_tx_result debug_noinline
565 ieee80211_tx_h_check_control_port_protocol(struct ieee80211_tx_data *tx)
567 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
569 if (unlikely(tx->sdata->control_port_protocol == tx->skb->protocol)) {
570 if (tx->sdata->control_port_no_encrypt)
571 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
572 info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO;
573 info->flags |= IEEE80211_TX_CTL_USE_MINRATE;
579 static struct ieee80211_key *
580 ieee80211_select_link_key(struct ieee80211_tx_data *tx)
582 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
583 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
588 } which_key = USE_NONE;
589 struct ieee80211_link_data *link;
590 unsigned int link_id;
592 if (ieee80211_is_group_privacy_action(tx->skb))
593 which_key = USE_MCAST_KEY;
594 else if (ieee80211_is_mgmt(hdr->frame_control) &&
595 is_multicast_ether_addr(hdr->addr1) &&
596 ieee80211_is_robust_mgmt_frame(tx->skb))
597 which_key = USE_MGMT_KEY;
598 else if (is_multicast_ether_addr(hdr->addr1))
599 which_key = USE_MCAST_KEY;
603 link_id = u32_get_bits(info->control.flags, IEEE80211_TX_CTRL_MLO_LINK);
604 if (link_id == IEEE80211_LINK_UNSPECIFIED) {
605 link = &tx->sdata->deflink;
607 link = rcu_dereference(tx->sdata->link[link_id]);
616 return rcu_dereference(link->default_mgmt_key);
618 return rcu_dereference(link->default_multicast_key);
624 static ieee80211_tx_result debug_noinline
625 ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
627 struct ieee80211_key *key;
628 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
629 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
631 if (unlikely(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)) {
637 (key = rcu_dereference(tx->sta->ptk[tx->sta->ptk_idx])))
639 else if ((key = ieee80211_select_link_key(tx)))
641 else if (!is_multicast_ether_addr(hdr->addr1) &&
642 (key = rcu_dereference(tx->sdata->default_unicast_key)))
648 bool skip_hw = false;
650 /* TODO: add threshold stuff again */
652 switch (tx->key->conf.cipher) {
653 case WLAN_CIPHER_SUITE_WEP40:
654 case WLAN_CIPHER_SUITE_WEP104:
655 case WLAN_CIPHER_SUITE_TKIP:
656 if (!ieee80211_is_data_present(hdr->frame_control))
659 case WLAN_CIPHER_SUITE_CCMP:
660 case WLAN_CIPHER_SUITE_CCMP_256:
661 case WLAN_CIPHER_SUITE_GCMP:
662 case WLAN_CIPHER_SUITE_GCMP_256:
663 if (!ieee80211_is_data_present(hdr->frame_control) &&
664 !ieee80211_use_mfp(hdr->frame_control, tx->sta,
666 !ieee80211_is_group_privacy_action(tx->skb))
669 skip_hw = (tx->key->conf.flags &
670 IEEE80211_KEY_FLAG_SW_MGMT_TX) &&
671 ieee80211_is_mgmt(hdr->frame_control);
673 case WLAN_CIPHER_SUITE_AES_CMAC:
674 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
675 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
676 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
677 if (!ieee80211_is_mgmt(hdr->frame_control))
682 if (unlikely(tx->key && tx->key->flags & KEY_FLAG_TAINTED &&
683 !ieee80211_is_deauth(hdr->frame_control)))
686 if (!skip_hw && tx->key &&
687 tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
688 info->control.hw_key = &tx->key->conf;
689 } else if (ieee80211_is_data_present(hdr->frame_control) && tx->sta &&
690 test_sta_flag(tx->sta, WLAN_STA_USES_ENCRYPTION)) {
697 static ieee80211_tx_result debug_noinline
698 ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
700 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
701 struct ieee80211_hdr *hdr = (void *)tx->skb->data;
702 struct ieee80211_supported_band *sband;
704 struct ieee80211_tx_rate_control txrc;
705 struct ieee80211_sta_rates *ratetbl = NULL;
706 bool encap = info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP;
709 memset(&txrc, 0, sizeof(txrc));
711 sband = tx->local->hw.wiphy->bands[info->band];
713 len = min_t(u32, tx->skb->len + FCS_LEN,
714 tx->local->hw.wiphy->frag_threshold);
716 /* set up the tx rate control struct we give the RC algo */
717 txrc.hw = &tx->local->hw;
719 txrc.bss_conf = &tx->sdata->vif.bss_conf;
721 txrc.reported_rate.idx = -1;
722 txrc.rate_idx_mask = tx->sdata->rc_rateidx_mask[info->band];
724 if (tx->sdata->rc_has_mcs_mask[info->band])
725 txrc.rate_idx_mcs_mask =
726 tx->sdata->rc_rateidx_mcs_mask[info->band];
728 txrc.bss = (tx->sdata->vif.type == NL80211_IFTYPE_AP ||
729 tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
730 tx->sdata->vif.type == NL80211_IFTYPE_ADHOC ||
731 tx->sdata->vif.type == NL80211_IFTYPE_OCB);
733 /* set up RTS protection if desired */
734 if (len > tx->local->hw.wiphy->rts_threshold) {
738 info->control.use_rts = txrc.rts;
739 info->control.use_cts_prot = tx->sdata->vif.bss_conf.use_cts_prot;
742 * Use short preamble if the BSS can handle it, but not for
743 * management frames unless we know the receiver can handle
744 * that -- the management frame might be to a station that
745 * just wants a probe response.
747 if (tx->sdata->vif.bss_conf.use_short_preamble &&
748 (ieee80211_is_tx_data(tx->skb) ||
749 (tx->sta && test_sta_flag(tx->sta, WLAN_STA_SHORT_PREAMBLE))))
750 txrc.short_preamble = true;
752 info->control.short_preamble = txrc.short_preamble;
754 /* don't ask rate control when rate already injected via radiotap */
755 if (info->control.flags & IEEE80211_TX_CTRL_RATE_INJECT)
759 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
762 * Lets not bother rate control if we're associated and cannot
763 * talk to the sta. This should not happen.
765 if (WARN(test_bit(SCAN_SW_SCANNING, &tx->local->scanning) && assoc &&
766 !rate_usable_index_exists(sband, &tx->sta->sta),
767 "%s: Dropped data frame as no usable bitrate found while "
768 "scanning and associated. Target station: "
769 "%pM on %d GHz band\n",
771 encap ? ((struct ethhdr *)hdr)->h_dest : hdr->addr1,
776 * If we're associated with the sta at this point we know we can at
777 * least send the frame at the lowest bit rate.
779 rate_control_get_rate(tx->sdata, tx->sta, &txrc);
781 if (tx->sta && !info->control.skip_table)
782 ratetbl = rcu_dereference(tx->sta->sta.rates);
784 if (unlikely(info->control.rates[0].idx < 0)) {
786 struct ieee80211_tx_rate rate = {
787 .idx = ratetbl->rate[0].idx,
788 .flags = ratetbl->rate[0].flags,
789 .count = ratetbl->rate[0].count
792 if (ratetbl->rate[0].idx < 0)
800 tx->rate = info->control.rates[0];
803 if (txrc.reported_rate.idx < 0) {
804 txrc.reported_rate = tx->rate;
805 if (tx->sta && ieee80211_is_tx_data(tx->skb))
806 tx->sta->deflink.tx_stats.last_rate = txrc.reported_rate;
808 tx->sta->deflink.tx_stats.last_rate = txrc.reported_rate;
813 if (unlikely(!info->control.rates[0].count))
814 info->control.rates[0].count = 1;
816 if (WARN_ON_ONCE((info->control.rates[0].count > 1) &&
817 (info->flags & IEEE80211_TX_CTL_NO_ACK)))
818 info->control.rates[0].count = 1;
823 static __le16 ieee80211_tx_next_seq(struct sta_info *sta, int tid)
825 u16 *seq = &sta->tid_seq[tid];
826 __le16 ret = cpu_to_le16(*seq);
828 /* Increase the sequence number. */
829 *seq = (*seq + 0x10) & IEEE80211_SCTL_SEQ;
834 static ieee80211_tx_result debug_noinline
835 ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx)
837 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
838 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
842 * Packet injection may want to control the sequence
843 * number, if we have no matching interface then we
844 * neither assign one ourselves nor ask the driver to.
846 if (unlikely(info->control.vif->type == NL80211_IFTYPE_MONITOR))
849 if (unlikely(ieee80211_is_ctl(hdr->frame_control)))
852 if (ieee80211_hdrlen(hdr->frame_control) < 24)
855 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
858 if (info->control.flags & IEEE80211_TX_CTRL_NO_SEQNO)
861 /* SNS11 from 802.11be 10.3.2.14 */
862 if (unlikely(is_multicast_ether_addr(hdr->addr1) &&
863 info->control.vif->valid_links &&
864 info->control.vif->type == NL80211_IFTYPE_AP)) {
865 if (info->control.flags & IEEE80211_TX_CTRL_MCAST_MLO_FIRST_TX)
866 tx->sdata->mld_mcast_seq += 0x10;
867 hdr->seq_ctrl = cpu_to_le16(tx->sdata->mld_mcast_seq);
872 * Anything but QoS data that has a sequence number field
873 * (is long enough) gets a sequence number from the global
874 * counter. QoS data frames with a multicast destination
875 * also use the global counter (802.11-2012 9.3.2.10).
877 if (!ieee80211_is_data_qos(hdr->frame_control) ||
878 is_multicast_ether_addr(hdr->addr1)) {
879 /* driver should assign sequence number */
880 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
881 /* for pure STA mode without beacons, we can do it */
882 hdr->seq_ctrl = cpu_to_le16(tx->sdata->sequence_number);
883 tx->sdata->sequence_number += 0x10;
885 tx->sta->deflink.tx_stats.msdu[IEEE80211_NUM_TIDS]++;
890 * This should be true for injected/management frames only, for
891 * management frames we have set the IEEE80211_TX_CTL_ASSIGN_SEQ
892 * above since they are not QoS-data frames.
897 /* include per-STA, per-TID sequence counter */
898 tid = ieee80211_get_tid(hdr);
899 tx->sta->deflink.tx_stats.msdu[tid]++;
901 hdr->seq_ctrl = ieee80211_tx_next_seq(tx->sta, tid);
906 static int ieee80211_fragment(struct ieee80211_tx_data *tx,
907 struct sk_buff *skb, int hdrlen,
910 struct ieee80211_local *local = tx->local;
911 struct ieee80211_tx_info *info;
913 int per_fragm = frag_threshold - hdrlen - FCS_LEN;
914 int pos = hdrlen + per_fragm;
915 int rem = skb->len - hdrlen - per_fragm;
917 if (WARN_ON(rem < 0))
920 /* first fragment was already added to queue by caller */
923 int fraglen = per_fragm;
928 tmp = dev_alloc_skb(local->tx_headroom +
930 IEEE80211_ENCRYPT_HEADROOM +
931 IEEE80211_ENCRYPT_TAILROOM);
935 __skb_queue_tail(&tx->skbs, tmp);
938 local->tx_headroom + IEEE80211_ENCRYPT_HEADROOM);
940 /* copy control information */
941 memcpy(tmp->cb, skb->cb, sizeof(tmp->cb));
943 info = IEEE80211_SKB_CB(tmp);
944 info->flags &= ~(IEEE80211_TX_CTL_CLEAR_PS_FILT |
945 IEEE80211_TX_CTL_FIRST_FRAGMENT);
948 info->flags |= IEEE80211_TX_CTL_MORE_FRAMES;
950 skb_copy_queue_mapping(tmp, skb);
951 tmp->priority = skb->priority;
954 /* copy header and data */
955 skb_put_data(tmp, skb->data, hdrlen);
956 skb_put_data(tmp, skb->data + pos, fraglen);
961 /* adjust first fragment's length */
962 skb_trim(skb, hdrlen + per_fragm);
966 static ieee80211_tx_result debug_noinline
967 ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
969 struct sk_buff *skb = tx->skb;
970 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
971 struct ieee80211_hdr *hdr = (void *)skb->data;
972 int frag_threshold = tx->local->hw.wiphy->frag_threshold;
976 /* no matter what happens, tx->skb moves to tx->skbs */
977 __skb_queue_tail(&tx->skbs, skb);
980 if (info->flags & IEEE80211_TX_CTL_DONTFRAG)
983 if (ieee80211_hw_check(&tx->local->hw, SUPPORTS_TX_FRAG))
987 * Warn when submitting a fragmented A-MPDU frame and drop it.
988 * This scenario is handled in ieee80211_tx_prepare but extra
989 * caution taken here as fragmented ampdu may cause Tx stop.
991 if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU))
994 hdrlen = ieee80211_hdrlen(hdr->frame_control);
996 /* internal error, why isn't DONTFRAG set? */
997 if (WARN_ON(skb->len + FCS_LEN <= frag_threshold))
1001 * Now fragment the frame. This will allocate all the fragments and
1002 * chain them (using skb as the first fragment) to skb->next.
1003 * During transmission, we will remove the successfully transmitted
1004 * fragments from this list. When the low-level driver rejects one
1005 * of the fragments then we will simply pretend to accept the skb
1006 * but store it away as pending.
1008 if (ieee80211_fragment(tx, skb, hdrlen, frag_threshold))
1011 /* update duration/seq/flags of fragments */
1014 skb_queue_walk(&tx->skbs, skb) {
1015 const __le16 morefrags = cpu_to_le16(IEEE80211_FCTL_MOREFRAGS);
1017 hdr = (void *)skb->data;
1018 info = IEEE80211_SKB_CB(skb);
1020 if (!skb_queue_is_last(&tx->skbs, skb)) {
1021 hdr->frame_control |= morefrags;
1023 * No multi-rate retries for fragmented frames, that
1024 * would completely throw off the NAV at other STAs.
1026 info->control.rates[1].idx = -1;
1027 info->control.rates[2].idx = -1;
1028 info->control.rates[3].idx = -1;
1029 BUILD_BUG_ON(IEEE80211_TX_MAX_RATES != 4);
1030 info->flags &= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE;
1032 hdr->frame_control &= ~morefrags;
1034 hdr->seq_ctrl |= cpu_to_le16(fragnum & IEEE80211_SCTL_FRAG);
1041 static ieee80211_tx_result debug_noinline
1042 ieee80211_tx_h_stats(struct ieee80211_tx_data *tx)
1044 struct sk_buff *skb;
1050 skb_queue_walk(&tx->skbs, skb) {
1051 ac = skb_get_queue_mapping(skb);
1052 tx->sta->deflink.tx_stats.bytes[ac] += skb->len;
1055 tx->sta->deflink.tx_stats.packets[ac]++;
1060 static ieee80211_tx_result debug_noinline
1061 ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx)
1066 switch (tx->key->conf.cipher) {
1067 case WLAN_CIPHER_SUITE_WEP40:
1068 case WLAN_CIPHER_SUITE_WEP104:
1069 return ieee80211_crypto_wep_encrypt(tx);
1070 case WLAN_CIPHER_SUITE_TKIP:
1071 return ieee80211_crypto_tkip_encrypt(tx);
1072 case WLAN_CIPHER_SUITE_CCMP:
1073 return ieee80211_crypto_ccmp_encrypt(
1074 tx, IEEE80211_CCMP_MIC_LEN);
1075 case WLAN_CIPHER_SUITE_CCMP_256:
1076 return ieee80211_crypto_ccmp_encrypt(
1077 tx, IEEE80211_CCMP_256_MIC_LEN);
1078 case WLAN_CIPHER_SUITE_AES_CMAC:
1079 return ieee80211_crypto_aes_cmac_encrypt(tx);
1080 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
1081 return ieee80211_crypto_aes_cmac_256_encrypt(tx);
1082 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
1083 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
1084 return ieee80211_crypto_aes_gmac_encrypt(tx);
1085 case WLAN_CIPHER_SUITE_GCMP:
1086 case WLAN_CIPHER_SUITE_GCMP_256:
1087 return ieee80211_crypto_gcmp_encrypt(tx);
1093 static ieee80211_tx_result debug_noinline
1094 ieee80211_tx_h_calculate_duration(struct ieee80211_tx_data *tx)
1096 struct sk_buff *skb;
1097 struct ieee80211_hdr *hdr;
1101 skb_queue_walk(&tx->skbs, skb) {
1102 hdr = (void *) skb->data;
1103 if (unlikely(ieee80211_is_pspoll(hdr->frame_control)))
1104 break; /* must not overwrite AID */
1105 if (!skb_queue_is_last(&tx->skbs, skb)) {
1106 struct sk_buff *next = skb_queue_next(&tx->skbs, skb);
1107 next_len = next->len;
1110 group_addr = is_multicast_ether_addr(hdr->addr1);
1113 ieee80211_duration(tx, skb, group_addr, next_len);
1119 /* actual transmit path */
1121 static bool ieee80211_tx_prep_agg(struct ieee80211_tx_data *tx,
1122 struct sk_buff *skb,
1123 struct ieee80211_tx_info *info,
1124 struct tid_ampdu_tx *tid_tx,
1127 bool queued = false;
1128 bool reset_agg_timer = false;
1129 struct sk_buff *purge_skb = NULL;
1131 if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
1132 reset_agg_timer = true;
1133 } else if (test_bit(HT_AGG_STATE_WANT_START, &tid_tx->state)) {
1135 * nothing -- this aggregation session is being started
1136 * but that might still fail with the driver
1138 } else if (!tx->sta->sta.txq[tid]) {
1139 spin_lock(&tx->sta->lock);
1141 * Need to re-check now, because we may get here
1143 * 1) in the window during which the setup is actually
1144 * already done, but not marked yet because not all
1145 * packets are spliced over to the driver pending
1146 * queue yet -- if this happened we acquire the lock
1147 * either before or after the splice happens, but
1148 * need to recheck which of these cases happened.
1150 * 2) during session teardown, if the OPERATIONAL bit
1151 * was cleared due to the teardown but the pointer
1152 * hasn't been assigned NULL yet (or we loaded it
1153 * before it was assigned) -- in this case it may
1154 * now be NULL which means we should just let the
1155 * packet pass through because splicing the frames
1156 * back is already done.
1158 tid_tx = rcu_dereference_protected_tid_tx(tx->sta, tid);
1161 /* do nothing, let packet pass through */
1162 } else if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
1163 reset_agg_timer = true;
1166 if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER) {
1167 clear_sta_flag(tx->sta, WLAN_STA_SP);
1168 ps_dbg(tx->sta->sdata,
1169 "STA %pM aid %d: SP frame queued, close the SP w/o telling the peer\n",
1170 tx->sta->sta.addr, tx->sta->sta.aid);
1172 info->control.vif = &tx->sdata->vif;
1173 info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
1174 info->flags &= ~IEEE80211_TX_TEMPORARY_FLAGS;
1175 __skb_queue_tail(&tid_tx->pending, skb);
1176 if (skb_queue_len(&tid_tx->pending) > STA_MAX_TX_BUFFER)
1177 purge_skb = __skb_dequeue(&tid_tx->pending);
1179 spin_unlock(&tx->sta->lock);
1182 ieee80211_free_txskb(&tx->local->hw, purge_skb);
1185 /* reset session timer */
1186 if (reset_agg_timer)
1187 tid_tx->last_tx = jiffies;
1193 ieee80211_aggr_check(struct ieee80211_sub_if_data *sdata,
1194 struct sta_info *sta,
1195 struct sk_buff *skb)
1197 struct rate_control_ref *ref = sdata->local->rate_ctrl;
1200 if (!ref || !(ref->ops->capa & RATE_CTRL_CAPA_AMPDU_TRIGGER))
1203 if (!sta || !sta->sta.deflink.ht_cap.ht_supported ||
1204 !sta->sta.wme || skb_get_queue_mapping(skb) == IEEE80211_AC_VO ||
1205 skb->protocol == sdata->control_port_protocol)
1208 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
1209 if (likely(sta->ampdu_mlme.tid_tx[tid]))
1212 ieee80211_start_tx_ba_session(&sta->sta, tid, 0);
1217 * pass %NULL for the station if unknown, a valid pointer if known
1218 * or an ERR_PTR() if the station is known not to exist
1220 static ieee80211_tx_result
1221 ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata,
1222 struct ieee80211_tx_data *tx,
1223 struct sta_info *sta, struct sk_buff *skb)
1225 struct ieee80211_local *local = sdata->local;
1226 struct ieee80211_hdr *hdr;
1227 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1228 bool aggr_check = false;
1231 memset(tx, 0, sizeof(*tx));
1235 __skb_queue_head_init(&tx->skbs);
1238 * If this flag is set to true anywhere, and we get here,
1239 * we are doing the needed processing, so remove the flag
1242 info->control.flags &= ~IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
1244 hdr = (struct ieee80211_hdr *) skb->data;
1250 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
1251 tx->sta = rcu_dereference(sdata->u.vlan.sta);
1252 if (!tx->sta && sdata->wdev.use_4addr)
1254 } else if (tx->sdata->control_port_protocol == tx->skb->protocol) {
1255 tx->sta = sta_info_get_bss(sdata, hdr->addr1);
1257 if (!tx->sta && !is_multicast_ether_addr(hdr->addr1)) {
1258 tx->sta = sta_info_get(sdata, hdr->addr1);
1263 if (tx->sta && ieee80211_is_data_qos(hdr->frame_control) &&
1264 !ieee80211_is_qos_nullfunc(hdr->frame_control) &&
1265 ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
1266 !ieee80211_hw_check(&local->hw, TX_AMPDU_SETUP_IN_HW)) {
1267 struct tid_ampdu_tx *tid_tx;
1269 tid = ieee80211_get_tid(hdr);
1270 tid_tx = rcu_dereference(tx->sta->ampdu_mlme.tid_tx[tid]);
1271 if (!tid_tx && aggr_check) {
1272 ieee80211_aggr_check(sdata, tx->sta, skb);
1273 tid_tx = rcu_dereference(tx->sta->ampdu_mlme.tid_tx[tid]);
1279 queued = ieee80211_tx_prep_agg(tx, skb, info,
1282 if (unlikely(queued))
1287 if (is_multicast_ether_addr(hdr->addr1)) {
1288 tx->flags &= ~IEEE80211_TX_UNICAST;
1289 info->flags |= IEEE80211_TX_CTL_NO_ACK;
1291 tx->flags |= IEEE80211_TX_UNICAST;
1293 if (!(info->flags & IEEE80211_TX_CTL_DONTFRAG)) {
1294 if (!(tx->flags & IEEE80211_TX_UNICAST) ||
1295 skb->len + FCS_LEN <= local->hw.wiphy->frag_threshold ||
1296 info->flags & IEEE80211_TX_CTL_AMPDU)
1297 info->flags |= IEEE80211_TX_CTL_DONTFRAG;
1301 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
1302 else if (test_and_clear_sta_flag(tx->sta, WLAN_STA_CLEAR_PS_FILT)) {
1303 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
1304 ieee80211_check_fast_xmit(tx->sta);
1307 info->flags |= IEEE80211_TX_CTL_FIRST_FRAGMENT;
1312 static struct txq_info *ieee80211_get_txq(struct ieee80211_local *local,
1313 struct ieee80211_vif *vif,
1314 struct sta_info *sta,
1315 struct sk_buff *skb)
1317 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1318 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1319 struct ieee80211_txq *txq = NULL;
1321 if ((info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) ||
1322 (info->control.flags & IEEE80211_TX_CTRL_PS_RESPONSE))
1325 if (!(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) &&
1326 unlikely(!ieee80211_is_data_present(hdr->frame_control))) {
1327 if ((!ieee80211_is_mgmt(hdr->frame_control) ||
1328 ieee80211_is_bufferable_mmpdu(hdr->frame_control) ||
1329 vif->type == NL80211_IFTYPE_STATION) &&
1330 sta && sta->uploaded) {
1332 * This will be NULL if the driver didn't set the
1333 * opt-in hardware flag.
1335 txq = sta->sta.txq[IEEE80211_NUM_TIDS];
1338 u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
1343 txq = sta->sta.txq[tid];
1351 return to_txq_info(txq);
1354 static void ieee80211_set_skb_enqueue_time(struct sk_buff *skb)
1356 struct sk_buff *next;
1357 codel_time_t now = codel_get_time();
1359 skb_list_walk_safe(skb, skb, next)
1360 IEEE80211_SKB_CB(skb)->control.enqueue_time = now;
1363 static u32 codel_skb_len_func(const struct sk_buff *skb)
1368 static codel_time_t codel_skb_time_func(const struct sk_buff *skb)
1370 const struct ieee80211_tx_info *info;
1372 info = (const struct ieee80211_tx_info *)skb->cb;
1373 return info->control.enqueue_time;
1376 static struct sk_buff *codel_dequeue_func(struct codel_vars *cvars,
1379 struct ieee80211_local *local;
1380 struct txq_info *txqi;
1382 struct fq_flow *flow;
1385 local = vif_to_sdata(txqi->txq.vif)->local;
1388 if (cvars == &txqi->def_cvars)
1389 flow = &txqi->tin.default_flow;
1391 flow = &fq->flows[cvars - local->cvars];
1393 return fq_flow_dequeue(fq, flow);
1396 static void codel_drop_func(struct sk_buff *skb,
1399 struct ieee80211_local *local;
1400 struct ieee80211_hw *hw;
1401 struct txq_info *txqi;
1404 local = vif_to_sdata(txqi->txq.vif)->local;
1407 ieee80211_free_txskb(hw, skb);
1410 static struct sk_buff *fq_tin_dequeue_func(struct fq *fq,
1412 struct fq_flow *flow)
1414 struct ieee80211_local *local;
1415 struct txq_info *txqi;
1416 struct codel_vars *cvars;
1417 struct codel_params *cparams;
1418 struct codel_stats *cstats;
1420 local = container_of(fq, struct ieee80211_local, fq);
1421 txqi = container_of(tin, struct txq_info, tin);
1422 cstats = &txqi->cstats;
1424 if (txqi->txq.sta) {
1425 struct sta_info *sta = container_of(txqi->txq.sta,
1426 struct sta_info, sta);
1427 cparams = &sta->cparams;
1429 cparams = &local->cparams;
1432 if (flow == &tin->default_flow)
1433 cvars = &txqi->def_cvars;
1435 cvars = &local->cvars[flow - fq->flows];
1437 return codel_dequeue(txqi,
1443 codel_skb_time_func,
1445 codel_dequeue_func);
1448 static void fq_skb_free_func(struct fq *fq,
1450 struct fq_flow *flow,
1451 struct sk_buff *skb)
1453 struct ieee80211_local *local;
1455 local = container_of(fq, struct ieee80211_local, fq);
1456 ieee80211_free_txskb(&local->hw, skb);
1459 static void ieee80211_txq_enqueue(struct ieee80211_local *local,
1460 struct txq_info *txqi,
1461 struct sk_buff *skb)
1463 struct fq *fq = &local->fq;
1464 struct fq_tin *tin = &txqi->tin;
1465 u32 flow_idx = fq_flow_idx(fq, skb);
1467 ieee80211_set_skb_enqueue_time(skb);
1469 spin_lock_bh(&fq->lock);
1471 * For management frames, don't really apply codel etc.,
1472 * we don't want to apply any shaping or anything we just
1473 * want to simplify the driver API by having them on the
1476 if (unlikely(txqi->txq.tid == IEEE80211_NUM_TIDS)) {
1477 IEEE80211_SKB_CB(skb)->control.flags |=
1478 IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
1479 __skb_queue_tail(&txqi->frags, skb);
1481 fq_tin_enqueue(fq, tin, flow_idx, skb,
1484 spin_unlock_bh(&fq->lock);
1487 static bool fq_vlan_filter_func(struct fq *fq, struct fq_tin *tin,
1488 struct fq_flow *flow, struct sk_buff *skb,
1491 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1493 return info->control.vif == data;
1496 void ieee80211_txq_remove_vlan(struct ieee80211_local *local,
1497 struct ieee80211_sub_if_data *sdata)
1499 struct fq *fq = &local->fq;
1500 struct txq_info *txqi;
1502 struct ieee80211_sub_if_data *ap;
1504 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_AP_VLAN))
1507 ap = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap);
1512 txqi = to_txq_info(ap->vif.txq);
1515 spin_lock_bh(&fq->lock);
1516 fq_tin_filter(fq, tin, fq_vlan_filter_func, &sdata->vif,
1518 spin_unlock_bh(&fq->lock);
1521 void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata,
1522 struct sta_info *sta,
1523 struct txq_info *txqi, int tid)
1525 fq_tin_init(&txqi->tin);
1526 codel_vars_init(&txqi->def_cvars);
1527 codel_stats_init(&txqi->cstats);
1528 __skb_queue_head_init(&txqi->frags);
1529 INIT_LIST_HEAD(&txqi->schedule_order);
1531 txqi->txq.vif = &sdata->vif;
1534 sdata->vif.txq = &txqi->txq;
1536 txqi->txq.ac = IEEE80211_AC_BE;
1541 if (tid == IEEE80211_NUM_TIDS) {
1542 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
1543 /* Drivers need to opt in to the management MPDU TXQ */
1544 if (!ieee80211_hw_check(&sdata->local->hw,
1547 } else if (!ieee80211_hw_check(&sdata->local->hw,
1549 /* Drivers need to opt in to the bufferable MMPDU TXQ */
1552 txqi->txq.ac = IEEE80211_AC_VO;
1554 txqi->txq.ac = ieee80211_ac_from_tid(tid);
1557 txqi->txq.sta = &sta->sta;
1558 txqi->txq.tid = tid;
1559 sta->sta.txq[tid] = &txqi->txq;
1562 void ieee80211_txq_purge(struct ieee80211_local *local,
1563 struct txq_info *txqi)
1565 struct fq *fq = &local->fq;
1566 struct fq_tin *tin = &txqi->tin;
1568 spin_lock_bh(&fq->lock);
1569 fq_tin_reset(fq, tin, fq_skb_free_func);
1570 ieee80211_purge_tx_queue(&local->hw, &txqi->frags);
1571 spin_unlock_bh(&fq->lock);
1573 spin_lock_bh(&local->active_txq_lock[txqi->txq.ac]);
1574 list_del_init(&txqi->schedule_order);
1575 spin_unlock_bh(&local->active_txq_lock[txqi->txq.ac]);
1578 void ieee80211_txq_set_params(struct ieee80211_local *local)
1580 if (local->hw.wiphy->txq_limit)
1581 local->fq.limit = local->hw.wiphy->txq_limit;
1583 local->hw.wiphy->txq_limit = local->fq.limit;
1585 if (local->hw.wiphy->txq_memory_limit)
1586 local->fq.memory_limit = local->hw.wiphy->txq_memory_limit;
1588 local->hw.wiphy->txq_memory_limit = local->fq.memory_limit;
1590 if (local->hw.wiphy->txq_quantum)
1591 local->fq.quantum = local->hw.wiphy->txq_quantum;
1593 local->hw.wiphy->txq_quantum = local->fq.quantum;
1596 int ieee80211_txq_setup_flows(struct ieee80211_local *local)
1598 struct fq *fq = &local->fq;
1601 bool supp_vht = false;
1602 enum nl80211_band band;
1604 ret = fq_init(fq, 4096);
1609 * If the hardware doesn't support VHT, it is safe to limit the maximum
1610 * queue size. 4 Mbytes is 64 max-size aggregates in 802.11n.
1612 for (band = 0; band < NUM_NL80211_BANDS; band++) {
1613 struct ieee80211_supported_band *sband;
1615 sband = local->hw.wiphy->bands[band];
1619 supp_vht = supp_vht || sband->vht_cap.vht_supported;
1623 fq->memory_limit = 4 << 20; /* 4 Mbytes */
1625 codel_params_init(&local->cparams);
1626 local->cparams.interval = MS2TIME(100);
1627 local->cparams.target = MS2TIME(20);
1628 local->cparams.ecn = true;
1630 local->cvars = kcalloc(fq->flows_cnt, sizeof(local->cvars[0]),
1632 if (!local->cvars) {
1633 spin_lock_bh(&fq->lock);
1634 fq_reset(fq, fq_skb_free_func);
1635 spin_unlock_bh(&fq->lock);
1639 for (i = 0; i < fq->flows_cnt; i++)
1640 codel_vars_init(&local->cvars[i]);
1642 ieee80211_txq_set_params(local);
1647 void ieee80211_txq_teardown_flows(struct ieee80211_local *local)
1649 struct fq *fq = &local->fq;
1651 kfree(local->cvars);
1652 local->cvars = NULL;
1654 spin_lock_bh(&fq->lock);
1655 fq_reset(fq, fq_skb_free_func);
1656 spin_unlock_bh(&fq->lock);
1659 static bool ieee80211_queue_skb(struct ieee80211_local *local,
1660 struct ieee80211_sub_if_data *sdata,
1661 struct sta_info *sta,
1662 struct sk_buff *skb)
1664 struct ieee80211_vif *vif;
1665 struct txq_info *txqi;
1667 if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
1670 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1671 sdata = container_of(sdata->bss,
1672 struct ieee80211_sub_if_data, u.ap);
1675 txqi = ieee80211_get_txq(local, vif, sta, skb);
1680 ieee80211_txq_enqueue(local, txqi, skb);
1682 schedule_and_wake_txq(local, txqi);
1687 static bool ieee80211_tx_frags(struct ieee80211_local *local,
1688 struct ieee80211_vif *vif,
1689 struct sta_info *sta,
1690 struct sk_buff_head *skbs,
1693 struct ieee80211_tx_control control = {};
1694 struct sk_buff *skb, *tmp;
1695 unsigned long flags;
1697 skb_queue_walk_safe(skbs, skb, tmp) {
1698 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1699 int q = info->hw_queue;
1701 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1702 if (WARN_ON_ONCE(q >= local->hw.queues)) {
1703 __skb_unlink(skb, skbs);
1704 ieee80211_free_txskb(&local->hw, skb);
1709 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1710 if (local->queue_stop_reasons[q] ||
1711 (!txpending && !skb_queue_empty(&local->pending[q]))) {
1712 if (unlikely(info->flags &
1713 IEEE80211_TX_INTFL_OFFCHAN_TX_OK)) {
1714 if (local->queue_stop_reasons[q] &
1715 ~BIT(IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL)) {
1717 * Drop off-channel frames if queues
1718 * are stopped for any reason other
1719 * than off-channel operation. Never
1722 spin_unlock_irqrestore(
1723 &local->queue_stop_reason_lock,
1725 ieee80211_purge_tx_queue(&local->hw,
1732 * Since queue is stopped, queue up frames for
1733 * later transmission from the tx-pending
1734 * tasklet when the queue is woken again.
1737 skb_queue_splice_init(skbs,
1738 &local->pending[q]);
1740 skb_queue_splice_tail_init(skbs,
1741 &local->pending[q]);
1743 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1748 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1750 info->control.vif = vif;
1751 control.sta = sta ? &sta->sta : NULL;
1753 __skb_unlink(skb, skbs);
1754 drv_tx(local, &control, skb);
1761 * Returns false if the frame couldn't be transmitted but was queued instead.
1763 static bool __ieee80211_tx(struct ieee80211_local *local,
1764 struct sk_buff_head *skbs, struct sta_info *sta,
1767 struct ieee80211_tx_info *info;
1768 struct ieee80211_sub_if_data *sdata;
1769 struct ieee80211_vif *vif;
1770 struct sk_buff *skb;
1773 if (WARN_ON(skb_queue_empty(skbs)))
1776 skb = skb_peek(skbs);
1777 info = IEEE80211_SKB_CB(skb);
1778 sdata = vif_to_sdata(info->control.vif);
1779 if (sta && !sta->uploaded)
1782 switch (sdata->vif.type) {
1783 case NL80211_IFTYPE_MONITOR:
1784 if (sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) {
1788 sdata = rcu_dereference(local->monitor_sdata);
1792 vif->hw_queue[skb_get_queue_mapping(skb)];
1793 } else if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) {
1794 ieee80211_purge_tx_queue(&local->hw, skbs);
1799 case NL80211_IFTYPE_AP_VLAN:
1800 sdata = container_of(sdata->bss,
1801 struct ieee80211_sub_if_data, u.ap);
1808 result = ieee80211_tx_frags(local, vif, sta, skbs, txpending);
1810 WARN_ON_ONCE(!skb_queue_empty(skbs));
1816 * Invoke TX handlers, return 0 on success and non-zero if the
1817 * frame was dropped or queued.
1819 * The handlers are split into an early and late part. The latter is everything
1820 * that can be sensitive to reordering, and will be deferred to after packets
1821 * are dequeued from the intermediate queues (when they are enabled).
1823 static int invoke_tx_handlers_early(struct ieee80211_tx_data *tx)
1825 ieee80211_tx_result res = TX_DROP;
1827 #define CALL_TXH(txh) \
1830 if (res != TX_CONTINUE) \
1834 CALL_TXH(ieee80211_tx_h_dynamic_ps);
1835 CALL_TXH(ieee80211_tx_h_check_assoc);
1836 CALL_TXH(ieee80211_tx_h_ps_buf);
1837 CALL_TXH(ieee80211_tx_h_check_control_port_protocol);
1838 CALL_TXH(ieee80211_tx_h_select_key);
1841 if (unlikely(res == TX_DROP)) {
1842 I802_DEBUG_INC(tx->local->tx_handlers_drop);
1844 ieee80211_free_txskb(&tx->local->hw, tx->skb);
1846 ieee80211_purge_tx_queue(&tx->local->hw, &tx->skbs);
1848 } else if (unlikely(res == TX_QUEUED)) {
1849 I802_DEBUG_INC(tx->local->tx_handlers_queued);
1857 * Late handlers can be called while the sta lock is held. Handlers that can
1858 * cause packets to be generated will cause deadlock!
1860 static int invoke_tx_handlers_late(struct ieee80211_tx_data *tx)
1862 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
1863 ieee80211_tx_result res = TX_CONTINUE;
1865 if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL))
1866 CALL_TXH(ieee80211_tx_h_rate_ctrl);
1868 if (unlikely(info->flags & IEEE80211_TX_INTFL_RETRANSMISSION)) {
1869 __skb_queue_tail(&tx->skbs, tx->skb);
1874 CALL_TXH(ieee80211_tx_h_michael_mic_add);
1875 CALL_TXH(ieee80211_tx_h_sequence);
1876 CALL_TXH(ieee80211_tx_h_fragment);
1877 /* handlers after fragment must be aware of tx info fragmentation! */
1878 CALL_TXH(ieee80211_tx_h_stats);
1879 CALL_TXH(ieee80211_tx_h_encrypt);
1880 if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL))
1881 CALL_TXH(ieee80211_tx_h_calculate_duration);
1885 if (unlikely(res == TX_DROP)) {
1886 I802_DEBUG_INC(tx->local->tx_handlers_drop);
1888 ieee80211_free_txskb(&tx->local->hw, tx->skb);
1890 ieee80211_purge_tx_queue(&tx->local->hw, &tx->skbs);
1892 } else if (unlikely(res == TX_QUEUED)) {
1893 I802_DEBUG_INC(tx->local->tx_handlers_queued);
1900 static int invoke_tx_handlers(struct ieee80211_tx_data *tx)
1902 int r = invoke_tx_handlers_early(tx);
1906 return invoke_tx_handlers_late(tx);
1909 bool ieee80211_tx_prepare_skb(struct ieee80211_hw *hw,
1910 struct ieee80211_vif *vif, struct sk_buff *skb,
1911 int band, struct ieee80211_sta **sta)
1913 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1914 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1915 struct ieee80211_tx_data tx;
1916 struct sk_buff *skb2;
1918 if (ieee80211_tx_prepare(sdata, &tx, NULL, skb) == TX_DROP)
1922 info->control.vif = vif;
1923 info->hw_queue = vif->hw_queue[skb_get_queue_mapping(skb)];
1925 if (invoke_tx_handlers(&tx))
1930 *sta = &tx.sta->sta;
1935 /* this function isn't suitable for fragmented data frames */
1936 skb2 = __skb_dequeue(&tx.skbs);
1937 if (WARN_ON(skb2 != skb || !skb_queue_empty(&tx.skbs))) {
1938 ieee80211_free_txskb(hw, skb2);
1939 ieee80211_purge_tx_queue(hw, &tx.skbs);
1945 EXPORT_SYMBOL(ieee80211_tx_prepare_skb);
1948 * Returns false if the frame couldn't be transmitted but was queued instead.
1950 static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata,
1951 struct sta_info *sta, struct sk_buff *skb,
1954 struct ieee80211_local *local = sdata->local;
1955 struct ieee80211_tx_data tx;
1956 ieee80211_tx_result res_prepare;
1957 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1960 if (unlikely(skb->len < 10)) {
1965 /* initialises tx */
1966 res_prepare = ieee80211_tx_prepare(sdata, &tx, sta, skb);
1968 if (unlikely(res_prepare == TX_DROP)) {
1969 ieee80211_free_txskb(&local->hw, skb);
1971 } else if (unlikely(res_prepare == TX_QUEUED)) {
1975 /* set up hw_queue value early */
1976 if (!(info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) ||
1977 !ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
1979 sdata->vif.hw_queue[skb_get_queue_mapping(skb)];
1981 if (invoke_tx_handlers_early(&tx))
1984 if (ieee80211_queue_skb(local, sdata, tx.sta, tx.skb))
1987 if (!invoke_tx_handlers_late(&tx))
1988 result = __ieee80211_tx(local, &tx.skbs, tx.sta, txpending);
1993 /* device xmit handlers */
1995 enum ieee80211_encrypt {
2001 static int ieee80211_skb_resize(struct ieee80211_sub_if_data *sdata,
2002 struct sk_buff *skb,
2004 enum ieee80211_encrypt encrypt)
2006 struct ieee80211_local *local = sdata->local;
2010 enc_tailroom = encrypt == ENCRYPT_MGMT ||
2011 (encrypt == ENCRYPT_DATA &&
2012 sdata->crypto_tx_tailroom_needed_cnt);
2015 tail_need = IEEE80211_ENCRYPT_TAILROOM;
2016 tail_need -= skb_tailroom(skb);
2017 tail_need = max_t(int, tail_need, 0);
2020 if (skb_cloned(skb) &&
2021 (!ieee80211_hw_check(&local->hw, SUPPORTS_CLONED_SKBS) ||
2022 !skb_clone_writable(skb, ETH_HLEN) || enc_tailroom))
2023 I802_DEBUG_INC(local->tx_expand_skb_head_cloned);
2024 else if (head_need || tail_need)
2025 I802_DEBUG_INC(local->tx_expand_skb_head);
2029 if (pskb_expand_head(skb, head_need, tail_need, GFP_ATOMIC)) {
2030 wiphy_debug(local->hw.wiphy,
2031 "failed to reallocate TX buffer\n");
2038 void ieee80211_xmit(struct ieee80211_sub_if_data *sdata,
2039 struct sta_info *sta, struct sk_buff *skb)
2041 struct ieee80211_local *local = sdata->local;
2042 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2043 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2045 enum ieee80211_encrypt encrypt;
2047 if (info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)
2048 encrypt = ENCRYPT_NO;
2049 else if (ieee80211_is_mgmt(hdr->frame_control))
2050 encrypt = ENCRYPT_MGMT;
2052 encrypt = ENCRYPT_DATA;
2054 headroom = local->tx_headroom;
2055 if (encrypt != ENCRYPT_NO)
2056 headroom += IEEE80211_ENCRYPT_HEADROOM;
2057 headroom -= skb_headroom(skb);
2058 headroom = max_t(int, 0, headroom);
2060 if (ieee80211_skb_resize(sdata, skb, headroom, encrypt)) {
2061 ieee80211_free_txskb(&local->hw, skb);
2065 /* reload after potential resize */
2066 hdr = (struct ieee80211_hdr *) skb->data;
2067 info->control.vif = &sdata->vif;
2069 if (ieee80211_vif_is_mesh(&sdata->vif)) {
2070 if (ieee80211_is_data(hdr->frame_control) &&
2071 is_unicast_ether_addr(hdr->addr1)) {
2072 if (mesh_nexthop_resolve(sdata, skb))
2073 return; /* skb queued: don't free */
2075 ieee80211_mps_set_frame_flags(sdata, NULL, hdr);
2079 ieee80211_set_qos_hdr(sdata, skb);
2080 ieee80211_tx(sdata, sta, skb, false);
2083 static bool ieee80211_validate_radiotap_len(struct sk_buff *skb)
2085 struct ieee80211_radiotap_header *rthdr =
2086 (struct ieee80211_radiotap_header *)skb->data;
2088 /* check for not even having the fixed radiotap header part */
2089 if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
2090 return false; /* too short to be possibly valid */
2092 /* is it a header version we can trust to find length from? */
2093 if (unlikely(rthdr->it_version))
2094 return false; /* only version 0 is supported */
2096 /* does the skb contain enough to deliver on the alleged length? */
2097 if (unlikely(skb->len < ieee80211_get_radiotap_len(skb->data)))
2098 return false; /* skb too short for claimed rt header extent */
2103 bool ieee80211_parse_tx_radiotap(struct sk_buff *skb,
2104 struct net_device *dev)
2106 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2107 struct ieee80211_radiotap_iterator iterator;
2108 struct ieee80211_radiotap_header *rthdr =
2109 (struct ieee80211_radiotap_header *) skb->data;
2110 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2111 int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len,
2115 bool rate_found = false;
2116 u8 rate_retries = 0;
2118 u8 mcs_known, mcs_flags, mcs_bw;
2120 u8 vht_mcs = 0, vht_nss = 0;
2123 if (!ieee80211_validate_radiotap_len(skb))
2126 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
2127 IEEE80211_TX_CTL_DONTFRAG;
2130 * for every radiotap entry that is present
2131 * (ieee80211_radiotap_iterator_next returns -ENOENT when no more
2132 * entries present, or -EINVAL on error)
2136 ret = ieee80211_radiotap_iterator_next(&iterator);
2141 /* see if this argument is something we can use */
2142 switch (iterator.this_arg_index) {
2144 * You must take care when dereferencing iterator.this_arg
2145 * for multibyte types... the pointer is not aligned. Use
2146 * get_unaligned((type *)iterator.this_arg) to dereference
2147 * iterator.this_arg for type "type" safely on all arches.
2149 case IEEE80211_RADIOTAP_FLAGS:
2150 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) {
2152 * this indicates that the skb we have been
2153 * handed has the 32-bit FCS CRC at the end...
2154 * we should react to that by snipping it off
2155 * because it will be recomputed and added
2158 if (skb->len < (iterator._max_length + FCS_LEN))
2161 skb_trim(skb, skb->len - FCS_LEN);
2163 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_WEP)
2164 info->flags &= ~IEEE80211_TX_INTFL_DONT_ENCRYPT;
2165 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG)
2166 info->flags &= ~IEEE80211_TX_CTL_DONTFRAG;
2169 case IEEE80211_RADIOTAP_TX_FLAGS:
2170 txflags = get_unaligned_le16(iterator.this_arg);
2171 if (txflags & IEEE80211_RADIOTAP_F_TX_NOACK)
2172 info->flags |= IEEE80211_TX_CTL_NO_ACK;
2173 if (txflags & IEEE80211_RADIOTAP_F_TX_NOSEQNO)
2174 info->control.flags |= IEEE80211_TX_CTRL_NO_SEQNO;
2175 if (txflags & IEEE80211_RADIOTAP_F_TX_ORDER)
2176 info->control.flags |=
2177 IEEE80211_TX_CTRL_DONT_REORDER;
2180 case IEEE80211_RADIOTAP_RATE:
2181 rate = *iterator.this_arg;
2186 case IEEE80211_RADIOTAP_DATA_RETRIES:
2187 rate_retries = *iterator.this_arg;
2190 case IEEE80211_RADIOTAP_MCS:
2191 mcs_known = iterator.this_arg[0];
2192 mcs_flags = iterator.this_arg[1];
2193 if (!(mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_MCS))
2197 rate = iterator.this_arg[2];
2198 rate_flags = IEEE80211_TX_RC_MCS;
2200 if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_GI &&
2201 mcs_flags & IEEE80211_RADIOTAP_MCS_SGI)
2202 rate_flags |= IEEE80211_TX_RC_SHORT_GI;
2204 mcs_bw = mcs_flags & IEEE80211_RADIOTAP_MCS_BW_MASK;
2205 if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_BW &&
2206 mcs_bw == IEEE80211_RADIOTAP_MCS_BW_40)
2207 rate_flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
2209 if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_FEC &&
2210 mcs_flags & IEEE80211_RADIOTAP_MCS_FEC_LDPC)
2211 info->flags |= IEEE80211_TX_CTL_LDPC;
2213 if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_STBC) {
2214 u8 stbc = u8_get_bits(mcs_flags,
2215 IEEE80211_RADIOTAP_MCS_STBC_MASK);
2218 u32_encode_bits(stbc,
2219 IEEE80211_TX_CTL_STBC);
2223 case IEEE80211_RADIOTAP_VHT:
2224 vht_known = get_unaligned_le16(iterator.this_arg);
2227 rate_flags = IEEE80211_TX_RC_VHT_MCS;
2228 if ((vht_known & IEEE80211_RADIOTAP_VHT_KNOWN_GI) &&
2229 (iterator.this_arg[2] &
2230 IEEE80211_RADIOTAP_VHT_FLAG_SGI))
2231 rate_flags |= IEEE80211_TX_RC_SHORT_GI;
2233 IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH) {
2234 if (iterator.this_arg[3] == 1)
2236 IEEE80211_TX_RC_40_MHZ_WIDTH;
2237 else if (iterator.this_arg[3] == 4)
2239 IEEE80211_TX_RC_80_MHZ_WIDTH;
2240 else if (iterator.this_arg[3] == 11)
2242 IEEE80211_TX_RC_160_MHZ_WIDTH;
2245 vht_mcs = iterator.this_arg[4] >> 4;
2248 vht_nss = iterator.this_arg[4] & 0xF;
2249 if (!vht_nss || vht_nss > 8)
2254 * Please update the file
2255 * Documentation/networking/mac80211-injection.rst
2256 * when parsing new fields here.
2264 if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */
2268 struct ieee80211_supported_band *sband =
2269 local->hw.wiphy->bands[info->band];
2271 info->control.flags |= IEEE80211_TX_CTRL_RATE_INJECT;
2273 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
2274 info->control.rates[i].idx = -1;
2275 info->control.rates[i].flags = 0;
2276 info->control.rates[i].count = 0;
2279 if (rate_flags & IEEE80211_TX_RC_MCS) {
2280 info->control.rates[0].idx = rate;
2281 } else if (rate_flags & IEEE80211_TX_RC_VHT_MCS) {
2282 ieee80211_rate_set_vht(info->control.rates, vht_mcs,
2285 for (i = 0; i < sband->n_bitrates; i++) {
2286 if (rate * 5 != sband->bitrates[i].bitrate)
2289 info->control.rates[0].idx = i;
2294 if (info->control.rates[0].idx < 0)
2295 info->control.flags &= ~IEEE80211_TX_CTRL_RATE_INJECT;
2297 info->control.rates[0].flags = rate_flags;
2298 info->control.rates[0].count = min_t(u8, rate_retries + 1,
2299 local->hw.max_rate_tries);
2305 netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
2306 struct net_device *dev)
2308 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2309 struct ieee80211_chanctx_conf *chanctx_conf;
2310 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2311 struct ieee80211_hdr *hdr;
2312 struct ieee80211_sub_if_data *tmp_sdata, *sdata;
2313 struct cfg80211_chan_def *chandef;
2317 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2318 if (unlikely(!ieee80211_sdata_running(sdata)))
2321 memset(info, 0, sizeof(*info));
2322 info->flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2323 IEEE80211_TX_CTL_INJECTED;
2325 /* Sanity-check the length of the radiotap header */
2326 if (!ieee80211_validate_radiotap_len(skb))
2329 /* we now know there is a radiotap header with a length we can use */
2330 len_rthdr = ieee80211_get_radiotap_len(skb->data);
2333 * fix up the pointers accounting for the radiotap
2334 * header still being in there. We are being given
2335 * a precooked IEEE80211 header so no need for
2338 skb_set_mac_header(skb, len_rthdr);
2340 * these are just fixed to the end of the rt area since we
2341 * don't have any better information and at this point, nobody cares
2343 skb_set_network_header(skb, len_rthdr);
2344 skb_set_transport_header(skb, len_rthdr);
2346 if (skb->len < len_rthdr + 2)
2349 hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
2350 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2352 if (skb->len < len_rthdr + hdrlen)
2356 * Initialize skb->protocol if the injected frame is a data frame
2357 * carrying a rfc1042 header
2359 if (ieee80211_is_data(hdr->frame_control) &&
2360 skb->len >= len_rthdr + hdrlen + sizeof(rfc1042_header) + 2) {
2361 u8 *payload = (u8 *)hdr + hdrlen;
2363 if (ether_addr_equal(payload, rfc1042_header))
2364 skb->protocol = cpu_to_be16((payload[6] << 8) |
2371 * We process outgoing injected frames that have a local address
2372 * we handle as though they are non-injected frames.
2373 * This code here isn't entirely correct, the local MAC address
2374 * isn't always enough to find the interface to use; for proper
2375 * VLAN support we have an nl80211-based mechanism.
2377 * This is necessary, for example, for old hostapd versions that
2378 * don't use nl80211-based management TX/RX.
2380 list_for_each_entry_rcu(tmp_sdata, &local->interfaces, list) {
2381 if (!ieee80211_sdata_running(tmp_sdata))
2383 if (tmp_sdata->vif.type == NL80211_IFTYPE_MONITOR ||
2384 tmp_sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
2386 if (ether_addr_equal(tmp_sdata->vif.addr, hdr->addr2)) {
2392 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
2393 if (!chanctx_conf) {
2394 tmp_sdata = rcu_dereference(local->monitor_sdata);
2397 rcu_dereference(tmp_sdata->vif.bss_conf.chanctx_conf);
2401 chandef = &chanctx_conf->def;
2402 else if (!local->use_chanctx)
2403 chandef = &local->_oper_chandef;
2408 * Frame injection is not allowed if beaconing is not allowed
2409 * or if we need radar detection. Beaconing is usually not allowed when
2410 * the mode or operation (Adhoc, AP, Mesh) does not support DFS.
2411 * Passive scan is also used in world regulatory domains where
2412 * your country is not known and as such it should be treated as
2413 * NO TX unless the channel is explicitly allowed in which case
2414 * your current regulatory domain would not have the passive scan
2417 * Since AP mode uses monitor interfaces to inject/TX management
2418 * frames we can make AP mode the exception to this rule once it
2419 * supports radar detection as its implementation can deal with
2420 * radar detection by itself. We can do that later by adding a
2421 * monitor flag interfaces used for AP support.
2423 if (!cfg80211_reg_can_beacon(local->hw.wiphy, chandef,
2427 info->band = chandef->chan->band;
2429 /* Initialize skb->priority according to frame type and TID class,
2430 * with respect to the sub interface that the frame will actually
2431 * be transmitted on. If the DONT_REORDER flag is set, the original
2432 * skb-priority is preserved to assure frames injected with this
2433 * flag are not reordered relative to each other.
2435 ieee80211_select_queue_80211(sdata, skb, hdr);
2436 skb_set_queue_mapping(skb, ieee80211_ac_from_tid(skb->priority));
2439 * Process the radiotap header. This will now take into account the
2440 * selected chandef above to accurately set injection rates and
2443 if (!ieee80211_parse_tx_radiotap(skb, dev))
2446 /* remove the injection radiotap header */
2447 skb_pull(skb, len_rthdr);
2449 ieee80211_xmit(sdata, NULL, skb);
2452 return NETDEV_TX_OK;
2458 return NETDEV_TX_OK; /* meaning, we dealt with the skb */
2461 static inline bool ieee80211_is_tdls_setup(struct sk_buff *skb)
2463 u16 ethertype = (skb->data[12] << 8) | skb->data[13];
2465 return ethertype == ETH_P_TDLS &&
2467 skb->data[14] == WLAN_TDLS_SNAP_RFTYPE;
2470 int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata,
2471 struct sk_buff *skb,
2472 struct sta_info **sta_out)
2474 struct sta_info *sta;
2476 switch (sdata->vif.type) {
2477 case NL80211_IFTYPE_AP_VLAN:
2478 sta = rcu_dereference(sdata->u.vlan.sta);
2482 } else if (sdata->wdev.use_4addr) {
2486 case NL80211_IFTYPE_AP:
2487 case NL80211_IFTYPE_OCB:
2488 case NL80211_IFTYPE_ADHOC:
2489 if (is_multicast_ether_addr(skb->data)) {
2490 *sta_out = ERR_PTR(-ENOENT);
2493 sta = sta_info_get_bss(sdata, skb->data);
2495 #ifdef CONFIG_MAC80211_MESH
2496 case NL80211_IFTYPE_MESH_POINT:
2497 /* determined much later */
2501 case NL80211_IFTYPE_STATION:
2502 if (sdata->wdev.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) {
2503 sta = sta_info_get(sdata, skb->data);
2504 if (sta && test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
2505 if (test_sta_flag(sta,
2506 WLAN_STA_TDLS_PEER_AUTH)) {
2512 * TDLS link during setup - throw out frames to
2513 * peer. Allow TDLS-setup frames to unauthorized
2514 * peers for the special case of a link teardown
2515 * after a TDLS sta is removed due to being
2518 if (!ieee80211_is_tdls_setup(skb))
2524 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
2532 *sta_out = sta ?: ERR_PTR(-ENOENT);
2536 static u16 ieee80211_store_ack_skb(struct ieee80211_local *local,
2537 struct sk_buff *skb,
2541 struct sk_buff *ack_skb;
2545 ack_skb = skb_clone_sk(skb);
2547 ack_skb = skb_clone(skb, GFP_ATOMIC);
2550 unsigned long flags;
2553 spin_lock_irqsave(&local->ack_status_lock, flags);
2554 id = idr_alloc(&local->ack_status_frames, ack_skb,
2555 1, 0x2000, GFP_ATOMIC);
2556 spin_unlock_irqrestore(&local->ack_status_lock, flags);
2560 *info_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
2562 *cookie = ieee80211_mgmt_tx_cookie(local);
2563 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
2574 * ieee80211_build_hdr - build 802.11 header in the given frame
2575 * @sdata: virtual interface to build the header for
2576 * @skb: the skb to build the header in
2577 * @info_flags: skb flags to set
2578 * @sta: the station pointer
2579 * @ctrl_flags: info control flags to set
2580 * @cookie: cookie pointer to fill (if not %NULL)
2582 * This function takes the skb with 802.3 header and reformats the header to
2583 * the appropriate IEEE 802.11 header based on which interface the packet is
2584 * being transmitted on.
2586 * Note that this function also takes care of the TX status request and
2587 * potential unsharing of the SKB - this needs to be interleaved with the
2590 * The function requires the read-side RCU lock held
2592 * Returns: the (possibly reallocated) skb or an ERR_PTR() code
2594 static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata,
2595 struct sk_buff *skb, u32 info_flags,
2596 struct sta_info *sta, u32 ctrl_flags,
2599 struct ieee80211_local *local = sdata->local;
2600 struct ieee80211_tx_info *info;
2602 u16 ethertype, hdrlen, meshhdrlen = 0;
2604 struct ieee80211_hdr hdr;
2605 struct ieee80211s_hdr mesh_hdr __maybe_unused;
2606 struct mesh_path __maybe_unused *mppath = NULL, *mpath = NULL;
2607 const u8 *encaps_data;
2608 int encaps_len, skip_header_bytes;
2609 bool wme_sta = false, authorized = false;
2613 struct ieee80211_chanctx_conf *chanctx_conf = NULL;
2614 enum nl80211_band band;
2616 u8 link_id = u32_get_bits(ctrl_flags, IEEE80211_TX_CTRL_MLO_LINK);
2621 #ifdef CONFIG_MAC80211_DEBUGFS
2622 if (local->force_tx_status)
2623 info_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
2626 /* convert Ethernet header to proper 802.11 header (based on
2627 * operation mode) */
2628 ethertype = (skb->data[12] << 8) | skb->data[13];
2629 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
2631 if (!sdata->vif.valid_links)
2633 rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
2635 switch (sdata->vif.type) {
2636 case NL80211_IFTYPE_AP_VLAN:
2637 if (sdata->wdev.use_4addr) {
2638 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
2640 memcpy(hdr.addr1, sta->sta.addr, ETH_ALEN);
2641 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
2642 memcpy(hdr.addr3, skb->data, ETH_ALEN);
2643 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
2645 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
2646 wme_sta = sta->sta.wme;
2648 if (!sdata->vif.valid_links) {
2649 struct ieee80211_sub_if_data *ap_sdata;
2651 /* override chanctx_conf from AP (we don't have one) */
2652 ap_sdata = container_of(sdata->bss,
2653 struct ieee80211_sub_if_data,
2656 rcu_dereference(ap_sdata->vif.bss_conf.chanctx_conf);
2658 if (sdata->wdev.use_4addr)
2661 case NL80211_IFTYPE_AP:
2662 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
2664 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2666 if (sdata->vif.valid_links && sta && !sta->sta.mlo) {
2667 struct ieee80211_link_data *link;
2669 link_id = sta->deflink.link_id;
2670 link = rcu_dereference(sdata->link[link_id]);
2671 if (WARN_ON(!link)) {
2675 memcpy(hdr.addr2, link->conf->addr, ETH_ALEN);
2676 } else if (link_id == IEEE80211_LINK_UNSPECIFIED ||
2677 (sta && sta->sta.mlo)) {
2678 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
2680 struct ieee80211_bss_conf *conf;
2682 conf = rcu_dereference(sdata->vif.link_conf[link_id]);
2683 if (unlikely(!conf)) {
2688 memcpy(hdr.addr2, conf->addr, ETH_ALEN);
2691 memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
2694 #ifdef CONFIG_MAC80211_MESH
2695 case NL80211_IFTYPE_MESH_POINT:
2696 if (!is_multicast_ether_addr(skb->data)) {
2697 struct sta_info *next_hop;
2698 bool mpp_lookup = true;
2700 mpath = mesh_path_lookup(sdata, skb->data);
2703 next_hop = rcu_dereference(mpath->next_hop);
2705 !(mpath->flags & (MESH_PATH_ACTIVE |
2706 MESH_PATH_RESOLVING)))
2711 mppath = mpp_path_lookup(sdata, skb->data);
2713 mppath->exp_time = jiffies;
2716 if (mppath && mpath)
2717 mesh_path_del(sdata, mpath->dst);
2721 * Use address extension if it is a packet from
2722 * another interface or if we know the destination
2723 * is being proxied by a portal (i.e. portal address
2724 * differs from proxied address)
2726 if (ether_addr_equal(sdata->vif.addr, skb->data + ETH_ALEN) &&
2727 !(mppath && !ether_addr_equal(mppath->mpp, skb->data))) {
2728 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
2729 skb->data, skb->data + ETH_ALEN);
2730 meshhdrlen = ieee80211_new_mesh_header(sdata, &mesh_hdr,
2733 /* DS -> MBSS (802.11-2012 13.11.3.3).
2734 * For unicast with unknown forwarding information,
2735 * destination might be in the MBSS or if that fails
2736 * forwarded to another mesh gate. In either case
2737 * resolution will be handled in ieee80211_xmit(), so
2738 * leave the original DA. This also works for mcast */
2739 const u8 *mesh_da = skb->data;
2742 mesh_da = mppath->mpp;
2744 mesh_da = mpath->dst;
2746 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
2747 mesh_da, sdata->vif.addr);
2748 if (is_multicast_ether_addr(mesh_da))
2749 /* DA TA mSA AE:SA */
2750 meshhdrlen = ieee80211_new_mesh_header(
2752 skb->data + ETH_ALEN, NULL);
2754 /* RA TA mDA mSA AE:DA SA */
2755 meshhdrlen = ieee80211_new_mesh_header(
2756 sdata, &mesh_hdr, skb->data,
2757 skb->data + ETH_ALEN);
2761 /* For injected frames, fill RA right away as nexthop lookup
2764 if ((ctrl_flags & IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP) &&
2765 is_zero_ether_addr(hdr.addr1))
2766 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2769 case NL80211_IFTYPE_STATION:
2770 /* we already did checks when looking up the RA STA */
2771 tdls_peer = test_sta_flag(sta, WLAN_STA_TDLS_PEER);
2775 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2776 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2777 memcpy(hdr.addr3, sdata->deflink.u.mgd.bssid, ETH_ALEN);
2779 } else if (sdata->u.mgd.use_4addr &&
2780 cpu_to_be16(ethertype) != sdata->control_port_protocol) {
2781 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
2782 IEEE80211_FCTL_TODS);
2784 memcpy(hdr.addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN);
2785 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
2786 memcpy(hdr.addr3, skb->data, ETH_ALEN);
2787 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
2790 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
2792 memcpy(hdr.addr1, sdata->vif.cfg.ap_addr, ETH_ALEN);
2793 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2794 memcpy(hdr.addr3, skb->data, ETH_ALEN);
2798 case NL80211_IFTYPE_OCB:
2800 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2801 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2802 eth_broadcast_addr(hdr.addr3);
2805 case NL80211_IFTYPE_ADHOC:
2807 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2808 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2809 memcpy(hdr.addr3, sdata->u.ibss.bssid, ETH_ALEN);
2817 if (!chanctx_conf) {
2818 if (!sdata->vif.valid_links) {
2822 /* MLD transmissions must not rely on the band */
2825 band = chanctx_conf->def.chan->band;
2828 multicast = is_multicast_ether_addr(hdr.addr1);
2830 /* sta is always NULL for mesh */
2832 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
2833 wme_sta = sta->sta.wme;
2834 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
2835 /* For mesh, the use of the QoS header is mandatory */
2839 /* receiver does QoS (which also means we do) use it */
2841 fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
2846 * Drop unicast frames to unauthorised stations unless they are
2847 * EAPOL frames from the local station.
2849 if (unlikely(!ieee80211_vif_is_mesh(&sdata->vif) &&
2850 (sdata->vif.type != NL80211_IFTYPE_OCB) &&
2851 !multicast && !authorized &&
2852 (cpu_to_be16(ethertype) != sdata->control_port_protocol ||
2853 !ieee80211_is_our_addr(sdata, skb->data + ETH_ALEN, NULL)))) {
2854 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2855 net_info_ratelimited("%s: dropped frame to %pM (unauthorized port)\n",
2856 sdata->name, hdr.addr1);
2859 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
2865 if (unlikely(!multicast && ((skb->sk &&
2866 skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS) ||
2867 ctrl_flags & IEEE80211_TX_CTL_REQ_TX_STATUS)))
2868 info_id = ieee80211_store_ack_skb(local, skb, &info_flags,
2872 * If the skb is shared we need to obtain our own copy.
2874 skb = skb_share_check(skb, GFP_ATOMIC);
2875 if (unlikely(!skb)) {
2880 hdr.frame_control = fc;
2881 hdr.duration_id = 0;
2884 skip_header_bytes = ETH_HLEN;
2885 if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
2886 encaps_data = bridge_tunnel_header;
2887 encaps_len = sizeof(bridge_tunnel_header);
2888 skip_header_bytes -= 2;
2889 } else if (ethertype >= ETH_P_802_3_MIN) {
2890 encaps_data = rfc1042_header;
2891 encaps_len = sizeof(rfc1042_header);
2892 skip_header_bytes -= 2;
2898 skb_pull(skb, skip_header_bytes);
2899 head_need = hdrlen + encaps_len + meshhdrlen - skb_headroom(skb);
2902 * So we need to modify the skb header and hence need a copy of
2903 * that. The head_need variable above doesn't, so far, include
2904 * the needed header space that we don't need right away. If we
2905 * can, then we don't reallocate right now but only after the
2906 * frame arrives at the master device (if it does...)
2908 * If we cannot, however, then we will reallocate to include all
2909 * the ever needed space. Also, if we need to reallocate it anyway,
2910 * make it big enough for everything we may ever need.
2913 if (head_need > 0 || skb_cloned(skb)) {
2914 head_need += IEEE80211_ENCRYPT_HEADROOM;
2915 head_need += local->tx_headroom;
2916 head_need = max_t(int, 0, head_need);
2917 if (ieee80211_skb_resize(sdata, skb, head_need, ENCRYPT_DATA)) {
2918 ieee80211_free_txskb(&local->hw, skb);
2920 return ERR_PTR(-ENOMEM);
2925 memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
2927 #ifdef CONFIG_MAC80211_MESH
2929 memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen);
2932 if (ieee80211_is_data_qos(fc)) {
2933 __le16 *qos_control;
2935 qos_control = skb_push(skb, 2);
2936 memcpy(skb_push(skb, hdrlen - 2), &hdr, hdrlen - 2);
2938 * Maybe we could actually set some fields here, for now just
2939 * initialise to zero to indicate no special operation.
2943 memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
2945 skb_reset_mac_header(skb);
2947 info = IEEE80211_SKB_CB(skb);
2948 memset(info, 0, sizeof(*info));
2950 info->flags = info_flags;
2951 info->ack_frame_id = info_id;
2954 if (likely(!cookie)) {
2955 ctrl_flags |= u32_encode_bits(link_id,
2956 IEEE80211_TX_CTRL_MLO_LINK);
2958 unsigned int pre_conf_link_id;
2961 * ctrl_flags already have been set by
2962 * ieee80211_tx_control_port(), here
2963 * we just sanity check that
2966 pre_conf_link_id = u32_get_bits(ctrl_flags,
2967 IEEE80211_TX_CTRL_MLO_LINK);
2969 if (pre_conf_link_id != link_id &&
2970 link_id != IEEE80211_LINK_UNSPECIFIED) {
2971 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2972 net_info_ratelimited("%s: dropped frame to %pM with bad link ID request (%d vs. %d)\n",
2973 sdata->name, hdr.addr1,
2974 pre_conf_link_id, link_id);
2981 info->control.flags = ctrl_flags;
2986 return ERR_PTR(ret);
2990 * fast-xmit overview
2992 * The core idea of this fast-xmit is to remove per-packet checks by checking
2993 * them out of band. ieee80211_check_fast_xmit() implements the out-of-band
2994 * checks that are needed to get the sta->fast_tx pointer assigned, after which
2995 * much less work can be done per packet. For example, fragmentation must be
2996 * disabled or the fast_tx pointer will not be set. All the conditions are seen
2999 * Once assigned, the fast_tx data structure also caches the per-packet 802.11
3000 * header and other data to aid packet processing in ieee80211_xmit_fast().
3002 * The most difficult part of this is that when any of these assumptions
3003 * change, an external trigger (i.e. a call to ieee80211_clear_fast_xmit(),
3004 * ieee80211_check_fast_xmit() or friends) is required to reset the data,
3005 * since the per-packet code no longer checks the conditions. This is reflected
3006 * by the calls to these functions throughout the rest of the code, and must be
3007 * maintained if any of the TX path checks change.
3010 void ieee80211_check_fast_xmit(struct sta_info *sta)
3012 struct ieee80211_fast_tx build = {}, *fast_tx = NULL, *old;
3013 struct ieee80211_local *local = sta->local;
3014 struct ieee80211_sub_if_data *sdata = sta->sdata;
3015 struct ieee80211_hdr *hdr = (void *)build.hdr;
3016 struct ieee80211_chanctx_conf *chanctx_conf;
3019 if (!ieee80211_hw_check(&local->hw, SUPPORT_FAST_XMIT))
3022 /* Locking here protects both the pointer itself, and against concurrent
3023 * invocations winning data access races to, e.g., the key pointer that
3025 * Without it, the invocation of this function right after the key
3026 * pointer changes wouldn't be sufficient, as another CPU could access
3027 * the pointer, then stall, and then do the cache update after the CPU
3028 * that invalidated the key.
3029 * With the locking, such scenarios cannot happen as the check for the
3030 * key and the fast-tx assignment are done atomically, so the CPU that
3031 * modifies the key will either wait or other one will see the key
3032 * cleared/changed already.
3034 spin_lock_bh(&sta->lock);
3035 if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
3036 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
3037 sdata->vif.type == NL80211_IFTYPE_STATION)
3040 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
3043 if (test_sta_flag(sta, WLAN_STA_PS_STA) ||
3044 test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
3045 test_sta_flag(sta, WLAN_STA_PS_DELIVER) ||
3046 test_sta_flag(sta, WLAN_STA_CLEAR_PS_FILT))
3049 if (sdata->noack_map)
3052 /* fast-xmit doesn't handle fragmentation at all */
3053 if (local->hw.wiphy->frag_threshold != (u32)-1 &&
3054 !ieee80211_hw_check(&local->hw, SUPPORTS_TX_FRAG))
3057 if (!sdata->vif.valid_links) {
3060 rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
3061 if (!chanctx_conf) {
3065 build.band = chanctx_conf->def.chan->band;
3068 /* MLD transmissions must not rely on the band */
3072 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
3074 switch (sdata->vif.type) {
3075 case NL80211_IFTYPE_ADHOC:
3077 build.da_offs = offsetof(struct ieee80211_hdr, addr1);
3078 build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3079 memcpy(hdr->addr3, sdata->u.ibss.bssid, ETH_ALEN);
3082 case NL80211_IFTYPE_STATION:
3083 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
3085 build.da_offs = offsetof(struct ieee80211_hdr, addr1);
3086 build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3087 memcpy(hdr->addr3, sdata->deflink.u.mgd.bssid, ETH_ALEN);
3092 if (sdata->u.mgd.use_4addr) {
3093 /* non-regular ethertype cannot use the fastpath */
3094 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
3095 IEEE80211_FCTL_TODS);
3097 memcpy(hdr->addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN);
3098 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
3099 build.da_offs = offsetof(struct ieee80211_hdr, addr3);
3100 build.sa_offs = offsetof(struct ieee80211_hdr, addr4);
3104 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
3106 memcpy(hdr->addr1, sdata->vif.cfg.ap_addr, ETH_ALEN);
3107 build.da_offs = offsetof(struct ieee80211_hdr, addr3);
3108 build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3111 case NL80211_IFTYPE_AP_VLAN:
3112 if (sdata->wdev.use_4addr) {
3113 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
3114 IEEE80211_FCTL_TODS);
3116 memcpy(hdr->addr1, sta->sta.addr, ETH_ALEN);
3117 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
3118 build.da_offs = offsetof(struct ieee80211_hdr, addr3);
3119 build.sa_offs = offsetof(struct ieee80211_hdr, addr4);
3124 case NL80211_IFTYPE_AP:
3125 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
3127 build.da_offs = offsetof(struct ieee80211_hdr, addr1);
3128 if (sta->sta.mlo || !sdata->vif.valid_links) {
3129 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
3131 unsigned int link_id = sta->deflink.link_id;
3132 struct ieee80211_link_data *link;
3135 link = rcu_dereference(sdata->link[link_id]);
3136 if (WARN_ON(!link)) {
3140 memcpy(hdr->addr2, link->conf->addr, ETH_ALEN);
3143 build.sa_offs = offsetof(struct ieee80211_hdr, addr3);
3147 /* not handled on fast-xmit */
3153 fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3156 /* We store the key here so there's no point in using rcu_dereference()
3157 * but that's fine because the code that changes the pointers will call
3158 * this function after doing so. For a single CPU that would be enough,
3159 * for multiple see the comment above.
3161 build.key = rcu_access_pointer(sta->ptk[sta->ptk_idx]);
3163 build.key = rcu_access_pointer(sdata->default_unicast_key);
3165 bool gen_iv, iv_spc, mmic;
3167 gen_iv = build.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV;
3168 iv_spc = build.key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3169 mmic = build.key->conf.flags &
3170 (IEEE80211_KEY_FLAG_GENERATE_MMIC |
3171 IEEE80211_KEY_FLAG_PUT_MIC_SPACE);
3173 /* don't handle software crypto */
3174 if (!(build.key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
3177 /* Key is being removed */
3178 if (build.key->flags & KEY_FLAG_TAINTED)
3181 switch (build.key->conf.cipher) {
3182 case WLAN_CIPHER_SUITE_CCMP:
3183 case WLAN_CIPHER_SUITE_CCMP_256:
3185 build.pn_offs = build.hdr_len;
3186 if (gen_iv || iv_spc)
3187 build.hdr_len += IEEE80211_CCMP_HDR_LEN;
3189 case WLAN_CIPHER_SUITE_GCMP:
3190 case WLAN_CIPHER_SUITE_GCMP_256:
3192 build.pn_offs = build.hdr_len;
3193 if (gen_iv || iv_spc)
3194 build.hdr_len += IEEE80211_GCMP_HDR_LEN;
3196 case WLAN_CIPHER_SUITE_TKIP:
3197 /* cannot handle MMIC or IV generation in xmit-fast */
3201 build.hdr_len += IEEE80211_TKIP_IV_LEN;
3203 case WLAN_CIPHER_SUITE_WEP40:
3204 case WLAN_CIPHER_SUITE_WEP104:
3205 /* cannot handle IV generation in fast-xmit */
3209 build.hdr_len += IEEE80211_WEP_IV_LEN;
3211 case WLAN_CIPHER_SUITE_AES_CMAC:
3212 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
3213 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3214 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3216 "management cipher suite 0x%x enabled for data\n",
3217 build.key->conf.cipher);
3220 /* we don't know how to generate IVs for this at all */
3221 if (WARN_ON(gen_iv))
3225 fc |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
3228 hdr->frame_control = fc;
3230 memcpy(build.hdr + build.hdr_len,
3231 rfc1042_header, sizeof(rfc1042_header));
3232 build.hdr_len += sizeof(rfc1042_header);
3234 fast_tx = kmemdup(&build, sizeof(build), GFP_ATOMIC);
3235 /* if the kmemdup fails, continue w/o fast_tx */
3238 /* we might have raced against another call to this function */
3239 old = rcu_dereference_protected(sta->fast_tx,
3240 lockdep_is_held(&sta->lock));
3241 rcu_assign_pointer(sta->fast_tx, fast_tx);
3243 kfree_rcu(old, rcu_head);
3244 spin_unlock_bh(&sta->lock);
3247 void ieee80211_check_fast_xmit_all(struct ieee80211_local *local)
3249 struct sta_info *sta;
3252 list_for_each_entry_rcu(sta, &local->sta_list, list)
3253 ieee80211_check_fast_xmit(sta);
3257 void ieee80211_check_fast_xmit_iface(struct ieee80211_sub_if_data *sdata)
3259 struct ieee80211_local *local = sdata->local;
3260 struct sta_info *sta;
3264 list_for_each_entry_rcu(sta, &local->sta_list, list) {
3265 if (sdata != sta->sdata &&
3266 (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
3268 ieee80211_check_fast_xmit(sta);
3274 void ieee80211_clear_fast_xmit(struct sta_info *sta)
3276 struct ieee80211_fast_tx *fast_tx;
3278 spin_lock_bh(&sta->lock);
3279 fast_tx = rcu_dereference_protected(sta->fast_tx,
3280 lockdep_is_held(&sta->lock));
3281 RCU_INIT_POINTER(sta->fast_tx, NULL);
3282 spin_unlock_bh(&sta->lock);
3285 kfree_rcu(fast_tx, rcu_head);
3288 static bool ieee80211_amsdu_realloc_pad(struct ieee80211_local *local,
3289 struct sk_buff *skb, int headroom)
3291 if (skb_headroom(skb) < headroom) {
3292 I802_DEBUG_INC(local->tx_expand_skb_head);
3294 if (pskb_expand_head(skb, headroom, 0, GFP_ATOMIC)) {
3295 wiphy_debug(local->hw.wiphy,
3296 "failed to reallocate TX buffer\n");
3304 static bool ieee80211_amsdu_prepare_head(struct ieee80211_sub_if_data *sdata,
3305 struct ieee80211_fast_tx *fast_tx,
3306 struct sk_buff *skb)
3308 struct ieee80211_local *local = sdata->local;
3309 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3310 struct ieee80211_hdr *hdr;
3311 struct ethhdr *amsdu_hdr;
3312 int hdr_len = fast_tx->hdr_len - sizeof(rfc1042_header);
3313 int subframe_len = skb->len - hdr_len;
3315 u8 *qc, *h_80211_src, *h_80211_dst;
3318 if (info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE)
3321 if (info->control.flags & IEEE80211_TX_CTRL_AMSDU)
3324 if (!ieee80211_amsdu_realloc_pad(local, skb,
3325 sizeof(*amsdu_hdr) +
3326 local->hw.extra_tx_headroom))
3329 data = skb_push(skb, sizeof(*amsdu_hdr));
3330 memmove(data, data + sizeof(*amsdu_hdr), hdr_len);
3332 amsdu_hdr = data + hdr_len;
3333 /* h_80211_src/dst is addr* field within hdr */
3334 h_80211_src = data + fast_tx->sa_offs;
3335 h_80211_dst = data + fast_tx->da_offs;
3337 amsdu_hdr->h_proto = cpu_to_be16(subframe_len);
3338 ether_addr_copy(amsdu_hdr->h_source, h_80211_src);
3339 ether_addr_copy(amsdu_hdr->h_dest, h_80211_dst);
3341 /* according to IEEE 802.11-2012 8.3.2 table 8-19, the outer SA/DA
3342 * fields needs to be changed to BSSID for A-MSDU frames depending
3343 * on FromDS/ToDS values.
3345 switch (sdata->vif.type) {
3346 case NL80211_IFTYPE_STATION:
3347 bssid = sdata->vif.cfg.ap_addr;
3349 case NL80211_IFTYPE_AP:
3350 case NL80211_IFTYPE_AP_VLAN:
3351 bssid = sdata->vif.addr;
3357 if (bssid && ieee80211_has_fromds(hdr->frame_control))
3358 ether_addr_copy(h_80211_src, bssid);
3360 if (bssid && ieee80211_has_tods(hdr->frame_control))
3361 ether_addr_copy(h_80211_dst, bssid);
3363 qc = ieee80211_get_qos_ctl(hdr);
3364 *qc |= IEEE80211_QOS_CTL_A_MSDU_PRESENT;
3366 info->control.flags |= IEEE80211_TX_CTRL_AMSDU;
3371 static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,
3372 struct sta_info *sta,
3373 struct ieee80211_fast_tx *fast_tx,
3374 struct sk_buff *skb)
3376 struct ieee80211_local *local = sdata->local;
3377 struct fq *fq = &local->fq;
3379 struct fq_flow *flow;
3380 u8 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
3381 struct ieee80211_txq *txq = sta->sta.txq[tid];
3382 struct txq_info *txqi;
3383 struct sk_buff **frag_tail, *head;
3384 int subframe_len = skb->len - ETH_ALEN;
3385 u8 max_subframes = sta->sta.max_amsdu_subframes;
3386 int max_frags = local->hw.max_tx_fragments;
3387 int max_amsdu_len = sta->sta.cur->max_amsdu_len;
3393 unsigned int orig_len;
3394 int n = 2, nfrags, pad = 0;
3397 if (!ieee80211_hw_check(&local->hw, TX_AMSDU))
3400 if (sdata->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED)
3403 if (skb_is_gso(skb))
3409 txqi = to_txq_info(txq);
3410 if (test_bit(IEEE80211_TXQ_NO_AMSDU, &txqi->flags))
3413 if (sta->sta.cur->max_rc_amsdu_len)
3414 max_amsdu_len = min_t(int, max_amsdu_len,
3415 sta->sta.cur->max_rc_amsdu_len);
3417 if (sta->sta.cur->max_tid_amsdu_len[tid])
3418 max_amsdu_len = min_t(int, max_amsdu_len,
3419 sta->sta.cur->max_tid_amsdu_len[tid]);
3421 flow_idx = fq_flow_idx(fq, skb);
3423 spin_lock_bh(&fq->lock);
3425 /* TODO: Ideally aggregation should be done on dequeue to remain
3426 * responsive to environment changes.
3430 flow = fq_flow_classify(fq, tin, flow_idx, skb);
3431 head = skb_peek_tail(&flow->queue);
3432 if (!head || skb_is_gso(head))
3435 orig_truesize = head->truesize;
3436 orig_len = head->len;
3438 if (skb->len + head->len > max_amsdu_len)
3441 nfrags = 1 + skb_shinfo(skb)->nr_frags;
3442 nfrags += 1 + skb_shinfo(head)->nr_frags;
3443 frag_tail = &skb_shinfo(head)->frag_list;
3444 while (*frag_tail) {
3445 nfrags += 1 + skb_shinfo(*frag_tail)->nr_frags;
3446 frag_tail = &(*frag_tail)->next;
3450 if (max_subframes && n > max_subframes)
3453 if (max_frags && nfrags > max_frags)
3456 if (!drv_can_aggregate_in_amsdu(local, head, skb))
3459 if (!ieee80211_amsdu_prepare_head(sdata, fast_tx, head))
3462 /* If n == 2, the "while (*frag_tail)" loop above didn't execute
3463 * and frag_tail should be &skb_shinfo(head)->frag_list.
3464 * However, ieee80211_amsdu_prepare_head() can reallocate it.
3465 * Reload frag_tail to have it pointing to the correct place.
3468 frag_tail = &skb_shinfo(head)->frag_list;
3471 * Pad out the previous subframe to a multiple of 4 by adding the
3472 * padding to the next one, that's being added. Note that head->len
3473 * is the length of the full A-MSDU, but that works since each time
3474 * we add a new subframe we pad out the previous one to a multiple
3475 * of 4 and thus it no longer matters in the next round.
3477 hdrlen = fast_tx->hdr_len - sizeof(rfc1042_header);
3478 if ((head->len - hdrlen) & 3)
3479 pad = 4 - ((head->len - hdrlen) & 3);
3481 if (!ieee80211_amsdu_realloc_pad(local, skb, sizeof(rfc1042_header) +
3486 data = skb_push(skb, ETH_ALEN + 2);
3487 memmove(data, data + ETH_ALEN + 2, 2 * ETH_ALEN);
3489 data += 2 * ETH_ALEN;
3490 len = cpu_to_be16(subframe_len);
3491 memcpy(data, &len, 2);
3492 memcpy(data + 2, rfc1042_header, sizeof(rfc1042_header));
3494 memset(skb_push(skb, pad), 0, pad);
3496 head->len += skb->len;
3497 head->data_len += skb->len;
3501 fq->memory_usage += head->truesize - orig_truesize;
3502 if (head->len != orig_len) {
3503 flow->backlog += head->len - orig_len;
3504 tin->backlog_bytes += head->len - orig_len;
3507 spin_unlock_bh(&fq->lock);
3513 * Can be called while the sta lock is held. Anything that can cause packets to
3514 * be generated will cause deadlock!
3516 static ieee80211_tx_result
3517 ieee80211_xmit_fast_finish(struct ieee80211_sub_if_data *sdata,
3518 struct sta_info *sta, u8 pn_offs,
3519 struct ieee80211_key *key,
3520 struct ieee80211_tx_data *tx)
3522 struct sk_buff *skb = tx->skb;
3523 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3524 struct ieee80211_hdr *hdr = (void *)skb->data;
3525 u8 tid = IEEE80211_NUM_TIDS;
3527 if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL) &&
3528 ieee80211_tx_h_rate_ctrl(tx) != TX_CONTINUE)
3532 info->control.hw_key = &key->conf;
3534 dev_sw_netstats_tx_add(skb->dev, 1, skb->len);
3536 if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
3537 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
3538 hdr->seq_ctrl = ieee80211_tx_next_seq(sta, tid);
3540 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
3541 hdr->seq_ctrl = cpu_to_le16(sdata->sequence_number);
3542 sdata->sequence_number += 0x10;
3545 if (skb_shinfo(skb)->gso_size)
3546 sta->deflink.tx_stats.msdu[tid] +=
3547 DIV_ROUND_UP(skb->len, skb_shinfo(skb)->gso_size);
3549 sta->deflink.tx_stats.msdu[tid]++;
3551 info->hw_queue = sdata->vif.hw_queue[skb_get_queue_mapping(skb)];
3553 /* statistics normally done by ieee80211_tx_h_stats (but that
3554 * has to consider fragmentation, so is more complex)
3556 sta->deflink.tx_stats.bytes[skb_get_queue_mapping(skb)] += skb->len;
3557 sta->deflink.tx_stats.packets[skb_get_queue_mapping(skb)]++;
3561 u8 *crypto_hdr = skb->data + pn_offs;
3563 switch (key->conf.cipher) {
3564 case WLAN_CIPHER_SUITE_CCMP:
3565 case WLAN_CIPHER_SUITE_CCMP_256:
3566 case WLAN_CIPHER_SUITE_GCMP:
3567 case WLAN_CIPHER_SUITE_GCMP_256:
3568 pn = atomic64_inc_return(&key->conf.tx_pn);
3570 crypto_hdr[1] = pn >> 8;
3571 crypto_hdr[3] = 0x20 | (key->conf.keyidx << 6);
3572 crypto_hdr[4] = pn >> 16;
3573 crypto_hdr[5] = pn >> 24;
3574 crypto_hdr[6] = pn >> 32;
3575 crypto_hdr[7] = pn >> 40;
3583 static netdev_features_t
3584 ieee80211_sdata_netdev_features(struct ieee80211_sub_if_data *sdata)
3586 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
3587 return sdata->vif.netdev_features;
3592 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap);
3593 return sdata->vif.netdev_features;
3596 static struct sk_buff *
3597 ieee80211_tx_skb_fixup(struct sk_buff *skb, netdev_features_t features)
3599 if (skb_is_gso(skb)) {
3600 struct sk_buff *segs;
3602 segs = skb_gso_segment(skb, features);
3612 if (skb_needs_linearize(skb, features) && __skb_linearize(skb))
3615 if (skb->ip_summed == CHECKSUM_PARTIAL) {
3616 int ofs = skb_checksum_start_offset(skb);
3618 if (skb->encapsulation)
3619 skb_set_inner_transport_header(skb, ofs);
3621 skb_set_transport_header(skb, ofs);
3623 if (skb_csum_hwoffload_help(skb, features))
3627 skb_mark_not_on_list(skb);
3635 static void __ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
3636 struct sta_info *sta,
3637 struct ieee80211_fast_tx *fast_tx,
3638 struct sk_buff *skb, u8 tid, bool ampdu)
3640 struct ieee80211_local *local = sdata->local;
3641 struct ieee80211_hdr *hdr = (void *)fast_tx->hdr;
3642 struct ieee80211_tx_info *info;
3643 struct ieee80211_tx_data tx;
3644 ieee80211_tx_result r;
3645 int hw_headroom = sdata->local->hw.extra_tx_headroom;
3646 int extra_head = fast_tx->hdr_len - (ETH_HLEN - 2);
3649 skb = skb_share_check(skb, GFP_ATOMIC);
3653 if ((hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) &&
3654 ieee80211_amsdu_aggregate(sdata, sta, fast_tx, skb))
3657 /* will not be crypto-handled beyond what we do here, so use false
3658 * as the may-encrypt argument for the resize to not account for
3659 * more room than we already have in 'extra_head'
3661 if (unlikely(ieee80211_skb_resize(sdata, skb,
3662 max_t(int, extra_head + hw_headroom -
3663 skb_headroom(skb), 0),
3667 memcpy(ð, skb->data, ETH_HLEN - 2);
3668 hdr = skb_push(skb, extra_head);
3669 memcpy(skb->data, fast_tx->hdr, fast_tx->hdr_len);
3670 memcpy(skb->data + fast_tx->da_offs, eth.h_dest, ETH_ALEN);
3671 memcpy(skb->data + fast_tx->sa_offs, eth.h_source, ETH_ALEN);
3673 info = IEEE80211_SKB_CB(skb);
3674 memset(info, 0, sizeof(*info));
3675 info->band = fast_tx->band;
3676 info->control.vif = &sdata->vif;
3677 info->flags = IEEE80211_TX_CTL_FIRST_FRAGMENT |
3678 IEEE80211_TX_CTL_DONTFRAG;
3679 info->control.flags = IEEE80211_TX_CTRL_FAST_XMIT |
3680 u32_encode_bits(IEEE80211_LINK_UNSPECIFIED,
3681 IEEE80211_TX_CTRL_MLO_LINK);
3683 #ifdef CONFIG_MAC80211_DEBUGFS
3684 if (local->force_tx_status)
3685 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
3688 if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
3689 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
3690 *ieee80211_get_qos_ctl(hdr) = tid;
3693 __skb_queue_head_init(&tx.skbs);
3695 tx.flags = IEEE80211_TX_UNICAST;
3699 tx.key = fast_tx->key;
3701 if (ieee80211_queue_skb(local, sdata, sta, skb))
3705 r = ieee80211_xmit_fast_finish(sdata, sta, fast_tx->pn_offs,
3711 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
3712 sdata = container_of(sdata->bss,
3713 struct ieee80211_sub_if_data, u.ap);
3715 __skb_queue_tail(&tx.skbs, skb);
3716 ieee80211_tx_frags(local, &sdata->vif, sta, &tx.skbs, false);
3723 static bool ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
3724 struct sta_info *sta,
3725 struct ieee80211_fast_tx *fast_tx,
3726 struct sk_buff *skb)
3728 u16 ethertype = (skb->data[12] << 8) | skb->data[13];
3729 struct ieee80211_hdr *hdr = (void *)fast_tx->hdr;
3730 struct tid_ampdu_tx *tid_tx = NULL;
3731 struct sk_buff *next;
3732 u8 tid = IEEE80211_NUM_TIDS;
3734 /* control port protocol needs a lot of special handling */
3735 if (cpu_to_be16(ethertype) == sdata->control_port_protocol)
3738 /* only RFC 1042 SNAP */
3739 if (ethertype < ETH_P_802_3_MIN)
3742 /* don't handle TX status request here either */
3743 if (skb->sk && skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS)
3746 if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
3747 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
3748 tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
3750 if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state))
3752 if (tid_tx->timeout)
3753 tid_tx->last_tx = jiffies;
3757 /* after this point (skb is modified) we cannot return false */
3758 skb = ieee80211_tx_skb_fixup(skb, ieee80211_sdata_netdev_features(sdata));
3762 skb_list_walk_safe(skb, skb, next) {
3763 skb_mark_not_on_list(skb);
3764 __ieee80211_xmit_fast(sdata, sta, fast_tx, skb, tid, tid_tx);
3770 struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,
3771 struct ieee80211_txq *txq)
3773 struct ieee80211_local *local = hw_to_local(hw);
3774 struct txq_info *txqi = container_of(txq, struct txq_info, txq);
3775 struct ieee80211_hdr *hdr;
3776 struct sk_buff *skb = NULL;
3777 struct fq *fq = &local->fq;
3778 struct fq_tin *tin = &txqi->tin;
3779 struct ieee80211_tx_info *info;
3780 struct ieee80211_tx_data tx;
3781 ieee80211_tx_result r;
3782 struct ieee80211_vif *vif = txq->vif;
3783 int q = vif->hw_queue[txq->ac];
3786 WARN_ON_ONCE(softirq_count() == 0);
3788 if (!ieee80211_txq_airtime_check(hw, txq))
3792 spin_lock(&local->queue_stop_reason_lock);
3793 q_stopped = local->queue_stop_reasons[q];
3794 spin_unlock(&local->queue_stop_reason_lock);
3796 if (unlikely(q_stopped)) {
3797 /* mark for waking later */
3798 set_bit(IEEE80211_TXQ_DIRTY, &txqi->flags);
3802 spin_lock_bh(&fq->lock);
3804 /* Make sure fragments stay together. */
3805 skb = __skb_dequeue(&txqi->frags);
3806 if (unlikely(skb)) {
3807 if (!(IEEE80211_SKB_CB(skb)->control.flags &
3808 IEEE80211_TX_INTCFL_NEED_TXPROCESSING))
3810 IEEE80211_SKB_CB(skb)->control.flags &=
3811 ~IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
3813 if (unlikely(test_bit(IEEE80211_TXQ_STOP, &txqi->flags)))
3816 skb = fq_tin_dequeue(fq, tin, fq_tin_dequeue_func);
3822 spin_unlock_bh(&fq->lock);
3824 hdr = (struct ieee80211_hdr *)skb->data;
3825 info = IEEE80211_SKB_CB(skb);
3827 memset(&tx, 0, sizeof(tx));
3828 __skb_queue_head_init(&tx.skbs);
3831 tx.sdata = vif_to_sdata(info->control.vif);
3834 tx.sta = container_of(txq->sta, struct sta_info, sta);
3836 * Drop unicast frames to unauthorised stations unless they are
3837 * injected frames or EAPOL frames from the local station.
3839 if (unlikely(!(info->flags & IEEE80211_TX_CTL_INJECTED) &&
3840 ieee80211_is_data(hdr->frame_control) &&
3841 !ieee80211_vif_is_mesh(&tx.sdata->vif) &&
3842 tx.sdata->vif.type != NL80211_IFTYPE_OCB &&
3843 !is_multicast_ether_addr(hdr->addr1) &&
3844 !test_sta_flag(tx.sta, WLAN_STA_AUTHORIZED) &&
3845 (!(info->control.flags &
3846 IEEE80211_TX_CTRL_PORT_CTRL_PROTO) ||
3847 !ieee80211_is_our_addr(tx.sdata, hdr->addr2,
3849 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
3850 ieee80211_free_txskb(&local->hw, skb);
3856 * The key can be removed while the packet was queued, so need to call
3857 * this here to get the current key.
3859 r = ieee80211_tx_h_select_key(&tx);
3860 if (r != TX_CONTINUE) {
3861 ieee80211_free_txskb(&local->hw, skb);
3865 if (test_bit(IEEE80211_TXQ_AMPDU, &txqi->flags))
3866 info->flags |= (IEEE80211_TX_CTL_AMPDU |
3867 IEEE80211_TX_CTL_DONTFRAG);
3869 if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) {
3870 if (!ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
3871 r = ieee80211_tx_h_rate_ctrl(&tx);
3872 if (r != TX_CONTINUE) {
3873 ieee80211_free_txskb(&local->hw, skb);
3880 if (info->control.flags & IEEE80211_TX_CTRL_FAST_XMIT) {
3881 struct sta_info *sta = container_of(txq->sta, struct sta_info,
3886 (tx.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
3887 pn_offs = ieee80211_hdrlen(hdr->frame_control);
3889 r = ieee80211_xmit_fast_finish(sta->sdata, sta, pn_offs,
3891 if (r != TX_CONTINUE) {
3892 ieee80211_free_txskb(&local->hw, skb);
3896 if (invoke_tx_handlers_late(&tx))
3899 skb = __skb_dequeue(&tx.skbs);
3901 if (!skb_queue_empty(&tx.skbs)) {
3902 spin_lock_bh(&fq->lock);
3903 skb_queue_splice_tail(&tx.skbs, &txqi->frags);
3904 spin_unlock_bh(&fq->lock);
3908 if (skb_has_frag_list(skb) &&
3909 !ieee80211_hw_check(&local->hw, TX_FRAG_LIST)) {
3910 if (skb_linearize(skb)) {
3911 ieee80211_free_txskb(&local->hw, skb);
3916 switch (tx.sdata->vif.type) {
3917 case NL80211_IFTYPE_MONITOR:
3918 if (tx.sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) {
3919 vif = &tx.sdata->vif;
3922 tx.sdata = rcu_dereference(local->monitor_sdata);
3924 vif = &tx.sdata->vif;
3926 vif->hw_queue[skb_get_queue_mapping(skb)];
3927 } else if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) {
3928 ieee80211_free_txskb(&local->hw, skb);
3934 case NL80211_IFTYPE_AP_VLAN:
3935 tx.sdata = container_of(tx.sdata->bss,
3936 struct ieee80211_sub_if_data, u.ap);
3939 vif = &tx.sdata->vif;
3944 IEEE80211_SKB_CB(skb)->control.vif = vif;
3947 wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL)) {
3948 bool ampdu = txq->ac != IEEE80211_AC_VO;
3951 airtime = ieee80211_calc_expected_tx_airtime(hw, vif, txq->sta,
3954 airtime = ieee80211_info_set_tx_time_est(info, airtime);
3955 ieee80211_sta_update_pending_airtime(local, tx.sta,
3965 spin_unlock_bh(&fq->lock);
3969 EXPORT_SYMBOL(ieee80211_tx_dequeue);
3971 static inline s32 ieee80211_sta_deficit(struct sta_info *sta, u8 ac)
3973 struct airtime_info *air_info = &sta->airtime[ac];
3975 return air_info->deficit - atomic_read(&air_info->aql_tx_pending);
3979 ieee80211_txq_set_active(struct txq_info *txqi)
3981 struct sta_info *sta;
3986 sta = container_of(txqi->txq.sta, struct sta_info, sta);
3987 sta->airtime[txqi->txq.ac].last_active = (u32)jiffies;
3991 ieee80211_txq_keep_active(struct txq_info *txqi)
3993 struct sta_info *sta;
3999 sta = container_of(txqi->txq.sta, struct sta_info, sta);
4000 if (ieee80211_sta_deficit(sta, txqi->txq.ac) >= 0)
4003 diff = (u32)jiffies - sta->airtime[txqi->txq.ac].last_active;
4005 return diff <= AIRTIME_ACTIVE_DURATION;
4008 struct ieee80211_txq *ieee80211_next_txq(struct ieee80211_hw *hw, u8 ac)
4010 struct ieee80211_local *local = hw_to_local(hw);
4011 struct ieee80211_txq *ret = NULL;
4012 struct txq_info *txqi = NULL, *head = NULL;
4013 bool found_eligible_txq = false;
4015 spin_lock_bh(&local->active_txq_lock[ac]);
4017 if (!local->schedule_round[ac])
4021 txqi = list_first_entry_or_null(&local->active_txqs[ac],
4028 if (!found_eligible_txq)
4031 found_eligible_txq = false;
4037 if (txqi->txq.sta) {
4038 struct sta_info *sta = container_of(txqi->txq.sta,
4039 struct sta_info, sta);
4040 bool aql_check = ieee80211_txq_airtime_check(hw, &txqi->txq);
4041 s32 deficit = ieee80211_sta_deficit(sta, txqi->txq.ac);
4044 found_eligible_txq = true;
4047 sta->airtime[txqi->txq.ac].deficit +=
4048 sta->airtime_weight;
4050 if (deficit < 0 || !aql_check) {
4051 list_move_tail(&txqi->schedule_order,
4052 &local->active_txqs[txqi->txq.ac]);
4057 if (txqi->schedule_round == local->schedule_round[ac])
4060 list_del_init(&txqi->schedule_order);
4061 txqi->schedule_round = local->schedule_round[ac];
4065 spin_unlock_bh(&local->active_txq_lock[ac]);
4068 EXPORT_SYMBOL(ieee80211_next_txq);
4070 void __ieee80211_schedule_txq(struct ieee80211_hw *hw,
4071 struct ieee80211_txq *txq,
4074 struct ieee80211_local *local = hw_to_local(hw);
4075 struct txq_info *txqi = to_txq_info(txq);
4078 spin_lock_bh(&local->active_txq_lock[txq->ac]);
4080 has_queue = force || txq_has_queue(txq);
4081 if (list_empty(&txqi->schedule_order) &&
4082 (has_queue || ieee80211_txq_keep_active(txqi))) {
4083 /* If airtime accounting is active, always enqueue STAs at the
4084 * head of the list to ensure that they only get moved to the
4085 * back by the airtime DRR scheduler once they have a negative
4086 * deficit. A station that already has a negative deficit will
4087 * get immediately moved to the back of the list on the next
4088 * call to ieee80211_next_txq().
4090 if (txqi->txq.sta && local->airtime_flags && has_queue &&
4091 wiphy_ext_feature_isset(local->hw.wiphy,
4092 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
4093 list_add(&txqi->schedule_order,
4094 &local->active_txqs[txq->ac]);
4096 list_add_tail(&txqi->schedule_order,
4097 &local->active_txqs[txq->ac]);
4099 ieee80211_txq_set_active(txqi);
4102 spin_unlock_bh(&local->active_txq_lock[txq->ac]);
4104 EXPORT_SYMBOL(__ieee80211_schedule_txq);
4106 DEFINE_STATIC_KEY_FALSE(aql_disable);
4108 bool ieee80211_txq_airtime_check(struct ieee80211_hw *hw,
4109 struct ieee80211_txq *txq)
4111 struct sta_info *sta;
4112 struct ieee80211_local *local = hw_to_local(hw);
4114 if (!wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL))
4117 if (static_branch_unlikely(&aql_disable))
4123 if (unlikely(txq->tid == IEEE80211_NUM_TIDS))
4126 sta = container_of(txq->sta, struct sta_info, sta);
4127 if (atomic_read(&sta->airtime[txq->ac].aql_tx_pending) <
4128 sta->airtime[txq->ac].aql_limit_low)
4131 if (atomic_read(&local->aql_total_pending_airtime) <
4132 local->aql_threshold &&
4133 atomic_read(&sta->airtime[txq->ac].aql_tx_pending) <
4134 sta->airtime[txq->ac].aql_limit_high)
4139 EXPORT_SYMBOL(ieee80211_txq_airtime_check);
4142 ieee80211_txq_schedule_airtime_check(struct ieee80211_local *local, u8 ac)
4144 unsigned int num_txq = 0;
4145 struct txq_info *txq;
4148 if (!wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL))
4151 list_for_each_entry(txq, &local->active_txqs[ac], schedule_order)
4154 aql_limit = (num_txq - 1) * local->aql_txq_limit_low[ac] / 2 +
4155 local->aql_txq_limit_high[ac];
4157 return atomic_read(&local->aql_ac_pending_airtime[ac]) < aql_limit;
4160 bool ieee80211_txq_may_transmit(struct ieee80211_hw *hw,
4161 struct ieee80211_txq *txq)
4163 struct ieee80211_local *local = hw_to_local(hw);
4164 struct txq_info *iter, *tmp, *txqi = to_txq_info(txq);
4165 struct sta_info *sta;
4168 spin_lock_bh(&local->active_txq_lock[ac]);
4173 if (list_empty(&txqi->schedule_order))
4176 if (!ieee80211_txq_schedule_airtime_check(local, ac))
4179 list_for_each_entry_safe(iter, tmp, &local->active_txqs[ac],
4184 if (!iter->txq.sta) {
4185 list_move_tail(&iter->schedule_order,
4186 &local->active_txqs[ac]);
4189 sta = container_of(iter->txq.sta, struct sta_info, sta);
4190 if (ieee80211_sta_deficit(sta, ac) < 0)
4191 sta->airtime[ac].deficit += sta->airtime_weight;
4192 list_move_tail(&iter->schedule_order, &local->active_txqs[ac]);
4195 sta = container_of(txqi->txq.sta, struct sta_info, sta);
4196 if (sta->airtime[ac].deficit >= 0)
4199 sta->airtime[ac].deficit += sta->airtime_weight;
4200 list_move_tail(&txqi->schedule_order, &local->active_txqs[ac]);
4201 spin_unlock_bh(&local->active_txq_lock[ac]);
4205 if (!list_empty(&txqi->schedule_order))
4206 list_del_init(&txqi->schedule_order);
4207 spin_unlock_bh(&local->active_txq_lock[ac]);
4211 EXPORT_SYMBOL(ieee80211_txq_may_transmit);
4213 void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac)
4215 struct ieee80211_local *local = hw_to_local(hw);
4217 spin_lock_bh(&local->active_txq_lock[ac]);
4219 if (ieee80211_txq_schedule_airtime_check(local, ac)) {
4220 local->schedule_round[ac]++;
4221 if (!local->schedule_round[ac])
4222 local->schedule_round[ac]++;
4224 local->schedule_round[ac] = 0;
4227 spin_unlock_bh(&local->active_txq_lock[ac]);
4229 EXPORT_SYMBOL(ieee80211_txq_schedule_start);
4231 void __ieee80211_subif_start_xmit(struct sk_buff *skb,
4232 struct net_device *dev,
4237 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4238 struct ieee80211_local *local = sdata->local;
4239 struct sta_info *sta;
4240 struct sk_buff *next;
4243 if (unlikely(!ieee80211_sdata_running(sdata) || skb->len < ETH_HLEN)) {
4250 if (ieee80211_lookup_ra_sta(sdata, skb, &sta))
4256 skb_set_queue_mapping(skb, ieee80211_select_queue(sdata, sta, skb));
4257 ieee80211_aggr_check(sdata, sta, skb);
4259 sk_pacing_shift_update(skb->sk, sdata->local->hw.tx_sk_pacing_shift);
4262 struct ieee80211_fast_tx *fast_tx;
4264 fast_tx = rcu_dereference(sta->fast_tx);
4267 ieee80211_xmit_fast(sdata, sta, fast_tx, skb))
4271 /* the frame could be fragmented, software-encrypted, and other
4272 * things so we cannot really handle checksum or GSO offload.
4273 * fix it up in software before we handle anything else.
4275 skb = ieee80211_tx_skb_fixup(skb, 0);
4281 skb_list_walk_safe(skb, skb, next) {
4282 skb_mark_not_on_list(skb);
4284 if (skb->protocol == sdata->control_port_protocol)
4285 ctrl_flags |= IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP;
4287 skb = ieee80211_build_hdr(sdata, skb, info_flags,
4288 sta, ctrl_flags, cookie);
4290 kfree_skb_list(next);
4294 dev_sw_netstats_tx_add(dev, 1, skb->len);
4296 ieee80211_xmit(sdata, sta, skb);
4304 ieee80211_tpt_led_trig_tx(local, len);
4308 static int ieee80211_change_da(struct sk_buff *skb, struct sta_info *sta)
4313 err = skb_ensure_writable(skb, ETH_HLEN);
4317 eth = (void *)skb->data;
4318 ether_addr_copy(eth->h_dest, sta->sta.addr);
4323 static bool ieee80211_multicast_to_unicast(struct sk_buff *skb,
4324 struct net_device *dev)
4326 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4327 const struct ethhdr *eth = (void *)skb->data;
4328 const struct vlan_ethhdr *ethvlan = (void *)skb->data;
4331 switch (sdata->vif.type) {
4332 case NL80211_IFTYPE_AP_VLAN:
4333 if (sdata->u.vlan.sta)
4335 if (sdata->wdev.use_4addr)
4338 case NL80211_IFTYPE_AP:
4339 /* check runtime toggle for this bss */
4340 if (!sdata->bss->multicast_to_unicast)
4347 /* multicast to unicast conversion only for some payload */
4348 ethertype = eth->h_proto;
4349 if (ethertype == htons(ETH_P_8021Q) && skb->len >= VLAN_ETH_HLEN)
4350 ethertype = ethvlan->h_vlan_encapsulated_proto;
4351 switch (ethertype) {
4352 case htons(ETH_P_ARP):
4353 case htons(ETH_P_IP):
4354 case htons(ETH_P_IPV6):
4364 ieee80211_convert_to_unicast(struct sk_buff *skb, struct net_device *dev,
4365 struct sk_buff_head *queue)
4367 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4368 struct ieee80211_local *local = sdata->local;
4369 const struct ethhdr *eth = (struct ethhdr *)skb->data;
4370 struct sta_info *sta, *first = NULL;
4371 struct sk_buff *cloned_skb;
4375 list_for_each_entry_rcu(sta, &local->sta_list, list) {
4376 if (sdata != sta->sdata)
4377 /* AP-VLAN mismatch */
4379 if (unlikely(ether_addr_equal(eth->h_source, sta->sta.addr)))
4380 /* do not send back to source */
4386 cloned_skb = skb_clone(skb, GFP_ATOMIC);
4389 if (unlikely(ieee80211_change_da(cloned_skb, sta))) {
4390 dev_kfree_skb(cloned_skb);
4393 __skb_queue_tail(queue, cloned_skb);
4396 if (likely(first)) {
4397 if (unlikely(ieee80211_change_da(skb, first)))
4399 __skb_queue_tail(queue, skb);
4401 /* no STA connected, drop */
4408 __skb_queue_purge(queue);
4409 __skb_queue_tail(queue, skb);
4414 static void ieee80211_mlo_multicast_tx_one(struct ieee80211_sub_if_data *sdata,
4415 struct sk_buff *skb, u32 ctrl_flags,
4416 unsigned int link_id)
4418 struct sk_buff *out;
4420 out = skb_copy(skb, GFP_ATOMIC);
4424 ctrl_flags |= u32_encode_bits(link_id, IEEE80211_TX_CTRL_MLO_LINK);
4425 __ieee80211_subif_start_xmit(out, sdata->dev, 0, ctrl_flags, NULL);
4428 static void ieee80211_mlo_multicast_tx(struct net_device *dev,
4429 struct sk_buff *skb)
4431 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4432 unsigned long links = sdata->vif.valid_links;
4434 u32 ctrl_flags = IEEE80211_TX_CTRL_MCAST_MLO_FIRST_TX;
4436 if (hweight16(links) == 1) {
4437 ctrl_flags |= u32_encode_bits(__ffs(links),
4438 IEEE80211_TX_CTRL_MLO_LINK);
4440 __ieee80211_subif_start_xmit(skb, sdata->dev, 0, ctrl_flags,
4445 for_each_set_bit(link, &links, IEEE80211_MLD_MAX_NUM_LINKS) {
4446 ieee80211_mlo_multicast_tx_one(sdata, skb, ctrl_flags, link);
4453 * ieee80211_subif_start_xmit - netif start_xmit function for 802.3 vifs
4454 * @skb: packet to be sent
4455 * @dev: incoming interface
4457 * On failure skb will be freed.
4459 netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
4460 struct net_device *dev)
4462 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4463 const struct ethhdr *eth = (void *)skb->data;
4465 if (likely(!is_multicast_ether_addr(eth->h_dest)))
4468 if (unlikely(!ieee80211_sdata_running(sdata))) {
4470 return NETDEV_TX_OK;
4473 if (unlikely(ieee80211_multicast_to_unicast(skb, dev))) {
4474 struct sk_buff_head queue;
4476 __skb_queue_head_init(&queue);
4477 ieee80211_convert_to_unicast(skb, dev, &queue);
4478 while ((skb = __skb_dequeue(&queue)))
4479 __ieee80211_subif_start_xmit(skb, dev, 0,
4480 IEEE80211_TX_CTRL_MLO_LINK_UNSPEC,
4482 } else if (sdata->vif.valid_links &&
4483 sdata->vif.type == NL80211_IFTYPE_AP &&
4484 !ieee80211_hw_check(&sdata->local->hw, MLO_MCAST_MULTI_LINK_TX)) {
4485 ieee80211_mlo_multicast_tx(dev, skb);
4488 __ieee80211_subif_start_xmit(skb, dev, 0,
4489 IEEE80211_TX_CTRL_MLO_LINK_UNSPEC,
4493 return NETDEV_TX_OK;
4498 static bool __ieee80211_tx_8023(struct ieee80211_sub_if_data *sdata,
4499 struct sk_buff *skb, struct sta_info *sta,
4502 struct ieee80211_local *local = sdata->local;
4503 struct ieee80211_tx_control control = {};
4504 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4505 struct ieee80211_sta *pubsta = NULL;
4506 unsigned long flags;
4507 int q = info->hw_queue;
4509 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
4511 if (local->queue_stop_reasons[q] ||
4512 (!txpending && !skb_queue_empty(&local->pending[q]))) {
4514 skb_queue_head(&local->pending[q], skb);
4516 skb_queue_tail(&local->pending[q], skb);
4518 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
4523 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
4525 if (sta && sta->uploaded)
4528 control.sta = pubsta;
4530 drv_tx(local, &control, skb);
4535 static bool ieee80211_tx_8023(struct ieee80211_sub_if_data *sdata,
4536 struct sk_buff *skb, struct sta_info *sta,
4539 struct ieee80211_local *local = sdata->local;
4540 struct sk_buff *next;
4543 if (ieee80211_queue_skb(local, sdata, sta, skb))
4546 skb_list_walk_safe(skb, skb, next) {
4547 skb_mark_not_on_list(skb);
4548 if (!__ieee80211_tx_8023(sdata, skb, sta, txpending))
4555 static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata,
4556 struct net_device *dev, struct sta_info *sta,
4557 struct ieee80211_key *key, struct sk_buff *skb)
4559 struct ieee80211_tx_info *info;
4560 struct ieee80211_local *local = sdata->local;
4561 struct tid_ampdu_tx *tid_tx;
4562 struct sk_buff *seg, *next;
4563 unsigned int skbs = 0, len = 0;
4567 queue = ieee80211_select_queue(sdata, sta, skb);
4568 skb_set_queue_mapping(skb, queue);
4570 if (unlikely(test_bit(SCAN_SW_SCANNING, &local->scanning)) &&
4571 test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))
4574 skb = skb_share_check(skb, GFP_ATOMIC);
4578 ieee80211_aggr_check(sdata, sta, skb);
4580 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
4581 tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
4583 if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
4584 /* fall back to non-offload slow path */
4585 __ieee80211_subif_start_xmit(skb, dev, 0,
4586 IEEE80211_TX_CTRL_MLO_LINK_UNSPEC,
4591 if (tid_tx->timeout)
4592 tid_tx->last_tx = jiffies;
4595 skb = ieee80211_tx_skb_fixup(skb, ieee80211_sdata_netdev_features(sdata));
4599 info = IEEE80211_SKB_CB(skb);
4600 memset(info, 0, sizeof(*info));
4602 info->hw_queue = sdata->vif.hw_queue[queue];
4604 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
4605 sdata = container_of(sdata->bss,
4606 struct ieee80211_sub_if_data, u.ap);
4608 info->flags |= IEEE80211_TX_CTL_HW_80211_ENCAP;
4609 info->control.vif = &sdata->vif;
4612 info->control.hw_key = &key->conf;
4614 skb_list_walk_safe(skb, seg, next) {
4618 memcpy(IEEE80211_SKB_CB(seg), info, sizeof(*info));
4621 if (unlikely(skb->sk &&
4622 skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS))
4623 info->ack_frame_id = ieee80211_store_ack_skb(local, skb,
4624 &info->flags, NULL);
4626 dev_sw_netstats_tx_add(dev, skbs, len);
4627 sta->deflink.tx_stats.packets[queue] += skbs;
4628 sta->deflink.tx_stats.bytes[queue] += len;
4630 ieee80211_tpt_led_trig_tx(local, len);
4632 ieee80211_tx_8023(sdata, skb, sta, false);
4640 netdev_tx_t ieee80211_subif_start_xmit_8023(struct sk_buff *skb,
4641 struct net_device *dev)
4643 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4644 struct ethhdr *ehdr = (struct ethhdr *)skb->data;
4645 struct ieee80211_key *key;
4646 struct sta_info *sta;
4648 if (unlikely(!ieee80211_sdata_running(sdata) || skb->len < ETH_HLEN)) {
4650 return NETDEV_TX_OK;
4655 if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) {
4660 if (unlikely(IS_ERR_OR_NULL(sta) || !sta->uploaded ||
4661 !test_sta_flag(sta, WLAN_STA_AUTHORIZED) ||
4662 sdata->control_port_protocol == ehdr->h_proto))
4665 key = rcu_dereference(sta->ptk[sta->ptk_idx]);
4667 key = rcu_dereference(sdata->default_unicast_key);
4669 if (key && (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) ||
4670 key->conf.cipher == WLAN_CIPHER_SUITE_TKIP))
4673 sk_pacing_shift_update(skb->sk, sdata->local->hw.tx_sk_pacing_shift);
4674 ieee80211_8023_xmit(sdata, dev, sta, key, skb);
4678 ieee80211_subif_start_xmit(skb, dev);
4682 return NETDEV_TX_OK;
4686 ieee80211_build_data_template(struct ieee80211_sub_if_data *sdata,
4687 struct sk_buff *skb, u32 info_flags)
4689 struct ieee80211_hdr *hdr;
4690 struct ieee80211_tx_data tx = {
4691 .local = sdata->local,
4694 struct sta_info *sta;
4698 if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) {
4700 skb = ERR_PTR(-EINVAL);
4704 skb = ieee80211_build_hdr(sdata, skb, info_flags, sta,
4705 IEEE80211_TX_CTRL_MLO_LINK_UNSPEC, NULL);
4709 hdr = (void *)skb->data;
4710 tx.sta = sta_info_get(sdata, hdr->addr1);
4713 if (ieee80211_tx_h_select_key(&tx) != TX_CONTINUE) {
4716 return ERR_PTR(-EINVAL);
4725 * ieee80211_clear_tx_pending may not be called in a context where
4726 * it is possible that it packets could come in again.
4728 void ieee80211_clear_tx_pending(struct ieee80211_local *local)
4730 struct sk_buff *skb;
4733 for (i = 0; i < local->hw.queues; i++) {
4734 while ((skb = skb_dequeue(&local->pending[i])) != NULL)
4735 ieee80211_free_txskb(&local->hw, skb);
4740 * Returns false if the frame couldn't be transmitted but was queued instead,
4741 * which in this case means re-queued -- take as an indication to stop sending
4742 * more pending frames.
4744 static bool ieee80211_tx_pending_skb(struct ieee80211_local *local,
4745 struct sk_buff *skb)
4747 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4748 struct ieee80211_sub_if_data *sdata;
4749 struct sta_info *sta;
4750 struct ieee80211_hdr *hdr;
4752 struct ieee80211_chanctx_conf *chanctx_conf;
4754 sdata = vif_to_sdata(info->control.vif);
4756 if (info->control.flags & IEEE80211_TX_INTCFL_NEED_TXPROCESSING) {
4757 /* update band only for non-MLD */
4758 if (!sdata->vif.valid_links) {
4760 rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
4761 if (unlikely(!chanctx_conf)) {
4765 info->band = chanctx_conf->def.chan->band;
4767 result = ieee80211_tx(sdata, NULL, skb, true);
4768 } else if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) {
4769 if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) {
4774 if (IS_ERR(sta) || (sta && !sta->uploaded))
4777 result = ieee80211_tx_8023(sdata, skb, sta, true);
4779 struct sk_buff_head skbs;
4781 __skb_queue_head_init(&skbs);
4782 __skb_queue_tail(&skbs, skb);
4784 hdr = (struct ieee80211_hdr *)skb->data;
4785 sta = sta_info_get(sdata, hdr->addr1);
4787 result = __ieee80211_tx(local, &skbs, sta, true);
4794 * Transmit all pending packets. Called from tasklet.
4796 void ieee80211_tx_pending(struct tasklet_struct *t)
4798 struct ieee80211_local *local = from_tasklet(local, t,
4799 tx_pending_tasklet);
4800 unsigned long flags;
4806 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
4807 for (i = 0; i < local->hw.queues; i++) {
4809 * If queue is stopped by something other than due to pending
4810 * frames, or we have no pending frames, proceed to next queue.
4812 if (local->queue_stop_reasons[i] ||
4813 skb_queue_empty(&local->pending[i]))
4816 while (!skb_queue_empty(&local->pending[i])) {
4817 struct sk_buff *skb = __skb_dequeue(&local->pending[i]);
4818 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4820 if (WARN_ON(!info->control.vif)) {
4821 ieee80211_free_txskb(&local->hw, skb);
4825 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
4828 txok = ieee80211_tx_pending_skb(local, skb);
4829 spin_lock_irqsave(&local->queue_stop_reason_lock,
4835 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
4840 /* functions for drivers to get certain frames */
4842 static void __ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
4843 struct ieee80211_link_data *link,
4844 struct ps_data *ps, struct sk_buff *skb,
4849 int i, have_bits = 0, n1, n2;
4850 struct ieee80211_bss_conf *link_conf = link->conf;
4852 /* Generate bitmap for TIM only if there are any STAs in power save
4854 if (atomic_read(&ps->num_sta_ps) > 0)
4855 /* in the hope that this is faster than
4856 * checking byte-for-byte */
4857 have_bits = !bitmap_empty((unsigned long *)ps->tim,
4858 IEEE80211_MAX_AID+1);
4860 if (ps->dtim_count == 0)
4861 ps->dtim_count = link_conf->dtim_period - 1;
4866 tim = pos = skb_put(skb, 5);
4867 *pos++ = WLAN_EID_TIM;
4869 *pos++ = ps->dtim_count;
4870 *pos++ = link_conf->dtim_period;
4872 if (ps->dtim_count == 0 && !skb_queue_empty(&ps->bc_buf))
4875 ps->dtim_bc_mc = aid0 == 1;
4878 /* Find largest even number N1 so that bits numbered 1 through
4879 * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits
4880 * (N2 + 1) x 8 through 2007 are 0. */
4882 for (i = 0; i < IEEE80211_MAX_TIM_LEN; i++) {
4889 for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) {
4896 /* Bitmap control */
4898 /* Part Virt Bitmap */
4899 skb_put_data(skb, ps->tim + n1, n2 - n1 + 1);
4901 tim[1] = n2 - n1 + 4;
4903 *pos++ = aid0; /* Bitmap control */
4905 if (ieee80211_get_link_sband(link)->band != NL80211_BAND_S1GHZ) {
4907 /* Part Virt Bitmap */
4913 static int ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
4914 struct ieee80211_link_data *link,
4915 struct ps_data *ps, struct sk_buff *skb,
4918 struct ieee80211_local *local = sdata->local;
4921 * Not very nice, but we want to allow the driver to call
4922 * ieee80211_beacon_get() as a response to the set_tim()
4923 * callback. That, however, is already invoked under the
4924 * sta_lock to guarantee consistent and race-free update
4925 * of the tim bitmap in mac80211 and the driver.
4927 if (local->tim_in_locked_section) {
4928 __ieee80211_beacon_add_tim(sdata, link, ps, skb, is_template);
4930 spin_lock_bh(&local->tim_lock);
4931 __ieee80211_beacon_add_tim(sdata, link, ps, skb, is_template);
4932 spin_unlock_bh(&local->tim_lock);
4938 static void ieee80211_set_beacon_cntdwn(struct ieee80211_sub_if_data *sdata,
4939 struct beacon_data *beacon,
4940 struct ieee80211_link_data *link)
4942 u8 *beacon_data, count, max_count = 1;
4943 struct probe_resp *resp;
4944 size_t beacon_data_len;
4948 switch (sdata->vif.type) {
4949 case NL80211_IFTYPE_AP:
4950 beacon_data = beacon->tail;
4951 beacon_data_len = beacon->tail_len;
4953 case NL80211_IFTYPE_ADHOC:
4954 beacon_data = beacon->head;
4955 beacon_data_len = beacon->head_len;
4957 case NL80211_IFTYPE_MESH_POINT:
4958 beacon_data = beacon->head;
4959 beacon_data_len = beacon->head_len;
4965 resp = rcu_dereference(link->u.ap.probe_resp);
4967 bcn_offsets = beacon->cntdwn_counter_offsets;
4968 count = beacon->cntdwn_current_counter;
4969 if (link->conf->csa_active)
4970 max_count = IEEE80211_MAX_CNTDWN_COUNTERS_NUM;
4972 for (i = 0; i < max_count; ++i) {
4973 if (bcn_offsets[i]) {
4974 if (WARN_ON_ONCE(bcn_offsets[i] >= beacon_data_len))
4976 beacon_data[bcn_offsets[i]] = count;
4979 if (sdata->vif.type == NL80211_IFTYPE_AP && resp) {
4980 u16 *resp_offsets = resp->cntdwn_counter_offsets;
4982 resp->data[resp_offsets[i]] = count;
4987 static u8 __ieee80211_beacon_update_cntdwn(struct beacon_data *beacon)
4989 beacon->cntdwn_current_counter--;
4991 /* the counter should never reach 0 */
4992 WARN_ON_ONCE(!beacon->cntdwn_current_counter);
4994 return beacon->cntdwn_current_counter;
4997 u8 ieee80211_beacon_update_cntdwn(struct ieee80211_vif *vif)
4999 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5000 struct beacon_data *beacon = NULL;
5005 if (sdata->vif.type == NL80211_IFTYPE_AP)
5006 beacon = rcu_dereference(sdata->deflink.u.ap.beacon);
5007 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
5008 beacon = rcu_dereference(sdata->u.ibss.presp);
5009 else if (ieee80211_vif_is_mesh(&sdata->vif))
5010 beacon = rcu_dereference(sdata->u.mesh.beacon);
5015 count = __ieee80211_beacon_update_cntdwn(beacon);
5021 EXPORT_SYMBOL(ieee80211_beacon_update_cntdwn);
5023 void ieee80211_beacon_set_cntdwn(struct ieee80211_vif *vif, u8 counter)
5025 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5026 struct beacon_data *beacon = NULL;
5030 if (sdata->vif.type == NL80211_IFTYPE_AP)
5031 beacon = rcu_dereference(sdata->deflink.u.ap.beacon);
5032 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
5033 beacon = rcu_dereference(sdata->u.ibss.presp);
5034 else if (ieee80211_vif_is_mesh(&sdata->vif))
5035 beacon = rcu_dereference(sdata->u.mesh.beacon);
5040 if (counter < beacon->cntdwn_current_counter)
5041 beacon->cntdwn_current_counter = counter;
5046 EXPORT_SYMBOL(ieee80211_beacon_set_cntdwn);
5048 bool ieee80211_beacon_cntdwn_is_complete(struct ieee80211_vif *vif)
5050 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5051 struct beacon_data *beacon = NULL;
5053 size_t beacon_data_len;
5056 if (!ieee80211_sdata_running(sdata))
5060 if (vif->type == NL80211_IFTYPE_AP) {
5061 beacon = rcu_dereference(sdata->deflink.u.ap.beacon);
5062 if (WARN_ON(!beacon || !beacon->tail))
5064 beacon_data = beacon->tail;
5065 beacon_data_len = beacon->tail_len;
5066 } else if (vif->type == NL80211_IFTYPE_ADHOC) {
5067 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
5069 beacon = rcu_dereference(ifibss->presp);
5073 beacon_data = beacon->head;
5074 beacon_data_len = beacon->head_len;
5075 } else if (vif->type == NL80211_IFTYPE_MESH_POINT) {
5076 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
5078 beacon = rcu_dereference(ifmsh->beacon);
5082 beacon_data = beacon->head;
5083 beacon_data_len = beacon->head_len;
5089 if (!beacon->cntdwn_counter_offsets[0])
5092 if (WARN_ON_ONCE(beacon->cntdwn_counter_offsets[0] > beacon_data_len))
5095 if (beacon_data[beacon->cntdwn_counter_offsets[0]] == 1)
5103 EXPORT_SYMBOL(ieee80211_beacon_cntdwn_is_complete);
5105 static int ieee80211_beacon_protect(struct sk_buff *skb,
5106 struct ieee80211_local *local,
5107 struct ieee80211_sub_if_data *sdata,
5108 struct ieee80211_link_data *link)
5110 ieee80211_tx_result res;
5111 struct ieee80211_tx_data tx;
5112 struct sk_buff *check_skb;
5114 memset(&tx, 0, sizeof(tx));
5115 tx.key = rcu_dereference(link->default_beacon_key);
5120 __skb_queue_head_init(&tx.skbs);
5121 __skb_queue_tail(&tx.skbs, skb);
5122 res = ieee80211_tx_h_encrypt(&tx);
5123 check_skb = __skb_dequeue(&tx.skbs);
5124 /* we may crash after this, but it'd be a bug in crypto */
5125 WARN_ON(check_skb != skb);
5126 if (WARN_ON_ONCE(res != TX_CONTINUE))
5133 ieee80211_beacon_get_finish(struct ieee80211_hw *hw,
5134 struct ieee80211_vif *vif,
5135 struct ieee80211_link_data *link,
5136 struct ieee80211_mutable_offsets *offs,
5137 struct beacon_data *beacon,
5138 struct sk_buff *skb,
5139 struct ieee80211_chanctx_conf *chanctx_conf,
5142 struct ieee80211_local *local = hw_to_local(hw);
5143 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5144 struct ieee80211_tx_info *info;
5145 enum nl80211_band band;
5146 struct ieee80211_tx_rate_control txrc;
5149 if (offs && beacon) {
5152 for (i = 0; i < IEEE80211_MAX_CNTDWN_COUNTERS_NUM; i++) {
5153 u16 csa_off = beacon->cntdwn_counter_offsets[i];
5158 offs->cntdwn_counter_offs[i] = csa_off_base + csa_off;
5162 band = chanctx_conf->def.chan->band;
5163 info = IEEE80211_SKB_CB(skb);
5164 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
5165 info->flags |= IEEE80211_TX_CTL_NO_ACK;
5168 memset(&txrc, 0, sizeof(txrc));
5170 txrc.sband = local->hw.wiphy->bands[band];
5171 txrc.bss_conf = link->conf;
5173 txrc.reported_rate.idx = -1;
5174 if (sdata->beacon_rate_set && sdata->beacon_rateidx_mask[band])
5175 txrc.rate_idx_mask = sdata->beacon_rateidx_mask[band];
5177 txrc.rate_idx_mask = sdata->rc_rateidx_mask[band];
5179 rate_control_get_rate(sdata, NULL, &txrc);
5181 info->control.vif = vif;
5182 info->control.flags |= u32_encode_bits(link->link_id,
5183 IEEE80211_TX_CTRL_MLO_LINK);
5184 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT |
5185 IEEE80211_TX_CTL_ASSIGN_SEQ |
5186 IEEE80211_TX_CTL_FIRST_FRAGMENT;
5190 ieee80211_beacon_add_mbssid(struct sk_buff *skb, struct beacon_data *beacon)
5194 if (!beacon->mbssid_ies)
5197 for (i = 0; i < beacon->mbssid_ies->cnt; i++)
5198 skb_put_data(skb, beacon->mbssid_ies->elem[i].data,
5199 beacon->mbssid_ies->elem[i].len);
5202 static struct sk_buff *
5203 ieee80211_beacon_get_ap(struct ieee80211_hw *hw,
5204 struct ieee80211_vif *vif,
5205 struct ieee80211_link_data *link,
5206 struct ieee80211_mutable_offsets *offs,
5208 struct beacon_data *beacon,
5209 struct ieee80211_chanctx_conf *chanctx_conf)
5211 struct ieee80211_local *local = hw_to_local(hw);
5212 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5213 struct ieee80211_if_ap *ap = &sdata->u.ap;
5214 struct sk_buff *skb = NULL;
5215 u16 csa_off_base = 0;
5218 if (beacon->cntdwn_counter_offsets[0]) {
5220 ieee80211_beacon_update_cntdwn(vif);
5222 ieee80211_set_beacon_cntdwn(sdata, beacon, link);
5225 /* headroom, head length,
5226 * tail length, maximum TIM length and multiple BSSID length
5228 mbssid_len = ieee80211_get_mbssid_beacon_len(beacon->mbssid_ies);
5229 skb = dev_alloc_skb(local->tx_headroom + beacon->head_len +
5230 beacon->tail_len + 256 +
5231 local->hw.extra_beacon_tailroom + mbssid_len);
5235 skb_reserve(skb, local->tx_headroom);
5236 skb_put_data(skb, beacon->head, beacon->head_len);
5238 ieee80211_beacon_add_tim(sdata, link, &ap->ps, skb, is_template);
5241 offs->tim_offset = beacon->head_len;
5242 offs->tim_length = skb->len - beacon->head_len;
5243 offs->cntdwn_counter_offs[0] = beacon->cntdwn_counter_offsets[0];
5246 ieee80211_beacon_add_mbssid(skb, beacon);
5247 offs->mbssid_off = skb->len - mbssid_len;
5250 /* for AP the csa offsets are from tail */
5251 csa_off_base = skb->len;
5255 skb_put_data(skb, beacon->tail, beacon->tail_len);
5257 if (ieee80211_beacon_protect(skb, local, sdata, link) < 0)
5260 ieee80211_beacon_get_finish(hw, vif, link, offs, beacon, skb,
5261 chanctx_conf, csa_off_base);
5265 static struct sk_buff *
5266 __ieee80211_beacon_get(struct ieee80211_hw *hw,
5267 struct ieee80211_vif *vif,
5268 struct ieee80211_mutable_offsets *offs,
5270 unsigned int link_id)
5272 struct ieee80211_local *local = hw_to_local(hw);
5273 struct beacon_data *beacon = NULL;
5274 struct sk_buff *skb = NULL;
5275 struct ieee80211_sub_if_data *sdata = NULL;
5276 struct ieee80211_chanctx_conf *chanctx_conf;
5277 struct ieee80211_link_data *link;
5281 sdata = vif_to_sdata(vif);
5282 link = rcu_dereference(sdata->link[link_id]);
5286 rcu_dereference(link->conf->chanctx_conf);
5288 if (!ieee80211_sdata_running(sdata) || !chanctx_conf)
5292 memset(offs, 0, sizeof(*offs));
5294 if (sdata->vif.type == NL80211_IFTYPE_AP) {
5295 beacon = rcu_dereference(link->u.ap.beacon);
5299 skb = ieee80211_beacon_get_ap(hw, vif, link, offs, is_template,
5300 beacon, chanctx_conf);
5301 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
5302 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
5303 struct ieee80211_hdr *hdr;
5305 beacon = rcu_dereference(ifibss->presp);
5309 if (beacon->cntdwn_counter_offsets[0]) {
5311 __ieee80211_beacon_update_cntdwn(beacon);
5313 ieee80211_set_beacon_cntdwn(sdata, beacon, link);
5316 skb = dev_alloc_skb(local->tx_headroom + beacon->head_len +
5317 local->hw.extra_beacon_tailroom);
5320 skb_reserve(skb, local->tx_headroom);
5321 skb_put_data(skb, beacon->head, beacon->head_len);
5323 hdr = (struct ieee80211_hdr *) skb->data;
5324 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
5325 IEEE80211_STYPE_BEACON);
5327 ieee80211_beacon_get_finish(hw, vif, link, offs, beacon, skb,
5329 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
5330 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
5332 beacon = rcu_dereference(ifmsh->beacon);
5336 if (beacon->cntdwn_counter_offsets[0]) {
5338 /* TODO: For mesh csa_counter is in TU, so
5339 * decrementing it by one isn't correct, but
5340 * for now we leave it consistent with overall
5341 * mac80211's behavior.
5343 __ieee80211_beacon_update_cntdwn(beacon);
5345 ieee80211_set_beacon_cntdwn(sdata, beacon, link);
5348 if (ifmsh->sync_ops)
5349 ifmsh->sync_ops->adjust_tsf(sdata, beacon);
5351 skb = dev_alloc_skb(local->tx_headroom +
5355 local->hw.extra_beacon_tailroom);
5358 skb_reserve(skb, local->tx_headroom);
5359 skb_put_data(skb, beacon->head, beacon->head_len);
5360 ieee80211_beacon_add_tim(sdata, link, &ifmsh->ps, skb,
5364 offs->tim_offset = beacon->head_len;
5365 offs->tim_length = skb->len - beacon->head_len;
5368 skb_put_data(skb, beacon->tail, beacon->tail_len);
5369 ieee80211_beacon_get_finish(hw, vif, link, offs, beacon, skb,
5383 ieee80211_beacon_get_template(struct ieee80211_hw *hw,
5384 struct ieee80211_vif *vif,
5385 struct ieee80211_mutable_offsets *offs,
5386 unsigned int link_id)
5388 return __ieee80211_beacon_get(hw, vif, offs, true, link_id);
5390 EXPORT_SYMBOL(ieee80211_beacon_get_template);
5392 struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
5393 struct ieee80211_vif *vif,
5394 u16 *tim_offset, u16 *tim_length,
5395 unsigned int link_id)
5397 struct ieee80211_mutable_offsets offs = {};
5398 struct sk_buff *bcn = __ieee80211_beacon_get(hw, vif, &offs, false,
5400 struct sk_buff *copy;
5407 *tim_offset = offs.tim_offset;
5410 *tim_length = offs.tim_length;
5412 if (ieee80211_hw_check(hw, BEACON_TX_STATUS) ||
5413 !hw_to_local(hw)->monitors)
5416 /* send a copy to monitor interfaces */
5417 copy = skb_copy(bcn, GFP_ATOMIC);
5421 shift = ieee80211_vif_get_shift(vif);
5422 ieee80211_tx_monitor(hw_to_local(hw), copy, 1, shift, false, NULL);
5426 EXPORT_SYMBOL(ieee80211_beacon_get_tim);
5428 struct sk_buff *ieee80211_proberesp_get(struct ieee80211_hw *hw,
5429 struct ieee80211_vif *vif)
5431 struct sk_buff *skb = NULL;
5432 struct probe_resp *presp = NULL;
5433 struct ieee80211_hdr *hdr;
5434 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5436 if (sdata->vif.type != NL80211_IFTYPE_AP)
5440 presp = rcu_dereference(sdata->deflink.u.ap.probe_resp);
5444 skb = dev_alloc_skb(presp->len);
5448 skb_put_data(skb, presp->data, presp->len);
5450 hdr = (struct ieee80211_hdr *) skb->data;
5451 memset(hdr->addr1, 0, sizeof(hdr->addr1));
5457 EXPORT_SYMBOL(ieee80211_proberesp_get);
5459 struct sk_buff *ieee80211_get_fils_discovery_tmpl(struct ieee80211_hw *hw,
5460 struct ieee80211_vif *vif)
5462 struct sk_buff *skb = NULL;
5463 struct fils_discovery_data *tmpl = NULL;
5464 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5466 if (sdata->vif.type != NL80211_IFTYPE_AP)
5470 tmpl = rcu_dereference(sdata->deflink.u.ap.fils_discovery);
5476 skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom + tmpl->len);
5478 skb_reserve(skb, sdata->local->hw.extra_tx_headroom);
5479 skb_put_data(skb, tmpl->data, tmpl->len);
5485 EXPORT_SYMBOL(ieee80211_get_fils_discovery_tmpl);
5488 ieee80211_get_unsol_bcast_probe_resp_tmpl(struct ieee80211_hw *hw,
5489 struct ieee80211_vif *vif)
5491 struct sk_buff *skb = NULL;
5492 struct unsol_bcast_probe_resp_data *tmpl = NULL;
5493 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5495 if (sdata->vif.type != NL80211_IFTYPE_AP)
5499 tmpl = rcu_dereference(sdata->deflink.u.ap.unsol_bcast_probe_resp);
5505 skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom + tmpl->len);
5507 skb_reserve(skb, sdata->local->hw.extra_tx_headroom);
5508 skb_put_data(skb, tmpl->data, tmpl->len);
5514 EXPORT_SYMBOL(ieee80211_get_unsol_bcast_probe_resp_tmpl);
5516 struct sk_buff *ieee80211_pspoll_get(struct ieee80211_hw *hw,
5517 struct ieee80211_vif *vif)
5519 struct ieee80211_sub_if_data *sdata;
5520 struct ieee80211_pspoll *pspoll;
5521 struct ieee80211_local *local;
5522 struct sk_buff *skb;
5524 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
5527 sdata = vif_to_sdata(vif);
5528 local = sdata->local;
5530 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll));
5534 skb_reserve(skb, local->hw.extra_tx_headroom);
5536 pspoll = skb_put_zero(skb, sizeof(*pspoll));
5537 pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
5538 IEEE80211_STYPE_PSPOLL);
5539 pspoll->aid = cpu_to_le16(sdata->vif.cfg.aid);
5541 /* aid in PS-Poll has its two MSBs each set to 1 */
5542 pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
5544 memcpy(pspoll->bssid, sdata->deflink.u.mgd.bssid, ETH_ALEN);
5545 memcpy(pspoll->ta, vif->addr, ETH_ALEN);
5549 EXPORT_SYMBOL(ieee80211_pspoll_get);
5551 struct sk_buff *ieee80211_nullfunc_get(struct ieee80211_hw *hw,
5552 struct ieee80211_vif *vif,
5553 int link_id, bool qos_ok)
5555 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5556 struct ieee80211_local *local = sdata->local;
5557 struct ieee80211_link_data *link = NULL;
5558 struct ieee80211_hdr_3addr *nullfunc;
5559 struct sk_buff *skb;
5562 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
5565 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
5566 sizeof(*nullfunc) + 2);
5572 struct sta_info *sta;
5574 sta = sta_info_get(sdata, vif->cfg.ap_addr);
5575 qos = sta && sta->sta.wme;
5579 link = rcu_dereference(sdata->link[link_id]);
5580 if (WARN_ON_ONCE(!link)) {
5587 skb_reserve(skb, local->hw.extra_tx_headroom);
5589 nullfunc = skb_put_zero(skb, sizeof(*nullfunc));
5590 nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
5591 IEEE80211_STYPE_NULLFUNC |
5592 IEEE80211_FCTL_TODS);
5594 __le16 qoshdr = cpu_to_le16(7);
5596 BUILD_BUG_ON((IEEE80211_STYPE_QOS_NULLFUNC |
5597 IEEE80211_STYPE_NULLFUNC) !=
5598 IEEE80211_STYPE_QOS_NULLFUNC);
5599 nullfunc->frame_control |=
5600 cpu_to_le16(IEEE80211_STYPE_QOS_NULLFUNC);
5602 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
5603 skb_put_data(skb, &qoshdr, sizeof(qoshdr));
5607 memcpy(nullfunc->addr1, link->conf->bssid, ETH_ALEN);
5608 memcpy(nullfunc->addr2, link->conf->addr, ETH_ALEN);
5609 memcpy(nullfunc->addr3, link->conf->bssid, ETH_ALEN);
5611 memcpy(nullfunc->addr1, vif->cfg.ap_addr, ETH_ALEN);
5612 memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
5613 memcpy(nullfunc->addr3, vif->cfg.ap_addr, ETH_ALEN);
5619 EXPORT_SYMBOL(ieee80211_nullfunc_get);
5621 struct sk_buff *ieee80211_probereq_get(struct ieee80211_hw *hw,
5623 const u8 *ssid, size_t ssid_len,
5626 struct ieee80211_local *local = hw_to_local(hw);
5627 struct ieee80211_hdr_3addr *hdr;
5628 struct sk_buff *skb;
5632 ie_ssid_len = 2 + ssid_len;
5634 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*hdr) +
5635 ie_ssid_len + tailroom);
5639 skb_reserve(skb, local->hw.extra_tx_headroom);
5641 hdr = skb_put_zero(skb, sizeof(*hdr));
5642 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
5643 IEEE80211_STYPE_PROBE_REQ);
5644 eth_broadcast_addr(hdr->addr1);
5645 memcpy(hdr->addr2, src_addr, ETH_ALEN);
5646 eth_broadcast_addr(hdr->addr3);
5648 pos = skb_put(skb, ie_ssid_len);
5649 *pos++ = WLAN_EID_SSID;
5652 memcpy(pos, ssid, ssid_len);
5657 EXPORT_SYMBOL(ieee80211_probereq_get);
5659 void ieee80211_rts_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5660 const void *frame, size_t frame_len,
5661 const struct ieee80211_tx_info *frame_txctl,
5662 struct ieee80211_rts *rts)
5664 const struct ieee80211_hdr *hdr = frame;
5666 rts->frame_control =
5667 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
5668 rts->duration = ieee80211_rts_duration(hw, vif, frame_len,
5670 memcpy(rts->ra, hdr->addr1, sizeof(rts->ra));
5671 memcpy(rts->ta, hdr->addr2, sizeof(rts->ta));
5673 EXPORT_SYMBOL(ieee80211_rts_get);
5675 void ieee80211_ctstoself_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5676 const void *frame, size_t frame_len,
5677 const struct ieee80211_tx_info *frame_txctl,
5678 struct ieee80211_cts *cts)
5680 const struct ieee80211_hdr *hdr = frame;
5682 cts->frame_control =
5683 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
5684 cts->duration = ieee80211_ctstoself_duration(hw, vif,
5685 frame_len, frame_txctl);
5686 memcpy(cts->ra, hdr->addr1, sizeof(cts->ra));
5688 EXPORT_SYMBOL(ieee80211_ctstoself_get);
5691 ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
5692 struct ieee80211_vif *vif)
5694 struct ieee80211_local *local = hw_to_local(hw);
5695 struct sk_buff *skb = NULL;
5696 struct ieee80211_tx_data tx;
5697 struct ieee80211_sub_if_data *sdata;
5699 struct ieee80211_tx_info *info;
5700 struct ieee80211_chanctx_conf *chanctx_conf;
5702 sdata = vif_to_sdata(vif);
5705 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
5710 if (sdata->vif.type == NL80211_IFTYPE_AP) {
5711 struct beacon_data *beacon =
5712 rcu_dereference(sdata->deflink.u.ap.beacon);
5714 if (!beacon || !beacon->head)
5717 ps = &sdata->u.ap.ps;
5718 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
5719 ps = &sdata->u.mesh.ps;
5724 if (ps->dtim_count != 0 || !ps->dtim_bc_mc)
5725 goto out; /* send buffered bc/mc only after DTIM beacon */
5728 skb = skb_dequeue(&ps->bc_buf);
5731 local->total_ps_buffered--;
5733 if (!skb_queue_empty(&ps->bc_buf) && skb->len >= 2) {
5734 struct ieee80211_hdr *hdr =
5735 (struct ieee80211_hdr *) skb->data;
5736 /* more buffered multicast/broadcast frames ==> set
5737 * MoreData flag in IEEE 802.11 header to inform PS
5739 hdr->frame_control |=
5740 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
5743 if (sdata->vif.type == NL80211_IFTYPE_AP)
5744 sdata = IEEE80211_DEV_TO_SUB_IF(skb->dev);
5745 if (!ieee80211_tx_prepare(sdata, &tx, NULL, skb))
5747 ieee80211_free_txskb(hw, skb);
5750 info = IEEE80211_SKB_CB(skb);
5752 tx.flags |= IEEE80211_TX_PS_BUFFERED;
5753 info->band = chanctx_conf->def.chan->band;
5755 if (invoke_tx_handlers(&tx))
5762 EXPORT_SYMBOL(ieee80211_get_buffered_bc);
5764 int ieee80211_reserve_tid(struct ieee80211_sta *pubsta, u8 tid)
5766 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
5767 struct ieee80211_sub_if_data *sdata = sta->sdata;
5768 struct ieee80211_local *local = sdata->local;
5772 lockdep_assert_held(&local->sta_mtx);
5774 /* only some cases are supported right now */
5775 switch (sdata->vif.type) {
5776 case NL80211_IFTYPE_STATION:
5777 case NL80211_IFTYPE_AP:
5778 case NL80211_IFTYPE_AP_VLAN:
5785 if (WARN_ON(tid >= IEEE80211_NUM_UPS))
5788 if (sta->reserved_tid == tid) {
5793 if (sta->reserved_tid != IEEE80211_TID_UNRESERVED) {
5794 sdata_err(sdata, "TID reservation already active\n");
5799 ieee80211_stop_vif_queues(sdata->local, sdata,
5800 IEEE80211_QUEUE_STOP_REASON_RESERVE_TID);
5804 /* Tear down BA sessions so we stop aggregating on this TID */
5805 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION)) {
5806 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
5807 __ieee80211_stop_tx_ba_session(sta, tid,
5808 AGG_STOP_LOCAL_REQUEST);
5811 queues = BIT(sdata->vif.hw_queue[ieee802_1d_to_ac[tid]]);
5812 __ieee80211_flush_queues(local, sdata, queues, false);
5814 sta->reserved_tid = tid;
5816 ieee80211_wake_vif_queues(local, sdata,
5817 IEEE80211_QUEUE_STOP_REASON_RESERVE_TID);
5819 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION))
5820 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
5826 EXPORT_SYMBOL(ieee80211_reserve_tid);
5828 void ieee80211_unreserve_tid(struct ieee80211_sta *pubsta, u8 tid)
5830 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
5831 struct ieee80211_sub_if_data *sdata = sta->sdata;
5833 lockdep_assert_held(&sdata->local->sta_mtx);
5835 /* only some cases are supported right now */
5836 switch (sdata->vif.type) {
5837 case NL80211_IFTYPE_STATION:
5838 case NL80211_IFTYPE_AP:
5839 case NL80211_IFTYPE_AP_VLAN:
5846 if (tid != sta->reserved_tid) {
5847 sdata_err(sdata, "TID to unreserve (%d) isn't reserved\n", tid);
5851 sta->reserved_tid = IEEE80211_TID_UNRESERVED;
5853 EXPORT_SYMBOL(ieee80211_unreserve_tid);
5855 void __ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata,
5856 struct sk_buff *skb, int tid, int link_id,
5857 enum nl80211_band band)
5859 const struct ieee80211_hdr *hdr = (void *)skb->data;
5860 int ac = ieee80211_ac_from_tid(tid);
5863 skb_reset_mac_header(skb);
5864 skb_set_queue_mapping(skb, ac);
5865 skb->priority = tid;
5867 skb->dev = sdata->dev;
5869 BUILD_BUG_ON(IEEE80211_LINK_UNSPECIFIED < IEEE80211_MLD_MAX_NUM_LINKS);
5870 BUILD_BUG_ON(!FIELD_FIT(IEEE80211_TX_CTRL_MLO_LINK,
5871 IEEE80211_LINK_UNSPECIFIED));
5873 if (!sdata->vif.valid_links) {
5875 } else if (link_id >= 0) {
5877 } else if (memcmp(sdata->vif.addr, hdr->addr2, ETH_ALEN) == 0) {
5878 /* address from the MLD */
5879 link = IEEE80211_LINK_UNSPECIFIED;
5881 /* otherwise must be addressed from a link */
5883 for (link = 0; link < ARRAY_SIZE(sdata->vif.link_conf); link++) {
5884 struct ieee80211_bss_conf *link_conf;
5886 link_conf = rcu_dereference(sdata->vif.link_conf[link]);
5889 if (memcmp(link_conf->addr, hdr->addr2, ETH_ALEN) == 0)
5894 if (WARN_ON_ONCE(link == ARRAY_SIZE(sdata->vif.link_conf)))
5895 link = ffs(sdata->vif.valid_links) - 1;
5898 IEEE80211_SKB_CB(skb)->control.flags |=
5899 u32_encode_bits(link, IEEE80211_TX_CTRL_MLO_LINK);
5902 * The other path calling ieee80211_xmit is from the tasklet,
5903 * and while we can handle concurrent transmissions locking
5904 * requirements are that we do not come into tx with bhs on.
5907 IEEE80211_SKB_CB(skb)->band = band;
5908 ieee80211_xmit(sdata, NULL, skb);
5912 void ieee80211_tx_skb_tid(struct ieee80211_sub_if_data *sdata,
5913 struct sk_buff *skb, int tid, int link_id)
5915 struct ieee80211_chanctx_conf *chanctx_conf;
5916 enum nl80211_band band;
5919 if (!sdata->vif.valid_links) {
5920 WARN_ON(link_id >= 0);
5922 rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
5923 if (WARN_ON(!chanctx_conf)) {
5928 band = chanctx_conf->def.chan->band;
5930 WARN_ON(link_id >= 0 &&
5931 !(sdata->vif.valid_links & BIT(link_id)));
5932 /* MLD transmissions must not rely on the band */
5936 __ieee80211_tx_skb_tid_band(sdata, skb, tid, link_id, band);
5940 int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev,
5941 const u8 *buf, size_t len,
5942 const u8 *dest, __be16 proto, bool unencrypted,
5943 int link_id, u64 *cookie)
5945 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5946 struct ieee80211_local *local = sdata->local;
5947 struct sta_info *sta;
5948 struct sk_buff *skb;
5949 struct ethhdr *ehdr;
5954 /* Only accept CONTROL_PORT_PROTOCOL configured in CONNECT/ASSOCIATE
5955 * or Pre-Authentication
5957 if (proto != sdata->control_port_protocol &&
5958 proto != cpu_to_be16(ETH_P_PREAUTH))
5961 if (proto == sdata->control_port_protocol)
5962 ctrl_flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO |
5963 IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP;
5966 flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
5969 ctrl_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
5971 flags |= IEEE80211_TX_INTFL_NL80211_FRAME_TX;
5973 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
5974 sizeof(struct ethhdr) + len);
5978 skb_reserve(skb, local->hw.extra_tx_headroom + sizeof(struct ethhdr));
5980 skb_put_data(skb, buf, len);
5982 ehdr = skb_push(skb, sizeof(struct ethhdr));
5983 memcpy(ehdr->h_dest, dest, ETH_ALEN);
5985 /* we may override the SA for MLO STA later */
5987 ctrl_flags |= u32_encode_bits(IEEE80211_LINK_UNSPECIFIED,
5988 IEEE80211_TX_CTRL_MLO_LINK);
5989 memcpy(ehdr->h_source, sdata->vif.addr, ETH_ALEN);
5991 struct ieee80211_bss_conf *link_conf;
5993 ctrl_flags |= u32_encode_bits(link_id,
5994 IEEE80211_TX_CTRL_MLO_LINK);
5997 link_conf = rcu_dereference(sdata->vif.link_conf[link_id]);
6003 memcpy(ehdr->h_source, link_conf->addr, ETH_ALEN);
6007 ehdr->h_proto = proto;
6010 skb->protocol = proto;
6011 skb_reset_network_header(skb);
6012 skb_reset_mac_header(skb);
6014 if (local->hw.queues < IEEE80211_NUM_ACS)
6017 /* update QoS header to prioritize control port frames if possible,
6018 * priorization also happens for control port frames send over
6022 err = ieee80211_lookup_ra_sta(sdata, skb, &sta);
6030 u16 queue = ieee80211_select_queue(sdata, sta, skb);
6032 skb_set_queue_mapping(skb, queue);
6035 * for MLO STA, the SA should be the AP MLD address, but
6036 * the link ID has been selected already
6038 if (sta && sta->sta.mlo)
6039 memcpy(ehdr->h_source, sdata->vif.addr, ETH_ALEN);
6044 /* mutex lock is only needed for incrementing the cookie counter */
6045 mutex_lock(&local->mtx);
6048 __ieee80211_subif_start_xmit(skb, skb->dev, flags, ctrl_flags, cookie);
6051 mutex_unlock(&local->mtx);
6056 int ieee80211_probe_mesh_link(struct wiphy *wiphy, struct net_device *dev,
6057 const u8 *buf, size_t len)
6059 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
6060 struct ieee80211_local *local = sdata->local;
6061 struct sk_buff *skb;
6063 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len +
6064 30 + /* header size */
6065 18); /* 11s header size */
6069 skb_reserve(skb, local->hw.extra_tx_headroom);
6070 skb_put_data(skb, buf, len);
6073 skb->protocol = htons(ETH_P_802_3);
6074 skb_reset_network_header(skb);
6075 skb_reset_mac_header(skb);
6078 __ieee80211_subif_start_xmit(skb, skb->dev, 0,
6079 IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP,