2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
5 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
6 * Copyright 2013-2014 Intel Mobile Communications GmbH
7 * Copyright (C) 2018 Intel Corporation
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 * Transmit and frame generation functions.
17 #include <linux/kernel.h>
18 #include <linux/slab.h>
19 #include <linux/skbuff.h>
20 #include <linux/if_vlan.h>
21 #include <linux/etherdevice.h>
22 #include <linux/bitmap.h>
23 #include <linux/rcupdate.h>
24 #include <linux/export.h>
25 #include <net/net_namespace.h>
26 #include <net/ieee80211_radiotap.h>
27 #include <net/cfg80211.h>
28 #include <net/mac80211.h>
29 #include <net/codel.h>
30 #include <net/codel_impl.h>
31 #include <asm/unaligned.h>
32 #include <net/fq_impl.h>
34 #include "ieee80211_i.h"
35 #include "driver-ops.h"
45 static inline void ieee80211_tx_stats(struct net_device
*dev
, u32 len
)
47 struct pcpu_sw_netstats
*tstats
= this_cpu_ptr(dev
->tstats
);
49 u64_stats_update_begin(&tstats
->syncp
);
51 tstats
->tx_bytes
+= len
;
52 u64_stats_update_end(&tstats
->syncp
);
55 static __le16
ieee80211_duration(struct ieee80211_tx_data
*tx
,
56 struct sk_buff
*skb
, int group_addr
,
59 int rate
, mrate
, erp
, dur
, i
, shift
= 0;
60 struct ieee80211_rate
*txrate
;
61 struct ieee80211_local
*local
= tx
->local
;
62 struct ieee80211_supported_band
*sband
;
63 struct ieee80211_hdr
*hdr
;
64 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
65 struct ieee80211_chanctx_conf
*chanctx_conf
;
68 /* assume HW handles this */
69 if (tx
->rate
.flags
& (IEEE80211_TX_RC_MCS
| IEEE80211_TX_RC_VHT_MCS
))
73 chanctx_conf
= rcu_dereference(tx
->sdata
->vif
.chanctx_conf
);
75 shift
= ieee80211_chandef_get_shift(&chanctx_conf
->def
);
76 rate_flags
= ieee80211_chandef_rate_flags(&chanctx_conf
->def
);
81 if (WARN_ON_ONCE(tx
->rate
.idx
< 0))
84 sband
= local
->hw
.wiphy
->bands
[info
->band
];
85 txrate
= &sband
->bitrates
[tx
->rate
.idx
];
87 erp
= txrate
->flags
& IEEE80211_RATE_ERP_G
;
90 * data and mgmt (except PS Poll):
92 * - during contention period:
93 * if addr1 is group address: 0
94 * if more fragments = 0 and addr1 is individual address: time to
95 * transmit one ACK plus SIFS
96 * if more fragments = 1 and addr1 is individual address: time to
97 * transmit next fragment plus 2 x ACK plus 3 x SIFS
100 * - control response frame (CTS or ACK) shall be transmitted using the
101 * same rate as the immediately previous frame in the frame exchange
102 * sequence, if this rate belongs to the PHY mandatory rates, or else
103 * at the highest possible rate belonging to the PHY rates in the
106 hdr
= (struct ieee80211_hdr
*)skb
->data
;
107 if (ieee80211_is_ctl(hdr
->frame_control
)) {
108 /* TODO: These control frames are not currently sent by
109 * mac80211, but should they be implemented, this function
110 * needs to be updated to support duration field calculation.
112 * RTS: time needed to transmit pending data/mgmt frame plus
113 * one CTS frame plus one ACK frame plus 3 x SIFS
114 * CTS: duration of immediately previous RTS minus time
115 * required to transmit CTS and its SIFS
116 * ACK: 0 if immediately previous directed data/mgmt had
117 * more=0, with more=1 duration in ACK frame is duration
118 * from previous frame minus time needed to transmit ACK
120 * PS Poll: BIT(15) | BIT(14) | aid
126 if (0 /* FIX: data/mgmt during CFP */)
127 return cpu_to_le16(32768);
129 if (group_addr
) /* Group address as the destination - no ACK */
132 /* Individual destination address:
133 * IEEE 802.11, Ch. 9.6 (after IEEE 802.11g changes)
134 * CTS and ACK frames shall be transmitted using the highest rate in
135 * basic rate set that is less than or equal to the rate of the
136 * immediately previous frame and that is using the same modulation
137 * (CCK or OFDM). If no basic rate set matches with these requirements,
138 * the highest mandatory rate of the PHY that is less than or equal to
139 * the rate of the previous frame is used.
140 * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps
143 /* use lowest available if everything fails */
144 mrate
= sband
->bitrates
[0].bitrate
;
145 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
146 struct ieee80211_rate
*r
= &sband
->bitrates
[i
];
148 if (r
->bitrate
> txrate
->bitrate
)
151 if ((rate_flags
& r
->flags
) != rate_flags
)
154 if (tx
->sdata
->vif
.bss_conf
.basic_rates
& BIT(i
))
155 rate
= DIV_ROUND_UP(r
->bitrate
, 1 << shift
);
157 switch (sband
->band
) {
158 case NL80211_BAND_2GHZ
: {
160 if (tx
->sdata
->flags
& IEEE80211_SDATA_OPERATING_GMODE
)
161 flag
= IEEE80211_RATE_MANDATORY_G
;
163 flag
= IEEE80211_RATE_MANDATORY_B
;
168 case NL80211_BAND_5GHZ
:
169 if (r
->flags
& IEEE80211_RATE_MANDATORY_A
)
172 case NL80211_BAND_60GHZ
:
173 /* TODO, for now fall through */
174 case NUM_NL80211_BANDS
:
180 /* No matching basic rate found; use highest suitable mandatory
182 rate
= DIV_ROUND_UP(mrate
, 1 << shift
);
185 /* Don't calculate ACKs for QoS Frames with NoAck Policy set */
186 if (ieee80211_is_data_qos(hdr
->frame_control
) &&
187 *(ieee80211_get_qos_ctl(hdr
)) & IEEE80211_QOS_CTL_ACK_POLICY_NOACK
)
190 /* Time needed to transmit ACK
191 * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up
192 * to closest integer */
193 dur
= ieee80211_frame_duration(sband
->band
, 10, rate
, erp
,
194 tx
->sdata
->vif
.bss_conf
.use_short_preamble
,
198 /* Frame is fragmented: duration increases with time needed to
199 * transmit next fragment plus ACK and 2 x SIFS. */
200 dur
*= 2; /* ACK + SIFS */
202 dur
+= ieee80211_frame_duration(sband
->band
, next_frag_len
,
203 txrate
->bitrate
, erp
,
204 tx
->sdata
->vif
.bss_conf
.use_short_preamble
,
208 return cpu_to_le16(dur
);
212 static ieee80211_tx_result debug_noinline
213 ieee80211_tx_h_dynamic_ps(struct ieee80211_tx_data
*tx
)
215 struct ieee80211_local
*local
= tx
->local
;
216 struct ieee80211_if_managed
*ifmgd
;
218 /* driver doesn't support power save */
219 if (!ieee80211_hw_check(&local
->hw
, SUPPORTS_PS
))
222 /* hardware does dynamic power save */
223 if (ieee80211_hw_check(&local
->hw
, SUPPORTS_DYNAMIC_PS
))
226 /* dynamic power save disabled */
227 if (local
->hw
.conf
.dynamic_ps_timeout
<= 0)
230 /* we are scanning, don't enable power save */
234 if (!local
->ps_sdata
)
237 /* No point if we're going to suspend */
238 if (local
->quiescing
)
241 /* dynamic ps is supported only in managed mode */
242 if (tx
->sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
245 ifmgd
= &tx
->sdata
->u
.mgd
;
248 * Don't wakeup from power save if u-apsd is enabled, voip ac has
249 * u-apsd enabled and the frame is in voip class. This effectively
250 * means that even if all access categories have u-apsd enabled, in
251 * practise u-apsd is only used with the voip ac. This is a
252 * workaround for the case when received voip class packets do not
253 * have correct qos tag for some reason, due the network or the
256 * Note: ifmgd->uapsd_queues access is racy here. If the value is
257 * changed via debugfs, user needs to reassociate manually to have
258 * everything in sync.
260 if ((ifmgd
->flags
& IEEE80211_STA_UAPSD_ENABLED
) &&
261 (ifmgd
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
) &&
262 skb_get_queue_mapping(tx
->skb
) == IEEE80211_AC_VO
)
265 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
) {
266 ieee80211_stop_queues_by_reason(&local
->hw
,
267 IEEE80211_MAX_QUEUE_MAP
,
268 IEEE80211_QUEUE_STOP_REASON_PS
,
270 ifmgd
->flags
&= ~IEEE80211_STA_NULLFUNC_ACKED
;
271 ieee80211_queue_work(&local
->hw
,
272 &local
->dynamic_ps_disable_work
);
275 /* Don't restart the timer if we're not disassociated */
276 if (!ifmgd
->associated
)
279 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
280 msecs_to_jiffies(local
->hw
.conf
.dynamic_ps_timeout
));
285 static ieee80211_tx_result debug_noinline
286 ieee80211_tx_h_check_assoc(struct ieee80211_tx_data
*tx
)
289 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)tx
->skb
->data
;
290 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(tx
->skb
);
293 if (unlikely(info
->flags
& IEEE80211_TX_CTL_INJECTED
))
296 if (unlikely(test_bit(SCAN_SW_SCANNING
, &tx
->local
->scanning
)) &&
297 test_bit(SDATA_STATE_OFFCHANNEL
, &tx
->sdata
->state
) &&
298 !ieee80211_is_probe_req(hdr
->frame_control
) &&
299 !ieee80211_is_nullfunc(hdr
->frame_control
))
301 * When software scanning only nullfunc frames (to notify
302 * the sleep state to the AP) and probe requests (for the
303 * active scan) are allowed, all other frames should not be
304 * sent and we should not get here, but if we do
305 * nonetheless, drop them to avoid sending them
306 * off-channel. See the link below and
307 * ieee80211_start_scan() for more.
309 * http://article.gmane.org/gmane.linux.kernel.wireless.general/30089
313 if (tx
->sdata
->vif
.type
== NL80211_IFTYPE_OCB
)
316 if (tx
->sdata
->vif
.type
== NL80211_IFTYPE_WDS
)
319 if (tx
->flags
& IEEE80211_TX_PS_BUFFERED
)
323 assoc
= test_sta_flag(tx
->sta
, WLAN_STA_ASSOC
);
325 if (likely(tx
->flags
& IEEE80211_TX_UNICAST
)) {
326 if (unlikely(!assoc
&&
327 ieee80211_is_data(hdr
->frame_control
))) {
328 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
329 sdata_info(tx
->sdata
,
330 "dropped data frame to not associated station %pM\n",
333 I802_DEBUG_INC(tx
->local
->tx_handlers_drop_not_assoc
);
336 } else if (unlikely(ieee80211_is_data(hdr
->frame_control
) &&
337 ieee80211_vif_get_num_mcast_if(tx
->sdata
) == 0)) {
339 * No associated STAs - no need to send multicast
348 /* This function is called whenever the AP is about to exceed the maximum limit
349 * of buffered frames for power saving STAs. This situation should not really
350 * happen often during normal operation, so dropping the oldest buffered packet
351 * from each queue should be OK to make some room for new frames. */
352 static void purge_old_ps_buffers(struct ieee80211_local
*local
)
354 int total
= 0, purged
= 0;
356 struct ieee80211_sub_if_data
*sdata
;
357 struct sta_info
*sta
;
359 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
362 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
)
363 ps
= &sdata
->u
.ap
.ps
;
364 else if (ieee80211_vif_is_mesh(&sdata
->vif
))
365 ps
= &sdata
->u
.mesh
.ps
;
369 skb
= skb_dequeue(&ps
->bc_buf
);
372 ieee80211_free_txskb(&local
->hw
, skb
);
374 total
+= skb_queue_len(&ps
->bc_buf
);
378 * Drop one frame from each station from the lowest-priority
379 * AC that has frames at all.
381 list_for_each_entry_rcu(sta
, &local
->sta_list
, list
) {
384 for (ac
= IEEE80211_AC_BK
; ac
>= IEEE80211_AC_VO
; ac
--) {
385 skb
= skb_dequeue(&sta
->ps_tx_buf
[ac
]);
386 total
+= skb_queue_len(&sta
->ps_tx_buf
[ac
]);
389 ieee80211_free_txskb(&local
->hw
, skb
);
395 local
->total_ps_buffered
= total
;
396 ps_dbg_hw(&local
->hw
, "PS buffers full - purged %d frames\n", purged
);
399 static ieee80211_tx_result
400 ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data
*tx
)
402 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(tx
->skb
);
403 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)tx
->skb
->data
;
407 * broadcast/multicast frame
409 * If any of the associated/peer stations is in power save mode,
410 * the frame is buffered to be sent after DTIM beacon frame.
411 * This is done either by the hardware or us.
414 /* powersaving STAs currently only in AP/VLAN/mesh mode */
415 if (tx
->sdata
->vif
.type
== NL80211_IFTYPE_AP
||
416 tx
->sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
) {
420 ps
= &tx
->sdata
->bss
->ps
;
421 } else if (ieee80211_vif_is_mesh(&tx
->sdata
->vif
)) {
422 ps
= &tx
->sdata
->u
.mesh
.ps
;
428 /* no buffering for ordered frames */
429 if (ieee80211_has_order(hdr
->frame_control
))
432 if (ieee80211_is_probe_req(hdr
->frame_control
))
435 if (ieee80211_hw_check(&tx
->local
->hw
, QUEUE_CONTROL
))
436 info
->hw_queue
= tx
->sdata
->vif
.cab_queue
;
438 /* no stations in PS mode and no buffered packets */
439 if (!atomic_read(&ps
->num_sta_ps
) && skb_queue_empty(&ps
->bc_buf
))
442 info
->flags
|= IEEE80211_TX_CTL_SEND_AFTER_DTIM
;
444 /* device releases frame after DTIM beacon */
445 if (!ieee80211_hw_check(&tx
->local
->hw
, HOST_BROADCAST_PS_BUFFERING
))
448 /* buffered in mac80211 */
449 if (tx
->local
->total_ps_buffered
>= TOTAL_MAX_TX_BUFFER
)
450 purge_old_ps_buffers(tx
->local
);
452 if (skb_queue_len(&ps
->bc_buf
) >= AP_MAX_BC_BUFFER
) {
454 "BC TX buffer full - dropping the oldest frame\n");
455 ieee80211_free_txskb(&tx
->local
->hw
, skb_dequeue(&ps
->bc_buf
));
457 tx
->local
->total_ps_buffered
++;
459 skb_queue_tail(&ps
->bc_buf
, tx
->skb
);
464 static int ieee80211_use_mfp(__le16 fc
, struct sta_info
*sta
,
467 if (!ieee80211_is_mgmt(fc
))
470 if (sta
== NULL
|| !test_sta_flag(sta
, WLAN_STA_MFP
))
473 if (!ieee80211_is_robust_mgmt_frame(skb
))
479 static ieee80211_tx_result
480 ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data
*tx
)
482 struct sta_info
*sta
= tx
->sta
;
483 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(tx
->skb
);
484 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)tx
->skb
->data
;
485 struct ieee80211_local
*local
= tx
->local
;
490 if (unlikely((test_sta_flag(sta
, WLAN_STA_PS_STA
) ||
491 test_sta_flag(sta
, WLAN_STA_PS_DRIVER
) ||
492 test_sta_flag(sta
, WLAN_STA_PS_DELIVER
)) &&
493 !(info
->flags
& IEEE80211_TX_CTL_NO_PS_BUFFER
))) {
494 int ac
= skb_get_queue_mapping(tx
->skb
);
496 if (ieee80211_is_mgmt(hdr
->frame_control
) &&
497 !ieee80211_is_bufferable_mmpdu(hdr
->frame_control
)) {
498 info
->flags
|= IEEE80211_TX_CTL_NO_PS_BUFFER
;
502 ps_dbg(sta
->sdata
, "STA %pM aid %d: PS buffer for AC %d\n",
503 sta
->sta
.addr
, sta
->sta
.aid
, ac
);
504 if (tx
->local
->total_ps_buffered
>= TOTAL_MAX_TX_BUFFER
)
505 purge_old_ps_buffers(tx
->local
);
507 /* sync with ieee80211_sta_ps_deliver_wakeup */
508 spin_lock(&sta
->ps_lock
);
510 * STA woke up the meantime and all the frames on ps_tx_buf have
511 * been queued to pending queue. No reordering can happen, go
512 * ahead and Tx the packet.
514 if (!test_sta_flag(sta
, WLAN_STA_PS_STA
) &&
515 !test_sta_flag(sta
, WLAN_STA_PS_DRIVER
) &&
516 !test_sta_flag(sta
, WLAN_STA_PS_DELIVER
)) {
517 spin_unlock(&sta
->ps_lock
);
521 if (skb_queue_len(&sta
->ps_tx_buf
[ac
]) >= STA_MAX_TX_BUFFER
) {
522 struct sk_buff
*old
= skb_dequeue(&sta
->ps_tx_buf
[ac
]);
524 "STA %pM TX buffer for AC %d full - dropping oldest frame\n",
526 ieee80211_free_txskb(&local
->hw
, old
);
528 tx
->local
->total_ps_buffered
++;
530 info
->control
.jiffies
= jiffies
;
531 info
->control
.vif
= &tx
->sdata
->vif
;
532 info
->flags
|= IEEE80211_TX_INTFL_NEED_TXPROCESSING
;
533 info
->flags
&= ~IEEE80211_TX_TEMPORARY_FLAGS
;
534 skb_queue_tail(&sta
->ps_tx_buf
[ac
], tx
->skb
);
535 spin_unlock(&sta
->ps_lock
);
537 if (!timer_pending(&local
->sta_cleanup
))
538 mod_timer(&local
->sta_cleanup
,
539 round_jiffies(jiffies
+
540 STA_INFO_CLEANUP_INTERVAL
));
543 * We queued up some frames, so the TIM bit might
544 * need to be set, recalculate it.
546 sta_info_recalc_tim(sta
);
549 } else if (unlikely(test_sta_flag(sta
, WLAN_STA_PS_STA
))) {
551 "STA %pM in PS mode, but polling/in SP -> send frame\n",
558 static ieee80211_tx_result debug_noinline
559 ieee80211_tx_h_ps_buf(struct ieee80211_tx_data
*tx
)
561 if (unlikely(tx
->flags
& IEEE80211_TX_PS_BUFFERED
))
564 if (tx
->flags
& IEEE80211_TX_UNICAST
)
565 return ieee80211_tx_h_unicast_ps_buf(tx
);
567 return ieee80211_tx_h_multicast_ps_buf(tx
);
570 static ieee80211_tx_result debug_noinline
571 ieee80211_tx_h_check_control_port_protocol(struct ieee80211_tx_data
*tx
)
573 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(tx
->skb
);
575 if (unlikely(tx
->sdata
->control_port_protocol
== tx
->skb
->protocol
)) {
576 if (tx
->sdata
->control_port_no_encrypt
)
577 info
->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
578 info
->control
.flags
|= IEEE80211_TX_CTRL_PORT_CTRL_PROTO
;
579 info
->flags
|= IEEE80211_TX_CTL_USE_MINRATE
;
585 static ieee80211_tx_result debug_noinline
586 ieee80211_tx_h_select_key(struct ieee80211_tx_data
*tx
)
588 struct ieee80211_key
*key
;
589 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(tx
->skb
);
590 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)tx
->skb
->data
;
592 if (unlikely(info
->flags
& IEEE80211_TX_INTFL_DONT_ENCRYPT
))
595 (key
= rcu_dereference(tx
->sta
->ptk
[tx
->sta
->ptk_idx
])))
597 else if (ieee80211_is_group_privacy_action(tx
->skb
) &&
598 (key
= rcu_dereference(tx
->sdata
->default_multicast_key
)))
600 else if (ieee80211_is_mgmt(hdr
->frame_control
) &&
601 is_multicast_ether_addr(hdr
->addr1
) &&
602 ieee80211_is_robust_mgmt_frame(tx
->skb
) &&
603 (key
= rcu_dereference(tx
->sdata
->default_mgmt_key
)))
605 else if (is_multicast_ether_addr(hdr
->addr1
) &&
606 (key
= rcu_dereference(tx
->sdata
->default_multicast_key
)))
608 else if (!is_multicast_ether_addr(hdr
->addr1
) &&
609 (key
= rcu_dereference(tx
->sdata
->default_unicast_key
)))
615 bool skip_hw
= false;
617 /* TODO: add threshold stuff again */
619 switch (tx
->key
->conf
.cipher
) {
620 case WLAN_CIPHER_SUITE_WEP40
:
621 case WLAN_CIPHER_SUITE_WEP104
:
622 case WLAN_CIPHER_SUITE_TKIP
:
623 if (!ieee80211_is_data_present(hdr
->frame_control
))
626 case WLAN_CIPHER_SUITE_CCMP
:
627 case WLAN_CIPHER_SUITE_CCMP_256
:
628 case WLAN_CIPHER_SUITE_GCMP
:
629 case WLAN_CIPHER_SUITE_GCMP_256
:
630 if (!ieee80211_is_data_present(hdr
->frame_control
) &&
631 !ieee80211_use_mfp(hdr
->frame_control
, tx
->sta
,
633 !ieee80211_is_group_privacy_action(tx
->skb
))
636 skip_hw
= (tx
->key
->conf
.flags
&
637 IEEE80211_KEY_FLAG_SW_MGMT_TX
) &&
638 ieee80211_is_mgmt(hdr
->frame_control
);
640 case WLAN_CIPHER_SUITE_AES_CMAC
:
641 case WLAN_CIPHER_SUITE_BIP_CMAC_256
:
642 case WLAN_CIPHER_SUITE_BIP_GMAC_128
:
643 case WLAN_CIPHER_SUITE_BIP_GMAC_256
:
644 if (!ieee80211_is_mgmt(hdr
->frame_control
))
649 if (unlikely(tx
->key
&& tx
->key
->flags
& KEY_FLAG_TAINTED
&&
650 !ieee80211_is_deauth(hdr
->frame_control
)))
653 if (!skip_hw
&& tx
->key
&&
654 tx
->key
->flags
& KEY_FLAG_UPLOADED_TO_HARDWARE
)
655 info
->control
.hw_key
= &tx
->key
->conf
;
661 static ieee80211_tx_result debug_noinline
662 ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data
*tx
)
664 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(tx
->skb
);
665 struct ieee80211_hdr
*hdr
= (void *)tx
->skb
->data
;
666 struct ieee80211_supported_band
*sband
;
668 struct ieee80211_tx_rate_control txrc
;
669 struct ieee80211_sta_rates
*ratetbl
= NULL
;
672 memset(&txrc
, 0, sizeof(txrc
));
674 sband
= tx
->local
->hw
.wiphy
->bands
[info
->band
];
676 len
= min_t(u32
, tx
->skb
->len
+ FCS_LEN
,
677 tx
->local
->hw
.wiphy
->frag_threshold
);
679 /* set up the tx rate control struct we give the RC algo */
680 txrc
.hw
= &tx
->local
->hw
;
682 txrc
.bss_conf
= &tx
->sdata
->vif
.bss_conf
;
684 txrc
.reported_rate
.idx
= -1;
685 txrc
.rate_idx_mask
= tx
->sdata
->rc_rateidx_mask
[info
->band
];
687 if (tx
->sdata
->rc_has_mcs_mask
[info
->band
])
688 txrc
.rate_idx_mcs_mask
=
689 tx
->sdata
->rc_rateidx_mcs_mask
[info
->band
];
691 txrc
.bss
= (tx
->sdata
->vif
.type
== NL80211_IFTYPE_AP
||
692 tx
->sdata
->vif
.type
== NL80211_IFTYPE_MESH_POINT
||
693 tx
->sdata
->vif
.type
== NL80211_IFTYPE_ADHOC
||
694 tx
->sdata
->vif
.type
== NL80211_IFTYPE_OCB
);
696 /* set up RTS protection if desired */
697 if (len
> tx
->local
->hw
.wiphy
->rts_threshold
) {
701 info
->control
.use_rts
= txrc
.rts
;
702 info
->control
.use_cts_prot
= tx
->sdata
->vif
.bss_conf
.use_cts_prot
;
705 * Use short preamble if the BSS can handle it, but not for
706 * management frames unless we know the receiver can handle
707 * that -- the management frame might be to a station that
708 * just wants a probe response.
710 if (tx
->sdata
->vif
.bss_conf
.use_short_preamble
&&
711 (ieee80211_is_data(hdr
->frame_control
) ||
712 (tx
->sta
&& test_sta_flag(tx
->sta
, WLAN_STA_SHORT_PREAMBLE
))))
713 txrc
.short_preamble
= true;
715 info
->control
.short_preamble
= txrc
.short_preamble
;
717 /* don't ask rate control when rate already injected via radiotap */
718 if (info
->control
.flags
& IEEE80211_TX_CTRL_RATE_INJECT
)
722 assoc
= test_sta_flag(tx
->sta
, WLAN_STA_ASSOC
);
725 * Lets not bother rate control if we're associated and cannot
726 * talk to the sta. This should not happen.
728 if (WARN(test_bit(SCAN_SW_SCANNING
, &tx
->local
->scanning
) && assoc
&&
729 !rate_usable_index_exists(sband
, &tx
->sta
->sta
),
730 "%s: Dropped data frame as no usable bitrate found while "
731 "scanning and associated. Target station: "
732 "%pM on %d GHz band\n",
733 tx
->sdata
->name
, hdr
->addr1
,
738 * If we're associated with the sta at this point we know we can at
739 * least send the frame at the lowest bit rate.
741 rate_control_get_rate(tx
->sdata
, tx
->sta
, &txrc
);
743 if (tx
->sta
&& !info
->control
.skip_table
)
744 ratetbl
= rcu_dereference(tx
->sta
->sta
.rates
);
746 if (unlikely(info
->control
.rates
[0].idx
< 0)) {
748 struct ieee80211_tx_rate rate
= {
749 .idx
= ratetbl
->rate
[0].idx
,
750 .flags
= ratetbl
->rate
[0].flags
,
751 .count
= ratetbl
->rate
[0].count
754 if (ratetbl
->rate
[0].idx
< 0)
762 tx
->rate
= info
->control
.rates
[0];
765 if (txrc
.reported_rate
.idx
< 0) {
766 txrc
.reported_rate
= tx
->rate
;
767 if (tx
->sta
&& ieee80211_is_data(hdr
->frame_control
))
768 tx
->sta
->tx_stats
.last_rate
= txrc
.reported_rate
;
770 tx
->sta
->tx_stats
.last_rate
= txrc
.reported_rate
;
775 if (unlikely(!info
->control
.rates
[0].count
))
776 info
->control
.rates
[0].count
= 1;
778 if (WARN_ON_ONCE((info
->control
.rates
[0].count
> 1) &&
779 (info
->flags
& IEEE80211_TX_CTL_NO_ACK
)))
780 info
->control
.rates
[0].count
= 1;
785 static __le16
ieee80211_tx_next_seq(struct sta_info
*sta
, int tid
)
787 u16
*seq
= &sta
->tid_seq
[tid
];
788 __le16 ret
= cpu_to_le16(*seq
);
790 /* Increase the sequence number. */
791 *seq
= (*seq
+ 0x10) & IEEE80211_SCTL_SEQ
;
796 static ieee80211_tx_result debug_noinline
797 ieee80211_tx_h_sequence(struct ieee80211_tx_data
*tx
)
799 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(tx
->skb
);
800 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)tx
->skb
->data
;
805 * Packet injection may want to control the sequence
806 * number, if we have no matching interface then we
807 * neither assign one ourselves nor ask the driver to.
809 if (unlikely(info
->control
.vif
->type
== NL80211_IFTYPE_MONITOR
))
812 if (unlikely(ieee80211_is_ctl(hdr
->frame_control
)))
815 if (ieee80211_hdrlen(hdr
->frame_control
) < 24)
818 if (ieee80211_is_qos_nullfunc(hdr
->frame_control
))
822 * Anything but QoS data that has a sequence number field
823 * (is long enough) gets a sequence number from the global
824 * counter. QoS data frames with a multicast destination
825 * also use the global counter (802.11-2012 9.3.2.10).
827 if (!ieee80211_is_data_qos(hdr
->frame_control
) ||
828 is_multicast_ether_addr(hdr
->addr1
)) {
829 /* driver should assign sequence number */
830 info
->flags
|= IEEE80211_TX_CTL_ASSIGN_SEQ
;
831 /* for pure STA mode without beacons, we can do it */
832 hdr
->seq_ctrl
= cpu_to_le16(tx
->sdata
->sequence_number
);
833 tx
->sdata
->sequence_number
+= 0x10;
835 tx
->sta
->tx_stats
.msdu
[IEEE80211_NUM_TIDS
]++;
840 * This should be true for injected/management frames only, for
841 * management frames we have set the IEEE80211_TX_CTL_ASSIGN_SEQ
842 * above since they are not QoS-data frames.
847 /* include per-STA, per-TID sequence counter */
849 qc
= ieee80211_get_qos_ctl(hdr
);
850 tid
= *qc
& IEEE80211_QOS_CTL_TID_MASK
;
851 tx
->sta
->tx_stats
.msdu
[tid
]++;
853 hdr
->seq_ctrl
= ieee80211_tx_next_seq(tx
->sta
, tid
);
858 static int ieee80211_fragment(struct ieee80211_tx_data
*tx
,
859 struct sk_buff
*skb
, int hdrlen
,
862 struct ieee80211_local
*local
= tx
->local
;
863 struct ieee80211_tx_info
*info
;
865 int per_fragm
= frag_threshold
- hdrlen
- FCS_LEN
;
866 int pos
= hdrlen
+ per_fragm
;
867 int rem
= skb
->len
- hdrlen
- per_fragm
;
869 if (WARN_ON(rem
< 0))
872 /* first fragment was already added to queue by caller */
875 int fraglen
= per_fragm
;
880 tmp
= dev_alloc_skb(local
->tx_headroom
+
882 tx
->sdata
->encrypt_headroom
+
883 IEEE80211_ENCRYPT_TAILROOM
);
887 __skb_queue_tail(&tx
->skbs
, tmp
);
890 local
->tx_headroom
+ tx
->sdata
->encrypt_headroom
);
892 /* copy control information */
893 memcpy(tmp
->cb
, skb
->cb
, sizeof(tmp
->cb
));
895 info
= IEEE80211_SKB_CB(tmp
);
896 info
->flags
&= ~(IEEE80211_TX_CTL_CLEAR_PS_FILT
|
897 IEEE80211_TX_CTL_FIRST_FRAGMENT
);
900 info
->flags
|= IEEE80211_TX_CTL_MORE_FRAMES
;
902 skb_copy_queue_mapping(tmp
, skb
);
903 tmp
->priority
= skb
->priority
;
906 /* copy header and data */
907 skb_put_data(tmp
, skb
->data
, hdrlen
);
908 skb_put_data(tmp
, skb
->data
+ pos
, fraglen
);
913 /* adjust first fragment's length */
914 skb_trim(skb
, hdrlen
+ per_fragm
);
918 static ieee80211_tx_result debug_noinline
919 ieee80211_tx_h_fragment(struct ieee80211_tx_data
*tx
)
921 struct sk_buff
*skb
= tx
->skb
;
922 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
923 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
924 int frag_threshold
= tx
->local
->hw
.wiphy
->frag_threshold
;
928 /* no matter what happens, tx->skb moves to tx->skbs */
929 __skb_queue_tail(&tx
->skbs
, skb
);
932 if (info
->flags
& IEEE80211_TX_CTL_DONTFRAG
)
935 if (ieee80211_hw_check(&tx
->local
->hw
, SUPPORTS_TX_FRAG
))
939 * Warn when submitting a fragmented A-MPDU frame and drop it.
940 * This scenario is handled in ieee80211_tx_prepare but extra
941 * caution taken here as fragmented ampdu may cause Tx stop.
943 if (WARN_ON(info
->flags
& IEEE80211_TX_CTL_AMPDU
))
946 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
948 /* internal error, why isn't DONTFRAG set? */
949 if (WARN_ON(skb
->len
+ FCS_LEN
<= frag_threshold
))
953 * Now fragment the frame. This will allocate all the fragments and
954 * chain them (using skb as the first fragment) to skb->next.
955 * During transmission, we will remove the successfully transmitted
956 * fragments from this list. When the low-level driver rejects one
957 * of the fragments then we will simply pretend to accept the skb
958 * but store it away as pending.
960 if (ieee80211_fragment(tx
, skb
, hdrlen
, frag_threshold
))
963 /* update duration/seq/flags of fragments */
966 skb_queue_walk(&tx
->skbs
, skb
) {
967 const __le16 morefrags
= cpu_to_le16(IEEE80211_FCTL_MOREFRAGS
);
969 hdr
= (void *)skb
->data
;
970 info
= IEEE80211_SKB_CB(skb
);
972 if (!skb_queue_is_last(&tx
->skbs
, skb
)) {
973 hdr
->frame_control
|= morefrags
;
975 * No multi-rate retries for fragmented frames, that
976 * would completely throw off the NAV at other STAs.
978 info
->control
.rates
[1].idx
= -1;
979 info
->control
.rates
[2].idx
= -1;
980 info
->control
.rates
[3].idx
= -1;
981 BUILD_BUG_ON(IEEE80211_TX_MAX_RATES
!= 4);
982 info
->flags
&= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE
;
984 hdr
->frame_control
&= ~morefrags
;
986 hdr
->seq_ctrl
|= cpu_to_le16(fragnum
& IEEE80211_SCTL_FRAG
);
993 static ieee80211_tx_result debug_noinline
994 ieee80211_tx_h_stats(struct ieee80211_tx_data
*tx
)
1002 skb_queue_walk(&tx
->skbs
, skb
) {
1003 ac
= skb_get_queue_mapping(skb
);
1004 tx
->sta
->tx_stats
.bytes
[ac
] += skb
->len
;
1007 tx
->sta
->tx_stats
.packets
[ac
]++;
1012 static ieee80211_tx_result debug_noinline
1013 ieee80211_tx_h_encrypt(struct ieee80211_tx_data
*tx
)
1018 switch (tx
->key
->conf
.cipher
) {
1019 case WLAN_CIPHER_SUITE_WEP40
:
1020 case WLAN_CIPHER_SUITE_WEP104
:
1021 return ieee80211_crypto_wep_encrypt(tx
);
1022 case WLAN_CIPHER_SUITE_TKIP
:
1023 return ieee80211_crypto_tkip_encrypt(tx
);
1024 case WLAN_CIPHER_SUITE_CCMP
:
1025 return ieee80211_crypto_ccmp_encrypt(
1026 tx
, IEEE80211_CCMP_MIC_LEN
);
1027 case WLAN_CIPHER_SUITE_CCMP_256
:
1028 return ieee80211_crypto_ccmp_encrypt(
1029 tx
, IEEE80211_CCMP_256_MIC_LEN
);
1030 case WLAN_CIPHER_SUITE_AES_CMAC
:
1031 return ieee80211_crypto_aes_cmac_encrypt(tx
);
1032 case WLAN_CIPHER_SUITE_BIP_CMAC_256
:
1033 return ieee80211_crypto_aes_cmac_256_encrypt(tx
);
1034 case WLAN_CIPHER_SUITE_BIP_GMAC_128
:
1035 case WLAN_CIPHER_SUITE_BIP_GMAC_256
:
1036 return ieee80211_crypto_aes_gmac_encrypt(tx
);
1037 case WLAN_CIPHER_SUITE_GCMP
:
1038 case WLAN_CIPHER_SUITE_GCMP_256
:
1039 return ieee80211_crypto_gcmp_encrypt(tx
);
1041 return ieee80211_crypto_hw_encrypt(tx
);
1047 static ieee80211_tx_result debug_noinline
1048 ieee80211_tx_h_calculate_duration(struct ieee80211_tx_data
*tx
)
1050 struct sk_buff
*skb
;
1051 struct ieee80211_hdr
*hdr
;
1055 skb_queue_walk(&tx
->skbs
, skb
) {
1056 hdr
= (void *) skb
->data
;
1057 if (unlikely(ieee80211_is_pspoll(hdr
->frame_control
)))
1058 break; /* must not overwrite AID */
1059 if (!skb_queue_is_last(&tx
->skbs
, skb
)) {
1060 struct sk_buff
*next
= skb_queue_next(&tx
->skbs
, skb
);
1061 next_len
= next
->len
;
1064 group_addr
= is_multicast_ether_addr(hdr
->addr1
);
1067 ieee80211_duration(tx
, skb
, group_addr
, next_len
);
1073 /* actual transmit path */
1075 static bool ieee80211_tx_prep_agg(struct ieee80211_tx_data
*tx
,
1076 struct sk_buff
*skb
,
1077 struct ieee80211_tx_info
*info
,
1078 struct tid_ampdu_tx
*tid_tx
,
1081 bool queued
= false;
1082 bool reset_agg_timer
= false;
1083 struct sk_buff
*purge_skb
= NULL
;
1085 if (test_bit(HT_AGG_STATE_OPERATIONAL
, &tid_tx
->state
)) {
1086 info
->flags
|= IEEE80211_TX_CTL_AMPDU
;
1087 reset_agg_timer
= true;
1088 } else if (test_bit(HT_AGG_STATE_WANT_START
, &tid_tx
->state
)) {
1090 * nothing -- this aggregation session is being started
1091 * but that might still fail with the driver
1093 } else if (!tx
->sta
->sta
.txq
[tid
]) {
1094 spin_lock(&tx
->sta
->lock
);
1096 * Need to re-check now, because we may get here
1098 * 1) in the window during which the setup is actually
1099 * already done, but not marked yet because not all
1100 * packets are spliced over to the driver pending
1101 * queue yet -- if this happened we acquire the lock
1102 * either before or after the splice happens, but
1103 * need to recheck which of these cases happened.
1105 * 2) during session teardown, if the OPERATIONAL bit
1106 * was cleared due to the teardown but the pointer
1107 * hasn't been assigned NULL yet (or we loaded it
1108 * before it was assigned) -- in this case it may
1109 * now be NULL which means we should just let the
1110 * packet pass through because splicing the frames
1111 * back is already done.
1113 tid_tx
= rcu_dereference_protected_tid_tx(tx
->sta
, tid
);
1116 /* do nothing, let packet pass through */
1117 } else if (test_bit(HT_AGG_STATE_OPERATIONAL
, &tid_tx
->state
)) {
1118 info
->flags
|= IEEE80211_TX_CTL_AMPDU
;
1119 reset_agg_timer
= true;
1122 if (info
->flags
& IEEE80211_TX_CTL_NO_PS_BUFFER
) {
1123 clear_sta_flag(tx
->sta
, WLAN_STA_SP
);
1124 ps_dbg(tx
->sta
->sdata
,
1125 "STA %pM aid %d: SP frame queued, close the SP w/o telling the peer\n",
1126 tx
->sta
->sta
.addr
, tx
->sta
->sta
.aid
);
1128 info
->control
.vif
= &tx
->sdata
->vif
;
1129 info
->flags
|= IEEE80211_TX_INTFL_NEED_TXPROCESSING
;
1130 info
->flags
&= ~IEEE80211_TX_TEMPORARY_FLAGS
;
1131 __skb_queue_tail(&tid_tx
->pending
, skb
);
1132 if (skb_queue_len(&tid_tx
->pending
) > STA_MAX_TX_BUFFER
)
1133 purge_skb
= __skb_dequeue(&tid_tx
->pending
);
1135 spin_unlock(&tx
->sta
->lock
);
1138 ieee80211_free_txskb(&tx
->local
->hw
, purge_skb
);
1141 /* reset session timer */
1142 if (reset_agg_timer
)
1143 tid_tx
->last_tx
= jiffies
;
1150 * pass %NULL for the station if unknown, a valid pointer if known
1151 * or an ERR_PTR() if the station is known not to exist
1153 static ieee80211_tx_result
1154 ieee80211_tx_prepare(struct ieee80211_sub_if_data
*sdata
,
1155 struct ieee80211_tx_data
*tx
,
1156 struct sta_info
*sta
, struct sk_buff
*skb
)
1158 struct ieee80211_local
*local
= sdata
->local
;
1159 struct ieee80211_hdr
*hdr
;
1160 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1164 memset(tx
, 0, sizeof(*tx
));
1168 __skb_queue_head_init(&tx
->skbs
);
1171 * If this flag is set to true anywhere, and we get here,
1172 * we are doing the needed processing, so remove the flag
1175 info
->flags
&= ~IEEE80211_TX_INTFL_NEED_TXPROCESSING
;
1177 hdr
= (struct ieee80211_hdr
*) skb
->data
;
1183 if (sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
) {
1184 tx
->sta
= rcu_dereference(sdata
->u
.vlan
.sta
);
1185 if (!tx
->sta
&& sdata
->wdev
.use_4addr
)
1187 } else if (info
->flags
& (IEEE80211_TX_INTFL_NL80211_FRAME_TX
|
1188 IEEE80211_TX_CTL_INJECTED
) ||
1189 tx
->sdata
->control_port_protocol
== tx
->skb
->protocol
) {
1190 tx
->sta
= sta_info_get_bss(sdata
, hdr
->addr1
);
1192 if (!tx
->sta
&& !is_multicast_ether_addr(hdr
->addr1
))
1193 tx
->sta
= sta_info_get(sdata
, hdr
->addr1
);
1196 if (tx
->sta
&& ieee80211_is_data_qos(hdr
->frame_control
) &&
1197 !ieee80211_is_qos_nullfunc(hdr
->frame_control
) &&
1198 ieee80211_hw_check(&local
->hw
, AMPDU_AGGREGATION
) &&
1199 !ieee80211_hw_check(&local
->hw
, TX_AMPDU_SETUP_IN_HW
)) {
1200 struct tid_ampdu_tx
*tid_tx
;
1202 qc
= ieee80211_get_qos_ctl(hdr
);
1203 tid
= *qc
& IEEE80211_QOS_CTL_TID_MASK
;
1205 tid_tx
= rcu_dereference(tx
->sta
->ampdu_mlme
.tid_tx
[tid
]);
1209 queued
= ieee80211_tx_prep_agg(tx
, skb
, info
,
1212 if (unlikely(queued
))
1217 if (is_multicast_ether_addr(hdr
->addr1
)) {
1218 tx
->flags
&= ~IEEE80211_TX_UNICAST
;
1219 info
->flags
|= IEEE80211_TX_CTL_NO_ACK
;
1221 tx
->flags
|= IEEE80211_TX_UNICAST
;
1223 if (!(info
->flags
& IEEE80211_TX_CTL_DONTFRAG
)) {
1224 if (!(tx
->flags
& IEEE80211_TX_UNICAST
) ||
1225 skb
->len
+ FCS_LEN
<= local
->hw
.wiphy
->frag_threshold
||
1226 info
->flags
& IEEE80211_TX_CTL_AMPDU
)
1227 info
->flags
|= IEEE80211_TX_CTL_DONTFRAG
;
1231 info
->flags
|= IEEE80211_TX_CTL_CLEAR_PS_FILT
;
1232 else if (test_and_clear_sta_flag(tx
->sta
, WLAN_STA_CLEAR_PS_FILT
)) {
1233 info
->flags
|= IEEE80211_TX_CTL_CLEAR_PS_FILT
;
1234 ieee80211_check_fast_xmit(tx
->sta
);
1237 info
->flags
|= IEEE80211_TX_CTL_FIRST_FRAGMENT
;
1242 static struct txq_info
*ieee80211_get_txq(struct ieee80211_local
*local
,
1243 struct ieee80211_vif
*vif
,
1244 struct sta_info
*sta
,
1245 struct sk_buff
*skb
)
1247 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1248 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1249 struct ieee80211_txq
*txq
= NULL
;
1251 if ((info
->flags
& IEEE80211_TX_CTL_SEND_AFTER_DTIM
) ||
1252 (info
->control
.flags
& IEEE80211_TX_CTRL_PS_RESPONSE
))
1255 if (!ieee80211_is_data(hdr
->frame_control
))
1259 u8 tid
= skb
->priority
& IEEE80211_QOS_CTL_TID_MASK
;
1264 txq
= sta
->sta
.txq
[tid
];
1272 return to_txq_info(txq
);
1275 static void ieee80211_set_skb_enqueue_time(struct sk_buff
*skb
)
1277 IEEE80211_SKB_CB(skb
)->control
.enqueue_time
= codel_get_time();
1280 static u32
codel_skb_len_func(const struct sk_buff
*skb
)
1285 static codel_time_t
codel_skb_time_func(const struct sk_buff
*skb
)
1287 const struct ieee80211_tx_info
*info
;
1289 info
= (const struct ieee80211_tx_info
*)skb
->cb
;
1290 return info
->control
.enqueue_time
;
1293 static struct sk_buff
*codel_dequeue_func(struct codel_vars
*cvars
,
1296 struct ieee80211_local
*local
;
1297 struct txq_info
*txqi
;
1299 struct fq_flow
*flow
;
1302 local
= vif_to_sdata(txqi
->txq
.vif
)->local
;
1305 if (cvars
== &txqi
->def_cvars
)
1306 flow
= &txqi
->def_flow
;
1308 flow
= &fq
->flows
[cvars
- local
->cvars
];
1310 return fq_flow_dequeue(fq
, flow
);
1313 static void codel_drop_func(struct sk_buff
*skb
,
1316 struct ieee80211_local
*local
;
1317 struct ieee80211_hw
*hw
;
1318 struct txq_info
*txqi
;
1321 local
= vif_to_sdata(txqi
->txq
.vif
)->local
;
1324 ieee80211_free_txskb(hw
, skb
);
1327 static struct sk_buff
*fq_tin_dequeue_func(struct fq
*fq
,
1329 struct fq_flow
*flow
)
1331 struct ieee80211_local
*local
;
1332 struct txq_info
*txqi
;
1333 struct codel_vars
*cvars
;
1334 struct codel_params
*cparams
;
1335 struct codel_stats
*cstats
;
1337 local
= container_of(fq
, struct ieee80211_local
, fq
);
1338 txqi
= container_of(tin
, struct txq_info
, tin
);
1339 cstats
= &txqi
->cstats
;
1341 if (txqi
->txq
.sta
) {
1342 struct sta_info
*sta
= container_of(txqi
->txq
.sta
,
1343 struct sta_info
, sta
);
1344 cparams
= &sta
->cparams
;
1346 cparams
= &local
->cparams
;
1349 if (flow
== &txqi
->def_flow
)
1350 cvars
= &txqi
->def_cvars
;
1352 cvars
= &local
->cvars
[flow
- fq
->flows
];
1354 return codel_dequeue(txqi
,
1360 codel_skb_time_func
,
1362 codel_dequeue_func
);
1365 static void fq_skb_free_func(struct fq
*fq
,
1367 struct fq_flow
*flow
,
1368 struct sk_buff
*skb
)
1370 struct ieee80211_local
*local
;
1372 local
= container_of(fq
, struct ieee80211_local
, fq
);
1373 ieee80211_free_txskb(&local
->hw
, skb
);
1376 static struct fq_flow
*fq_flow_get_default_func(struct fq
*fq
,
1379 struct sk_buff
*skb
)
1381 struct txq_info
*txqi
;
1383 txqi
= container_of(tin
, struct txq_info
, tin
);
1384 return &txqi
->def_flow
;
1387 static void ieee80211_txq_enqueue(struct ieee80211_local
*local
,
1388 struct txq_info
*txqi
,
1389 struct sk_buff
*skb
)
1391 struct fq
*fq
= &local
->fq
;
1392 struct fq_tin
*tin
= &txqi
->tin
;
1394 ieee80211_set_skb_enqueue_time(skb
);
1395 fq_tin_enqueue(fq
, tin
, skb
,
1397 fq_flow_get_default_func
);
1400 static bool fq_vlan_filter_func(struct fq
*fq
, struct fq_tin
*tin
,
1401 struct fq_flow
*flow
, struct sk_buff
*skb
,
1404 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1406 return info
->control
.vif
== data
;
1409 void ieee80211_txq_remove_vlan(struct ieee80211_local
*local
,
1410 struct ieee80211_sub_if_data
*sdata
)
1412 struct fq
*fq
= &local
->fq
;
1413 struct txq_info
*txqi
;
1415 struct ieee80211_sub_if_data
*ap
;
1417 if (WARN_ON(sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
))
1420 ap
= container_of(sdata
->bss
, struct ieee80211_sub_if_data
, u
.ap
);
1425 txqi
= to_txq_info(ap
->vif
.txq
);
1428 spin_lock_bh(&fq
->lock
);
1429 fq_tin_filter(fq
, tin
, fq_vlan_filter_func
, &sdata
->vif
,
1431 spin_unlock_bh(&fq
->lock
);
1434 void ieee80211_txq_init(struct ieee80211_sub_if_data
*sdata
,
1435 struct sta_info
*sta
,
1436 struct txq_info
*txqi
, int tid
)
1438 fq_tin_init(&txqi
->tin
);
1439 fq_flow_init(&txqi
->def_flow
);
1440 codel_vars_init(&txqi
->def_cvars
);
1441 codel_stats_init(&txqi
->cstats
);
1442 __skb_queue_head_init(&txqi
->frags
);
1444 txqi
->txq
.vif
= &sdata
->vif
;
1447 txqi
->txq
.sta
= &sta
->sta
;
1448 sta
->sta
.txq
[tid
] = &txqi
->txq
;
1449 txqi
->txq
.tid
= tid
;
1450 txqi
->txq
.ac
= ieee80211_ac_from_tid(tid
);
1452 sdata
->vif
.txq
= &txqi
->txq
;
1454 txqi
->txq
.ac
= IEEE80211_AC_BE
;
1458 void ieee80211_txq_purge(struct ieee80211_local
*local
,
1459 struct txq_info
*txqi
)
1461 struct fq
*fq
= &local
->fq
;
1462 struct fq_tin
*tin
= &txqi
->tin
;
1464 fq_tin_reset(fq
, tin
, fq_skb_free_func
);
1465 ieee80211_purge_tx_queue(&local
->hw
, &txqi
->frags
);
1468 int ieee80211_txq_setup_flows(struct ieee80211_local
*local
)
1470 struct fq
*fq
= &local
->fq
;
1473 bool supp_vht
= false;
1474 enum nl80211_band band
;
1476 if (!local
->ops
->wake_tx_queue
)
1479 ret
= fq_init(fq
, 4096);
1484 * If the hardware doesn't support VHT, it is safe to limit the maximum
1485 * queue size. 4 Mbytes is 64 max-size aggregates in 802.11n.
1487 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
1488 struct ieee80211_supported_band
*sband
;
1490 sband
= local
->hw
.wiphy
->bands
[band
];
1494 supp_vht
= supp_vht
|| sband
->vht_cap
.vht_supported
;
1498 fq
->memory_limit
= 4 << 20; /* 4 Mbytes */
1500 codel_params_init(&local
->cparams
);
1501 local
->cparams
.interval
= MS2TIME(100);
1502 local
->cparams
.target
= MS2TIME(20);
1503 local
->cparams
.ecn
= true;
1505 local
->cvars
= kcalloc(fq
->flows_cnt
, sizeof(local
->cvars
[0]),
1507 if (!local
->cvars
) {
1508 spin_lock_bh(&fq
->lock
);
1509 fq_reset(fq
, fq_skb_free_func
);
1510 spin_unlock_bh(&fq
->lock
);
1514 for (i
= 0; i
< fq
->flows_cnt
; i
++)
1515 codel_vars_init(&local
->cvars
[i
]);
1520 void ieee80211_txq_teardown_flows(struct ieee80211_local
*local
)
1522 struct fq
*fq
= &local
->fq
;
1524 if (!local
->ops
->wake_tx_queue
)
1527 kfree(local
->cvars
);
1528 local
->cvars
= NULL
;
1530 spin_lock_bh(&fq
->lock
);
1531 fq_reset(fq
, fq_skb_free_func
);
1532 spin_unlock_bh(&fq
->lock
);
1535 static bool ieee80211_queue_skb(struct ieee80211_local
*local
,
1536 struct ieee80211_sub_if_data
*sdata
,
1537 struct sta_info
*sta
,
1538 struct sk_buff
*skb
)
1540 struct fq
*fq
= &local
->fq
;
1541 struct ieee80211_vif
*vif
;
1542 struct txq_info
*txqi
;
1544 if (!local
->ops
->wake_tx_queue
||
1545 sdata
->vif
.type
== NL80211_IFTYPE_MONITOR
)
1548 if (sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
)
1549 sdata
= container_of(sdata
->bss
,
1550 struct ieee80211_sub_if_data
, u
.ap
);
1553 txqi
= ieee80211_get_txq(local
, vif
, sta
, skb
);
1558 spin_lock_bh(&fq
->lock
);
1559 ieee80211_txq_enqueue(local
, txqi
, skb
);
1560 spin_unlock_bh(&fq
->lock
);
1562 drv_wake_tx_queue(local
, txqi
);
1567 static bool ieee80211_tx_frags(struct ieee80211_local
*local
,
1568 struct ieee80211_vif
*vif
,
1569 struct ieee80211_sta
*sta
,
1570 struct sk_buff_head
*skbs
,
1573 struct ieee80211_tx_control control
= {};
1574 struct sk_buff
*skb
, *tmp
;
1575 unsigned long flags
;
1577 skb_queue_walk_safe(skbs
, skb
, tmp
) {
1578 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1579 int q
= info
->hw_queue
;
1581 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1582 if (WARN_ON_ONCE(q
>= local
->hw
.queues
)) {
1583 __skb_unlink(skb
, skbs
);
1584 ieee80211_free_txskb(&local
->hw
, skb
);
1589 spin_lock_irqsave(&local
->queue_stop_reason_lock
, flags
);
1590 if (local
->queue_stop_reasons
[q
] ||
1591 (!txpending
&& !skb_queue_empty(&local
->pending
[q
]))) {
1592 if (unlikely(info
->flags
&
1593 IEEE80211_TX_INTFL_OFFCHAN_TX_OK
)) {
1594 if (local
->queue_stop_reasons
[q
] &
1595 ~BIT(IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL
)) {
1597 * Drop off-channel frames if queues
1598 * are stopped for any reason other
1599 * than off-channel operation. Never
1602 spin_unlock_irqrestore(
1603 &local
->queue_stop_reason_lock
,
1605 ieee80211_purge_tx_queue(&local
->hw
,
1612 * Since queue is stopped, queue up frames for
1613 * later transmission from the tx-pending
1614 * tasklet when the queue is woken again.
1617 skb_queue_splice_init(skbs
,
1618 &local
->pending
[q
]);
1620 skb_queue_splice_tail_init(skbs
,
1621 &local
->pending
[q
]);
1623 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
,
1628 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
, flags
);
1630 info
->control
.vif
= vif
;
1633 __skb_unlink(skb
, skbs
);
1634 drv_tx(local
, &control
, skb
);
1641 * Returns false if the frame couldn't be transmitted but was queued instead.
1643 static bool __ieee80211_tx(struct ieee80211_local
*local
,
1644 struct sk_buff_head
*skbs
, int led_len
,
1645 struct sta_info
*sta
, bool txpending
)
1647 struct ieee80211_tx_info
*info
;
1648 struct ieee80211_sub_if_data
*sdata
;
1649 struct ieee80211_vif
*vif
;
1650 struct ieee80211_sta
*pubsta
;
1651 struct sk_buff
*skb
;
1655 if (WARN_ON(skb_queue_empty(skbs
)))
1658 skb
= skb_peek(skbs
);
1659 fc
= ((struct ieee80211_hdr
*)skb
->data
)->frame_control
;
1660 info
= IEEE80211_SKB_CB(skb
);
1661 sdata
= vif_to_sdata(info
->control
.vif
);
1662 if (sta
&& !sta
->uploaded
)
1670 switch (sdata
->vif
.type
) {
1671 case NL80211_IFTYPE_MONITOR
:
1672 if (sdata
->u
.mntr
.flags
& MONITOR_FLAG_ACTIVE
) {
1676 sdata
= rcu_dereference(local
->monitor_sdata
);
1680 vif
->hw_queue
[skb_get_queue_mapping(skb
)];
1681 } else if (ieee80211_hw_check(&local
->hw
, QUEUE_CONTROL
)) {
1682 ieee80211_purge_tx_queue(&local
->hw
, skbs
);
1687 case NL80211_IFTYPE_AP_VLAN
:
1688 sdata
= container_of(sdata
->bss
,
1689 struct ieee80211_sub_if_data
, u
.ap
);
1696 result
= ieee80211_tx_frags(local
, vif
, pubsta
, skbs
,
1699 ieee80211_tpt_led_trig_tx(local
, fc
, led_len
);
1701 WARN_ON_ONCE(!skb_queue_empty(skbs
));
1707 * Invoke TX handlers, return 0 on success and non-zero if the
1708 * frame was dropped or queued.
1710 * The handlers are split into an early and late part. The latter is everything
1711 * that can be sensitive to reordering, and will be deferred to after packets
1712 * are dequeued from the intermediate queues (when they are enabled).
1714 static int invoke_tx_handlers_early(struct ieee80211_tx_data
*tx
)
1716 ieee80211_tx_result res
= TX_DROP
;
1718 #define CALL_TXH(txh) \
1721 if (res != TX_CONTINUE) \
1725 CALL_TXH(ieee80211_tx_h_dynamic_ps
);
1726 CALL_TXH(ieee80211_tx_h_check_assoc
);
1727 CALL_TXH(ieee80211_tx_h_ps_buf
);
1728 CALL_TXH(ieee80211_tx_h_check_control_port_protocol
);
1729 CALL_TXH(ieee80211_tx_h_select_key
);
1730 if (!ieee80211_hw_check(&tx
->local
->hw
, HAS_RATE_CONTROL
))
1731 CALL_TXH(ieee80211_tx_h_rate_ctrl
);
1734 if (unlikely(res
== TX_DROP
)) {
1735 I802_DEBUG_INC(tx
->local
->tx_handlers_drop
);
1737 ieee80211_free_txskb(&tx
->local
->hw
, tx
->skb
);
1739 ieee80211_purge_tx_queue(&tx
->local
->hw
, &tx
->skbs
);
1741 } else if (unlikely(res
== TX_QUEUED
)) {
1742 I802_DEBUG_INC(tx
->local
->tx_handlers_queued
);
1750 * Late handlers can be called while the sta lock is held. Handlers that can
1751 * cause packets to be generated will cause deadlock!
1753 static int invoke_tx_handlers_late(struct ieee80211_tx_data
*tx
)
1755 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(tx
->skb
);
1756 ieee80211_tx_result res
= TX_CONTINUE
;
1758 if (unlikely(info
->flags
& IEEE80211_TX_INTFL_RETRANSMISSION
)) {
1759 __skb_queue_tail(&tx
->skbs
, tx
->skb
);
1764 CALL_TXH(ieee80211_tx_h_michael_mic_add
);
1765 CALL_TXH(ieee80211_tx_h_sequence
);
1766 CALL_TXH(ieee80211_tx_h_fragment
);
1767 /* handlers after fragment must be aware of tx info fragmentation! */
1768 CALL_TXH(ieee80211_tx_h_stats
);
1769 CALL_TXH(ieee80211_tx_h_encrypt
);
1770 if (!ieee80211_hw_check(&tx
->local
->hw
, HAS_RATE_CONTROL
))
1771 CALL_TXH(ieee80211_tx_h_calculate_duration
);
1775 if (unlikely(res
== TX_DROP
)) {
1776 I802_DEBUG_INC(tx
->local
->tx_handlers_drop
);
1778 ieee80211_free_txskb(&tx
->local
->hw
, tx
->skb
);
1780 ieee80211_purge_tx_queue(&tx
->local
->hw
, &tx
->skbs
);
1782 } else if (unlikely(res
== TX_QUEUED
)) {
1783 I802_DEBUG_INC(tx
->local
->tx_handlers_queued
);
1790 static int invoke_tx_handlers(struct ieee80211_tx_data
*tx
)
1792 int r
= invoke_tx_handlers_early(tx
);
1796 return invoke_tx_handlers_late(tx
);
1799 bool ieee80211_tx_prepare_skb(struct ieee80211_hw
*hw
,
1800 struct ieee80211_vif
*vif
, struct sk_buff
*skb
,
1801 int band
, struct ieee80211_sta
**sta
)
1803 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
1804 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1805 struct ieee80211_tx_data tx
;
1806 struct sk_buff
*skb2
;
1808 if (ieee80211_tx_prepare(sdata
, &tx
, NULL
, skb
) == TX_DROP
)
1812 info
->control
.vif
= vif
;
1813 info
->hw_queue
= vif
->hw_queue
[skb_get_queue_mapping(skb
)];
1815 if (invoke_tx_handlers(&tx
))
1820 *sta
= &tx
.sta
->sta
;
1825 /* this function isn't suitable for fragmented data frames */
1826 skb2
= __skb_dequeue(&tx
.skbs
);
1827 if (WARN_ON(skb2
!= skb
|| !skb_queue_empty(&tx
.skbs
))) {
1828 ieee80211_free_txskb(hw
, skb2
);
1829 ieee80211_purge_tx_queue(hw
, &tx
.skbs
);
1835 EXPORT_SYMBOL(ieee80211_tx_prepare_skb
);
1838 * Returns false if the frame couldn't be transmitted but was queued instead.
1840 static bool ieee80211_tx(struct ieee80211_sub_if_data
*sdata
,
1841 struct sta_info
*sta
, struct sk_buff
*skb
,
1844 struct ieee80211_local
*local
= sdata
->local
;
1845 struct ieee80211_tx_data tx
;
1846 ieee80211_tx_result res_prepare
;
1847 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1851 if (unlikely(skb
->len
< 10)) {
1856 /* initialises tx */
1858 res_prepare
= ieee80211_tx_prepare(sdata
, &tx
, sta
, skb
);
1860 if (unlikely(res_prepare
== TX_DROP
)) {
1861 ieee80211_free_txskb(&local
->hw
, skb
);
1863 } else if (unlikely(res_prepare
== TX_QUEUED
)) {
1867 /* set up hw_queue value early */
1868 if (!(info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
) ||
1869 !ieee80211_hw_check(&local
->hw
, QUEUE_CONTROL
))
1871 sdata
->vif
.hw_queue
[skb_get_queue_mapping(skb
)];
1873 if (invoke_tx_handlers_early(&tx
))
1876 if (ieee80211_queue_skb(local
, sdata
, tx
.sta
, tx
.skb
))
1879 if (!invoke_tx_handlers_late(&tx
))
1880 result
= __ieee80211_tx(local
, &tx
.skbs
, led_len
,
1886 /* device xmit handlers */
1888 static int ieee80211_skb_resize(struct ieee80211_sub_if_data
*sdata
,
1889 struct sk_buff
*skb
,
1890 int head_need
, bool may_encrypt
)
1892 struct ieee80211_local
*local
= sdata
->local
;
1893 struct ieee80211_hdr
*hdr
;
1897 hdr
= (struct ieee80211_hdr
*) skb
->data
;
1898 enc_tailroom
= may_encrypt
&&
1899 (sdata
->crypto_tx_tailroom_needed_cnt
||
1900 ieee80211_is_mgmt(hdr
->frame_control
));
1903 tail_need
= IEEE80211_ENCRYPT_TAILROOM
;
1904 tail_need
-= skb_tailroom(skb
);
1905 tail_need
= max_t(int, tail_need
, 0);
1908 if (skb_cloned(skb
) &&
1909 (!ieee80211_hw_check(&local
->hw
, SUPPORTS_CLONED_SKBS
) ||
1910 !skb_clone_writable(skb
, ETH_HLEN
) || enc_tailroom
))
1911 I802_DEBUG_INC(local
->tx_expand_skb_head_cloned
);
1912 else if (head_need
|| tail_need
)
1913 I802_DEBUG_INC(local
->tx_expand_skb_head
);
1917 if (pskb_expand_head(skb
, head_need
, tail_need
, GFP_ATOMIC
)) {
1918 wiphy_debug(local
->hw
.wiphy
,
1919 "failed to reallocate TX buffer\n");
1926 void ieee80211_xmit(struct ieee80211_sub_if_data
*sdata
,
1927 struct sta_info
*sta
, struct sk_buff
*skb
)
1929 struct ieee80211_local
*local
= sdata
->local
;
1930 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1931 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1935 may_encrypt
= !(info
->flags
& IEEE80211_TX_INTFL_DONT_ENCRYPT
);
1937 headroom
= local
->tx_headroom
;
1939 headroom
+= sdata
->encrypt_headroom
;
1940 headroom
-= skb_headroom(skb
);
1941 headroom
= max_t(int, 0, headroom
);
1943 if (ieee80211_skb_resize(sdata
, skb
, headroom
, may_encrypt
)) {
1944 ieee80211_free_txskb(&local
->hw
, skb
);
1948 hdr
= (struct ieee80211_hdr
*) skb
->data
;
1949 info
->control
.vif
= &sdata
->vif
;
1951 if (ieee80211_vif_is_mesh(&sdata
->vif
)) {
1952 if (ieee80211_is_data(hdr
->frame_control
) &&
1953 is_unicast_ether_addr(hdr
->addr1
)) {
1954 if (mesh_nexthop_resolve(sdata
, skb
))
1955 return; /* skb queued: don't free */
1957 ieee80211_mps_set_frame_flags(sdata
, NULL
, hdr
);
1961 ieee80211_set_qos_hdr(sdata
, skb
);
1962 ieee80211_tx(sdata
, sta
, skb
, false);
1965 static bool ieee80211_parse_tx_radiotap(struct ieee80211_local
*local
,
1966 struct sk_buff
*skb
)
1968 struct ieee80211_radiotap_iterator iterator
;
1969 struct ieee80211_radiotap_header
*rthdr
=
1970 (struct ieee80211_radiotap_header
*) skb
->data
;
1971 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1972 struct ieee80211_supported_band
*sband
=
1973 local
->hw
.wiphy
->bands
[info
->band
];
1974 int ret
= ieee80211_radiotap_iterator_init(&iterator
, rthdr
, skb
->len
,
1978 bool rate_found
= false;
1979 u8 rate_retries
= 0;
1981 u8 mcs_known
, mcs_flags
, mcs_bw
;
1983 u8 vht_mcs
= 0, vht_nss
= 0;
1986 info
->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
|
1987 IEEE80211_TX_CTL_DONTFRAG
;
1990 * for every radiotap entry that is present
1991 * (ieee80211_radiotap_iterator_next returns -ENOENT when no more
1992 * entries present, or -EINVAL on error)
1996 ret
= ieee80211_radiotap_iterator_next(&iterator
);
2001 /* see if this argument is something we can use */
2002 switch (iterator
.this_arg_index
) {
2004 * You must take care when dereferencing iterator.this_arg
2005 * for multibyte types... the pointer is not aligned. Use
2006 * get_unaligned((type *)iterator.this_arg) to dereference
2007 * iterator.this_arg for type "type" safely on all arches.
2009 case IEEE80211_RADIOTAP_FLAGS
:
2010 if (*iterator
.this_arg
& IEEE80211_RADIOTAP_F_FCS
) {
2012 * this indicates that the skb we have been
2013 * handed has the 32-bit FCS CRC at the end...
2014 * we should react to that by snipping it off
2015 * because it will be recomputed and added
2018 if (skb
->len
< (iterator
._max_length
+ FCS_LEN
))
2021 skb_trim(skb
, skb
->len
- FCS_LEN
);
2023 if (*iterator
.this_arg
& IEEE80211_RADIOTAP_F_WEP
)
2024 info
->flags
&= ~IEEE80211_TX_INTFL_DONT_ENCRYPT
;
2025 if (*iterator
.this_arg
& IEEE80211_RADIOTAP_F_FRAG
)
2026 info
->flags
&= ~IEEE80211_TX_CTL_DONTFRAG
;
2029 case IEEE80211_RADIOTAP_TX_FLAGS
:
2030 txflags
= get_unaligned_le16(iterator
.this_arg
);
2031 if (txflags
& IEEE80211_RADIOTAP_F_TX_NOACK
)
2032 info
->flags
|= IEEE80211_TX_CTL_NO_ACK
;
2035 case IEEE80211_RADIOTAP_RATE
:
2036 rate
= *iterator
.this_arg
;
2041 case IEEE80211_RADIOTAP_DATA_RETRIES
:
2042 rate_retries
= *iterator
.this_arg
;
2045 case IEEE80211_RADIOTAP_MCS
:
2046 mcs_known
= iterator
.this_arg
[0];
2047 mcs_flags
= iterator
.this_arg
[1];
2048 if (!(mcs_known
& IEEE80211_RADIOTAP_MCS_HAVE_MCS
))
2052 rate
= iterator
.this_arg
[2];
2053 rate_flags
= IEEE80211_TX_RC_MCS
;
2055 if (mcs_known
& IEEE80211_RADIOTAP_MCS_HAVE_GI
&&
2056 mcs_flags
& IEEE80211_RADIOTAP_MCS_SGI
)
2057 rate_flags
|= IEEE80211_TX_RC_SHORT_GI
;
2059 mcs_bw
= mcs_flags
& IEEE80211_RADIOTAP_MCS_BW_MASK
;
2060 if (mcs_known
& IEEE80211_RADIOTAP_MCS_HAVE_BW
&&
2061 mcs_bw
== IEEE80211_RADIOTAP_MCS_BW_40
)
2062 rate_flags
|= IEEE80211_TX_RC_40_MHZ_WIDTH
;
2065 case IEEE80211_RADIOTAP_VHT
:
2066 vht_known
= get_unaligned_le16(iterator
.this_arg
);
2069 rate_flags
= IEEE80211_TX_RC_VHT_MCS
;
2070 if ((vht_known
& IEEE80211_RADIOTAP_VHT_KNOWN_GI
) &&
2071 (iterator
.this_arg
[2] &
2072 IEEE80211_RADIOTAP_VHT_FLAG_SGI
))
2073 rate_flags
|= IEEE80211_TX_RC_SHORT_GI
;
2075 IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH
) {
2076 if (iterator
.this_arg
[3] == 1)
2078 IEEE80211_TX_RC_40_MHZ_WIDTH
;
2079 else if (iterator
.this_arg
[3] == 4)
2081 IEEE80211_TX_RC_80_MHZ_WIDTH
;
2082 else if (iterator
.this_arg
[3] == 11)
2084 IEEE80211_TX_RC_160_MHZ_WIDTH
;
2087 vht_mcs
= iterator
.this_arg
[4] >> 4;
2088 vht_nss
= iterator
.this_arg
[4] & 0xF;
2092 * Please update the file
2093 * Documentation/networking/mac80211-injection.txt
2094 * when parsing new fields here.
2102 if (ret
!= -ENOENT
) /* ie, if we didn't simply run out of fields */
2106 info
->control
.flags
|= IEEE80211_TX_CTRL_RATE_INJECT
;
2108 for (i
= 0; i
< IEEE80211_TX_MAX_RATES
; i
++) {
2109 info
->control
.rates
[i
].idx
= -1;
2110 info
->control
.rates
[i
].flags
= 0;
2111 info
->control
.rates
[i
].count
= 0;
2114 if (rate_flags
& IEEE80211_TX_RC_MCS
) {
2115 info
->control
.rates
[0].idx
= rate
;
2116 } else if (rate_flags
& IEEE80211_TX_RC_VHT_MCS
) {
2117 ieee80211_rate_set_vht(info
->control
.rates
, vht_mcs
,
2120 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
2121 if (rate
* 5 != sband
->bitrates
[i
].bitrate
)
2124 info
->control
.rates
[0].idx
= i
;
2129 if (info
->control
.rates
[0].idx
< 0)
2130 info
->control
.flags
&= ~IEEE80211_TX_CTRL_RATE_INJECT
;
2132 info
->control
.rates
[0].flags
= rate_flags
;
2133 info
->control
.rates
[0].count
= min_t(u8
, rate_retries
+ 1,
2134 local
->hw
.max_rate_tries
);
2138 * remove the radiotap header
2139 * iterator->_max_length was sanity-checked against
2140 * skb->len by iterator init
2142 skb_pull(skb
, iterator
._max_length
);
2147 netdev_tx_t
ieee80211_monitor_start_xmit(struct sk_buff
*skb
,
2148 struct net_device
*dev
)
2150 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2151 struct ieee80211_chanctx_conf
*chanctx_conf
;
2152 struct ieee80211_radiotap_header
*prthdr
=
2153 (struct ieee80211_radiotap_header
*)skb
->data
;
2154 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
2155 struct ieee80211_hdr
*hdr
;
2156 struct ieee80211_sub_if_data
*tmp_sdata
, *sdata
;
2157 struct cfg80211_chan_def
*chandef
;
2161 /* check for not even having the fixed radiotap header part */
2162 if (unlikely(skb
->len
< sizeof(struct ieee80211_radiotap_header
)))
2163 goto fail
; /* too short to be possibly valid */
2165 /* is it a header version we can trust to find length from? */
2166 if (unlikely(prthdr
->it_version
))
2167 goto fail
; /* only version 0 is supported */
2169 /* then there must be a radiotap header with a length we can use */
2170 len_rthdr
= ieee80211_get_radiotap_len(skb
->data
);
2172 /* does the skb contain enough to deliver on the alleged length? */
2173 if (unlikely(skb
->len
< len_rthdr
))
2174 goto fail
; /* skb too short for claimed rt header extent */
2177 * fix up the pointers accounting for the radiotap
2178 * header still being in there. We are being given
2179 * a precooked IEEE80211 header so no need for
2182 skb_set_mac_header(skb
, len_rthdr
);
2184 * these are just fixed to the end of the rt area since we
2185 * don't have any better information and at this point, nobody cares
2187 skb_set_network_header(skb
, len_rthdr
);
2188 skb_set_transport_header(skb
, len_rthdr
);
2190 if (skb
->len
< len_rthdr
+ 2)
2193 hdr
= (struct ieee80211_hdr
*)(skb
->data
+ len_rthdr
);
2194 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
2196 if (skb
->len
< len_rthdr
+ hdrlen
)
2200 * Initialize skb->protocol if the injected frame is a data frame
2201 * carrying a rfc1042 header
2203 if (ieee80211_is_data(hdr
->frame_control
) &&
2204 skb
->len
>= len_rthdr
+ hdrlen
+ sizeof(rfc1042_header
) + 2) {
2205 u8
*payload
= (u8
*)hdr
+ hdrlen
;
2207 if (ether_addr_equal(payload
, rfc1042_header
))
2208 skb
->protocol
= cpu_to_be16((payload
[6] << 8) |
2212 memset(info
, 0, sizeof(*info
));
2214 info
->flags
= IEEE80211_TX_CTL_REQ_TX_STATUS
|
2215 IEEE80211_TX_CTL_INJECTED
;
2220 * We process outgoing injected frames that have a local address
2221 * we handle as though they are non-injected frames.
2222 * This code here isn't entirely correct, the local MAC address
2223 * isn't always enough to find the interface to use; for proper
2224 * VLAN/WDS support we will need a different mechanism (which
2225 * likely isn't going to be monitor interfaces).
2227 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2229 list_for_each_entry_rcu(tmp_sdata
, &local
->interfaces
, list
) {
2230 if (!ieee80211_sdata_running(tmp_sdata
))
2232 if (tmp_sdata
->vif
.type
== NL80211_IFTYPE_MONITOR
||
2233 tmp_sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
||
2234 tmp_sdata
->vif
.type
== NL80211_IFTYPE_WDS
)
2236 if (ether_addr_equal(tmp_sdata
->vif
.addr
, hdr
->addr2
)) {
2242 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
2243 if (!chanctx_conf
) {
2244 tmp_sdata
= rcu_dereference(local
->monitor_sdata
);
2247 rcu_dereference(tmp_sdata
->vif
.chanctx_conf
);
2251 chandef
= &chanctx_conf
->def
;
2252 else if (!local
->use_chanctx
)
2253 chandef
= &local
->_oper_chandef
;
2258 * Frame injection is not allowed if beaconing is not allowed
2259 * or if we need radar detection. Beaconing is usually not allowed when
2260 * the mode or operation (Adhoc, AP, Mesh) does not support DFS.
2261 * Passive scan is also used in world regulatory domains where
2262 * your country is not known and as such it should be treated as
2263 * NO TX unless the channel is explicitly allowed in which case
2264 * your current regulatory domain would not have the passive scan
2267 * Since AP mode uses monitor interfaces to inject/TX management
2268 * frames we can make AP mode the exception to this rule once it
2269 * supports radar detection as its implementation can deal with
2270 * radar detection by itself. We can do that later by adding a
2271 * monitor flag interfaces used for AP support.
2273 if (!cfg80211_reg_can_beacon(local
->hw
.wiphy
, chandef
,
2277 info
->band
= chandef
->chan
->band
;
2279 /* process and remove the injection radiotap header */
2280 if (!ieee80211_parse_tx_radiotap(local
, skb
))
2283 ieee80211_xmit(sdata
, NULL
, skb
);
2286 return NETDEV_TX_OK
;
2292 return NETDEV_TX_OK
; /* meaning, we dealt with the skb */
2295 static inline bool ieee80211_is_tdls_setup(struct sk_buff
*skb
)
2297 u16 ethertype
= (skb
->data
[12] << 8) | skb
->data
[13];
2299 return ethertype
== ETH_P_TDLS
&&
2301 skb
->data
[14] == WLAN_TDLS_SNAP_RFTYPE
;
2304 static int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data
*sdata
,
2305 struct sk_buff
*skb
,
2306 struct sta_info
**sta_out
)
2308 struct sta_info
*sta
;
2310 switch (sdata
->vif
.type
) {
2311 case NL80211_IFTYPE_AP_VLAN
:
2312 sta
= rcu_dereference(sdata
->u
.vlan
.sta
);
2316 } else if (sdata
->wdev
.use_4addr
) {
2320 case NL80211_IFTYPE_AP
:
2321 case NL80211_IFTYPE_OCB
:
2322 case NL80211_IFTYPE_ADHOC
:
2323 if (is_multicast_ether_addr(skb
->data
)) {
2324 *sta_out
= ERR_PTR(-ENOENT
);
2327 sta
= sta_info_get_bss(sdata
, skb
->data
);
2329 case NL80211_IFTYPE_WDS
:
2330 sta
= sta_info_get(sdata
, sdata
->u
.wds
.remote_addr
);
2332 #ifdef CONFIG_MAC80211_MESH
2333 case NL80211_IFTYPE_MESH_POINT
:
2334 /* determined much later */
2338 case NL80211_IFTYPE_STATION
:
2339 if (sdata
->wdev
.wiphy
->flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
2340 sta
= sta_info_get(sdata
, skb
->data
);
2341 if (sta
&& test_sta_flag(sta
, WLAN_STA_TDLS_PEER
)) {
2342 if (test_sta_flag(sta
,
2343 WLAN_STA_TDLS_PEER_AUTH
)) {
2349 * TDLS link during setup - throw out frames to
2350 * peer. Allow TDLS-setup frames to unauthorized
2351 * peers for the special case of a link teardown
2352 * after a TDLS sta is removed due to being
2355 if (!ieee80211_is_tdls_setup(skb
))
2361 sta
= sta_info_get(sdata
, sdata
->u
.mgd
.bssid
);
2369 *sta_out
= sta
?: ERR_PTR(-ENOENT
);
2374 * ieee80211_build_hdr - build 802.11 header in the given frame
2375 * @sdata: virtual interface to build the header for
2376 * @skb: the skb to build the header in
2377 * @info_flags: skb flags to set
2379 * This function takes the skb with 802.3 header and reformats the header to
2380 * the appropriate IEEE 802.11 header based on which interface the packet is
2381 * being transmitted on.
2383 * Note that this function also takes care of the TX status request and
2384 * potential unsharing of the SKB - this needs to be interleaved with the
2387 * The function requires the read-side RCU lock held
2389 * Returns: the (possibly reallocated) skb or an ERR_PTR() code
2391 static struct sk_buff
*ieee80211_build_hdr(struct ieee80211_sub_if_data
*sdata
,
2392 struct sk_buff
*skb
, u32 info_flags
,
2393 struct sta_info
*sta
)
2395 struct ieee80211_local
*local
= sdata
->local
;
2396 struct ieee80211_tx_info
*info
;
2398 u16 ethertype
, hdrlen
, meshhdrlen
= 0;
2400 struct ieee80211_hdr hdr
;
2401 struct ieee80211s_hdr mesh_hdr __maybe_unused
;
2402 struct mesh_path __maybe_unused
*mppath
= NULL
, *mpath
= NULL
;
2403 const u8
*encaps_data
;
2404 int encaps_len
, skip_header_bytes
;
2405 bool wme_sta
= false, authorized
= false;
2409 struct ieee80211_chanctx_conf
*chanctx_conf
;
2410 struct ieee80211_sub_if_data
*ap_sdata
;
2411 enum nl80211_band band
;
2417 /* convert Ethernet header to proper 802.11 header (based on
2418 * operation mode) */
2419 ethertype
= (skb
->data
[12] << 8) | skb
->data
[13];
2420 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_DATA
);
2422 switch (sdata
->vif
.type
) {
2423 case NL80211_IFTYPE_AP_VLAN
:
2424 if (sdata
->wdev
.use_4addr
) {
2425 fc
|= cpu_to_le16(IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
);
2427 memcpy(hdr
.addr1
, sta
->sta
.addr
, ETH_ALEN
);
2428 memcpy(hdr
.addr2
, sdata
->vif
.addr
, ETH_ALEN
);
2429 memcpy(hdr
.addr3
, skb
->data
, ETH_ALEN
);
2430 memcpy(hdr
.addr4
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
2432 authorized
= test_sta_flag(sta
, WLAN_STA_AUTHORIZED
);
2433 wme_sta
= sta
->sta
.wme
;
2435 ap_sdata
= container_of(sdata
->bss
, struct ieee80211_sub_if_data
,
2437 chanctx_conf
= rcu_dereference(ap_sdata
->vif
.chanctx_conf
);
2438 if (!chanctx_conf
) {
2442 band
= chanctx_conf
->def
.chan
->band
;
2443 if (sdata
->wdev
.use_4addr
)
2446 case NL80211_IFTYPE_AP
:
2447 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
)
2448 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
2449 if (!chanctx_conf
) {
2453 fc
|= cpu_to_le16(IEEE80211_FCTL_FROMDS
);
2455 memcpy(hdr
.addr1
, skb
->data
, ETH_ALEN
);
2456 memcpy(hdr
.addr2
, sdata
->vif
.addr
, ETH_ALEN
);
2457 memcpy(hdr
.addr3
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
2459 band
= chanctx_conf
->def
.chan
->band
;
2461 case NL80211_IFTYPE_WDS
:
2462 fc
|= cpu_to_le16(IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
);
2464 memcpy(hdr
.addr1
, sdata
->u
.wds
.remote_addr
, ETH_ALEN
);
2465 memcpy(hdr
.addr2
, sdata
->vif
.addr
, ETH_ALEN
);
2466 memcpy(hdr
.addr3
, skb
->data
, ETH_ALEN
);
2467 memcpy(hdr
.addr4
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
2470 * This is the exception! WDS style interfaces are prohibited
2471 * when channel contexts are in used so this must be valid
2473 band
= local
->hw
.conf
.chandef
.chan
->band
;
2475 #ifdef CONFIG_MAC80211_MESH
2476 case NL80211_IFTYPE_MESH_POINT
:
2477 if (!is_multicast_ether_addr(skb
->data
)) {
2478 struct sta_info
*next_hop
;
2479 bool mpp_lookup
= true;
2481 mpath
= mesh_path_lookup(sdata
, skb
->data
);
2484 next_hop
= rcu_dereference(mpath
->next_hop
);
2486 !(mpath
->flags
& (MESH_PATH_ACTIVE
|
2487 MESH_PATH_RESOLVING
)))
2492 mppath
= mpp_path_lookup(sdata
, skb
->data
);
2494 mppath
->exp_time
= jiffies
;
2497 if (mppath
&& mpath
)
2498 mesh_path_del(sdata
, mpath
->dst
);
2502 * Use address extension if it is a packet from
2503 * another interface or if we know the destination
2504 * is being proxied by a portal (i.e. portal address
2505 * differs from proxied address)
2507 if (ether_addr_equal(sdata
->vif
.addr
, skb
->data
+ ETH_ALEN
) &&
2508 !(mppath
&& !ether_addr_equal(mppath
->mpp
, skb
->data
))) {
2509 hdrlen
= ieee80211_fill_mesh_addresses(&hdr
, &fc
,
2510 skb
->data
, skb
->data
+ ETH_ALEN
);
2511 meshhdrlen
= ieee80211_new_mesh_header(sdata
, &mesh_hdr
,
2514 /* DS -> MBSS (802.11-2012 13.11.3.3).
2515 * For unicast with unknown forwarding information,
2516 * destination might be in the MBSS or if that fails
2517 * forwarded to another mesh gate. In either case
2518 * resolution will be handled in ieee80211_xmit(), so
2519 * leave the original DA. This also works for mcast */
2520 const u8
*mesh_da
= skb
->data
;
2523 mesh_da
= mppath
->mpp
;
2525 mesh_da
= mpath
->dst
;
2527 hdrlen
= ieee80211_fill_mesh_addresses(&hdr
, &fc
,
2528 mesh_da
, sdata
->vif
.addr
);
2529 if (is_multicast_ether_addr(mesh_da
))
2530 /* DA TA mSA AE:SA */
2531 meshhdrlen
= ieee80211_new_mesh_header(
2533 skb
->data
+ ETH_ALEN
, NULL
);
2535 /* RA TA mDA mSA AE:DA SA */
2536 meshhdrlen
= ieee80211_new_mesh_header(
2537 sdata
, &mesh_hdr
, skb
->data
,
2538 skb
->data
+ ETH_ALEN
);
2541 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
2542 if (!chanctx_conf
) {
2546 band
= chanctx_conf
->def
.chan
->band
;
2549 case NL80211_IFTYPE_STATION
:
2550 /* we already did checks when looking up the RA STA */
2551 tdls_peer
= test_sta_flag(sta
, WLAN_STA_TDLS_PEER
);
2555 memcpy(hdr
.addr1
, skb
->data
, ETH_ALEN
);
2556 memcpy(hdr
.addr2
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
2557 memcpy(hdr
.addr3
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
2559 } else if (sdata
->u
.mgd
.use_4addr
&&
2560 cpu_to_be16(ethertype
) != sdata
->control_port_protocol
) {
2561 fc
|= cpu_to_le16(IEEE80211_FCTL_FROMDS
|
2562 IEEE80211_FCTL_TODS
);
2564 memcpy(hdr
.addr1
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
2565 memcpy(hdr
.addr2
, sdata
->vif
.addr
, ETH_ALEN
);
2566 memcpy(hdr
.addr3
, skb
->data
, ETH_ALEN
);
2567 memcpy(hdr
.addr4
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
2570 fc
|= cpu_to_le16(IEEE80211_FCTL_TODS
);
2572 memcpy(hdr
.addr1
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
2573 memcpy(hdr
.addr2
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
2574 memcpy(hdr
.addr3
, skb
->data
, ETH_ALEN
);
2577 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
2578 if (!chanctx_conf
) {
2582 band
= chanctx_conf
->def
.chan
->band
;
2584 case NL80211_IFTYPE_OCB
:
2586 memcpy(hdr
.addr1
, skb
->data
, ETH_ALEN
);
2587 memcpy(hdr
.addr2
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
2588 eth_broadcast_addr(hdr
.addr3
);
2590 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
2591 if (!chanctx_conf
) {
2595 band
= chanctx_conf
->def
.chan
->band
;
2597 case NL80211_IFTYPE_ADHOC
:
2599 memcpy(hdr
.addr1
, skb
->data
, ETH_ALEN
);
2600 memcpy(hdr
.addr2
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
2601 memcpy(hdr
.addr3
, sdata
->u
.ibss
.bssid
, ETH_ALEN
);
2603 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
2604 if (!chanctx_conf
) {
2608 band
= chanctx_conf
->def
.chan
->band
;
2615 multicast
= is_multicast_ether_addr(hdr
.addr1
);
2617 /* sta is always NULL for mesh */
2619 authorized
= test_sta_flag(sta
, WLAN_STA_AUTHORIZED
);
2620 wme_sta
= sta
->sta
.wme
;
2621 } else if (ieee80211_vif_is_mesh(&sdata
->vif
)) {
2622 /* For mesh, the use of the QoS header is mandatory */
2626 /* receiver does QoS (which also means we do) use it */
2628 fc
|= cpu_to_le16(IEEE80211_STYPE_QOS_DATA
);
2633 * Drop unicast frames to unauthorised stations unless they are
2634 * EAPOL frames from the local station.
2636 if (unlikely(!ieee80211_vif_is_mesh(&sdata
->vif
) &&
2637 (sdata
->vif
.type
!= NL80211_IFTYPE_OCB
) &&
2638 !multicast
&& !authorized
&&
2639 (cpu_to_be16(ethertype
) != sdata
->control_port_protocol
||
2640 !ether_addr_equal(sdata
->vif
.addr
, skb
->data
+ ETH_ALEN
)))) {
2641 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2642 net_info_ratelimited("%s: dropped frame to %pM (unauthorized port)\n",
2643 sdata
->name
, hdr
.addr1
);
2646 I802_DEBUG_INC(local
->tx_handlers_drop_unauth_port
);
2652 if (unlikely(!multicast
&& skb
->sk
&&
2653 skb_shinfo(skb
)->tx_flags
& SKBTX_WIFI_STATUS
)) {
2654 struct sk_buff
*ack_skb
= skb_clone_sk(skb
);
2657 unsigned long flags
;
2660 spin_lock_irqsave(&local
->ack_status_lock
, flags
);
2661 id
= idr_alloc(&local
->ack_status_frames
, ack_skb
,
2662 1, 0x10000, GFP_ATOMIC
);
2663 spin_unlock_irqrestore(&local
->ack_status_lock
, flags
);
2667 info_flags
|= IEEE80211_TX_CTL_REQ_TX_STATUS
;
2675 * If the skb is shared we need to obtain our own copy.
2677 if (skb_shared(skb
)) {
2678 struct sk_buff
*tmp_skb
= skb
;
2680 /* can't happen -- skb is a clone if info_id != 0 */
2683 skb
= skb_clone(skb
, GFP_ATOMIC
);
2692 hdr
.frame_control
= fc
;
2693 hdr
.duration_id
= 0;
2696 skip_header_bytes
= ETH_HLEN
;
2697 if (ethertype
== ETH_P_AARP
|| ethertype
== ETH_P_IPX
) {
2698 encaps_data
= bridge_tunnel_header
;
2699 encaps_len
= sizeof(bridge_tunnel_header
);
2700 skip_header_bytes
-= 2;
2701 } else if (ethertype
>= ETH_P_802_3_MIN
) {
2702 encaps_data
= rfc1042_header
;
2703 encaps_len
= sizeof(rfc1042_header
);
2704 skip_header_bytes
-= 2;
2710 skb_pull(skb
, skip_header_bytes
);
2711 head_need
= hdrlen
+ encaps_len
+ meshhdrlen
- skb_headroom(skb
);
2714 * So we need to modify the skb header and hence need a copy of
2715 * that. The head_need variable above doesn't, so far, include
2716 * the needed header space that we don't need right away. If we
2717 * can, then we don't reallocate right now but only after the
2718 * frame arrives at the master device (if it does...)
2720 * If we cannot, however, then we will reallocate to include all
2721 * the ever needed space. Also, if we need to reallocate it anyway,
2722 * make it big enough for everything we may ever need.
2725 if (head_need
> 0 || skb_cloned(skb
)) {
2726 head_need
+= sdata
->encrypt_headroom
;
2727 head_need
+= local
->tx_headroom
;
2728 head_need
= max_t(int, 0, head_need
);
2729 if (ieee80211_skb_resize(sdata
, skb
, head_need
, true)) {
2730 ieee80211_free_txskb(&local
->hw
, skb
);
2732 return ERR_PTR(-ENOMEM
);
2737 memcpy(skb_push(skb
, encaps_len
), encaps_data
, encaps_len
);
2739 #ifdef CONFIG_MAC80211_MESH
2741 memcpy(skb_push(skb
, meshhdrlen
), &mesh_hdr
, meshhdrlen
);
2744 if (ieee80211_is_data_qos(fc
)) {
2745 __le16
*qos_control
;
2747 qos_control
= skb_push(skb
, 2);
2748 memcpy(skb_push(skb
, hdrlen
- 2), &hdr
, hdrlen
- 2);
2750 * Maybe we could actually set some fields here, for now just
2751 * initialise to zero to indicate no special operation.
2755 memcpy(skb_push(skb
, hdrlen
), &hdr
, hdrlen
);
2757 skb_reset_mac_header(skb
);
2759 info
= IEEE80211_SKB_CB(skb
);
2760 memset(info
, 0, sizeof(*info
));
2762 info
->flags
= info_flags
;
2763 info
->ack_frame_id
= info_id
;
2769 return ERR_PTR(ret
);
2773 * fast-xmit overview
2775 * The core idea of this fast-xmit is to remove per-packet checks by checking
2776 * them out of band. ieee80211_check_fast_xmit() implements the out-of-band
2777 * checks that are needed to get the sta->fast_tx pointer assigned, after which
2778 * much less work can be done per packet. For example, fragmentation must be
2779 * disabled or the fast_tx pointer will not be set. All the conditions are seen
2782 * Once assigned, the fast_tx data structure also caches the per-packet 802.11
2783 * header and other data to aid packet processing in ieee80211_xmit_fast().
2785 * The most difficult part of this is that when any of these assumptions
2786 * change, an external trigger (i.e. a call to ieee80211_clear_fast_xmit(),
2787 * ieee80211_check_fast_xmit() or friends) is required to reset the data,
2788 * since the per-packet code no longer checks the conditions. This is reflected
2789 * by the calls to these functions throughout the rest of the code, and must be
2790 * maintained if any of the TX path checks change.
2793 void ieee80211_check_fast_xmit(struct sta_info
*sta
)
2795 struct ieee80211_fast_tx build
= {}, *fast_tx
= NULL
, *old
;
2796 struct ieee80211_local
*local
= sta
->local
;
2797 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
2798 struct ieee80211_hdr
*hdr
= (void *)build
.hdr
;
2799 struct ieee80211_chanctx_conf
*chanctx_conf
;
2802 if (!ieee80211_hw_check(&local
->hw
, SUPPORT_FAST_XMIT
))
2805 /* Locking here protects both the pointer itself, and against concurrent
2806 * invocations winning data access races to, e.g., the key pointer that
2808 * Without it, the invocation of this function right after the key
2809 * pointer changes wouldn't be sufficient, as another CPU could access
2810 * the pointer, then stall, and then do the cache update after the CPU
2811 * that invalidated the key.
2812 * With the locking, such scenarios cannot happen as the check for the
2813 * key and the fast-tx assignment are done atomically, so the CPU that
2814 * modifies the key will either wait or other one will see the key
2815 * cleared/changed already.
2817 spin_lock_bh(&sta
->lock
);
2818 if (ieee80211_hw_check(&local
->hw
, SUPPORTS_PS
) &&
2819 !ieee80211_hw_check(&local
->hw
, SUPPORTS_DYNAMIC_PS
) &&
2820 sdata
->vif
.type
== NL80211_IFTYPE_STATION
)
2823 if (!test_sta_flag(sta
, WLAN_STA_AUTHORIZED
))
2826 if (test_sta_flag(sta
, WLAN_STA_PS_STA
) ||
2827 test_sta_flag(sta
, WLAN_STA_PS_DRIVER
) ||
2828 test_sta_flag(sta
, WLAN_STA_PS_DELIVER
) ||
2829 test_sta_flag(sta
, WLAN_STA_CLEAR_PS_FILT
))
2832 if (sdata
->noack_map
)
2835 /* fast-xmit doesn't handle fragmentation at all */
2836 if (local
->hw
.wiphy
->frag_threshold
!= (u32
)-1 &&
2837 !ieee80211_hw_check(&local
->hw
, SUPPORTS_TX_FRAG
))
2841 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
2842 if (!chanctx_conf
) {
2846 build
.band
= chanctx_conf
->def
.chan
->band
;
2849 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_DATA
);
2851 switch (sdata
->vif
.type
) {
2852 case NL80211_IFTYPE_ADHOC
:
2854 build
.da_offs
= offsetof(struct ieee80211_hdr
, addr1
);
2855 build
.sa_offs
= offsetof(struct ieee80211_hdr
, addr2
);
2856 memcpy(hdr
->addr3
, sdata
->u
.ibss
.bssid
, ETH_ALEN
);
2859 case NL80211_IFTYPE_STATION
:
2860 if (test_sta_flag(sta
, WLAN_STA_TDLS_PEER
)) {
2862 build
.da_offs
= offsetof(struct ieee80211_hdr
, addr1
);
2863 build
.sa_offs
= offsetof(struct ieee80211_hdr
, addr2
);
2864 memcpy(hdr
->addr3
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
2869 if (sdata
->u
.mgd
.use_4addr
) {
2870 /* non-regular ethertype cannot use the fastpath */
2871 fc
|= cpu_to_le16(IEEE80211_FCTL_FROMDS
|
2872 IEEE80211_FCTL_TODS
);
2874 memcpy(hdr
->addr1
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
2875 memcpy(hdr
->addr2
, sdata
->vif
.addr
, ETH_ALEN
);
2876 build
.da_offs
= offsetof(struct ieee80211_hdr
, addr3
);
2877 build
.sa_offs
= offsetof(struct ieee80211_hdr
, addr4
);
2881 fc
|= cpu_to_le16(IEEE80211_FCTL_TODS
);
2883 memcpy(hdr
->addr1
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
2884 build
.da_offs
= offsetof(struct ieee80211_hdr
, addr3
);
2885 build
.sa_offs
= offsetof(struct ieee80211_hdr
, addr2
);
2888 case NL80211_IFTYPE_AP_VLAN
:
2889 if (sdata
->wdev
.use_4addr
) {
2890 fc
|= cpu_to_le16(IEEE80211_FCTL_FROMDS
|
2891 IEEE80211_FCTL_TODS
);
2893 memcpy(hdr
->addr1
, sta
->sta
.addr
, ETH_ALEN
);
2894 memcpy(hdr
->addr2
, sdata
->vif
.addr
, ETH_ALEN
);
2895 build
.da_offs
= offsetof(struct ieee80211_hdr
, addr3
);
2896 build
.sa_offs
= offsetof(struct ieee80211_hdr
, addr4
);
2901 case NL80211_IFTYPE_AP
:
2902 fc
|= cpu_to_le16(IEEE80211_FCTL_FROMDS
);
2904 build
.da_offs
= offsetof(struct ieee80211_hdr
, addr1
);
2905 memcpy(hdr
->addr2
, sdata
->vif
.addr
, ETH_ALEN
);
2906 build
.sa_offs
= offsetof(struct ieee80211_hdr
, addr3
);
2910 /* not handled on fast-xmit */
2916 fc
|= cpu_to_le16(IEEE80211_STYPE_QOS_DATA
);
2919 /* We store the key here so there's no point in using rcu_dereference()
2920 * but that's fine because the code that changes the pointers will call
2921 * this function after doing so. For a single CPU that would be enough,
2922 * for multiple see the comment above.
2924 build
.key
= rcu_access_pointer(sta
->ptk
[sta
->ptk_idx
]);
2926 build
.key
= rcu_access_pointer(sdata
->default_unicast_key
);
2928 bool gen_iv
, iv_spc
, mmic
;
2930 gen_iv
= build
.key
->conf
.flags
& IEEE80211_KEY_FLAG_GENERATE_IV
;
2931 iv_spc
= build
.key
->conf
.flags
& IEEE80211_KEY_FLAG_PUT_IV_SPACE
;
2932 mmic
= build
.key
->conf
.flags
& IEEE80211_KEY_FLAG_GENERATE_MMIC
;
2934 /* don't handle software crypto */
2935 if (!(build
.key
->flags
& KEY_FLAG_UPLOADED_TO_HARDWARE
))
2938 switch (build
.key
->conf
.cipher
) {
2939 case WLAN_CIPHER_SUITE_CCMP
:
2940 case WLAN_CIPHER_SUITE_CCMP_256
:
2941 /* add fixed key ID */
2943 (build
.hdr
+ build
.hdr_len
)[3] =
2944 0x20 | (build
.key
->conf
.keyidx
<< 6);
2945 build
.pn_offs
= build
.hdr_len
;
2947 if (gen_iv
|| iv_spc
)
2948 build
.hdr_len
+= IEEE80211_CCMP_HDR_LEN
;
2950 case WLAN_CIPHER_SUITE_GCMP
:
2951 case WLAN_CIPHER_SUITE_GCMP_256
:
2952 /* add fixed key ID */
2954 (build
.hdr
+ build
.hdr_len
)[3] =
2955 0x20 | (build
.key
->conf
.keyidx
<< 6);
2956 build
.pn_offs
= build
.hdr_len
;
2958 if (gen_iv
|| iv_spc
)
2959 build
.hdr_len
+= IEEE80211_GCMP_HDR_LEN
;
2961 case WLAN_CIPHER_SUITE_TKIP
:
2962 /* cannot handle MMIC or IV generation in xmit-fast */
2966 build
.hdr_len
+= IEEE80211_TKIP_IV_LEN
;
2968 case WLAN_CIPHER_SUITE_WEP40
:
2969 case WLAN_CIPHER_SUITE_WEP104
:
2970 /* cannot handle IV generation in fast-xmit */
2974 build
.hdr_len
+= IEEE80211_WEP_IV_LEN
;
2976 case WLAN_CIPHER_SUITE_AES_CMAC
:
2977 case WLAN_CIPHER_SUITE_BIP_CMAC_256
:
2978 case WLAN_CIPHER_SUITE_BIP_GMAC_128
:
2979 case WLAN_CIPHER_SUITE_BIP_GMAC_256
:
2981 "management cipher suite 0x%x enabled for data\n",
2982 build
.key
->conf
.cipher
);
2985 /* we don't know how to generate IVs for this at all */
2986 if (WARN_ON(gen_iv
))
2988 /* pure hardware keys are OK, of course */
2989 if (!(build
.key
->flags
& KEY_FLAG_CIPHER_SCHEME
))
2991 /* cipher scheme might require space allocation */
2993 build
.key
->conf
.iv_len
> IEEE80211_FAST_XMIT_MAX_IV
)
2996 build
.hdr_len
+= build
.key
->conf
.iv_len
;
2999 fc
|= cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
3002 hdr
->frame_control
= fc
;
3004 memcpy(build
.hdr
+ build
.hdr_len
,
3005 rfc1042_header
, sizeof(rfc1042_header
));
3006 build
.hdr_len
+= sizeof(rfc1042_header
);
3008 fast_tx
= kmemdup(&build
, sizeof(build
), GFP_ATOMIC
);
3009 /* if the kmemdup fails, continue w/o fast_tx */
3014 /* we might have raced against another call to this function */
3015 old
= rcu_dereference_protected(sta
->fast_tx
,
3016 lockdep_is_held(&sta
->lock
));
3017 rcu_assign_pointer(sta
->fast_tx
, fast_tx
);
3019 kfree_rcu(old
, rcu_head
);
3020 spin_unlock_bh(&sta
->lock
);
3023 void ieee80211_check_fast_xmit_all(struct ieee80211_local
*local
)
3025 struct sta_info
*sta
;
3028 list_for_each_entry_rcu(sta
, &local
->sta_list
, list
)
3029 ieee80211_check_fast_xmit(sta
);
3033 void ieee80211_check_fast_xmit_iface(struct ieee80211_sub_if_data
*sdata
)
3035 struct ieee80211_local
*local
= sdata
->local
;
3036 struct sta_info
*sta
;
3040 list_for_each_entry_rcu(sta
, &local
->sta_list
, list
) {
3041 if (sdata
!= sta
->sdata
&&
3042 (!sta
->sdata
->bss
|| sta
->sdata
->bss
!= sdata
->bss
))
3044 ieee80211_check_fast_xmit(sta
);
3050 void ieee80211_clear_fast_xmit(struct sta_info
*sta
)
3052 struct ieee80211_fast_tx
*fast_tx
;
3054 spin_lock_bh(&sta
->lock
);
3055 fast_tx
= rcu_dereference_protected(sta
->fast_tx
,
3056 lockdep_is_held(&sta
->lock
));
3057 RCU_INIT_POINTER(sta
->fast_tx
, NULL
);
3058 spin_unlock_bh(&sta
->lock
);
3061 kfree_rcu(fast_tx
, rcu_head
);
3064 static bool ieee80211_amsdu_realloc_pad(struct ieee80211_local
*local
,
3065 struct sk_buff
*skb
, int headroom
)
3067 if (skb_headroom(skb
) < headroom
) {
3068 I802_DEBUG_INC(local
->tx_expand_skb_head
);
3070 if (pskb_expand_head(skb
, headroom
, 0, GFP_ATOMIC
)) {
3071 wiphy_debug(local
->hw
.wiphy
,
3072 "failed to reallocate TX buffer\n");
3080 static bool ieee80211_amsdu_prepare_head(struct ieee80211_sub_if_data
*sdata
,
3081 struct ieee80211_fast_tx
*fast_tx
,
3082 struct sk_buff
*skb
)
3084 struct ieee80211_local
*local
= sdata
->local
;
3085 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
3086 struct ieee80211_hdr
*hdr
;
3087 struct ethhdr
*amsdu_hdr
;
3088 int hdr_len
= fast_tx
->hdr_len
- sizeof(rfc1042_header
);
3089 int subframe_len
= skb
->len
- hdr_len
;
3091 u8
*qc
, *h_80211_src
, *h_80211_dst
;
3094 if (info
->flags
& IEEE80211_TX_CTL_RATE_CTRL_PROBE
)
3097 if (info
->control
.flags
& IEEE80211_TX_CTRL_AMSDU
)
3100 if (!ieee80211_amsdu_realloc_pad(local
, skb
, sizeof(*amsdu_hdr
)))
3103 data
= skb_push(skb
, sizeof(*amsdu_hdr
));
3104 memmove(data
, data
+ sizeof(*amsdu_hdr
), hdr_len
);
3106 amsdu_hdr
= data
+ hdr_len
;
3107 /* h_80211_src/dst is addr* field within hdr */
3108 h_80211_src
= data
+ fast_tx
->sa_offs
;
3109 h_80211_dst
= data
+ fast_tx
->da_offs
;
3111 amsdu_hdr
->h_proto
= cpu_to_be16(subframe_len
);
3112 ether_addr_copy(amsdu_hdr
->h_source
, h_80211_src
);
3113 ether_addr_copy(amsdu_hdr
->h_dest
, h_80211_dst
);
3115 /* according to IEEE 802.11-2012 8.3.2 table 8-19, the outer SA/DA
3116 * fields needs to be changed to BSSID for A-MSDU frames depending
3117 * on FromDS/ToDS values.
3119 switch (sdata
->vif
.type
) {
3120 case NL80211_IFTYPE_STATION
:
3121 bssid
= sdata
->u
.mgd
.bssid
;
3123 case NL80211_IFTYPE_AP
:
3124 case NL80211_IFTYPE_AP_VLAN
:
3125 bssid
= sdata
->vif
.addr
;
3131 if (bssid
&& ieee80211_has_fromds(hdr
->frame_control
))
3132 ether_addr_copy(h_80211_src
, bssid
);
3134 if (bssid
&& ieee80211_has_tods(hdr
->frame_control
))
3135 ether_addr_copy(h_80211_dst
, bssid
);
3137 qc
= ieee80211_get_qos_ctl(hdr
);
3138 *qc
|= IEEE80211_QOS_CTL_A_MSDU_PRESENT
;
3140 info
->control
.flags
|= IEEE80211_TX_CTRL_AMSDU
;
3145 static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data
*sdata
,
3146 struct sta_info
*sta
,
3147 struct ieee80211_fast_tx
*fast_tx
,
3148 struct sk_buff
*skb
)
3150 struct ieee80211_local
*local
= sdata
->local
;
3151 struct fq
*fq
= &local
->fq
;
3153 struct fq_flow
*flow
;
3154 u8 tid
= skb
->priority
& IEEE80211_QOS_CTL_TAG1D_MASK
;
3155 struct ieee80211_txq
*txq
= sta
->sta
.txq
[tid
];
3156 struct txq_info
*txqi
;
3157 struct sk_buff
**frag_tail
, *head
;
3158 int subframe_len
= skb
->len
- ETH_ALEN
;
3159 u8 max_subframes
= sta
->sta
.max_amsdu_subframes
;
3160 int max_frags
= local
->hw
.max_tx_fragments
;
3161 int max_amsdu_len
= sta
->sta
.max_amsdu_len
;
3166 unsigned int orig_len
;
3167 int n
= 2, nfrags
, pad
= 0;
3170 if (!ieee80211_hw_check(&local
->hw
, TX_AMSDU
))
3176 txqi
= to_txq_info(txq
);
3177 if (test_bit(IEEE80211_TXQ_NO_AMSDU
, &txqi
->flags
))
3180 if (sta
->sta
.max_rc_amsdu_len
)
3181 max_amsdu_len
= min_t(int, max_amsdu_len
,
3182 sta
->sta
.max_rc_amsdu_len
);
3184 spin_lock_bh(&fq
->lock
);
3186 /* TODO: Ideally aggregation should be done on dequeue to remain
3187 * responsive to environment changes.
3191 flow
= fq_flow_classify(fq
, tin
, skb
, fq_flow_get_default_func
);
3192 head
= skb_peek_tail(&flow
->queue
);
3196 orig_truesize
= head
->truesize
;
3197 orig_len
= head
->len
;
3199 if (skb
->len
+ head
->len
> max_amsdu_len
)
3202 nfrags
= 1 + skb_shinfo(skb
)->nr_frags
;
3203 nfrags
+= 1 + skb_shinfo(head
)->nr_frags
;
3204 frag_tail
= &skb_shinfo(head
)->frag_list
;
3205 while (*frag_tail
) {
3206 nfrags
+= 1 + skb_shinfo(*frag_tail
)->nr_frags
;
3207 frag_tail
= &(*frag_tail
)->next
;
3211 if (max_subframes
&& n
> max_subframes
)
3214 if (max_frags
&& nfrags
> max_frags
)
3217 if (!ieee80211_amsdu_prepare_head(sdata
, fast_tx
, head
))
3221 * Pad out the previous subframe to a multiple of 4 by adding the
3222 * padding to the next one, that's being added. Note that head->len
3223 * is the length of the full A-MSDU, but that works since each time
3224 * we add a new subframe we pad out the previous one to a multiple
3225 * of 4 and thus it no longer matters in the next round.
3227 hdrlen
= fast_tx
->hdr_len
- sizeof(rfc1042_header
);
3228 if ((head
->len
- hdrlen
) & 3)
3229 pad
= 4 - ((head
->len
- hdrlen
) & 3);
3231 if (!ieee80211_amsdu_realloc_pad(local
, skb
, sizeof(rfc1042_header
) +
3236 data
= skb_push(skb
, ETH_ALEN
+ 2);
3237 memmove(data
, data
+ ETH_ALEN
+ 2, 2 * ETH_ALEN
);
3239 data
+= 2 * ETH_ALEN
;
3240 len
= cpu_to_be16(subframe_len
);
3241 memcpy(data
, &len
, 2);
3242 memcpy(data
+ 2, rfc1042_header
, sizeof(rfc1042_header
));
3244 memset(skb_push(skb
, pad
), 0, pad
);
3246 head
->len
+= skb
->len
;
3247 head
->data_len
+= skb
->len
;
3251 fq
->memory_usage
+= head
->truesize
- orig_truesize
;
3252 if (head
->len
!= orig_len
) {
3253 flow
->backlog
+= head
->len
- orig_len
;
3254 tin
->backlog_bytes
+= head
->len
- orig_len
;
3256 fq_recalc_backlog(fq
, tin
, flow
);
3259 spin_unlock_bh(&fq
->lock
);
3265 * Can be called while the sta lock is held. Anything that can cause packets to
3266 * be generated will cause deadlock!
3268 static void ieee80211_xmit_fast_finish(struct ieee80211_sub_if_data
*sdata
,
3269 struct sta_info
*sta
, u8 pn_offs
,
3270 struct ieee80211_key
*key
,
3271 struct sk_buff
*skb
)
3273 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
3274 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3275 u8 tid
= IEEE80211_NUM_TIDS
;
3278 info
->control
.hw_key
= &key
->conf
;
3280 ieee80211_tx_stats(skb
->dev
, skb
->len
);
3282 if (hdr
->frame_control
& cpu_to_le16(IEEE80211_STYPE_QOS_DATA
)) {
3283 tid
= skb
->priority
& IEEE80211_QOS_CTL_TAG1D_MASK
;
3284 hdr
->seq_ctrl
= ieee80211_tx_next_seq(sta
, tid
);
3286 info
->flags
|= IEEE80211_TX_CTL_ASSIGN_SEQ
;
3287 hdr
->seq_ctrl
= cpu_to_le16(sdata
->sequence_number
);
3288 sdata
->sequence_number
+= 0x10;
3291 if (skb_shinfo(skb
)->gso_size
)
3292 sta
->tx_stats
.msdu
[tid
] +=
3293 DIV_ROUND_UP(skb
->len
, skb_shinfo(skb
)->gso_size
);
3295 sta
->tx_stats
.msdu
[tid
]++;
3297 info
->hw_queue
= sdata
->vif
.hw_queue
[skb_get_queue_mapping(skb
)];
3299 /* statistics normally done by ieee80211_tx_h_stats (but that
3300 * has to consider fragmentation, so is more complex)
3302 sta
->tx_stats
.bytes
[skb_get_queue_mapping(skb
)] += skb
->len
;
3303 sta
->tx_stats
.packets
[skb_get_queue_mapping(skb
)]++;
3307 u8
*crypto_hdr
= skb
->data
+ pn_offs
;
3309 switch (key
->conf
.cipher
) {
3310 case WLAN_CIPHER_SUITE_CCMP
:
3311 case WLAN_CIPHER_SUITE_CCMP_256
:
3312 case WLAN_CIPHER_SUITE_GCMP
:
3313 case WLAN_CIPHER_SUITE_GCMP_256
:
3314 pn
= atomic64_inc_return(&key
->conf
.tx_pn
);
3316 crypto_hdr
[1] = pn
>> 8;
3317 crypto_hdr
[4] = pn
>> 16;
3318 crypto_hdr
[5] = pn
>> 24;
3319 crypto_hdr
[6] = pn
>> 32;
3320 crypto_hdr
[7] = pn
>> 40;
3326 static bool ieee80211_xmit_fast(struct ieee80211_sub_if_data
*sdata
,
3327 struct sta_info
*sta
,
3328 struct ieee80211_fast_tx
*fast_tx
,
3329 struct sk_buff
*skb
)
3331 struct ieee80211_local
*local
= sdata
->local
;
3332 u16 ethertype
= (skb
->data
[12] << 8) | skb
->data
[13];
3333 int extra_head
= fast_tx
->hdr_len
- (ETH_HLEN
- 2);
3334 int hw_headroom
= sdata
->local
->hw
.extra_tx_headroom
;
3336 struct ieee80211_tx_info
*info
;
3337 struct ieee80211_hdr
*hdr
= (void *)fast_tx
->hdr
;
3338 struct ieee80211_tx_data tx
;
3339 ieee80211_tx_result r
;
3340 struct tid_ampdu_tx
*tid_tx
= NULL
;
3341 u8 tid
= IEEE80211_NUM_TIDS
;
3343 /* control port protocol needs a lot of special handling */
3344 if (cpu_to_be16(ethertype
) == sdata
->control_port_protocol
)
3347 /* only RFC 1042 SNAP */
3348 if (ethertype
< ETH_P_802_3_MIN
)
3351 /* don't handle TX status request here either */
3352 if (skb
->sk
&& skb_shinfo(skb
)->tx_flags
& SKBTX_WIFI_STATUS
)
3355 if (hdr
->frame_control
& cpu_to_le16(IEEE80211_STYPE_QOS_DATA
)) {
3356 tid
= skb
->priority
& IEEE80211_QOS_CTL_TAG1D_MASK
;
3357 tid_tx
= rcu_dereference(sta
->ampdu_mlme
.tid_tx
[tid
]);
3359 if (!test_bit(HT_AGG_STATE_OPERATIONAL
, &tid_tx
->state
))
3361 if (tid_tx
->timeout
)
3362 tid_tx
->last_tx
= jiffies
;
3366 /* after this point (skb is modified) we cannot return false */
3368 if (skb_shared(skb
)) {
3369 struct sk_buff
*tmp_skb
= skb
;
3371 skb
= skb_clone(skb
, GFP_ATOMIC
);
3378 if ((hdr
->frame_control
& cpu_to_le16(IEEE80211_STYPE_QOS_DATA
)) &&
3379 ieee80211_amsdu_aggregate(sdata
, sta
, fast_tx
, skb
))
3382 /* will not be crypto-handled beyond what we do here, so use false
3383 * as the may-encrypt argument for the resize to not account for
3384 * more room than we already have in 'extra_head'
3386 if (unlikely(ieee80211_skb_resize(sdata
, skb
,
3387 max_t(int, extra_head
+ hw_headroom
-
3388 skb_headroom(skb
), 0),
3394 memcpy(ð
, skb
->data
, ETH_HLEN
- 2);
3395 hdr
= skb_push(skb
, extra_head
);
3396 memcpy(skb
->data
, fast_tx
->hdr
, fast_tx
->hdr_len
);
3397 memcpy(skb
->data
+ fast_tx
->da_offs
, eth
.h_dest
, ETH_ALEN
);
3398 memcpy(skb
->data
+ fast_tx
->sa_offs
, eth
.h_source
, ETH_ALEN
);
3400 info
= IEEE80211_SKB_CB(skb
);
3401 memset(info
, 0, sizeof(*info
));
3402 info
->band
= fast_tx
->band
;
3403 info
->control
.vif
= &sdata
->vif
;
3404 info
->flags
= IEEE80211_TX_CTL_FIRST_FRAGMENT
|
3405 IEEE80211_TX_CTL_DONTFRAG
|
3406 (tid_tx
? IEEE80211_TX_CTL_AMPDU
: 0);
3407 info
->control
.flags
= IEEE80211_TX_CTRL_FAST_XMIT
;
3409 if (hdr
->frame_control
& cpu_to_le16(IEEE80211_STYPE_QOS_DATA
)) {
3410 tid
= skb
->priority
& IEEE80211_QOS_CTL_TAG1D_MASK
;
3411 *ieee80211_get_qos_ctl(hdr
) = tid
;
3414 __skb_queue_head_init(&tx
.skbs
);
3416 tx
.flags
= IEEE80211_TX_UNICAST
;
3420 tx
.key
= fast_tx
->key
;
3422 if (!ieee80211_hw_check(&local
->hw
, HAS_RATE_CONTROL
)) {
3424 r
= ieee80211_tx_h_rate_ctrl(&tx
);
3428 if (r
!= TX_CONTINUE
) {
3435 if (ieee80211_queue_skb(local
, sdata
, sta
, skb
))
3438 ieee80211_xmit_fast_finish(sdata
, sta
, fast_tx
->pn_offs
,
3441 if (sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
)
3442 sdata
= container_of(sdata
->bss
,
3443 struct ieee80211_sub_if_data
, u
.ap
);
3445 __skb_queue_tail(&tx
.skbs
, skb
);
3446 ieee80211_tx_frags(local
, &sdata
->vif
, &sta
->sta
, &tx
.skbs
, false);
3450 struct sk_buff
*ieee80211_tx_dequeue(struct ieee80211_hw
*hw
,
3451 struct ieee80211_txq
*txq
)
3453 struct ieee80211_local
*local
= hw_to_local(hw
);
3454 struct txq_info
*txqi
= container_of(txq
, struct txq_info
, txq
);
3455 struct ieee80211_hdr
*hdr
;
3456 struct sk_buff
*skb
= NULL
;
3457 struct fq
*fq
= &local
->fq
;
3458 struct fq_tin
*tin
= &txqi
->tin
;
3459 struct ieee80211_tx_info
*info
;
3460 struct ieee80211_tx_data tx
;
3461 ieee80211_tx_result r
;
3462 struct ieee80211_vif
*vif
;
3464 spin_lock_bh(&fq
->lock
);
3466 if (test_bit(IEEE80211_TXQ_STOP
, &txqi
->flags
))
3469 /* Make sure fragments stay together. */
3470 skb
= __skb_dequeue(&txqi
->frags
);
3475 skb
= fq_tin_dequeue(fq
, tin
, fq_tin_dequeue_func
);
3479 hdr
= (struct ieee80211_hdr
*)skb
->data
;
3480 info
= IEEE80211_SKB_CB(skb
);
3482 memset(&tx
, 0, sizeof(tx
));
3483 __skb_queue_head_init(&tx
.skbs
);
3486 tx
.sdata
= vif_to_sdata(info
->control
.vif
);
3489 tx
.sta
= container_of(txq
->sta
, struct sta_info
, sta
);
3492 * The key can be removed while the packet was queued, so need to call
3493 * this here to get the current key.
3495 r
= ieee80211_tx_h_select_key(&tx
);
3496 if (r
!= TX_CONTINUE
) {
3497 ieee80211_free_txskb(&local
->hw
, skb
);
3501 if (test_bit(IEEE80211_TXQ_AMPDU
, &txqi
->flags
))
3502 info
->flags
|= IEEE80211_TX_CTL_AMPDU
;
3504 info
->flags
&= ~IEEE80211_TX_CTL_AMPDU
;
3506 if (info
->control
.flags
& IEEE80211_TX_CTRL_FAST_XMIT
) {
3507 struct sta_info
*sta
= container_of(txq
->sta
, struct sta_info
,
3512 (tx
.key
->conf
.flags
& IEEE80211_KEY_FLAG_GENERATE_IV
))
3513 pn_offs
= ieee80211_hdrlen(hdr
->frame_control
);
3515 ieee80211_xmit_fast_finish(sta
->sdata
, sta
, pn_offs
,
3518 if (invoke_tx_handlers_late(&tx
))
3521 skb
= __skb_dequeue(&tx
.skbs
);
3523 if (!skb_queue_empty(&tx
.skbs
))
3524 skb_queue_splice_tail(&tx
.skbs
, &txqi
->frags
);
3527 if (skb
&& skb_has_frag_list(skb
) &&
3528 !ieee80211_hw_check(&local
->hw
, TX_FRAG_LIST
)) {
3529 if (skb_linearize(skb
)) {
3530 ieee80211_free_txskb(&local
->hw
, skb
);
3535 switch (tx
.sdata
->vif
.type
) {
3536 case NL80211_IFTYPE_MONITOR
:
3537 if (tx
.sdata
->u
.mntr
.flags
& MONITOR_FLAG_ACTIVE
) {
3538 vif
= &tx
.sdata
->vif
;
3541 tx
.sdata
= rcu_dereference(local
->monitor_sdata
);
3543 vif
= &tx
.sdata
->vif
;
3545 vif
->hw_queue
[skb_get_queue_mapping(skb
)];
3546 } else if (ieee80211_hw_check(&local
->hw
, QUEUE_CONTROL
)) {
3547 ieee80211_free_txskb(&local
->hw
, skb
);
3553 case NL80211_IFTYPE_AP_VLAN
:
3554 tx
.sdata
= container_of(tx
.sdata
->bss
,
3555 struct ieee80211_sub_if_data
, u
.ap
);
3558 vif
= &tx
.sdata
->vif
;
3562 IEEE80211_SKB_CB(skb
)->control
.vif
= vif
;
3564 spin_unlock_bh(&fq
->lock
);
3568 EXPORT_SYMBOL(ieee80211_tx_dequeue
);
3570 void __ieee80211_subif_start_xmit(struct sk_buff
*skb
,
3571 struct net_device
*dev
,
3574 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3575 struct sta_info
*sta
;
3576 struct sk_buff
*next
;
3578 if (unlikely(skb
->len
< ETH_HLEN
)) {
3585 if (ieee80211_lookup_ra_sta(sdata
, skb
, &sta
))
3588 if (!IS_ERR_OR_NULL(sta
)) {
3589 struct ieee80211_fast_tx
*fast_tx
;
3591 fast_tx
= rcu_dereference(sta
->fast_tx
);
3594 ieee80211_xmit_fast(sdata
, sta
, fast_tx
, skb
))
3598 if (skb_is_gso(skb
)) {
3599 struct sk_buff
*segs
;
3601 segs
= skb_gso_segment(skb
, 0);
3609 /* we cannot process non-linear frames on this path */
3610 if (skb_linearize(skb
)) {
3615 /* the frame could be fragmented, software-encrypted, and other
3616 * things so we cannot really handle checksum offload with it -
3617 * fix it up in software before we handle anything else.
3619 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
3620 skb_set_transport_header(skb
,
3621 skb_checksum_start_offset(skb
));
3622 if (skb_checksum_help(skb
))
3635 skb
= ieee80211_build_hdr(sdata
, skb
, info_flags
, sta
);
3639 ieee80211_tx_stats(dev
, skb
->len
);
3641 ieee80211_xmit(sdata
, sta
, skb
);
3650 static int ieee80211_change_da(struct sk_buff
*skb
, struct sta_info
*sta
)
3655 err
= skb_ensure_writable(skb
, ETH_HLEN
);
3659 eth
= (void *)skb
->data
;
3660 ether_addr_copy(eth
->h_dest
, sta
->sta
.addr
);
3665 static bool ieee80211_multicast_to_unicast(struct sk_buff
*skb
,
3666 struct net_device
*dev
)
3668 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3669 const struct ethhdr
*eth
= (void *)skb
->data
;
3670 const struct vlan_ethhdr
*ethvlan
= (void *)skb
->data
;
3673 if (likely(!is_multicast_ether_addr(eth
->h_dest
)))
3676 switch (sdata
->vif
.type
) {
3677 case NL80211_IFTYPE_AP_VLAN
:
3678 if (sdata
->u
.vlan
.sta
)
3680 if (sdata
->wdev
.use_4addr
)
3683 case NL80211_IFTYPE_AP
:
3684 /* check runtime toggle for this bss */
3685 if (!sdata
->bss
->multicast_to_unicast
)
3692 /* multicast to unicast conversion only for some payload */
3693 ethertype
= eth
->h_proto
;
3694 if (ethertype
== htons(ETH_P_8021Q
) && skb
->len
>= VLAN_ETH_HLEN
)
3695 ethertype
= ethvlan
->h_vlan_encapsulated_proto
;
3696 switch (ethertype
) {
3697 case htons(ETH_P_ARP
):
3698 case htons(ETH_P_IP
):
3699 case htons(ETH_P_IPV6
):
3709 ieee80211_convert_to_unicast(struct sk_buff
*skb
, struct net_device
*dev
,
3710 struct sk_buff_head
*queue
)
3712 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3713 struct ieee80211_local
*local
= sdata
->local
;
3714 const struct ethhdr
*eth
= (struct ethhdr
*)skb
->data
;
3715 struct sta_info
*sta
, *first
= NULL
;
3716 struct sk_buff
*cloned_skb
;
3720 list_for_each_entry_rcu(sta
, &local
->sta_list
, list
) {
3721 if (sdata
!= sta
->sdata
)
3722 /* AP-VLAN mismatch */
3724 if (unlikely(ether_addr_equal(eth
->h_source
, sta
->sta
.addr
)))
3725 /* do not send back to source */
3731 cloned_skb
= skb_clone(skb
, GFP_ATOMIC
);
3734 if (unlikely(ieee80211_change_da(cloned_skb
, sta
))) {
3735 dev_kfree_skb(cloned_skb
);
3738 __skb_queue_tail(queue
, cloned_skb
);
3741 if (likely(first
)) {
3742 if (unlikely(ieee80211_change_da(skb
, first
)))
3744 __skb_queue_tail(queue
, skb
);
3746 /* no STA connected, drop */
3753 __skb_queue_purge(queue
);
3754 __skb_queue_tail(queue
, skb
);
3760 * ieee80211_subif_start_xmit - netif start_xmit function for 802.3 vifs
3761 * @skb: packet to be sent
3762 * @dev: incoming interface
3764 * On failure skb will be freed.
3766 netdev_tx_t
ieee80211_subif_start_xmit(struct sk_buff
*skb
,
3767 struct net_device
*dev
)
3769 if (unlikely(ieee80211_multicast_to_unicast(skb
, dev
))) {
3770 struct sk_buff_head queue
;
3772 __skb_queue_head_init(&queue
);
3773 ieee80211_convert_to_unicast(skb
, dev
, &queue
);
3774 while ((skb
= __skb_dequeue(&queue
)))
3775 __ieee80211_subif_start_xmit(skb
, dev
, 0);
3777 __ieee80211_subif_start_xmit(skb
, dev
, 0);
3780 return NETDEV_TX_OK
;
3784 ieee80211_build_data_template(struct ieee80211_sub_if_data
*sdata
,
3785 struct sk_buff
*skb
, u32 info_flags
)
3787 struct ieee80211_hdr
*hdr
;
3788 struct ieee80211_tx_data tx
= {
3789 .local
= sdata
->local
,
3792 struct sta_info
*sta
;
3796 if (ieee80211_lookup_ra_sta(sdata
, skb
, &sta
)) {
3798 skb
= ERR_PTR(-EINVAL
);
3802 skb
= ieee80211_build_hdr(sdata
, skb
, info_flags
, sta
);
3806 hdr
= (void *)skb
->data
;
3807 tx
.sta
= sta_info_get(sdata
, hdr
->addr1
);
3810 if (ieee80211_tx_h_select_key(&tx
) != TX_CONTINUE
) {
3813 return ERR_PTR(-EINVAL
);
3822 * ieee80211_clear_tx_pending may not be called in a context where
3823 * it is possible that it packets could come in again.
3825 void ieee80211_clear_tx_pending(struct ieee80211_local
*local
)
3827 struct sk_buff
*skb
;
3830 for (i
= 0; i
< local
->hw
.queues
; i
++) {
3831 while ((skb
= skb_dequeue(&local
->pending
[i
])) != NULL
)
3832 ieee80211_free_txskb(&local
->hw
, skb
);
3837 * Returns false if the frame couldn't be transmitted but was queued instead,
3838 * which in this case means re-queued -- take as an indication to stop sending
3839 * more pending frames.
3841 static bool ieee80211_tx_pending_skb(struct ieee80211_local
*local
,
3842 struct sk_buff
*skb
)
3844 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
3845 struct ieee80211_sub_if_data
*sdata
;
3846 struct sta_info
*sta
;
3847 struct ieee80211_hdr
*hdr
;
3849 struct ieee80211_chanctx_conf
*chanctx_conf
;
3851 sdata
= vif_to_sdata(info
->control
.vif
);
3853 if (info
->flags
& IEEE80211_TX_INTFL_NEED_TXPROCESSING
) {
3854 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
3855 if (unlikely(!chanctx_conf
)) {
3859 info
->band
= chanctx_conf
->def
.chan
->band
;
3860 result
= ieee80211_tx(sdata
, NULL
, skb
, true);
3862 struct sk_buff_head skbs
;
3864 __skb_queue_head_init(&skbs
);
3865 __skb_queue_tail(&skbs
, skb
);
3867 hdr
= (struct ieee80211_hdr
*)skb
->data
;
3868 sta
= sta_info_get(sdata
, hdr
->addr1
);
3870 result
= __ieee80211_tx(local
, &skbs
, skb
->len
, sta
, true);
3877 * Transmit all pending packets. Called from tasklet.
3879 void ieee80211_tx_pending(unsigned long data
)
3881 struct ieee80211_local
*local
= (struct ieee80211_local
*)data
;
3882 unsigned long flags
;
3888 spin_lock_irqsave(&local
->queue_stop_reason_lock
, flags
);
3889 for (i
= 0; i
< local
->hw
.queues
; i
++) {
3891 * If queue is stopped by something other than due to pending
3892 * frames, or we have no pending frames, proceed to next queue.
3894 if (local
->queue_stop_reasons
[i
] ||
3895 skb_queue_empty(&local
->pending
[i
]))
3898 while (!skb_queue_empty(&local
->pending
[i
])) {
3899 struct sk_buff
*skb
= __skb_dequeue(&local
->pending
[i
]);
3900 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
3902 if (WARN_ON(!info
->control
.vif
)) {
3903 ieee80211_free_txskb(&local
->hw
, skb
);
3907 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
,
3910 txok
= ieee80211_tx_pending_skb(local
, skb
);
3911 spin_lock_irqsave(&local
->queue_stop_reason_lock
,
3917 if (skb_queue_empty(&local
->pending
[i
]))
3918 ieee80211_propagate_queue_wake(local
, i
);
3920 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
, flags
);
3925 /* functions for drivers to get certain frames */
3927 static void __ieee80211_beacon_add_tim(struct ieee80211_sub_if_data
*sdata
,
3928 struct ps_data
*ps
, struct sk_buff
*skb
,
3933 int i
, have_bits
= 0, n1
, n2
;
3935 /* Generate bitmap for TIM only if there are any STAs in power save
3937 if (atomic_read(&ps
->num_sta_ps
) > 0)
3938 /* in the hope that this is faster than
3939 * checking byte-for-byte */
3940 have_bits
= !bitmap_empty((unsigned long *)ps
->tim
,
3941 IEEE80211_MAX_AID
+1);
3943 if (ps
->dtim_count
== 0)
3944 ps
->dtim_count
= sdata
->vif
.bss_conf
.dtim_period
- 1;
3949 tim
= pos
= skb_put(skb
, 6);
3950 *pos
++ = WLAN_EID_TIM
;
3952 *pos
++ = ps
->dtim_count
;
3953 *pos
++ = sdata
->vif
.bss_conf
.dtim_period
;
3955 if (ps
->dtim_count
== 0 && !skb_queue_empty(&ps
->bc_buf
))
3958 ps
->dtim_bc_mc
= aid0
== 1;
3961 /* Find largest even number N1 so that bits numbered 1 through
3962 * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits
3963 * (N2 + 1) x 8 through 2007 are 0. */
3965 for (i
= 0; i
< IEEE80211_MAX_TIM_LEN
; i
++) {
3972 for (i
= IEEE80211_MAX_TIM_LEN
- 1; i
>= n1
; i
--) {
3979 /* Bitmap control */
3981 /* Part Virt Bitmap */
3982 skb_put(skb
, n2
- n1
);
3983 memcpy(pos
, ps
->tim
+ n1
, n2
- n1
+ 1);
3985 tim
[1] = n2
- n1
+ 4;
3987 *pos
++ = aid0
; /* Bitmap control */
3988 *pos
++ = 0; /* Part Virt Bitmap */
3992 static int ieee80211_beacon_add_tim(struct ieee80211_sub_if_data
*sdata
,
3993 struct ps_data
*ps
, struct sk_buff
*skb
,
3996 struct ieee80211_local
*local
= sdata
->local
;
3999 * Not very nice, but we want to allow the driver to call
4000 * ieee80211_beacon_get() as a response to the set_tim()
4001 * callback. That, however, is already invoked under the
4002 * sta_lock to guarantee consistent and race-free update
4003 * of the tim bitmap in mac80211 and the driver.
4005 if (local
->tim_in_locked_section
) {
4006 __ieee80211_beacon_add_tim(sdata
, ps
, skb
, is_template
);
4008 spin_lock_bh(&local
->tim_lock
);
4009 __ieee80211_beacon_add_tim(sdata
, ps
, skb
, is_template
);
4010 spin_unlock_bh(&local
->tim_lock
);
4016 static void ieee80211_set_csa(struct ieee80211_sub_if_data
*sdata
,
4017 struct beacon_data
*beacon
)
4019 struct probe_resp
*resp
;
4021 size_t beacon_data_len
;
4023 u8 count
= beacon
->csa_current_counter
;
4025 switch (sdata
->vif
.type
) {
4026 case NL80211_IFTYPE_AP
:
4027 beacon_data
= beacon
->tail
;
4028 beacon_data_len
= beacon
->tail_len
;
4030 case NL80211_IFTYPE_ADHOC
:
4031 beacon_data
= beacon
->head
;
4032 beacon_data_len
= beacon
->head_len
;
4034 case NL80211_IFTYPE_MESH_POINT
:
4035 beacon_data
= beacon
->head
;
4036 beacon_data_len
= beacon
->head_len
;
4043 for (i
= 0; i
< IEEE80211_MAX_CSA_COUNTERS_NUM
; ++i
) {
4044 resp
= rcu_dereference(sdata
->u
.ap
.probe_resp
);
4046 if (beacon
->csa_counter_offsets
[i
]) {
4047 if (WARN_ON_ONCE(beacon
->csa_counter_offsets
[i
] >=
4053 beacon_data
[beacon
->csa_counter_offsets
[i
]] = count
;
4056 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
&& resp
)
4057 resp
->data
[resp
->csa_counter_offsets
[i
]] = count
;
4062 static u8
__ieee80211_csa_update_counter(struct beacon_data
*beacon
)
4064 beacon
->csa_current_counter
--;
4066 /* the counter should never reach 0 */
4067 WARN_ON_ONCE(!beacon
->csa_current_counter
);
4069 return beacon
->csa_current_counter
;
4072 u8
ieee80211_csa_update_counter(struct ieee80211_vif
*vif
)
4074 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
4075 struct beacon_data
*beacon
= NULL
;
4080 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
)
4081 beacon
= rcu_dereference(sdata
->u
.ap
.beacon
);
4082 else if (sdata
->vif
.type
== NL80211_IFTYPE_ADHOC
)
4083 beacon
= rcu_dereference(sdata
->u
.ibss
.presp
);
4084 else if (ieee80211_vif_is_mesh(&sdata
->vif
))
4085 beacon
= rcu_dereference(sdata
->u
.mesh
.beacon
);
4090 count
= __ieee80211_csa_update_counter(beacon
);
4096 EXPORT_SYMBOL(ieee80211_csa_update_counter
);
4098 bool ieee80211_csa_is_complete(struct ieee80211_vif
*vif
)
4100 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
4101 struct beacon_data
*beacon
= NULL
;
4103 size_t beacon_data_len
;
4106 if (!ieee80211_sdata_running(sdata
))
4110 if (vif
->type
== NL80211_IFTYPE_AP
) {
4111 struct ieee80211_if_ap
*ap
= &sdata
->u
.ap
;
4113 beacon
= rcu_dereference(ap
->beacon
);
4114 if (WARN_ON(!beacon
|| !beacon
->tail
))
4116 beacon_data
= beacon
->tail
;
4117 beacon_data_len
= beacon
->tail_len
;
4118 } else if (vif
->type
== NL80211_IFTYPE_ADHOC
) {
4119 struct ieee80211_if_ibss
*ifibss
= &sdata
->u
.ibss
;
4121 beacon
= rcu_dereference(ifibss
->presp
);
4125 beacon_data
= beacon
->head
;
4126 beacon_data_len
= beacon
->head_len
;
4127 } else if (vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
4128 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
4130 beacon
= rcu_dereference(ifmsh
->beacon
);
4134 beacon_data
= beacon
->head
;
4135 beacon_data_len
= beacon
->head_len
;
4141 if (!beacon
->csa_counter_offsets
[0])
4144 if (WARN_ON_ONCE(beacon
->csa_counter_offsets
[0] > beacon_data_len
))
4147 if (beacon_data
[beacon
->csa_counter_offsets
[0]] == 1)
4154 EXPORT_SYMBOL(ieee80211_csa_is_complete
);
4156 static struct sk_buff
*
4157 __ieee80211_beacon_get(struct ieee80211_hw
*hw
,
4158 struct ieee80211_vif
*vif
,
4159 struct ieee80211_mutable_offsets
*offs
,
4162 struct ieee80211_local
*local
= hw_to_local(hw
);
4163 struct beacon_data
*beacon
= NULL
;
4164 struct sk_buff
*skb
= NULL
;
4165 struct ieee80211_tx_info
*info
;
4166 struct ieee80211_sub_if_data
*sdata
= NULL
;
4167 enum nl80211_band band
;
4168 struct ieee80211_tx_rate_control txrc
;
4169 struct ieee80211_chanctx_conf
*chanctx_conf
;
4170 int csa_off_base
= 0;
4174 sdata
= vif_to_sdata(vif
);
4175 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
4177 if (!ieee80211_sdata_running(sdata
) || !chanctx_conf
)
4181 memset(offs
, 0, sizeof(*offs
));
4183 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
) {
4184 struct ieee80211_if_ap
*ap
= &sdata
->u
.ap
;
4186 beacon
= rcu_dereference(ap
->beacon
);
4188 if (beacon
->csa_counter_offsets
[0]) {
4190 __ieee80211_csa_update_counter(beacon
);
4192 ieee80211_set_csa(sdata
, beacon
);
4196 * headroom, head length,
4197 * tail length and maximum TIM length
4199 skb
= dev_alloc_skb(local
->tx_headroom
+
4201 beacon
->tail_len
+ 256 +
4202 local
->hw
.extra_beacon_tailroom
);
4206 skb_reserve(skb
, local
->tx_headroom
);
4207 skb_put_data(skb
, beacon
->head
, beacon
->head_len
);
4209 ieee80211_beacon_add_tim(sdata
, &ap
->ps
, skb
,
4213 offs
->tim_offset
= beacon
->head_len
;
4214 offs
->tim_length
= skb
->len
- beacon
->head_len
;
4216 /* for AP the csa offsets are from tail */
4217 csa_off_base
= skb
->len
;
4221 skb_put_data(skb
, beacon
->tail
,
4225 } else if (sdata
->vif
.type
== NL80211_IFTYPE_ADHOC
) {
4226 struct ieee80211_if_ibss
*ifibss
= &sdata
->u
.ibss
;
4227 struct ieee80211_hdr
*hdr
;
4229 beacon
= rcu_dereference(ifibss
->presp
);
4233 if (beacon
->csa_counter_offsets
[0]) {
4235 __ieee80211_csa_update_counter(beacon
);
4237 ieee80211_set_csa(sdata
, beacon
);
4240 skb
= dev_alloc_skb(local
->tx_headroom
+ beacon
->head_len
+
4241 local
->hw
.extra_beacon_tailroom
);
4244 skb_reserve(skb
, local
->tx_headroom
);
4245 skb_put_data(skb
, beacon
->head
, beacon
->head_len
);
4247 hdr
= (struct ieee80211_hdr
*) skb
->data
;
4248 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
4249 IEEE80211_STYPE_BEACON
);
4250 } else if (ieee80211_vif_is_mesh(&sdata
->vif
)) {
4251 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
4253 beacon
= rcu_dereference(ifmsh
->beacon
);
4257 if (beacon
->csa_counter_offsets
[0]) {
4259 /* TODO: For mesh csa_counter is in TU, so
4260 * decrementing it by one isn't correct, but
4261 * for now we leave it consistent with overall
4262 * mac80211's behavior.
4264 __ieee80211_csa_update_counter(beacon
);
4266 ieee80211_set_csa(sdata
, beacon
);
4269 if (ifmsh
->sync_ops
)
4270 ifmsh
->sync_ops
->adjust_tsf(sdata
, beacon
);
4272 skb
= dev_alloc_skb(local
->tx_headroom
+
4276 local
->hw
.extra_beacon_tailroom
);
4279 skb_reserve(skb
, local
->tx_headroom
);
4280 skb_put_data(skb
, beacon
->head
, beacon
->head_len
);
4281 ieee80211_beacon_add_tim(sdata
, &ifmsh
->ps
, skb
, is_template
);
4284 offs
->tim_offset
= beacon
->head_len
;
4285 offs
->tim_length
= skb
->len
- beacon
->head_len
;
4288 skb_put_data(skb
, beacon
->tail
, beacon
->tail_len
);
4295 if (offs
&& beacon
) {
4298 for (i
= 0; i
< IEEE80211_MAX_CSA_COUNTERS_NUM
; i
++) {
4299 u16 csa_off
= beacon
->csa_counter_offsets
[i
];
4304 offs
->csa_counter_offs
[i
] = csa_off_base
+ csa_off
;
4308 band
= chanctx_conf
->def
.chan
->band
;
4310 info
= IEEE80211_SKB_CB(skb
);
4312 info
->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
4313 info
->flags
|= IEEE80211_TX_CTL_NO_ACK
;
4316 memset(&txrc
, 0, sizeof(txrc
));
4318 txrc
.sband
= local
->hw
.wiphy
->bands
[band
];
4319 txrc
.bss_conf
= &sdata
->vif
.bss_conf
;
4321 txrc
.reported_rate
.idx
= -1;
4322 txrc
.rate_idx_mask
= sdata
->rc_rateidx_mask
[band
];
4324 rate_control_get_rate(sdata
, NULL
, &txrc
);
4326 info
->control
.vif
= vif
;
4328 info
->flags
|= IEEE80211_TX_CTL_CLEAR_PS_FILT
|
4329 IEEE80211_TX_CTL_ASSIGN_SEQ
|
4330 IEEE80211_TX_CTL_FIRST_FRAGMENT
;
4338 ieee80211_beacon_get_template(struct ieee80211_hw
*hw
,
4339 struct ieee80211_vif
*vif
,
4340 struct ieee80211_mutable_offsets
*offs
)
4342 return __ieee80211_beacon_get(hw
, vif
, offs
, true);
4344 EXPORT_SYMBOL(ieee80211_beacon_get_template
);
4346 struct sk_buff
*ieee80211_beacon_get_tim(struct ieee80211_hw
*hw
,
4347 struct ieee80211_vif
*vif
,
4348 u16
*tim_offset
, u16
*tim_length
)
4350 struct ieee80211_mutable_offsets offs
= {};
4351 struct sk_buff
*bcn
= __ieee80211_beacon_get(hw
, vif
, &offs
, false);
4352 struct sk_buff
*copy
;
4353 struct ieee80211_supported_band
*sband
;
4360 *tim_offset
= offs
.tim_offset
;
4363 *tim_length
= offs
.tim_length
;
4365 if (ieee80211_hw_check(hw
, BEACON_TX_STATUS
) ||
4366 !hw_to_local(hw
)->monitors
)
4369 /* send a copy to monitor interfaces */
4370 copy
= skb_copy(bcn
, GFP_ATOMIC
);
4374 shift
= ieee80211_vif_get_shift(vif
);
4375 sband
= ieee80211_get_sband(vif_to_sdata(vif
));
4379 ieee80211_tx_monitor(hw_to_local(hw
), copy
, sband
, 1, shift
, false);
4383 EXPORT_SYMBOL(ieee80211_beacon_get_tim
);
4385 struct sk_buff
*ieee80211_proberesp_get(struct ieee80211_hw
*hw
,
4386 struct ieee80211_vif
*vif
)
4388 struct ieee80211_if_ap
*ap
= NULL
;
4389 struct sk_buff
*skb
= NULL
;
4390 struct probe_resp
*presp
= NULL
;
4391 struct ieee80211_hdr
*hdr
;
4392 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
4394 if (sdata
->vif
.type
!= NL80211_IFTYPE_AP
)
4400 presp
= rcu_dereference(ap
->probe_resp
);
4404 skb
= dev_alloc_skb(presp
->len
);
4408 skb_put_data(skb
, presp
->data
, presp
->len
);
4410 hdr
= (struct ieee80211_hdr
*) skb
->data
;
4411 memset(hdr
->addr1
, 0, sizeof(hdr
->addr1
));
4417 EXPORT_SYMBOL(ieee80211_proberesp_get
);
4419 struct sk_buff
*ieee80211_pspoll_get(struct ieee80211_hw
*hw
,
4420 struct ieee80211_vif
*vif
)
4422 struct ieee80211_sub_if_data
*sdata
;
4423 struct ieee80211_if_managed
*ifmgd
;
4424 struct ieee80211_pspoll
*pspoll
;
4425 struct ieee80211_local
*local
;
4426 struct sk_buff
*skb
;
4428 if (WARN_ON(vif
->type
!= NL80211_IFTYPE_STATION
))
4431 sdata
= vif_to_sdata(vif
);
4432 ifmgd
= &sdata
->u
.mgd
;
4433 local
= sdata
->local
;
4435 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*pspoll
));
4439 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
4441 pspoll
= skb_put_zero(skb
, sizeof(*pspoll
));
4442 pspoll
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_CTL
|
4443 IEEE80211_STYPE_PSPOLL
);
4444 pspoll
->aid
= cpu_to_le16(ifmgd
->aid
);
4446 /* aid in PS-Poll has its two MSBs each set to 1 */
4447 pspoll
->aid
|= cpu_to_le16(1 << 15 | 1 << 14);
4449 memcpy(pspoll
->bssid
, ifmgd
->bssid
, ETH_ALEN
);
4450 memcpy(pspoll
->ta
, vif
->addr
, ETH_ALEN
);
4454 EXPORT_SYMBOL(ieee80211_pspoll_get
);
4456 struct sk_buff
*ieee80211_nullfunc_get(struct ieee80211_hw
*hw
,
4457 struct ieee80211_vif
*vif
,
4460 struct ieee80211_hdr_3addr
*nullfunc
;
4461 struct ieee80211_sub_if_data
*sdata
;
4462 struct ieee80211_if_managed
*ifmgd
;
4463 struct ieee80211_local
*local
;
4464 struct sk_buff
*skb
;
4467 if (WARN_ON(vif
->type
!= NL80211_IFTYPE_STATION
))
4470 sdata
= vif_to_sdata(vif
);
4471 ifmgd
= &sdata
->u
.mgd
;
4472 local
= sdata
->local
;
4475 struct sta_info
*sta
;
4478 sta
= sta_info_get(sdata
, ifmgd
->bssid
);
4479 qos
= sta
&& sta
->sta
.wme
;
4483 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
4484 sizeof(*nullfunc
) + 2);
4488 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
4490 nullfunc
= skb_put_zero(skb
, sizeof(*nullfunc
));
4491 nullfunc
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
4492 IEEE80211_STYPE_NULLFUNC
|
4493 IEEE80211_FCTL_TODS
);
4495 __le16 qos
= cpu_to_le16(7);
4497 BUILD_BUG_ON((IEEE80211_STYPE_QOS_NULLFUNC
|
4498 IEEE80211_STYPE_NULLFUNC
) !=
4499 IEEE80211_STYPE_QOS_NULLFUNC
);
4500 nullfunc
->frame_control
|=
4501 cpu_to_le16(IEEE80211_STYPE_QOS_NULLFUNC
);
4503 skb_set_queue_mapping(skb
, IEEE80211_AC_VO
);
4504 skb_put_data(skb
, &qos
, sizeof(qos
));
4507 memcpy(nullfunc
->addr1
, ifmgd
->bssid
, ETH_ALEN
);
4508 memcpy(nullfunc
->addr2
, vif
->addr
, ETH_ALEN
);
4509 memcpy(nullfunc
->addr3
, ifmgd
->bssid
, ETH_ALEN
);
4513 EXPORT_SYMBOL(ieee80211_nullfunc_get
);
4515 struct sk_buff
*ieee80211_probereq_get(struct ieee80211_hw
*hw
,
4517 const u8
*ssid
, size_t ssid_len
,
4520 struct ieee80211_local
*local
= hw_to_local(hw
);
4521 struct ieee80211_hdr_3addr
*hdr
;
4522 struct sk_buff
*skb
;
4526 ie_ssid_len
= 2 + ssid_len
;
4528 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*hdr
) +
4529 ie_ssid_len
+ tailroom
);
4533 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
4535 hdr
= skb_put_zero(skb
, sizeof(*hdr
));
4536 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
4537 IEEE80211_STYPE_PROBE_REQ
);
4538 eth_broadcast_addr(hdr
->addr1
);
4539 memcpy(hdr
->addr2
, src_addr
, ETH_ALEN
);
4540 eth_broadcast_addr(hdr
->addr3
);
4542 pos
= skb_put(skb
, ie_ssid_len
);
4543 *pos
++ = WLAN_EID_SSID
;
4546 memcpy(pos
, ssid
, ssid_len
);
4551 EXPORT_SYMBOL(ieee80211_probereq_get
);
4553 void ieee80211_rts_get(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
4554 const void *frame
, size_t frame_len
,
4555 const struct ieee80211_tx_info
*frame_txctl
,
4556 struct ieee80211_rts
*rts
)
4558 const struct ieee80211_hdr
*hdr
= frame
;
4560 rts
->frame_control
=
4561 cpu_to_le16(IEEE80211_FTYPE_CTL
| IEEE80211_STYPE_RTS
);
4562 rts
->duration
= ieee80211_rts_duration(hw
, vif
, frame_len
,
4564 memcpy(rts
->ra
, hdr
->addr1
, sizeof(rts
->ra
));
4565 memcpy(rts
->ta
, hdr
->addr2
, sizeof(rts
->ta
));
4567 EXPORT_SYMBOL(ieee80211_rts_get
);
4569 void ieee80211_ctstoself_get(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
4570 const void *frame
, size_t frame_len
,
4571 const struct ieee80211_tx_info
*frame_txctl
,
4572 struct ieee80211_cts
*cts
)
4574 const struct ieee80211_hdr
*hdr
= frame
;
4576 cts
->frame_control
=
4577 cpu_to_le16(IEEE80211_FTYPE_CTL
| IEEE80211_STYPE_CTS
);
4578 cts
->duration
= ieee80211_ctstoself_duration(hw
, vif
,
4579 frame_len
, frame_txctl
);
4580 memcpy(cts
->ra
, hdr
->addr1
, sizeof(cts
->ra
));
4582 EXPORT_SYMBOL(ieee80211_ctstoself_get
);
4585 ieee80211_get_buffered_bc(struct ieee80211_hw
*hw
,
4586 struct ieee80211_vif
*vif
)
4588 struct ieee80211_local
*local
= hw_to_local(hw
);
4589 struct sk_buff
*skb
= NULL
;
4590 struct ieee80211_tx_data tx
;
4591 struct ieee80211_sub_if_data
*sdata
;
4593 struct ieee80211_tx_info
*info
;
4594 struct ieee80211_chanctx_conf
*chanctx_conf
;
4596 sdata
= vif_to_sdata(vif
);
4599 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
4604 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
) {
4605 struct beacon_data
*beacon
=
4606 rcu_dereference(sdata
->u
.ap
.beacon
);
4608 if (!beacon
|| !beacon
->head
)
4611 ps
= &sdata
->u
.ap
.ps
;
4612 } else if (ieee80211_vif_is_mesh(&sdata
->vif
)) {
4613 ps
= &sdata
->u
.mesh
.ps
;
4618 if (ps
->dtim_count
!= 0 || !ps
->dtim_bc_mc
)
4619 goto out
; /* send buffered bc/mc only after DTIM beacon */
4622 skb
= skb_dequeue(&ps
->bc_buf
);
4625 local
->total_ps_buffered
--;
4627 if (!skb_queue_empty(&ps
->bc_buf
) && skb
->len
>= 2) {
4628 struct ieee80211_hdr
*hdr
=
4629 (struct ieee80211_hdr
*) skb
->data
;
4630 /* more buffered multicast/broadcast frames ==> set
4631 * MoreData flag in IEEE 802.11 header to inform PS
4633 hdr
->frame_control
|=
4634 cpu_to_le16(IEEE80211_FCTL_MOREDATA
);
4637 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
)
4638 sdata
= IEEE80211_DEV_TO_SUB_IF(skb
->dev
);
4639 if (!ieee80211_tx_prepare(sdata
, &tx
, NULL
, skb
))
4641 ieee80211_free_txskb(hw
, skb
);
4644 info
= IEEE80211_SKB_CB(skb
);
4646 tx
.flags
|= IEEE80211_TX_PS_BUFFERED
;
4647 info
->band
= chanctx_conf
->def
.chan
->band
;
4649 if (invoke_tx_handlers(&tx
))
4656 EXPORT_SYMBOL(ieee80211_get_buffered_bc
);
4658 int ieee80211_reserve_tid(struct ieee80211_sta
*pubsta
, u8 tid
)
4660 struct sta_info
*sta
= container_of(pubsta
, struct sta_info
, sta
);
4661 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
4662 struct ieee80211_local
*local
= sdata
->local
;
4666 lockdep_assert_held(&local
->sta_mtx
);
4668 /* only some cases are supported right now */
4669 switch (sdata
->vif
.type
) {
4670 case NL80211_IFTYPE_STATION
:
4671 case NL80211_IFTYPE_AP
:
4672 case NL80211_IFTYPE_AP_VLAN
:
4679 if (WARN_ON(tid
>= IEEE80211_NUM_UPS
))
4682 if (sta
->reserved_tid
== tid
) {
4687 if (sta
->reserved_tid
!= IEEE80211_TID_UNRESERVED
) {
4688 sdata_err(sdata
, "TID reservation already active\n");
4693 ieee80211_stop_vif_queues(sdata
->local
, sdata
,
4694 IEEE80211_QUEUE_STOP_REASON_RESERVE_TID
);
4698 /* Tear down BA sessions so we stop aggregating on this TID */
4699 if (ieee80211_hw_check(&local
->hw
, AMPDU_AGGREGATION
)) {
4700 set_sta_flag(sta
, WLAN_STA_BLOCK_BA
);
4701 __ieee80211_stop_tx_ba_session(sta
, tid
,
4702 AGG_STOP_LOCAL_REQUEST
);
4705 queues
= BIT(sdata
->vif
.hw_queue
[ieee802_1d_to_ac
[tid
]]);
4706 __ieee80211_flush_queues(local
, sdata
, queues
, false);
4708 sta
->reserved_tid
= tid
;
4710 ieee80211_wake_vif_queues(local
, sdata
,
4711 IEEE80211_QUEUE_STOP_REASON_RESERVE_TID
);
4713 if (ieee80211_hw_check(&local
->hw
, AMPDU_AGGREGATION
))
4714 clear_sta_flag(sta
, WLAN_STA_BLOCK_BA
);
4720 EXPORT_SYMBOL(ieee80211_reserve_tid
);
4722 void ieee80211_unreserve_tid(struct ieee80211_sta
*pubsta
, u8 tid
)
4724 struct sta_info
*sta
= container_of(pubsta
, struct sta_info
, sta
);
4725 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
4727 lockdep_assert_held(&sdata
->local
->sta_mtx
);
4729 /* only some cases are supported right now */
4730 switch (sdata
->vif
.type
) {
4731 case NL80211_IFTYPE_STATION
:
4732 case NL80211_IFTYPE_AP
:
4733 case NL80211_IFTYPE_AP_VLAN
:
4740 if (tid
!= sta
->reserved_tid
) {
4741 sdata_err(sdata
, "TID to unreserve (%d) isn't reserved\n", tid
);
4745 sta
->reserved_tid
= IEEE80211_TID_UNRESERVED
;
4747 EXPORT_SYMBOL(ieee80211_unreserve_tid
);
4749 void __ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data
*sdata
,
4750 struct sk_buff
*skb
, int tid
,
4751 enum nl80211_band band
)
4753 int ac
= ieee80211_ac_from_tid(tid
);
4755 skb_reset_mac_header(skb
);
4756 skb_set_queue_mapping(skb
, ac
);
4757 skb
->priority
= tid
;
4759 skb
->dev
= sdata
->dev
;
4762 * The other path calling ieee80211_xmit is from the tasklet,
4763 * and while we can handle concurrent transmissions locking
4764 * requirements are that we do not come into tx with bhs on.
4767 IEEE80211_SKB_CB(skb
)->band
= band
;
4768 ieee80211_xmit(sdata
, NULL
, skb
);