1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2002-2005, Instant802 Networks, Inc.
4 * Copyright 2005-2006, Devicescape Software, Inc.
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(tx->skb)) {
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;
1192 void ieee80211_aggr_check(struct ieee80211_sub_if_data *sdata,
1193 struct sta_info *sta, struct sk_buff *skb)
1195 struct rate_control_ref *ref = sdata->local->rate_ctrl;
1198 if (!ref || !(ref->ops->capa & RATE_CTRL_CAPA_AMPDU_TRIGGER))
1201 if (!sta || !sta->sta.deflink.ht_cap.ht_supported ||
1202 !sta->sta.wme || skb_get_queue_mapping(skb) == IEEE80211_AC_VO ||
1203 skb->protocol == sdata->control_port_protocol)
1206 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
1207 if (likely(sta->ampdu_mlme.tid_tx[tid]))
1210 ieee80211_start_tx_ba_session(&sta->sta, tid, 0);
1215 * pass %NULL for the station if unknown, a valid pointer if known
1216 * or an ERR_PTR() if the station is known not to exist
1218 static ieee80211_tx_result
1219 ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata,
1220 struct ieee80211_tx_data *tx,
1221 struct sta_info *sta, struct sk_buff *skb)
1223 struct ieee80211_local *local = sdata->local;
1224 struct ieee80211_hdr *hdr;
1225 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1226 bool aggr_check = false;
1229 memset(tx, 0, sizeof(*tx));
1233 __skb_queue_head_init(&tx->skbs);
1236 * If this flag is set to true anywhere, and we get here,
1237 * we are doing the needed processing, so remove the flag
1240 info->control.flags &= ~IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
1242 hdr = (struct ieee80211_hdr *) skb->data;
1248 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
1249 tx->sta = rcu_dereference(sdata->u.vlan.sta);
1250 if (!tx->sta && sdata->wdev.use_4addr)
1252 } else if (tx->sdata->control_port_protocol == tx->skb->protocol) {
1253 tx->sta = sta_info_get_bss(sdata, hdr->addr1);
1255 if (!tx->sta && !is_multicast_ether_addr(hdr->addr1)) {
1256 tx->sta = sta_info_get(sdata, hdr->addr1);
1261 if (tx->sta && ieee80211_is_data_qos(hdr->frame_control) &&
1262 !ieee80211_is_qos_nullfunc(hdr->frame_control) &&
1263 ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
1264 !ieee80211_hw_check(&local->hw, TX_AMPDU_SETUP_IN_HW)) {
1265 struct tid_ampdu_tx *tid_tx;
1267 tid = ieee80211_get_tid(hdr);
1268 tid_tx = rcu_dereference(tx->sta->ampdu_mlme.tid_tx[tid]);
1269 if (!tid_tx && aggr_check) {
1270 ieee80211_aggr_check(sdata, tx->sta, skb);
1271 tid_tx = rcu_dereference(tx->sta->ampdu_mlme.tid_tx[tid]);
1277 queued = ieee80211_tx_prep_agg(tx, skb, info,
1280 if (unlikely(queued))
1285 if (is_multicast_ether_addr(hdr->addr1)) {
1286 tx->flags &= ~IEEE80211_TX_UNICAST;
1287 info->flags |= IEEE80211_TX_CTL_NO_ACK;
1289 tx->flags |= IEEE80211_TX_UNICAST;
1291 if (!(info->flags & IEEE80211_TX_CTL_DONTFRAG)) {
1292 if (!(tx->flags & IEEE80211_TX_UNICAST) ||
1293 skb->len + FCS_LEN <= local->hw.wiphy->frag_threshold ||
1294 info->flags & IEEE80211_TX_CTL_AMPDU)
1295 info->flags |= IEEE80211_TX_CTL_DONTFRAG;
1299 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
1300 else if (test_and_clear_sta_flag(tx->sta, WLAN_STA_CLEAR_PS_FILT)) {
1301 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
1302 ieee80211_check_fast_xmit(tx->sta);
1305 info->flags |= IEEE80211_TX_CTL_FIRST_FRAGMENT;
1310 static struct txq_info *ieee80211_get_txq(struct ieee80211_local *local,
1311 struct ieee80211_vif *vif,
1312 struct sta_info *sta,
1313 struct sk_buff *skb)
1315 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1316 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1317 struct ieee80211_txq *txq = NULL;
1319 if ((info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) ||
1320 (info->control.flags & IEEE80211_TX_CTRL_PS_RESPONSE))
1323 if (!(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) &&
1324 unlikely(!ieee80211_is_data_present(hdr->frame_control))) {
1325 if ((!ieee80211_is_mgmt(hdr->frame_control) ||
1326 ieee80211_is_bufferable_mmpdu(skb) ||
1327 vif->type == NL80211_IFTYPE_STATION) &&
1328 sta && sta->uploaded) {
1330 * This will be NULL if the driver didn't set the
1331 * opt-in hardware flag.
1333 txq = sta->sta.txq[IEEE80211_NUM_TIDS];
1336 u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
1341 txq = sta->sta.txq[tid];
1349 return to_txq_info(txq);
1352 static void ieee80211_set_skb_enqueue_time(struct sk_buff *skb)
1354 struct sk_buff *next;
1355 codel_time_t now = codel_get_time();
1357 skb_list_walk_safe(skb, skb, next)
1358 IEEE80211_SKB_CB(skb)->control.enqueue_time = now;
1361 static u32 codel_skb_len_func(const struct sk_buff *skb)
1366 static codel_time_t codel_skb_time_func(const struct sk_buff *skb)
1368 const struct ieee80211_tx_info *info;
1370 info = (const struct ieee80211_tx_info *)skb->cb;
1371 return info->control.enqueue_time;
1374 static struct sk_buff *codel_dequeue_func(struct codel_vars *cvars,
1377 struct ieee80211_local *local;
1378 struct txq_info *txqi;
1380 struct fq_flow *flow;
1383 local = vif_to_sdata(txqi->txq.vif)->local;
1386 if (cvars == &txqi->def_cvars)
1387 flow = &txqi->tin.default_flow;
1389 flow = &fq->flows[cvars - local->cvars];
1391 return fq_flow_dequeue(fq, flow);
1394 static void codel_drop_func(struct sk_buff *skb,
1397 struct ieee80211_local *local;
1398 struct ieee80211_hw *hw;
1399 struct txq_info *txqi;
1402 local = vif_to_sdata(txqi->txq.vif)->local;
1405 ieee80211_free_txskb(hw, skb);
1408 static struct sk_buff *fq_tin_dequeue_func(struct fq *fq,
1410 struct fq_flow *flow)
1412 struct ieee80211_local *local;
1413 struct txq_info *txqi;
1414 struct codel_vars *cvars;
1415 struct codel_params *cparams;
1416 struct codel_stats *cstats;
1418 local = container_of(fq, struct ieee80211_local, fq);
1419 txqi = container_of(tin, struct txq_info, tin);
1420 cstats = &txqi->cstats;
1422 if (txqi->txq.sta) {
1423 struct sta_info *sta = container_of(txqi->txq.sta,
1424 struct sta_info, sta);
1425 cparams = &sta->cparams;
1427 cparams = &local->cparams;
1430 if (flow == &tin->default_flow)
1431 cvars = &txqi->def_cvars;
1433 cvars = &local->cvars[flow - fq->flows];
1435 return codel_dequeue(txqi,
1441 codel_skb_time_func,
1443 codel_dequeue_func);
1446 static void fq_skb_free_func(struct fq *fq,
1448 struct fq_flow *flow,
1449 struct sk_buff *skb)
1451 struct ieee80211_local *local;
1453 local = container_of(fq, struct ieee80211_local, fq);
1454 ieee80211_free_txskb(&local->hw, skb);
1457 static void ieee80211_txq_enqueue(struct ieee80211_local *local,
1458 struct txq_info *txqi,
1459 struct sk_buff *skb)
1461 struct fq *fq = &local->fq;
1462 struct fq_tin *tin = &txqi->tin;
1463 u32 flow_idx = fq_flow_idx(fq, skb);
1465 ieee80211_set_skb_enqueue_time(skb);
1467 spin_lock_bh(&fq->lock);
1469 * For management frames, don't really apply codel etc.,
1470 * we don't want to apply any shaping or anything we just
1471 * want to simplify the driver API by having them on the
1474 if (unlikely(txqi->txq.tid == IEEE80211_NUM_TIDS)) {
1475 IEEE80211_SKB_CB(skb)->control.flags |=
1476 IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
1477 __skb_queue_tail(&txqi->frags, skb);
1479 fq_tin_enqueue(fq, tin, flow_idx, skb,
1482 spin_unlock_bh(&fq->lock);
1485 static bool fq_vlan_filter_func(struct fq *fq, struct fq_tin *tin,
1486 struct fq_flow *flow, struct sk_buff *skb,
1489 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1491 return info->control.vif == data;
1494 void ieee80211_txq_remove_vlan(struct ieee80211_local *local,
1495 struct ieee80211_sub_if_data *sdata)
1497 struct fq *fq = &local->fq;
1498 struct txq_info *txqi;
1500 struct ieee80211_sub_if_data *ap;
1502 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_AP_VLAN))
1505 ap = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap);
1510 txqi = to_txq_info(ap->vif.txq);
1513 spin_lock_bh(&fq->lock);
1514 fq_tin_filter(fq, tin, fq_vlan_filter_func, &sdata->vif,
1516 spin_unlock_bh(&fq->lock);
1519 void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata,
1520 struct sta_info *sta,
1521 struct txq_info *txqi, int tid)
1523 fq_tin_init(&txqi->tin);
1524 codel_vars_init(&txqi->def_cvars);
1525 codel_stats_init(&txqi->cstats);
1526 __skb_queue_head_init(&txqi->frags);
1527 INIT_LIST_HEAD(&txqi->schedule_order);
1529 txqi->txq.vif = &sdata->vif;
1532 sdata->vif.txq = &txqi->txq;
1534 txqi->txq.ac = IEEE80211_AC_BE;
1539 if (tid == IEEE80211_NUM_TIDS) {
1540 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
1541 /* Drivers need to opt in to the management MPDU TXQ */
1542 if (!ieee80211_hw_check(&sdata->local->hw,
1545 } else if (!ieee80211_hw_check(&sdata->local->hw,
1547 /* Drivers need to opt in to the bufferable MMPDU TXQ */
1550 txqi->txq.ac = IEEE80211_AC_VO;
1552 txqi->txq.ac = ieee80211_ac_from_tid(tid);
1555 txqi->txq.sta = &sta->sta;
1556 txqi->txq.tid = tid;
1557 sta->sta.txq[tid] = &txqi->txq;
1560 void ieee80211_txq_purge(struct ieee80211_local *local,
1561 struct txq_info *txqi)
1563 struct fq *fq = &local->fq;
1564 struct fq_tin *tin = &txqi->tin;
1566 spin_lock_bh(&fq->lock);
1567 fq_tin_reset(fq, tin, fq_skb_free_func);
1568 ieee80211_purge_tx_queue(&local->hw, &txqi->frags);
1569 spin_unlock_bh(&fq->lock);
1571 spin_lock_bh(&local->active_txq_lock[txqi->txq.ac]);
1572 list_del_init(&txqi->schedule_order);
1573 spin_unlock_bh(&local->active_txq_lock[txqi->txq.ac]);
1576 void ieee80211_txq_set_params(struct ieee80211_local *local)
1578 if (local->hw.wiphy->txq_limit)
1579 local->fq.limit = local->hw.wiphy->txq_limit;
1581 local->hw.wiphy->txq_limit = local->fq.limit;
1583 if (local->hw.wiphy->txq_memory_limit)
1584 local->fq.memory_limit = local->hw.wiphy->txq_memory_limit;
1586 local->hw.wiphy->txq_memory_limit = local->fq.memory_limit;
1588 if (local->hw.wiphy->txq_quantum)
1589 local->fq.quantum = local->hw.wiphy->txq_quantum;
1591 local->hw.wiphy->txq_quantum = local->fq.quantum;
1594 int ieee80211_txq_setup_flows(struct ieee80211_local *local)
1596 struct fq *fq = &local->fq;
1599 bool supp_vht = false;
1600 enum nl80211_band band;
1602 ret = fq_init(fq, 4096);
1607 * If the hardware doesn't support VHT, it is safe to limit the maximum
1608 * queue size. 4 Mbytes is 64 max-size aggregates in 802.11n.
1610 for (band = 0; band < NUM_NL80211_BANDS; band++) {
1611 struct ieee80211_supported_band *sband;
1613 sband = local->hw.wiphy->bands[band];
1617 supp_vht = supp_vht || sband->vht_cap.vht_supported;
1621 fq->memory_limit = 4 << 20; /* 4 Mbytes */
1623 codel_params_init(&local->cparams);
1624 local->cparams.interval = MS2TIME(100);
1625 local->cparams.target = MS2TIME(20);
1626 local->cparams.ecn = true;
1628 local->cvars = kcalloc(fq->flows_cnt, sizeof(local->cvars[0]),
1630 if (!local->cvars) {
1631 spin_lock_bh(&fq->lock);
1632 fq_reset(fq, fq_skb_free_func);
1633 spin_unlock_bh(&fq->lock);
1637 for (i = 0; i < fq->flows_cnt; i++)
1638 codel_vars_init(&local->cvars[i]);
1640 ieee80211_txq_set_params(local);
1645 void ieee80211_txq_teardown_flows(struct ieee80211_local *local)
1647 struct fq *fq = &local->fq;
1649 kfree(local->cvars);
1650 local->cvars = NULL;
1652 spin_lock_bh(&fq->lock);
1653 fq_reset(fq, fq_skb_free_func);
1654 spin_unlock_bh(&fq->lock);
1657 static bool ieee80211_queue_skb(struct ieee80211_local *local,
1658 struct ieee80211_sub_if_data *sdata,
1659 struct sta_info *sta,
1660 struct sk_buff *skb)
1662 struct ieee80211_vif *vif;
1663 struct txq_info *txqi;
1665 if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
1668 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1669 sdata = container_of(sdata->bss,
1670 struct ieee80211_sub_if_data, u.ap);
1673 txqi = ieee80211_get_txq(local, vif, sta, skb);
1678 ieee80211_txq_enqueue(local, txqi, skb);
1680 schedule_and_wake_txq(local, txqi);
1685 static bool ieee80211_tx_frags(struct ieee80211_local *local,
1686 struct ieee80211_vif *vif,
1687 struct sta_info *sta,
1688 struct sk_buff_head *skbs,
1691 struct ieee80211_tx_control control = {};
1692 struct sk_buff *skb, *tmp;
1693 unsigned long flags;
1695 skb_queue_walk_safe(skbs, skb, tmp) {
1696 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1697 int q = info->hw_queue;
1699 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1700 if (WARN_ON_ONCE(q >= local->hw.queues)) {
1701 __skb_unlink(skb, skbs);
1702 ieee80211_free_txskb(&local->hw, skb);
1707 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1708 if (local->queue_stop_reasons[q] ||
1709 (!txpending && !skb_queue_empty(&local->pending[q]))) {
1710 if (unlikely(info->flags &
1711 IEEE80211_TX_INTFL_OFFCHAN_TX_OK)) {
1712 if (local->queue_stop_reasons[q] &
1713 ~BIT(IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL)) {
1715 * Drop off-channel frames if queues
1716 * are stopped for any reason other
1717 * than off-channel operation. Never
1720 spin_unlock_irqrestore(
1721 &local->queue_stop_reason_lock,
1723 ieee80211_purge_tx_queue(&local->hw,
1730 * Since queue is stopped, queue up frames for
1731 * later transmission from the tx-pending
1732 * tasklet when the queue is woken again.
1735 skb_queue_splice_init(skbs,
1736 &local->pending[q]);
1738 skb_queue_splice_tail_init(skbs,
1739 &local->pending[q]);
1741 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1746 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1748 info->control.vif = vif;
1749 control.sta = sta ? &sta->sta : NULL;
1751 __skb_unlink(skb, skbs);
1752 drv_tx(local, &control, skb);
1759 * Returns false if the frame couldn't be transmitted but was queued instead.
1761 static bool __ieee80211_tx(struct ieee80211_local *local,
1762 struct sk_buff_head *skbs, struct sta_info *sta,
1765 struct ieee80211_tx_info *info;
1766 struct ieee80211_sub_if_data *sdata;
1767 struct ieee80211_vif *vif;
1768 struct sk_buff *skb;
1771 if (WARN_ON(skb_queue_empty(skbs)))
1774 skb = skb_peek(skbs);
1775 info = IEEE80211_SKB_CB(skb);
1776 sdata = vif_to_sdata(info->control.vif);
1777 if (sta && !sta->uploaded)
1780 switch (sdata->vif.type) {
1781 case NL80211_IFTYPE_MONITOR:
1782 if (sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) {
1786 sdata = rcu_dereference(local->monitor_sdata);
1790 vif->hw_queue[skb_get_queue_mapping(skb)];
1791 } else if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) {
1792 ieee80211_purge_tx_queue(&local->hw, skbs);
1797 case NL80211_IFTYPE_AP_VLAN:
1798 sdata = container_of(sdata->bss,
1799 struct ieee80211_sub_if_data, u.ap);
1806 result = ieee80211_tx_frags(local, vif, sta, skbs, txpending);
1808 WARN_ON_ONCE(!skb_queue_empty(skbs));
1814 * Invoke TX handlers, return 0 on success and non-zero if the
1815 * frame was dropped or queued.
1817 * The handlers are split into an early and late part. The latter is everything
1818 * that can be sensitive to reordering, and will be deferred to after packets
1819 * are dequeued from the intermediate queues (when they are enabled).
1821 static int invoke_tx_handlers_early(struct ieee80211_tx_data *tx)
1823 ieee80211_tx_result res = TX_DROP;
1825 #define CALL_TXH(txh) \
1828 if (res != TX_CONTINUE) \
1832 CALL_TXH(ieee80211_tx_h_dynamic_ps);
1833 CALL_TXH(ieee80211_tx_h_check_assoc);
1834 CALL_TXH(ieee80211_tx_h_ps_buf);
1835 CALL_TXH(ieee80211_tx_h_check_control_port_protocol);
1836 CALL_TXH(ieee80211_tx_h_select_key);
1839 if (unlikely(res == TX_DROP)) {
1840 I802_DEBUG_INC(tx->local->tx_handlers_drop);
1842 ieee80211_free_txskb(&tx->local->hw, tx->skb);
1844 ieee80211_purge_tx_queue(&tx->local->hw, &tx->skbs);
1846 } else if (unlikely(res == TX_QUEUED)) {
1847 I802_DEBUG_INC(tx->local->tx_handlers_queued);
1855 * Late handlers can be called while the sta lock is held. Handlers that can
1856 * cause packets to be generated will cause deadlock!
1858 static int invoke_tx_handlers_late(struct ieee80211_tx_data *tx)
1860 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
1861 ieee80211_tx_result res = TX_CONTINUE;
1863 if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL))
1864 CALL_TXH(ieee80211_tx_h_rate_ctrl);
1866 if (unlikely(info->flags & IEEE80211_TX_INTFL_RETRANSMISSION)) {
1867 __skb_queue_tail(&tx->skbs, tx->skb);
1872 CALL_TXH(ieee80211_tx_h_michael_mic_add);
1873 CALL_TXH(ieee80211_tx_h_sequence);
1874 CALL_TXH(ieee80211_tx_h_fragment);
1875 /* handlers after fragment must be aware of tx info fragmentation! */
1876 CALL_TXH(ieee80211_tx_h_stats);
1877 CALL_TXH(ieee80211_tx_h_encrypt);
1878 if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL))
1879 CALL_TXH(ieee80211_tx_h_calculate_duration);
1883 if (unlikely(res == TX_DROP)) {
1884 I802_DEBUG_INC(tx->local->tx_handlers_drop);
1886 ieee80211_free_txskb(&tx->local->hw, tx->skb);
1888 ieee80211_purge_tx_queue(&tx->local->hw, &tx->skbs);
1890 } else if (unlikely(res == TX_QUEUED)) {
1891 I802_DEBUG_INC(tx->local->tx_handlers_queued);
1898 static int invoke_tx_handlers(struct ieee80211_tx_data *tx)
1900 int r = invoke_tx_handlers_early(tx);
1904 return invoke_tx_handlers_late(tx);
1907 bool ieee80211_tx_prepare_skb(struct ieee80211_hw *hw,
1908 struct ieee80211_vif *vif, struct sk_buff *skb,
1909 int band, struct ieee80211_sta **sta)
1911 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1912 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1913 struct ieee80211_tx_data tx;
1914 struct sk_buff *skb2;
1916 if (ieee80211_tx_prepare(sdata, &tx, NULL, skb) == TX_DROP)
1920 info->control.vif = vif;
1921 info->hw_queue = vif->hw_queue[skb_get_queue_mapping(skb)];
1923 if (invoke_tx_handlers(&tx))
1928 *sta = &tx.sta->sta;
1933 /* this function isn't suitable for fragmented data frames */
1934 skb2 = __skb_dequeue(&tx.skbs);
1935 if (WARN_ON(skb2 != skb || !skb_queue_empty(&tx.skbs))) {
1936 ieee80211_free_txskb(hw, skb2);
1937 ieee80211_purge_tx_queue(hw, &tx.skbs);
1943 EXPORT_SYMBOL(ieee80211_tx_prepare_skb);
1946 * Returns false if the frame couldn't be transmitted but was queued instead.
1948 static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata,
1949 struct sta_info *sta, struct sk_buff *skb,
1952 struct ieee80211_local *local = sdata->local;
1953 struct ieee80211_tx_data tx;
1954 ieee80211_tx_result res_prepare;
1955 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1958 if (unlikely(skb->len < 10)) {
1963 /* initialises tx */
1964 res_prepare = ieee80211_tx_prepare(sdata, &tx, sta, skb);
1966 if (unlikely(res_prepare == TX_DROP)) {
1967 ieee80211_free_txskb(&local->hw, skb);
1969 } else if (unlikely(res_prepare == TX_QUEUED)) {
1973 /* set up hw_queue value early */
1974 if (!(info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) ||
1975 !ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
1977 sdata->vif.hw_queue[skb_get_queue_mapping(skb)];
1979 if (invoke_tx_handlers_early(&tx))
1982 if (ieee80211_queue_skb(local, sdata, tx.sta, tx.skb))
1985 if (!invoke_tx_handlers_late(&tx))
1986 result = __ieee80211_tx(local, &tx.skbs, tx.sta, txpending);
1991 /* device xmit handlers */
1993 enum ieee80211_encrypt {
1999 static int ieee80211_skb_resize(struct ieee80211_sub_if_data *sdata,
2000 struct sk_buff *skb,
2002 enum ieee80211_encrypt encrypt)
2004 struct ieee80211_local *local = sdata->local;
2008 enc_tailroom = encrypt == ENCRYPT_MGMT ||
2009 (encrypt == ENCRYPT_DATA &&
2010 sdata->crypto_tx_tailroom_needed_cnt);
2013 tail_need = IEEE80211_ENCRYPT_TAILROOM;
2014 tail_need -= skb_tailroom(skb);
2015 tail_need = max_t(int, tail_need, 0);
2018 if (skb_cloned(skb) &&
2019 (!ieee80211_hw_check(&local->hw, SUPPORTS_CLONED_SKBS) ||
2020 !skb_clone_writable(skb, ETH_HLEN) || enc_tailroom))
2021 I802_DEBUG_INC(local->tx_expand_skb_head_cloned);
2022 else if (head_need || tail_need)
2023 I802_DEBUG_INC(local->tx_expand_skb_head);
2027 if (pskb_expand_head(skb, head_need, tail_need, GFP_ATOMIC)) {
2028 wiphy_debug(local->hw.wiphy,
2029 "failed to reallocate TX buffer\n");
2036 void ieee80211_xmit(struct ieee80211_sub_if_data *sdata,
2037 struct sta_info *sta, struct sk_buff *skb)
2039 struct ieee80211_local *local = sdata->local;
2040 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2041 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2043 enum ieee80211_encrypt encrypt;
2045 if (info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)
2046 encrypt = ENCRYPT_NO;
2047 else if (ieee80211_is_mgmt(hdr->frame_control))
2048 encrypt = ENCRYPT_MGMT;
2050 encrypt = ENCRYPT_DATA;
2052 headroom = local->tx_headroom;
2053 if (encrypt != ENCRYPT_NO)
2054 headroom += IEEE80211_ENCRYPT_HEADROOM;
2055 headroom -= skb_headroom(skb);
2056 headroom = max_t(int, 0, headroom);
2058 if (ieee80211_skb_resize(sdata, skb, headroom, encrypt)) {
2059 ieee80211_free_txskb(&local->hw, skb);
2063 /* reload after potential resize */
2064 hdr = (struct ieee80211_hdr *) skb->data;
2065 info->control.vif = &sdata->vif;
2067 if (ieee80211_vif_is_mesh(&sdata->vif)) {
2068 if (ieee80211_is_data(hdr->frame_control) &&
2069 is_unicast_ether_addr(hdr->addr1)) {
2070 if (mesh_nexthop_resolve(sdata, skb))
2071 return; /* skb queued: don't free */
2073 ieee80211_mps_set_frame_flags(sdata, NULL, hdr);
2077 ieee80211_set_qos_hdr(sdata, skb);
2078 ieee80211_tx(sdata, sta, skb, false);
2081 static bool ieee80211_validate_radiotap_len(struct sk_buff *skb)
2083 struct ieee80211_radiotap_header *rthdr =
2084 (struct ieee80211_radiotap_header *)skb->data;
2086 /* check for not even having the fixed radiotap header part */
2087 if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
2088 return false; /* too short to be possibly valid */
2090 /* is it a header version we can trust to find length from? */
2091 if (unlikely(rthdr->it_version))
2092 return false; /* only version 0 is supported */
2094 /* does the skb contain enough to deliver on the alleged length? */
2095 if (unlikely(skb->len < ieee80211_get_radiotap_len(skb->data)))
2096 return false; /* skb too short for claimed rt header extent */
2101 bool ieee80211_parse_tx_radiotap(struct sk_buff *skb,
2102 struct net_device *dev)
2104 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2105 struct ieee80211_radiotap_iterator iterator;
2106 struct ieee80211_radiotap_header *rthdr =
2107 (struct ieee80211_radiotap_header *) skb->data;
2108 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2109 int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len,
2113 bool rate_found = false;
2114 u8 rate_retries = 0;
2116 u8 mcs_known, mcs_flags, mcs_bw;
2118 u8 vht_mcs = 0, vht_nss = 0;
2121 if (!ieee80211_validate_radiotap_len(skb))
2124 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
2125 IEEE80211_TX_CTL_DONTFRAG;
2128 * for every radiotap entry that is present
2129 * (ieee80211_radiotap_iterator_next returns -ENOENT when no more
2130 * entries present, or -EINVAL on error)
2134 ret = ieee80211_radiotap_iterator_next(&iterator);
2139 /* see if this argument is something we can use */
2140 switch (iterator.this_arg_index) {
2142 * You must take care when dereferencing iterator.this_arg
2143 * for multibyte types... the pointer is not aligned. Use
2144 * get_unaligned((type *)iterator.this_arg) to dereference
2145 * iterator.this_arg for type "type" safely on all arches.
2147 case IEEE80211_RADIOTAP_FLAGS:
2148 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) {
2150 * this indicates that the skb we have been
2151 * handed has the 32-bit FCS CRC at the end...
2152 * we should react to that by snipping it off
2153 * because it will be recomputed and added
2156 if (skb->len < (iterator._max_length + FCS_LEN))
2159 skb_trim(skb, skb->len - FCS_LEN);
2161 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_WEP)
2162 info->flags &= ~IEEE80211_TX_INTFL_DONT_ENCRYPT;
2163 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG)
2164 info->flags &= ~IEEE80211_TX_CTL_DONTFRAG;
2167 case IEEE80211_RADIOTAP_TX_FLAGS:
2168 txflags = get_unaligned_le16(iterator.this_arg);
2169 if (txflags & IEEE80211_RADIOTAP_F_TX_NOACK)
2170 info->flags |= IEEE80211_TX_CTL_NO_ACK;
2171 if (txflags & IEEE80211_RADIOTAP_F_TX_NOSEQNO)
2172 info->control.flags |= IEEE80211_TX_CTRL_NO_SEQNO;
2173 if (txflags & IEEE80211_RADIOTAP_F_TX_ORDER)
2174 info->control.flags |=
2175 IEEE80211_TX_CTRL_DONT_REORDER;
2178 case IEEE80211_RADIOTAP_RATE:
2179 rate = *iterator.this_arg;
2184 case IEEE80211_RADIOTAP_DATA_RETRIES:
2185 rate_retries = *iterator.this_arg;
2188 case IEEE80211_RADIOTAP_MCS:
2189 mcs_known = iterator.this_arg[0];
2190 mcs_flags = iterator.this_arg[1];
2191 if (!(mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_MCS))
2195 rate = iterator.this_arg[2];
2196 rate_flags = IEEE80211_TX_RC_MCS;
2198 if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_GI &&
2199 mcs_flags & IEEE80211_RADIOTAP_MCS_SGI)
2200 rate_flags |= IEEE80211_TX_RC_SHORT_GI;
2202 mcs_bw = mcs_flags & IEEE80211_RADIOTAP_MCS_BW_MASK;
2203 if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_BW &&
2204 mcs_bw == IEEE80211_RADIOTAP_MCS_BW_40)
2205 rate_flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
2207 if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_FEC &&
2208 mcs_flags & IEEE80211_RADIOTAP_MCS_FEC_LDPC)
2209 info->flags |= IEEE80211_TX_CTL_LDPC;
2211 if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_STBC) {
2212 u8 stbc = u8_get_bits(mcs_flags,
2213 IEEE80211_RADIOTAP_MCS_STBC_MASK);
2216 u32_encode_bits(stbc,
2217 IEEE80211_TX_CTL_STBC);
2221 case IEEE80211_RADIOTAP_VHT:
2222 vht_known = get_unaligned_le16(iterator.this_arg);
2225 rate_flags = IEEE80211_TX_RC_VHT_MCS;
2226 if ((vht_known & IEEE80211_RADIOTAP_VHT_KNOWN_GI) &&
2227 (iterator.this_arg[2] &
2228 IEEE80211_RADIOTAP_VHT_FLAG_SGI))
2229 rate_flags |= IEEE80211_TX_RC_SHORT_GI;
2231 IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH) {
2232 if (iterator.this_arg[3] == 1)
2234 IEEE80211_TX_RC_40_MHZ_WIDTH;
2235 else if (iterator.this_arg[3] == 4)
2237 IEEE80211_TX_RC_80_MHZ_WIDTH;
2238 else if (iterator.this_arg[3] == 11)
2240 IEEE80211_TX_RC_160_MHZ_WIDTH;
2243 vht_mcs = iterator.this_arg[4] >> 4;
2246 vht_nss = iterator.this_arg[4] & 0xF;
2247 if (!vht_nss || vht_nss > 8)
2252 * Please update the file
2253 * Documentation/networking/mac80211-injection.rst
2254 * when parsing new fields here.
2262 if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */
2266 struct ieee80211_supported_band *sband =
2267 local->hw.wiphy->bands[info->band];
2269 info->control.flags |= IEEE80211_TX_CTRL_RATE_INJECT;
2271 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
2272 info->control.rates[i].idx = -1;
2273 info->control.rates[i].flags = 0;
2274 info->control.rates[i].count = 0;
2277 if (rate_flags & IEEE80211_TX_RC_MCS) {
2278 info->control.rates[0].idx = rate;
2279 } else if (rate_flags & IEEE80211_TX_RC_VHT_MCS) {
2280 ieee80211_rate_set_vht(info->control.rates, vht_mcs,
2283 for (i = 0; i < sband->n_bitrates; i++) {
2284 if (rate * 5 != sband->bitrates[i].bitrate)
2287 info->control.rates[0].idx = i;
2292 if (info->control.rates[0].idx < 0)
2293 info->control.flags &= ~IEEE80211_TX_CTRL_RATE_INJECT;
2295 info->control.rates[0].flags = rate_flags;
2296 info->control.rates[0].count = min_t(u8, rate_retries + 1,
2297 local->hw.max_rate_tries);
2303 netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
2304 struct net_device *dev)
2306 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2307 struct ieee80211_chanctx_conf *chanctx_conf;
2308 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2309 struct ieee80211_hdr *hdr;
2310 struct ieee80211_sub_if_data *tmp_sdata, *sdata;
2311 struct cfg80211_chan_def *chandef;
2315 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2316 if (unlikely(!ieee80211_sdata_running(sdata)))
2319 memset(info, 0, sizeof(*info));
2320 info->flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2321 IEEE80211_TX_CTL_INJECTED;
2323 /* Sanity-check the length of the radiotap header */
2324 if (!ieee80211_validate_radiotap_len(skb))
2327 /* we now know there is a radiotap header with a length we can use */
2328 len_rthdr = ieee80211_get_radiotap_len(skb->data);
2331 * fix up the pointers accounting for the radiotap
2332 * header still being in there. We are being given
2333 * a precooked IEEE80211 header so no need for
2336 skb_set_mac_header(skb, len_rthdr);
2338 * these are just fixed to the end of the rt area since we
2339 * don't have any better information and at this point, nobody cares
2341 skb_set_network_header(skb, len_rthdr);
2342 skb_set_transport_header(skb, len_rthdr);
2344 if (skb->len < len_rthdr + 2)
2347 hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
2348 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2350 if (skb->len < len_rthdr + hdrlen)
2354 * Initialize skb->protocol if the injected frame is a data frame
2355 * carrying a rfc1042 header
2357 if (ieee80211_is_data(hdr->frame_control) &&
2358 skb->len >= len_rthdr + hdrlen + sizeof(rfc1042_header) + 2) {
2359 u8 *payload = (u8 *)hdr + hdrlen;
2361 if (ether_addr_equal(payload, rfc1042_header))
2362 skb->protocol = cpu_to_be16((payload[6] << 8) |
2369 * We process outgoing injected frames that have a local address
2370 * we handle as though they are non-injected frames.
2371 * This code here isn't entirely correct, the local MAC address
2372 * isn't always enough to find the interface to use; for proper
2373 * VLAN support we have an nl80211-based mechanism.
2375 * This is necessary, for example, for old hostapd versions that
2376 * don't use nl80211-based management TX/RX.
2378 list_for_each_entry_rcu(tmp_sdata, &local->interfaces, list) {
2379 if (!ieee80211_sdata_running(tmp_sdata))
2381 if (tmp_sdata->vif.type == NL80211_IFTYPE_MONITOR ||
2382 tmp_sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
2384 if (ether_addr_equal(tmp_sdata->vif.addr, hdr->addr2)) {
2390 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
2391 if (!chanctx_conf) {
2392 tmp_sdata = rcu_dereference(local->monitor_sdata);
2395 rcu_dereference(tmp_sdata->vif.bss_conf.chanctx_conf);
2399 chandef = &chanctx_conf->def;
2400 else if (!local->use_chanctx)
2401 chandef = &local->_oper_chandef;
2406 * Frame injection is not allowed if beaconing is not allowed
2407 * or if we need radar detection. Beaconing is usually not allowed when
2408 * the mode or operation (Adhoc, AP, Mesh) does not support DFS.
2409 * Passive scan is also used in world regulatory domains where
2410 * your country is not known and as such it should be treated as
2411 * NO TX unless the channel is explicitly allowed in which case
2412 * your current regulatory domain would not have the passive scan
2415 * Since AP mode uses monitor interfaces to inject/TX management
2416 * frames we can make AP mode the exception to this rule once it
2417 * supports radar detection as its implementation can deal with
2418 * radar detection by itself. We can do that later by adding a
2419 * monitor flag interfaces used for AP support.
2421 if (!cfg80211_reg_can_beacon(local->hw.wiphy, chandef,
2425 info->band = chandef->chan->band;
2427 /* Initialize skb->priority according to frame type and TID class,
2428 * with respect to the sub interface that the frame will actually
2429 * be transmitted on. If the DONT_REORDER flag is set, the original
2430 * skb-priority is preserved to assure frames injected with this
2431 * flag are not reordered relative to each other.
2433 ieee80211_select_queue_80211(sdata, skb, hdr);
2434 skb_set_queue_mapping(skb, ieee80211_ac_from_tid(skb->priority));
2437 * Process the radiotap header. This will now take into account the
2438 * selected chandef above to accurately set injection rates and
2441 if (!ieee80211_parse_tx_radiotap(skb, dev))
2444 /* remove the injection radiotap header */
2445 skb_pull(skb, len_rthdr);
2447 ieee80211_xmit(sdata, NULL, skb);
2450 return NETDEV_TX_OK;
2456 return NETDEV_TX_OK; /* meaning, we dealt with the skb */
2459 static inline bool ieee80211_is_tdls_setup(struct sk_buff *skb)
2461 u16 ethertype = (skb->data[12] << 8) | skb->data[13];
2463 return ethertype == ETH_P_TDLS &&
2465 skb->data[14] == WLAN_TDLS_SNAP_RFTYPE;
2468 int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata,
2469 struct sk_buff *skb,
2470 struct sta_info **sta_out)
2472 struct sta_info *sta;
2474 switch (sdata->vif.type) {
2475 case NL80211_IFTYPE_AP_VLAN:
2476 sta = rcu_dereference(sdata->u.vlan.sta);
2480 } else if (sdata->wdev.use_4addr) {
2484 case NL80211_IFTYPE_AP:
2485 case NL80211_IFTYPE_OCB:
2486 case NL80211_IFTYPE_ADHOC:
2487 if (is_multicast_ether_addr(skb->data)) {
2488 *sta_out = ERR_PTR(-ENOENT);
2491 sta = sta_info_get_bss(sdata, skb->data);
2493 #ifdef CONFIG_MAC80211_MESH
2494 case NL80211_IFTYPE_MESH_POINT:
2495 /* determined much later */
2499 case NL80211_IFTYPE_STATION:
2500 if (sdata->wdev.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) {
2501 sta = sta_info_get(sdata, skb->data);
2502 if (sta && test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
2503 if (test_sta_flag(sta,
2504 WLAN_STA_TDLS_PEER_AUTH)) {
2510 * TDLS link during setup - throw out frames to
2511 * peer. Allow TDLS-setup frames to unauthorized
2512 * peers for the special case of a link teardown
2513 * after a TDLS sta is removed due to being
2516 if (!ieee80211_is_tdls_setup(skb))
2522 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
2530 *sta_out = sta ?: ERR_PTR(-ENOENT);
2534 static u16 ieee80211_store_ack_skb(struct ieee80211_local *local,
2535 struct sk_buff *skb,
2539 struct sk_buff *ack_skb;
2543 ack_skb = skb_clone_sk(skb);
2545 ack_skb = skb_clone(skb, GFP_ATOMIC);
2548 unsigned long flags;
2551 spin_lock_irqsave(&local->ack_status_lock, flags);
2552 id = idr_alloc(&local->ack_status_frames, ack_skb,
2553 1, 0x2000, GFP_ATOMIC);
2554 spin_unlock_irqrestore(&local->ack_status_lock, flags);
2558 *info_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
2560 *cookie = ieee80211_mgmt_tx_cookie(local);
2561 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
2572 * ieee80211_build_hdr - build 802.11 header in the given frame
2573 * @sdata: virtual interface to build the header for
2574 * @skb: the skb to build the header in
2575 * @info_flags: skb flags to set
2576 * @sta: the station pointer
2577 * @ctrl_flags: info control flags to set
2578 * @cookie: cookie pointer to fill (if not %NULL)
2580 * This function takes the skb with 802.3 header and reformats the header to
2581 * the appropriate IEEE 802.11 header based on which interface the packet is
2582 * being transmitted on.
2584 * Note that this function also takes care of the TX status request and
2585 * potential unsharing of the SKB - this needs to be interleaved with the
2588 * The function requires the read-side RCU lock held
2590 * Returns: the (possibly reallocated) skb or an ERR_PTR() code
2592 static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata,
2593 struct sk_buff *skb, u32 info_flags,
2594 struct sta_info *sta, u32 ctrl_flags,
2597 struct ieee80211_local *local = sdata->local;
2598 struct ieee80211_tx_info *info;
2600 u16 ethertype, hdrlen, meshhdrlen = 0;
2602 struct ieee80211_hdr hdr;
2603 struct ieee80211s_hdr mesh_hdr __maybe_unused;
2604 struct mesh_path __maybe_unused *mppath = NULL, *mpath = NULL;
2605 const u8 *encaps_data;
2606 int encaps_len, skip_header_bytes;
2607 bool wme_sta = false, authorized = false;
2611 struct ieee80211_chanctx_conf *chanctx_conf = NULL;
2612 enum nl80211_band band;
2614 u8 link_id = u32_get_bits(ctrl_flags, IEEE80211_TX_CTRL_MLO_LINK);
2619 #ifdef CONFIG_MAC80211_DEBUGFS
2620 if (local->force_tx_status)
2621 info_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
2624 /* convert Ethernet header to proper 802.11 header (based on
2625 * operation mode) */
2626 ethertype = (skb->data[12] << 8) | skb->data[13];
2627 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
2629 if (!sdata->vif.valid_links)
2631 rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
2633 switch (sdata->vif.type) {
2634 case NL80211_IFTYPE_AP_VLAN:
2635 if (sdata->wdev.use_4addr) {
2636 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
2638 memcpy(hdr.addr1, sta->sta.addr, ETH_ALEN);
2639 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
2640 memcpy(hdr.addr3, skb->data, ETH_ALEN);
2641 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
2643 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
2644 wme_sta = sta->sta.wme;
2646 if (!sdata->vif.valid_links) {
2647 struct ieee80211_sub_if_data *ap_sdata;
2649 /* override chanctx_conf from AP (we don't have one) */
2650 ap_sdata = container_of(sdata->bss,
2651 struct ieee80211_sub_if_data,
2654 rcu_dereference(ap_sdata->vif.bss_conf.chanctx_conf);
2656 if (sdata->wdev.use_4addr)
2659 case NL80211_IFTYPE_AP:
2660 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
2662 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2664 if (sdata->vif.valid_links && sta && !sta->sta.mlo) {
2665 struct ieee80211_link_data *link;
2667 link_id = sta->deflink.link_id;
2668 link = rcu_dereference(sdata->link[link_id]);
2669 if (WARN_ON(!link)) {
2673 memcpy(hdr.addr2, link->conf->addr, ETH_ALEN);
2674 } else if (link_id == IEEE80211_LINK_UNSPECIFIED ||
2675 (sta && sta->sta.mlo)) {
2676 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
2678 struct ieee80211_bss_conf *conf;
2680 conf = rcu_dereference(sdata->vif.link_conf[link_id]);
2681 if (unlikely(!conf)) {
2686 memcpy(hdr.addr2, conf->addr, ETH_ALEN);
2689 memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
2692 #ifdef CONFIG_MAC80211_MESH
2693 case NL80211_IFTYPE_MESH_POINT:
2694 if (!is_multicast_ether_addr(skb->data)) {
2695 struct sta_info *next_hop;
2696 bool mpp_lookup = true;
2698 mpath = mesh_path_lookup(sdata, skb->data);
2701 next_hop = rcu_dereference(mpath->next_hop);
2703 !(mpath->flags & (MESH_PATH_ACTIVE |
2704 MESH_PATH_RESOLVING)))
2709 mppath = mpp_path_lookup(sdata, skb->data);
2711 mppath->exp_time = jiffies;
2714 if (mppath && mpath)
2715 mesh_path_del(sdata, mpath->dst);
2719 * Use address extension if it is a packet from
2720 * another interface or if we know the destination
2721 * is being proxied by a portal (i.e. portal address
2722 * differs from proxied address)
2724 if (ether_addr_equal(sdata->vif.addr, skb->data + ETH_ALEN) &&
2725 !(mppath && !ether_addr_equal(mppath->mpp, skb->data))) {
2726 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
2727 skb->data, skb->data + ETH_ALEN);
2728 meshhdrlen = ieee80211_new_mesh_header(sdata, &mesh_hdr,
2731 /* DS -> MBSS (802.11-2012 13.11.3.3).
2732 * For unicast with unknown forwarding information,
2733 * destination might be in the MBSS or if that fails
2734 * forwarded to another mesh gate. In either case
2735 * resolution will be handled in ieee80211_xmit(), so
2736 * leave the original DA. This also works for mcast */
2737 const u8 *mesh_da = skb->data;
2740 mesh_da = mppath->mpp;
2742 mesh_da = mpath->dst;
2744 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
2745 mesh_da, sdata->vif.addr);
2746 if (is_multicast_ether_addr(mesh_da))
2747 /* DA TA mSA AE:SA */
2748 meshhdrlen = ieee80211_new_mesh_header(
2750 skb->data + ETH_ALEN, NULL);
2752 /* RA TA mDA mSA AE:DA SA */
2753 meshhdrlen = ieee80211_new_mesh_header(
2754 sdata, &mesh_hdr, skb->data,
2755 skb->data + ETH_ALEN);
2759 /* For injected frames, fill RA right away as nexthop lookup
2762 if ((ctrl_flags & IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP) &&
2763 is_zero_ether_addr(hdr.addr1))
2764 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2767 case NL80211_IFTYPE_STATION:
2768 /* we already did checks when looking up the RA STA */
2769 tdls_peer = test_sta_flag(sta, WLAN_STA_TDLS_PEER);
2773 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2774 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2775 memcpy(hdr.addr3, sdata->deflink.u.mgd.bssid, ETH_ALEN);
2777 } else if (sdata->u.mgd.use_4addr &&
2778 cpu_to_be16(ethertype) != sdata->control_port_protocol) {
2779 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
2780 IEEE80211_FCTL_TODS);
2782 memcpy(hdr.addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN);
2783 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
2784 memcpy(hdr.addr3, skb->data, ETH_ALEN);
2785 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
2788 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
2790 memcpy(hdr.addr1, sdata->vif.cfg.ap_addr, ETH_ALEN);
2791 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2792 memcpy(hdr.addr3, skb->data, ETH_ALEN);
2796 case NL80211_IFTYPE_OCB:
2798 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2799 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2800 eth_broadcast_addr(hdr.addr3);
2803 case NL80211_IFTYPE_ADHOC:
2805 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2806 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2807 memcpy(hdr.addr3, sdata->u.ibss.bssid, ETH_ALEN);
2815 if (!chanctx_conf) {
2816 if (!sdata->vif.valid_links) {
2820 /* MLD transmissions must not rely on the band */
2823 band = chanctx_conf->def.chan->band;
2826 multicast = is_multicast_ether_addr(hdr.addr1);
2828 /* sta is always NULL for mesh */
2830 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
2831 wme_sta = sta->sta.wme;
2832 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
2833 /* For mesh, the use of the QoS header is mandatory */
2837 /* receiver does QoS (which also means we do) use it */
2839 fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
2844 * Drop unicast frames to unauthorised stations unless they are
2845 * EAPOL frames from the local station.
2847 if (unlikely(!ieee80211_vif_is_mesh(&sdata->vif) &&
2848 (sdata->vif.type != NL80211_IFTYPE_OCB) &&
2849 !multicast && !authorized &&
2850 (cpu_to_be16(ethertype) != sdata->control_port_protocol ||
2851 !ieee80211_is_our_addr(sdata, skb->data + ETH_ALEN, NULL)))) {
2852 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2853 net_info_ratelimited("%s: dropped frame to %pM (unauthorized port)\n",
2854 sdata->name, hdr.addr1);
2857 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
2863 if (unlikely(!multicast && ((skb->sk &&
2864 skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS) ||
2865 ctrl_flags & IEEE80211_TX_CTL_REQ_TX_STATUS)))
2866 info_id = ieee80211_store_ack_skb(local, skb, &info_flags,
2870 * If the skb is shared we need to obtain our own copy.
2872 skb = skb_share_check(skb, GFP_ATOMIC);
2873 if (unlikely(!skb)) {
2878 hdr.frame_control = fc;
2879 hdr.duration_id = 0;
2882 skip_header_bytes = ETH_HLEN;
2883 if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
2884 encaps_data = bridge_tunnel_header;
2885 encaps_len = sizeof(bridge_tunnel_header);
2886 skip_header_bytes -= 2;
2887 } else if (ethertype >= ETH_P_802_3_MIN) {
2888 encaps_data = rfc1042_header;
2889 encaps_len = sizeof(rfc1042_header);
2890 skip_header_bytes -= 2;
2896 skb_pull(skb, skip_header_bytes);
2897 head_need = hdrlen + encaps_len + meshhdrlen - skb_headroom(skb);
2900 * So we need to modify the skb header and hence need a copy of
2901 * that. The head_need variable above doesn't, so far, include
2902 * the needed header space that we don't need right away. If we
2903 * can, then we don't reallocate right now but only after the
2904 * frame arrives at the master device (if it does...)
2906 * If we cannot, however, then we will reallocate to include all
2907 * the ever needed space. Also, if we need to reallocate it anyway,
2908 * make it big enough for everything we may ever need.
2911 if (head_need > 0 || skb_cloned(skb)) {
2912 head_need += IEEE80211_ENCRYPT_HEADROOM;
2913 head_need += local->tx_headroom;
2914 head_need = max_t(int, 0, head_need);
2915 if (ieee80211_skb_resize(sdata, skb, head_need, ENCRYPT_DATA)) {
2916 ieee80211_free_txskb(&local->hw, skb);
2918 return ERR_PTR(-ENOMEM);
2923 memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
2925 #ifdef CONFIG_MAC80211_MESH
2927 memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen);
2930 if (ieee80211_is_data_qos(fc)) {
2931 __le16 *qos_control;
2933 qos_control = skb_push(skb, 2);
2934 memcpy(skb_push(skb, hdrlen - 2), &hdr, hdrlen - 2);
2936 * Maybe we could actually set some fields here, for now just
2937 * initialise to zero to indicate no special operation.
2941 memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
2943 skb_reset_mac_header(skb);
2945 info = IEEE80211_SKB_CB(skb);
2946 memset(info, 0, sizeof(*info));
2948 info->flags = info_flags;
2949 info->ack_frame_id = info_id;
2952 if (likely(!cookie)) {
2953 ctrl_flags |= u32_encode_bits(link_id,
2954 IEEE80211_TX_CTRL_MLO_LINK);
2956 unsigned int pre_conf_link_id;
2959 * ctrl_flags already have been set by
2960 * ieee80211_tx_control_port(), here
2961 * we just sanity check that
2964 pre_conf_link_id = u32_get_bits(ctrl_flags,
2965 IEEE80211_TX_CTRL_MLO_LINK);
2967 if (pre_conf_link_id != link_id &&
2968 link_id != IEEE80211_LINK_UNSPECIFIED) {
2969 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2970 net_info_ratelimited("%s: dropped frame to %pM with bad link ID request (%d vs. %d)\n",
2971 sdata->name, hdr.addr1,
2972 pre_conf_link_id, link_id);
2979 info->control.flags = ctrl_flags;
2984 return ERR_PTR(ret);
2988 * fast-xmit overview
2990 * The core idea of this fast-xmit is to remove per-packet checks by checking
2991 * them out of band. ieee80211_check_fast_xmit() implements the out-of-band
2992 * checks that are needed to get the sta->fast_tx pointer assigned, after which
2993 * much less work can be done per packet. For example, fragmentation must be
2994 * disabled or the fast_tx pointer will not be set. All the conditions are seen
2997 * Once assigned, the fast_tx data structure also caches the per-packet 802.11
2998 * header and other data to aid packet processing in ieee80211_xmit_fast().
3000 * The most difficult part of this is that when any of these assumptions
3001 * change, an external trigger (i.e. a call to ieee80211_clear_fast_xmit(),
3002 * ieee80211_check_fast_xmit() or friends) is required to reset the data,
3003 * since the per-packet code no longer checks the conditions. This is reflected
3004 * by the calls to these functions throughout the rest of the code, and must be
3005 * maintained if any of the TX path checks change.
3008 void ieee80211_check_fast_xmit(struct sta_info *sta)
3010 struct ieee80211_fast_tx build = {}, *fast_tx = NULL, *old;
3011 struct ieee80211_local *local = sta->local;
3012 struct ieee80211_sub_if_data *sdata = sta->sdata;
3013 struct ieee80211_hdr *hdr = (void *)build.hdr;
3014 struct ieee80211_chanctx_conf *chanctx_conf;
3017 if (!ieee80211_hw_check(&local->hw, SUPPORT_FAST_XMIT))
3020 if (ieee80211_vif_is_mesh(&sdata->vif))
3021 mesh_fast_tx_flush_sta(sdata, sta);
3023 /* Locking here protects both the pointer itself, and against concurrent
3024 * invocations winning data access races to, e.g., the key pointer that
3026 * Without it, the invocation of this function right after the key
3027 * pointer changes wouldn't be sufficient, as another CPU could access
3028 * the pointer, then stall, and then do the cache update after the CPU
3029 * that invalidated the key.
3030 * With the locking, such scenarios cannot happen as the check for the
3031 * key and the fast-tx assignment are done atomically, so the CPU that
3032 * modifies the key will either wait or other one will see the key
3033 * cleared/changed already.
3035 spin_lock_bh(&sta->lock);
3036 if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
3037 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
3038 sdata->vif.type == NL80211_IFTYPE_STATION)
3041 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
3044 if (test_sta_flag(sta, WLAN_STA_PS_STA) ||
3045 test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
3046 test_sta_flag(sta, WLAN_STA_PS_DELIVER) ||
3047 test_sta_flag(sta, WLAN_STA_CLEAR_PS_FILT))
3050 if (sdata->noack_map)
3053 /* fast-xmit doesn't handle fragmentation at all */
3054 if (local->hw.wiphy->frag_threshold != (u32)-1 &&
3055 !ieee80211_hw_check(&local->hw, SUPPORTS_TX_FRAG))
3058 if (!sdata->vif.valid_links) {
3061 rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
3062 if (!chanctx_conf) {
3066 build.band = chanctx_conf->def.chan->band;
3069 /* MLD transmissions must not rely on the band */
3073 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
3075 switch (sdata->vif.type) {
3076 case NL80211_IFTYPE_ADHOC:
3078 build.da_offs = offsetof(struct ieee80211_hdr, addr1);
3079 build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3080 memcpy(hdr->addr3, sdata->u.ibss.bssid, ETH_ALEN);
3083 case NL80211_IFTYPE_STATION:
3084 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
3086 build.da_offs = offsetof(struct ieee80211_hdr, addr1);
3087 build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3088 memcpy(hdr->addr3, sdata->deflink.u.mgd.bssid, ETH_ALEN);
3093 if (sdata->u.mgd.use_4addr) {
3094 /* non-regular ethertype cannot use the fastpath */
3095 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
3096 IEEE80211_FCTL_TODS);
3098 memcpy(hdr->addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN);
3099 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
3100 build.da_offs = offsetof(struct ieee80211_hdr, addr3);
3101 build.sa_offs = offsetof(struct ieee80211_hdr, addr4);
3105 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
3107 memcpy(hdr->addr1, sdata->vif.cfg.ap_addr, ETH_ALEN);
3108 build.da_offs = offsetof(struct ieee80211_hdr, addr3);
3109 build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3112 case NL80211_IFTYPE_AP_VLAN:
3113 if (sdata->wdev.use_4addr) {
3114 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
3115 IEEE80211_FCTL_TODS);
3117 memcpy(hdr->addr1, sta->sta.addr, ETH_ALEN);
3118 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
3119 build.da_offs = offsetof(struct ieee80211_hdr, addr3);
3120 build.sa_offs = offsetof(struct ieee80211_hdr, addr4);
3125 case NL80211_IFTYPE_AP:
3126 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
3128 build.da_offs = offsetof(struct ieee80211_hdr, addr1);
3129 if (sta->sta.mlo || !sdata->vif.valid_links) {
3130 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
3132 unsigned int link_id = sta->deflink.link_id;
3133 struct ieee80211_link_data *link;
3136 link = rcu_dereference(sdata->link[link_id]);
3137 if (WARN_ON(!link)) {
3141 memcpy(hdr->addr2, link->conf->addr, ETH_ALEN);
3144 build.sa_offs = offsetof(struct ieee80211_hdr, addr3);
3148 /* not handled on fast-xmit */
3154 fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3157 /* We store the key here so there's no point in using rcu_dereference()
3158 * but that's fine because the code that changes the pointers will call
3159 * this function after doing so. For a single CPU that would be enough,
3160 * for multiple see the comment above.
3162 build.key = rcu_access_pointer(sta->ptk[sta->ptk_idx]);
3164 build.key = rcu_access_pointer(sdata->default_unicast_key);
3166 bool gen_iv, iv_spc, mmic;
3168 gen_iv = build.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV;
3169 iv_spc = build.key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3170 mmic = build.key->conf.flags &
3171 (IEEE80211_KEY_FLAG_GENERATE_MMIC |
3172 IEEE80211_KEY_FLAG_PUT_MIC_SPACE);
3174 /* don't handle software crypto */
3175 if (!(build.key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
3178 /* Key is being removed */
3179 if (build.key->flags & KEY_FLAG_TAINTED)
3182 switch (build.key->conf.cipher) {
3183 case WLAN_CIPHER_SUITE_CCMP:
3184 case WLAN_CIPHER_SUITE_CCMP_256:
3186 build.pn_offs = build.hdr_len;
3187 if (gen_iv || iv_spc)
3188 build.hdr_len += IEEE80211_CCMP_HDR_LEN;
3190 case WLAN_CIPHER_SUITE_GCMP:
3191 case WLAN_CIPHER_SUITE_GCMP_256:
3193 build.pn_offs = build.hdr_len;
3194 if (gen_iv || iv_spc)
3195 build.hdr_len += IEEE80211_GCMP_HDR_LEN;
3197 case WLAN_CIPHER_SUITE_TKIP:
3198 /* cannot handle MMIC or IV generation in xmit-fast */
3202 build.hdr_len += IEEE80211_TKIP_IV_LEN;
3204 case WLAN_CIPHER_SUITE_WEP40:
3205 case WLAN_CIPHER_SUITE_WEP104:
3206 /* cannot handle IV generation in fast-xmit */
3210 build.hdr_len += IEEE80211_WEP_IV_LEN;
3212 case WLAN_CIPHER_SUITE_AES_CMAC:
3213 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
3214 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3215 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3217 "management cipher suite 0x%x enabled for data\n",
3218 build.key->conf.cipher);
3221 /* we don't know how to generate IVs for this at all */
3222 if (WARN_ON(gen_iv))
3226 fc |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
3229 hdr->frame_control = fc;
3231 memcpy(build.hdr + build.hdr_len,
3232 rfc1042_header, sizeof(rfc1042_header));
3233 build.hdr_len += sizeof(rfc1042_header);
3235 fast_tx = kmemdup(&build, sizeof(build), GFP_ATOMIC);
3236 /* if the kmemdup fails, continue w/o fast_tx */
3239 /* we might have raced against another call to this function */
3240 old = rcu_dereference_protected(sta->fast_tx,
3241 lockdep_is_held(&sta->lock));
3242 rcu_assign_pointer(sta->fast_tx, fast_tx);
3244 kfree_rcu(old, rcu_head);
3245 spin_unlock_bh(&sta->lock);
3248 void ieee80211_check_fast_xmit_all(struct ieee80211_local *local)
3250 struct sta_info *sta;
3253 list_for_each_entry_rcu(sta, &local->sta_list, list)
3254 ieee80211_check_fast_xmit(sta);
3258 void ieee80211_check_fast_xmit_iface(struct ieee80211_sub_if_data *sdata)
3260 struct ieee80211_local *local = sdata->local;
3261 struct sta_info *sta;
3265 list_for_each_entry_rcu(sta, &local->sta_list, list) {
3266 if (sdata != sta->sdata &&
3267 (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
3269 ieee80211_check_fast_xmit(sta);
3275 void ieee80211_clear_fast_xmit(struct sta_info *sta)
3277 struct ieee80211_fast_tx *fast_tx;
3279 spin_lock_bh(&sta->lock);
3280 fast_tx = rcu_dereference_protected(sta->fast_tx,
3281 lockdep_is_held(&sta->lock));
3282 RCU_INIT_POINTER(sta->fast_tx, NULL);
3283 spin_unlock_bh(&sta->lock);
3286 kfree_rcu(fast_tx, rcu_head);
3289 static bool ieee80211_amsdu_realloc_pad(struct ieee80211_local *local,
3290 struct sk_buff *skb, int headroom)
3292 if (skb_headroom(skb) < headroom) {
3293 I802_DEBUG_INC(local->tx_expand_skb_head);
3295 if (pskb_expand_head(skb, headroom, 0, GFP_ATOMIC)) {
3296 wiphy_debug(local->hw.wiphy,
3297 "failed to reallocate TX buffer\n");
3305 static bool ieee80211_amsdu_prepare_head(struct ieee80211_sub_if_data *sdata,
3306 struct ieee80211_fast_tx *fast_tx,
3307 struct sk_buff *skb)
3309 struct ieee80211_local *local = sdata->local;
3310 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3311 struct ieee80211_hdr *hdr;
3312 struct ethhdr *amsdu_hdr;
3313 int hdr_len = fast_tx->hdr_len - sizeof(rfc1042_header);
3314 int subframe_len = skb->len - hdr_len;
3316 u8 *qc, *h_80211_src, *h_80211_dst;
3319 if (info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE)
3322 if (info->control.flags & IEEE80211_TX_CTRL_AMSDU)
3325 if (!ieee80211_amsdu_realloc_pad(local, skb,
3326 sizeof(*amsdu_hdr) +
3327 local->hw.extra_tx_headroom))
3330 data = skb_push(skb, sizeof(*amsdu_hdr));
3331 memmove(data, data + sizeof(*amsdu_hdr), hdr_len);
3333 amsdu_hdr = data + hdr_len;
3334 /* h_80211_src/dst is addr* field within hdr */
3335 h_80211_src = data + fast_tx->sa_offs;
3336 h_80211_dst = data + fast_tx->da_offs;
3338 amsdu_hdr->h_proto = cpu_to_be16(subframe_len);
3339 ether_addr_copy(amsdu_hdr->h_source, h_80211_src);
3340 ether_addr_copy(amsdu_hdr->h_dest, h_80211_dst);
3342 /* according to IEEE 802.11-2012 8.3.2 table 8-19, the outer SA/DA
3343 * fields needs to be changed to BSSID for A-MSDU frames depending
3344 * on FromDS/ToDS values.
3346 switch (sdata->vif.type) {
3347 case NL80211_IFTYPE_STATION:
3348 bssid = sdata->vif.cfg.ap_addr;
3350 case NL80211_IFTYPE_AP:
3351 case NL80211_IFTYPE_AP_VLAN:
3352 bssid = sdata->vif.addr;
3358 if (bssid && ieee80211_has_fromds(hdr->frame_control))
3359 ether_addr_copy(h_80211_src, bssid);
3361 if (bssid && ieee80211_has_tods(hdr->frame_control))
3362 ether_addr_copy(h_80211_dst, bssid);
3364 qc = ieee80211_get_qos_ctl(hdr);
3365 *qc |= IEEE80211_QOS_CTL_A_MSDU_PRESENT;
3367 info->control.flags |= IEEE80211_TX_CTRL_AMSDU;
3372 static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,
3373 struct sta_info *sta,
3374 struct ieee80211_fast_tx *fast_tx,
3375 struct sk_buff *skb,
3376 const u8 *da, const u8 *sa)
3378 struct ieee80211_local *local = sdata->local;
3379 struct fq *fq = &local->fq;
3381 struct fq_flow *flow;
3382 u8 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
3383 struct ieee80211_txq *txq = sta->sta.txq[tid];
3384 struct txq_info *txqi;
3385 struct sk_buff **frag_tail, *head;
3386 int subframe_len = skb->len - ETH_ALEN;
3387 u8 max_subframes = sta->sta.max_amsdu_subframes;
3388 int max_frags = local->hw.max_tx_fragments;
3389 int max_amsdu_len = sta->sta.cur->max_amsdu_len;
3395 unsigned int orig_len;
3396 int n = 2, nfrags, pad = 0;
3399 if (!ieee80211_hw_check(&local->hw, TX_AMSDU))
3402 if (sdata->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED)
3405 if (ieee80211_vif_is_mesh(&sdata->vif))
3408 if (skb_is_gso(skb))
3414 txqi = to_txq_info(txq);
3415 if (test_bit(IEEE80211_TXQ_NO_AMSDU, &txqi->flags))
3418 if (sta->sta.cur->max_rc_amsdu_len)
3419 max_amsdu_len = min_t(int, max_amsdu_len,
3420 sta->sta.cur->max_rc_amsdu_len);
3422 if (sta->sta.cur->max_tid_amsdu_len[tid])
3423 max_amsdu_len = min_t(int, max_amsdu_len,
3424 sta->sta.cur->max_tid_amsdu_len[tid]);
3426 flow_idx = fq_flow_idx(fq, skb);
3428 spin_lock_bh(&fq->lock);
3430 /* TODO: Ideally aggregation should be done on dequeue to remain
3431 * responsive to environment changes.
3435 flow = fq_flow_classify(fq, tin, flow_idx, skb);
3436 head = skb_peek_tail(&flow->queue);
3437 if (!head || skb_is_gso(head))
3440 orig_truesize = head->truesize;
3441 orig_len = head->len;
3443 if (skb->len + head->len > max_amsdu_len)
3446 nfrags = 1 + skb_shinfo(skb)->nr_frags;
3447 nfrags += 1 + skb_shinfo(head)->nr_frags;
3448 frag_tail = &skb_shinfo(head)->frag_list;
3449 while (*frag_tail) {
3450 nfrags += 1 + skb_shinfo(*frag_tail)->nr_frags;
3451 frag_tail = &(*frag_tail)->next;
3455 if (max_subframes && n > max_subframes)
3458 if (max_frags && nfrags > max_frags)
3461 if (!drv_can_aggregate_in_amsdu(local, head, skb))
3464 if (!ieee80211_amsdu_prepare_head(sdata, fast_tx, head))
3467 /* If n == 2, the "while (*frag_tail)" loop above didn't execute
3468 * and frag_tail should be &skb_shinfo(head)->frag_list.
3469 * However, ieee80211_amsdu_prepare_head() can reallocate it.
3470 * Reload frag_tail to have it pointing to the correct place.
3473 frag_tail = &skb_shinfo(head)->frag_list;
3476 * Pad out the previous subframe to a multiple of 4 by adding the
3477 * padding to the next one, that's being added. Note that head->len
3478 * is the length of the full A-MSDU, but that works since each time
3479 * we add a new subframe we pad out the previous one to a multiple
3480 * of 4 and thus it no longer matters in the next round.
3482 hdrlen = fast_tx->hdr_len - sizeof(rfc1042_header);
3483 if ((head->len - hdrlen) & 3)
3484 pad = 4 - ((head->len - hdrlen) & 3);
3486 if (!ieee80211_amsdu_realloc_pad(local, skb, sizeof(rfc1042_header) +
3491 data = skb_push(skb, ETH_ALEN + 2);
3492 ether_addr_copy(data, da);
3493 ether_addr_copy(data + ETH_ALEN, sa);
3495 data += 2 * ETH_ALEN;
3496 len = cpu_to_be16(subframe_len);
3497 memcpy(data, &len, 2);
3498 memcpy(data + 2, rfc1042_header, sizeof(rfc1042_header));
3500 memset(skb_push(skb, pad), 0, pad);
3502 head->len += skb->len;
3503 head->data_len += skb->len;
3507 fq->memory_usage += head->truesize - orig_truesize;
3508 if (head->len != orig_len) {
3509 flow->backlog += head->len - orig_len;
3510 tin->backlog_bytes += head->len - orig_len;
3513 spin_unlock_bh(&fq->lock);
3519 * Can be called while the sta lock is held. Anything that can cause packets to
3520 * be generated will cause deadlock!
3522 static ieee80211_tx_result
3523 ieee80211_xmit_fast_finish(struct ieee80211_sub_if_data *sdata,
3524 struct sta_info *sta, u8 pn_offs,
3525 struct ieee80211_key *key,
3526 struct ieee80211_tx_data *tx)
3528 struct sk_buff *skb = tx->skb;
3529 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3530 struct ieee80211_hdr *hdr = (void *)skb->data;
3531 u8 tid = IEEE80211_NUM_TIDS;
3533 if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL) &&
3534 ieee80211_tx_h_rate_ctrl(tx) != TX_CONTINUE)
3538 info->control.hw_key = &key->conf;
3540 dev_sw_netstats_tx_add(skb->dev, 1, skb->len);
3542 if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
3543 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
3544 hdr->seq_ctrl = ieee80211_tx_next_seq(sta, tid);
3546 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
3547 hdr->seq_ctrl = cpu_to_le16(sdata->sequence_number);
3548 sdata->sequence_number += 0x10;
3551 if (skb_shinfo(skb)->gso_size)
3552 sta->deflink.tx_stats.msdu[tid] +=
3553 DIV_ROUND_UP(skb->len, skb_shinfo(skb)->gso_size);
3555 sta->deflink.tx_stats.msdu[tid]++;
3557 info->hw_queue = sdata->vif.hw_queue[skb_get_queue_mapping(skb)];
3559 /* statistics normally done by ieee80211_tx_h_stats (but that
3560 * has to consider fragmentation, so is more complex)
3562 sta->deflink.tx_stats.bytes[skb_get_queue_mapping(skb)] += skb->len;
3563 sta->deflink.tx_stats.packets[skb_get_queue_mapping(skb)]++;
3567 u8 *crypto_hdr = skb->data + pn_offs;
3569 switch (key->conf.cipher) {
3570 case WLAN_CIPHER_SUITE_CCMP:
3571 case WLAN_CIPHER_SUITE_CCMP_256:
3572 case WLAN_CIPHER_SUITE_GCMP:
3573 case WLAN_CIPHER_SUITE_GCMP_256:
3574 pn = atomic64_inc_return(&key->conf.tx_pn);
3576 crypto_hdr[1] = pn >> 8;
3577 crypto_hdr[3] = 0x20 | (key->conf.keyidx << 6);
3578 crypto_hdr[4] = pn >> 16;
3579 crypto_hdr[5] = pn >> 24;
3580 crypto_hdr[6] = pn >> 32;
3581 crypto_hdr[7] = pn >> 40;
3589 static netdev_features_t
3590 ieee80211_sdata_netdev_features(struct ieee80211_sub_if_data *sdata)
3592 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
3593 return sdata->vif.netdev_features;
3598 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap);
3599 return sdata->vif.netdev_features;
3602 static struct sk_buff *
3603 ieee80211_tx_skb_fixup(struct sk_buff *skb, netdev_features_t features)
3605 if (skb_is_gso(skb)) {
3606 struct sk_buff *segs;
3608 segs = skb_gso_segment(skb, features);
3618 if (skb_needs_linearize(skb, features) && __skb_linearize(skb))
3621 if (skb->ip_summed == CHECKSUM_PARTIAL) {
3622 int ofs = skb_checksum_start_offset(skb);
3624 if (skb->encapsulation)
3625 skb_set_inner_transport_header(skb, ofs);
3627 skb_set_transport_header(skb, ofs);
3629 if (skb_csum_hwoffload_help(skb, features))
3633 skb_mark_not_on_list(skb);
3641 void __ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
3642 struct sta_info *sta,
3643 struct ieee80211_fast_tx *fast_tx,
3644 struct sk_buff *skb, bool ampdu,
3645 const u8 *da, const u8 *sa)
3647 struct ieee80211_local *local = sdata->local;
3648 struct ieee80211_hdr *hdr = (void *)fast_tx->hdr;
3649 struct ieee80211_tx_info *info;
3650 struct ieee80211_tx_data tx;
3651 ieee80211_tx_result r;
3652 int hw_headroom = sdata->local->hw.extra_tx_headroom;
3653 int extra_head = fast_tx->hdr_len - (ETH_HLEN - 2);
3655 skb = skb_share_check(skb, GFP_ATOMIC);
3659 if ((hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) &&
3660 ieee80211_amsdu_aggregate(sdata, sta, fast_tx, skb, da, sa))
3663 /* will not be crypto-handled beyond what we do here, so use false
3664 * as the may-encrypt argument for the resize to not account for
3665 * more room than we already have in 'extra_head'
3667 if (unlikely(ieee80211_skb_resize(sdata, skb,
3668 max_t(int, extra_head + hw_headroom -
3669 skb_headroom(skb), 0),
3673 hdr = skb_push(skb, extra_head);
3674 memcpy(skb->data, fast_tx->hdr, fast_tx->hdr_len);
3675 memcpy(skb->data + fast_tx->da_offs, da, ETH_ALEN);
3676 memcpy(skb->data + fast_tx->sa_offs, sa, ETH_ALEN);
3678 info = IEEE80211_SKB_CB(skb);
3679 memset(info, 0, sizeof(*info));
3680 info->band = fast_tx->band;
3681 info->control.vif = &sdata->vif;
3682 info->flags = IEEE80211_TX_CTL_FIRST_FRAGMENT |
3683 IEEE80211_TX_CTL_DONTFRAG;
3684 info->control.flags = IEEE80211_TX_CTRL_FAST_XMIT |
3685 u32_encode_bits(IEEE80211_LINK_UNSPECIFIED,
3686 IEEE80211_TX_CTRL_MLO_LINK);
3688 #ifdef CONFIG_MAC80211_DEBUGFS
3689 if (local->force_tx_status)
3690 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
3693 if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
3694 u8 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
3696 *ieee80211_get_qos_ctl(hdr) = tid;
3699 __skb_queue_head_init(&tx.skbs);
3701 tx.flags = IEEE80211_TX_UNICAST;
3705 tx.key = fast_tx->key;
3707 if (ieee80211_queue_skb(local, sdata, sta, skb))
3711 r = ieee80211_xmit_fast_finish(sdata, sta, fast_tx->pn_offs,
3717 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
3718 sdata = container_of(sdata->bss,
3719 struct ieee80211_sub_if_data, u.ap);
3721 __skb_queue_tail(&tx.skbs, skb);
3722 ieee80211_tx_frags(local, &sdata->vif, sta, &tx.skbs, false);
3729 static bool ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
3730 struct sta_info *sta,
3731 struct ieee80211_fast_tx *fast_tx,
3732 struct sk_buff *skb)
3734 u16 ethertype = (skb->data[12] << 8) | skb->data[13];
3735 struct ieee80211_hdr *hdr = (void *)fast_tx->hdr;
3736 struct tid_ampdu_tx *tid_tx = NULL;
3737 struct sk_buff *next;
3739 u8 tid = IEEE80211_NUM_TIDS;
3741 /* control port protocol needs a lot of special handling */
3742 if (cpu_to_be16(ethertype) == sdata->control_port_protocol)
3745 /* only RFC 1042 SNAP */
3746 if (ethertype < ETH_P_802_3_MIN)
3749 /* don't handle TX status request here either */
3750 if (skb->sk && skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS)
3753 if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
3754 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
3755 tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
3757 if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state))
3759 if (tid_tx->timeout)
3760 tid_tx->last_tx = jiffies;
3764 memcpy(ð, skb->data, ETH_HLEN - 2);
3766 /* after this point (skb is modified) we cannot return false */
3767 skb = ieee80211_tx_skb_fixup(skb, ieee80211_sdata_netdev_features(sdata));
3771 skb_list_walk_safe(skb, skb, next) {
3772 skb_mark_not_on_list(skb);
3773 __ieee80211_xmit_fast(sdata, sta, fast_tx, skb, tid_tx,
3774 eth.h_dest, eth.h_source);
3780 struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,
3781 struct ieee80211_txq *txq)
3783 struct ieee80211_local *local = hw_to_local(hw);
3784 struct txq_info *txqi = container_of(txq, struct txq_info, txq);
3785 struct ieee80211_hdr *hdr;
3786 struct sk_buff *skb = NULL;
3787 struct fq *fq = &local->fq;
3788 struct fq_tin *tin = &txqi->tin;
3789 struct ieee80211_tx_info *info;
3790 struct ieee80211_tx_data tx;
3791 ieee80211_tx_result r;
3792 struct ieee80211_vif *vif = txq->vif;
3793 int q = vif->hw_queue[txq->ac];
3794 unsigned long flags;
3797 WARN_ON_ONCE(softirq_count() == 0);
3799 if (!ieee80211_txq_airtime_check(hw, txq))
3803 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
3804 q_stopped = local->queue_stop_reasons[q];
3805 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
3807 if (unlikely(q_stopped)) {
3808 /* mark for waking later */
3809 set_bit(IEEE80211_TXQ_DIRTY, &txqi->flags);
3813 spin_lock_bh(&fq->lock);
3815 /* Make sure fragments stay together. */
3816 skb = __skb_dequeue(&txqi->frags);
3817 if (unlikely(skb)) {
3818 if (!(IEEE80211_SKB_CB(skb)->control.flags &
3819 IEEE80211_TX_INTCFL_NEED_TXPROCESSING))
3821 IEEE80211_SKB_CB(skb)->control.flags &=
3822 ~IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
3824 if (unlikely(test_bit(IEEE80211_TXQ_STOP, &txqi->flags)))
3827 skb = fq_tin_dequeue(fq, tin, fq_tin_dequeue_func);
3833 spin_unlock_bh(&fq->lock);
3835 hdr = (struct ieee80211_hdr *)skb->data;
3836 info = IEEE80211_SKB_CB(skb);
3838 memset(&tx, 0, sizeof(tx));
3839 __skb_queue_head_init(&tx.skbs);
3842 tx.sdata = vif_to_sdata(info->control.vif);
3845 tx.sta = container_of(txq->sta, struct sta_info, sta);
3847 * Drop unicast frames to unauthorised stations unless they are
3848 * injected frames or EAPOL frames from the local station.
3850 if (unlikely(!(info->flags & IEEE80211_TX_CTL_INJECTED) &&
3851 ieee80211_is_data(hdr->frame_control) &&
3852 !ieee80211_vif_is_mesh(&tx.sdata->vif) &&
3853 tx.sdata->vif.type != NL80211_IFTYPE_OCB &&
3854 !is_multicast_ether_addr(hdr->addr1) &&
3855 !test_sta_flag(tx.sta, WLAN_STA_AUTHORIZED) &&
3856 (!(info->control.flags &
3857 IEEE80211_TX_CTRL_PORT_CTRL_PROTO) ||
3858 !ieee80211_is_our_addr(tx.sdata, hdr->addr2,
3860 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
3861 ieee80211_free_txskb(&local->hw, skb);
3867 * The key can be removed while the packet was queued, so need to call
3868 * this here to get the current key.
3870 r = ieee80211_tx_h_select_key(&tx);
3871 if (r != TX_CONTINUE) {
3872 ieee80211_free_txskb(&local->hw, skb);
3876 if (test_bit(IEEE80211_TXQ_AMPDU, &txqi->flags))
3877 info->flags |= (IEEE80211_TX_CTL_AMPDU |
3878 IEEE80211_TX_CTL_DONTFRAG);
3880 if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) {
3881 if (!ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
3882 r = ieee80211_tx_h_rate_ctrl(&tx);
3883 if (r != TX_CONTINUE) {
3884 ieee80211_free_txskb(&local->hw, skb);
3891 if (info->control.flags & IEEE80211_TX_CTRL_FAST_XMIT) {
3892 struct sta_info *sta = container_of(txq->sta, struct sta_info,
3897 (tx.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
3898 pn_offs = ieee80211_hdrlen(hdr->frame_control);
3900 r = ieee80211_xmit_fast_finish(sta->sdata, sta, pn_offs,
3902 if (r != TX_CONTINUE) {
3903 ieee80211_free_txskb(&local->hw, skb);
3907 if (invoke_tx_handlers_late(&tx))
3910 skb = __skb_dequeue(&tx.skbs);
3912 if (!skb_queue_empty(&tx.skbs)) {
3913 spin_lock_bh(&fq->lock);
3914 skb_queue_splice_tail(&tx.skbs, &txqi->frags);
3915 spin_unlock_bh(&fq->lock);
3919 if (skb_has_frag_list(skb) &&
3920 !ieee80211_hw_check(&local->hw, TX_FRAG_LIST)) {
3921 if (skb_linearize(skb)) {
3922 ieee80211_free_txskb(&local->hw, skb);
3927 switch (tx.sdata->vif.type) {
3928 case NL80211_IFTYPE_MONITOR:
3929 if (tx.sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) {
3930 vif = &tx.sdata->vif;
3933 tx.sdata = rcu_dereference(local->monitor_sdata);
3935 vif = &tx.sdata->vif;
3937 vif->hw_queue[skb_get_queue_mapping(skb)];
3938 } else if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) {
3939 ieee80211_free_txskb(&local->hw, skb);
3945 case NL80211_IFTYPE_AP_VLAN:
3946 tx.sdata = container_of(tx.sdata->bss,
3947 struct ieee80211_sub_if_data, u.ap);
3950 vif = &tx.sdata->vif;
3955 IEEE80211_SKB_CB(skb)->control.vif = vif;
3958 wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL)) {
3959 bool ampdu = txq->ac != IEEE80211_AC_VO;
3962 airtime = ieee80211_calc_expected_tx_airtime(hw, vif, txq->sta,
3965 airtime = ieee80211_info_set_tx_time_est(info, airtime);
3966 ieee80211_sta_update_pending_airtime(local, tx.sta,
3976 spin_unlock_bh(&fq->lock);
3980 EXPORT_SYMBOL(ieee80211_tx_dequeue);
3982 static inline s32 ieee80211_sta_deficit(struct sta_info *sta, u8 ac)
3984 struct airtime_info *air_info = &sta->airtime[ac];
3986 return air_info->deficit - atomic_read(&air_info->aql_tx_pending);
3990 ieee80211_txq_set_active(struct txq_info *txqi)
3992 struct sta_info *sta;
3997 sta = container_of(txqi->txq.sta, struct sta_info, sta);
3998 sta->airtime[txqi->txq.ac].last_active = (u32)jiffies;
4002 ieee80211_txq_keep_active(struct txq_info *txqi)
4004 struct sta_info *sta;
4010 sta = container_of(txqi->txq.sta, struct sta_info, sta);
4011 if (ieee80211_sta_deficit(sta, txqi->txq.ac) >= 0)
4014 diff = (u32)jiffies - sta->airtime[txqi->txq.ac].last_active;
4016 return diff <= AIRTIME_ACTIVE_DURATION;
4019 struct ieee80211_txq *ieee80211_next_txq(struct ieee80211_hw *hw, u8 ac)
4021 struct ieee80211_local *local = hw_to_local(hw);
4022 struct ieee80211_txq *ret = NULL;
4023 struct txq_info *txqi = NULL, *head = NULL;
4024 bool found_eligible_txq = false;
4026 spin_lock_bh(&local->active_txq_lock[ac]);
4028 if (!local->schedule_round[ac])
4032 txqi = list_first_entry_or_null(&local->active_txqs[ac],
4039 if (!found_eligible_txq)
4042 found_eligible_txq = false;
4048 if (txqi->txq.sta) {
4049 struct sta_info *sta = container_of(txqi->txq.sta,
4050 struct sta_info, sta);
4051 bool aql_check = ieee80211_txq_airtime_check(hw, &txqi->txq);
4052 s32 deficit = ieee80211_sta_deficit(sta, txqi->txq.ac);
4055 found_eligible_txq = true;
4058 sta->airtime[txqi->txq.ac].deficit +=
4059 sta->airtime_weight;
4061 if (deficit < 0 || !aql_check) {
4062 list_move_tail(&txqi->schedule_order,
4063 &local->active_txqs[txqi->txq.ac]);
4068 if (txqi->schedule_round == local->schedule_round[ac])
4071 list_del_init(&txqi->schedule_order);
4072 txqi->schedule_round = local->schedule_round[ac];
4076 spin_unlock_bh(&local->active_txq_lock[ac]);
4079 EXPORT_SYMBOL(ieee80211_next_txq);
4081 void __ieee80211_schedule_txq(struct ieee80211_hw *hw,
4082 struct ieee80211_txq *txq,
4085 struct ieee80211_local *local = hw_to_local(hw);
4086 struct txq_info *txqi = to_txq_info(txq);
4089 spin_lock_bh(&local->active_txq_lock[txq->ac]);
4091 has_queue = force || txq_has_queue(txq);
4092 if (list_empty(&txqi->schedule_order) &&
4093 (has_queue || ieee80211_txq_keep_active(txqi))) {
4094 /* If airtime accounting is active, always enqueue STAs at the
4095 * head of the list to ensure that they only get moved to the
4096 * back by the airtime DRR scheduler once they have a negative
4097 * deficit. A station that already has a negative deficit will
4098 * get immediately moved to the back of the list on the next
4099 * call to ieee80211_next_txq().
4101 if (txqi->txq.sta && local->airtime_flags && has_queue &&
4102 wiphy_ext_feature_isset(local->hw.wiphy,
4103 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
4104 list_add(&txqi->schedule_order,
4105 &local->active_txqs[txq->ac]);
4107 list_add_tail(&txqi->schedule_order,
4108 &local->active_txqs[txq->ac]);
4110 ieee80211_txq_set_active(txqi);
4113 spin_unlock_bh(&local->active_txq_lock[txq->ac]);
4115 EXPORT_SYMBOL(__ieee80211_schedule_txq);
4117 DEFINE_STATIC_KEY_FALSE(aql_disable);
4119 bool ieee80211_txq_airtime_check(struct ieee80211_hw *hw,
4120 struct ieee80211_txq *txq)
4122 struct sta_info *sta;
4123 struct ieee80211_local *local = hw_to_local(hw);
4125 if (!wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL))
4128 if (static_branch_unlikely(&aql_disable))
4134 if (unlikely(txq->tid == IEEE80211_NUM_TIDS))
4137 sta = container_of(txq->sta, struct sta_info, sta);
4138 if (atomic_read(&sta->airtime[txq->ac].aql_tx_pending) <
4139 sta->airtime[txq->ac].aql_limit_low)
4142 if (atomic_read(&local->aql_total_pending_airtime) <
4143 local->aql_threshold &&
4144 atomic_read(&sta->airtime[txq->ac].aql_tx_pending) <
4145 sta->airtime[txq->ac].aql_limit_high)
4150 EXPORT_SYMBOL(ieee80211_txq_airtime_check);
4153 ieee80211_txq_schedule_airtime_check(struct ieee80211_local *local, u8 ac)
4155 unsigned int num_txq = 0;
4156 struct txq_info *txq;
4159 if (!wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL))
4162 list_for_each_entry(txq, &local->active_txqs[ac], schedule_order)
4165 aql_limit = (num_txq - 1) * local->aql_txq_limit_low[ac] / 2 +
4166 local->aql_txq_limit_high[ac];
4168 return atomic_read(&local->aql_ac_pending_airtime[ac]) < aql_limit;
4171 bool ieee80211_txq_may_transmit(struct ieee80211_hw *hw,
4172 struct ieee80211_txq *txq)
4174 struct ieee80211_local *local = hw_to_local(hw);
4175 struct txq_info *iter, *tmp, *txqi = to_txq_info(txq);
4176 struct sta_info *sta;
4179 spin_lock_bh(&local->active_txq_lock[ac]);
4184 if (list_empty(&txqi->schedule_order))
4187 if (!ieee80211_txq_schedule_airtime_check(local, ac))
4190 list_for_each_entry_safe(iter, tmp, &local->active_txqs[ac],
4195 if (!iter->txq.sta) {
4196 list_move_tail(&iter->schedule_order,
4197 &local->active_txqs[ac]);
4200 sta = container_of(iter->txq.sta, struct sta_info, sta);
4201 if (ieee80211_sta_deficit(sta, ac) < 0)
4202 sta->airtime[ac].deficit += sta->airtime_weight;
4203 list_move_tail(&iter->schedule_order, &local->active_txqs[ac]);
4206 sta = container_of(txqi->txq.sta, struct sta_info, sta);
4207 if (sta->airtime[ac].deficit >= 0)
4210 sta->airtime[ac].deficit += sta->airtime_weight;
4211 list_move_tail(&txqi->schedule_order, &local->active_txqs[ac]);
4212 spin_unlock_bh(&local->active_txq_lock[ac]);
4216 if (!list_empty(&txqi->schedule_order))
4217 list_del_init(&txqi->schedule_order);
4218 spin_unlock_bh(&local->active_txq_lock[ac]);
4222 EXPORT_SYMBOL(ieee80211_txq_may_transmit);
4224 void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac)
4226 struct ieee80211_local *local = hw_to_local(hw);
4228 spin_lock_bh(&local->active_txq_lock[ac]);
4230 if (ieee80211_txq_schedule_airtime_check(local, ac)) {
4231 local->schedule_round[ac]++;
4232 if (!local->schedule_round[ac])
4233 local->schedule_round[ac]++;
4235 local->schedule_round[ac] = 0;
4238 spin_unlock_bh(&local->active_txq_lock[ac]);
4240 EXPORT_SYMBOL(ieee80211_txq_schedule_start);
4242 void __ieee80211_subif_start_xmit(struct sk_buff *skb,
4243 struct net_device *dev,
4248 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4249 struct ieee80211_local *local = sdata->local;
4250 struct sta_info *sta;
4251 struct sk_buff *next;
4254 if (unlikely(!ieee80211_sdata_running(sdata) || skb->len < ETH_HLEN)) {
4259 sk_pacing_shift_update(skb->sk, sdata->local->hw.tx_sk_pacing_shift);
4263 if (ieee80211_vif_is_mesh(&sdata->vif) &&
4264 ieee80211_hw_check(&local->hw, SUPPORT_FAST_XMIT) &&
4265 ieee80211_mesh_xmit_fast(sdata, skb, ctrl_flags))
4268 if (ieee80211_lookup_ra_sta(sdata, skb, &sta))
4274 skb_set_queue_mapping(skb, ieee80211_select_queue(sdata, sta, skb));
4275 ieee80211_aggr_check(sdata, sta, skb);
4278 struct ieee80211_fast_tx *fast_tx;
4280 fast_tx = rcu_dereference(sta->fast_tx);
4283 ieee80211_xmit_fast(sdata, sta, fast_tx, skb))
4287 /* the frame could be fragmented, software-encrypted, and other
4288 * things so we cannot really handle checksum or GSO offload.
4289 * fix it up in software before we handle anything else.
4291 skb = ieee80211_tx_skb_fixup(skb, 0);
4297 skb_list_walk_safe(skb, skb, next) {
4298 skb_mark_not_on_list(skb);
4300 if (skb->protocol == sdata->control_port_protocol)
4301 ctrl_flags |= IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP;
4303 skb = ieee80211_build_hdr(sdata, skb, info_flags,
4304 sta, ctrl_flags, cookie);
4306 kfree_skb_list(next);
4310 dev_sw_netstats_tx_add(dev, 1, skb->len);
4312 ieee80211_xmit(sdata, sta, skb);
4320 ieee80211_tpt_led_trig_tx(local, len);
4324 static int ieee80211_change_da(struct sk_buff *skb, struct sta_info *sta)
4329 err = skb_ensure_writable(skb, ETH_HLEN);
4333 eth = (void *)skb->data;
4334 ether_addr_copy(eth->h_dest, sta->sta.addr);
4339 static bool ieee80211_multicast_to_unicast(struct sk_buff *skb,
4340 struct net_device *dev)
4342 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4343 const struct ethhdr *eth = (void *)skb->data;
4344 const struct vlan_ethhdr *ethvlan = (void *)skb->data;
4347 switch (sdata->vif.type) {
4348 case NL80211_IFTYPE_AP_VLAN:
4349 if (sdata->u.vlan.sta)
4351 if (sdata->wdev.use_4addr)
4354 case NL80211_IFTYPE_AP:
4355 /* check runtime toggle for this bss */
4356 if (!sdata->bss->multicast_to_unicast)
4363 /* multicast to unicast conversion only for some payload */
4364 ethertype = eth->h_proto;
4365 if (ethertype == htons(ETH_P_8021Q) && skb->len >= VLAN_ETH_HLEN)
4366 ethertype = ethvlan->h_vlan_encapsulated_proto;
4367 switch (ethertype) {
4368 case htons(ETH_P_ARP):
4369 case htons(ETH_P_IP):
4370 case htons(ETH_P_IPV6):
4380 ieee80211_convert_to_unicast(struct sk_buff *skb, struct net_device *dev,
4381 struct sk_buff_head *queue)
4383 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4384 struct ieee80211_local *local = sdata->local;
4385 const struct ethhdr *eth = (struct ethhdr *)skb->data;
4386 struct sta_info *sta, *first = NULL;
4387 struct sk_buff *cloned_skb;
4391 list_for_each_entry_rcu(sta, &local->sta_list, list) {
4392 if (sdata != sta->sdata)
4393 /* AP-VLAN mismatch */
4395 if (unlikely(ether_addr_equal(eth->h_source, sta->sta.addr)))
4396 /* do not send back to source */
4402 cloned_skb = skb_clone(skb, GFP_ATOMIC);
4405 if (unlikely(ieee80211_change_da(cloned_skb, sta))) {
4406 dev_kfree_skb(cloned_skb);
4409 __skb_queue_tail(queue, cloned_skb);
4412 if (likely(first)) {
4413 if (unlikely(ieee80211_change_da(skb, first)))
4415 __skb_queue_tail(queue, skb);
4417 /* no STA connected, drop */
4424 __skb_queue_purge(queue);
4425 __skb_queue_tail(queue, skb);
4430 static void ieee80211_mlo_multicast_tx_one(struct ieee80211_sub_if_data *sdata,
4431 struct sk_buff *skb, u32 ctrl_flags,
4432 unsigned int link_id)
4434 struct sk_buff *out;
4436 out = skb_copy(skb, GFP_ATOMIC);
4440 ctrl_flags |= u32_encode_bits(link_id, IEEE80211_TX_CTRL_MLO_LINK);
4441 __ieee80211_subif_start_xmit(out, sdata->dev, 0, ctrl_flags, NULL);
4444 static void ieee80211_mlo_multicast_tx(struct net_device *dev,
4445 struct sk_buff *skb)
4447 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4448 unsigned long links = sdata->vif.valid_links;
4450 u32 ctrl_flags = IEEE80211_TX_CTRL_MCAST_MLO_FIRST_TX;
4452 if (hweight16(links) == 1) {
4453 ctrl_flags |= u32_encode_bits(__ffs(links),
4454 IEEE80211_TX_CTRL_MLO_LINK);
4456 __ieee80211_subif_start_xmit(skb, sdata->dev, 0, ctrl_flags,
4461 for_each_set_bit(link, &links, IEEE80211_MLD_MAX_NUM_LINKS) {
4462 ieee80211_mlo_multicast_tx_one(sdata, skb, ctrl_flags, link);
4469 * ieee80211_subif_start_xmit - netif start_xmit function for 802.3 vifs
4470 * @skb: packet to be sent
4471 * @dev: incoming interface
4473 * On failure skb will be freed.
4475 netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
4476 struct net_device *dev)
4478 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4479 const struct ethhdr *eth = (void *)skb->data;
4481 if (likely(!is_multicast_ether_addr(eth->h_dest)))
4484 if (unlikely(!ieee80211_sdata_running(sdata))) {
4486 return NETDEV_TX_OK;
4489 if (unlikely(ieee80211_multicast_to_unicast(skb, dev))) {
4490 struct sk_buff_head queue;
4492 __skb_queue_head_init(&queue);
4493 ieee80211_convert_to_unicast(skb, dev, &queue);
4494 while ((skb = __skb_dequeue(&queue)))
4495 __ieee80211_subif_start_xmit(skb, dev, 0,
4496 IEEE80211_TX_CTRL_MLO_LINK_UNSPEC,
4498 } else if (sdata->vif.valid_links &&
4499 sdata->vif.type == NL80211_IFTYPE_AP &&
4500 !ieee80211_hw_check(&sdata->local->hw, MLO_MCAST_MULTI_LINK_TX)) {
4501 ieee80211_mlo_multicast_tx(dev, skb);
4504 __ieee80211_subif_start_xmit(skb, dev, 0,
4505 IEEE80211_TX_CTRL_MLO_LINK_UNSPEC,
4509 return NETDEV_TX_OK;
4514 static bool __ieee80211_tx_8023(struct ieee80211_sub_if_data *sdata,
4515 struct sk_buff *skb, struct sta_info *sta,
4518 struct ieee80211_local *local = sdata->local;
4519 struct ieee80211_tx_control control = {};
4520 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4521 struct ieee80211_sta *pubsta = NULL;
4522 unsigned long flags;
4523 int q = info->hw_queue;
4525 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
4527 if (local->queue_stop_reasons[q] ||
4528 (!txpending && !skb_queue_empty(&local->pending[q]))) {
4530 skb_queue_head(&local->pending[q], skb);
4532 skb_queue_tail(&local->pending[q], skb);
4534 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
4539 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
4541 if (sta && sta->uploaded)
4544 control.sta = pubsta;
4546 drv_tx(local, &control, skb);
4551 static bool ieee80211_tx_8023(struct ieee80211_sub_if_data *sdata,
4552 struct sk_buff *skb, struct sta_info *sta,
4555 struct ieee80211_local *local = sdata->local;
4556 struct sk_buff *next;
4559 if (ieee80211_queue_skb(local, sdata, sta, skb))
4562 skb_list_walk_safe(skb, skb, next) {
4563 skb_mark_not_on_list(skb);
4564 if (!__ieee80211_tx_8023(sdata, skb, sta, txpending))
4571 static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata,
4572 struct net_device *dev, struct sta_info *sta,
4573 struct ieee80211_key *key, struct sk_buff *skb)
4575 struct ieee80211_tx_info *info;
4576 struct ieee80211_local *local = sdata->local;
4577 struct tid_ampdu_tx *tid_tx;
4578 struct sk_buff *seg, *next;
4579 unsigned int skbs = 0, len = 0;
4583 queue = ieee80211_select_queue(sdata, sta, skb);
4584 skb_set_queue_mapping(skb, queue);
4586 if (unlikely(test_bit(SCAN_SW_SCANNING, &local->scanning)) &&
4587 test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))
4590 skb = skb_share_check(skb, GFP_ATOMIC);
4594 ieee80211_aggr_check(sdata, sta, skb);
4596 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
4597 tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
4599 if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
4600 /* fall back to non-offload slow path */
4601 __ieee80211_subif_start_xmit(skb, dev, 0,
4602 IEEE80211_TX_CTRL_MLO_LINK_UNSPEC,
4607 if (tid_tx->timeout)
4608 tid_tx->last_tx = jiffies;
4611 skb = ieee80211_tx_skb_fixup(skb, ieee80211_sdata_netdev_features(sdata));
4615 info = IEEE80211_SKB_CB(skb);
4616 memset(info, 0, sizeof(*info));
4618 info->hw_queue = sdata->vif.hw_queue[queue];
4620 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
4621 sdata = container_of(sdata->bss,
4622 struct ieee80211_sub_if_data, u.ap);
4624 info->flags |= IEEE80211_TX_CTL_HW_80211_ENCAP;
4625 info->control.vif = &sdata->vif;
4628 info->control.hw_key = &key->conf;
4630 skb_list_walk_safe(skb, seg, next) {
4634 memcpy(IEEE80211_SKB_CB(seg), info, sizeof(*info));
4637 if (unlikely(skb->sk &&
4638 skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS))
4639 info->ack_frame_id = ieee80211_store_ack_skb(local, skb,
4640 &info->flags, NULL);
4642 dev_sw_netstats_tx_add(dev, skbs, len);
4643 sta->deflink.tx_stats.packets[queue] += skbs;
4644 sta->deflink.tx_stats.bytes[queue] += len;
4646 ieee80211_tpt_led_trig_tx(local, len);
4648 ieee80211_tx_8023(sdata, skb, sta, false);
4656 netdev_tx_t ieee80211_subif_start_xmit_8023(struct sk_buff *skb,
4657 struct net_device *dev)
4659 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4660 struct ethhdr *ehdr = (struct ethhdr *)skb->data;
4661 struct ieee80211_key *key;
4662 struct sta_info *sta;
4664 if (unlikely(!ieee80211_sdata_running(sdata) || skb->len < ETH_HLEN)) {
4666 return NETDEV_TX_OK;
4671 if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) {
4676 if (unlikely(IS_ERR_OR_NULL(sta) || !sta->uploaded ||
4677 !test_sta_flag(sta, WLAN_STA_AUTHORIZED) ||
4678 sdata->control_port_protocol == ehdr->h_proto))
4681 key = rcu_dereference(sta->ptk[sta->ptk_idx]);
4683 key = rcu_dereference(sdata->default_unicast_key);
4685 if (key && (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) ||
4686 key->conf.cipher == WLAN_CIPHER_SUITE_TKIP))
4689 sk_pacing_shift_update(skb->sk, sdata->local->hw.tx_sk_pacing_shift);
4690 ieee80211_8023_xmit(sdata, dev, sta, key, skb);
4694 ieee80211_subif_start_xmit(skb, dev);
4698 return NETDEV_TX_OK;
4702 ieee80211_build_data_template(struct ieee80211_sub_if_data *sdata,
4703 struct sk_buff *skb, u32 info_flags)
4705 struct ieee80211_hdr *hdr;
4706 struct ieee80211_tx_data tx = {
4707 .local = sdata->local,
4710 struct sta_info *sta;
4714 if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) {
4716 skb = ERR_PTR(-EINVAL);
4720 skb = ieee80211_build_hdr(sdata, skb, info_flags, sta,
4721 IEEE80211_TX_CTRL_MLO_LINK_UNSPEC, NULL);
4725 hdr = (void *)skb->data;
4726 tx.sta = sta_info_get(sdata, hdr->addr1);
4729 if (ieee80211_tx_h_select_key(&tx) != TX_CONTINUE) {
4732 return ERR_PTR(-EINVAL);
4741 * ieee80211_clear_tx_pending may not be called in a context where
4742 * it is possible that it packets could come in again.
4744 void ieee80211_clear_tx_pending(struct ieee80211_local *local)
4746 struct sk_buff *skb;
4749 for (i = 0; i < local->hw.queues; i++) {
4750 while ((skb = skb_dequeue(&local->pending[i])) != NULL)
4751 ieee80211_free_txskb(&local->hw, skb);
4756 * Returns false if the frame couldn't be transmitted but was queued instead,
4757 * which in this case means re-queued -- take as an indication to stop sending
4758 * more pending frames.
4760 static bool ieee80211_tx_pending_skb(struct ieee80211_local *local,
4761 struct sk_buff *skb)
4763 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4764 struct ieee80211_sub_if_data *sdata;
4765 struct sta_info *sta;
4766 struct ieee80211_hdr *hdr;
4768 struct ieee80211_chanctx_conf *chanctx_conf;
4770 sdata = vif_to_sdata(info->control.vif);
4772 if (info->control.flags & IEEE80211_TX_INTCFL_NEED_TXPROCESSING) {
4773 /* update band only for non-MLD */
4774 if (!sdata->vif.valid_links) {
4776 rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
4777 if (unlikely(!chanctx_conf)) {
4781 info->band = chanctx_conf->def.chan->band;
4783 result = ieee80211_tx(sdata, NULL, skb, true);
4784 } else if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) {
4785 if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) {
4790 if (IS_ERR(sta) || (sta && !sta->uploaded))
4793 result = ieee80211_tx_8023(sdata, skb, sta, true);
4795 struct sk_buff_head skbs;
4797 __skb_queue_head_init(&skbs);
4798 __skb_queue_tail(&skbs, skb);
4800 hdr = (struct ieee80211_hdr *)skb->data;
4801 sta = sta_info_get(sdata, hdr->addr1);
4803 result = __ieee80211_tx(local, &skbs, sta, true);
4810 * Transmit all pending packets. Called from tasklet.
4812 void ieee80211_tx_pending(struct tasklet_struct *t)
4814 struct ieee80211_local *local = from_tasklet(local, t,
4815 tx_pending_tasklet);
4816 unsigned long flags;
4822 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
4823 for (i = 0; i < local->hw.queues; i++) {
4825 * If queue is stopped by something other than due to pending
4826 * frames, or we have no pending frames, proceed to next queue.
4828 if (local->queue_stop_reasons[i] ||
4829 skb_queue_empty(&local->pending[i]))
4832 while (!skb_queue_empty(&local->pending[i])) {
4833 struct sk_buff *skb = __skb_dequeue(&local->pending[i]);
4834 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4836 if (WARN_ON(!info->control.vif)) {
4837 ieee80211_free_txskb(&local->hw, skb);
4841 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
4844 txok = ieee80211_tx_pending_skb(local, skb);
4845 spin_lock_irqsave(&local->queue_stop_reason_lock,
4851 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
4856 /* functions for drivers to get certain frames */
4858 static void __ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
4859 struct ieee80211_link_data *link,
4860 struct ps_data *ps, struct sk_buff *skb,
4865 int i, have_bits = 0, n1, n2;
4866 struct ieee80211_bss_conf *link_conf = link->conf;
4868 /* Generate bitmap for TIM only if there are any STAs in power save
4870 if (atomic_read(&ps->num_sta_ps) > 0)
4871 /* in the hope that this is faster than
4872 * checking byte-for-byte */
4873 have_bits = !bitmap_empty((unsigned long *)ps->tim,
4874 IEEE80211_MAX_AID+1);
4876 if (ps->dtim_count == 0)
4877 ps->dtim_count = link_conf->dtim_period - 1;
4882 tim = pos = skb_put(skb, 5);
4883 *pos++ = WLAN_EID_TIM;
4885 *pos++ = ps->dtim_count;
4886 *pos++ = link_conf->dtim_period;
4888 if (ps->dtim_count == 0 && !skb_queue_empty(&ps->bc_buf))
4891 ps->dtim_bc_mc = aid0 == 1;
4894 /* Find largest even number N1 so that bits numbered 1 through
4895 * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits
4896 * (N2 + 1) x 8 through 2007 are 0. */
4898 for (i = 0; i < IEEE80211_MAX_TIM_LEN; i++) {
4905 for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) {
4912 /* Bitmap control */
4914 /* Part Virt Bitmap */
4915 skb_put_data(skb, ps->tim + n1, n2 - n1 + 1);
4917 tim[1] = n2 - n1 + 4;
4919 *pos++ = aid0; /* Bitmap control */
4921 if (ieee80211_get_link_sband(link)->band != NL80211_BAND_S1GHZ) {
4923 /* Part Virt Bitmap */
4929 static int ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
4930 struct ieee80211_link_data *link,
4931 struct ps_data *ps, struct sk_buff *skb,
4934 struct ieee80211_local *local = sdata->local;
4937 * Not very nice, but we want to allow the driver to call
4938 * ieee80211_beacon_get() as a response to the set_tim()
4939 * callback. That, however, is already invoked under the
4940 * sta_lock to guarantee consistent and race-free update
4941 * of the tim bitmap in mac80211 and the driver.
4943 if (local->tim_in_locked_section) {
4944 __ieee80211_beacon_add_tim(sdata, link, ps, skb, is_template);
4946 spin_lock_bh(&local->tim_lock);
4947 __ieee80211_beacon_add_tim(sdata, link, ps, skb, is_template);
4948 spin_unlock_bh(&local->tim_lock);
4954 static void ieee80211_set_beacon_cntdwn(struct ieee80211_sub_if_data *sdata,
4955 struct beacon_data *beacon,
4956 struct ieee80211_link_data *link)
4958 u8 *beacon_data, count, max_count = 1;
4959 struct probe_resp *resp;
4960 size_t beacon_data_len;
4964 switch (sdata->vif.type) {
4965 case NL80211_IFTYPE_AP:
4966 beacon_data = beacon->tail;
4967 beacon_data_len = beacon->tail_len;
4969 case NL80211_IFTYPE_ADHOC:
4970 beacon_data = beacon->head;
4971 beacon_data_len = beacon->head_len;
4973 case NL80211_IFTYPE_MESH_POINT:
4974 beacon_data = beacon->head;
4975 beacon_data_len = beacon->head_len;
4981 resp = rcu_dereference(link->u.ap.probe_resp);
4983 bcn_offsets = beacon->cntdwn_counter_offsets;
4984 count = beacon->cntdwn_current_counter;
4985 if (link->conf->csa_active)
4986 max_count = IEEE80211_MAX_CNTDWN_COUNTERS_NUM;
4988 for (i = 0; i < max_count; ++i) {
4989 if (bcn_offsets[i]) {
4990 if (WARN_ON_ONCE(bcn_offsets[i] >= beacon_data_len))
4992 beacon_data[bcn_offsets[i]] = count;
4995 if (sdata->vif.type == NL80211_IFTYPE_AP && resp) {
4996 u16 *resp_offsets = resp->cntdwn_counter_offsets;
4998 resp->data[resp_offsets[i]] = count;
5003 static u8 __ieee80211_beacon_update_cntdwn(struct beacon_data *beacon)
5005 beacon->cntdwn_current_counter--;
5007 /* the counter should never reach 0 */
5008 WARN_ON_ONCE(!beacon->cntdwn_current_counter);
5010 return beacon->cntdwn_current_counter;
5013 u8 ieee80211_beacon_update_cntdwn(struct ieee80211_vif *vif)
5015 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5016 struct beacon_data *beacon = NULL;
5021 if (sdata->vif.type == NL80211_IFTYPE_AP)
5022 beacon = rcu_dereference(sdata->deflink.u.ap.beacon);
5023 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
5024 beacon = rcu_dereference(sdata->u.ibss.presp);
5025 else if (ieee80211_vif_is_mesh(&sdata->vif))
5026 beacon = rcu_dereference(sdata->u.mesh.beacon);
5031 count = __ieee80211_beacon_update_cntdwn(beacon);
5037 EXPORT_SYMBOL(ieee80211_beacon_update_cntdwn);
5039 void ieee80211_beacon_set_cntdwn(struct ieee80211_vif *vif, u8 counter)
5041 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5042 struct beacon_data *beacon = NULL;
5046 if (sdata->vif.type == NL80211_IFTYPE_AP)
5047 beacon = rcu_dereference(sdata->deflink.u.ap.beacon);
5048 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
5049 beacon = rcu_dereference(sdata->u.ibss.presp);
5050 else if (ieee80211_vif_is_mesh(&sdata->vif))
5051 beacon = rcu_dereference(sdata->u.mesh.beacon);
5056 if (counter < beacon->cntdwn_current_counter)
5057 beacon->cntdwn_current_counter = counter;
5062 EXPORT_SYMBOL(ieee80211_beacon_set_cntdwn);
5064 bool ieee80211_beacon_cntdwn_is_complete(struct ieee80211_vif *vif)
5066 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5067 struct beacon_data *beacon = NULL;
5069 size_t beacon_data_len;
5072 if (!ieee80211_sdata_running(sdata))
5076 if (vif->type == NL80211_IFTYPE_AP) {
5077 beacon = rcu_dereference(sdata->deflink.u.ap.beacon);
5078 if (WARN_ON(!beacon || !beacon->tail))
5080 beacon_data = beacon->tail;
5081 beacon_data_len = beacon->tail_len;
5082 } else if (vif->type == NL80211_IFTYPE_ADHOC) {
5083 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
5085 beacon = rcu_dereference(ifibss->presp);
5089 beacon_data = beacon->head;
5090 beacon_data_len = beacon->head_len;
5091 } else if (vif->type == NL80211_IFTYPE_MESH_POINT) {
5092 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
5094 beacon = rcu_dereference(ifmsh->beacon);
5098 beacon_data = beacon->head;
5099 beacon_data_len = beacon->head_len;
5105 if (!beacon->cntdwn_counter_offsets[0])
5108 if (WARN_ON_ONCE(beacon->cntdwn_counter_offsets[0] > beacon_data_len))
5111 if (beacon_data[beacon->cntdwn_counter_offsets[0]] == 1)
5119 EXPORT_SYMBOL(ieee80211_beacon_cntdwn_is_complete);
5121 static int ieee80211_beacon_protect(struct sk_buff *skb,
5122 struct ieee80211_local *local,
5123 struct ieee80211_sub_if_data *sdata,
5124 struct ieee80211_link_data *link)
5126 ieee80211_tx_result res;
5127 struct ieee80211_tx_data tx;
5128 struct sk_buff *check_skb;
5130 memset(&tx, 0, sizeof(tx));
5131 tx.key = rcu_dereference(link->default_beacon_key);
5135 if (unlikely(tx.key->flags & KEY_FLAG_TAINTED)) {
5140 if (!(tx.key->conf.flags & IEEE80211_KEY_FLAG_SW_MGMT_TX) &&
5141 tx.key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
5142 IEEE80211_SKB_CB(skb)->control.hw_key = &tx.key->conf;
5146 __skb_queue_head_init(&tx.skbs);
5147 __skb_queue_tail(&tx.skbs, skb);
5148 res = ieee80211_tx_h_encrypt(&tx);
5149 check_skb = __skb_dequeue(&tx.skbs);
5150 /* we may crash after this, but it'd be a bug in crypto */
5151 WARN_ON(check_skb != skb);
5152 if (WARN_ON_ONCE(res != TX_CONTINUE))
5159 ieee80211_beacon_get_finish(struct ieee80211_hw *hw,
5160 struct ieee80211_vif *vif,
5161 struct ieee80211_link_data *link,
5162 struct ieee80211_mutable_offsets *offs,
5163 struct beacon_data *beacon,
5164 struct sk_buff *skb,
5165 struct ieee80211_chanctx_conf *chanctx_conf,
5168 struct ieee80211_local *local = hw_to_local(hw);
5169 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5170 struct ieee80211_tx_info *info;
5171 enum nl80211_band band;
5172 struct ieee80211_tx_rate_control txrc;
5175 if (offs && beacon) {
5178 for (i = 0; i < IEEE80211_MAX_CNTDWN_COUNTERS_NUM; i++) {
5179 u16 csa_off = beacon->cntdwn_counter_offsets[i];
5184 offs->cntdwn_counter_offs[i] = csa_off_base + csa_off;
5188 band = chanctx_conf->def.chan->band;
5189 info = IEEE80211_SKB_CB(skb);
5190 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
5191 info->flags |= IEEE80211_TX_CTL_NO_ACK;
5194 memset(&txrc, 0, sizeof(txrc));
5196 txrc.sband = local->hw.wiphy->bands[band];
5197 txrc.bss_conf = link->conf;
5199 txrc.reported_rate.idx = -1;
5200 if (sdata->beacon_rate_set && sdata->beacon_rateidx_mask[band])
5201 txrc.rate_idx_mask = sdata->beacon_rateidx_mask[band];
5203 txrc.rate_idx_mask = sdata->rc_rateidx_mask[band];
5205 rate_control_get_rate(sdata, NULL, &txrc);
5207 info->control.vif = vif;
5208 info->control.flags |= u32_encode_bits(link->link_id,
5209 IEEE80211_TX_CTRL_MLO_LINK);
5210 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT |
5211 IEEE80211_TX_CTL_ASSIGN_SEQ |
5212 IEEE80211_TX_CTL_FIRST_FRAGMENT;
5216 ieee80211_beacon_add_mbssid(struct sk_buff *skb, struct beacon_data *beacon,
5219 if (!beacon->mbssid_ies || !beacon->mbssid_ies->cnt ||
5220 i > beacon->mbssid_ies->cnt)
5223 if (i < beacon->mbssid_ies->cnt) {
5224 skb_put_data(skb, beacon->mbssid_ies->elem[i].data,
5225 beacon->mbssid_ies->elem[i].len);
5227 if (beacon->rnr_ies && beacon->rnr_ies->cnt) {
5228 skb_put_data(skb, beacon->rnr_ies->elem[i].data,
5229 beacon->rnr_ies->elem[i].len);
5231 for (i = beacon->mbssid_ies->cnt; i < beacon->rnr_ies->cnt; i++)
5232 skb_put_data(skb, beacon->rnr_ies->elem[i].data,
5233 beacon->rnr_ies->elem[i].len);
5238 /* i == beacon->mbssid_ies->cnt, include all MBSSID elements */
5239 for (i = 0; i < beacon->mbssid_ies->cnt; i++)
5240 skb_put_data(skb, beacon->mbssid_ies->elem[i].data,
5241 beacon->mbssid_ies->elem[i].len);
5244 static struct sk_buff *
5245 ieee80211_beacon_get_ap(struct ieee80211_hw *hw,
5246 struct ieee80211_vif *vif,
5247 struct ieee80211_link_data *link,
5248 struct ieee80211_mutable_offsets *offs,
5250 struct beacon_data *beacon,
5251 struct ieee80211_chanctx_conf *chanctx_conf,
5254 struct ieee80211_local *local = hw_to_local(hw);
5255 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5256 struct ieee80211_if_ap *ap = &sdata->u.ap;
5257 struct sk_buff *skb = NULL;
5258 u16 csa_off_base = 0;
5261 if (beacon->cntdwn_counter_offsets[0]) {
5263 ieee80211_beacon_update_cntdwn(vif);
5265 ieee80211_set_beacon_cntdwn(sdata, beacon, link);
5268 /* headroom, head length,
5269 * tail length, maximum TIM length and multiple BSSID length
5271 mbssid_len = ieee80211_get_mbssid_beacon_len(beacon->mbssid_ies,
5275 skb = dev_alloc_skb(local->tx_headroom + beacon->head_len +
5276 beacon->tail_len + 256 +
5277 local->hw.extra_beacon_tailroom + mbssid_len);
5281 skb_reserve(skb, local->tx_headroom);
5282 skb_put_data(skb, beacon->head, beacon->head_len);
5284 ieee80211_beacon_add_tim(sdata, link, &ap->ps, skb, is_template);
5287 offs->tim_offset = beacon->head_len;
5288 offs->tim_length = skb->len - beacon->head_len;
5289 offs->cntdwn_counter_offs[0] = beacon->cntdwn_counter_offsets[0];
5292 ieee80211_beacon_add_mbssid(skb, beacon, ema_index);
5293 offs->mbssid_off = skb->len - mbssid_len;
5296 /* for AP the csa offsets are from tail */
5297 csa_off_base = skb->len;
5301 skb_put_data(skb, beacon->tail, beacon->tail_len);
5303 if (ieee80211_beacon_protect(skb, local, sdata, link) < 0)
5306 ieee80211_beacon_get_finish(hw, vif, link, offs, beacon, skb,
5307 chanctx_conf, csa_off_base);
5311 static struct ieee80211_ema_beacons *
5312 ieee80211_beacon_get_ap_ema_list(struct ieee80211_hw *hw,
5313 struct ieee80211_vif *vif,
5314 struct ieee80211_link_data *link,
5315 struct ieee80211_mutable_offsets *offs,
5316 bool is_template, struct beacon_data *beacon,
5317 struct ieee80211_chanctx_conf *chanctx_conf)
5319 struct ieee80211_ema_beacons *ema = NULL;
5321 if (!beacon->mbssid_ies || !beacon->mbssid_ies->cnt)
5324 ema = kzalloc(struct_size(ema, bcn, beacon->mbssid_ies->cnt),
5329 for (ema->cnt = 0; ema->cnt < beacon->mbssid_ies->cnt; ema->cnt++) {
5330 ema->bcn[ema->cnt].skb =
5331 ieee80211_beacon_get_ap(hw, vif, link,
5332 &ema->bcn[ema->cnt].offs,
5333 is_template, beacon,
5334 chanctx_conf, ema->cnt);
5335 if (!ema->bcn[ema->cnt].skb)
5339 if (ema->cnt == beacon->mbssid_ies->cnt)
5342 ieee80211_beacon_free_ema_list(ema);
5346 #define IEEE80211_INCLUDE_ALL_MBSSID_ELEMS -1
5348 static struct sk_buff *
5349 __ieee80211_beacon_get(struct ieee80211_hw *hw,
5350 struct ieee80211_vif *vif,
5351 struct ieee80211_mutable_offsets *offs,
5353 unsigned int link_id,
5355 struct ieee80211_ema_beacons **ema_beacons)
5357 struct ieee80211_local *local = hw_to_local(hw);
5358 struct beacon_data *beacon = NULL;
5359 struct sk_buff *skb = NULL;
5360 struct ieee80211_sub_if_data *sdata = NULL;
5361 struct ieee80211_chanctx_conf *chanctx_conf;
5362 struct ieee80211_link_data *link;
5366 sdata = vif_to_sdata(vif);
5367 link = rcu_dereference(sdata->link[link_id]);
5371 rcu_dereference(link->conf->chanctx_conf);
5373 if (!ieee80211_sdata_running(sdata) || !chanctx_conf)
5377 memset(offs, 0, sizeof(*offs));
5379 if (sdata->vif.type == NL80211_IFTYPE_AP) {
5380 beacon = rcu_dereference(link->u.ap.beacon);
5386 ieee80211_beacon_get_ap_ema_list(hw, vif, link,
5392 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) {
5393 if (ema_index >= beacon->mbssid_ies->cnt)
5394 goto out; /* End of MBSSID elements */
5396 if (ema_index <= IEEE80211_INCLUDE_ALL_MBSSID_ELEMS)
5397 ema_index = beacon->mbssid_ies->cnt;
5402 skb = ieee80211_beacon_get_ap(hw, vif, link, offs,
5403 is_template, beacon,
5407 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
5408 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
5409 struct ieee80211_hdr *hdr;
5411 beacon = rcu_dereference(ifibss->presp);
5415 if (beacon->cntdwn_counter_offsets[0]) {
5417 __ieee80211_beacon_update_cntdwn(beacon);
5419 ieee80211_set_beacon_cntdwn(sdata, beacon, link);
5422 skb = dev_alloc_skb(local->tx_headroom + beacon->head_len +
5423 local->hw.extra_beacon_tailroom);
5426 skb_reserve(skb, local->tx_headroom);
5427 skb_put_data(skb, beacon->head, beacon->head_len);
5429 hdr = (struct ieee80211_hdr *) skb->data;
5430 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
5431 IEEE80211_STYPE_BEACON);
5433 ieee80211_beacon_get_finish(hw, vif, link, offs, beacon, skb,
5435 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
5436 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
5438 beacon = rcu_dereference(ifmsh->beacon);
5442 if (beacon->cntdwn_counter_offsets[0]) {
5444 /* TODO: For mesh csa_counter is in TU, so
5445 * decrementing it by one isn't correct, but
5446 * for now we leave it consistent with overall
5447 * mac80211's behavior.
5449 __ieee80211_beacon_update_cntdwn(beacon);
5451 ieee80211_set_beacon_cntdwn(sdata, beacon, link);
5454 if (ifmsh->sync_ops)
5455 ifmsh->sync_ops->adjust_tsf(sdata, beacon);
5457 skb = dev_alloc_skb(local->tx_headroom +
5461 local->hw.extra_beacon_tailroom);
5464 skb_reserve(skb, local->tx_headroom);
5465 skb_put_data(skb, beacon->head, beacon->head_len);
5466 ieee80211_beacon_add_tim(sdata, link, &ifmsh->ps, skb,
5470 offs->tim_offset = beacon->head_len;
5471 offs->tim_length = skb->len - beacon->head_len;
5474 skb_put_data(skb, beacon->tail, beacon->tail_len);
5475 ieee80211_beacon_get_finish(hw, vif, link, offs, beacon, skb,
5489 ieee80211_beacon_get_template(struct ieee80211_hw *hw,
5490 struct ieee80211_vif *vif,
5491 struct ieee80211_mutable_offsets *offs,
5492 unsigned int link_id)
5494 return __ieee80211_beacon_get(hw, vif, offs, true, link_id,
5495 IEEE80211_INCLUDE_ALL_MBSSID_ELEMS, NULL);
5497 EXPORT_SYMBOL(ieee80211_beacon_get_template);
5500 ieee80211_beacon_get_template_ema_index(struct ieee80211_hw *hw,
5501 struct ieee80211_vif *vif,
5502 struct ieee80211_mutable_offsets *offs,
5503 unsigned int link_id, u8 ema_index)
5505 return __ieee80211_beacon_get(hw, vif, offs, true, link_id, ema_index,
5508 EXPORT_SYMBOL(ieee80211_beacon_get_template_ema_index);
5510 void ieee80211_beacon_free_ema_list(struct ieee80211_ema_beacons *ema_beacons)
5517 for (i = 0; i < ema_beacons->cnt; i++)
5518 kfree_skb(ema_beacons->bcn[i].skb);
5522 EXPORT_SYMBOL(ieee80211_beacon_free_ema_list);
5524 struct ieee80211_ema_beacons *
5525 ieee80211_beacon_get_template_ema_list(struct ieee80211_hw *hw,
5526 struct ieee80211_vif *vif,
5527 unsigned int link_id)
5529 struct ieee80211_ema_beacons *ema_beacons = NULL;
5531 WARN_ON(__ieee80211_beacon_get(hw, vif, NULL, true, link_id, 0,
5536 EXPORT_SYMBOL(ieee80211_beacon_get_template_ema_list);
5538 struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
5539 struct ieee80211_vif *vif,
5540 u16 *tim_offset, u16 *tim_length,
5541 unsigned int link_id)
5543 struct ieee80211_mutable_offsets offs = {};
5544 struct sk_buff *bcn = __ieee80211_beacon_get(hw, vif, &offs, false,
5546 IEEE80211_INCLUDE_ALL_MBSSID_ELEMS,
5548 struct sk_buff *copy;
5555 *tim_offset = offs.tim_offset;
5558 *tim_length = offs.tim_length;
5560 if (ieee80211_hw_check(hw, BEACON_TX_STATUS) ||
5561 !hw_to_local(hw)->monitors)
5564 /* send a copy to monitor interfaces */
5565 copy = skb_copy(bcn, GFP_ATOMIC);
5569 shift = ieee80211_vif_get_shift(vif);
5570 ieee80211_tx_monitor(hw_to_local(hw), copy, 1, shift, false, NULL);
5574 EXPORT_SYMBOL(ieee80211_beacon_get_tim);
5576 struct sk_buff *ieee80211_proberesp_get(struct ieee80211_hw *hw,
5577 struct ieee80211_vif *vif)
5579 struct sk_buff *skb = NULL;
5580 struct probe_resp *presp = NULL;
5581 struct ieee80211_hdr *hdr;
5582 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5584 if (sdata->vif.type != NL80211_IFTYPE_AP)
5588 presp = rcu_dereference(sdata->deflink.u.ap.probe_resp);
5592 skb = dev_alloc_skb(presp->len);
5596 skb_put_data(skb, presp->data, presp->len);
5598 hdr = (struct ieee80211_hdr *) skb->data;
5599 memset(hdr->addr1, 0, sizeof(hdr->addr1));
5605 EXPORT_SYMBOL(ieee80211_proberesp_get);
5607 struct sk_buff *ieee80211_get_fils_discovery_tmpl(struct ieee80211_hw *hw,
5608 struct ieee80211_vif *vif)
5610 struct sk_buff *skb = NULL;
5611 struct fils_discovery_data *tmpl = NULL;
5612 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5614 if (sdata->vif.type != NL80211_IFTYPE_AP)
5618 tmpl = rcu_dereference(sdata->deflink.u.ap.fils_discovery);
5624 skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom + tmpl->len);
5626 skb_reserve(skb, sdata->local->hw.extra_tx_headroom);
5627 skb_put_data(skb, tmpl->data, tmpl->len);
5633 EXPORT_SYMBOL(ieee80211_get_fils_discovery_tmpl);
5636 ieee80211_get_unsol_bcast_probe_resp_tmpl(struct ieee80211_hw *hw,
5637 struct ieee80211_vif *vif)
5639 struct sk_buff *skb = NULL;
5640 struct unsol_bcast_probe_resp_data *tmpl = NULL;
5641 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5643 if (sdata->vif.type != NL80211_IFTYPE_AP)
5647 tmpl = rcu_dereference(sdata->deflink.u.ap.unsol_bcast_probe_resp);
5653 skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom + tmpl->len);
5655 skb_reserve(skb, sdata->local->hw.extra_tx_headroom);
5656 skb_put_data(skb, tmpl->data, tmpl->len);
5662 EXPORT_SYMBOL(ieee80211_get_unsol_bcast_probe_resp_tmpl);
5664 struct sk_buff *ieee80211_pspoll_get(struct ieee80211_hw *hw,
5665 struct ieee80211_vif *vif)
5667 struct ieee80211_sub_if_data *sdata;
5668 struct ieee80211_pspoll *pspoll;
5669 struct ieee80211_local *local;
5670 struct sk_buff *skb;
5672 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
5675 sdata = vif_to_sdata(vif);
5676 local = sdata->local;
5678 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll));
5682 skb_reserve(skb, local->hw.extra_tx_headroom);
5684 pspoll = skb_put_zero(skb, sizeof(*pspoll));
5685 pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
5686 IEEE80211_STYPE_PSPOLL);
5687 pspoll->aid = cpu_to_le16(sdata->vif.cfg.aid);
5689 /* aid in PS-Poll has its two MSBs each set to 1 */
5690 pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
5692 memcpy(pspoll->bssid, sdata->deflink.u.mgd.bssid, ETH_ALEN);
5693 memcpy(pspoll->ta, vif->addr, ETH_ALEN);
5697 EXPORT_SYMBOL(ieee80211_pspoll_get);
5699 struct sk_buff *ieee80211_nullfunc_get(struct ieee80211_hw *hw,
5700 struct ieee80211_vif *vif,
5701 int link_id, bool qos_ok)
5703 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5704 struct ieee80211_local *local = sdata->local;
5705 struct ieee80211_link_data *link = NULL;
5706 struct ieee80211_hdr_3addr *nullfunc;
5707 struct sk_buff *skb;
5710 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
5713 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
5714 sizeof(*nullfunc) + 2);
5720 struct sta_info *sta;
5722 sta = sta_info_get(sdata, vif->cfg.ap_addr);
5723 qos = sta && sta->sta.wme;
5727 link = rcu_dereference(sdata->link[link_id]);
5728 if (WARN_ON_ONCE(!link)) {
5735 skb_reserve(skb, local->hw.extra_tx_headroom);
5737 nullfunc = skb_put_zero(skb, sizeof(*nullfunc));
5738 nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
5739 IEEE80211_STYPE_NULLFUNC |
5740 IEEE80211_FCTL_TODS);
5742 __le16 qoshdr = cpu_to_le16(7);
5744 BUILD_BUG_ON((IEEE80211_STYPE_QOS_NULLFUNC |
5745 IEEE80211_STYPE_NULLFUNC) !=
5746 IEEE80211_STYPE_QOS_NULLFUNC);
5747 nullfunc->frame_control |=
5748 cpu_to_le16(IEEE80211_STYPE_QOS_NULLFUNC);
5750 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
5751 skb_put_data(skb, &qoshdr, sizeof(qoshdr));
5755 memcpy(nullfunc->addr1, link->conf->bssid, ETH_ALEN);
5756 memcpy(nullfunc->addr2, link->conf->addr, ETH_ALEN);
5757 memcpy(nullfunc->addr3, link->conf->bssid, ETH_ALEN);
5759 memcpy(nullfunc->addr1, vif->cfg.ap_addr, ETH_ALEN);
5760 memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
5761 memcpy(nullfunc->addr3, vif->cfg.ap_addr, ETH_ALEN);
5767 EXPORT_SYMBOL(ieee80211_nullfunc_get);
5769 struct sk_buff *ieee80211_probereq_get(struct ieee80211_hw *hw,
5771 const u8 *ssid, size_t ssid_len,
5774 struct ieee80211_local *local = hw_to_local(hw);
5775 struct ieee80211_hdr_3addr *hdr;
5776 struct sk_buff *skb;
5780 ie_ssid_len = 2 + ssid_len;
5782 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*hdr) +
5783 ie_ssid_len + tailroom);
5787 skb_reserve(skb, local->hw.extra_tx_headroom);
5789 hdr = skb_put_zero(skb, sizeof(*hdr));
5790 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
5791 IEEE80211_STYPE_PROBE_REQ);
5792 eth_broadcast_addr(hdr->addr1);
5793 memcpy(hdr->addr2, src_addr, ETH_ALEN);
5794 eth_broadcast_addr(hdr->addr3);
5796 pos = skb_put(skb, ie_ssid_len);
5797 *pos++ = WLAN_EID_SSID;
5800 memcpy(pos, ssid, ssid_len);
5805 EXPORT_SYMBOL(ieee80211_probereq_get);
5807 void ieee80211_rts_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5808 const void *frame, size_t frame_len,
5809 const struct ieee80211_tx_info *frame_txctl,
5810 struct ieee80211_rts *rts)
5812 const struct ieee80211_hdr *hdr = frame;
5814 rts->frame_control =
5815 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
5816 rts->duration = ieee80211_rts_duration(hw, vif, frame_len,
5818 memcpy(rts->ra, hdr->addr1, sizeof(rts->ra));
5819 memcpy(rts->ta, hdr->addr2, sizeof(rts->ta));
5821 EXPORT_SYMBOL(ieee80211_rts_get);
5823 void ieee80211_ctstoself_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5824 const void *frame, size_t frame_len,
5825 const struct ieee80211_tx_info *frame_txctl,
5826 struct ieee80211_cts *cts)
5828 const struct ieee80211_hdr *hdr = frame;
5830 cts->frame_control =
5831 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
5832 cts->duration = ieee80211_ctstoself_duration(hw, vif,
5833 frame_len, frame_txctl);
5834 memcpy(cts->ra, hdr->addr1, sizeof(cts->ra));
5836 EXPORT_SYMBOL(ieee80211_ctstoself_get);
5839 ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
5840 struct ieee80211_vif *vif)
5842 struct ieee80211_local *local = hw_to_local(hw);
5843 struct sk_buff *skb = NULL;
5844 struct ieee80211_tx_data tx;
5845 struct ieee80211_sub_if_data *sdata;
5847 struct ieee80211_tx_info *info;
5848 struct ieee80211_chanctx_conf *chanctx_conf;
5850 sdata = vif_to_sdata(vif);
5853 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
5858 if (sdata->vif.type == NL80211_IFTYPE_AP) {
5859 struct beacon_data *beacon =
5860 rcu_dereference(sdata->deflink.u.ap.beacon);
5862 if (!beacon || !beacon->head)
5865 ps = &sdata->u.ap.ps;
5866 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
5867 ps = &sdata->u.mesh.ps;
5872 if (ps->dtim_count != 0 || !ps->dtim_bc_mc)
5873 goto out; /* send buffered bc/mc only after DTIM beacon */
5876 skb = skb_dequeue(&ps->bc_buf);
5879 local->total_ps_buffered--;
5881 if (!skb_queue_empty(&ps->bc_buf) && skb->len >= 2) {
5882 struct ieee80211_hdr *hdr =
5883 (struct ieee80211_hdr *) skb->data;
5884 /* more buffered multicast/broadcast frames ==> set
5885 * MoreData flag in IEEE 802.11 header to inform PS
5887 hdr->frame_control |=
5888 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
5891 if (sdata->vif.type == NL80211_IFTYPE_AP)
5892 sdata = IEEE80211_DEV_TO_SUB_IF(skb->dev);
5893 if (!ieee80211_tx_prepare(sdata, &tx, NULL, skb))
5895 ieee80211_free_txskb(hw, skb);
5898 info = IEEE80211_SKB_CB(skb);
5900 tx.flags |= IEEE80211_TX_PS_BUFFERED;
5901 info->band = chanctx_conf->def.chan->band;
5903 if (invoke_tx_handlers(&tx))
5910 EXPORT_SYMBOL(ieee80211_get_buffered_bc);
5912 int ieee80211_reserve_tid(struct ieee80211_sta *pubsta, u8 tid)
5914 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
5915 struct ieee80211_sub_if_data *sdata = sta->sdata;
5916 struct ieee80211_local *local = sdata->local;
5920 lockdep_assert_held(&local->sta_mtx);
5922 /* only some cases are supported right now */
5923 switch (sdata->vif.type) {
5924 case NL80211_IFTYPE_STATION:
5925 case NL80211_IFTYPE_AP:
5926 case NL80211_IFTYPE_AP_VLAN:
5933 if (WARN_ON(tid >= IEEE80211_NUM_UPS))
5936 if (sta->reserved_tid == tid) {
5941 if (sta->reserved_tid != IEEE80211_TID_UNRESERVED) {
5942 sdata_err(sdata, "TID reservation already active\n");
5947 ieee80211_stop_vif_queues(sdata->local, sdata,
5948 IEEE80211_QUEUE_STOP_REASON_RESERVE_TID);
5952 /* Tear down BA sessions so we stop aggregating on this TID */
5953 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION)) {
5954 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
5955 __ieee80211_stop_tx_ba_session(sta, tid,
5956 AGG_STOP_LOCAL_REQUEST);
5959 queues = BIT(sdata->vif.hw_queue[ieee802_1d_to_ac[tid]]);
5960 __ieee80211_flush_queues(local, sdata, queues, false);
5962 sta->reserved_tid = tid;
5964 ieee80211_wake_vif_queues(local, sdata,
5965 IEEE80211_QUEUE_STOP_REASON_RESERVE_TID);
5967 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION))
5968 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
5974 EXPORT_SYMBOL(ieee80211_reserve_tid);
5976 void ieee80211_unreserve_tid(struct ieee80211_sta *pubsta, u8 tid)
5978 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
5979 struct ieee80211_sub_if_data *sdata = sta->sdata;
5981 lockdep_assert_held(&sdata->local->sta_mtx);
5983 /* only some cases are supported right now */
5984 switch (sdata->vif.type) {
5985 case NL80211_IFTYPE_STATION:
5986 case NL80211_IFTYPE_AP:
5987 case NL80211_IFTYPE_AP_VLAN:
5994 if (tid != sta->reserved_tid) {
5995 sdata_err(sdata, "TID to unreserve (%d) isn't reserved\n", tid);
5999 sta->reserved_tid = IEEE80211_TID_UNRESERVED;
6001 EXPORT_SYMBOL(ieee80211_unreserve_tid);
6003 void __ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata,
6004 struct sk_buff *skb, int tid, int link_id,
6005 enum nl80211_band band)
6007 const struct ieee80211_hdr *hdr = (void *)skb->data;
6008 int ac = ieee80211_ac_from_tid(tid);
6011 skb_reset_mac_header(skb);
6012 skb_set_queue_mapping(skb, ac);
6013 skb->priority = tid;
6015 skb->dev = sdata->dev;
6017 BUILD_BUG_ON(IEEE80211_LINK_UNSPECIFIED < IEEE80211_MLD_MAX_NUM_LINKS);
6018 BUILD_BUG_ON(!FIELD_FIT(IEEE80211_TX_CTRL_MLO_LINK,
6019 IEEE80211_LINK_UNSPECIFIED));
6021 if (!sdata->vif.valid_links) {
6023 } else if (link_id >= 0) {
6025 } else if (memcmp(sdata->vif.addr, hdr->addr2, ETH_ALEN) == 0) {
6026 /* address from the MLD */
6027 link = IEEE80211_LINK_UNSPECIFIED;
6029 /* otherwise must be addressed from a link */
6031 for (link = 0; link < ARRAY_SIZE(sdata->vif.link_conf); link++) {
6032 struct ieee80211_bss_conf *link_conf;
6034 link_conf = rcu_dereference(sdata->vif.link_conf[link]);
6037 if (memcmp(link_conf->addr, hdr->addr2, ETH_ALEN) == 0)
6042 if (WARN_ON_ONCE(link == ARRAY_SIZE(sdata->vif.link_conf)))
6043 link = ffs(sdata->vif.valid_links) - 1;
6046 IEEE80211_SKB_CB(skb)->control.flags |=
6047 u32_encode_bits(link, IEEE80211_TX_CTRL_MLO_LINK);
6050 * The other path calling ieee80211_xmit is from the tasklet,
6051 * and while we can handle concurrent transmissions locking
6052 * requirements are that we do not come into tx with bhs on.
6055 IEEE80211_SKB_CB(skb)->band = band;
6056 ieee80211_xmit(sdata, NULL, skb);
6060 void ieee80211_tx_skb_tid(struct ieee80211_sub_if_data *sdata,
6061 struct sk_buff *skb, int tid, int link_id)
6063 struct ieee80211_chanctx_conf *chanctx_conf;
6064 enum nl80211_band band;
6067 if (!sdata->vif.valid_links) {
6068 WARN_ON(link_id >= 0);
6070 rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
6071 if (WARN_ON(!chanctx_conf)) {
6076 band = chanctx_conf->def.chan->band;
6078 WARN_ON(link_id >= 0 &&
6079 !(sdata->vif.valid_links & BIT(link_id)));
6080 /* MLD transmissions must not rely on the band */
6084 __ieee80211_tx_skb_tid_band(sdata, skb, tid, link_id, band);
6088 int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev,
6089 const u8 *buf, size_t len,
6090 const u8 *dest, __be16 proto, bool unencrypted,
6091 int link_id, u64 *cookie)
6093 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
6094 struct ieee80211_local *local = sdata->local;
6095 struct sta_info *sta;
6096 struct sk_buff *skb;
6097 struct ethhdr *ehdr;
6102 /* Only accept CONTROL_PORT_PROTOCOL configured in CONNECT/ASSOCIATE
6103 * or Pre-Authentication
6105 if (proto != sdata->control_port_protocol &&
6106 proto != cpu_to_be16(ETH_P_PREAUTH))
6109 if (proto == sdata->control_port_protocol)
6110 ctrl_flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO |
6111 IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP;
6114 flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
6117 ctrl_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
6119 flags |= IEEE80211_TX_INTFL_NL80211_FRAME_TX;
6121 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
6122 sizeof(struct ethhdr) + len);
6126 skb_reserve(skb, local->hw.extra_tx_headroom + sizeof(struct ethhdr));
6128 skb_put_data(skb, buf, len);
6130 ehdr = skb_push(skb, sizeof(struct ethhdr));
6131 memcpy(ehdr->h_dest, dest, ETH_ALEN);
6133 /* we may override the SA for MLO STA later */
6135 ctrl_flags |= u32_encode_bits(IEEE80211_LINK_UNSPECIFIED,
6136 IEEE80211_TX_CTRL_MLO_LINK);
6137 memcpy(ehdr->h_source, sdata->vif.addr, ETH_ALEN);
6139 struct ieee80211_bss_conf *link_conf;
6141 ctrl_flags |= u32_encode_bits(link_id,
6142 IEEE80211_TX_CTRL_MLO_LINK);
6145 link_conf = rcu_dereference(sdata->vif.link_conf[link_id]);
6151 memcpy(ehdr->h_source, link_conf->addr, ETH_ALEN);
6155 ehdr->h_proto = proto;
6158 skb->protocol = proto;
6159 skb_reset_network_header(skb);
6160 skb_reset_mac_header(skb);
6162 if (local->hw.queues < IEEE80211_NUM_ACS)
6165 /* update QoS header to prioritize control port frames if possible,
6166 * priorization also happens for control port frames send over
6170 err = ieee80211_lookup_ra_sta(sdata, skb, &sta);
6178 u16 queue = ieee80211_select_queue(sdata, sta, skb);
6180 skb_set_queue_mapping(skb, queue);
6183 * for MLO STA, the SA should be the AP MLD address, but
6184 * the link ID has been selected already
6186 if (sta && sta->sta.mlo)
6187 memcpy(ehdr->h_source, sdata->vif.addr, ETH_ALEN);
6192 /* mutex lock is only needed for incrementing the cookie counter */
6193 mutex_lock(&local->mtx);
6196 __ieee80211_subif_start_xmit(skb, skb->dev, flags, ctrl_flags, cookie);
6199 mutex_unlock(&local->mtx);
6204 int ieee80211_probe_mesh_link(struct wiphy *wiphy, struct net_device *dev,
6205 const u8 *buf, size_t len)
6207 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
6208 struct ieee80211_local *local = sdata->local;
6209 struct sk_buff *skb;
6211 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len +
6212 30 + /* header size */
6213 18); /* 11s header size */
6217 skb_reserve(skb, local->hw.extra_tx_headroom);
6218 skb_put_data(skb, buf, len);
6221 skb->protocol = htons(ETH_P_802_3);
6222 skb_reset_network_header(skb);
6223 skb_reset_mac_header(skb);
6226 __ieee80211_subif_start_xmit(skb, skb->dev, 0,
6227 IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP,