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
;
217 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(tx
->skb
);
219 /* driver doesn't support power save */
220 if (!ieee80211_hw_check(&local
->hw
, SUPPORTS_PS
))
223 /* hardware does dynamic power save */
224 if (ieee80211_hw_check(&local
->hw
, SUPPORTS_DYNAMIC_PS
))
227 /* dynamic power save disabled */
228 if (local
->hw
.conf
.dynamic_ps_timeout
<= 0)
231 /* we are scanning, don't enable power save */
235 if (!local
->ps_sdata
)
238 /* No point if we're going to suspend */
239 if (local
->quiescing
)
242 /* dynamic ps is supported only in managed mode */
243 if (tx
->sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
246 if (unlikely(info
->flags
& IEEE80211_TX_INTFL_OFFCHAN_TX_OK
))
249 ifmgd
= &tx
->sdata
->u
.mgd
;
252 * Don't wakeup from power save if u-apsd is enabled, voip ac has
253 * u-apsd enabled and the frame is in voip class. This effectively
254 * means that even if all access categories have u-apsd enabled, in
255 * practise u-apsd is only used with the voip ac. This is a
256 * workaround for the case when received voip class packets do not
257 * have correct qos tag for some reason, due the network or the
260 * Note: ifmgd->uapsd_queues access is racy here. If the value is
261 * changed via debugfs, user needs to reassociate manually to have
262 * everything in sync.
264 if ((ifmgd
->flags
& IEEE80211_STA_UAPSD_ENABLED
) &&
265 (ifmgd
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
) &&
266 skb_get_queue_mapping(tx
->skb
) == IEEE80211_AC_VO
)
269 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
) {
270 ieee80211_stop_queues_by_reason(&local
->hw
,
271 IEEE80211_MAX_QUEUE_MAP
,
272 IEEE80211_QUEUE_STOP_REASON_PS
,
274 ifmgd
->flags
&= ~IEEE80211_STA_NULLFUNC_ACKED
;
275 ieee80211_queue_work(&local
->hw
,
276 &local
->dynamic_ps_disable_work
);
279 /* Don't restart the timer if we're not disassociated */
280 if (!ifmgd
->associated
)
283 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
284 msecs_to_jiffies(local
->hw
.conf
.dynamic_ps_timeout
));
289 static ieee80211_tx_result debug_noinline
290 ieee80211_tx_h_check_assoc(struct ieee80211_tx_data
*tx
)
293 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)tx
->skb
->data
;
294 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(tx
->skb
);
297 if (unlikely(info
->flags
& IEEE80211_TX_CTL_INJECTED
))
300 if (unlikely(test_bit(SCAN_SW_SCANNING
, &tx
->local
->scanning
)) &&
301 test_bit(SDATA_STATE_OFFCHANNEL
, &tx
->sdata
->state
) &&
302 !ieee80211_is_probe_req(hdr
->frame_control
) &&
303 !ieee80211_is_nullfunc(hdr
->frame_control
))
305 * When software scanning only nullfunc frames (to notify
306 * the sleep state to the AP) and probe requests (for the
307 * active scan) are allowed, all other frames should not be
308 * sent and we should not get here, but if we do
309 * nonetheless, drop them to avoid sending them
310 * off-channel. See the link below and
311 * ieee80211_start_scan() for more.
313 * http://article.gmane.org/gmane.linux.kernel.wireless.general/30089
317 if (tx
->sdata
->vif
.type
== NL80211_IFTYPE_OCB
)
320 if (tx
->sdata
->vif
.type
== NL80211_IFTYPE_WDS
)
323 if (tx
->flags
& IEEE80211_TX_PS_BUFFERED
)
327 assoc
= test_sta_flag(tx
->sta
, WLAN_STA_ASSOC
);
329 if (likely(tx
->flags
& IEEE80211_TX_UNICAST
)) {
330 if (unlikely(!assoc
&&
331 ieee80211_is_data(hdr
->frame_control
))) {
332 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
333 sdata_info(tx
->sdata
,
334 "dropped data frame to not associated station %pM\n",
337 I802_DEBUG_INC(tx
->local
->tx_handlers_drop_not_assoc
);
340 } else if (unlikely(ieee80211_is_data(hdr
->frame_control
) &&
341 ieee80211_vif_get_num_mcast_if(tx
->sdata
) == 0)) {
343 * No associated STAs - no need to send multicast
352 /* This function is called whenever the AP is about to exceed the maximum limit
353 * of buffered frames for power saving STAs. This situation should not really
354 * happen often during normal operation, so dropping the oldest buffered packet
355 * from each queue should be OK to make some room for new frames. */
356 static void purge_old_ps_buffers(struct ieee80211_local
*local
)
358 int total
= 0, purged
= 0;
360 struct ieee80211_sub_if_data
*sdata
;
361 struct sta_info
*sta
;
363 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
366 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
)
367 ps
= &sdata
->u
.ap
.ps
;
368 else if (ieee80211_vif_is_mesh(&sdata
->vif
))
369 ps
= &sdata
->u
.mesh
.ps
;
373 skb
= skb_dequeue(&ps
->bc_buf
);
376 ieee80211_free_txskb(&local
->hw
, skb
);
378 total
+= skb_queue_len(&ps
->bc_buf
);
382 * Drop one frame from each station from the lowest-priority
383 * AC that has frames at all.
385 list_for_each_entry_rcu(sta
, &local
->sta_list
, list
) {
388 for (ac
= IEEE80211_AC_BK
; ac
>= IEEE80211_AC_VO
; ac
--) {
389 skb
= skb_dequeue(&sta
->ps_tx_buf
[ac
]);
390 total
+= skb_queue_len(&sta
->ps_tx_buf
[ac
]);
393 ieee80211_free_txskb(&local
->hw
, skb
);
399 local
->total_ps_buffered
= total
;
400 ps_dbg_hw(&local
->hw
, "PS buffers full - purged %d frames\n", purged
);
403 static ieee80211_tx_result
404 ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data
*tx
)
406 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(tx
->skb
);
407 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)tx
->skb
->data
;
411 * broadcast/multicast frame
413 * If any of the associated/peer stations is in power save mode,
414 * the frame is buffered to be sent after DTIM beacon frame.
415 * This is done either by the hardware or us.
418 /* powersaving STAs currently only in AP/VLAN/mesh mode */
419 if (tx
->sdata
->vif
.type
== NL80211_IFTYPE_AP
||
420 tx
->sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
) {
424 ps
= &tx
->sdata
->bss
->ps
;
425 } else if (ieee80211_vif_is_mesh(&tx
->sdata
->vif
)) {
426 ps
= &tx
->sdata
->u
.mesh
.ps
;
432 /* no buffering for ordered frames */
433 if (ieee80211_has_order(hdr
->frame_control
))
436 if (ieee80211_is_probe_req(hdr
->frame_control
))
439 if (ieee80211_hw_check(&tx
->local
->hw
, QUEUE_CONTROL
))
440 info
->hw_queue
= tx
->sdata
->vif
.cab_queue
;
442 /* no stations in PS mode and no buffered packets */
443 if (!atomic_read(&ps
->num_sta_ps
) && skb_queue_empty(&ps
->bc_buf
))
446 info
->flags
|= IEEE80211_TX_CTL_SEND_AFTER_DTIM
;
448 /* device releases frame after DTIM beacon */
449 if (!ieee80211_hw_check(&tx
->local
->hw
, HOST_BROADCAST_PS_BUFFERING
))
452 /* buffered in mac80211 */
453 if (tx
->local
->total_ps_buffered
>= TOTAL_MAX_TX_BUFFER
)
454 purge_old_ps_buffers(tx
->local
);
456 if (skb_queue_len(&ps
->bc_buf
) >= AP_MAX_BC_BUFFER
) {
458 "BC TX buffer full - dropping the oldest frame\n");
459 ieee80211_free_txskb(&tx
->local
->hw
, skb_dequeue(&ps
->bc_buf
));
461 tx
->local
->total_ps_buffered
++;
463 skb_queue_tail(&ps
->bc_buf
, tx
->skb
);
468 static int ieee80211_use_mfp(__le16 fc
, struct sta_info
*sta
,
471 if (!ieee80211_is_mgmt(fc
))
474 if (sta
== NULL
|| !test_sta_flag(sta
, WLAN_STA_MFP
))
477 if (!ieee80211_is_robust_mgmt_frame(skb
))
483 static ieee80211_tx_result
484 ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data
*tx
)
486 struct sta_info
*sta
= tx
->sta
;
487 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(tx
->skb
);
488 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)tx
->skb
->data
;
489 struct ieee80211_local
*local
= tx
->local
;
494 if (unlikely((test_sta_flag(sta
, WLAN_STA_PS_STA
) ||
495 test_sta_flag(sta
, WLAN_STA_PS_DRIVER
) ||
496 test_sta_flag(sta
, WLAN_STA_PS_DELIVER
)) &&
497 !(info
->flags
& IEEE80211_TX_CTL_NO_PS_BUFFER
))) {
498 int ac
= skb_get_queue_mapping(tx
->skb
);
500 if (ieee80211_is_mgmt(hdr
->frame_control
) &&
501 !ieee80211_is_bufferable_mmpdu(hdr
->frame_control
)) {
502 info
->flags
|= IEEE80211_TX_CTL_NO_PS_BUFFER
;
506 ps_dbg(sta
->sdata
, "STA %pM aid %d: PS buffer for AC %d\n",
507 sta
->sta
.addr
, sta
->sta
.aid
, ac
);
508 if (tx
->local
->total_ps_buffered
>= TOTAL_MAX_TX_BUFFER
)
509 purge_old_ps_buffers(tx
->local
);
511 /* sync with ieee80211_sta_ps_deliver_wakeup */
512 spin_lock(&sta
->ps_lock
);
514 * STA woke up the meantime and all the frames on ps_tx_buf have
515 * been queued to pending queue. No reordering can happen, go
516 * ahead and Tx the packet.
518 if (!test_sta_flag(sta
, WLAN_STA_PS_STA
) &&
519 !test_sta_flag(sta
, WLAN_STA_PS_DRIVER
) &&
520 !test_sta_flag(sta
, WLAN_STA_PS_DELIVER
)) {
521 spin_unlock(&sta
->ps_lock
);
525 if (skb_queue_len(&sta
->ps_tx_buf
[ac
]) >= STA_MAX_TX_BUFFER
) {
526 struct sk_buff
*old
= skb_dequeue(&sta
->ps_tx_buf
[ac
]);
528 "STA %pM TX buffer for AC %d full - dropping oldest frame\n",
530 ieee80211_free_txskb(&local
->hw
, old
);
532 tx
->local
->total_ps_buffered
++;
534 info
->control
.jiffies
= jiffies
;
535 info
->control
.vif
= &tx
->sdata
->vif
;
536 info
->flags
|= IEEE80211_TX_INTFL_NEED_TXPROCESSING
;
537 info
->flags
&= ~IEEE80211_TX_TEMPORARY_FLAGS
;
538 skb_queue_tail(&sta
->ps_tx_buf
[ac
], tx
->skb
);
539 spin_unlock(&sta
->ps_lock
);
541 if (!timer_pending(&local
->sta_cleanup
))
542 mod_timer(&local
->sta_cleanup
,
543 round_jiffies(jiffies
+
544 STA_INFO_CLEANUP_INTERVAL
));
547 * We queued up some frames, so the TIM bit might
548 * need to be set, recalculate it.
550 sta_info_recalc_tim(sta
);
553 } else if (unlikely(test_sta_flag(sta
, WLAN_STA_PS_STA
))) {
555 "STA %pM in PS mode, but polling/in SP -> send frame\n",
562 static ieee80211_tx_result debug_noinline
563 ieee80211_tx_h_ps_buf(struct ieee80211_tx_data
*tx
)
565 if (unlikely(tx
->flags
& IEEE80211_TX_PS_BUFFERED
))
568 if (tx
->flags
& IEEE80211_TX_UNICAST
)
569 return ieee80211_tx_h_unicast_ps_buf(tx
);
571 return ieee80211_tx_h_multicast_ps_buf(tx
);
574 static ieee80211_tx_result debug_noinline
575 ieee80211_tx_h_check_control_port_protocol(struct ieee80211_tx_data
*tx
)
577 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(tx
->skb
);
579 if (unlikely(tx
->sdata
->control_port_protocol
== tx
->skb
->protocol
)) {
580 if (tx
->sdata
->control_port_no_encrypt
)
581 info
->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
582 info
->control
.flags
|= IEEE80211_TX_CTRL_PORT_CTRL_PROTO
;
583 info
->flags
|= IEEE80211_TX_CTL_USE_MINRATE
;
589 static ieee80211_tx_result debug_noinline
590 ieee80211_tx_h_select_key(struct ieee80211_tx_data
*tx
)
592 struct ieee80211_key
*key
;
593 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(tx
->skb
);
594 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)tx
->skb
->data
;
596 if (unlikely(info
->flags
& IEEE80211_TX_INTFL_DONT_ENCRYPT
))
599 (key
= rcu_dereference(tx
->sta
->ptk
[tx
->sta
->ptk_idx
])))
601 else if (ieee80211_is_group_privacy_action(tx
->skb
) &&
602 (key
= rcu_dereference(tx
->sdata
->default_multicast_key
)))
604 else if (ieee80211_is_mgmt(hdr
->frame_control
) &&
605 is_multicast_ether_addr(hdr
->addr1
) &&
606 ieee80211_is_robust_mgmt_frame(tx
->skb
) &&
607 (key
= rcu_dereference(tx
->sdata
->default_mgmt_key
)))
609 else if (is_multicast_ether_addr(hdr
->addr1
) &&
610 (key
= rcu_dereference(tx
->sdata
->default_multicast_key
)))
612 else if (!is_multicast_ether_addr(hdr
->addr1
) &&
613 (key
= rcu_dereference(tx
->sdata
->default_unicast_key
)))
619 bool skip_hw
= false;
621 /* TODO: add threshold stuff again */
623 switch (tx
->key
->conf
.cipher
) {
624 case WLAN_CIPHER_SUITE_WEP40
:
625 case WLAN_CIPHER_SUITE_WEP104
:
626 case WLAN_CIPHER_SUITE_TKIP
:
627 if (!ieee80211_is_data_present(hdr
->frame_control
))
630 case WLAN_CIPHER_SUITE_CCMP
:
631 case WLAN_CIPHER_SUITE_CCMP_256
:
632 case WLAN_CIPHER_SUITE_GCMP
:
633 case WLAN_CIPHER_SUITE_GCMP_256
:
634 if (!ieee80211_is_data_present(hdr
->frame_control
) &&
635 !ieee80211_use_mfp(hdr
->frame_control
, tx
->sta
,
637 !ieee80211_is_group_privacy_action(tx
->skb
))
640 skip_hw
= (tx
->key
->conf
.flags
&
641 IEEE80211_KEY_FLAG_SW_MGMT_TX
) &&
642 ieee80211_is_mgmt(hdr
->frame_control
);
644 case WLAN_CIPHER_SUITE_AES_CMAC
:
645 case WLAN_CIPHER_SUITE_BIP_CMAC_256
:
646 case WLAN_CIPHER_SUITE_BIP_GMAC_128
:
647 case WLAN_CIPHER_SUITE_BIP_GMAC_256
:
648 if (!ieee80211_is_mgmt(hdr
->frame_control
))
653 if (unlikely(tx
->key
&& tx
->key
->flags
& KEY_FLAG_TAINTED
&&
654 !ieee80211_is_deauth(hdr
->frame_control
)))
657 if (!skip_hw
&& tx
->key
&&
658 tx
->key
->flags
& KEY_FLAG_UPLOADED_TO_HARDWARE
)
659 info
->control
.hw_key
= &tx
->key
->conf
;
665 static ieee80211_tx_result debug_noinline
666 ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data
*tx
)
668 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(tx
->skb
);
669 struct ieee80211_hdr
*hdr
= (void *)tx
->skb
->data
;
670 struct ieee80211_supported_band
*sband
;
672 struct ieee80211_tx_rate_control txrc
;
673 struct ieee80211_sta_rates
*ratetbl
= NULL
;
676 memset(&txrc
, 0, sizeof(txrc
));
678 sband
= tx
->local
->hw
.wiphy
->bands
[info
->band
];
680 len
= min_t(u32
, tx
->skb
->len
+ FCS_LEN
,
681 tx
->local
->hw
.wiphy
->frag_threshold
);
683 /* set up the tx rate control struct we give the RC algo */
684 txrc
.hw
= &tx
->local
->hw
;
686 txrc
.bss_conf
= &tx
->sdata
->vif
.bss_conf
;
688 txrc
.reported_rate
.idx
= -1;
689 txrc
.rate_idx_mask
= tx
->sdata
->rc_rateidx_mask
[info
->band
];
691 if (tx
->sdata
->rc_has_mcs_mask
[info
->band
])
692 txrc
.rate_idx_mcs_mask
=
693 tx
->sdata
->rc_rateidx_mcs_mask
[info
->band
];
695 txrc
.bss
= (tx
->sdata
->vif
.type
== NL80211_IFTYPE_AP
||
696 tx
->sdata
->vif
.type
== NL80211_IFTYPE_MESH_POINT
||
697 tx
->sdata
->vif
.type
== NL80211_IFTYPE_ADHOC
||
698 tx
->sdata
->vif
.type
== NL80211_IFTYPE_OCB
);
700 /* set up RTS protection if desired */
701 if (len
> tx
->local
->hw
.wiphy
->rts_threshold
) {
705 info
->control
.use_rts
= txrc
.rts
;
706 info
->control
.use_cts_prot
= tx
->sdata
->vif
.bss_conf
.use_cts_prot
;
709 * Use short preamble if the BSS can handle it, but not for
710 * management frames unless we know the receiver can handle
711 * that -- the management frame might be to a station that
712 * just wants a probe response.
714 if (tx
->sdata
->vif
.bss_conf
.use_short_preamble
&&
715 (ieee80211_is_data(hdr
->frame_control
) ||
716 (tx
->sta
&& test_sta_flag(tx
->sta
, WLAN_STA_SHORT_PREAMBLE
))))
717 txrc
.short_preamble
= true;
719 info
->control
.short_preamble
= txrc
.short_preamble
;
721 /* don't ask rate control when rate already injected via radiotap */
722 if (info
->control
.flags
& IEEE80211_TX_CTRL_RATE_INJECT
)
726 assoc
= test_sta_flag(tx
->sta
, WLAN_STA_ASSOC
);
729 * Lets not bother rate control if we're associated and cannot
730 * talk to the sta. This should not happen.
732 if (WARN(test_bit(SCAN_SW_SCANNING
, &tx
->local
->scanning
) && assoc
&&
733 !rate_usable_index_exists(sband
, &tx
->sta
->sta
),
734 "%s: Dropped data frame as no usable bitrate found while "
735 "scanning and associated. Target station: "
736 "%pM on %d GHz band\n",
737 tx
->sdata
->name
, hdr
->addr1
,
742 * If we're associated with the sta at this point we know we can at
743 * least send the frame at the lowest bit rate.
745 rate_control_get_rate(tx
->sdata
, tx
->sta
, &txrc
);
747 if (tx
->sta
&& !info
->control
.skip_table
)
748 ratetbl
= rcu_dereference(tx
->sta
->sta
.rates
);
750 if (unlikely(info
->control
.rates
[0].idx
< 0)) {
752 struct ieee80211_tx_rate rate
= {
753 .idx
= ratetbl
->rate
[0].idx
,
754 .flags
= ratetbl
->rate
[0].flags
,
755 .count
= ratetbl
->rate
[0].count
758 if (ratetbl
->rate
[0].idx
< 0)
766 tx
->rate
= info
->control
.rates
[0];
769 if (txrc
.reported_rate
.idx
< 0) {
770 txrc
.reported_rate
= tx
->rate
;
771 if (tx
->sta
&& ieee80211_is_data(hdr
->frame_control
))
772 tx
->sta
->tx_stats
.last_rate
= txrc
.reported_rate
;
774 tx
->sta
->tx_stats
.last_rate
= txrc
.reported_rate
;
779 if (unlikely(!info
->control
.rates
[0].count
))
780 info
->control
.rates
[0].count
= 1;
782 if (WARN_ON_ONCE((info
->control
.rates
[0].count
> 1) &&
783 (info
->flags
& IEEE80211_TX_CTL_NO_ACK
)))
784 info
->control
.rates
[0].count
= 1;
789 static __le16
ieee80211_tx_next_seq(struct sta_info
*sta
, int tid
)
791 u16
*seq
= &sta
->tid_seq
[tid
];
792 __le16 ret
= cpu_to_le16(*seq
);
794 /* Increase the sequence number. */
795 *seq
= (*seq
+ 0x10) & IEEE80211_SCTL_SEQ
;
800 static ieee80211_tx_result debug_noinline
801 ieee80211_tx_h_sequence(struct ieee80211_tx_data
*tx
)
803 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(tx
->skb
);
804 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)tx
->skb
->data
;
808 * Packet injection may want to control the sequence
809 * number, if we have no matching interface then we
810 * neither assign one ourselves nor ask the driver to.
812 if (unlikely(info
->control
.vif
->type
== NL80211_IFTYPE_MONITOR
))
815 if (unlikely(ieee80211_is_ctl(hdr
->frame_control
)))
818 if (ieee80211_hdrlen(hdr
->frame_control
) < 24)
821 if (ieee80211_is_qos_nullfunc(hdr
->frame_control
))
825 * Anything but QoS data that has a sequence number field
826 * (is long enough) gets a sequence number from the global
827 * counter. QoS data frames with a multicast destination
828 * also use the global counter (802.11-2012 9.3.2.10).
830 if (!ieee80211_is_data_qos(hdr
->frame_control
) ||
831 is_multicast_ether_addr(hdr
->addr1
)) {
832 if (tx
->flags
& IEEE80211_TX_NO_SEQNO
)
834 /* driver should assign sequence number */
835 info
->flags
|= IEEE80211_TX_CTL_ASSIGN_SEQ
;
836 /* for pure STA mode without beacons, we can do it */
837 hdr
->seq_ctrl
= cpu_to_le16(tx
->sdata
->sequence_number
);
838 tx
->sdata
->sequence_number
+= 0x10;
840 tx
->sta
->tx_stats
.msdu
[IEEE80211_NUM_TIDS
]++;
845 * This should be true for injected/management frames only, for
846 * management frames we have set the IEEE80211_TX_CTL_ASSIGN_SEQ
847 * above since they are not QoS-data frames.
852 /* include per-STA, per-TID sequence counter */
853 tid
= ieee80211_get_tid(hdr
);
854 tx
->sta
->tx_stats
.msdu
[tid
]++;
856 hdr
->seq_ctrl
= ieee80211_tx_next_seq(tx
->sta
, tid
);
861 static int ieee80211_fragment(struct ieee80211_tx_data
*tx
,
862 struct sk_buff
*skb
, int hdrlen
,
865 struct ieee80211_local
*local
= tx
->local
;
866 struct ieee80211_tx_info
*info
;
868 int per_fragm
= frag_threshold
- hdrlen
- FCS_LEN
;
869 int pos
= hdrlen
+ per_fragm
;
870 int rem
= skb
->len
- hdrlen
- per_fragm
;
872 if (WARN_ON(rem
< 0))
875 /* first fragment was already added to queue by caller */
878 int fraglen
= per_fragm
;
883 tmp
= dev_alloc_skb(local
->tx_headroom
+
885 tx
->sdata
->encrypt_headroom
+
886 IEEE80211_ENCRYPT_TAILROOM
);
890 __skb_queue_tail(&tx
->skbs
, tmp
);
893 local
->tx_headroom
+ tx
->sdata
->encrypt_headroom
);
895 /* copy control information */
896 memcpy(tmp
->cb
, skb
->cb
, sizeof(tmp
->cb
));
898 info
= IEEE80211_SKB_CB(tmp
);
899 info
->flags
&= ~(IEEE80211_TX_CTL_CLEAR_PS_FILT
|
900 IEEE80211_TX_CTL_FIRST_FRAGMENT
);
903 info
->flags
|= IEEE80211_TX_CTL_MORE_FRAMES
;
905 skb_copy_queue_mapping(tmp
, skb
);
906 tmp
->priority
= skb
->priority
;
909 /* copy header and data */
910 skb_put_data(tmp
, skb
->data
, hdrlen
);
911 skb_put_data(tmp
, skb
->data
+ pos
, fraglen
);
916 /* adjust first fragment's length */
917 skb_trim(skb
, hdrlen
+ per_fragm
);
921 static ieee80211_tx_result debug_noinline
922 ieee80211_tx_h_fragment(struct ieee80211_tx_data
*tx
)
924 struct sk_buff
*skb
= tx
->skb
;
925 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
926 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
927 int frag_threshold
= tx
->local
->hw
.wiphy
->frag_threshold
;
931 /* no matter what happens, tx->skb moves to tx->skbs */
932 __skb_queue_tail(&tx
->skbs
, skb
);
935 if (info
->flags
& IEEE80211_TX_CTL_DONTFRAG
)
938 if (ieee80211_hw_check(&tx
->local
->hw
, SUPPORTS_TX_FRAG
))
942 * Warn when submitting a fragmented A-MPDU frame and drop it.
943 * This scenario is handled in ieee80211_tx_prepare but extra
944 * caution taken here as fragmented ampdu may cause Tx stop.
946 if (WARN_ON(info
->flags
& IEEE80211_TX_CTL_AMPDU
))
949 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
951 /* internal error, why isn't DONTFRAG set? */
952 if (WARN_ON(skb
->len
+ FCS_LEN
<= frag_threshold
))
956 * Now fragment the frame. This will allocate all the fragments and
957 * chain them (using skb as the first fragment) to skb->next.
958 * During transmission, we will remove the successfully transmitted
959 * fragments from this list. When the low-level driver rejects one
960 * of the fragments then we will simply pretend to accept the skb
961 * but store it away as pending.
963 if (ieee80211_fragment(tx
, skb
, hdrlen
, frag_threshold
))
966 /* update duration/seq/flags of fragments */
969 skb_queue_walk(&tx
->skbs
, skb
) {
970 const __le16 morefrags
= cpu_to_le16(IEEE80211_FCTL_MOREFRAGS
);
972 hdr
= (void *)skb
->data
;
973 info
= IEEE80211_SKB_CB(skb
);
975 if (!skb_queue_is_last(&tx
->skbs
, skb
)) {
976 hdr
->frame_control
|= morefrags
;
978 * No multi-rate retries for fragmented frames, that
979 * would completely throw off the NAV at other STAs.
981 info
->control
.rates
[1].idx
= -1;
982 info
->control
.rates
[2].idx
= -1;
983 info
->control
.rates
[3].idx
= -1;
984 BUILD_BUG_ON(IEEE80211_TX_MAX_RATES
!= 4);
985 info
->flags
&= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE
;
987 hdr
->frame_control
&= ~morefrags
;
989 hdr
->seq_ctrl
|= cpu_to_le16(fragnum
& IEEE80211_SCTL_FRAG
);
996 static ieee80211_tx_result debug_noinline
997 ieee80211_tx_h_stats(struct ieee80211_tx_data
*tx
)
1005 skb_queue_walk(&tx
->skbs
, skb
) {
1006 ac
= skb_get_queue_mapping(skb
);
1007 tx
->sta
->tx_stats
.bytes
[ac
] += skb
->len
;
1010 tx
->sta
->tx_stats
.packets
[ac
]++;
1015 static ieee80211_tx_result debug_noinline
1016 ieee80211_tx_h_encrypt(struct ieee80211_tx_data
*tx
)
1021 switch (tx
->key
->conf
.cipher
) {
1022 case WLAN_CIPHER_SUITE_WEP40
:
1023 case WLAN_CIPHER_SUITE_WEP104
:
1024 return ieee80211_crypto_wep_encrypt(tx
);
1025 case WLAN_CIPHER_SUITE_TKIP
:
1026 return ieee80211_crypto_tkip_encrypt(tx
);
1027 case WLAN_CIPHER_SUITE_CCMP
:
1028 return ieee80211_crypto_ccmp_encrypt(
1029 tx
, IEEE80211_CCMP_MIC_LEN
);
1030 case WLAN_CIPHER_SUITE_CCMP_256
:
1031 return ieee80211_crypto_ccmp_encrypt(
1032 tx
, IEEE80211_CCMP_256_MIC_LEN
);
1033 case WLAN_CIPHER_SUITE_AES_CMAC
:
1034 return ieee80211_crypto_aes_cmac_encrypt(tx
);
1035 case WLAN_CIPHER_SUITE_BIP_CMAC_256
:
1036 return ieee80211_crypto_aes_cmac_256_encrypt(tx
);
1037 case WLAN_CIPHER_SUITE_BIP_GMAC_128
:
1038 case WLAN_CIPHER_SUITE_BIP_GMAC_256
:
1039 return ieee80211_crypto_aes_gmac_encrypt(tx
);
1040 case WLAN_CIPHER_SUITE_GCMP
:
1041 case WLAN_CIPHER_SUITE_GCMP_256
:
1042 return ieee80211_crypto_gcmp_encrypt(tx
);
1044 return ieee80211_crypto_hw_encrypt(tx
);
1050 static ieee80211_tx_result debug_noinline
1051 ieee80211_tx_h_calculate_duration(struct ieee80211_tx_data
*tx
)
1053 struct sk_buff
*skb
;
1054 struct ieee80211_hdr
*hdr
;
1058 skb_queue_walk(&tx
->skbs
, skb
) {
1059 hdr
= (void *) skb
->data
;
1060 if (unlikely(ieee80211_is_pspoll(hdr
->frame_control
)))
1061 break; /* must not overwrite AID */
1062 if (!skb_queue_is_last(&tx
->skbs
, skb
)) {
1063 struct sk_buff
*next
= skb_queue_next(&tx
->skbs
, skb
);
1064 next_len
= next
->len
;
1067 group_addr
= is_multicast_ether_addr(hdr
->addr1
);
1070 ieee80211_duration(tx
, skb
, group_addr
, next_len
);
1076 /* actual transmit path */
1078 static bool ieee80211_tx_prep_agg(struct ieee80211_tx_data
*tx
,
1079 struct sk_buff
*skb
,
1080 struct ieee80211_tx_info
*info
,
1081 struct tid_ampdu_tx
*tid_tx
,
1084 bool queued
= false;
1085 bool reset_agg_timer
= false;
1086 struct sk_buff
*purge_skb
= NULL
;
1088 if (test_bit(HT_AGG_STATE_OPERATIONAL
, &tid_tx
->state
)) {
1089 info
->flags
|= IEEE80211_TX_CTL_AMPDU
;
1090 reset_agg_timer
= true;
1091 } else if (test_bit(HT_AGG_STATE_WANT_START
, &tid_tx
->state
)) {
1093 * nothing -- this aggregation session is being started
1094 * but that might still fail with the driver
1096 } else if (!tx
->sta
->sta
.txq
[tid
]) {
1097 spin_lock(&tx
->sta
->lock
);
1099 * Need to re-check now, because we may get here
1101 * 1) in the window during which the setup is actually
1102 * already done, but not marked yet because not all
1103 * packets are spliced over to the driver pending
1104 * queue yet -- if this happened we acquire the lock
1105 * either before or after the splice happens, but
1106 * need to recheck which of these cases happened.
1108 * 2) during session teardown, if the OPERATIONAL bit
1109 * was cleared due to the teardown but the pointer
1110 * hasn't been assigned NULL yet (or we loaded it
1111 * before it was assigned) -- in this case it may
1112 * now be NULL which means we should just let the
1113 * packet pass through because splicing the frames
1114 * back is already done.
1116 tid_tx
= rcu_dereference_protected_tid_tx(tx
->sta
, tid
);
1119 /* do nothing, let packet pass through */
1120 } else if (test_bit(HT_AGG_STATE_OPERATIONAL
, &tid_tx
->state
)) {
1121 info
->flags
|= IEEE80211_TX_CTL_AMPDU
;
1122 reset_agg_timer
= true;
1125 if (info
->flags
& IEEE80211_TX_CTL_NO_PS_BUFFER
) {
1126 clear_sta_flag(tx
->sta
, WLAN_STA_SP
);
1127 ps_dbg(tx
->sta
->sdata
,
1128 "STA %pM aid %d: SP frame queued, close the SP w/o telling the peer\n",
1129 tx
->sta
->sta
.addr
, tx
->sta
->sta
.aid
);
1131 info
->control
.vif
= &tx
->sdata
->vif
;
1132 info
->flags
|= IEEE80211_TX_INTFL_NEED_TXPROCESSING
;
1133 info
->flags
&= ~IEEE80211_TX_TEMPORARY_FLAGS
;
1134 __skb_queue_tail(&tid_tx
->pending
, skb
);
1135 if (skb_queue_len(&tid_tx
->pending
) > STA_MAX_TX_BUFFER
)
1136 purge_skb
= __skb_dequeue(&tid_tx
->pending
);
1138 spin_unlock(&tx
->sta
->lock
);
1141 ieee80211_free_txskb(&tx
->local
->hw
, purge_skb
);
1144 /* reset session timer */
1145 if (reset_agg_timer
)
1146 tid_tx
->last_tx
= jiffies
;
1153 * pass %NULL for the station if unknown, a valid pointer if known
1154 * or an ERR_PTR() if the station is known not to exist
1156 static ieee80211_tx_result
1157 ieee80211_tx_prepare(struct ieee80211_sub_if_data
*sdata
,
1158 struct ieee80211_tx_data
*tx
,
1159 struct sta_info
*sta
, struct sk_buff
*skb
)
1161 struct ieee80211_local
*local
= sdata
->local
;
1162 struct ieee80211_hdr
*hdr
;
1163 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1166 memset(tx
, 0, sizeof(*tx
));
1170 __skb_queue_head_init(&tx
->skbs
);
1173 * If this flag is set to true anywhere, and we get here,
1174 * we are doing the needed processing, so remove the flag
1177 info
->flags
&= ~IEEE80211_TX_INTFL_NEED_TXPROCESSING
;
1179 hdr
= (struct ieee80211_hdr
*) skb
->data
;
1185 if (sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
) {
1186 tx
->sta
= rcu_dereference(sdata
->u
.vlan
.sta
);
1187 if (!tx
->sta
&& sdata
->wdev
.use_4addr
)
1189 } else if (info
->flags
& (IEEE80211_TX_INTFL_NL80211_FRAME_TX
|
1190 IEEE80211_TX_CTL_INJECTED
) ||
1191 tx
->sdata
->control_port_protocol
== tx
->skb
->protocol
) {
1192 tx
->sta
= sta_info_get_bss(sdata
, hdr
->addr1
);
1194 if (!tx
->sta
&& !is_multicast_ether_addr(hdr
->addr1
))
1195 tx
->sta
= sta_info_get(sdata
, hdr
->addr1
);
1198 if (tx
->sta
&& ieee80211_is_data_qos(hdr
->frame_control
) &&
1199 !ieee80211_is_qos_nullfunc(hdr
->frame_control
) &&
1200 ieee80211_hw_check(&local
->hw
, AMPDU_AGGREGATION
) &&
1201 !ieee80211_hw_check(&local
->hw
, TX_AMPDU_SETUP_IN_HW
)) {
1202 struct tid_ampdu_tx
*tid_tx
;
1204 tid
= ieee80211_get_tid(hdr
);
1206 tid_tx
= rcu_dereference(tx
->sta
->ampdu_mlme
.tid_tx
[tid
]);
1210 queued
= ieee80211_tx_prep_agg(tx
, skb
, info
,
1213 if (unlikely(queued
))
1218 if (is_multicast_ether_addr(hdr
->addr1
)) {
1219 tx
->flags
&= ~IEEE80211_TX_UNICAST
;
1220 info
->flags
|= IEEE80211_TX_CTL_NO_ACK
;
1222 tx
->flags
|= IEEE80211_TX_UNICAST
;
1224 if (!(info
->flags
& IEEE80211_TX_CTL_DONTFRAG
)) {
1225 if (!(tx
->flags
& IEEE80211_TX_UNICAST
) ||
1226 skb
->len
+ FCS_LEN
<= local
->hw
.wiphy
->frag_threshold
||
1227 info
->flags
& IEEE80211_TX_CTL_AMPDU
)
1228 info
->flags
|= IEEE80211_TX_CTL_DONTFRAG
;
1232 info
->flags
|= IEEE80211_TX_CTL_CLEAR_PS_FILT
;
1233 else if (test_and_clear_sta_flag(tx
->sta
, WLAN_STA_CLEAR_PS_FILT
)) {
1234 info
->flags
|= IEEE80211_TX_CTL_CLEAR_PS_FILT
;
1235 ieee80211_check_fast_xmit(tx
->sta
);
1238 info
->flags
|= IEEE80211_TX_CTL_FIRST_FRAGMENT
;
1243 static struct txq_info
*ieee80211_get_txq(struct ieee80211_local
*local
,
1244 struct ieee80211_vif
*vif
,
1245 struct sta_info
*sta
,
1246 struct sk_buff
*skb
)
1248 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1249 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1250 struct ieee80211_txq
*txq
= NULL
;
1252 if ((info
->flags
& IEEE80211_TX_CTL_SEND_AFTER_DTIM
) ||
1253 (info
->control
.flags
& IEEE80211_TX_CTRL_PS_RESPONSE
))
1256 if (unlikely(!ieee80211_is_data_present(hdr
->frame_control
))) {
1257 if ((!ieee80211_is_mgmt(hdr
->frame_control
) ||
1258 ieee80211_is_bufferable_mmpdu(hdr
->frame_control
) ||
1259 vif
->type
== NL80211_IFTYPE_STATION
) &&
1260 sta
&& sta
->uploaded
) {
1262 * This will be NULL if the driver didn't set the
1263 * opt-in hardware flag.
1265 txq
= sta
->sta
.txq
[IEEE80211_NUM_TIDS
];
1268 u8 tid
= skb
->priority
& IEEE80211_QOS_CTL_TID_MASK
;
1273 txq
= sta
->sta
.txq
[tid
];
1281 return to_txq_info(txq
);
1284 static void ieee80211_set_skb_enqueue_time(struct sk_buff
*skb
)
1286 IEEE80211_SKB_CB(skb
)->control
.enqueue_time
= codel_get_time();
1289 static u32
codel_skb_len_func(const struct sk_buff
*skb
)
1294 static codel_time_t
codel_skb_time_func(const struct sk_buff
*skb
)
1296 const struct ieee80211_tx_info
*info
;
1298 info
= (const struct ieee80211_tx_info
*)skb
->cb
;
1299 return info
->control
.enqueue_time
;
1302 static struct sk_buff
*codel_dequeue_func(struct codel_vars
*cvars
,
1305 struct ieee80211_local
*local
;
1306 struct txq_info
*txqi
;
1308 struct fq_flow
*flow
;
1311 local
= vif_to_sdata(txqi
->txq
.vif
)->local
;
1314 if (cvars
== &txqi
->def_cvars
)
1315 flow
= &txqi
->def_flow
;
1317 flow
= &fq
->flows
[cvars
- local
->cvars
];
1319 return fq_flow_dequeue(fq
, flow
);
1322 static void codel_drop_func(struct sk_buff
*skb
,
1325 struct ieee80211_local
*local
;
1326 struct ieee80211_hw
*hw
;
1327 struct txq_info
*txqi
;
1330 local
= vif_to_sdata(txqi
->txq
.vif
)->local
;
1333 ieee80211_free_txskb(hw
, skb
);
1336 static struct sk_buff
*fq_tin_dequeue_func(struct fq
*fq
,
1338 struct fq_flow
*flow
)
1340 struct ieee80211_local
*local
;
1341 struct txq_info
*txqi
;
1342 struct codel_vars
*cvars
;
1343 struct codel_params
*cparams
;
1344 struct codel_stats
*cstats
;
1346 local
= container_of(fq
, struct ieee80211_local
, fq
);
1347 txqi
= container_of(tin
, struct txq_info
, tin
);
1348 cstats
= &txqi
->cstats
;
1350 if (txqi
->txq
.sta
) {
1351 struct sta_info
*sta
= container_of(txqi
->txq
.sta
,
1352 struct sta_info
, sta
);
1353 cparams
= &sta
->cparams
;
1355 cparams
= &local
->cparams
;
1358 if (flow
== &txqi
->def_flow
)
1359 cvars
= &txqi
->def_cvars
;
1361 cvars
= &local
->cvars
[flow
- fq
->flows
];
1363 return codel_dequeue(txqi
,
1369 codel_skb_time_func
,
1371 codel_dequeue_func
);
1374 static void fq_skb_free_func(struct fq
*fq
,
1376 struct fq_flow
*flow
,
1377 struct sk_buff
*skb
)
1379 struct ieee80211_local
*local
;
1381 local
= container_of(fq
, struct ieee80211_local
, fq
);
1382 ieee80211_free_txskb(&local
->hw
, skb
);
1385 static struct fq_flow
*fq_flow_get_default_func(struct fq
*fq
,
1388 struct sk_buff
*skb
)
1390 struct txq_info
*txqi
;
1392 txqi
= container_of(tin
, struct txq_info
, tin
);
1393 return &txqi
->def_flow
;
1396 static void ieee80211_txq_enqueue(struct ieee80211_local
*local
,
1397 struct txq_info
*txqi
,
1398 struct sk_buff
*skb
)
1400 struct fq
*fq
= &local
->fq
;
1401 struct fq_tin
*tin
= &txqi
->tin
;
1402 u32 flow_idx
= fq_flow_idx(fq
, skb
);
1404 ieee80211_set_skb_enqueue_time(skb
);
1406 spin_lock_bh(&fq
->lock
);
1407 fq_tin_enqueue(fq
, tin
, flow_idx
, skb
,
1409 fq_flow_get_default_func
);
1410 spin_unlock_bh(&fq
->lock
);
1413 static bool fq_vlan_filter_func(struct fq
*fq
, struct fq_tin
*tin
,
1414 struct fq_flow
*flow
, struct sk_buff
*skb
,
1417 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1419 return info
->control
.vif
== data
;
1422 void ieee80211_txq_remove_vlan(struct ieee80211_local
*local
,
1423 struct ieee80211_sub_if_data
*sdata
)
1425 struct fq
*fq
= &local
->fq
;
1426 struct txq_info
*txqi
;
1428 struct ieee80211_sub_if_data
*ap
;
1430 if (WARN_ON(sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
))
1433 ap
= container_of(sdata
->bss
, struct ieee80211_sub_if_data
, u
.ap
);
1438 txqi
= to_txq_info(ap
->vif
.txq
);
1441 spin_lock_bh(&fq
->lock
);
1442 fq_tin_filter(fq
, tin
, fq_vlan_filter_func
, &sdata
->vif
,
1444 spin_unlock_bh(&fq
->lock
);
1447 void ieee80211_txq_init(struct ieee80211_sub_if_data
*sdata
,
1448 struct sta_info
*sta
,
1449 struct txq_info
*txqi
, int tid
)
1451 fq_tin_init(&txqi
->tin
);
1452 fq_flow_init(&txqi
->def_flow
);
1453 codel_vars_init(&txqi
->def_cvars
);
1454 codel_stats_init(&txqi
->cstats
);
1455 __skb_queue_head_init(&txqi
->frags
);
1456 INIT_LIST_HEAD(&txqi
->schedule_order
);
1458 txqi
->txq
.vif
= &sdata
->vif
;
1461 sdata
->vif
.txq
= &txqi
->txq
;
1463 txqi
->txq
.ac
= IEEE80211_AC_BE
;
1468 if (tid
== IEEE80211_NUM_TIDS
) {
1469 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
) {
1470 /* Drivers need to opt in to the management MPDU TXQ */
1471 if (!ieee80211_hw_check(&sdata
->local
->hw
,
1474 } else if (!ieee80211_hw_check(&sdata
->local
->hw
,
1476 /* Drivers need to opt in to the bufferable MMPDU TXQ */
1479 txqi
->txq
.ac
= IEEE80211_AC_VO
;
1481 txqi
->txq
.ac
= ieee80211_ac_from_tid(tid
);
1484 txqi
->txq
.sta
= &sta
->sta
;
1485 txqi
->txq
.tid
= tid
;
1486 sta
->sta
.txq
[tid
] = &txqi
->txq
;
1489 void ieee80211_txq_purge(struct ieee80211_local
*local
,
1490 struct txq_info
*txqi
)
1492 struct fq
*fq
= &local
->fq
;
1493 struct fq_tin
*tin
= &txqi
->tin
;
1495 spin_lock_bh(&fq
->lock
);
1496 fq_tin_reset(fq
, tin
, fq_skb_free_func
);
1497 ieee80211_purge_tx_queue(&local
->hw
, &txqi
->frags
);
1498 spin_unlock_bh(&fq
->lock
);
1500 spin_lock_bh(&local
->active_txq_lock
[txqi
->txq
.ac
]);
1501 list_del_init(&txqi
->schedule_order
);
1502 spin_unlock_bh(&local
->active_txq_lock
[txqi
->txq
.ac
]);
1505 void ieee80211_txq_set_params(struct ieee80211_local
*local
)
1507 if (local
->hw
.wiphy
->txq_limit
)
1508 local
->fq
.limit
= local
->hw
.wiphy
->txq_limit
;
1510 local
->hw
.wiphy
->txq_limit
= local
->fq
.limit
;
1512 if (local
->hw
.wiphy
->txq_memory_limit
)
1513 local
->fq
.memory_limit
= local
->hw
.wiphy
->txq_memory_limit
;
1515 local
->hw
.wiphy
->txq_memory_limit
= local
->fq
.memory_limit
;
1517 if (local
->hw
.wiphy
->txq_quantum
)
1518 local
->fq
.quantum
= local
->hw
.wiphy
->txq_quantum
;
1520 local
->hw
.wiphy
->txq_quantum
= local
->fq
.quantum
;
1523 int ieee80211_txq_setup_flows(struct ieee80211_local
*local
)
1525 struct fq
*fq
= &local
->fq
;
1528 bool supp_vht
= false;
1529 enum nl80211_band band
;
1531 if (!local
->ops
->wake_tx_queue
)
1534 ret
= fq_init(fq
, 4096);
1539 * If the hardware doesn't support VHT, it is safe to limit the maximum
1540 * queue size. 4 Mbytes is 64 max-size aggregates in 802.11n.
1542 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
1543 struct ieee80211_supported_band
*sband
;
1545 sband
= local
->hw
.wiphy
->bands
[band
];
1549 supp_vht
= supp_vht
|| sband
->vht_cap
.vht_supported
;
1553 fq
->memory_limit
= 4 << 20; /* 4 Mbytes */
1555 codel_params_init(&local
->cparams
);
1556 local
->cparams
.interval
= MS2TIME(100);
1557 local
->cparams
.target
= MS2TIME(20);
1558 local
->cparams
.ecn
= true;
1560 local
->cvars
= kcalloc(fq
->flows_cnt
, sizeof(local
->cvars
[0]),
1562 if (!local
->cvars
) {
1563 spin_lock_bh(&fq
->lock
);
1564 fq_reset(fq
, fq_skb_free_func
);
1565 spin_unlock_bh(&fq
->lock
);
1569 for (i
= 0; i
< fq
->flows_cnt
; i
++)
1570 codel_vars_init(&local
->cvars
[i
]);
1572 ieee80211_txq_set_params(local
);
1577 void ieee80211_txq_teardown_flows(struct ieee80211_local
*local
)
1579 struct fq
*fq
= &local
->fq
;
1581 if (!local
->ops
->wake_tx_queue
)
1584 kfree(local
->cvars
);
1585 local
->cvars
= NULL
;
1587 spin_lock_bh(&fq
->lock
);
1588 fq_reset(fq
, fq_skb_free_func
);
1589 spin_unlock_bh(&fq
->lock
);
1592 static bool ieee80211_queue_skb(struct ieee80211_local
*local
,
1593 struct ieee80211_sub_if_data
*sdata
,
1594 struct sta_info
*sta
,
1595 struct sk_buff
*skb
)
1597 struct ieee80211_vif
*vif
;
1598 struct txq_info
*txqi
;
1600 if (!local
->ops
->wake_tx_queue
||
1601 sdata
->vif
.type
== NL80211_IFTYPE_MONITOR
)
1604 if (sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
)
1605 sdata
= container_of(sdata
->bss
,
1606 struct ieee80211_sub_if_data
, u
.ap
);
1609 txqi
= ieee80211_get_txq(local
, vif
, sta
, skb
);
1614 ieee80211_txq_enqueue(local
, txqi
, skb
);
1616 schedule_and_wake_txq(local
, txqi
);
1621 static bool ieee80211_tx_frags(struct ieee80211_local
*local
,
1622 struct ieee80211_vif
*vif
,
1623 struct ieee80211_sta
*sta
,
1624 struct sk_buff_head
*skbs
,
1627 struct ieee80211_tx_control control
= {};
1628 struct sk_buff
*skb
, *tmp
;
1629 unsigned long flags
;
1631 skb_queue_walk_safe(skbs
, skb
, tmp
) {
1632 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1633 int q
= info
->hw_queue
;
1635 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1636 if (WARN_ON_ONCE(q
>= local
->hw
.queues
)) {
1637 __skb_unlink(skb
, skbs
);
1638 ieee80211_free_txskb(&local
->hw
, skb
);
1643 spin_lock_irqsave(&local
->queue_stop_reason_lock
, flags
);
1644 if (local
->queue_stop_reasons
[q
] ||
1645 (!txpending
&& !skb_queue_empty(&local
->pending
[q
]))) {
1646 if (unlikely(info
->flags
&
1647 IEEE80211_TX_INTFL_OFFCHAN_TX_OK
)) {
1648 if (local
->queue_stop_reasons
[q
] &
1649 ~BIT(IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL
)) {
1651 * Drop off-channel frames if queues
1652 * are stopped for any reason other
1653 * than off-channel operation. Never
1656 spin_unlock_irqrestore(
1657 &local
->queue_stop_reason_lock
,
1659 ieee80211_purge_tx_queue(&local
->hw
,
1666 * Since queue is stopped, queue up frames for
1667 * later transmission from the tx-pending
1668 * tasklet when the queue is woken again.
1671 skb_queue_splice_init(skbs
,
1672 &local
->pending
[q
]);
1674 skb_queue_splice_tail_init(skbs
,
1675 &local
->pending
[q
]);
1677 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
,
1682 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
, flags
);
1684 info
->control
.vif
= vif
;
1687 __skb_unlink(skb
, skbs
);
1688 drv_tx(local
, &control
, skb
);
1695 * Returns false if the frame couldn't be transmitted but was queued instead.
1697 static bool __ieee80211_tx(struct ieee80211_local
*local
,
1698 struct sk_buff_head
*skbs
, int led_len
,
1699 struct sta_info
*sta
, bool txpending
)
1701 struct ieee80211_tx_info
*info
;
1702 struct ieee80211_sub_if_data
*sdata
;
1703 struct ieee80211_vif
*vif
;
1704 struct ieee80211_sta
*pubsta
;
1705 struct sk_buff
*skb
;
1709 if (WARN_ON(skb_queue_empty(skbs
)))
1712 skb
= skb_peek(skbs
);
1713 fc
= ((struct ieee80211_hdr
*)skb
->data
)->frame_control
;
1714 info
= IEEE80211_SKB_CB(skb
);
1715 sdata
= vif_to_sdata(info
->control
.vif
);
1716 if (sta
&& !sta
->uploaded
)
1724 switch (sdata
->vif
.type
) {
1725 case NL80211_IFTYPE_MONITOR
:
1726 if (sdata
->u
.mntr
.flags
& MONITOR_FLAG_ACTIVE
) {
1730 sdata
= rcu_dereference(local
->monitor_sdata
);
1734 vif
->hw_queue
[skb_get_queue_mapping(skb
)];
1735 } else if (ieee80211_hw_check(&local
->hw
, QUEUE_CONTROL
)) {
1736 ieee80211_purge_tx_queue(&local
->hw
, skbs
);
1741 case NL80211_IFTYPE_AP_VLAN
:
1742 sdata
= container_of(sdata
->bss
,
1743 struct ieee80211_sub_if_data
, u
.ap
);
1750 result
= ieee80211_tx_frags(local
, vif
, pubsta
, skbs
,
1753 ieee80211_tpt_led_trig_tx(local
, fc
, led_len
);
1755 WARN_ON_ONCE(!skb_queue_empty(skbs
));
1761 * Invoke TX handlers, return 0 on success and non-zero if the
1762 * frame was dropped or queued.
1764 * The handlers are split into an early and late part. The latter is everything
1765 * that can be sensitive to reordering, and will be deferred to after packets
1766 * are dequeued from the intermediate queues (when they are enabled).
1768 static int invoke_tx_handlers_early(struct ieee80211_tx_data
*tx
)
1770 ieee80211_tx_result res
= TX_DROP
;
1772 #define CALL_TXH(txh) \
1775 if (res != TX_CONTINUE) \
1779 CALL_TXH(ieee80211_tx_h_dynamic_ps
);
1780 CALL_TXH(ieee80211_tx_h_check_assoc
);
1781 CALL_TXH(ieee80211_tx_h_ps_buf
);
1782 CALL_TXH(ieee80211_tx_h_check_control_port_protocol
);
1783 CALL_TXH(ieee80211_tx_h_select_key
);
1784 if (!ieee80211_hw_check(&tx
->local
->hw
, HAS_RATE_CONTROL
))
1785 CALL_TXH(ieee80211_tx_h_rate_ctrl
);
1788 if (unlikely(res
== TX_DROP
)) {
1789 I802_DEBUG_INC(tx
->local
->tx_handlers_drop
);
1791 ieee80211_free_txskb(&tx
->local
->hw
, tx
->skb
);
1793 ieee80211_purge_tx_queue(&tx
->local
->hw
, &tx
->skbs
);
1795 } else if (unlikely(res
== TX_QUEUED
)) {
1796 I802_DEBUG_INC(tx
->local
->tx_handlers_queued
);
1804 * Late handlers can be called while the sta lock is held. Handlers that can
1805 * cause packets to be generated will cause deadlock!
1807 static int invoke_tx_handlers_late(struct ieee80211_tx_data
*tx
)
1809 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(tx
->skb
);
1810 ieee80211_tx_result res
= TX_CONTINUE
;
1812 if (unlikely(info
->flags
& IEEE80211_TX_INTFL_RETRANSMISSION
)) {
1813 __skb_queue_tail(&tx
->skbs
, tx
->skb
);
1818 CALL_TXH(ieee80211_tx_h_michael_mic_add
);
1819 CALL_TXH(ieee80211_tx_h_sequence
);
1820 CALL_TXH(ieee80211_tx_h_fragment
);
1821 /* handlers after fragment must be aware of tx info fragmentation! */
1822 CALL_TXH(ieee80211_tx_h_stats
);
1823 CALL_TXH(ieee80211_tx_h_encrypt
);
1824 if (!ieee80211_hw_check(&tx
->local
->hw
, HAS_RATE_CONTROL
))
1825 CALL_TXH(ieee80211_tx_h_calculate_duration
);
1829 if (unlikely(res
== TX_DROP
)) {
1830 I802_DEBUG_INC(tx
->local
->tx_handlers_drop
);
1832 ieee80211_free_txskb(&tx
->local
->hw
, tx
->skb
);
1834 ieee80211_purge_tx_queue(&tx
->local
->hw
, &tx
->skbs
);
1836 } else if (unlikely(res
== TX_QUEUED
)) {
1837 I802_DEBUG_INC(tx
->local
->tx_handlers_queued
);
1844 static int invoke_tx_handlers(struct ieee80211_tx_data
*tx
)
1846 int r
= invoke_tx_handlers_early(tx
);
1850 return invoke_tx_handlers_late(tx
);
1853 bool ieee80211_tx_prepare_skb(struct ieee80211_hw
*hw
,
1854 struct ieee80211_vif
*vif
, struct sk_buff
*skb
,
1855 int band
, struct ieee80211_sta
**sta
)
1857 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
1858 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1859 struct ieee80211_tx_data tx
;
1860 struct sk_buff
*skb2
;
1862 if (ieee80211_tx_prepare(sdata
, &tx
, NULL
, skb
) == TX_DROP
)
1866 info
->control
.vif
= vif
;
1867 info
->hw_queue
= vif
->hw_queue
[skb_get_queue_mapping(skb
)];
1869 if (invoke_tx_handlers(&tx
))
1874 *sta
= &tx
.sta
->sta
;
1879 /* this function isn't suitable for fragmented data frames */
1880 skb2
= __skb_dequeue(&tx
.skbs
);
1881 if (WARN_ON(skb2
!= skb
|| !skb_queue_empty(&tx
.skbs
))) {
1882 ieee80211_free_txskb(hw
, skb2
);
1883 ieee80211_purge_tx_queue(hw
, &tx
.skbs
);
1889 EXPORT_SYMBOL(ieee80211_tx_prepare_skb
);
1892 * Returns false if the frame couldn't be transmitted but was queued instead.
1894 static bool ieee80211_tx(struct ieee80211_sub_if_data
*sdata
,
1895 struct sta_info
*sta
, struct sk_buff
*skb
,
1896 bool txpending
, u32 txdata_flags
)
1898 struct ieee80211_local
*local
= sdata
->local
;
1899 struct ieee80211_tx_data tx
;
1900 ieee80211_tx_result res_prepare
;
1901 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1905 if (unlikely(skb
->len
< 10)) {
1910 /* initialises tx */
1912 res_prepare
= ieee80211_tx_prepare(sdata
, &tx
, sta
, skb
);
1914 tx
.flags
|= txdata_flags
;
1916 if (unlikely(res_prepare
== TX_DROP
)) {
1917 ieee80211_free_txskb(&local
->hw
, skb
);
1919 } else if (unlikely(res_prepare
== TX_QUEUED
)) {
1923 /* set up hw_queue value early */
1924 if (!(info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
) ||
1925 !ieee80211_hw_check(&local
->hw
, QUEUE_CONTROL
))
1927 sdata
->vif
.hw_queue
[skb_get_queue_mapping(skb
)];
1929 if (invoke_tx_handlers_early(&tx
))
1932 if (ieee80211_queue_skb(local
, sdata
, tx
.sta
, tx
.skb
))
1935 if (!invoke_tx_handlers_late(&tx
))
1936 result
= __ieee80211_tx(local
, &tx
.skbs
, led_len
,
1942 /* device xmit handlers */
1944 static int ieee80211_skb_resize(struct ieee80211_sub_if_data
*sdata
,
1945 struct sk_buff
*skb
,
1946 int head_need
, bool may_encrypt
)
1948 struct ieee80211_local
*local
= sdata
->local
;
1949 struct ieee80211_hdr
*hdr
;
1953 hdr
= (struct ieee80211_hdr
*) skb
->data
;
1954 enc_tailroom
= may_encrypt
&&
1955 (sdata
->crypto_tx_tailroom_needed_cnt
||
1956 ieee80211_is_mgmt(hdr
->frame_control
));
1959 tail_need
= IEEE80211_ENCRYPT_TAILROOM
;
1960 tail_need
-= skb_tailroom(skb
);
1961 tail_need
= max_t(int, tail_need
, 0);
1964 if (skb_cloned(skb
) &&
1965 (!ieee80211_hw_check(&local
->hw
, SUPPORTS_CLONED_SKBS
) ||
1966 !skb_clone_writable(skb
, ETH_HLEN
) || enc_tailroom
))
1967 I802_DEBUG_INC(local
->tx_expand_skb_head_cloned
);
1968 else if (head_need
|| tail_need
)
1969 I802_DEBUG_INC(local
->tx_expand_skb_head
);
1973 if (pskb_expand_head(skb
, head_need
, tail_need
, GFP_ATOMIC
)) {
1974 wiphy_debug(local
->hw
.wiphy
,
1975 "failed to reallocate TX buffer\n");
1982 void ieee80211_xmit(struct ieee80211_sub_if_data
*sdata
,
1983 struct sta_info
*sta
, struct sk_buff
*skb
,
1986 struct ieee80211_local
*local
= sdata
->local
;
1987 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1988 struct ieee80211_hdr
*hdr
;
1992 may_encrypt
= !(info
->flags
& IEEE80211_TX_INTFL_DONT_ENCRYPT
);
1994 headroom
= local
->tx_headroom
;
1996 headroom
+= sdata
->encrypt_headroom
;
1997 headroom
-= skb_headroom(skb
);
1998 headroom
= max_t(int, 0, headroom
);
2000 if (ieee80211_skb_resize(sdata
, skb
, headroom
, may_encrypt
)) {
2001 ieee80211_free_txskb(&local
->hw
, skb
);
2005 hdr
= (struct ieee80211_hdr
*) skb
->data
;
2006 info
->control
.vif
= &sdata
->vif
;
2008 if (ieee80211_vif_is_mesh(&sdata
->vif
)) {
2009 if (ieee80211_is_data(hdr
->frame_control
) &&
2010 is_unicast_ether_addr(hdr
->addr1
)) {
2011 if (mesh_nexthop_resolve(sdata
, skb
))
2012 return; /* skb queued: don't free */
2014 ieee80211_mps_set_frame_flags(sdata
, NULL
, hdr
);
2018 ieee80211_set_qos_hdr(sdata
, skb
);
2019 ieee80211_tx(sdata
, sta
, skb
, false, txdata_flags
);
2022 static bool ieee80211_parse_tx_radiotap(struct ieee80211_local
*local
,
2023 struct sk_buff
*skb
)
2025 struct ieee80211_radiotap_iterator iterator
;
2026 struct ieee80211_radiotap_header
*rthdr
=
2027 (struct ieee80211_radiotap_header
*) skb
->data
;
2028 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
2029 struct ieee80211_supported_band
*sband
=
2030 local
->hw
.wiphy
->bands
[info
->band
];
2031 int ret
= ieee80211_radiotap_iterator_init(&iterator
, rthdr
, skb
->len
,
2035 bool rate_found
= false;
2036 u8 rate_retries
= 0;
2038 u8 mcs_known
, mcs_flags
, mcs_bw
;
2040 u8 vht_mcs
= 0, vht_nss
= 0;
2043 info
->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
|
2044 IEEE80211_TX_CTL_DONTFRAG
;
2047 * for every radiotap entry that is present
2048 * (ieee80211_radiotap_iterator_next returns -ENOENT when no more
2049 * entries present, or -EINVAL on error)
2053 ret
= ieee80211_radiotap_iterator_next(&iterator
);
2058 /* see if this argument is something we can use */
2059 switch (iterator
.this_arg_index
) {
2061 * You must take care when dereferencing iterator.this_arg
2062 * for multibyte types... the pointer is not aligned. Use
2063 * get_unaligned((type *)iterator.this_arg) to dereference
2064 * iterator.this_arg for type "type" safely on all arches.
2066 case IEEE80211_RADIOTAP_FLAGS
:
2067 if (*iterator
.this_arg
& IEEE80211_RADIOTAP_F_FCS
) {
2069 * this indicates that the skb we have been
2070 * handed has the 32-bit FCS CRC at the end...
2071 * we should react to that by snipping it off
2072 * because it will be recomputed and added
2075 if (skb
->len
< (iterator
._max_length
+ FCS_LEN
))
2078 skb_trim(skb
, skb
->len
- FCS_LEN
);
2080 if (*iterator
.this_arg
& IEEE80211_RADIOTAP_F_WEP
)
2081 info
->flags
&= ~IEEE80211_TX_INTFL_DONT_ENCRYPT
;
2082 if (*iterator
.this_arg
& IEEE80211_RADIOTAP_F_FRAG
)
2083 info
->flags
&= ~IEEE80211_TX_CTL_DONTFRAG
;
2086 case IEEE80211_RADIOTAP_TX_FLAGS
:
2087 txflags
= get_unaligned_le16(iterator
.this_arg
);
2088 if (txflags
& IEEE80211_RADIOTAP_F_TX_NOACK
)
2089 info
->flags
|= IEEE80211_TX_CTL_NO_ACK
;
2092 case IEEE80211_RADIOTAP_RATE
:
2093 rate
= *iterator
.this_arg
;
2098 case IEEE80211_RADIOTAP_DATA_RETRIES
:
2099 rate_retries
= *iterator
.this_arg
;
2102 case IEEE80211_RADIOTAP_MCS
:
2103 mcs_known
= iterator
.this_arg
[0];
2104 mcs_flags
= iterator
.this_arg
[1];
2105 if (!(mcs_known
& IEEE80211_RADIOTAP_MCS_HAVE_MCS
))
2109 rate
= iterator
.this_arg
[2];
2110 rate_flags
= IEEE80211_TX_RC_MCS
;
2112 if (mcs_known
& IEEE80211_RADIOTAP_MCS_HAVE_GI
&&
2113 mcs_flags
& IEEE80211_RADIOTAP_MCS_SGI
)
2114 rate_flags
|= IEEE80211_TX_RC_SHORT_GI
;
2116 mcs_bw
= mcs_flags
& IEEE80211_RADIOTAP_MCS_BW_MASK
;
2117 if (mcs_known
& IEEE80211_RADIOTAP_MCS_HAVE_BW
&&
2118 mcs_bw
== IEEE80211_RADIOTAP_MCS_BW_40
)
2119 rate_flags
|= IEEE80211_TX_RC_40_MHZ_WIDTH
;
2122 case IEEE80211_RADIOTAP_VHT
:
2123 vht_known
= get_unaligned_le16(iterator
.this_arg
);
2126 rate_flags
= IEEE80211_TX_RC_VHT_MCS
;
2127 if ((vht_known
& IEEE80211_RADIOTAP_VHT_KNOWN_GI
) &&
2128 (iterator
.this_arg
[2] &
2129 IEEE80211_RADIOTAP_VHT_FLAG_SGI
))
2130 rate_flags
|= IEEE80211_TX_RC_SHORT_GI
;
2132 IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH
) {
2133 if (iterator
.this_arg
[3] == 1)
2135 IEEE80211_TX_RC_40_MHZ_WIDTH
;
2136 else if (iterator
.this_arg
[3] == 4)
2138 IEEE80211_TX_RC_80_MHZ_WIDTH
;
2139 else if (iterator
.this_arg
[3] == 11)
2141 IEEE80211_TX_RC_160_MHZ_WIDTH
;
2144 vht_mcs
= iterator
.this_arg
[4] >> 4;
2145 vht_nss
= iterator
.this_arg
[4] & 0xF;
2149 * Please update the file
2150 * Documentation/networking/mac80211-injection.txt
2151 * when parsing new fields here.
2159 if (ret
!= -ENOENT
) /* ie, if we didn't simply run out of fields */
2163 info
->control
.flags
|= IEEE80211_TX_CTRL_RATE_INJECT
;
2165 for (i
= 0; i
< IEEE80211_TX_MAX_RATES
; i
++) {
2166 info
->control
.rates
[i
].idx
= -1;
2167 info
->control
.rates
[i
].flags
= 0;
2168 info
->control
.rates
[i
].count
= 0;
2171 if (rate_flags
& IEEE80211_TX_RC_MCS
) {
2172 info
->control
.rates
[0].idx
= rate
;
2173 } else if (rate_flags
& IEEE80211_TX_RC_VHT_MCS
) {
2174 ieee80211_rate_set_vht(info
->control
.rates
, vht_mcs
,
2177 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
2178 if (rate
* 5 != sband
->bitrates
[i
].bitrate
)
2181 info
->control
.rates
[0].idx
= i
;
2186 if (info
->control
.rates
[0].idx
< 0)
2187 info
->control
.flags
&= ~IEEE80211_TX_CTRL_RATE_INJECT
;
2189 info
->control
.rates
[0].flags
= rate_flags
;
2190 info
->control
.rates
[0].count
= min_t(u8
, rate_retries
+ 1,
2191 local
->hw
.max_rate_tries
);
2195 * remove the radiotap header
2196 * iterator->_max_length was sanity-checked against
2197 * skb->len by iterator init
2199 skb_pull(skb
, iterator
._max_length
);
2204 netdev_tx_t
ieee80211_monitor_start_xmit(struct sk_buff
*skb
,
2205 struct net_device
*dev
)
2207 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2208 struct ieee80211_chanctx_conf
*chanctx_conf
;
2209 struct ieee80211_radiotap_header
*prthdr
=
2210 (struct ieee80211_radiotap_header
*)skb
->data
;
2211 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
2212 struct ieee80211_hdr
*hdr
;
2213 struct ieee80211_sub_if_data
*tmp_sdata
, *sdata
;
2214 struct cfg80211_chan_def
*chandef
;
2218 /* check for not even having the fixed radiotap header part */
2219 if (unlikely(skb
->len
< sizeof(struct ieee80211_radiotap_header
)))
2220 goto fail
; /* too short to be possibly valid */
2222 /* is it a header version we can trust to find length from? */
2223 if (unlikely(prthdr
->it_version
))
2224 goto fail
; /* only version 0 is supported */
2226 /* then there must be a radiotap header with a length we can use */
2227 len_rthdr
= ieee80211_get_radiotap_len(skb
->data
);
2229 /* does the skb contain enough to deliver on the alleged length? */
2230 if (unlikely(skb
->len
< len_rthdr
))
2231 goto fail
; /* skb too short for claimed rt header extent */
2234 * fix up the pointers accounting for the radiotap
2235 * header still being in there. We are being given
2236 * a precooked IEEE80211 header so no need for
2239 skb_set_mac_header(skb
, len_rthdr
);
2241 * these are just fixed to the end of the rt area since we
2242 * don't have any better information and at this point, nobody cares
2244 skb_set_network_header(skb
, len_rthdr
);
2245 skb_set_transport_header(skb
, len_rthdr
);
2247 if (skb
->len
< len_rthdr
+ 2)
2250 hdr
= (struct ieee80211_hdr
*)(skb
->data
+ len_rthdr
);
2251 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
2253 if (skb
->len
< len_rthdr
+ hdrlen
)
2257 * Initialize skb->protocol if the injected frame is a data frame
2258 * carrying a rfc1042 header
2260 if (ieee80211_is_data(hdr
->frame_control
) &&
2261 skb
->len
>= len_rthdr
+ hdrlen
+ sizeof(rfc1042_header
) + 2) {
2262 u8
*payload
= (u8
*)hdr
+ hdrlen
;
2264 if (ether_addr_equal(payload
, rfc1042_header
))
2265 skb
->protocol
= cpu_to_be16((payload
[6] << 8) |
2269 memset(info
, 0, sizeof(*info
));
2271 info
->flags
= IEEE80211_TX_CTL_REQ_TX_STATUS
|
2272 IEEE80211_TX_CTL_INJECTED
;
2277 * We process outgoing injected frames that have a local address
2278 * we handle as though they are non-injected frames.
2279 * This code here isn't entirely correct, the local MAC address
2280 * isn't always enough to find the interface to use; for proper
2281 * VLAN/WDS support we will need a different mechanism (which
2282 * likely isn't going to be monitor interfaces).
2284 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2286 list_for_each_entry_rcu(tmp_sdata
, &local
->interfaces
, list
) {
2287 if (!ieee80211_sdata_running(tmp_sdata
))
2289 if (tmp_sdata
->vif
.type
== NL80211_IFTYPE_MONITOR
||
2290 tmp_sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
||
2291 tmp_sdata
->vif
.type
== NL80211_IFTYPE_WDS
)
2293 if (ether_addr_equal(tmp_sdata
->vif
.addr
, hdr
->addr2
)) {
2299 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
2300 if (!chanctx_conf
) {
2301 tmp_sdata
= rcu_dereference(local
->monitor_sdata
);
2304 rcu_dereference(tmp_sdata
->vif
.chanctx_conf
);
2308 chandef
= &chanctx_conf
->def
;
2309 else if (!local
->use_chanctx
)
2310 chandef
= &local
->_oper_chandef
;
2315 * Frame injection is not allowed if beaconing is not allowed
2316 * or if we need radar detection. Beaconing is usually not allowed when
2317 * the mode or operation (Adhoc, AP, Mesh) does not support DFS.
2318 * Passive scan is also used in world regulatory domains where
2319 * your country is not known and as such it should be treated as
2320 * NO TX unless the channel is explicitly allowed in which case
2321 * your current regulatory domain would not have the passive scan
2324 * Since AP mode uses monitor interfaces to inject/TX management
2325 * frames we can make AP mode the exception to this rule once it
2326 * supports radar detection as its implementation can deal with
2327 * radar detection by itself. We can do that later by adding a
2328 * monitor flag interfaces used for AP support.
2330 if (!cfg80211_reg_can_beacon(local
->hw
.wiphy
, chandef
,
2334 info
->band
= chandef
->chan
->band
;
2336 /* process and remove the injection radiotap header */
2337 if (!ieee80211_parse_tx_radiotap(local
, skb
))
2340 ieee80211_xmit(sdata
, NULL
, skb
, 0);
2343 return NETDEV_TX_OK
;
2349 return NETDEV_TX_OK
; /* meaning, we dealt with the skb */
2352 static inline bool ieee80211_is_tdls_setup(struct sk_buff
*skb
)
2354 u16 ethertype
= (skb
->data
[12] << 8) | skb
->data
[13];
2356 return ethertype
== ETH_P_TDLS
&&
2358 skb
->data
[14] == WLAN_TDLS_SNAP_RFTYPE
;
2361 static int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data
*sdata
,
2362 struct sk_buff
*skb
,
2363 struct sta_info
**sta_out
)
2365 struct sta_info
*sta
;
2367 switch (sdata
->vif
.type
) {
2368 case NL80211_IFTYPE_AP_VLAN
:
2369 sta
= rcu_dereference(sdata
->u
.vlan
.sta
);
2373 } else if (sdata
->wdev
.use_4addr
) {
2377 case NL80211_IFTYPE_AP
:
2378 case NL80211_IFTYPE_OCB
:
2379 case NL80211_IFTYPE_ADHOC
:
2380 if (is_multicast_ether_addr(skb
->data
)) {
2381 *sta_out
= ERR_PTR(-ENOENT
);
2384 sta
= sta_info_get_bss(sdata
, skb
->data
);
2386 case NL80211_IFTYPE_WDS
:
2387 sta
= sta_info_get(sdata
, sdata
->u
.wds
.remote_addr
);
2389 #ifdef CONFIG_MAC80211_MESH
2390 case NL80211_IFTYPE_MESH_POINT
:
2391 /* determined much later */
2395 case NL80211_IFTYPE_STATION
:
2396 if (sdata
->wdev
.wiphy
->flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
2397 sta
= sta_info_get(sdata
, skb
->data
);
2398 if (sta
&& test_sta_flag(sta
, WLAN_STA_TDLS_PEER
)) {
2399 if (test_sta_flag(sta
,
2400 WLAN_STA_TDLS_PEER_AUTH
)) {
2406 * TDLS link during setup - throw out frames to
2407 * peer. Allow TDLS-setup frames to unauthorized
2408 * peers for the special case of a link teardown
2409 * after a TDLS sta is removed due to being
2412 if (!ieee80211_is_tdls_setup(skb
))
2418 sta
= sta_info_get(sdata
, sdata
->u
.mgd
.bssid
);
2426 *sta_out
= sta
?: ERR_PTR(-ENOENT
);
2431 * ieee80211_build_hdr - build 802.11 header in the given frame
2432 * @sdata: virtual interface to build the header for
2433 * @skb: the skb to build the header in
2434 * @info_flags: skb flags to set
2436 * This function takes the skb with 802.3 header and reformats the header to
2437 * the appropriate IEEE 802.11 header based on which interface the packet is
2438 * being transmitted on.
2440 * Note that this function also takes care of the TX status request and
2441 * potential unsharing of the SKB - this needs to be interleaved with the
2444 * The function requires the read-side RCU lock held
2446 * Returns: the (possibly reallocated) skb or an ERR_PTR() code
2448 static struct sk_buff
*ieee80211_build_hdr(struct ieee80211_sub_if_data
*sdata
,
2449 struct sk_buff
*skb
, u32 info_flags
,
2450 struct sta_info
*sta
)
2452 struct ieee80211_local
*local
= sdata
->local
;
2453 struct ieee80211_tx_info
*info
;
2455 u16 ethertype
, hdrlen
, meshhdrlen
= 0;
2457 struct ieee80211_hdr hdr
;
2458 struct ieee80211s_hdr mesh_hdr __maybe_unused
;
2459 struct mesh_path __maybe_unused
*mppath
= NULL
, *mpath
= NULL
;
2460 const u8
*encaps_data
;
2461 int encaps_len
, skip_header_bytes
;
2462 bool wme_sta
= false, authorized
= false;
2466 struct ieee80211_chanctx_conf
*chanctx_conf
;
2467 struct ieee80211_sub_if_data
*ap_sdata
;
2468 enum nl80211_band band
;
2474 /* convert Ethernet header to proper 802.11 header (based on
2475 * operation mode) */
2476 ethertype
= (skb
->data
[12] << 8) | skb
->data
[13];
2477 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_DATA
);
2479 switch (sdata
->vif
.type
) {
2480 case NL80211_IFTYPE_AP_VLAN
:
2481 if (sdata
->wdev
.use_4addr
) {
2482 fc
|= cpu_to_le16(IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
);
2484 memcpy(hdr
.addr1
, sta
->sta
.addr
, ETH_ALEN
);
2485 memcpy(hdr
.addr2
, sdata
->vif
.addr
, ETH_ALEN
);
2486 memcpy(hdr
.addr3
, skb
->data
, ETH_ALEN
);
2487 memcpy(hdr
.addr4
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
2489 authorized
= test_sta_flag(sta
, WLAN_STA_AUTHORIZED
);
2490 wme_sta
= sta
->sta
.wme
;
2492 ap_sdata
= container_of(sdata
->bss
, struct ieee80211_sub_if_data
,
2494 chanctx_conf
= rcu_dereference(ap_sdata
->vif
.chanctx_conf
);
2495 if (!chanctx_conf
) {
2499 band
= chanctx_conf
->def
.chan
->band
;
2500 if (sdata
->wdev
.use_4addr
)
2503 case NL80211_IFTYPE_AP
:
2504 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
)
2505 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
2506 if (!chanctx_conf
) {
2510 fc
|= cpu_to_le16(IEEE80211_FCTL_FROMDS
);
2512 memcpy(hdr
.addr1
, skb
->data
, ETH_ALEN
);
2513 memcpy(hdr
.addr2
, sdata
->vif
.addr
, ETH_ALEN
);
2514 memcpy(hdr
.addr3
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
2516 band
= chanctx_conf
->def
.chan
->band
;
2518 case NL80211_IFTYPE_WDS
:
2519 fc
|= cpu_to_le16(IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
);
2521 memcpy(hdr
.addr1
, sdata
->u
.wds
.remote_addr
, ETH_ALEN
);
2522 memcpy(hdr
.addr2
, sdata
->vif
.addr
, ETH_ALEN
);
2523 memcpy(hdr
.addr3
, skb
->data
, ETH_ALEN
);
2524 memcpy(hdr
.addr4
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
2527 * This is the exception! WDS style interfaces are prohibited
2528 * when channel contexts are in used so this must be valid
2530 band
= local
->hw
.conf
.chandef
.chan
->band
;
2532 #ifdef CONFIG_MAC80211_MESH
2533 case NL80211_IFTYPE_MESH_POINT
:
2534 if (!is_multicast_ether_addr(skb
->data
)) {
2535 struct sta_info
*next_hop
;
2536 bool mpp_lookup
= true;
2538 mpath
= mesh_path_lookup(sdata
, skb
->data
);
2541 next_hop
= rcu_dereference(mpath
->next_hop
);
2543 !(mpath
->flags
& (MESH_PATH_ACTIVE
|
2544 MESH_PATH_RESOLVING
)))
2549 mppath
= mpp_path_lookup(sdata
, skb
->data
);
2551 mppath
->exp_time
= jiffies
;
2554 if (mppath
&& mpath
)
2555 mesh_path_del(sdata
, mpath
->dst
);
2559 * Use address extension if it is a packet from
2560 * another interface or if we know the destination
2561 * is being proxied by a portal (i.e. portal address
2562 * differs from proxied address)
2564 if (ether_addr_equal(sdata
->vif
.addr
, skb
->data
+ ETH_ALEN
) &&
2565 !(mppath
&& !ether_addr_equal(mppath
->mpp
, skb
->data
))) {
2566 hdrlen
= ieee80211_fill_mesh_addresses(&hdr
, &fc
,
2567 skb
->data
, skb
->data
+ ETH_ALEN
);
2568 meshhdrlen
= ieee80211_new_mesh_header(sdata
, &mesh_hdr
,
2571 /* DS -> MBSS (802.11-2012 13.11.3.3).
2572 * For unicast with unknown forwarding information,
2573 * destination might be in the MBSS or if that fails
2574 * forwarded to another mesh gate. In either case
2575 * resolution will be handled in ieee80211_xmit(), so
2576 * leave the original DA. This also works for mcast */
2577 const u8
*mesh_da
= skb
->data
;
2580 mesh_da
= mppath
->mpp
;
2582 mesh_da
= mpath
->dst
;
2584 hdrlen
= ieee80211_fill_mesh_addresses(&hdr
, &fc
,
2585 mesh_da
, sdata
->vif
.addr
);
2586 if (is_multicast_ether_addr(mesh_da
))
2587 /* DA TA mSA AE:SA */
2588 meshhdrlen
= ieee80211_new_mesh_header(
2590 skb
->data
+ ETH_ALEN
, NULL
);
2592 /* RA TA mDA mSA AE:DA SA */
2593 meshhdrlen
= ieee80211_new_mesh_header(
2594 sdata
, &mesh_hdr
, skb
->data
,
2595 skb
->data
+ ETH_ALEN
);
2598 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
2599 if (!chanctx_conf
) {
2603 band
= chanctx_conf
->def
.chan
->band
;
2606 case NL80211_IFTYPE_STATION
:
2607 /* we already did checks when looking up the RA STA */
2608 tdls_peer
= test_sta_flag(sta
, WLAN_STA_TDLS_PEER
);
2612 memcpy(hdr
.addr1
, skb
->data
, ETH_ALEN
);
2613 memcpy(hdr
.addr2
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
2614 memcpy(hdr
.addr3
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
2616 } else if (sdata
->u
.mgd
.use_4addr
&&
2617 cpu_to_be16(ethertype
) != sdata
->control_port_protocol
) {
2618 fc
|= cpu_to_le16(IEEE80211_FCTL_FROMDS
|
2619 IEEE80211_FCTL_TODS
);
2621 memcpy(hdr
.addr1
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
2622 memcpy(hdr
.addr2
, sdata
->vif
.addr
, ETH_ALEN
);
2623 memcpy(hdr
.addr3
, skb
->data
, ETH_ALEN
);
2624 memcpy(hdr
.addr4
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
2627 fc
|= cpu_to_le16(IEEE80211_FCTL_TODS
);
2629 memcpy(hdr
.addr1
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
2630 memcpy(hdr
.addr2
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
2631 memcpy(hdr
.addr3
, skb
->data
, ETH_ALEN
);
2634 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
2635 if (!chanctx_conf
) {
2639 band
= chanctx_conf
->def
.chan
->band
;
2641 case NL80211_IFTYPE_OCB
:
2643 memcpy(hdr
.addr1
, skb
->data
, ETH_ALEN
);
2644 memcpy(hdr
.addr2
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
2645 eth_broadcast_addr(hdr
.addr3
);
2647 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
2648 if (!chanctx_conf
) {
2652 band
= chanctx_conf
->def
.chan
->band
;
2654 case NL80211_IFTYPE_ADHOC
:
2656 memcpy(hdr
.addr1
, skb
->data
, ETH_ALEN
);
2657 memcpy(hdr
.addr2
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
2658 memcpy(hdr
.addr3
, sdata
->u
.ibss
.bssid
, ETH_ALEN
);
2660 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
2661 if (!chanctx_conf
) {
2665 band
= chanctx_conf
->def
.chan
->band
;
2672 multicast
= is_multicast_ether_addr(hdr
.addr1
);
2674 /* sta is always NULL for mesh */
2676 authorized
= test_sta_flag(sta
, WLAN_STA_AUTHORIZED
);
2677 wme_sta
= sta
->sta
.wme
;
2678 } else if (ieee80211_vif_is_mesh(&sdata
->vif
)) {
2679 /* For mesh, the use of the QoS header is mandatory */
2683 /* receiver does QoS (which also means we do) use it */
2685 fc
|= cpu_to_le16(IEEE80211_STYPE_QOS_DATA
);
2690 * Drop unicast frames to unauthorised stations unless they are
2691 * EAPOL frames from the local station.
2693 if (unlikely(!ieee80211_vif_is_mesh(&sdata
->vif
) &&
2694 (sdata
->vif
.type
!= NL80211_IFTYPE_OCB
) &&
2695 !multicast
&& !authorized
&&
2696 (cpu_to_be16(ethertype
) != sdata
->control_port_protocol
||
2697 !ether_addr_equal(sdata
->vif
.addr
, skb
->data
+ ETH_ALEN
)))) {
2698 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2699 net_info_ratelimited("%s: dropped frame to %pM (unauthorized port)\n",
2700 sdata
->name
, hdr
.addr1
);
2703 I802_DEBUG_INC(local
->tx_handlers_drop_unauth_port
);
2709 if (unlikely(!multicast
&& skb
->sk
&&
2710 skb_shinfo(skb
)->tx_flags
& SKBTX_WIFI_STATUS
)) {
2711 struct sk_buff
*ack_skb
= skb_clone_sk(skb
);
2714 unsigned long flags
;
2717 spin_lock_irqsave(&local
->ack_status_lock
, flags
);
2718 id
= idr_alloc(&local
->ack_status_frames
, ack_skb
,
2719 1, 0x10000, GFP_ATOMIC
);
2720 spin_unlock_irqrestore(&local
->ack_status_lock
, flags
);
2724 info_flags
|= IEEE80211_TX_CTL_REQ_TX_STATUS
;
2732 * If the skb is shared we need to obtain our own copy.
2734 if (skb_shared(skb
)) {
2735 struct sk_buff
*tmp_skb
= skb
;
2737 /* can't happen -- skb is a clone if info_id != 0 */
2740 skb
= skb_clone(skb
, GFP_ATOMIC
);
2749 hdr
.frame_control
= fc
;
2750 hdr
.duration_id
= 0;
2753 skip_header_bytes
= ETH_HLEN
;
2754 if (ethertype
== ETH_P_AARP
|| ethertype
== ETH_P_IPX
) {
2755 encaps_data
= bridge_tunnel_header
;
2756 encaps_len
= sizeof(bridge_tunnel_header
);
2757 skip_header_bytes
-= 2;
2758 } else if (ethertype
>= ETH_P_802_3_MIN
) {
2759 encaps_data
= rfc1042_header
;
2760 encaps_len
= sizeof(rfc1042_header
);
2761 skip_header_bytes
-= 2;
2767 skb_pull(skb
, skip_header_bytes
);
2768 head_need
= hdrlen
+ encaps_len
+ meshhdrlen
- skb_headroom(skb
);
2771 * So we need to modify the skb header and hence need a copy of
2772 * that. The head_need variable above doesn't, so far, include
2773 * the needed header space that we don't need right away. If we
2774 * can, then we don't reallocate right now but only after the
2775 * frame arrives at the master device (if it does...)
2777 * If we cannot, however, then we will reallocate to include all
2778 * the ever needed space. Also, if we need to reallocate it anyway,
2779 * make it big enough for everything we may ever need.
2782 if (head_need
> 0 || skb_cloned(skb
)) {
2783 head_need
+= sdata
->encrypt_headroom
;
2784 head_need
+= local
->tx_headroom
;
2785 head_need
= max_t(int, 0, head_need
);
2786 if (ieee80211_skb_resize(sdata
, skb
, head_need
, true)) {
2787 ieee80211_free_txskb(&local
->hw
, skb
);
2789 return ERR_PTR(-ENOMEM
);
2794 memcpy(skb_push(skb
, encaps_len
), encaps_data
, encaps_len
);
2796 #ifdef CONFIG_MAC80211_MESH
2798 memcpy(skb_push(skb
, meshhdrlen
), &mesh_hdr
, meshhdrlen
);
2801 if (ieee80211_is_data_qos(fc
)) {
2802 __le16
*qos_control
;
2804 qos_control
= skb_push(skb
, 2);
2805 memcpy(skb_push(skb
, hdrlen
- 2), &hdr
, hdrlen
- 2);
2807 * Maybe we could actually set some fields here, for now just
2808 * initialise to zero to indicate no special operation.
2812 memcpy(skb_push(skb
, hdrlen
), &hdr
, hdrlen
);
2814 skb_reset_mac_header(skb
);
2816 info
= IEEE80211_SKB_CB(skb
);
2817 memset(info
, 0, sizeof(*info
));
2819 info
->flags
= info_flags
;
2820 info
->ack_frame_id
= info_id
;
2826 return ERR_PTR(ret
);
2830 * fast-xmit overview
2832 * The core idea of this fast-xmit is to remove per-packet checks by checking
2833 * them out of band. ieee80211_check_fast_xmit() implements the out-of-band
2834 * checks that are needed to get the sta->fast_tx pointer assigned, after which
2835 * much less work can be done per packet. For example, fragmentation must be
2836 * disabled or the fast_tx pointer will not be set. All the conditions are seen
2839 * Once assigned, the fast_tx data structure also caches the per-packet 802.11
2840 * header and other data to aid packet processing in ieee80211_xmit_fast().
2842 * The most difficult part of this is that when any of these assumptions
2843 * change, an external trigger (i.e. a call to ieee80211_clear_fast_xmit(),
2844 * ieee80211_check_fast_xmit() or friends) is required to reset the data,
2845 * since the per-packet code no longer checks the conditions. This is reflected
2846 * by the calls to these functions throughout the rest of the code, and must be
2847 * maintained if any of the TX path checks change.
2850 void ieee80211_check_fast_xmit(struct sta_info
*sta
)
2852 struct ieee80211_fast_tx build
= {}, *fast_tx
= NULL
, *old
;
2853 struct ieee80211_local
*local
= sta
->local
;
2854 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
2855 struct ieee80211_hdr
*hdr
= (void *)build
.hdr
;
2856 struct ieee80211_chanctx_conf
*chanctx_conf
;
2859 if (!ieee80211_hw_check(&local
->hw
, SUPPORT_FAST_XMIT
))
2862 /* Locking here protects both the pointer itself, and against concurrent
2863 * invocations winning data access races to, e.g., the key pointer that
2865 * Without it, the invocation of this function right after the key
2866 * pointer changes wouldn't be sufficient, as another CPU could access
2867 * the pointer, then stall, and then do the cache update after the CPU
2868 * that invalidated the key.
2869 * With the locking, such scenarios cannot happen as the check for the
2870 * key and the fast-tx assignment are done atomically, so the CPU that
2871 * modifies the key will either wait or other one will see the key
2872 * cleared/changed already.
2874 spin_lock_bh(&sta
->lock
);
2875 if (ieee80211_hw_check(&local
->hw
, SUPPORTS_PS
) &&
2876 !ieee80211_hw_check(&local
->hw
, SUPPORTS_DYNAMIC_PS
) &&
2877 sdata
->vif
.type
== NL80211_IFTYPE_STATION
)
2880 if (!test_sta_flag(sta
, WLAN_STA_AUTHORIZED
))
2883 if (test_sta_flag(sta
, WLAN_STA_PS_STA
) ||
2884 test_sta_flag(sta
, WLAN_STA_PS_DRIVER
) ||
2885 test_sta_flag(sta
, WLAN_STA_PS_DELIVER
) ||
2886 test_sta_flag(sta
, WLAN_STA_CLEAR_PS_FILT
))
2889 if (sdata
->noack_map
)
2892 /* fast-xmit doesn't handle fragmentation at all */
2893 if (local
->hw
.wiphy
->frag_threshold
!= (u32
)-1 &&
2894 !ieee80211_hw_check(&local
->hw
, SUPPORTS_TX_FRAG
))
2898 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
2899 if (!chanctx_conf
) {
2903 build
.band
= chanctx_conf
->def
.chan
->band
;
2906 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_DATA
);
2908 switch (sdata
->vif
.type
) {
2909 case NL80211_IFTYPE_ADHOC
:
2911 build
.da_offs
= offsetof(struct ieee80211_hdr
, addr1
);
2912 build
.sa_offs
= offsetof(struct ieee80211_hdr
, addr2
);
2913 memcpy(hdr
->addr3
, sdata
->u
.ibss
.bssid
, ETH_ALEN
);
2916 case NL80211_IFTYPE_STATION
:
2917 if (test_sta_flag(sta
, WLAN_STA_TDLS_PEER
)) {
2919 build
.da_offs
= offsetof(struct ieee80211_hdr
, addr1
);
2920 build
.sa_offs
= offsetof(struct ieee80211_hdr
, addr2
);
2921 memcpy(hdr
->addr3
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
2926 if (sdata
->u
.mgd
.use_4addr
) {
2927 /* non-regular ethertype cannot use the fastpath */
2928 fc
|= cpu_to_le16(IEEE80211_FCTL_FROMDS
|
2929 IEEE80211_FCTL_TODS
);
2931 memcpy(hdr
->addr1
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
2932 memcpy(hdr
->addr2
, sdata
->vif
.addr
, ETH_ALEN
);
2933 build
.da_offs
= offsetof(struct ieee80211_hdr
, addr3
);
2934 build
.sa_offs
= offsetof(struct ieee80211_hdr
, addr4
);
2938 fc
|= cpu_to_le16(IEEE80211_FCTL_TODS
);
2940 memcpy(hdr
->addr1
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
2941 build
.da_offs
= offsetof(struct ieee80211_hdr
, addr3
);
2942 build
.sa_offs
= offsetof(struct ieee80211_hdr
, addr2
);
2945 case NL80211_IFTYPE_AP_VLAN
:
2946 if (sdata
->wdev
.use_4addr
) {
2947 fc
|= cpu_to_le16(IEEE80211_FCTL_FROMDS
|
2948 IEEE80211_FCTL_TODS
);
2950 memcpy(hdr
->addr1
, sta
->sta
.addr
, ETH_ALEN
);
2951 memcpy(hdr
->addr2
, sdata
->vif
.addr
, ETH_ALEN
);
2952 build
.da_offs
= offsetof(struct ieee80211_hdr
, addr3
);
2953 build
.sa_offs
= offsetof(struct ieee80211_hdr
, addr4
);
2958 case NL80211_IFTYPE_AP
:
2959 fc
|= cpu_to_le16(IEEE80211_FCTL_FROMDS
);
2961 build
.da_offs
= offsetof(struct ieee80211_hdr
, addr1
);
2962 memcpy(hdr
->addr2
, sdata
->vif
.addr
, ETH_ALEN
);
2963 build
.sa_offs
= offsetof(struct ieee80211_hdr
, addr3
);
2967 /* not handled on fast-xmit */
2973 fc
|= cpu_to_le16(IEEE80211_STYPE_QOS_DATA
);
2976 /* We store the key here so there's no point in using rcu_dereference()
2977 * but that's fine because the code that changes the pointers will call
2978 * this function after doing so. For a single CPU that would be enough,
2979 * for multiple see the comment above.
2981 build
.key
= rcu_access_pointer(sta
->ptk
[sta
->ptk_idx
]);
2983 build
.key
= rcu_access_pointer(sdata
->default_unicast_key
);
2985 bool gen_iv
, iv_spc
, mmic
;
2987 gen_iv
= build
.key
->conf
.flags
& IEEE80211_KEY_FLAG_GENERATE_IV
;
2988 iv_spc
= build
.key
->conf
.flags
& IEEE80211_KEY_FLAG_PUT_IV_SPACE
;
2989 mmic
= build
.key
->conf
.flags
&
2990 (IEEE80211_KEY_FLAG_GENERATE_MMIC
|
2991 IEEE80211_KEY_FLAG_PUT_MIC_SPACE
);
2993 /* don't handle software crypto */
2994 if (!(build
.key
->flags
& KEY_FLAG_UPLOADED_TO_HARDWARE
))
2997 /* Key is being removed */
2998 if (build
.key
->flags
& KEY_FLAG_TAINTED
)
3001 switch (build
.key
->conf
.cipher
) {
3002 case WLAN_CIPHER_SUITE_CCMP
:
3003 case WLAN_CIPHER_SUITE_CCMP_256
:
3005 build
.pn_offs
= build
.hdr_len
;
3006 if (gen_iv
|| iv_spc
)
3007 build
.hdr_len
+= IEEE80211_CCMP_HDR_LEN
;
3009 case WLAN_CIPHER_SUITE_GCMP
:
3010 case WLAN_CIPHER_SUITE_GCMP_256
:
3012 build
.pn_offs
= build
.hdr_len
;
3013 if (gen_iv
|| iv_spc
)
3014 build
.hdr_len
+= IEEE80211_GCMP_HDR_LEN
;
3016 case WLAN_CIPHER_SUITE_TKIP
:
3017 /* cannot handle MMIC or IV generation in xmit-fast */
3021 build
.hdr_len
+= IEEE80211_TKIP_IV_LEN
;
3023 case WLAN_CIPHER_SUITE_WEP40
:
3024 case WLAN_CIPHER_SUITE_WEP104
:
3025 /* cannot handle IV generation in fast-xmit */
3029 build
.hdr_len
+= IEEE80211_WEP_IV_LEN
;
3031 case WLAN_CIPHER_SUITE_AES_CMAC
:
3032 case WLAN_CIPHER_SUITE_BIP_CMAC_256
:
3033 case WLAN_CIPHER_SUITE_BIP_GMAC_128
:
3034 case WLAN_CIPHER_SUITE_BIP_GMAC_256
:
3036 "management cipher suite 0x%x enabled for data\n",
3037 build
.key
->conf
.cipher
);
3040 /* we don't know how to generate IVs for this at all */
3041 if (WARN_ON(gen_iv
))
3043 /* pure hardware keys are OK, of course */
3044 if (!(build
.key
->flags
& KEY_FLAG_CIPHER_SCHEME
))
3046 /* cipher scheme might require space allocation */
3048 build
.key
->conf
.iv_len
> IEEE80211_FAST_XMIT_MAX_IV
)
3051 build
.hdr_len
+= build
.key
->conf
.iv_len
;
3054 fc
|= cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
3057 hdr
->frame_control
= fc
;
3059 memcpy(build
.hdr
+ build
.hdr_len
,
3060 rfc1042_header
, sizeof(rfc1042_header
));
3061 build
.hdr_len
+= sizeof(rfc1042_header
);
3063 fast_tx
= kmemdup(&build
, sizeof(build
), GFP_ATOMIC
);
3064 /* if the kmemdup fails, continue w/o fast_tx */
3069 /* we might have raced against another call to this function */
3070 old
= rcu_dereference_protected(sta
->fast_tx
,
3071 lockdep_is_held(&sta
->lock
));
3072 rcu_assign_pointer(sta
->fast_tx
, fast_tx
);
3074 kfree_rcu(old
, rcu_head
);
3075 spin_unlock_bh(&sta
->lock
);
3078 void ieee80211_check_fast_xmit_all(struct ieee80211_local
*local
)
3080 struct sta_info
*sta
;
3083 list_for_each_entry_rcu(sta
, &local
->sta_list
, list
)
3084 ieee80211_check_fast_xmit(sta
);
3088 void ieee80211_check_fast_xmit_iface(struct ieee80211_sub_if_data
*sdata
)
3090 struct ieee80211_local
*local
= sdata
->local
;
3091 struct sta_info
*sta
;
3095 list_for_each_entry_rcu(sta
, &local
->sta_list
, list
) {
3096 if (sdata
!= sta
->sdata
&&
3097 (!sta
->sdata
->bss
|| sta
->sdata
->bss
!= sdata
->bss
))
3099 ieee80211_check_fast_xmit(sta
);
3105 void ieee80211_clear_fast_xmit(struct sta_info
*sta
)
3107 struct ieee80211_fast_tx
*fast_tx
;
3109 spin_lock_bh(&sta
->lock
);
3110 fast_tx
= rcu_dereference_protected(sta
->fast_tx
,
3111 lockdep_is_held(&sta
->lock
));
3112 RCU_INIT_POINTER(sta
->fast_tx
, NULL
);
3113 spin_unlock_bh(&sta
->lock
);
3116 kfree_rcu(fast_tx
, rcu_head
);
3119 static bool ieee80211_amsdu_realloc_pad(struct ieee80211_local
*local
,
3120 struct sk_buff
*skb
, int headroom
)
3122 if (skb_headroom(skb
) < headroom
) {
3123 I802_DEBUG_INC(local
->tx_expand_skb_head
);
3125 if (pskb_expand_head(skb
, headroom
, 0, GFP_ATOMIC
)) {
3126 wiphy_debug(local
->hw
.wiphy
,
3127 "failed to reallocate TX buffer\n");
3135 static bool ieee80211_amsdu_prepare_head(struct ieee80211_sub_if_data
*sdata
,
3136 struct ieee80211_fast_tx
*fast_tx
,
3137 struct sk_buff
*skb
)
3139 struct ieee80211_local
*local
= sdata
->local
;
3140 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
3141 struct ieee80211_hdr
*hdr
;
3142 struct ethhdr
*amsdu_hdr
;
3143 int hdr_len
= fast_tx
->hdr_len
- sizeof(rfc1042_header
);
3144 int subframe_len
= skb
->len
- hdr_len
;
3146 u8
*qc
, *h_80211_src
, *h_80211_dst
;
3149 if (info
->flags
& IEEE80211_TX_CTL_RATE_CTRL_PROBE
)
3152 if (info
->control
.flags
& IEEE80211_TX_CTRL_AMSDU
)
3155 if (!ieee80211_amsdu_realloc_pad(local
, skb
, sizeof(*amsdu_hdr
)))
3158 data
= skb_push(skb
, sizeof(*amsdu_hdr
));
3159 memmove(data
, data
+ sizeof(*amsdu_hdr
), hdr_len
);
3161 amsdu_hdr
= data
+ hdr_len
;
3162 /* h_80211_src/dst is addr* field within hdr */
3163 h_80211_src
= data
+ fast_tx
->sa_offs
;
3164 h_80211_dst
= data
+ fast_tx
->da_offs
;
3166 amsdu_hdr
->h_proto
= cpu_to_be16(subframe_len
);
3167 ether_addr_copy(amsdu_hdr
->h_source
, h_80211_src
);
3168 ether_addr_copy(amsdu_hdr
->h_dest
, h_80211_dst
);
3170 /* according to IEEE 802.11-2012 8.3.2 table 8-19, the outer SA/DA
3171 * fields needs to be changed to BSSID for A-MSDU frames depending
3172 * on FromDS/ToDS values.
3174 switch (sdata
->vif
.type
) {
3175 case NL80211_IFTYPE_STATION
:
3176 bssid
= sdata
->u
.mgd
.bssid
;
3178 case NL80211_IFTYPE_AP
:
3179 case NL80211_IFTYPE_AP_VLAN
:
3180 bssid
= sdata
->vif
.addr
;
3186 if (bssid
&& ieee80211_has_fromds(hdr
->frame_control
))
3187 ether_addr_copy(h_80211_src
, bssid
);
3189 if (bssid
&& ieee80211_has_tods(hdr
->frame_control
))
3190 ether_addr_copy(h_80211_dst
, bssid
);
3192 qc
= ieee80211_get_qos_ctl(hdr
);
3193 *qc
|= IEEE80211_QOS_CTL_A_MSDU_PRESENT
;
3195 info
->control
.flags
|= IEEE80211_TX_CTRL_AMSDU
;
3200 static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data
*sdata
,
3201 struct sta_info
*sta
,
3202 struct ieee80211_fast_tx
*fast_tx
,
3203 struct sk_buff
*skb
)
3205 struct ieee80211_local
*local
= sdata
->local
;
3206 struct fq
*fq
= &local
->fq
;
3208 struct fq_flow
*flow
;
3209 u8 tid
= skb
->priority
& IEEE80211_QOS_CTL_TAG1D_MASK
;
3210 struct ieee80211_txq
*txq
= sta
->sta
.txq
[tid
];
3211 struct txq_info
*txqi
;
3212 struct sk_buff
**frag_tail
, *head
;
3213 int subframe_len
= skb
->len
- ETH_ALEN
;
3214 u8 max_subframes
= sta
->sta
.max_amsdu_subframes
;
3215 int max_frags
= local
->hw
.max_tx_fragments
;
3216 int max_amsdu_len
= sta
->sta
.max_amsdu_len
;
3221 unsigned int orig_len
;
3222 int n
= 2, nfrags
, pad
= 0;
3225 if (!ieee80211_hw_check(&local
->hw
, TX_AMSDU
))
3228 if (skb_is_gso(skb
))
3234 txqi
= to_txq_info(txq
);
3235 if (test_bit(IEEE80211_TXQ_NO_AMSDU
, &txqi
->flags
))
3238 if (sta
->sta
.max_rc_amsdu_len
)
3239 max_amsdu_len
= min_t(int, max_amsdu_len
,
3240 sta
->sta
.max_rc_amsdu_len
);
3242 if (sta
->sta
.max_tid_amsdu_len
[tid
])
3243 max_amsdu_len
= min_t(int, max_amsdu_len
,
3244 sta
->sta
.max_tid_amsdu_len
[tid
]);
3246 flow_idx
= fq_flow_idx(fq
, skb
);
3248 spin_lock_bh(&fq
->lock
);
3250 /* TODO: Ideally aggregation should be done on dequeue to remain
3251 * responsive to environment changes.
3255 flow
= fq_flow_classify(fq
, tin
, flow_idx
, skb
,
3256 fq_flow_get_default_func
);
3257 head
= skb_peek_tail(&flow
->queue
);
3258 if (!head
|| skb_is_gso(head
))
3261 orig_len
= head
->len
;
3263 if (skb
->len
+ head
->len
> max_amsdu_len
)
3266 nfrags
= 1 + skb_shinfo(skb
)->nr_frags
;
3267 nfrags
+= 1 + skb_shinfo(head
)->nr_frags
;
3268 frag_tail
= &skb_shinfo(head
)->frag_list
;
3269 while (*frag_tail
) {
3270 nfrags
+= 1 + skb_shinfo(*frag_tail
)->nr_frags
;
3271 frag_tail
= &(*frag_tail
)->next
;
3275 if (max_subframes
&& n
> max_subframes
)
3278 if (max_frags
&& nfrags
> max_frags
)
3281 if (!drv_can_aggregate_in_amsdu(local
, head
, skb
))
3284 if (!ieee80211_amsdu_prepare_head(sdata
, fast_tx
, head
))
3288 * Pad out the previous subframe to a multiple of 4 by adding the
3289 * padding to the next one, that's being added. Note that head->len
3290 * is the length of the full A-MSDU, but that works since each time
3291 * we add a new subframe we pad out the previous one to a multiple
3292 * of 4 and thus it no longer matters in the next round.
3294 hdrlen
= fast_tx
->hdr_len
- sizeof(rfc1042_header
);
3295 if ((head
->len
- hdrlen
) & 3)
3296 pad
= 4 - ((head
->len
- hdrlen
) & 3);
3298 if (!ieee80211_amsdu_realloc_pad(local
, skb
, sizeof(rfc1042_header
) +
3303 data
= skb_push(skb
, ETH_ALEN
+ 2);
3304 memmove(data
, data
+ ETH_ALEN
+ 2, 2 * ETH_ALEN
);
3306 data
+= 2 * ETH_ALEN
;
3307 len
= cpu_to_be16(subframe_len
);
3308 memcpy(data
, &len
, 2);
3309 memcpy(data
+ 2, rfc1042_header
, sizeof(rfc1042_header
));
3311 memset(skb_push(skb
, pad
), 0, pad
);
3313 head
->len
+= skb
->len
;
3314 head
->data_len
+= skb
->len
;
3318 if (head
->len
!= orig_len
) {
3319 flow
->backlog
+= head
->len
- orig_len
;
3320 tin
->backlog_bytes
+= head
->len
- orig_len
;
3322 fq_recalc_backlog(fq
, tin
, flow
);
3325 spin_unlock_bh(&fq
->lock
);
3331 * Can be called while the sta lock is held. Anything that can cause packets to
3332 * be generated will cause deadlock!
3334 static void ieee80211_xmit_fast_finish(struct ieee80211_sub_if_data
*sdata
,
3335 struct sta_info
*sta
, u8 pn_offs
,
3336 struct ieee80211_key
*key
,
3337 struct sk_buff
*skb
)
3339 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
3340 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
3341 u8 tid
= IEEE80211_NUM_TIDS
;
3344 info
->control
.hw_key
= &key
->conf
;
3346 ieee80211_tx_stats(skb
->dev
, skb
->len
);
3348 if (hdr
->frame_control
& cpu_to_le16(IEEE80211_STYPE_QOS_DATA
)) {
3349 tid
= skb
->priority
& IEEE80211_QOS_CTL_TAG1D_MASK
;
3350 hdr
->seq_ctrl
= ieee80211_tx_next_seq(sta
, tid
);
3352 info
->flags
|= IEEE80211_TX_CTL_ASSIGN_SEQ
;
3353 hdr
->seq_ctrl
= cpu_to_le16(sdata
->sequence_number
);
3354 sdata
->sequence_number
+= 0x10;
3357 if (skb_shinfo(skb
)->gso_size
)
3358 sta
->tx_stats
.msdu
[tid
] +=
3359 DIV_ROUND_UP(skb
->len
, skb_shinfo(skb
)->gso_size
);
3361 sta
->tx_stats
.msdu
[tid
]++;
3363 info
->hw_queue
= sdata
->vif
.hw_queue
[skb_get_queue_mapping(skb
)];
3365 /* statistics normally done by ieee80211_tx_h_stats (but that
3366 * has to consider fragmentation, so is more complex)
3368 sta
->tx_stats
.bytes
[skb_get_queue_mapping(skb
)] += skb
->len
;
3369 sta
->tx_stats
.packets
[skb_get_queue_mapping(skb
)]++;
3373 u8
*crypto_hdr
= skb
->data
+ pn_offs
;
3375 switch (key
->conf
.cipher
) {
3376 case WLAN_CIPHER_SUITE_CCMP
:
3377 case WLAN_CIPHER_SUITE_CCMP_256
:
3378 case WLAN_CIPHER_SUITE_GCMP
:
3379 case WLAN_CIPHER_SUITE_GCMP_256
:
3380 pn
= atomic64_inc_return(&key
->conf
.tx_pn
);
3382 crypto_hdr
[1] = pn
>> 8;
3383 crypto_hdr
[3] = 0x20 | (key
->conf
.keyidx
<< 6);
3384 crypto_hdr
[4] = pn
>> 16;
3385 crypto_hdr
[5] = pn
>> 24;
3386 crypto_hdr
[6] = pn
>> 32;
3387 crypto_hdr
[7] = pn
>> 40;
3393 static bool ieee80211_xmit_fast(struct ieee80211_sub_if_data
*sdata
,
3394 struct sta_info
*sta
,
3395 struct ieee80211_fast_tx
*fast_tx
,
3396 struct sk_buff
*skb
)
3398 struct ieee80211_local
*local
= sdata
->local
;
3399 u16 ethertype
= (skb
->data
[12] << 8) | skb
->data
[13];
3400 int extra_head
= fast_tx
->hdr_len
- (ETH_HLEN
- 2);
3401 int hw_headroom
= sdata
->local
->hw
.extra_tx_headroom
;
3403 struct ieee80211_tx_info
*info
;
3404 struct ieee80211_hdr
*hdr
= (void *)fast_tx
->hdr
;
3405 struct ieee80211_tx_data tx
;
3406 ieee80211_tx_result r
;
3407 struct tid_ampdu_tx
*tid_tx
= NULL
;
3408 u8 tid
= IEEE80211_NUM_TIDS
;
3410 /* control port protocol needs a lot of special handling */
3411 if (cpu_to_be16(ethertype
) == sdata
->control_port_protocol
)
3414 /* only RFC 1042 SNAP */
3415 if (ethertype
< ETH_P_802_3_MIN
)
3418 /* don't handle TX status request here either */
3419 if (skb
->sk
&& skb_shinfo(skb
)->tx_flags
& SKBTX_WIFI_STATUS
)
3422 if (hdr
->frame_control
& cpu_to_le16(IEEE80211_STYPE_QOS_DATA
)) {
3423 tid
= skb
->priority
& IEEE80211_QOS_CTL_TAG1D_MASK
;
3424 tid_tx
= rcu_dereference(sta
->ampdu_mlme
.tid_tx
[tid
]);
3426 if (!test_bit(HT_AGG_STATE_OPERATIONAL
, &tid_tx
->state
))
3428 if (tid_tx
->timeout
)
3429 tid_tx
->last_tx
= jiffies
;
3433 /* after this point (skb is modified) we cannot return false */
3435 if (skb_shared(skb
)) {
3436 struct sk_buff
*tmp_skb
= skb
;
3438 skb
= skb_clone(skb
, GFP_ATOMIC
);
3445 if ((hdr
->frame_control
& cpu_to_le16(IEEE80211_STYPE_QOS_DATA
)) &&
3446 ieee80211_amsdu_aggregate(sdata
, sta
, fast_tx
, skb
))
3449 /* will not be crypto-handled beyond what we do here, so use false
3450 * as the may-encrypt argument for the resize to not account for
3451 * more room than we already have in 'extra_head'
3453 if (unlikely(ieee80211_skb_resize(sdata
, skb
,
3454 max_t(int, extra_head
+ hw_headroom
-
3455 skb_headroom(skb
), 0),
3461 memcpy(ð
, skb
->data
, ETH_HLEN
- 2);
3462 hdr
= skb_push(skb
, extra_head
);
3463 memcpy(skb
->data
, fast_tx
->hdr
, fast_tx
->hdr_len
);
3464 memcpy(skb
->data
+ fast_tx
->da_offs
, eth
.h_dest
, ETH_ALEN
);
3465 memcpy(skb
->data
+ fast_tx
->sa_offs
, eth
.h_source
, ETH_ALEN
);
3467 info
= IEEE80211_SKB_CB(skb
);
3468 memset(info
, 0, sizeof(*info
));
3469 info
->band
= fast_tx
->band
;
3470 info
->control
.vif
= &sdata
->vif
;
3471 info
->flags
= IEEE80211_TX_CTL_FIRST_FRAGMENT
|
3472 IEEE80211_TX_CTL_DONTFRAG
|
3473 (tid_tx
? IEEE80211_TX_CTL_AMPDU
: 0);
3474 info
->control
.flags
= IEEE80211_TX_CTRL_FAST_XMIT
;
3476 if (hdr
->frame_control
& cpu_to_le16(IEEE80211_STYPE_QOS_DATA
)) {
3477 tid
= skb
->priority
& IEEE80211_QOS_CTL_TAG1D_MASK
;
3478 *ieee80211_get_qos_ctl(hdr
) = tid
;
3481 __skb_queue_head_init(&tx
.skbs
);
3483 tx
.flags
= IEEE80211_TX_UNICAST
;
3487 tx
.key
= fast_tx
->key
;
3489 if (!ieee80211_hw_check(&local
->hw
, HAS_RATE_CONTROL
)) {
3491 r
= ieee80211_tx_h_rate_ctrl(&tx
);
3495 if (r
!= TX_CONTINUE
) {
3502 if (ieee80211_queue_skb(local
, sdata
, sta
, skb
))
3505 ieee80211_xmit_fast_finish(sdata
, sta
, fast_tx
->pn_offs
,
3508 if (sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
)
3509 sdata
= container_of(sdata
->bss
,
3510 struct ieee80211_sub_if_data
, u
.ap
);
3512 __skb_queue_tail(&tx
.skbs
, skb
);
3513 ieee80211_tx_frags(local
, &sdata
->vif
, &sta
->sta
, &tx
.skbs
, false);
3517 struct sk_buff
*ieee80211_tx_dequeue(struct ieee80211_hw
*hw
,
3518 struct ieee80211_txq
*txq
)
3520 struct ieee80211_local
*local
= hw_to_local(hw
);
3521 struct txq_info
*txqi
= container_of(txq
, struct txq_info
, txq
);
3522 struct ieee80211_hdr
*hdr
;
3523 struct sk_buff
*skb
= NULL
;
3524 struct fq
*fq
= &local
->fq
;
3525 struct fq_tin
*tin
= &txqi
->tin
;
3526 struct ieee80211_tx_info
*info
;
3527 struct ieee80211_tx_data tx
;
3528 ieee80211_tx_result r
;
3529 struct ieee80211_vif
*vif
= txq
->vif
;
3532 spin_lock_bh(&fq
->lock
);
3534 if (test_bit(IEEE80211_TXQ_STOP
, &txqi
->flags
) ||
3535 test_bit(IEEE80211_TXQ_STOP_NETIF_TX
, &txqi
->flags
))
3538 if (vif
->txqs_stopped
[ieee80211_ac_from_tid(txq
->tid
)]) {
3539 set_bit(IEEE80211_TXQ_STOP_NETIF_TX
, &txqi
->flags
);
3543 /* Make sure fragments stay together. */
3544 skb
= __skb_dequeue(&txqi
->frags
);
3548 skb
= fq_tin_dequeue(fq
, tin
, fq_tin_dequeue_func
);
3552 spin_unlock_bh(&fq
->lock
);
3554 hdr
= (struct ieee80211_hdr
*)skb
->data
;
3555 info
= IEEE80211_SKB_CB(skb
);
3557 memset(&tx
, 0, sizeof(tx
));
3558 __skb_queue_head_init(&tx
.skbs
);
3561 tx
.sdata
= vif_to_sdata(info
->control
.vif
);
3564 tx
.sta
= container_of(txq
->sta
, struct sta_info
, sta
);
3567 * The key can be removed while the packet was queued, so need to call
3568 * this here to get the current key.
3570 r
= ieee80211_tx_h_select_key(&tx
);
3571 if (r
!= TX_CONTINUE
) {
3572 ieee80211_free_txskb(&local
->hw
, skb
);
3576 if (test_bit(IEEE80211_TXQ_AMPDU
, &txqi
->flags
))
3577 info
->flags
|= IEEE80211_TX_CTL_AMPDU
;
3579 info
->flags
&= ~IEEE80211_TX_CTL_AMPDU
;
3581 if (info
->control
.flags
& IEEE80211_TX_CTRL_FAST_XMIT
) {
3582 struct sta_info
*sta
= container_of(txq
->sta
, struct sta_info
,
3587 (tx
.key
->conf
.flags
& IEEE80211_KEY_FLAG_GENERATE_IV
))
3588 pn_offs
= ieee80211_hdrlen(hdr
->frame_control
);
3590 ieee80211_xmit_fast_finish(sta
->sdata
, sta
, pn_offs
,
3593 if (invoke_tx_handlers_late(&tx
))
3596 skb
= __skb_dequeue(&tx
.skbs
);
3598 if (!skb_queue_empty(&tx
.skbs
)) {
3599 spin_lock_bh(&fq
->lock
);
3600 skb_queue_splice_tail(&tx
.skbs
, &txqi
->frags
);
3601 spin_unlock_bh(&fq
->lock
);
3605 if (skb_has_frag_list(skb
) &&
3606 !ieee80211_hw_check(&local
->hw
, TX_FRAG_LIST
)) {
3607 if (skb_linearize(skb
)) {
3608 ieee80211_free_txskb(&local
->hw
, skb
);
3613 switch (tx
.sdata
->vif
.type
) {
3614 case NL80211_IFTYPE_MONITOR
:
3615 if (tx
.sdata
->u
.mntr
.flags
& MONITOR_FLAG_ACTIVE
) {
3616 vif
= &tx
.sdata
->vif
;
3619 tx
.sdata
= rcu_dereference(local
->monitor_sdata
);
3621 vif
= &tx
.sdata
->vif
;
3623 vif
->hw_queue
[skb_get_queue_mapping(skb
)];
3624 } else if (ieee80211_hw_check(&local
->hw
, QUEUE_CONTROL
)) {
3625 ieee80211_free_txskb(&local
->hw
, skb
);
3631 case NL80211_IFTYPE_AP_VLAN
:
3632 tx
.sdata
= container_of(tx
.sdata
->bss
,
3633 struct ieee80211_sub_if_data
, u
.ap
);
3636 vif
= &tx
.sdata
->vif
;
3640 IEEE80211_SKB_CB(skb
)->control
.vif
= vif
;
3644 spin_unlock_bh(&fq
->lock
);
3648 EXPORT_SYMBOL(ieee80211_tx_dequeue
);
3650 struct ieee80211_txq
*ieee80211_next_txq(struct ieee80211_hw
*hw
, u8 ac
)
3652 struct ieee80211_local
*local
= hw_to_local(hw
);
3653 struct txq_info
*txqi
= NULL
;
3655 lockdep_assert_held(&local
->active_txq_lock
[ac
]);
3658 txqi
= list_first_entry_or_null(&local
->active_txqs
[ac
],
3664 if (txqi
->txq
.sta
) {
3665 struct sta_info
*sta
= container_of(txqi
->txq
.sta
,
3666 struct sta_info
, sta
);
3668 if (sta
->airtime
[txqi
->txq
.ac
].deficit
< 0) {
3669 sta
->airtime
[txqi
->txq
.ac
].deficit
+=
3670 sta
->airtime_weight
;
3671 list_move_tail(&txqi
->schedule_order
,
3672 &local
->active_txqs
[txqi
->txq
.ac
]);
3678 if (txqi
->schedule_round
== local
->schedule_round
[ac
])
3681 list_del_init(&txqi
->schedule_order
);
3682 txqi
->schedule_round
= local
->schedule_round
[ac
];
3685 EXPORT_SYMBOL(ieee80211_next_txq
);
3687 void ieee80211_return_txq(struct ieee80211_hw
*hw
,
3688 struct ieee80211_txq
*txq
)
3690 struct ieee80211_local
*local
= hw_to_local(hw
);
3691 struct txq_info
*txqi
= to_txq_info(txq
);
3693 lockdep_assert_held(&local
->active_txq_lock
[txq
->ac
]);
3695 if (list_empty(&txqi
->schedule_order
) &&
3696 (!skb_queue_empty(&txqi
->frags
) || txqi
->tin
.backlog_packets
)) {
3697 /* If airtime accounting is active, always enqueue STAs at the
3698 * head of the list to ensure that they only get moved to the
3699 * back by the airtime DRR scheduler once they have a negative
3700 * deficit. A station that already has a negative deficit will
3701 * get immediately moved to the back of the list on the next
3702 * call to ieee80211_next_txq().
3704 if (txqi
->txq
.sta
&&
3705 wiphy_ext_feature_isset(local
->hw
.wiphy
,
3706 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS
))
3707 list_add(&txqi
->schedule_order
,
3708 &local
->active_txqs
[txq
->ac
]);
3710 list_add_tail(&txqi
->schedule_order
,
3711 &local
->active_txqs
[txq
->ac
]);
3714 EXPORT_SYMBOL(ieee80211_return_txq
);
3716 void ieee80211_schedule_txq(struct ieee80211_hw
*hw
,
3717 struct ieee80211_txq
*txq
)
3718 __acquires(txq_lock
) __releases(txq_lock
)
3720 struct ieee80211_local
*local
= hw_to_local(hw
);
3722 spin_lock_bh(&local
->active_txq_lock
[txq
->ac
]);
3723 ieee80211_return_txq(hw
, txq
);
3724 spin_unlock_bh(&local
->active_txq_lock
[txq
->ac
]);
3726 EXPORT_SYMBOL(ieee80211_schedule_txq
);
3728 bool ieee80211_txq_may_transmit(struct ieee80211_hw
*hw
,
3729 struct ieee80211_txq
*txq
)
3731 struct ieee80211_local
*local
= hw_to_local(hw
);
3732 struct txq_info
*iter
, *tmp
, *txqi
= to_txq_info(txq
);
3733 struct sta_info
*sta
;
3736 lockdep_assert_held(&local
->active_txq_lock
[ac
]);
3741 if (list_empty(&txqi
->schedule_order
))
3744 list_for_each_entry_safe(iter
, tmp
, &local
->active_txqs
[ac
],
3749 if (!iter
->txq
.sta
) {
3750 list_move_tail(&iter
->schedule_order
,
3751 &local
->active_txqs
[ac
]);
3754 sta
= container_of(iter
->txq
.sta
, struct sta_info
, sta
);
3755 if (sta
->airtime
[ac
].deficit
< 0)
3756 sta
->airtime
[ac
].deficit
+= sta
->airtime_weight
;
3757 list_move_tail(&iter
->schedule_order
, &local
->active_txqs
[ac
]);
3760 sta
= container_of(txqi
->txq
.sta
, struct sta_info
, sta
);
3761 if (sta
->airtime
[ac
].deficit
>= 0)
3764 sta
->airtime
[ac
].deficit
+= sta
->airtime_weight
;
3765 list_move_tail(&txqi
->schedule_order
, &local
->active_txqs
[ac
]);
3769 if (!list_empty(&txqi
->schedule_order
))
3770 list_del_init(&txqi
->schedule_order
);
3774 EXPORT_SYMBOL(ieee80211_txq_may_transmit
);
3776 void ieee80211_txq_schedule_start(struct ieee80211_hw
*hw
, u8 ac
)
3777 __acquires(txq_lock
)
3779 struct ieee80211_local
*local
= hw_to_local(hw
);
3781 spin_lock_bh(&local
->active_txq_lock
[ac
]);
3782 local
->schedule_round
[ac
]++;
3784 EXPORT_SYMBOL(ieee80211_txq_schedule_start
);
3786 void ieee80211_txq_schedule_end(struct ieee80211_hw
*hw
, u8 ac
)
3787 __releases(txq_lock
)
3789 struct ieee80211_local
*local
= hw_to_local(hw
);
3791 spin_unlock_bh(&local
->active_txq_lock
[ac
]);
3793 EXPORT_SYMBOL(ieee80211_txq_schedule_end
);
3795 void __ieee80211_subif_start_xmit(struct sk_buff
*skb
,
3796 struct net_device
*dev
,
3799 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3800 struct sta_info
*sta
;
3801 struct sk_buff
*next
;
3803 if (unlikely(skb
->len
< ETH_HLEN
)) {
3810 if (ieee80211_lookup_ra_sta(sdata
, skb
, &sta
))
3813 if (!IS_ERR_OR_NULL(sta
)) {
3814 struct ieee80211_fast_tx
*fast_tx
;
3816 sk_pacing_shift_update(skb
->sk
, sdata
->local
->hw
.tx_sk_pacing_shift
);
3818 fast_tx
= rcu_dereference(sta
->fast_tx
);
3821 ieee80211_xmit_fast(sdata
, sta
, fast_tx
, skb
))
3825 if (skb_is_gso(skb
)) {
3826 struct sk_buff
*segs
;
3828 segs
= skb_gso_segment(skb
, 0);
3836 /* we cannot process non-linear frames on this path */
3837 if (skb_linearize(skb
)) {
3842 /* the frame could be fragmented, software-encrypted, and other
3843 * things so we cannot really handle checksum offload with it -
3844 * fix it up in software before we handle anything else.
3846 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
3847 skb_set_transport_header(skb
,
3848 skb_checksum_start_offset(skb
));
3849 if (skb_checksum_help(skb
))
3862 skb
= ieee80211_build_hdr(sdata
, skb
, info_flags
, sta
);
3866 ieee80211_tx_stats(dev
, skb
->len
);
3868 ieee80211_xmit(sdata
, sta
, skb
, 0);
3877 static int ieee80211_change_da(struct sk_buff
*skb
, struct sta_info
*sta
)
3882 err
= skb_ensure_writable(skb
, ETH_HLEN
);
3886 eth
= (void *)skb
->data
;
3887 ether_addr_copy(eth
->h_dest
, sta
->sta
.addr
);
3892 static bool ieee80211_multicast_to_unicast(struct sk_buff
*skb
,
3893 struct net_device
*dev
)
3895 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3896 const struct ethhdr
*eth
= (void *)skb
->data
;
3897 const struct vlan_ethhdr
*ethvlan
= (void *)skb
->data
;
3900 if (likely(!is_multicast_ether_addr(eth
->h_dest
)))
3903 switch (sdata
->vif
.type
) {
3904 case NL80211_IFTYPE_AP_VLAN
:
3905 if (sdata
->u
.vlan
.sta
)
3907 if (sdata
->wdev
.use_4addr
)
3910 case NL80211_IFTYPE_AP
:
3911 /* check runtime toggle for this bss */
3912 if (!sdata
->bss
->multicast_to_unicast
)
3919 /* multicast to unicast conversion only for some payload */
3920 ethertype
= eth
->h_proto
;
3921 if (ethertype
== htons(ETH_P_8021Q
) && skb
->len
>= VLAN_ETH_HLEN
)
3922 ethertype
= ethvlan
->h_vlan_encapsulated_proto
;
3923 switch (ethertype
) {
3924 case htons(ETH_P_ARP
):
3925 case htons(ETH_P_IP
):
3926 case htons(ETH_P_IPV6
):
3936 ieee80211_convert_to_unicast(struct sk_buff
*skb
, struct net_device
*dev
,
3937 struct sk_buff_head
*queue
)
3939 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3940 struct ieee80211_local
*local
= sdata
->local
;
3941 const struct ethhdr
*eth
= (struct ethhdr
*)skb
->data
;
3942 struct sta_info
*sta
, *first
= NULL
;
3943 struct sk_buff
*cloned_skb
;
3947 list_for_each_entry_rcu(sta
, &local
->sta_list
, list
) {
3948 if (sdata
!= sta
->sdata
)
3949 /* AP-VLAN mismatch */
3951 if (unlikely(ether_addr_equal(eth
->h_source
, sta
->sta
.addr
)))
3952 /* do not send back to source */
3958 cloned_skb
= skb_clone(skb
, GFP_ATOMIC
);
3961 if (unlikely(ieee80211_change_da(cloned_skb
, sta
))) {
3962 dev_kfree_skb(cloned_skb
);
3965 __skb_queue_tail(queue
, cloned_skb
);
3968 if (likely(first
)) {
3969 if (unlikely(ieee80211_change_da(skb
, first
)))
3971 __skb_queue_tail(queue
, skb
);
3973 /* no STA connected, drop */
3980 __skb_queue_purge(queue
);
3981 __skb_queue_tail(queue
, skb
);
3987 * ieee80211_subif_start_xmit - netif start_xmit function for 802.3 vifs
3988 * @skb: packet to be sent
3989 * @dev: incoming interface
3991 * On failure skb will be freed.
3993 netdev_tx_t
ieee80211_subif_start_xmit(struct sk_buff
*skb
,
3994 struct net_device
*dev
)
3996 if (unlikely(ieee80211_multicast_to_unicast(skb
, dev
))) {
3997 struct sk_buff_head queue
;
3999 __skb_queue_head_init(&queue
);
4000 ieee80211_convert_to_unicast(skb
, dev
, &queue
);
4001 while ((skb
= __skb_dequeue(&queue
)))
4002 __ieee80211_subif_start_xmit(skb
, dev
, 0);
4004 __ieee80211_subif_start_xmit(skb
, dev
, 0);
4007 return NETDEV_TX_OK
;
4011 ieee80211_build_data_template(struct ieee80211_sub_if_data
*sdata
,
4012 struct sk_buff
*skb
, u32 info_flags
)
4014 struct ieee80211_hdr
*hdr
;
4015 struct ieee80211_tx_data tx
= {
4016 .local
= sdata
->local
,
4019 struct sta_info
*sta
;
4023 if (ieee80211_lookup_ra_sta(sdata
, skb
, &sta
)) {
4025 skb
= ERR_PTR(-EINVAL
);
4029 skb
= ieee80211_build_hdr(sdata
, skb
, info_flags
, sta
);
4033 hdr
= (void *)skb
->data
;
4034 tx
.sta
= sta_info_get(sdata
, hdr
->addr1
);
4037 if (ieee80211_tx_h_select_key(&tx
) != TX_CONTINUE
) {
4040 return ERR_PTR(-EINVAL
);
4049 * ieee80211_clear_tx_pending may not be called in a context where
4050 * it is possible that it packets could come in again.
4052 void ieee80211_clear_tx_pending(struct ieee80211_local
*local
)
4054 struct sk_buff
*skb
;
4057 for (i
= 0; i
< local
->hw
.queues
; i
++) {
4058 while ((skb
= skb_dequeue(&local
->pending
[i
])) != NULL
)
4059 ieee80211_free_txskb(&local
->hw
, skb
);
4064 * Returns false if the frame couldn't be transmitted but was queued instead,
4065 * which in this case means re-queued -- take as an indication to stop sending
4066 * more pending frames.
4068 static bool ieee80211_tx_pending_skb(struct ieee80211_local
*local
,
4069 struct sk_buff
*skb
)
4071 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
4072 struct ieee80211_sub_if_data
*sdata
;
4073 struct sta_info
*sta
;
4074 struct ieee80211_hdr
*hdr
;
4076 struct ieee80211_chanctx_conf
*chanctx_conf
;
4078 sdata
= vif_to_sdata(info
->control
.vif
);
4080 if (info
->flags
& IEEE80211_TX_INTFL_NEED_TXPROCESSING
) {
4081 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
4082 if (unlikely(!chanctx_conf
)) {
4086 info
->band
= chanctx_conf
->def
.chan
->band
;
4087 result
= ieee80211_tx(sdata
, NULL
, skb
, true, 0);
4089 struct sk_buff_head skbs
;
4091 __skb_queue_head_init(&skbs
);
4092 __skb_queue_tail(&skbs
, skb
);
4094 hdr
= (struct ieee80211_hdr
*)skb
->data
;
4095 sta
= sta_info_get(sdata
, hdr
->addr1
);
4097 result
= __ieee80211_tx(local
, &skbs
, skb
->len
, sta
, true);
4104 * Transmit all pending packets. Called from tasklet.
4106 void ieee80211_tx_pending(unsigned long data
)
4108 struct ieee80211_local
*local
= (struct ieee80211_local
*)data
;
4109 unsigned long flags
;
4115 spin_lock_irqsave(&local
->queue_stop_reason_lock
, flags
);
4116 for (i
= 0; i
< local
->hw
.queues
; i
++) {
4118 * If queue is stopped by something other than due to pending
4119 * frames, or we have no pending frames, proceed to next queue.
4121 if (local
->queue_stop_reasons
[i
] ||
4122 skb_queue_empty(&local
->pending
[i
]))
4125 while (!skb_queue_empty(&local
->pending
[i
])) {
4126 struct sk_buff
*skb
= __skb_dequeue(&local
->pending
[i
]);
4127 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
4129 if (WARN_ON(!info
->control
.vif
)) {
4130 ieee80211_free_txskb(&local
->hw
, skb
);
4134 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
,
4137 txok
= ieee80211_tx_pending_skb(local
, skb
);
4138 spin_lock_irqsave(&local
->queue_stop_reason_lock
,
4144 if (skb_queue_empty(&local
->pending
[i
]))
4145 ieee80211_propagate_queue_wake(local
, i
);
4147 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
, flags
);
4152 /* functions for drivers to get certain frames */
4154 static void __ieee80211_beacon_add_tim(struct ieee80211_sub_if_data
*sdata
,
4155 struct ps_data
*ps
, struct sk_buff
*skb
,
4160 int i
, have_bits
= 0, n1
, n2
;
4162 /* Generate bitmap for TIM only if there are any STAs in power save
4164 if (atomic_read(&ps
->num_sta_ps
) > 0)
4165 /* in the hope that this is faster than
4166 * checking byte-for-byte */
4167 have_bits
= !bitmap_empty((unsigned long *)ps
->tim
,
4168 IEEE80211_MAX_AID
+1);
4170 if (ps
->dtim_count
== 0)
4171 ps
->dtim_count
= sdata
->vif
.bss_conf
.dtim_period
- 1;
4176 tim
= pos
= skb_put(skb
, 6);
4177 *pos
++ = WLAN_EID_TIM
;
4179 *pos
++ = ps
->dtim_count
;
4180 *pos
++ = sdata
->vif
.bss_conf
.dtim_period
;
4182 if (ps
->dtim_count
== 0 && !skb_queue_empty(&ps
->bc_buf
))
4185 ps
->dtim_bc_mc
= aid0
== 1;
4188 /* Find largest even number N1 so that bits numbered 1 through
4189 * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits
4190 * (N2 + 1) x 8 through 2007 are 0. */
4192 for (i
= 0; i
< IEEE80211_MAX_TIM_LEN
; i
++) {
4199 for (i
= IEEE80211_MAX_TIM_LEN
- 1; i
>= n1
; i
--) {
4206 /* Bitmap control */
4208 /* Part Virt Bitmap */
4209 skb_put(skb
, n2
- n1
);
4210 memcpy(pos
, ps
->tim
+ n1
, n2
- n1
+ 1);
4212 tim
[1] = n2
- n1
+ 4;
4214 *pos
++ = aid0
; /* Bitmap control */
4215 *pos
++ = 0; /* Part Virt Bitmap */
4219 static int ieee80211_beacon_add_tim(struct ieee80211_sub_if_data
*sdata
,
4220 struct ps_data
*ps
, struct sk_buff
*skb
,
4223 struct ieee80211_local
*local
= sdata
->local
;
4226 * Not very nice, but we want to allow the driver to call
4227 * ieee80211_beacon_get() as a response to the set_tim()
4228 * callback. That, however, is already invoked under the
4229 * sta_lock to guarantee consistent and race-free update
4230 * of the tim bitmap in mac80211 and the driver.
4232 if (local
->tim_in_locked_section
) {
4233 __ieee80211_beacon_add_tim(sdata
, ps
, skb
, is_template
);
4235 spin_lock_bh(&local
->tim_lock
);
4236 __ieee80211_beacon_add_tim(sdata
, ps
, skb
, is_template
);
4237 spin_unlock_bh(&local
->tim_lock
);
4243 static void ieee80211_set_csa(struct ieee80211_sub_if_data
*sdata
,
4244 struct beacon_data
*beacon
)
4246 struct probe_resp
*resp
;
4248 size_t beacon_data_len
;
4250 u8 count
= beacon
->csa_current_counter
;
4252 switch (sdata
->vif
.type
) {
4253 case NL80211_IFTYPE_AP
:
4254 beacon_data
= beacon
->tail
;
4255 beacon_data_len
= beacon
->tail_len
;
4257 case NL80211_IFTYPE_ADHOC
:
4258 beacon_data
= beacon
->head
;
4259 beacon_data_len
= beacon
->head_len
;
4261 case NL80211_IFTYPE_MESH_POINT
:
4262 beacon_data
= beacon
->head
;
4263 beacon_data_len
= beacon
->head_len
;
4270 for (i
= 0; i
< IEEE80211_MAX_CSA_COUNTERS_NUM
; ++i
) {
4271 resp
= rcu_dereference(sdata
->u
.ap
.probe_resp
);
4273 if (beacon
->csa_counter_offsets
[i
]) {
4274 if (WARN_ON_ONCE(beacon
->csa_counter_offsets
[i
] >=
4280 beacon_data
[beacon
->csa_counter_offsets
[i
]] = count
;
4283 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
&& resp
)
4284 resp
->data
[resp
->csa_counter_offsets
[i
]] = count
;
4289 static u8
__ieee80211_csa_update_counter(struct beacon_data
*beacon
)
4291 beacon
->csa_current_counter
--;
4293 /* the counter should never reach 0 */
4294 WARN_ON_ONCE(!beacon
->csa_current_counter
);
4296 return beacon
->csa_current_counter
;
4299 u8
ieee80211_csa_update_counter(struct ieee80211_vif
*vif
)
4301 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
4302 struct beacon_data
*beacon
= NULL
;
4307 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
)
4308 beacon
= rcu_dereference(sdata
->u
.ap
.beacon
);
4309 else if (sdata
->vif
.type
== NL80211_IFTYPE_ADHOC
)
4310 beacon
= rcu_dereference(sdata
->u
.ibss
.presp
);
4311 else if (ieee80211_vif_is_mesh(&sdata
->vif
))
4312 beacon
= rcu_dereference(sdata
->u
.mesh
.beacon
);
4317 count
= __ieee80211_csa_update_counter(beacon
);
4323 EXPORT_SYMBOL(ieee80211_csa_update_counter
);
4325 void ieee80211_csa_set_counter(struct ieee80211_vif
*vif
, u8 counter
)
4327 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
4328 struct beacon_data
*beacon
= NULL
;
4332 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
)
4333 beacon
= rcu_dereference(sdata
->u
.ap
.beacon
);
4334 else if (sdata
->vif
.type
== NL80211_IFTYPE_ADHOC
)
4335 beacon
= rcu_dereference(sdata
->u
.ibss
.presp
);
4336 else if (ieee80211_vif_is_mesh(&sdata
->vif
))
4337 beacon
= rcu_dereference(sdata
->u
.mesh
.beacon
);
4342 if (counter
< beacon
->csa_current_counter
)
4343 beacon
->csa_current_counter
= counter
;
4348 EXPORT_SYMBOL(ieee80211_csa_set_counter
);
4350 bool ieee80211_csa_is_complete(struct ieee80211_vif
*vif
)
4352 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
4353 struct beacon_data
*beacon
= NULL
;
4355 size_t beacon_data_len
;
4358 if (!ieee80211_sdata_running(sdata
))
4362 if (vif
->type
== NL80211_IFTYPE_AP
) {
4363 struct ieee80211_if_ap
*ap
= &sdata
->u
.ap
;
4365 beacon
= rcu_dereference(ap
->beacon
);
4366 if (WARN_ON(!beacon
|| !beacon
->tail
))
4368 beacon_data
= beacon
->tail
;
4369 beacon_data_len
= beacon
->tail_len
;
4370 } else if (vif
->type
== NL80211_IFTYPE_ADHOC
) {
4371 struct ieee80211_if_ibss
*ifibss
= &sdata
->u
.ibss
;
4373 beacon
= rcu_dereference(ifibss
->presp
);
4377 beacon_data
= beacon
->head
;
4378 beacon_data_len
= beacon
->head_len
;
4379 } else if (vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
4380 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
4382 beacon
= rcu_dereference(ifmsh
->beacon
);
4386 beacon_data
= beacon
->head
;
4387 beacon_data_len
= beacon
->head_len
;
4393 if (!beacon
->csa_counter_offsets
[0])
4396 if (WARN_ON_ONCE(beacon
->csa_counter_offsets
[0] > beacon_data_len
))
4399 if (beacon_data
[beacon
->csa_counter_offsets
[0]] == 1)
4406 EXPORT_SYMBOL(ieee80211_csa_is_complete
);
4408 static struct sk_buff
*
4409 __ieee80211_beacon_get(struct ieee80211_hw
*hw
,
4410 struct ieee80211_vif
*vif
,
4411 struct ieee80211_mutable_offsets
*offs
,
4414 struct ieee80211_local
*local
= hw_to_local(hw
);
4415 struct beacon_data
*beacon
= NULL
;
4416 struct sk_buff
*skb
= NULL
;
4417 struct ieee80211_tx_info
*info
;
4418 struct ieee80211_sub_if_data
*sdata
= NULL
;
4419 enum nl80211_band band
;
4420 struct ieee80211_tx_rate_control txrc
;
4421 struct ieee80211_chanctx_conf
*chanctx_conf
;
4422 int csa_off_base
= 0;
4426 sdata
= vif_to_sdata(vif
);
4427 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
4429 if (!ieee80211_sdata_running(sdata
) || !chanctx_conf
)
4433 memset(offs
, 0, sizeof(*offs
));
4435 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
) {
4436 struct ieee80211_if_ap
*ap
= &sdata
->u
.ap
;
4438 beacon
= rcu_dereference(ap
->beacon
);
4440 if (beacon
->csa_counter_offsets
[0]) {
4442 __ieee80211_csa_update_counter(beacon
);
4444 ieee80211_set_csa(sdata
, beacon
);
4448 * headroom, head length,
4449 * tail length and maximum TIM length
4451 skb
= dev_alloc_skb(local
->tx_headroom
+
4453 beacon
->tail_len
+ 256 +
4454 local
->hw
.extra_beacon_tailroom
);
4458 skb_reserve(skb
, local
->tx_headroom
);
4459 skb_put_data(skb
, beacon
->head
, beacon
->head_len
);
4461 ieee80211_beacon_add_tim(sdata
, &ap
->ps
, skb
,
4465 offs
->tim_offset
= beacon
->head_len
;
4466 offs
->tim_length
= skb
->len
- beacon
->head_len
;
4468 /* for AP the csa offsets are from tail */
4469 csa_off_base
= skb
->len
;
4473 skb_put_data(skb
, beacon
->tail
,
4477 } else if (sdata
->vif
.type
== NL80211_IFTYPE_ADHOC
) {
4478 struct ieee80211_if_ibss
*ifibss
= &sdata
->u
.ibss
;
4479 struct ieee80211_hdr
*hdr
;
4481 beacon
= rcu_dereference(ifibss
->presp
);
4485 if (beacon
->csa_counter_offsets
[0]) {
4487 __ieee80211_csa_update_counter(beacon
);
4489 ieee80211_set_csa(sdata
, beacon
);
4492 skb
= dev_alloc_skb(local
->tx_headroom
+ beacon
->head_len
+
4493 local
->hw
.extra_beacon_tailroom
);
4496 skb_reserve(skb
, local
->tx_headroom
);
4497 skb_put_data(skb
, beacon
->head
, beacon
->head_len
);
4499 hdr
= (struct ieee80211_hdr
*) skb
->data
;
4500 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
4501 IEEE80211_STYPE_BEACON
);
4502 } else if (ieee80211_vif_is_mesh(&sdata
->vif
)) {
4503 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
4505 beacon
= rcu_dereference(ifmsh
->beacon
);
4509 if (beacon
->csa_counter_offsets
[0]) {
4511 /* TODO: For mesh csa_counter is in TU, so
4512 * decrementing it by one isn't correct, but
4513 * for now we leave it consistent with overall
4514 * mac80211's behavior.
4516 __ieee80211_csa_update_counter(beacon
);
4518 ieee80211_set_csa(sdata
, beacon
);
4521 if (ifmsh
->sync_ops
)
4522 ifmsh
->sync_ops
->adjust_tsf(sdata
, beacon
);
4524 skb
= dev_alloc_skb(local
->tx_headroom
+
4528 local
->hw
.extra_beacon_tailroom
);
4531 skb_reserve(skb
, local
->tx_headroom
);
4532 skb_put_data(skb
, beacon
->head
, beacon
->head_len
);
4533 ieee80211_beacon_add_tim(sdata
, &ifmsh
->ps
, skb
, is_template
);
4536 offs
->tim_offset
= beacon
->head_len
;
4537 offs
->tim_length
= skb
->len
- beacon
->head_len
;
4540 skb_put_data(skb
, beacon
->tail
, beacon
->tail_len
);
4547 if (offs
&& beacon
) {
4550 for (i
= 0; i
< IEEE80211_MAX_CSA_COUNTERS_NUM
; i
++) {
4551 u16 csa_off
= beacon
->csa_counter_offsets
[i
];
4556 offs
->csa_counter_offs
[i
] = csa_off_base
+ csa_off
;
4560 band
= chanctx_conf
->def
.chan
->band
;
4562 info
= IEEE80211_SKB_CB(skb
);
4564 info
->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
4565 info
->flags
|= IEEE80211_TX_CTL_NO_ACK
;
4568 memset(&txrc
, 0, sizeof(txrc
));
4570 txrc
.sband
= local
->hw
.wiphy
->bands
[band
];
4571 txrc
.bss_conf
= &sdata
->vif
.bss_conf
;
4573 txrc
.reported_rate
.idx
= -1;
4574 txrc
.rate_idx_mask
= sdata
->rc_rateidx_mask
[band
];
4576 rate_control_get_rate(sdata
, NULL
, &txrc
);
4578 info
->control
.vif
= vif
;
4580 info
->flags
|= IEEE80211_TX_CTL_CLEAR_PS_FILT
|
4581 IEEE80211_TX_CTL_ASSIGN_SEQ
|
4582 IEEE80211_TX_CTL_FIRST_FRAGMENT
;
4590 ieee80211_beacon_get_template(struct ieee80211_hw
*hw
,
4591 struct ieee80211_vif
*vif
,
4592 struct ieee80211_mutable_offsets
*offs
)
4594 return __ieee80211_beacon_get(hw
, vif
, offs
, true);
4596 EXPORT_SYMBOL(ieee80211_beacon_get_template
);
4598 struct sk_buff
*ieee80211_beacon_get_tim(struct ieee80211_hw
*hw
,
4599 struct ieee80211_vif
*vif
,
4600 u16
*tim_offset
, u16
*tim_length
)
4602 struct ieee80211_mutable_offsets offs
= {};
4603 struct sk_buff
*bcn
= __ieee80211_beacon_get(hw
, vif
, &offs
, false);
4604 struct sk_buff
*copy
;
4605 struct ieee80211_supported_band
*sband
;
4612 *tim_offset
= offs
.tim_offset
;
4615 *tim_length
= offs
.tim_length
;
4617 if (ieee80211_hw_check(hw
, BEACON_TX_STATUS
) ||
4618 !hw_to_local(hw
)->monitors
)
4621 /* send a copy to monitor interfaces */
4622 copy
= skb_copy(bcn
, GFP_ATOMIC
);
4626 shift
= ieee80211_vif_get_shift(vif
);
4627 sband
= ieee80211_get_sband(vif_to_sdata(vif
));
4631 ieee80211_tx_monitor(hw_to_local(hw
), copy
, sband
, 1, shift
, false);
4635 EXPORT_SYMBOL(ieee80211_beacon_get_tim
);
4637 struct sk_buff
*ieee80211_proberesp_get(struct ieee80211_hw
*hw
,
4638 struct ieee80211_vif
*vif
)
4640 struct ieee80211_if_ap
*ap
= NULL
;
4641 struct sk_buff
*skb
= NULL
;
4642 struct probe_resp
*presp
= NULL
;
4643 struct ieee80211_hdr
*hdr
;
4644 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
4646 if (sdata
->vif
.type
!= NL80211_IFTYPE_AP
)
4652 presp
= rcu_dereference(ap
->probe_resp
);
4656 skb
= dev_alloc_skb(presp
->len
);
4660 skb_put_data(skb
, presp
->data
, presp
->len
);
4662 hdr
= (struct ieee80211_hdr
*) skb
->data
;
4663 memset(hdr
->addr1
, 0, sizeof(hdr
->addr1
));
4669 EXPORT_SYMBOL(ieee80211_proberesp_get
);
4671 struct sk_buff
*ieee80211_pspoll_get(struct ieee80211_hw
*hw
,
4672 struct ieee80211_vif
*vif
)
4674 struct ieee80211_sub_if_data
*sdata
;
4675 struct ieee80211_if_managed
*ifmgd
;
4676 struct ieee80211_pspoll
*pspoll
;
4677 struct ieee80211_local
*local
;
4678 struct sk_buff
*skb
;
4680 if (WARN_ON(vif
->type
!= NL80211_IFTYPE_STATION
))
4683 sdata
= vif_to_sdata(vif
);
4684 ifmgd
= &sdata
->u
.mgd
;
4685 local
= sdata
->local
;
4687 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*pspoll
));
4691 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
4693 pspoll
= skb_put_zero(skb
, sizeof(*pspoll
));
4694 pspoll
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_CTL
|
4695 IEEE80211_STYPE_PSPOLL
);
4696 pspoll
->aid
= cpu_to_le16(ifmgd
->aid
);
4698 /* aid in PS-Poll has its two MSBs each set to 1 */
4699 pspoll
->aid
|= cpu_to_le16(1 << 15 | 1 << 14);
4701 memcpy(pspoll
->bssid
, ifmgd
->bssid
, ETH_ALEN
);
4702 memcpy(pspoll
->ta
, vif
->addr
, ETH_ALEN
);
4706 EXPORT_SYMBOL(ieee80211_pspoll_get
);
4708 struct sk_buff
*ieee80211_nullfunc_get(struct ieee80211_hw
*hw
,
4709 struct ieee80211_vif
*vif
,
4712 struct ieee80211_hdr_3addr
*nullfunc
;
4713 struct ieee80211_sub_if_data
*sdata
;
4714 struct ieee80211_if_managed
*ifmgd
;
4715 struct ieee80211_local
*local
;
4716 struct sk_buff
*skb
;
4719 if (WARN_ON(vif
->type
!= NL80211_IFTYPE_STATION
))
4722 sdata
= vif_to_sdata(vif
);
4723 ifmgd
= &sdata
->u
.mgd
;
4724 local
= sdata
->local
;
4727 struct sta_info
*sta
;
4730 sta
= sta_info_get(sdata
, ifmgd
->bssid
);
4731 qos
= sta
&& sta
->sta
.wme
;
4735 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
4736 sizeof(*nullfunc
) + 2);
4740 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
4742 nullfunc
= skb_put_zero(skb
, sizeof(*nullfunc
));
4743 nullfunc
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
4744 IEEE80211_STYPE_NULLFUNC
|
4745 IEEE80211_FCTL_TODS
);
4747 __le16 qoshdr
= cpu_to_le16(7);
4749 BUILD_BUG_ON((IEEE80211_STYPE_QOS_NULLFUNC
|
4750 IEEE80211_STYPE_NULLFUNC
) !=
4751 IEEE80211_STYPE_QOS_NULLFUNC
);
4752 nullfunc
->frame_control
|=
4753 cpu_to_le16(IEEE80211_STYPE_QOS_NULLFUNC
);
4755 skb_set_queue_mapping(skb
, IEEE80211_AC_VO
);
4756 skb_put_data(skb
, &qoshdr
, sizeof(qoshdr
));
4759 memcpy(nullfunc
->addr1
, ifmgd
->bssid
, ETH_ALEN
);
4760 memcpy(nullfunc
->addr2
, vif
->addr
, ETH_ALEN
);
4761 memcpy(nullfunc
->addr3
, ifmgd
->bssid
, ETH_ALEN
);
4765 EXPORT_SYMBOL(ieee80211_nullfunc_get
);
4767 struct sk_buff
*ieee80211_probereq_get(struct ieee80211_hw
*hw
,
4769 const u8
*ssid
, size_t ssid_len
,
4772 struct ieee80211_local
*local
= hw_to_local(hw
);
4773 struct ieee80211_hdr_3addr
*hdr
;
4774 struct sk_buff
*skb
;
4778 ie_ssid_len
= 2 + ssid_len
;
4780 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*hdr
) +
4781 ie_ssid_len
+ tailroom
);
4785 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
4787 hdr
= skb_put_zero(skb
, sizeof(*hdr
));
4788 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
4789 IEEE80211_STYPE_PROBE_REQ
);
4790 eth_broadcast_addr(hdr
->addr1
);
4791 memcpy(hdr
->addr2
, src_addr
, ETH_ALEN
);
4792 eth_broadcast_addr(hdr
->addr3
);
4794 pos
= skb_put(skb
, ie_ssid_len
);
4795 *pos
++ = WLAN_EID_SSID
;
4798 memcpy(pos
, ssid
, ssid_len
);
4803 EXPORT_SYMBOL(ieee80211_probereq_get
);
4805 void ieee80211_rts_get(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
4806 const void *frame
, size_t frame_len
,
4807 const struct ieee80211_tx_info
*frame_txctl
,
4808 struct ieee80211_rts
*rts
)
4810 const struct ieee80211_hdr
*hdr
= frame
;
4812 rts
->frame_control
=
4813 cpu_to_le16(IEEE80211_FTYPE_CTL
| IEEE80211_STYPE_RTS
);
4814 rts
->duration
= ieee80211_rts_duration(hw
, vif
, frame_len
,
4816 memcpy(rts
->ra
, hdr
->addr1
, sizeof(rts
->ra
));
4817 memcpy(rts
->ta
, hdr
->addr2
, sizeof(rts
->ta
));
4819 EXPORT_SYMBOL(ieee80211_rts_get
);
4821 void ieee80211_ctstoself_get(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
4822 const void *frame
, size_t frame_len
,
4823 const struct ieee80211_tx_info
*frame_txctl
,
4824 struct ieee80211_cts
*cts
)
4826 const struct ieee80211_hdr
*hdr
= frame
;
4828 cts
->frame_control
=
4829 cpu_to_le16(IEEE80211_FTYPE_CTL
| IEEE80211_STYPE_CTS
);
4830 cts
->duration
= ieee80211_ctstoself_duration(hw
, vif
,
4831 frame_len
, frame_txctl
);
4832 memcpy(cts
->ra
, hdr
->addr1
, sizeof(cts
->ra
));
4834 EXPORT_SYMBOL(ieee80211_ctstoself_get
);
4837 ieee80211_get_buffered_bc(struct ieee80211_hw
*hw
,
4838 struct ieee80211_vif
*vif
)
4840 struct ieee80211_local
*local
= hw_to_local(hw
);
4841 struct sk_buff
*skb
= NULL
;
4842 struct ieee80211_tx_data tx
;
4843 struct ieee80211_sub_if_data
*sdata
;
4845 struct ieee80211_tx_info
*info
;
4846 struct ieee80211_chanctx_conf
*chanctx_conf
;
4848 sdata
= vif_to_sdata(vif
);
4851 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
4856 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
) {
4857 struct beacon_data
*beacon
=
4858 rcu_dereference(sdata
->u
.ap
.beacon
);
4860 if (!beacon
|| !beacon
->head
)
4863 ps
= &sdata
->u
.ap
.ps
;
4864 } else if (ieee80211_vif_is_mesh(&sdata
->vif
)) {
4865 ps
= &sdata
->u
.mesh
.ps
;
4870 if (ps
->dtim_count
!= 0 || !ps
->dtim_bc_mc
)
4871 goto out
; /* send buffered bc/mc only after DTIM beacon */
4874 skb
= skb_dequeue(&ps
->bc_buf
);
4877 local
->total_ps_buffered
--;
4879 if (!skb_queue_empty(&ps
->bc_buf
) && skb
->len
>= 2) {
4880 struct ieee80211_hdr
*hdr
=
4881 (struct ieee80211_hdr
*) skb
->data
;
4882 /* more buffered multicast/broadcast frames ==> set
4883 * MoreData flag in IEEE 802.11 header to inform PS
4885 hdr
->frame_control
|=
4886 cpu_to_le16(IEEE80211_FCTL_MOREDATA
);
4889 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
)
4890 sdata
= IEEE80211_DEV_TO_SUB_IF(skb
->dev
);
4891 if (!ieee80211_tx_prepare(sdata
, &tx
, NULL
, skb
))
4893 ieee80211_free_txskb(hw
, skb
);
4896 info
= IEEE80211_SKB_CB(skb
);
4898 tx
.flags
|= IEEE80211_TX_PS_BUFFERED
;
4899 info
->band
= chanctx_conf
->def
.chan
->band
;
4901 if (invoke_tx_handlers(&tx
))
4908 EXPORT_SYMBOL(ieee80211_get_buffered_bc
);
4910 int ieee80211_reserve_tid(struct ieee80211_sta
*pubsta
, u8 tid
)
4912 struct sta_info
*sta
= container_of(pubsta
, struct sta_info
, sta
);
4913 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
4914 struct ieee80211_local
*local
= sdata
->local
;
4918 lockdep_assert_held(&local
->sta_mtx
);
4920 /* only some cases are supported right now */
4921 switch (sdata
->vif
.type
) {
4922 case NL80211_IFTYPE_STATION
:
4923 case NL80211_IFTYPE_AP
:
4924 case NL80211_IFTYPE_AP_VLAN
:
4931 if (WARN_ON(tid
>= IEEE80211_NUM_UPS
))
4934 if (sta
->reserved_tid
== tid
) {
4939 if (sta
->reserved_tid
!= IEEE80211_TID_UNRESERVED
) {
4940 sdata_err(sdata
, "TID reservation already active\n");
4945 ieee80211_stop_vif_queues(sdata
->local
, sdata
,
4946 IEEE80211_QUEUE_STOP_REASON_RESERVE_TID
);
4950 /* Tear down BA sessions so we stop aggregating on this TID */
4951 if (ieee80211_hw_check(&local
->hw
, AMPDU_AGGREGATION
)) {
4952 set_sta_flag(sta
, WLAN_STA_BLOCK_BA
);
4953 __ieee80211_stop_tx_ba_session(sta
, tid
,
4954 AGG_STOP_LOCAL_REQUEST
);
4957 queues
= BIT(sdata
->vif
.hw_queue
[ieee802_1d_to_ac
[tid
]]);
4958 __ieee80211_flush_queues(local
, sdata
, queues
, false);
4960 sta
->reserved_tid
= tid
;
4962 ieee80211_wake_vif_queues(local
, sdata
,
4963 IEEE80211_QUEUE_STOP_REASON_RESERVE_TID
);
4965 if (ieee80211_hw_check(&local
->hw
, AMPDU_AGGREGATION
))
4966 clear_sta_flag(sta
, WLAN_STA_BLOCK_BA
);
4972 EXPORT_SYMBOL(ieee80211_reserve_tid
);
4974 void ieee80211_unreserve_tid(struct ieee80211_sta
*pubsta
, u8 tid
)
4976 struct sta_info
*sta
= container_of(pubsta
, struct sta_info
, sta
);
4977 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
4979 lockdep_assert_held(&sdata
->local
->sta_mtx
);
4981 /* only some cases are supported right now */
4982 switch (sdata
->vif
.type
) {
4983 case NL80211_IFTYPE_STATION
:
4984 case NL80211_IFTYPE_AP
:
4985 case NL80211_IFTYPE_AP_VLAN
:
4992 if (tid
!= sta
->reserved_tid
) {
4993 sdata_err(sdata
, "TID to unreserve (%d) isn't reserved\n", tid
);
4997 sta
->reserved_tid
= IEEE80211_TID_UNRESERVED
;
4999 EXPORT_SYMBOL(ieee80211_unreserve_tid
);
5001 void __ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data
*sdata
,
5002 struct sk_buff
*skb
, int tid
,
5003 enum nl80211_band band
, u32 txdata_flags
)
5005 int ac
= ieee80211_ac_from_tid(tid
);
5007 skb_reset_mac_header(skb
);
5008 skb_set_queue_mapping(skb
, ac
);
5009 skb
->priority
= tid
;
5011 skb
->dev
= sdata
->dev
;
5014 * The other path calling ieee80211_xmit is from the tasklet,
5015 * and while we can handle concurrent transmissions locking
5016 * requirements are that we do not come into tx with bhs on.
5019 IEEE80211_SKB_CB(skb
)->band
= band
;
5020 ieee80211_xmit(sdata
, NULL
, skb
, txdata_flags
);
5024 int ieee80211_tx_control_port(struct wiphy
*wiphy
, struct net_device
*dev
,
5025 const u8
*buf
, size_t len
,
5026 const u8
*dest
, __be16 proto
, bool unencrypted
)
5028 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
5029 struct ieee80211_local
*local
= sdata
->local
;
5030 struct sk_buff
*skb
;
5031 struct ethhdr
*ehdr
;
5034 /* Only accept CONTROL_PORT_PROTOCOL configured in CONNECT/ASSOCIATE
5035 * or Pre-Authentication
5037 if (proto
!= sdata
->control_port_protocol
&&
5038 proto
!= cpu_to_be16(ETH_P_PREAUTH
))
5042 flags
= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
5046 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
5047 sizeof(struct ethhdr
) + len
);
5051 skb_reserve(skb
, local
->hw
.extra_tx_headroom
+ sizeof(struct ethhdr
));
5053 skb_put_data(skb
, buf
, len
);
5055 ehdr
= skb_push(skb
, sizeof(struct ethhdr
));
5056 memcpy(ehdr
->h_dest
, dest
, ETH_ALEN
);
5057 memcpy(ehdr
->h_source
, sdata
->vif
.addr
, ETH_ALEN
);
5058 ehdr
->h_proto
= proto
;
5061 skb
->protocol
= htons(ETH_P_802_3
);
5062 skb_reset_network_header(skb
);
5063 skb_reset_mac_header(skb
);
5066 __ieee80211_subif_start_xmit(skb
, skb
->dev
, flags
);