1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Copyright 2002-2005, Instant802 Networks, Inc.
4*4882a593Smuzhiyun * Copyright 2005-2006, Devicescape Software, Inc.
5*4882a593Smuzhiyun * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
6*4882a593Smuzhiyun * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
7*4882a593Smuzhiyun * Copyright 2013-2014 Intel Mobile Communications GmbH
8*4882a593Smuzhiyun * Copyright (C) 2018-2020 Intel Corporation
9*4882a593Smuzhiyun *
10*4882a593Smuzhiyun * Transmit and frame generation functions.
11*4882a593Smuzhiyun */
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #include <linux/kernel.h>
14*4882a593Smuzhiyun #include <linux/slab.h>
15*4882a593Smuzhiyun #include <linux/skbuff.h>
16*4882a593Smuzhiyun #include <linux/if_vlan.h>
17*4882a593Smuzhiyun #include <linux/etherdevice.h>
18*4882a593Smuzhiyun #include <linux/bitmap.h>
19*4882a593Smuzhiyun #include <linux/rcupdate.h>
20*4882a593Smuzhiyun #include <linux/export.h>
21*4882a593Smuzhiyun #include <net/net_namespace.h>
22*4882a593Smuzhiyun #include <net/ieee80211_radiotap.h>
23*4882a593Smuzhiyun #include <net/cfg80211.h>
24*4882a593Smuzhiyun #include <net/mac80211.h>
25*4882a593Smuzhiyun #include <net/codel.h>
26*4882a593Smuzhiyun #include <net/codel_impl.h>
27*4882a593Smuzhiyun #include <asm/unaligned.h>
28*4882a593Smuzhiyun #include <net/fq_impl.h>
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun #include "ieee80211_i.h"
31*4882a593Smuzhiyun #include "driver-ops.h"
32*4882a593Smuzhiyun #include "led.h"
33*4882a593Smuzhiyun #include "mesh.h"
34*4882a593Smuzhiyun #include "wep.h"
35*4882a593Smuzhiyun #include "wpa.h"
36*4882a593Smuzhiyun #include "wme.h"
37*4882a593Smuzhiyun #include "rate.h"
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun /* misc utils */
40*4882a593Smuzhiyun
ieee80211_tx_stats(struct net_device * dev,u32 len)41*4882a593Smuzhiyun static inline void ieee80211_tx_stats(struct net_device *dev, u32 len)
42*4882a593Smuzhiyun {
43*4882a593Smuzhiyun struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun u64_stats_update_begin(&tstats->syncp);
46*4882a593Smuzhiyun tstats->tx_packets++;
47*4882a593Smuzhiyun tstats->tx_bytes += len;
48*4882a593Smuzhiyun u64_stats_update_end(&tstats->syncp);
49*4882a593Smuzhiyun }
50*4882a593Smuzhiyun
ieee80211_duration(struct ieee80211_tx_data * tx,struct sk_buff * skb,int group_addr,int next_frag_len)51*4882a593Smuzhiyun static __le16 ieee80211_duration(struct ieee80211_tx_data *tx,
52*4882a593Smuzhiyun struct sk_buff *skb, int group_addr,
53*4882a593Smuzhiyun int next_frag_len)
54*4882a593Smuzhiyun {
55*4882a593Smuzhiyun int rate, mrate, erp, dur, i, shift = 0;
56*4882a593Smuzhiyun struct ieee80211_rate *txrate;
57*4882a593Smuzhiyun struct ieee80211_local *local = tx->local;
58*4882a593Smuzhiyun struct ieee80211_supported_band *sband;
59*4882a593Smuzhiyun struct ieee80211_hdr *hdr;
60*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
61*4882a593Smuzhiyun struct ieee80211_chanctx_conf *chanctx_conf;
62*4882a593Smuzhiyun u32 rate_flags = 0;
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun /* assume HW handles this */
65*4882a593Smuzhiyun if (tx->rate.flags & (IEEE80211_TX_RC_MCS | IEEE80211_TX_RC_VHT_MCS))
66*4882a593Smuzhiyun return 0;
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun rcu_read_lock();
69*4882a593Smuzhiyun chanctx_conf = rcu_dereference(tx->sdata->vif.chanctx_conf);
70*4882a593Smuzhiyun if (chanctx_conf) {
71*4882a593Smuzhiyun shift = ieee80211_chandef_get_shift(&chanctx_conf->def);
72*4882a593Smuzhiyun rate_flags = ieee80211_chandef_rate_flags(&chanctx_conf->def);
73*4882a593Smuzhiyun }
74*4882a593Smuzhiyun rcu_read_unlock();
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun /* uh huh? */
77*4882a593Smuzhiyun if (WARN_ON_ONCE(tx->rate.idx < 0))
78*4882a593Smuzhiyun return 0;
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun sband = local->hw.wiphy->bands[info->band];
81*4882a593Smuzhiyun txrate = &sband->bitrates[tx->rate.idx];
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun erp = txrate->flags & IEEE80211_RATE_ERP_G;
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun /* device is expected to do this */
86*4882a593Smuzhiyun if (sband->band == NL80211_BAND_S1GHZ)
87*4882a593Smuzhiyun return 0;
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun /*
90*4882a593Smuzhiyun * data and mgmt (except PS Poll):
91*4882a593Smuzhiyun * - during CFP: 32768
92*4882a593Smuzhiyun * - during contention period:
93*4882a593Smuzhiyun * if addr1 is group address: 0
94*4882a593Smuzhiyun * if more fragments = 0 and addr1 is individual address: time to
95*4882a593Smuzhiyun * transmit one ACK plus SIFS
96*4882a593Smuzhiyun * if more fragments = 1 and addr1 is individual address: time to
97*4882a593Smuzhiyun * transmit next fragment plus 2 x ACK plus 3 x SIFS
98*4882a593Smuzhiyun *
99*4882a593Smuzhiyun * IEEE 802.11, 9.6:
100*4882a593Smuzhiyun * - control response frame (CTS or ACK) shall be transmitted using the
101*4882a593Smuzhiyun * same rate as the immediately previous frame in the frame exchange
102*4882a593Smuzhiyun * sequence, if this rate belongs to the PHY mandatory rates, or else
103*4882a593Smuzhiyun * at the highest possible rate belonging to the PHY rates in the
104*4882a593Smuzhiyun * BSSBasicRateSet
105*4882a593Smuzhiyun */
106*4882a593Smuzhiyun hdr = (struct ieee80211_hdr *)skb->data;
107*4882a593Smuzhiyun if (ieee80211_is_ctl(hdr->frame_control)) {
108*4882a593Smuzhiyun /* TODO: These control frames are not currently sent by
109*4882a593Smuzhiyun * mac80211, but should they be implemented, this function
110*4882a593Smuzhiyun * needs to be updated to support duration field calculation.
111*4882a593Smuzhiyun *
112*4882a593Smuzhiyun * RTS: time needed to transmit pending data/mgmt frame plus
113*4882a593Smuzhiyun * one CTS frame plus one ACK frame plus 3 x SIFS
114*4882a593Smuzhiyun * CTS: duration of immediately previous RTS minus time
115*4882a593Smuzhiyun * required to transmit CTS and its SIFS
116*4882a593Smuzhiyun * ACK: 0 if immediately previous directed data/mgmt had
117*4882a593Smuzhiyun * more=0, with more=1 duration in ACK frame is duration
118*4882a593Smuzhiyun * from previous frame minus time needed to transmit ACK
119*4882a593Smuzhiyun * and its SIFS
120*4882a593Smuzhiyun * PS Poll: BIT(15) | BIT(14) | aid
121*4882a593Smuzhiyun */
122*4882a593Smuzhiyun return 0;
123*4882a593Smuzhiyun }
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun /* data/mgmt */
126*4882a593Smuzhiyun if (0 /* FIX: data/mgmt during CFP */)
127*4882a593Smuzhiyun return cpu_to_le16(32768);
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun if (group_addr) /* Group address as the destination - no ACK */
130*4882a593Smuzhiyun return 0;
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun /* Individual destination address:
133*4882a593Smuzhiyun * IEEE 802.11, Ch. 9.6 (after IEEE 802.11g changes)
134*4882a593Smuzhiyun * CTS and ACK frames shall be transmitted using the highest rate in
135*4882a593Smuzhiyun * basic rate set that is less than or equal to the rate of the
136*4882a593Smuzhiyun * immediately previous frame and that is using the same modulation
137*4882a593Smuzhiyun * (CCK or OFDM). If no basic rate set matches with these requirements,
138*4882a593Smuzhiyun * the highest mandatory rate of the PHY that is less than or equal to
139*4882a593Smuzhiyun * the rate of the previous frame is used.
140*4882a593Smuzhiyun * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps
141*4882a593Smuzhiyun */
142*4882a593Smuzhiyun rate = -1;
143*4882a593Smuzhiyun /* use lowest available if everything fails */
144*4882a593Smuzhiyun mrate = sband->bitrates[0].bitrate;
145*4882a593Smuzhiyun for (i = 0; i < sband->n_bitrates; i++) {
146*4882a593Smuzhiyun struct ieee80211_rate *r = &sband->bitrates[i];
147*4882a593Smuzhiyun
148*4882a593Smuzhiyun if (r->bitrate > txrate->bitrate)
149*4882a593Smuzhiyun break;
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun if ((rate_flags & r->flags) != rate_flags)
152*4882a593Smuzhiyun continue;
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun if (tx->sdata->vif.bss_conf.basic_rates & BIT(i))
155*4882a593Smuzhiyun rate = DIV_ROUND_UP(r->bitrate, 1 << shift);
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun switch (sband->band) {
158*4882a593Smuzhiyun case NL80211_BAND_2GHZ: {
159*4882a593Smuzhiyun u32 flag;
160*4882a593Smuzhiyun if (tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
161*4882a593Smuzhiyun flag = IEEE80211_RATE_MANDATORY_G;
162*4882a593Smuzhiyun else
163*4882a593Smuzhiyun flag = IEEE80211_RATE_MANDATORY_B;
164*4882a593Smuzhiyun if (r->flags & flag)
165*4882a593Smuzhiyun mrate = r->bitrate;
166*4882a593Smuzhiyun break;
167*4882a593Smuzhiyun }
168*4882a593Smuzhiyun case NL80211_BAND_5GHZ:
169*4882a593Smuzhiyun case NL80211_BAND_6GHZ:
170*4882a593Smuzhiyun if (r->flags & IEEE80211_RATE_MANDATORY_A)
171*4882a593Smuzhiyun mrate = r->bitrate;
172*4882a593Smuzhiyun break;
173*4882a593Smuzhiyun case NL80211_BAND_S1GHZ:
174*4882a593Smuzhiyun case NL80211_BAND_60GHZ:
175*4882a593Smuzhiyun /* TODO, for now fall through */
176*4882a593Smuzhiyun case NUM_NL80211_BANDS:
177*4882a593Smuzhiyun WARN_ON(1);
178*4882a593Smuzhiyun break;
179*4882a593Smuzhiyun }
180*4882a593Smuzhiyun }
181*4882a593Smuzhiyun if (rate == -1) {
182*4882a593Smuzhiyun /* No matching basic rate found; use highest suitable mandatory
183*4882a593Smuzhiyun * PHY rate */
184*4882a593Smuzhiyun rate = DIV_ROUND_UP(mrate, 1 << shift);
185*4882a593Smuzhiyun }
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun /* Don't calculate ACKs for QoS Frames with NoAck Policy set */
188*4882a593Smuzhiyun if (ieee80211_is_data_qos(hdr->frame_control) &&
189*4882a593Smuzhiyun *(ieee80211_get_qos_ctl(hdr)) & IEEE80211_QOS_CTL_ACK_POLICY_NOACK)
190*4882a593Smuzhiyun dur = 0;
191*4882a593Smuzhiyun else
192*4882a593Smuzhiyun /* Time needed to transmit ACK
193*4882a593Smuzhiyun * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up
194*4882a593Smuzhiyun * to closest integer */
195*4882a593Smuzhiyun dur = ieee80211_frame_duration(sband->band, 10, rate, erp,
196*4882a593Smuzhiyun tx->sdata->vif.bss_conf.use_short_preamble,
197*4882a593Smuzhiyun shift);
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun if (next_frag_len) {
200*4882a593Smuzhiyun /* Frame is fragmented: duration increases with time needed to
201*4882a593Smuzhiyun * transmit next fragment plus ACK and 2 x SIFS. */
202*4882a593Smuzhiyun dur *= 2; /* ACK + SIFS */
203*4882a593Smuzhiyun /* next fragment */
204*4882a593Smuzhiyun dur += ieee80211_frame_duration(sband->band, next_frag_len,
205*4882a593Smuzhiyun txrate->bitrate, erp,
206*4882a593Smuzhiyun tx->sdata->vif.bss_conf.use_short_preamble,
207*4882a593Smuzhiyun shift);
208*4882a593Smuzhiyun }
209*4882a593Smuzhiyun
210*4882a593Smuzhiyun return cpu_to_le16(dur);
211*4882a593Smuzhiyun }
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun /* tx handlers */
214*4882a593Smuzhiyun static ieee80211_tx_result debug_noinline
ieee80211_tx_h_dynamic_ps(struct ieee80211_tx_data * tx)215*4882a593Smuzhiyun ieee80211_tx_h_dynamic_ps(struct ieee80211_tx_data *tx)
216*4882a593Smuzhiyun {
217*4882a593Smuzhiyun struct ieee80211_local *local = tx->local;
218*4882a593Smuzhiyun struct ieee80211_if_managed *ifmgd;
219*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
220*4882a593Smuzhiyun
221*4882a593Smuzhiyun /* driver doesn't support power save */
222*4882a593Smuzhiyun if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
223*4882a593Smuzhiyun return TX_CONTINUE;
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun /* hardware does dynamic power save */
226*4882a593Smuzhiyun if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
227*4882a593Smuzhiyun return TX_CONTINUE;
228*4882a593Smuzhiyun
229*4882a593Smuzhiyun /* dynamic power save disabled */
230*4882a593Smuzhiyun if (local->hw.conf.dynamic_ps_timeout <= 0)
231*4882a593Smuzhiyun return TX_CONTINUE;
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun /* we are scanning, don't enable power save */
234*4882a593Smuzhiyun if (local->scanning)
235*4882a593Smuzhiyun return TX_CONTINUE;
236*4882a593Smuzhiyun
237*4882a593Smuzhiyun if (!local->ps_sdata)
238*4882a593Smuzhiyun return TX_CONTINUE;
239*4882a593Smuzhiyun
240*4882a593Smuzhiyun /* No point if we're going to suspend */
241*4882a593Smuzhiyun if (local->quiescing)
242*4882a593Smuzhiyun return TX_CONTINUE;
243*4882a593Smuzhiyun
244*4882a593Smuzhiyun /* dynamic ps is supported only in managed mode */
245*4882a593Smuzhiyun if (tx->sdata->vif.type != NL80211_IFTYPE_STATION)
246*4882a593Smuzhiyun return TX_CONTINUE;
247*4882a593Smuzhiyun
248*4882a593Smuzhiyun if (unlikely(info->flags & IEEE80211_TX_INTFL_OFFCHAN_TX_OK))
249*4882a593Smuzhiyun return TX_CONTINUE;
250*4882a593Smuzhiyun
251*4882a593Smuzhiyun ifmgd = &tx->sdata->u.mgd;
252*4882a593Smuzhiyun
253*4882a593Smuzhiyun /*
254*4882a593Smuzhiyun * Don't wakeup from power save if u-apsd is enabled, voip ac has
255*4882a593Smuzhiyun * u-apsd enabled and the frame is in voip class. This effectively
256*4882a593Smuzhiyun * means that even if all access categories have u-apsd enabled, in
257*4882a593Smuzhiyun * practise u-apsd is only used with the voip ac. This is a
258*4882a593Smuzhiyun * workaround for the case when received voip class packets do not
259*4882a593Smuzhiyun * have correct qos tag for some reason, due the network or the
260*4882a593Smuzhiyun * peer application.
261*4882a593Smuzhiyun *
262*4882a593Smuzhiyun * Note: ifmgd->uapsd_queues access is racy here. If the value is
263*4882a593Smuzhiyun * changed via debugfs, user needs to reassociate manually to have
264*4882a593Smuzhiyun * everything in sync.
265*4882a593Smuzhiyun */
266*4882a593Smuzhiyun if ((ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED) &&
267*4882a593Smuzhiyun (ifmgd->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) &&
268*4882a593Smuzhiyun skb_get_queue_mapping(tx->skb) == IEEE80211_AC_VO)
269*4882a593Smuzhiyun return TX_CONTINUE;
270*4882a593Smuzhiyun
271*4882a593Smuzhiyun if (local->hw.conf.flags & IEEE80211_CONF_PS) {
272*4882a593Smuzhiyun ieee80211_stop_queues_by_reason(&local->hw,
273*4882a593Smuzhiyun IEEE80211_MAX_QUEUE_MAP,
274*4882a593Smuzhiyun IEEE80211_QUEUE_STOP_REASON_PS,
275*4882a593Smuzhiyun false);
276*4882a593Smuzhiyun ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
277*4882a593Smuzhiyun ieee80211_queue_work(&local->hw,
278*4882a593Smuzhiyun &local->dynamic_ps_disable_work);
279*4882a593Smuzhiyun }
280*4882a593Smuzhiyun
281*4882a593Smuzhiyun /* Don't restart the timer if we're not disassociated */
282*4882a593Smuzhiyun if (!ifmgd->associated)
283*4882a593Smuzhiyun return TX_CONTINUE;
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun mod_timer(&local->dynamic_ps_timer, jiffies +
286*4882a593Smuzhiyun msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
287*4882a593Smuzhiyun
288*4882a593Smuzhiyun return TX_CONTINUE;
289*4882a593Smuzhiyun }
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun static ieee80211_tx_result debug_noinline
ieee80211_tx_h_check_assoc(struct ieee80211_tx_data * tx)292*4882a593Smuzhiyun ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
293*4882a593Smuzhiyun {
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
296*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
297*4882a593Smuzhiyun bool assoc = false;
298*4882a593Smuzhiyun
299*4882a593Smuzhiyun if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED))
300*4882a593Smuzhiyun return TX_CONTINUE;
301*4882a593Smuzhiyun
302*4882a593Smuzhiyun if (unlikely(test_bit(SCAN_SW_SCANNING, &tx->local->scanning)) &&
303*4882a593Smuzhiyun test_bit(SDATA_STATE_OFFCHANNEL, &tx->sdata->state) &&
304*4882a593Smuzhiyun !ieee80211_is_probe_req(hdr->frame_control) &&
305*4882a593Smuzhiyun !ieee80211_is_any_nullfunc(hdr->frame_control))
306*4882a593Smuzhiyun /*
307*4882a593Smuzhiyun * When software scanning only nullfunc frames (to notify
308*4882a593Smuzhiyun * the sleep state to the AP) and probe requests (for the
309*4882a593Smuzhiyun * active scan) are allowed, all other frames should not be
310*4882a593Smuzhiyun * sent and we should not get here, but if we do
311*4882a593Smuzhiyun * nonetheless, drop them to avoid sending them
312*4882a593Smuzhiyun * off-channel. See the link below and
313*4882a593Smuzhiyun * ieee80211_start_scan() for more.
314*4882a593Smuzhiyun *
315*4882a593Smuzhiyun * http://article.gmane.org/gmane.linux.kernel.wireless.general/30089
316*4882a593Smuzhiyun */
317*4882a593Smuzhiyun return TX_DROP;
318*4882a593Smuzhiyun
319*4882a593Smuzhiyun if (tx->sdata->vif.type == NL80211_IFTYPE_OCB)
320*4882a593Smuzhiyun return TX_CONTINUE;
321*4882a593Smuzhiyun
322*4882a593Smuzhiyun if (tx->sdata->vif.type == NL80211_IFTYPE_WDS)
323*4882a593Smuzhiyun return TX_CONTINUE;
324*4882a593Smuzhiyun
325*4882a593Smuzhiyun if (tx->flags & IEEE80211_TX_PS_BUFFERED)
326*4882a593Smuzhiyun return TX_CONTINUE;
327*4882a593Smuzhiyun
328*4882a593Smuzhiyun if (tx->sta)
329*4882a593Smuzhiyun assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
330*4882a593Smuzhiyun
331*4882a593Smuzhiyun if (likely(tx->flags & IEEE80211_TX_UNICAST)) {
332*4882a593Smuzhiyun if (unlikely(!assoc &&
333*4882a593Smuzhiyun ieee80211_is_data(hdr->frame_control))) {
334*4882a593Smuzhiyun #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
335*4882a593Smuzhiyun sdata_info(tx->sdata,
336*4882a593Smuzhiyun "dropped data frame to not associated station %pM\n",
337*4882a593Smuzhiyun hdr->addr1);
338*4882a593Smuzhiyun #endif
339*4882a593Smuzhiyun I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
340*4882a593Smuzhiyun return TX_DROP;
341*4882a593Smuzhiyun }
342*4882a593Smuzhiyun } else if (unlikely(ieee80211_is_data(hdr->frame_control) &&
343*4882a593Smuzhiyun ieee80211_vif_get_num_mcast_if(tx->sdata) == 0)) {
344*4882a593Smuzhiyun /*
345*4882a593Smuzhiyun * No associated STAs - no need to send multicast
346*4882a593Smuzhiyun * frames.
347*4882a593Smuzhiyun */
348*4882a593Smuzhiyun return TX_DROP;
349*4882a593Smuzhiyun }
350*4882a593Smuzhiyun
351*4882a593Smuzhiyun return TX_CONTINUE;
352*4882a593Smuzhiyun }
353*4882a593Smuzhiyun
354*4882a593Smuzhiyun /* This function is called whenever the AP is about to exceed the maximum limit
355*4882a593Smuzhiyun * of buffered frames for power saving STAs. This situation should not really
356*4882a593Smuzhiyun * happen often during normal operation, so dropping the oldest buffered packet
357*4882a593Smuzhiyun * from each queue should be OK to make some room for new frames. */
purge_old_ps_buffers(struct ieee80211_local * local)358*4882a593Smuzhiyun static void purge_old_ps_buffers(struct ieee80211_local *local)
359*4882a593Smuzhiyun {
360*4882a593Smuzhiyun int total = 0, purged = 0;
361*4882a593Smuzhiyun struct sk_buff *skb;
362*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata;
363*4882a593Smuzhiyun struct sta_info *sta;
364*4882a593Smuzhiyun
365*4882a593Smuzhiyun list_for_each_entry_rcu(sdata, &local->interfaces, list) {
366*4882a593Smuzhiyun struct ps_data *ps;
367*4882a593Smuzhiyun
368*4882a593Smuzhiyun if (sdata->vif.type == NL80211_IFTYPE_AP)
369*4882a593Smuzhiyun ps = &sdata->u.ap.ps;
370*4882a593Smuzhiyun else if (ieee80211_vif_is_mesh(&sdata->vif))
371*4882a593Smuzhiyun ps = &sdata->u.mesh.ps;
372*4882a593Smuzhiyun else
373*4882a593Smuzhiyun continue;
374*4882a593Smuzhiyun
375*4882a593Smuzhiyun skb = skb_dequeue(&ps->bc_buf);
376*4882a593Smuzhiyun if (skb) {
377*4882a593Smuzhiyun purged++;
378*4882a593Smuzhiyun ieee80211_free_txskb(&local->hw, skb);
379*4882a593Smuzhiyun }
380*4882a593Smuzhiyun total += skb_queue_len(&ps->bc_buf);
381*4882a593Smuzhiyun }
382*4882a593Smuzhiyun
383*4882a593Smuzhiyun /*
384*4882a593Smuzhiyun * Drop one frame from each station from the lowest-priority
385*4882a593Smuzhiyun * AC that has frames at all.
386*4882a593Smuzhiyun */
387*4882a593Smuzhiyun list_for_each_entry_rcu(sta, &local->sta_list, list) {
388*4882a593Smuzhiyun int ac;
389*4882a593Smuzhiyun
390*4882a593Smuzhiyun for (ac = IEEE80211_AC_BK; ac >= IEEE80211_AC_VO; ac--) {
391*4882a593Smuzhiyun skb = skb_dequeue(&sta->ps_tx_buf[ac]);
392*4882a593Smuzhiyun total += skb_queue_len(&sta->ps_tx_buf[ac]);
393*4882a593Smuzhiyun if (skb) {
394*4882a593Smuzhiyun purged++;
395*4882a593Smuzhiyun ieee80211_free_txskb(&local->hw, skb);
396*4882a593Smuzhiyun break;
397*4882a593Smuzhiyun }
398*4882a593Smuzhiyun }
399*4882a593Smuzhiyun }
400*4882a593Smuzhiyun
401*4882a593Smuzhiyun local->total_ps_buffered = total;
402*4882a593Smuzhiyun ps_dbg_hw(&local->hw, "PS buffers full - purged %d frames\n", purged);
403*4882a593Smuzhiyun }
404*4882a593Smuzhiyun
405*4882a593Smuzhiyun static ieee80211_tx_result
ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data * tx)406*4882a593Smuzhiyun ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx)
407*4882a593Smuzhiyun {
408*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
409*4882a593Smuzhiyun struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
410*4882a593Smuzhiyun struct ps_data *ps;
411*4882a593Smuzhiyun
412*4882a593Smuzhiyun /*
413*4882a593Smuzhiyun * broadcast/multicast frame
414*4882a593Smuzhiyun *
415*4882a593Smuzhiyun * If any of the associated/peer stations is in power save mode,
416*4882a593Smuzhiyun * the frame is buffered to be sent after DTIM beacon frame.
417*4882a593Smuzhiyun * This is done either by the hardware or us.
418*4882a593Smuzhiyun */
419*4882a593Smuzhiyun
420*4882a593Smuzhiyun /* powersaving STAs currently only in AP/VLAN/mesh mode */
421*4882a593Smuzhiyun if (tx->sdata->vif.type == NL80211_IFTYPE_AP ||
422*4882a593Smuzhiyun tx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
423*4882a593Smuzhiyun if (!tx->sdata->bss)
424*4882a593Smuzhiyun return TX_CONTINUE;
425*4882a593Smuzhiyun
426*4882a593Smuzhiyun ps = &tx->sdata->bss->ps;
427*4882a593Smuzhiyun } else if (ieee80211_vif_is_mesh(&tx->sdata->vif)) {
428*4882a593Smuzhiyun ps = &tx->sdata->u.mesh.ps;
429*4882a593Smuzhiyun } else {
430*4882a593Smuzhiyun return TX_CONTINUE;
431*4882a593Smuzhiyun }
432*4882a593Smuzhiyun
433*4882a593Smuzhiyun
434*4882a593Smuzhiyun /* no buffering for ordered frames */
435*4882a593Smuzhiyun if (ieee80211_has_order(hdr->frame_control))
436*4882a593Smuzhiyun return TX_CONTINUE;
437*4882a593Smuzhiyun
438*4882a593Smuzhiyun if (ieee80211_is_probe_req(hdr->frame_control))
439*4882a593Smuzhiyun return TX_CONTINUE;
440*4882a593Smuzhiyun
441*4882a593Smuzhiyun if (ieee80211_hw_check(&tx->local->hw, QUEUE_CONTROL))
442*4882a593Smuzhiyun info->hw_queue = tx->sdata->vif.cab_queue;
443*4882a593Smuzhiyun
444*4882a593Smuzhiyun /* no stations in PS mode and no buffered packets */
445*4882a593Smuzhiyun if (!atomic_read(&ps->num_sta_ps) && skb_queue_empty(&ps->bc_buf))
446*4882a593Smuzhiyun return TX_CONTINUE;
447*4882a593Smuzhiyun
448*4882a593Smuzhiyun info->flags |= IEEE80211_TX_CTL_SEND_AFTER_DTIM;
449*4882a593Smuzhiyun
450*4882a593Smuzhiyun /* device releases frame after DTIM beacon */
451*4882a593Smuzhiyun if (!ieee80211_hw_check(&tx->local->hw, HOST_BROADCAST_PS_BUFFERING))
452*4882a593Smuzhiyun return TX_CONTINUE;
453*4882a593Smuzhiyun
454*4882a593Smuzhiyun /* buffered in mac80211 */
455*4882a593Smuzhiyun if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
456*4882a593Smuzhiyun purge_old_ps_buffers(tx->local);
457*4882a593Smuzhiyun
458*4882a593Smuzhiyun if (skb_queue_len(&ps->bc_buf) >= AP_MAX_BC_BUFFER) {
459*4882a593Smuzhiyun ps_dbg(tx->sdata,
460*4882a593Smuzhiyun "BC TX buffer full - dropping the oldest frame\n");
461*4882a593Smuzhiyun ieee80211_free_txskb(&tx->local->hw, skb_dequeue(&ps->bc_buf));
462*4882a593Smuzhiyun } else
463*4882a593Smuzhiyun tx->local->total_ps_buffered++;
464*4882a593Smuzhiyun
465*4882a593Smuzhiyun skb_queue_tail(&ps->bc_buf, tx->skb);
466*4882a593Smuzhiyun
467*4882a593Smuzhiyun return TX_QUEUED;
468*4882a593Smuzhiyun }
469*4882a593Smuzhiyun
ieee80211_use_mfp(__le16 fc,struct sta_info * sta,struct sk_buff * skb)470*4882a593Smuzhiyun static int ieee80211_use_mfp(__le16 fc, struct sta_info *sta,
471*4882a593Smuzhiyun struct sk_buff *skb)
472*4882a593Smuzhiyun {
473*4882a593Smuzhiyun if (!ieee80211_is_mgmt(fc))
474*4882a593Smuzhiyun return 0;
475*4882a593Smuzhiyun
476*4882a593Smuzhiyun if (sta == NULL || !test_sta_flag(sta, WLAN_STA_MFP))
477*4882a593Smuzhiyun return 0;
478*4882a593Smuzhiyun
479*4882a593Smuzhiyun if (!ieee80211_is_robust_mgmt_frame(skb))
480*4882a593Smuzhiyun return 0;
481*4882a593Smuzhiyun
482*4882a593Smuzhiyun return 1;
483*4882a593Smuzhiyun }
484*4882a593Smuzhiyun
485*4882a593Smuzhiyun static ieee80211_tx_result
ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data * tx)486*4882a593Smuzhiyun ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
487*4882a593Smuzhiyun {
488*4882a593Smuzhiyun struct sta_info *sta = tx->sta;
489*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
490*4882a593Smuzhiyun struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
491*4882a593Smuzhiyun struct ieee80211_local *local = tx->local;
492*4882a593Smuzhiyun
493*4882a593Smuzhiyun if (unlikely(!sta))
494*4882a593Smuzhiyun return TX_CONTINUE;
495*4882a593Smuzhiyun
496*4882a593Smuzhiyun if (unlikely((test_sta_flag(sta, WLAN_STA_PS_STA) ||
497*4882a593Smuzhiyun test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
498*4882a593Smuzhiyun test_sta_flag(sta, WLAN_STA_PS_DELIVER)) &&
499*4882a593Smuzhiyun !(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER))) {
500*4882a593Smuzhiyun int ac = skb_get_queue_mapping(tx->skb);
501*4882a593Smuzhiyun
502*4882a593Smuzhiyun if (ieee80211_is_mgmt(hdr->frame_control) &&
503*4882a593Smuzhiyun !ieee80211_is_bufferable_mmpdu(hdr->frame_control)) {
504*4882a593Smuzhiyun info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER;
505*4882a593Smuzhiyun return TX_CONTINUE;
506*4882a593Smuzhiyun }
507*4882a593Smuzhiyun
508*4882a593Smuzhiyun ps_dbg(sta->sdata, "STA %pM aid %d: PS buffer for AC %d\n",
509*4882a593Smuzhiyun sta->sta.addr, sta->sta.aid, ac);
510*4882a593Smuzhiyun if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
511*4882a593Smuzhiyun purge_old_ps_buffers(tx->local);
512*4882a593Smuzhiyun
513*4882a593Smuzhiyun /* sync with ieee80211_sta_ps_deliver_wakeup */
514*4882a593Smuzhiyun spin_lock(&sta->ps_lock);
515*4882a593Smuzhiyun /*
516*4882a593Smuzhiyun * STA woke up the meantime and all the frames on ps_tx_buf have
517*4882a593Smuzhiyun * been queued to pending queue. No reordering can happen, go
518*4882a593Smuzhiyun * ahead and Tx the packet.
519*4882a593Smuzhiyun */
520*4882a593Smuzhiyun if (!test_sta_flag(sta, WLAN_STA_PS_STA) &&
521*4882a593Smuzhiyun !test_sta_flag(sta, WLAN_STA_PS_DRIVER) &&
522*4882a593Smuzhiyun !test_sta_flag(sta, WLAN_STA_PS_DELIVER)) {
523*4882a593Smuzhiyun spin_unlock(&sta->ps_lock);
524*4882a593Smuzhiyun return TX_CONTINUE;
525*4882a593Smuzhiyun }
526*4882a593Smuzhiyun
527*4882a593Smuzhiyun if (skb_queue_len(&sta->ps_tx_buf[ac]) >= STA_MAX_TX_BUFFER) {
528*4882a593Smuzhiyun struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf[ac]);
529*4882a593Smuzhiyun ps_dbg(tx->sdata,
530*4882a593Smuzhiyun "STA %pM TX buffer for AC %d full - dropping oldest frame\n",
531*4882a593Smuzhiyun sta->sta.addr, ac);
532*4882a593Smuzhiyun ieee80211_free_txskb(&local->hw, old);
533*4882a593Smuzhiyun } else
534*4882a593Smuzhiyun tx->local->total_ps_buffered++;
535*4882a593Smuzhiyun
536*4882a593Smuzhiyun info->control.jiffies = jiffies;
537*4882a593Smuzhiyun info->control.vif = &tx->sdata->vif;
538*4882a593Smuzhiyun info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
539*4882a593Smuzhiyun info->flags &= ~IEEE80211_TX_TEMPORARY_FLAGS;
540*4882a593Smuzhiyun skb_queue_tail(&sta->ps_tx_buf[ac], tx->skb);
541*4882a593Smuzhiyun spin_unlock(&sta->ps_lock);
542*4882a593Smuzhiyun
543*4882a593Smuzhiyun if (!timer_pending(&local->sta_cleanup))
544*4882a593Smuzhiyun mod_timer(&local->sta_cleanup,
545*4882a593Smuzhiyun round_jiffies(jiffies +
546*4882a593Smuzhiyun STA_INFO_CLEANUP_INTERVAL));
547*4882a593Smuzhiyun
548*4882a593Smuzhiyun /*
549*4882a593Smuzhiyun * We queued up some frames, so the TIM bit might
550*4882a593Smuzhiyun * need to be set, recalculate it.
551*4882a593Smuzhiyun */
552*4882a593Smuzhiyun sta_info_recalc_tim(sta);
553*4882a593Smuzhiyun
554*4882a593Smuzhiyun return TX_QUEUED;
555*4882a593Smuzhiyun } else if (unlikely(test_sta_flag(sta, WLAN_STA_PS_STA))) {
556*4882a593Smuzhiyun ps_dbg(tx->sdata,
557*4882a593Smuzhiyun "STA %pM in PS mode, but polling/in SP -> send frame\n",
558*4882a593Smuzhiyun sta->sta.addr);
559*4882a593Smuzhiyun }
560*4882a593Smuzhiyun
561*4882a593Smuzhiyun return TX_CONTINUE;
562*4882a593Smuzhiyun }
563*4882a593Smuzhiyun
564*4882a593Smuzhiyun static ieee80211_tx_result debug_noinline
ieee80211_tx_h_ps_buf(struct ieee80211_tx_data * tx)565*4882a593Smuzhiyun ieee80211_tx_h_ps_buf(struct ieee80211_tx_data *tx)
566*4882a593Smuzhiyun {
567*4882a593Smuzhiyun if (unlikely(tx->flags & IEEE80211_TX_PS_BUFFERED))
568*4882a593Smuzhiyun return TX_CONTINUE;
569*4882a593Smuzhiyun
570*4882a593Smuzhiyun if (tx->flags & IEEE80211_TX_UNICAST)
571*4882a593Smuzhiyun return ieee80211_tx_h_unicast_ps_buf(tx);
572*4882a593Smuzhiyun else
573*4882a593Smuzhiyun return ieee80211_tx_h_multicast_ps_buf(tx);
574*4882a593Smuzhiyun }
575*4882a593Smuzhiyun
576*4882a593Smuzhiyun static ieee80211_tx_result debug_noinline
ieee80211_tx_h_check_control_port_protocol(struct ieee80211_tx_data * tx)577*4882a593Smuzhiyun ieee80211_tx_h_check_control_port_protocol(struct ieee80211_tx_data *tx)
578*4882a593Smuzhiyun {
579*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
580*4882a593Smuzhiyun
581*4882a593Smuzhiyun if (unlikely(tx->sdata->control_port_protocol == tx->skb->protocol)) {
582*4882a593Smuzhiyun if (tx->sdata->control_port_no_encrypt)
583*4882a593Smuzhiyun info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
584*4882a593Smuzhiyun info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO;
585*4882a593Smuzhiyun info->flags |= IEEE80211_TX_CTL_USE_MINRATE;
586*4882a593Smuzhiyun }
587*4882a593Smuzhiyun
588*4882a593Smuzhiyun return TX_CONTINUE;
589*4882a593Smuzhiyun }
590*4882a593Smuzhiyun
591*4882a593Smuzhiyun static ieee80211_tx_result debug_noinline
ieee80211_tx_h_select_key(struct ieee80211_tx_data * tx)592*4882a593Smuzhiyun ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
593*4882a593Smuzhiyun {
594*4882a593Smuzhiyun struct ieee80211_key *key;
595*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
596*4882a593Smuzhiyun struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
597*4882a593Smuzhiyun
598*4882a593Smuzhiyun if (unlikely(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)) {
599*4882a593Smuzhiyun tx->key = NULL;
600*4882a593Smuzhiyun return TX_CONTINUE;
601*4882a593Smuzhiyun }
602*4882a593Smuzhiyun
603*4882a593Smuzhiyun if (tx->sta &&
604*4882a593Smuzhiyun (key = rcu_dereference(tx->sta->ptk[tx->sta->ptk_idx])))
605*4882a593Smuzhiyun tx->key = key;
606*4882a593Smuzhiyun else if (ieee80211_is_group_privacy_action(tx->skb) &&
607*4882a593Smuzhiyun (key = rcu_dereference(tx->sdata->default_multicast_key)))
608*4882a593Smuzhiyun tx->key = key;
609*4882a593Smuzhiyun else if (ieee80211_is_mgmt(hdr->frame_control) &&
610*4882a593Smuzhiyun is_multicast_ether_addr(hdr->addr1) &&
611*4882a593Smuzhiyun ieee80211_is_robust_mgmt_frame(tx->skb) &&
612*4882a593Smuzhiyun (key = rcu_dereference(tx->sdata->default_mgmt_key)))
613*4882a593Smuzhiyun tx->key = key;
614*4882a593Smuzhiyun else if (is_multicast_ether_addr(hdr->addr1) &&
615*4882a593Smuzhiyun (key = rcu_dereference(tx->sdata->default_multicast_key)))
616*4882a593Smuzhiyun tx->key = key;
617*4882a593Smuzhiyun else if (!is_multicast_ether_addr(hdr->addr1) &&
618*4882a593Smuzhiyun (key = rcu_dereference(tx->sdata->default_unicast_key)))
619*4882a593Smuzhiyun tx->key = key;
620*4882a593Smuzhiyun else
621*4882a593Smuzhiyun tx->key = NULL;
622*4882a593Smuzhiyun
623*4882a593Smuzhiyun if (tx->key) {
624*4882a593Smuzhiyun bool skip_hw = false;
625*4882a593Smuzhiyun
626*4882a593Smuzhiyun /* TODO: add threshold stuff again */
627*4882a593Smuzhiyun
628*4882a593Smuzhiyun switch (tx->key->conf.cipher) {
629*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_WEP40:
630*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_WEP104:
631*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_TKIP:
632*4882a593Smuzhiyun if (!ieee80211_is_data_present(hdr->frame_control))
633*4882a593Smuzhiyun tx->key = NULL;
634*4882a593Smuzhiyun break;
635*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_CCMP:
636*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_CCMP_256:
637*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_GCMP:
638*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_GCMP_256:
639*4882a593Smuzhiyun if (!ieee80211_is_data_present(hdr->frame_control) &&
640*4882a593Smuzhiyun !ieee80211_use_mfp(hdr->frame_control, tx->sta,
641*4882a593Smuzhiyun tx->skb) &&
642*4882a593Smuzhiyun !ieee80211_is_group_privacy_action(tx->skb))
643*4882a593Smuzhiyun tx->key = NULL;
644*4882a593Smuzhiyun else
645*4882a593Smuzhiyun skip_hw = (tx->key->conf.flags &
646*4882a593Smuzhiyun IEEE80211_KEY_FLAG_SW_MGMT_TX) &&
647*4882a593Smuzhiyun ieee80211_is_mgmt(hdr->frame_control);
648*4882a593Smuzhiyun break;
649*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_AES_CMAC:
650*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_BIP_CMAC_256:
651*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_BIP_GMAC_128:
652*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_BIP_GMAC_256:
653*4882a593Smuzhiyun if (!ieee80211_is_mgmt(hdr->frame_control))
654*4882a593Smuzhiyun tx->key = NULL;
655*4882a593Smuzhiyun break;
656*4882a593Smuzhiyun }
657*4882a593Smuzhiyun
658*4882a593Smuzhiyun if (unlikely(tx->key && tx->key->flags & KEY_FLAG_TAINTED &&
659*4882a593Smuzhiyun !ieee80211_is_deauth(hdr->frame_control)))
660*4882a593Smuzhiyun return TX_DROP;
661*4882a593Smuzhiyun
662*4882a593Smuzhiyun if (!skip_hw && tx->key &&
663*4882a593Smuzhiyun tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
664*4882a593Smuzhiyun info->control.hw_key = &tx->key->conf;
665*4882a593Smuzhiyun } else if (ieee80211_is_data_present(hdr->frame_control) && tx->sta &&
666*4882a593Smuzhiyun test_sta_flag(tx->sta, WLAN_STA_USES_ENCRYPTION)) {
667*4882a593Smuzhiyun return TX_DROP;
668*4882a593Smuzhiyun }
669*4882a593Smuzhiyun
670*4882a593Smuzhiyun return TX_CONTINUE;
671*4882a593Smuzhiyun }
672*4882a593Smuzhiyun
673*4882a593Smuzhiyun static ieee80211_tx_result debug_noinline
ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data * tx)674*4882a593Smuzhiyun ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
675*4882a593Smuzhiyun {
676*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
677*4882a593Smuzhiyun struct ieee80211_hdr *hdr = (void *)tx->skb->data;
678*4882a593Smuzhiyun struct ieee80211_supported_band *sband;
679*4882a593Smuzhiyun u32 len;
680*4882a593Smuzhiyun struct ieee80211_tx_rate_control txrc;
681*4882a593Smuzhiyun struct ieee80211_sta_rates *ratetbl = NULL;
682*4882a593Smuzhiyun bool assoc = false;
683*4882a593Smuzhiyun
684*4882a593Smuzhiyun memset(&txrc, 0, sizeof(txrc));
685*4882a593Smuzhiyun
686*4882a593Smuzhiyun sband = tx->local->hw.wiphy->bands[info->band];
687*4882a593Smuzhiyun
688*4882a593Smuzhiyun len = min_t(u32, tx->skb->len + FCS_LEN,
689*4882a593Smuzhiyun tx->local->hw.wiphy->frag_threshold);
690*4882a593Smuzhiyun
691*4882a593Smuzhiyun /* set up the tx rate control struct we give the RC algo */
692*4882a593Smuzhiyun txrc.hw = &tx->local->hw;
693*4882a593Smuzhiyun txrc.sband = sband;
694*4882a593Smuzhiyun txrc.bss_conf = &tx->sdata->vif.bss_conf;
695*4882a593Smuzhiyun txrc.skb = tx->skb;
696*4882a593Smuzhiyun txrc.reported_rate.idx = -1;
697*4882a593Smuzhiyun txrc.rate_idx_mask = tx->sdata->rc_rateidx_mask[info->band];
698*4882a593Smuzhiyun
699*4882a593Smuzhiyun if (tx->sdata->rc_has_mcs_mask[info->band])
700*4882a593Smuzhiyun txrc.rate_idx_mcs_mask =
701*4882a593Smuzhiyun tx->sdata->rc_rateidx_mcs_mask[info->band];
702*4882a593Smuzhiyun
703*4882a593Smuzhiyun txrc.bss = (tx->sdata->vif.type == NL80211_IFTYPE_AP ||
704*4882a593Smuzhiyun tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
705*4882a593Smuzhiyun tx->sdata->vif.type == NL80211_IFTYPE_ADHOC ||
706*4882a593Smuzhiyun tx->sdata->vif.type == NL80211_IFTYPE_OCB);
707*4882a593Smuzhiyun
708*4882a593Smuzhiyun /* set up RTS protection if desired */
709*4882a593Smuzhiyun if (len > tx->local->hw.wiphy->rts_threshold) {
710*4882a593Smuzhiyun txrc.rts = true;
711*4882a593Smuzhiyun }
712*4882a593Smuzhiyun
713*4882a593Smuzhiyun info->control.use_rts = txrc.rts;
714*4882a593Smuzhiyun info->control.use_cts_prot = tx->sdata->vif.bss_conf.use_cts_prot;
715*4882a593Smuzhiyun
716*4882a593Smuzhiyun /*
717*4882a593Smuzhiyun * Use short preamble if the BSS can handle it, but not for
718*4882a593Smuzhiyun * management frames unless we know the receiver can handle
719*4882a593Smuzhiyun * that -- the management frame might be to a station that
720*4882a593Smuzhiyun * just wants a probe response.
721*4882a593Smuzhiyun */
722*4882a593Smuzhiyun if (tx->sdata->vif.bss_conf.use_short_preamble &&
723*4882a593Smuzhiyun (ieee80211_is_data(hdr->frame_control) ||
724*4882a593Smuzhiyun (tx->sta && test_sta_flag(tx->sta, WLAN_STA_SHORT_PREAMBLE))))
725*4882a593Smuzhiyun txrc.short_preamble = true;
726*4882a593Smuzhiyun
727*4882a593Smuzhiyun info->control.short_preamble = txrc.short_preamble;
728*4882a593Smuzhiyun
729*4882a593Smuzhiyun /* don't ask rate control when rate already injected via radiotap */
730*4882a593Smuzhiyun if (info->control.flags & IEEE80211_TX_CTRL_RATE_INJECT)
731*4882a593Smuzhiyun return TX_CONTINUE;
732*4882a593Smuzhiyun
733*4882a593Smuzhiyun if (tx->sta)
734*4882a593Smuzhiyun assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
735*4882a593Smuzhiyun
736*4882a593Smuzhiyun /*
737*4882a593Smuzhiyun * Lets not bother rate control if we're associated and cannot
738*4882a593Smuzhiyun * talk to the sta. This should not happen.
739*4882a593Smuzhiyun */
740*4882a593Smuzhiyun if (WARN(test_bit(SCAN_SW_SCANNING, &tx->local->scanning) && assoc &&
741*4882a593Smuzhiyun !rate_usable_index_exists(sband, &tx->sta->sta),
742*4882a593Smuzhiyun "%s: Dropped data frame as no usable bitrate found while "
743*4882a593Smuzhiyun "scanning and associated. Target station: "
744*4882a593Smuzhiyun "%pM on %d GHz band\n",
745*4882a593Smuzhiyun tx->sdata->name, hdr->addr1,
746*4882a593Smuzhiyun info->band ? 5 : 2))
747*4882a593Smuzhiyun return TX_DROP;
748*4882a593Smuzhiyun
749*4882a593Smuzhiyun /*
750*4882a593Smuzhiyun * If we're associated with the sta at this point we know we can at
751*4882a593Smuzhiyun * least send the frame at the lowest bit rate.
752*4882a593Smuzhiyun */
753*4882a593Smuzhiyun rate_control_get_rate(tx->sdata, tx->sta, &txrc);
754*4882a593Smuzhiyun
755*4882a593Smuzhiyun if (tx->sta && !info->control.skip_table)
756*4882a593Smuzhiyun ratetbl = rcu_dereference(tx->sta->sta.rates);
757*4882a593Smuzhiyun
758*4882a593Smuzhiyun if (unlikely(info->control.rates[0].idx < 0)) {
759*4882a593Smuzhiyun if (ratetbl) {
760*4882a593Smuzhiyun struct ieee80211_tx_rate rate = {
761*4882a593Smuzhiyun .idx = ratetbl->rate[0].idx,
762*4882a593Smuzhiyun .flags = ratetbl->rate[0].flags,
763*4882a593Smuzhiyun .count = ratetbl->rate[0].count
764*4882a593Smuzhiyun };
765*4882a593Smuzhiyun
766*4882a593Smuzhiyun if (ratetbl->rate[0].idx < 0)
767*4882a593Smuzhiyun return TX_DROP;
768*4882a593Smuzhiyun
769*4882a593Smuzhiyun tx->rate = rate;
770*4882a593Smuzhiyun } else {
771*4882a593Smuzhiyun return TX_DROP;
772*4882a593Smuzhiyun }
773*4882a593Smuzhiyun } else {
774*4882a593Smuzhiyun tx->rate = info->control.rates[0];
775*4882a593Smuzhiyun }
776*4882a593Smuzhiyun
777*4882a593Smuzhiyun if (txrc.reported_rate.idx < 0) {
778*4882a593Smuzhiyun txrc.reported_rate = tx->rate;
779*4882a593Smuzhiyun if (tx->sta && ieee80211_is_data(hdr->frame_control))
780*4882a593Smuzhiyun tx->sta->tx_stats.last_rate = txrc.reported_rate;
781*4882a593Smuzhiyun } else if (tx->sta)
782*4882a593Smuzhiyun tx->sta->tx_stats.last_rate = txrc.reported_rate;
783*4882a593Smuzhiyun
784*4882a593Smuzhiyun if (ratetbl)
785*4882a593Smuzhiyun return TX_CONTINUE;
786*4882a593Smuzhiyun
787*4882a593Smuzhiyun if (unlikely(!info->control.rates[0].count))
788*4882a593Smuzhiyun info->control.rates[0].count = 1;
789*4882a593Smuzhiyun
790*4882a593Smuzhiyun if (WARN_ON_ONCE((info->control.rates[0].count > 1) &&
791*4882a593Smuzhiyun (info->flags & IEEE80211_TX_CTL_NO_ACK)))
792*4882a593Smuzhiyun info->control.rates[0].count = 1;
793*4882a593Smuzhiyun
794*4882a593Smuzhiyun return TX_CONTINUE;
795*4882a593Smuzhiyun }
796*4882a593Smuzhiyun
ieee80211_tx_next_seq(struct sta_info * sta,int tid)797*4882a593Smuzhiyun static __le16 ieee80211_tx_next_seq(struct sta_info *sta, int tid)
798*4882a593Smuzhiyun {
799*4882a593Smuzhiyun u16 *seq = &sta->tid_seq[tid];
800*4882a593Smuzhiyun __le16 ret = cpu_to_le16(*seq);
801*4882a593Smuzhiyun
802*4882a593Smuzhiyun /* Increase the sequence number. */
803*4882a593Smuzhiyun *seq = (*seq + 0x10) & IEEE80211_SCTL_SEQ;
804*4882a593Smuzhiyun
805*4882a593Smuzhiyun return ret;
806*4882a593Smuzhiyun }
807*4882a593Smuzhiyun
808*4882a593Smuzhiyun static ieee80211_tx_result debug_noinline
ieee80211_tx_h_sequence(struct ieee80211_tx_data * tx)809*4882a593Smuzhiyun ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx)
810*4882a593Smuzhiyun {
811*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
812*4882a593Smuzhiyun struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
813*4882a593Smuzhiyun int tid;
814*4882a593Smuzhiyun
815*4882a593Smuzhiyun /*
816*4882a593Smuzhiyun * Packet injection may want to control the sequence
817*4882a593Smuzhiyun * number, if we have no matching interface then we
818*4882a593Smuzhiyun * neither assign one ourselves nor ask the driver to.
819*4882a593Smuzhiyun */
820*4882a593Smuzhiyun if (unlikely(info->control.vif->type == NL80211_IFTYPE_MONITOR))
821*4882a593Smuzhiyun return TX_CONTINUE;
822*4882a593Smuzhiyun
823*4882a593Smuzhiyun if (unlikely(ieee80211_is_ctl(hdr->frame_control)))
824*4882a593Smuzhiyun return TX_CONTINUE;
825*4882a593Smuzhiyun
826*4882a593Smuzhiyun if (ieee80211_hdrlen(hdr->frame_control) < 24)
827*4882a593Smuzhiyun return TX_CONTINUE;
828*4882a593Smuzhiyun
829*4882a593Smuzhiyun if (ieee80211_is_qos_nullfunc(hdr->frame_control))
830*4882a593Smuzhiyun return TX_CONTINUE;
831*4882a593Smuzhiyun
832*4882a593Smuzhiyun if (info->control.flags & IEEE80211_TX_CTRL_NO_SEQNO)
833*4882a593Smuzhiyun return TX_CONTINUE;
834*4882a593Smuzhiyun
835*4882a593Smuzhiyun /*
836*4882a593Smuzhiyun * Anything but QoS data that has a sequence number field
837*4882a593Smuzhiyun * (is long enough) gets a sequence number from the global
838*4882a593Smuzhiyun * counter. QoS data frames with a multicast destination
839*4882a593Smuzhiyun * also use the global counter (802.11-2012 9.3.2.10).
840*4882a593Smuzhiyun */
841*4882a593Smuzhiyun if (!ieee80211_is_data_qos(hdr->frame_control) ||
842*4882a593Smuzhiyun is_multicast_ether_addr(hdr->addr1)) {
843*4882a593Smuzhiyun /* driver should assign sequence number */
844*4882a593Smuzhiyun info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
845*4882a593Smuzhiyun /* for pure STA mode without beacons, we can do it */
846*4882a593Smuzhiyun hdr->seq_ctrl = cpu_to_le16(tx->sdata->sequence_number);
847*4882a593Smuzhiyun tx->sdata->sequence_number += 0x10;
848*4882a593Smuzhiyun if (tx->sta)
849*4882a593Smuzhiyun tx->sta->tx_stats.msdu[IEEE80211_NUM_TIDS]++;
850*4882a593Smuzhiyun return TX_CONTINUE;
851*4882a593Smuzhiyun }
852*4882a593Smuzhiyun
853*4882a593Smuzhiyun /*
854*4882a593Smuzhiyun * This should be true for injected/management frames only, for
855*4882a593Smuzhiyun * management frames we have set the IEEE80211_TX_CTL_ASSIGN_SEQ
856*4882a593Smuzhiyun * above since they are not QoS-data frames.
857*4882a593Smuzhiyun */
858*4882a593Smuzhiyun if (!tx->sta)
859*4882a593Smuzhiyun return TX_CONTINUE;
860*4882a593Smuzhiyun
861*4882a593Smuzhiyun /* include per-STA, per-TID sequence counter */
862*4882a593Smuzhiyun tid = ieee80211_get_tid(hdr);
863*4882a593Smuzhiyun tx->sta->tx_stats.msdu[tid]++;
864*4882a593Smuzhiyun
865*4882a593Smuzhiyun hdr->seq_ctrl = ieee80211_tx_next_seq(tx->sta, tid);
866*4882a593Smuzhiyun
867*4882a593Smuzhiyun return TX_CONTINUE;
868*4882a593Smuzhiyun }
869*4882a593Smuzhiyun
ieee80211_fragment(struct ieee80211_tx_data * tx,struct sk_buff * skb,int hdrlen,int frag_threshold)870*4882a593Smuzhiyun static int ieee80211_fragment(struct ieee80211_tx_data *tx,
871*4882a593Smuzhiyun struct sk_buff *skb, int hdrlen,
872*4882a593Smuzhiyun int frag_threshold)
873*4882a593Smuzhiyun {
874*4882a593Smuzhiyun struct ieee80211_local *local = tx->local;
875*4882a593Smuzhiyun struct ieee80211_tx_info *info;
876*4882a593Smuzhiyun struct sk_buff *tmp;
877*4882a593Smuzhiyun int per_fragm = frag_threshold - hdrlen - FCS_LEN;
878*4882a593Smuzhiyun int pos = hdrlen + per_fragm;
879*4882a593Smuzhiyun int rem = skb->len - hdrlen - per_fragm;
880*4882a593Smuzhiyun
881*4882a593Smuzhiyun if (WARN_ON(rem < 0))
882*4882a593Smuzhiyun return -EINVAL;
883*4882a593Smuzhiyun
884*4882a593Smuzhiyun /* first fragment was already added to queue by caller */
885*4882a593Smuzhiyun
886*4882a593Smuzhiyun while (rem) {
887*4882a593Smuzhiyun int fraglen = per_fragm;
888*4882a593Smuzhiyun
889*4882a593Smuzhiyun if (fraglen > rem)
890*4882a593Smuzhiyun fraglen = rem;
891*4882a593Smuzhiyun rem -= fraglen;
892*4882a593Smuzhiyun tmp = dev_alloc_skb(local->tx_headroom +
893*4882a593Smuzhiyun frag_threshold +
894*4882a593Smuzhiyun tx->sdata->encrypt_headroom +
895*4882a593Smuzhiyun IEEE80211_ENCRYPT_TAILROOM);
896*4882a593Smuzhiyun if (!tmp)
897*4882a593Smuzhiyun return -ENOMEM;
898*4882a593Smuzhiyun
899*4882a593Smuzhiyun __skb_queue_tail(&tx->skbs, tmp);
900*4882a593Smuzhiyun
901*4882a593Smuzhiyun skb_reserve(tmp,
902*4882a593Smuzhiyun local->tx_headroom + tx->sdata->encrypt_headroom);
903*4882a593Smuzhiyun
904*4882a593Smuzhiyun /* copy control information */
905*4882a593Smuzhiyun memcpy(tmp->cb, skb->cb, sizeof(tmp->cb));
906*4882a593Smuzhiyun
907*4882a593Smuzhiyun info = IEEE80211_SKB_CB(tmp);
908*4882a593Smuzhiyun info->flags &= ~(IEEE80211_TX_CTL_CLEAR_PS_FILT |
909*4882a593Smuzhiyun IEEE80211_TX_CTL_FIRST_FRAGMENT);
910*4882a593Smuzhiyun
911*4882a593Smuzhiyun if (rem)
912*4882a593Smuzhiyun info->flags |= IEEE80211_TX_CTL_MORE_FRAMES;
913*4882a593Smuzhiyun
914*4882a593Smuzhiyun skb_copy_queue_mapping(tmp, skb);
915*4882a593Smuzhiyun tmp->priority = skb->priority;
916*4882a593Smuzhiyun tmp->dev = skb->dev;
917*4882a593Smuzhiyun
918*4882a593Smuzhiyun /* copy header and data */
919*4882a593Smuzhiyun skb_put_data(tmp, skb->data, hdrlen);
920*4882a593Smuzhiyun skb_put_data(tmp, skb->data + pos, fraglen);
921*4882a593Smuzhiyun
922*4882a593Smuzhiyun pos += fraglen;
923*4882a593Smuzhiyun }
924*4882a593Smuzhiyun
925*4882a593Smuzhiyun /* adjust first fragment's length */
926*4882a593Smuzhiyun skb_trim(skb, hdrlen + per_fragm);
927*4882a593Smuzhiyun return 0;
928*4882a593Smuzhiyun }
929*4882a593Smuzhiyun
930*4882a593Smuzhiyun static ieee80211_tx_result debug_noinline
ieee80211_tx_h_fragment(struct ieee80211_tx_data * tx)931*4882a593Smuzhiyun ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
932*4882a593Smuzhiyun {
933*4882a593Smuzhiyun struct sk_buff *skb = tx->skb;
934*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
935*4882a593Smuzhiyun struct ieee80211_hdr *hdr = (void *)skb->data;
936*4882a593Smuzhiyun int frag_threshold = tx->local->hw.wiphy->frag_threshold;
937*4882a593Smuzhiyun int hdrlen;
938*4882a593Smuzhiyun int fragnum;
939*4882a593Smuzhiyun
940*4882a593Smuzhiyun /* no matter what happens, tx->skb moves to tx->skbs */
941*4882a593Smuzhiyun __skb_queue_tail(&tx->skbs, skb);
942*4882a593Smuzhiyun tx->skb = NULL;
943*4882a593Smuzhiyun
944*4882a593Smuzhiyun if (info->flags & IEEE80211_TX_CTL_DONTFRAG)
945*4882a593Smuzhiyun return TX_CONTINUE;
946*4882a593Smuzhiyun
947*4882a593Smuzhiyun if (ieee80211_hw_check(&tx->local->hw, SUPPORTS_TX_FRAG))
948*4882a593Smuzhiyun return TX_CONTINUE;
949*4882a593Smuzhiyun
950*4882a593Smuzhiyun /*
951*4882a593Smuzhiyun * Warn when submitting a fragmented A-MPDU frame and drop it.
952*4882a593Smuzhiyun * This scenario is handled in ieee80211_tx_prepare but extra
953*4882a593Smuzhiyun * caution taken here as fragmented ampdu may cause Tx stop.
954*4882a593Smuzhiyun */
955*4882a593Smuzhiyun if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU))
956*4882a593Smuzhiyun return TX_DROP;
957*4882a593Smuzhiyun
958*4882a593Smuzhiyun hdrlen = ieee80211_hdrlen(hdr->frame_control);
959*4882a593Smuzhiyun
960*4882a593Smuzhiyun /* internal error, why isn't DONTFRAG set? */
961*4882a593Smuzhiyun if (WARN_ON(skb->len + FCS_LEN <= frag_threshold))
962*4882a593Smuzhiyun return TX_DROP;
963*4882a593Smuzhiyun
964*4882a593Smuzhiyun /*
965*4882a593Smuzhiyun * Now fragment the frame. This will allocate all the fragments and
966*4882a593Smuzhiyun * chain them (using skb as the first fragment) to skb->next.
967*4882a593Smuzhiyun * During transmission, we will remove the successfully transmitted
968*4882a593Smuzhiyun * fragments from this list. When the low-level driver rejects one
969*4882a593Smuzhiyun * of the fragments then we will simply pretend to accept the skb
970*4882a593Smuzhiyun * but store it away as pending.
971*4882a593Smuzhiyun */
972*4882a593Smuzhiyun if (ieee80211_fragment(tx, skb, hdrlen, frag_threshold))
973*4882a593Smuzhiyun return TX_DROP;
974*4882a593Smuzhiyun
975*4882a593Smuzhiyun /* update duration/seq/flags of fragments */
976*4882a593Smuzhiyun fragnum = 0;
977*4882a593Smuzhiyun
978*4882a593Smuzhiyun skb_queue_walk(&tx->skbs, skb) {
979*4882a593Smuzhiyun const __le16 morefrags = cpu_to_le16(IEEE80211_FCTL_MOREFRAGS);
980*4882a593Smuzhiyun
981*4882a593Smuzhiyun hdr = (void *)skb->data;
982*4882a593Smuzhiyun info = IEEE80211_SKB_CB(skb);
983*4882a593Smuzhiyun
984*4882a593Smuzhiyun if (!skb_queue_is_last(&tx->skbs, skb)) {
985*4882a593Smuzhiyun hdr->frame_control |= morefrags;
986*4882a593Smuzhiyun /*
987*4882a593Smuzhiyun * No multi-rate retries for fragmented frames, that
988*4882a593Smuzhiyun * would completely throw off the NAV at other STAs.
989*4882a593Smuzhiyun */
990*4882a593Smuzhiyun info->control.rates[1].idx = -1;
991*4882a593Smuzhiyun info->control.rates[2].idx = -1;
992*4882a593Smuzhiyun info->control.rates[3].idx = -1;
993*4882a593Smuzhiyun BUILD_BUG_ON(IEEE80211_TX_MAX_RATES != 4);
994*4882a593Smuzhiyun info->flags &= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE;
995*4882a593Smuzhiyun } else {
996*4882a593Smuzhiyun hdr->frame_control &= ~morefrags;
997*4882a593Smuzhiyun }
998*4882a593Smuzhiyun hdr->seq_ctrl |= cpu_to_le16(fragnum & IEEE80211_SCTL_FRAG);
999*4882a593Smuzhiyun fragnum++;
1000*4882a593Smuzhiyun }
1001*4882a593Smuzhiyun
1002*4882a593Smuzhiyun return TX_CONTINUE;
1003*4882a593Smuzhiyun }
1004*4882a593Smuzhiyun
1005*4882a593Smuzhiyun static ieee80211_tx_result debug_noinline
ieee80211_tx_h_stats(struct ieee80211_tx_data * tx)1006*4882a593Smuzhiyun ieee80211_tx_h_stats(struct ieee80211_tx_data *tx)
1007*4882a593Smuzhiyun {
1008*4882a593Smuzhiyun struct sk_buff *skb;
1009*4882a593Smuzhiyun int ac = -1;
1010*4882a593Smuzhiyun
1011*4882a593Smuzhiyun if (!tx->sta)
1012*4882a593Smuzhiyun return TX_CONTINUE;
1013*4882a593Smuzhiyun
1014*4882a593Smuzhiyun skb_queue_walk(&tx->skbs, skb) {
1015*4882a593Smuzhiyun ac = skb_get_queue_mapping(skb);
1016*4882a593Smuzhiyun tx->sta->tx_stats.bytes[ac] += skb->len;
1017*4882a593Smuzhiyun }
1018*4882a593Smuzhiyun if (ac >= 0)
1019*4882a593Smuzhiyun tx->sta->tx_stats.packets[ac]++;
1020*4882a593Smuzhiyun
1021*4882a593Smuzhiyun return TX_CONTINUE;
1022*4882a593Smuzhiyun }
1023*4882a593Smuzhiyun
1024*4882a593Smuzhiyun static ieee80211_tx_result debug_noinline
ieee80211_tx_h_encrypt(struct ieee80211_tx_data * tx)1025*4882a593Smuzhiyun ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx)
1026*4882a593Smuzhiyun {
1027*4882a593Smuzhiyun if (!tx->key)
1028*4882a593Smuzhiyun return TX_CONTINUE;
1029*4882a593Smuzhiyun
1030*4882a593Smuzhiyun switch (tx->key->conf.cipher) {
1031*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_WEP40:
1032*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_WEP104:
1033*4882a593Smuzhiyun return ieee80211_crypto_wep_encrypt(tx);
1034*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_TKIP:
1035*4882a593Smuzhiyun return ieee80211_crypto_tkip_encrypt(tx);
1036*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_CCMP:
1037*4882a593Smuzhiyun return ieee80211_crypto_ccmp_encrypt(
1038*4882a593Smuzhiyun tx, IEEE80211_CCMP_MIC_LEN);
1039*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_CCMP_256:
1040*4882a593Smuzhiyun return ieee80211_crypto_ccmp_encrypt(
1041*4882a593Smuzhiyun tx, IEEE80211_CCMP_256_MIC_LEN);
1042*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_AES_CMAC:
1043*4882a593Smuzhiyun return ieee80211_crypto_aes_cmac_encrypt(tx);
1044*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_BIP_CMAC_256:
1045*4882a593Smuzhiyun return ieee80211_crypto_aes_cmac_256_encrypt(tx);
1046*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_BIP_GMAC_128:
1047*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_BIP_GMAC_256:
1048*4882a593Smuzhiyun return ieee80211_crypto_aes_gmac_encrypt(tx);
1049*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_GCMP:
1050*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_GCMP_256:
1051*4882a593Smuzhiyun return ieee80211_crypto_gcmp_encrypt(tx);
1052*4882a593Smuzhiyun default:
1053*4882a593Smuzhiyun return ieee80211_crypto_hw_encrypt(tx);
1054*4882a593Smuzhiyun }
1055*4882a593Smuzhiyun
1056*4882a593Smuzhiyun return TX_DROP;
1057*4882a593Smuzhiyun }
1058*4882a593Smuzhiyun
1059*4882a593Smuzhiyun static ieee80211_tx_result debug_noinline
ieee80211_tx_h_calculate_duration(struct ieee80211_tx_data * tx)1060*4882a593Smuzhiyun ieee80211_tx_h_calculate_duration(struct ieee80211_tx_data *tx)
1061*4882a593Smuzhiyun {
1062*4882a593Smuzhiyun struct sk_buff *skb;
1063*4882a593Smuzhiyun struct ieee80211_hdr *hdr;
1064*4882a593Smuzhiyun int next_len;
1065*4882a593Smuzhiyun bool group_addr;
1066*4882a593Smuzhiyun
1067*4882a593Smuzhiyun skb_queue_walk(&tx->skbs, skb) {
1068*4882a593Smuzhiyun hdr = (void *) skb->data;
1069*4882a593Smuzhiyun if (unlikely(ieee80211_is_pspoll(hdr->frame_control)))
1070*4882a593Smuzhiyun break; /* must not overwrite AID */
1071*4882a593Smuzhiyun if (!skb_queue_is_last(&tx->skbs, skb)) {
1072*4882a593Smuzhiyun struct sk_buff *next = skb_queue_next(&tx->skbs, skb);
1073*4882a593Smuzhiyun next_len = next->len;
1074*4882a593Smuzhiyun } else
1075*4882a593Smuzhiyun next_len = 0;
1076*4882a593Smuzhiyun group_addr = is_multicast_ether_addr(hdr->addr1);
1077*4882a593Smuzhiyun
1078*4882a593Smuzhiyun hdr->duration_id =
1079*4882a593Smuzhiyun ieee80211_duration(tx, skb, group_addr, next_len);
1080*4882a593Smuzhiyun }
1081*4882a593Smuzhiyun
1082*4882a593Smuzhiyun return TX_CONTINUE;
1083*4882a593Smuzhiyun }
1084*4882a593Smuzhiyun
1085*4882a593Smuzhiyun /* actual transmit path */
1086*4882a593Smuzhiyun
ieee80211_tx_prep_agg(struct ieee80211_tx_data * tx,struct sk_buff * skb,struct ieee80211_tx_info * info,struct tid_ampdu_tx * tid_tx,int tid)1087*4882a593Smuzhiyun static bool ieee80211_tx_prep_agg(struct ieee80211_tx_data *tx,
1088*4882a593Smuzhiyun struct sk_buff *skb,
1089*4882a593Smuzhiyun struct ieee80211_tx_info *info,
1090*4882a593Smuzhiyun struct tid_ampdu_tx *tid_tx,
1091*4882a593Smuzhiyun int tid)
1092*4882a593Smuzhiyun {
1093*4882a593Smuzhiyun bool queued = false;
1094*4882a593Smuzhiyun bool reset_agg_timer = false;
1095*4882a593Smuzhiyun struct sk_buff *purge_skb = NULL;
1096*4882a593Smuzhiyun
1097*4882a593Smuzhiyun if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
1098*4882a593Smuzhiyun info->flags |= IEEE80211_TX_CTL_AMPDU;
1099*4882a593Smuzhiyun reset_agg_timer = true;
1100*4882a593Smuzhiyun } else if (test_bit(HT_AGG_STATE_WANT_START, &tid_tx->state)) {
1101*4882a593Smuzhiyun /*
1102*4882a593Smuzhiyun * nothing -- this aggregation session is being started
1103*4882a593Smuzhiyun * but that might still fail with the driver
1104*4882a593Smuzhiyun */
1105*4882a593Smuzhiyun } else if (!tx->sta->sta.txq[tid]) {
1106*4882a593Smuzhiyun spin_lock(&tx->sta->lock);
1107*4882a593Smuzhiyun /*
1108*4882a593Smuzhiyun * Need to re-check now, because we may get here
1109*4882a593Smuzhiyun *
1110*4882a593Smuzhiyun * 1) in the window during which the setup is actually
1111*4882a593Smuzhiyun * already done, but not marked yet because not all
1112*4882a593Smuzhiyun * packets are spliced over to the driver pending
1113*4882a593Smuzhiyun * queue yet -- if this happened we acquire the lock
1114*4882a593Smuzhiyun * either before or after the splice happens, but
1115*4882a593Smuzhiyun * need to recheck which of these cases happened.
1116*4882a593Smuzhiyun *
1117*4882a593Smuzhiyun * 2) during session teardown, if the OPERATIONAL bit
1118*4882a593Smuzhiyun * was cleared due to the teardown but the pointer
1119*4882a593Smuzhiyun * hasn't been assigned NULL yet (or we loaded it
1120*4882a593Smuzhiyun * before it was assigned) -- in this case it may
1121*4882a593Smuzhiyun * now be NULL which means we should just let the
1122*4882a593Smuzhiyun * packet pass through because splicing the frames
1123*4882a593Smuzhiyun * back is already done.
1124*4882a593Smuzhiyun */
1125*4882a593Smuzhiyun tid_tx = rcu_dereference_protected_tid_tx(tx->sta, tid);
1126*4882a593Smuzhiyun
1127*4882a593Smuzhiyun if (!tid_tx) {
1128*4882a593Smuzhiyun /* do nothing, let packet pass through */
1129*4882a593Smuzhiyun } else if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
1130*4882a593Smuzhiyun info->flags |= IEEE80211_TX_CTL_AMPDU;
1131*4882a593Smuzhiyun reset_agg_timer = true;
1132*4882a593Smuzhiyun } else {
1133*4882a593Smuzhiyun queued = true;
1134*4882a593Smuzhiyun if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER) {
1135*4882a593Smuzhiyun clear_sta_flag(tx->sta, WLAN_STA_SP);
1136*4882a593Smuzhiyun ps_dbg(tx->sta->sdata,
1137*4882a593Smuzhiyun "STA %pM aid %d: SP frame queued, close the SP w/o telling the peer\n",
1138*4882a593Smuzhiyun tx->sta->sta.addr, tx->sta->sta.aid);
1139*4882a593Smuzhiyun }
1140*4882a593Smuzhiyun info->control.vif = &tx->sdata->vif;
1141*4882a593Smuzhiyun info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
1142*4882a593Smuzhiyun info->flags &= ~IEEE80211_TX_TEMPORARY_FLAGS;
1143*4882a593Smuzhiyun __skb_queue_tail(&tid_tx->pending, skb);
1144*4882a593Smuzhiyun if (skb_queue_len(&tid_tx->pending) > STA_MAX_TX_BUFFER)
1145*4882a593Smuzhiyun purge_skb = __skb_dequeue(&tid_tx->pending);
1146*4882a593Smuzhiyun }
1147*4882a593Smuzhiyun spin_unlock(&tx->sta->lock);
1148*4882a593Smuzhiyun
1149*4882a593Smuzhiyun if (purge_skb)
1150*4882a593Smuzhiyun ieee80211_free_txskb(&tx->local->hw, purge_skb);
1151*4882a593Smuzhiyun }
1152*4882a593Smuzhiyun
1153*4882a593Smuzhiyun /* reset session timer */
1154*4882a593Smuzhiyun if (reset_agg_timer)
1155*4882a593Smuzhiyun tid_tx->last_tx = jiffies;
1156*4882a593Smuzhiyun
1157*4882a593Smuzhiyun return queued;
1158*4882a593Smuzhiyun }
1159*4882a593Smuzhiyun
1160*4882a593Smuzhiyun /*
1161*4882a593Smuzhiyun * initialises @tx
1162*4882a593Smuzhiyun * pass %NULL for the station if unknown, a valid pointer if known
1163*4882a593Smuzhiyun * or an ERR_PTR() if the station is known not to exist
1164*4882a593Smuzhiyun */
1165*4882a593Smuzhiyun static ieee80211_tx_result
ieee80211_tx_prepare(struct ieee80211_sub_if_data * sdata,struct ieee80211_tx_data * tx,struct sta_info * sta,struct sk_buff * skb)1166*4882a593Smuzhiyun ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata,
1167*4882a593Smuzhiyun struct ieee80211_tx_data *tx,
1168*4882a593Smuzhiyun struct sta_info *sta, struct sk_buff *skb)
1169*4882a593Smuzhiyun {
1170*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
1171*4882a593Smuzhiyun struct ieee80211_hdr *hdr;
1172*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1173*4882a593Smuzhiyun int tid;
1174*4882a593Smuzhiyun
1175*4882a593Smuzhiyun memset(tx, 0, sizeof(*tx));
1176*4882a593Smuzhiyun tx->skb = skb;
1177*4882a593Smuzhiyun tx->local = local;
1178*4882a593Smuzhiyun tx->sdata = sdata;
1179*4882a593Smuzhiyun __skb_queue_head_init(&tx->skbs);
1180*4882a593Smuzhiyun
1181*4882a593Smuzhiyun /*
1182*4882a593Smuzhiyun * If this flag is set to true anywhere, and we get here,
1183*4882a593Smuzhiyun * we are doing the needed processing, so remove the flag
1184*4882a593Smuzhiyun * now.
1185*4882a593Smuzhiyun */
1186*4882a593Smuzhiyun info->control.flags &= ~IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
1187*4882a593Smuzhiyun
1188*4882a593Smuzhiyun hdr = (struct ieee80211_hdr *) skb->data;
1189*4882a593Smuzhiyun
1190*4882a593Smuzhiyun if (likely(sta)) {
1191*4882a593Smuzhiyun if (!IS_ERR(sta))
1192*4882a593Smuzhiyun tx->sta = sta;
1193*4882a593Smuzhiyun } else {
1194*4882a593Smuzhiyun if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
1195*4882a593Smuzhiyun tx->sta = rcu_dereference(sdata->u.vlan.sta);
1196*4882a593Smuzhiyun if (!tx->sta && sdata->wdev.use_4addr)
1197*4882a593Smuzhiyun return TX_DROP;
1198*4882a593Smuzhiyun } else if (info->flags & (IEEE80211_TX_INTFL_NL80211_FRAME_TX |
1199*4882a593Smuzhiyun IEEE80211_TX_CTL_INJECTED) ||
1200*4882a593Smuzhiyun tx->sdata->control_port_protocol == tx->skb->protocol) {
1201*4882a593Smuzhiyun tx->sta = sta_info_get_bss(sdata, hdr->addr1);
1202*4882a593Smuzhiyun }
1203*4882a593Smuzhiyun if (!tx->sta && !is_multicast_ether_addr(hdr->addr1))
1204*4882a593Smuzhiyun tx->sta = sta_info_get(sdata, hdr->addr1);
1205*4882a593Smuzhiyun }
1206*4882a593Smuzhiyun
1207*4882a593Smuzhiyun if (tx->sta && ieee80211_is_data_qos(hdr->frame_control) &&
1208*4882a593Smuzhiyun !ieee80211_is_qos_nullfunc(hdr->frame_control) &&
1209*4882a593Smuzhiyun ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
1210*4882a593Smuzhiyun !ieee80211_hw_check(&local->hw, TX_AMPDU_SETUP_IN_HW)) {
1211*4882a593Smuzhiyun struct tid_ampdu_tx *tid_tx;
1212*4882a593Smuzhiyun
1213*4882a593Smuzhiyun tid = ieee80211_get_tid(hdr);
1214*4882a593Smuzhiyun
1215*4882a593Smuzhiyun tid_tx = rcu_dereference(tx->sta->ampdu_mlme.tid_tx[tid]);
1216*4882a593Smuzhiyun if (tid_tx) {
1217*4882a593Smuzhiyun bool queued;
1218*4882a593Smuzhiyun
1219*4882a593Smuzhiyun queued = ieee80211_tx_prep_agg(tx, skb, info,
1220*4882a593Smuzhiyun tid_tx, tid);
1221*4882a593Smuzhiyun
1222*4882a593Smuzhiyun if (unlikely(queued))
1223*4882a593Smuzhiyun return TX_QUEUED;
1224*4882a593Smuzhiyun }
1225*4882a593Smuzhiyun }
1226*4882a593Smuzhiyun
1227*4882a593Smuzhiyun if (is_multicast_ether_addr(hdr->addr1)) {
1228*4882a593Smuzhiyun tx->flags &= ~IEEE80211_TX_UNICAST;
1229*4882a593Smuzhiyun info->flags |= IEEE80211_TX_CTL_NO_ACK;
1230*4882a593Smuzhiyun } else
1231*4882a593Smuzhiyun tx->flags |= IEEE80211_TX_UNICAST;
1232*4882a593Smuzhiyun
1233*4882a593Smuzhiyun if (!(info->flags & IEEE80211_TX_CTL_DONTFRAG)) {
1234*4882a593Smuzhiyun if (!(tx->flags & IEEE80211_TX_UNICAST) ||
1235*4882a593Smuzhiyun skb->len + FCS_LEN <= local->hw.wiphy->frag_threshold ||
1236*4882a593Smuzhiyun info->flags & IEEE80211_TX_CTL_AMPDU)
1237*4882a593Smuzhiyun info->flags |= IEEE80211_TX_CTL_DONTFRAG;
1238*4882a593Smuzhiyun }
1239*4882a593Smuzhiyun
1240*4882a593Smuzhiyun if (!tx->sta)
1241*4882a593Smuzhiyun info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
1242*4882a593Smuzhiyun else if (test_and_clear_sta_flag(tx->sta, WLAN_STA_CLEAR_PS_FILT)) {
1243*4882a593Smuzhiyun info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
1244*4882a593Smuzhiyun ieee80211_check_fast_xmit(tx->sta);
1245*4882a593Smuzhiyun }
1246*4882a593Smuzhiyun
1247*4882a593Smuzhiyun info->flags |= IEEE80211_TX_CTL_FIRST_FRAGMENT;
1248*4882a593Smuzhiyun
1249*4882a593Smuzhiyun return TX_CONTINUE;
1250*4882a593Smuzhiyun }
1251*4882a593Smuzhiyun
ieee80211_get_txq(struct ieee80211_local * local,struct ieee80211_vif * vif,struct sta_info * sta,struct sk_buff * skb)1252*4882a593Smuzhiyun static struct txq_info *ieee80211_get_txq(struct ieee80211_local *local,
1253*4882a593Smuzhiyun struct ieee80211_vif *vif,
1254*4882a593Smuzhiyun struct sta_info *sta,
1255*4882a593Smuzhiyun struct sk_buff *skb)
1256*4882a593Smuzhiyun {
1257*4882a593Smuzhiyun struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1258*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1259*4882a593Smuzhiyun struct ieee80211_txq *txq = NULL;
1260*4882a593Smuzhiyun
1261*4882a593Smuzhiyun if ((info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) ||
1262*4882a593Smuzhiyun (info->control.flags & IEEE80211_TX_CTRL_PS_RESPONSE))
1263*4882a593Smuzhiyun return NULL;
1264*4882a593Smuzhiyun
1265*4882a593Smuzhiyun if (!(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) &&
1266*4882a593Smuzhiyun unlikely(!ieee80211_is_data_present(hdr->frame_control))) {
1267*4882a593Smuzhiyun if ((!ieee80211_is_mgmt(hdr->frame_control) ||
1268*4882a593Smuzhiyun ieee80211_is_bufferable_mmpdu(hdr->frame_control) ||
1269*4882a593Smuzhiyun vif->type == NL80211_IFTYPE_STATION) &&
1270*4882a593Smuzhiyun sta && sta->uploaded) {
1271*4882a593Smuzhiyun /*
1272*4882a593Smuzhiyun * This will be NULL if the driver didn't set the
1273*4882a593Smuzhiyun * opt-in hardware flag.
1274*4882a593Smuzhiyun */
1275*4882a593Smuzhiyun txq = sta->sta.txq[IEEE80211_NUM_TIDS];
1276*4882a593Smuzhiyun }
1277*4882a593Smuzhiyun } else if (sta) {
1278*4882a593Smuzhiyun u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
1279*4882a593Smuzhiyun
1280*4882a593Smuzhiyun if (!sta->uploaded)
1281*4882a593Smuzhiyun return NULL;
1282*4882a593Smuzhiyun
1283*4882a593Smuzhiyun txq = sta->sta.txq[tid];
1284*4882a593Smuzhiyun } else if (vif) {
1285*4882a593Smuzhiyun txq = vif->txq;
1286*4882a593Smuzhiyun }
1287*4882a593Smuzhiyun
1288*4882a593Smuzhiyun if (!txq)
1289*4882a593Smuzhiyun return NULL;
1290*4882a593Smuzhiyun
1291*4882a593Smuzhiyun return to_txq_info(txq);
1292*4882a593Smuzhiyun }
1293*4882a593Smuzhiyun
ieee80211_set_skb_enqueue_time(struct sk_buff * skb)1294*4882a593Smuzhiyun static void ieee80211_set_skb_enqueue_time(struct sk_buff *skb)
1295*4882a593Smuzhiyun {
1296*4882a593Smuzhiyun IEEE80211_SKB_CB(skb)->control.enqueue_time = codel_get_time();
1297*4882a593Smuzhiyun }
1298*4882a593Smuzhiyun
codel_skb_len_func(const struct sk_buff * skb)1299*4882a593Smuzhiyun static u32 codel_skb_len_func(const struct sk_buff *skb)
1300*4882a593Smuzhiyun {
1301*4882a593Smuzhiyun return skb->len;
1302*4882a593Smuzhiyun }
1303*4882a593Smuzhiyun
codel_skb_time_func(const struct sk_buff * skb)1304*4882a593Smuzhiyun static codel_time_t codel_skb_time_func(const struct sk_buff *skb)
1305*4882a593Smuzhiyun {
1306*4882a593Smuzhiyun const struct ieee80211_tx_info *info;
1307*4882a593Smuzhiyun
1308*4882a593Smuzhiyun info = (const struct ieee80211_tx_info *)skb->cb;
1309*4882a593Smuzhiyun return info->control.enqueue_time;
1310*4882a593Smuzhiyun }
1311*4882a593Smuzhiyun
codel_dequeue_func(struct codel_vars * cvars,void * ctx)1312*4882a593Smuzhiyun static struct sk_buff *codel_dequeue_func(struct codel_vars *cvars,
1313*4882a593Smuzhiyun void *ctx)
1314*4882a593Smuzhiyun {
1315*4882a593Smuzhiyun struct ieee80211_local *local;
1316*4882a593Smuzhiyun struct txq_info *txqi;
1317*4882a593Smuzhiyun struct fq *fq;
1318*4882a593Smuzhiyun struct fq_flow *flow;
1319*4882a593Smuzhiyun
1320*4882a593Smuzhiyun txqi = ctx;
1321*4882a593Smuzhiyun local = vif_to_sdata(txqi->txq.vif)->local;
1322*4882a593Smuzhiyun fq = &local->fq;
1323*4882a593Smuzhiyun
1324*4882a593Smuzhiyun if (cvars == &txqi->def_cvars)
1325*4882a593Smuzhiyun flow = &txqi->def_flow;
1326*4882a593Smuzhiyun else
1327*4882a593Smuzhiyun flow = &fq->flows[cvars - local->cvars];
1328*4882a593Smuzhiyun
1329*4882a593Smuzhiyun return fq_flow_dequeue(fq, flow);
1330*4882a593Smuzhiyun }
1331*4882a593Smuzhiyun
codel_drop_func(struct sk_buff * skb,void * ctx)1332*4882a593Smuzhiyun static void codel_drop_func(struct sk_buff *skb,
1333*4882a593Smuzhiyun void *ctx)
1334*4882a593Smuzhiyun {
1335*4882a593Smuzhiyun struct ieee80211_local *local;
1336*4882a593Smuzhiyun struct ieee80211_hw *hw;
1337*4882a593Smuzhiyun struct txq_info *txqi;
1338*4882a593Smuzhiyun
1339*4882a593Smuzhiyun txqi = ctx;
1340*4882a593Smuzhiyun local = vif_to_sdata(txqi->txq.vif)->local;
1341*4882a593Smuzhiyun hw = &local->hw;
1342*4882a593Smuzhiyun
1343*4882a593Smuzhiyun ieee80211_free_txskb(hw, skb);
1344*4882a593Smuzhiyun }
1345*4882a593Smuzhiyun
fq_tin_dequeue_func(struct fq * fq,struct fq_tin * tin,struct fq_flow * flow)1346*4882a593Smuzhiyun static struct sk_buff *fq_tin_dequeue_func(struct fq *fq,
1347*4882a593Smuzhiyun struct fq_tin *tin,
1348*4882a593Smuzhiyun struct fq_flow *flow)
1349*4882a593Smuzhiyun {
1350*4882a593Smuzhiyun struct ieee80211_local *local;
1351*4882a593Smuzhiyun struct txq_info *txqi;
1352*4882a593Smuzhiyun struct codel_vars *cvars;
1353*4882a593Smuzhiyun struct codel_params *cparams;
1354*4882a593Smuzhiyun struct codel_stats *cstats;
1355*4882a593Smuzhiyun
1356*4882a593Smuzhiyun local = container_of(fq, struct ieee80211_local, fq);
1357*4882a593Smuzhiyun txqi = container_of(tin, struct txq_info, tin);
1358*4882a593Smuzhiyun cstats = &txqi->cstats;
1359*4882a593Smuzhiyun
1360*4882a593Smuzhiyun if (txqi->txq.sta) {
1361*4882a593Smuzhiyun struct sta_info *sta = container_of(txqi->txq.sta,
1362*4882a593Smuzhiyun struct sta_info, sta);
1363*4882a593Smuzhiyun cparams = &sta->cparams;
1364*4882a593Smuzhiyun } else {
1365*4882a593Smuzhiyun cparams = &local->cparams;
1366*4882a593Smuzhiyun }
1367*4882a593Smuzhiyun
1368*4882a593Smuzhiyun if (flow == &txqi->def_flow)
1369*4882a593Smuzhiyun cvars = &txqi->def_cvars;
1370*4882a593Smuzhiyun else
1371*4882a593Smuzhiyun cvars = &local->cvars[flow - fq->flows];
1372*4882a593Smuzhiyun
1373*4882a593Smuzhiyun return codel_dequeue(txqi,
1374*4882a593Smuzhiyun &flow->backlog,
1375*4882a593Smuzhiyun cparams,
1376*4882a593Smuzhiyun cvars,
1377*4882a593Smuzhiyun cstats,
1378*4882a593Smuzhiyun codel_skb_len_func,
1379*4882a593Smuzhiyun codel_skb_time_func,
1380*4882a593Smuzhiyun codel_drop_func,
1381*4882a593Smuzhiyun codel_dequeue_func);
1382*4882a593Smuzhiyun }
1383*4882a593Smuzhiyun
fq_skb_free_func(struct fq * fq,struct fq_tin * tin,struct fq_flow * flow,struct sk_buff * skb)1384*4882a593Smuzhiyun static void fq_skb_free_func(struct fq *fq,
1385*4882a593Smuzhiyun struct fq_tin *tin,
1386*4882a593Smuzhiyun struct fq_flow *flow,
1387*4882a593Smuzhiyun struct sk_buff *skb)
1388*4882a593Smuzhiyun {
1389*4882a593Smuzhiyun struct ieee80211_local *local;
1390*4882a593Smuzhiyun
1391*4882a593Smuzhiyun local = container_of(fq, struct ieee80211_local, fq);
1392*4882a593Smuzhiyun ieee80211_free_txskb(&local->hw, skb);
1393*4882a593Smuzhiyun }
1394*4882a593Smuzhiyun
fq_flow_get_default_func(struct fq * fq,struct fq_tin * tin,int idx,struct sk_buff * skb)1395*4882a593Smuzhiyun static struct fq_flow *fq_flow_get_default_func(struct fq *fq,
1396*4882a593Smuzhiyun struct fq_tin *tin,
1397*4882a593Smuzhiyun int idx,
1398*4882a593Smuzhiyun struct sk_buff *skb)
1399*4882a593Smuzhiyun {
1400*4882a593Smuzhiyun struct txq_info *txqi;
1401*4882a593Smuzhiyun
1402*4882a593Smuzhiyun txqi = container_of(tin, struct txq_info, tin);
1403*4882a593Smuzhiyun return &txqi->def_flow;
1404*4882a593Smuzhiyun }
1405*4882a593Smuzhiyun
ieee80211_txq_enqueue(struct ieee80211_local * local,struct txq_info * txqi,struct sk_buff * skb)1406*4882a593Smuzhiyun static void ieee80211_txq_enqueue(struct ieee80211_local *local,
1407*4882a593Smuzhiyun struct txq_info *txqi,
1408*4882a593Smuzhiyun struct sk_buff *skb)
1409*4882a593Smuzhiyun {
1410*4882a593Smuzhiyun struct fq *fq = &local->fq;
1411*4882a593Smuzhiyun struct fq_tin *tin = &txqi->tin;
1412*4882a593Smuzhiyun u32 flow_idx = fq_flow_idx(fq, skb);
1413*4882a593Smuzhiyun
1414*4882a593Smuzhiyun ieee80211_set_skb_enqueue_time(skb);
1415*4882a593Smuzhiyun
1416*4882a593Smuzhiyun spin_lock_bh(&fq->lock);
1417*4882a593Smuzhiyun fq_tin_enqueue(fq, tin, flow_idx, skb,
1418*4882a593Smuzhiyun fq_skb_free_func,
1419*4882a593Smuzhiyun fq_flow_get_default_func);
1420*4882a593Smuzhiyun spin_unlock_bh(&fq->lock);
1421*4882a593Smuzhiyun }
1422*4882a593Smuzhiyun
fq_vlan_filter_func(struct fq * fq,struct fq_tin * tin,struct fq_flow * flow,struct sk_buff * skb,void * data)1423*4882a593Smuzhiyun static bool fq_vlan_filter_func(struct fq *fq, struct fq_tin *tin,
1424*4882a593Smuzhiyun struct fq_flow *flow, struct sk_buff *skb,
1425*4882a593Smuzhiyun void *data)
1426*4882a593Smuzhiyun {
1427*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1428*4882a593Smuzhiyun
1429*4882a593Smuzhiyun return info->control.vif == data;
1430*4882a593Smuzhiyun }
1431*4882a593Smuzhiyun
ieee80211_txq_remove_vlan(struct ieee80211_local * local,struct ieee80211_sub_if_data * sdata)1432*4882a593Smuzhiyun void ieee80211_txq_remove_vlan(struct ieee80211_local *local,
1433*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata)
1434*4882a593Smuzhiyun {
1435*4882a593Smuzhiyun struct fq *fq = &local->fq;
1436*4882a593Smuzhiyun struct txq_info *txqi;
1437*4882a593Smuzhiyun struct fq_tin *tin;
1438*4882a593Smuzhiyun struct ieee80211_sub_if_data *ap;
1439*4882a593Smuzhiyun
1440*4882a593Smuzhiyun if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_AP_VLAN))
1441*4882a593Smuzhiyun return;
1442*4882a593Smuzhiyun
1443*4882a593Smuzhiyun ap = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap);
1444*4882a593Smuzhiyun
1445*4882a593Smuzhiyun if (!ap->vif.txq)
1446*4882a593Smuzhiyun return;
1447*4882a593Smuzhiyun
1448*4882a593Smuzhiyun txqi = to_txq_info(ap->vif.txq);
1449*4882a593Smuzhiyun tin = &txqi->tin;
1450*4882a593Smuzhiyun
1451*4882a593Smuzhiyun spin_lock_bh(&fq->lock);
1452*4882a593Smuzhiyun fq_tin_filter(fq, tin, fq_vlan_filter_func, &sdata->vif,
1453*4882a593Smuzhiyun fq_skb_free_func);
1454*4882a593Smuzhiyun spin_unlock_bh(&fq->lock);
1455*4882a593Smuzhiyun }
1456*4882a593Smuzhiyun
ieee80211_txq_init(struct ieee80211_sub_if_data * sdata,struct sta_info * sta,struct txq_info * txqi,int tid)1457*4882a593Smuzhiyun void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata,
1458*4882a593Smuzhiyun struct sta_info *sta,
1459*4882a593Smuzhiyun struct txq_info *txqi, int tid)
1460*4882a593Smuzhiyun {
1461*4882a593Smuzhiyun fq_tin_init(&txqi->tin);
1462*4882a593Smuzhiyun fq_flow_init(&txqi->def_flow);
1463*4882a593Smuzhiyun codel_vars_init(&txqi->def_cvars);
1464*4882a593Smuzhiyun codel_stats_init(&txqi->cstats);
1465*4882a593Smuzhiyun __skb_queue_head_init(&txqi->frags);
1466*4882a593Smuzhiyun INIT_LIST_HEAD(&txqi->schedule_order);
1467*4882a593Smuzhiyun
1468*4882a593Smuzhiyun txqi->txq.vif = &sdata->vif;
1469*4882a593Smuzhiyun
1470*4882a593Smuzhiyun if (!sta) {
1471*4882a593Smuzhiyun sdata->vif.txq = &txqi->txq;
1472*4882a593Smuzhiyun txqi->txq.tid = 0;
1473*4882a593Smuzhiyun txqi->txq.ac = IEEE80211_AC_BE;
1474*4882a593Smuzhiyun
1475*4882a593Smuzhiyun return;
1476*4882a593Smuzhiyun }
1477*4882a593Smuzhiyun
1478*4882a593Smuzhiyun if (tid == IEEE80211_NUM_TIDS) {
1479*4882a593Smuzhiyun if (sdata->vif.type == NL80211_IFTYPE_STATION) {
1480*4882a593Smuzhiyun /* Drivers need to opt in to the management MPDU TXQ */
1481*4882a593Smuzhiyun if (!ieee80211_hw_check(&sdata->local->hw,
1482*4882a593Smuzhiyun STA_MMPDU_TXQ))
1483*4882a593Smuzhiyun return;
1484*4882a593Smuzhiyun } else if (!ieee80211_hw_check(&sdata->local->hw,
1485*4882a593Smuzhiyun BUFF_MMPDU_TXQ)) {
1486*4882a593Smuzhiyun /* Drivers need to opt in to the bufferable MMPDU TXQ */
1487*4882a593Smuzhiyun return;
1488*4882a593Smuzhiyun }
1489*4882a593Smuzhiyun txqi->txq.ac = IEEE80211_AC_VO;
1490*4882a593Smuzhiyun } else {
1491*4882a593Smuzhiyun txqi->txq.ac = ieee80211_ac_from_tid(tid);
1492*4882a593Smuzhiyun }
1493*4882a593Smuzhiyun
1494*4882a593Smuzhiyun txqi->txq.sta = &sta->sta;
1495*4882a593Smuzhiyun txqi->txq.tid = tid;
1496*4882a593Smuzhiyun sta->sta.txq[tid] = &txqi->txq;
1497*4882a593Smuzhiyun }
1498*4882a593Smuzhiyun
ieee80211_txq_purge(struct ieee80211_local * local,struct txq_info * txqi)1499*4882a593Smuzhiyun void ieee80211_txq_purge(struct ieee80211_local *local,
1500*4882a593Smuzhiyun struct txq_info *txqi)
1501*4882a593Smuzhiyun {
1502*4882a593Smuzhiyun struct fq *fq = &local->fq;
1503*4882a593Smuzhiyun struct fq_tin *tin = &txqi->tin;
1504*4882a593Smuzhiyun
1505*4882a593Smuzhiyun spin_lock_bh(&fq->lock);
1506*4882a593Smuzhiyun fq_tin_reset(fq, tin, fq_skb_free_func);
1507*4882a593Smuzhiyun ieee80211_purge_tx_queue(&local->hw, &txqi->frags);
1508*4882a593Smuzhiyun spin_unlock_bh(&fq->lock);
1509*4882a593Smuzhiyun
1510*4882a593Smuzhiyun spin_lock_bh(&local->active_txq_lock[txqi->txq.ac]);
1511*4882a593Smuzhiyun list_del_init(&txqi->schedule_order);
1512*4882a593Smuzhiyun spin_unlock_bh(&local->active_txq_lock[txqi->txq.ac]);
1513*4882a593Smuzhiyun }
1514*4882a593Smuzhiyun
ieee80211_txq_set_params(struct ieee80211_local * local)1515*4882a593Smuzhiyun void ieee80211_txq_set_params(struct ieee80211_local *local)
1516*4882a593Smuzhiyun {
1517*4882a593Smuzhiyun if (local->hw.wiphy->txq_limit)
1518*4882a593Smuzhiyun local->fq.limit = local->hw.wiphy->txq_limit;
1519*4882a593Smuzhiyun else
1520*4882a593Smuzhiyun local->hw.wiphy->txq_limit = local->fq.limit;
1521*4882a593Smuzhiyun
1522*4882a593Smuzhiyun if (local->hw.wiphy->txq_memory_limit)
1523*4882a593Smuzhiyun local->fq.memory_limit = local->hw.wiphy->txq_memory_limit;
1524*4882a593Smuzhiyun else
1525*4882a593Smuzhiyun local->hw.wiphy->txq_memory_limit = local->fq.memory_limit;
1526*4882a593Smuzhiyun
1527*4882a593Smuzhiyun if (local->hw.wiphy->txq_quantum)
1528*4882a593Smuzhiyun local->fq.quantum = local->hw.wiphy->txq_quantum;
1529*4882a593Smuzhiyun else
1530*4882a593Smuzhiyun local->hw.wiphy->txq_quantum = local->fq.quantum;
1531*4882a593Smuzhiyun }
1532*4882a593Smuzhiyun
ieee80211_txq_setup_flows(struct ieee80211_local * local)1533*4882a593Smuzhiyun int ieee80211_txq_setup_flows(struct ieee80211_local *local)
1534*4882a593Smuzhiyun {
1535*4882a593Smuzhiyun struct fq *fq = &local->fq;
1536*4882a593Smuzhiyun int ret;
1537*4882a593Smuzhiyun int i;
1538*4882a593Smuzhiyun bool supp_vht = false;
1539*4882a593Smuzhiyun enum nl80211_band band;
1540*4882a593Smuzhiyun
1541*4882a593Smuzhiyun if (!local->ops->wake_tx_queue)
1542*4882a593Smuzhiyun return 0;
1543*4882a593Smuzhiyun
1544*4882a593Smuzhiyun ret = fq_init(fq, 4096);
1545*4882a593Smuzhiyun if (ret)
1546*4882a593Smuzhiyun return ret;
1547*4882a593Smuzhiyun
1548*4882a593Smuzhiyun /*
1549*4882a593Smuzhiyun * If the hardware doesn't support VHT, it is safe to limit the maximum
1550*4882a593Smuzhiyun * queue size. 4 Mbytes is 64 max-size aggregates in 802.11n.
1551*4882a593Smuzhiyun */
1552*4882a593Smuzhiyun for (band = 0; band < NUM_NL80211_BANDS; band++) {
1553*4882a593Smuzhiyun struct ieee80211_supported_band *sband;
1554*4882a593Smuzhiyun
1555*4882a593Smuzhiyun sband = local->hw.wiphy->bands[band];
1556*4882a593Smuzhiyun if (!sband)
1557*4882a593Smuzhiyun continue;
1558*4882a593Smuzhiyun
1559*4882a593Smuzhiyun supp_vht = supp_vht || sband->vht_cap.vht_supported;
1560*4882a593Smuzhiyun }
1561*4882a593Smuzhiyun
1562*4882a593Smuzhiyun if (!supp_vht)
1563*4882a593Smuzhiyun fq->memory_limit = 4 << 20; /* 4 Mbytes */
1564*4882a593Smuzhiyun
1565*4882a593Smuzhiyun codel_params_init(&local->cparams);
1566*4882a593Smuzhiyun local->cparams.interval = MS2TIME(100);
1567*4882a593Smuzhiyun local->cparams.target = MS2TIME(20);
1568*4882a593Smuzhiyun local->cparams.ecn = true;
1569*4882a593Smuzhiyun
1570*4882a593Smuzhiyun local->cvars = kcalloc(fq->flows_cnt, sizeof(local->cvars[0]),
1571*4882a593Smuzhiyun GFP_KERNEL);
1572*4882a593Smuzhiyun if (!local->cvars) {
1573*4882a593Smuzhiyun spin_lock_bh(&fq->lock);
1574*4882a593Smuzhiyun fq_reset(fq, fq_skb_free_func);
1575*4882a593Smuzhiyun spin_unlock_bh(&fq->lock);
1576*4882a593Smuzhiyun return -ENOMEM;
1577*4882a593Smuzhiyun }
1578*4882a593Smuzhiyun
1579*4882a593Smuzhiyun for (i = 0; i < fq->flows_cnt; i++)
1580*4882a593Smuzhiyun codel_vars_init(&local->cvars[i]);
1581*4882a593Smuzhiyun
1582*4882a593Smuzhiyun ieee80211_txq_set_params(local);
1583*4882a593Smuzhiyun
1584*4882a593Smuzhiyun return 0;
1585*4882a593Smuzhiyun }
1586*4882a593Smuzhiyun
ieee80211_txq_teardown_flows(struct ieee80211_local * local)1587*4882a593Smuzhiyun void ieee80211_txq_teardown_flows(struct ieee80211_local *local)
1588*4882a593Smuzhiyun {
1589*4882a593Smuzhiyun struct fq *fq = &local->fq;
1590*4882a593Smuzhiyun
1591*4882a593Smuzhiyun if (!local->ops->wake_tx_queue)
1592*4882a593Smuzhiyun return;
1593*4882a593Smuzhiyun
1594*4882a593Smuzhiyun kfree(local->cvars);
1595*4882a593Smuzhiyun local->cvars = NULL;
1596*4882a593Smuzhiyun
1597*4882a593Smuzhiyun spin_lock_bh(&fq->lock);
1598*4882a593Smuzhiyun fq_reset(fq, fq_skb_free_func);
1599*4882a593Smuzhiyun spin_unlock_bh(&fq->lock);
1600*4882a593Smuzhiyun }
1601*4882a593Smuzhiyun
ieee80211_queue_skb(struct ieee80211_local * local,struct ieee80211_sub_if_data * sdata,struct sta_info * sta,struct sk_buff * skb)1602*4882a593Smuzhiyun static bool ieee80211_queue_skb(struct ieee80211_local *local,
1603*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata,
1604*4882a593Smuzhiyun struct sta_info *sta,
1605*4882a593Smuzhiyun struct sk_buff *skb)
1606*4882a593Smuzhiyun {
1607*4882a593Smuzhiyun struct ieee80211_vif *vif;
1608*4882a593Smuzhiyun struct txq_info *txqi;
1609*4882a593Smuzhiyun
1610*4882a593Smuzhiyun if (!local->ops->wake_tx_queue ||
1611*4882a593Smuzhiyun sdata->vif.type == NL80211_IFTYPE_MONITOR)
1612*4882a593Smuzhiyun return false;
1613*4882a593Smuzhiyun
1614*4882a593Smuzhiyun if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1615*4882a593Smuzhiyun sdata = container_of(sdata->bss,
1616*4882a593Smuzhiyun struct ieee80211_sub_if_data, u.ap);
1617*4882a593Smuzhiyun
1618*4882a593Smuzhiyun vif = &sdata->vif;
1619*4882a593Smuzhiyun txqi = ieee80211_get_txq(local, vif, sta, skb);
1620*4882a593Smuzhiyun
1621*4882a593Smuzhiyun if (!txqi)
1622*4882a593Smuzhiyun return false;
1623*4882a593Smuzhiyun
1624*4882a593Smuzhiyun ieee80211_txq_enqueue(local, txqi, skb);
1625*4882a593Smuzhiyun
1626*4882a593Smuzhiyun schedule_and_wake_txq(local, txqi);
1627*4882a593Smuzhiyun
1628*4882a593Smuzhiyun return true;
1629*4882a593Smuzhiyun }
1630*4882a593Smuzhiyun
ieee80211_tx_frags(struct ieee80211_local * local,struct ieee80211_vif * vif,struct sta_info * sta,struct sk_buff_head * skbs,bool txpending)1631*4882a593Smuzhiyun static bool ieee80211_tx_frags(struct ieee80211_local *local,
1632*4882a593Smuzhiyun struct ieee80211_vif *vif,
1633*4882a593Smuzhiyun struct sta_info *sta,
1634*4882a593Smuzhiyun struct sk_buff_head *skbs,
1635*4882a593Smuzhiyun bool txpending)
1636*4882a593Smuzhiyun {
1637*4882a593Smuzhiyun struct ieee80211_tx_control control = {};
1638*4882a593Smuzhiyun struct sk_buff *skb, *tmp;
1639*4882a593Smuzhiyun unsigned long flags;
1640*4882a593Smuzhiyun
1641*4882a593Smuzhiyun skb_queue_walk_safe(skbs, skb, tmp) {
1642*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1643*4882a593Smuzhiyun int q = info->hw_queue;
1644*4882a593Smuzhiyun
1645*4882a593Smuzhiyun #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1646*4882a593Smuzhiyun if (WARN_ON_ONCE(q >= local->hw.queues)) {
1647*4882a593Smuzhiyun __skb_unlink(skb, skbs);
1648*4882a593Smuzhiyun ieee80211_free_txskb(&local->hw, skb);
1649*4882a593Smuzhiyun continue;
1650*4882a593Smuzhiyun }
1651*4882a593Smuzhiyun #endif
1652*4882a593Smuzhiyun
1653*4882a593Smuzhiyun spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1654*4882a593Smuzhiyun if (local->queue_stop_reasons[q] ||
1655*4882a593Smuzhiyun (!txpending && !skb_queue_empty(&local->pending[q]))) {
1656*4882a593Smuzhiyun if (unlikely(info->flags &
1657*4882a593Smuzhiyun IEEE80211_TX_INTFL_OFFCHAN_TX_OK)) {
1658*4882a593Smuzhiyun if (local->queue_stop_reasons[q] &
1659*4882a593Smuzhiyun ~BIT(IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL)) {
1660*4882a593Smuzhiyun /*
1661*4882a593Smuzhiyun * Drop off-channel frames if queues
1662*4882a593Smuzhiyun * are stopped for any reason other
1663*4882a593Smuzhiyun * than off-channel operation. Never
1664*4882a593Smuzhiyun * queue them.
1665*4882a593Smuzhiyun */
1666*4882a593Smuzhiyun spin_unlock_irqrestore(
1667*4882a593Smuzhiyun &local->queue_stop_reason_lock,
1668*4882a593Smuzhiyun flags);
1669*4882a593Smuzhiyun ieee80211_purge_tx_queue(&local->hw,
1670*4882a593Smuzhiyun skbs);
1671*4882a593Smuzhiyun return true;
1672*4882a593Smuzhiyun }
1673*4882a593Smuzhiyun } else {
1674*4882a593Smuzhiyun
1675*4882a593Smuzhiyun /*
1676*4882a593Smuzhiyun * Since queue is stopped, queue up frames for
1677*4882a593Smuzhiyun * later transmission from the tx-pending
1678*4882a593Smuzhiyun * tasklet when the queue is woken again.
1679*4882a593Smuzhiyun */
1680*4882a593Smuzhiyun if (txpending)
1681*4882a593Smuzhiyun skb_queue_splice_init(skbs,
1682*4882a593Smuzhiyun &local->pending[q]);
1683*4882a593Smuzhiyun else
1684*4882a593Smuzhiyun skb_queue_splice_tail_init(skbs,
1685*4882a593Smuzhiyun &local->pending[q]);
1686*4882a593Smuzhiyun
1687*4882a593Smuzhiyun spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1688*4882a593Smuzhiyun flags);
1689*4882a593Smuzhiyun return false;
1690*4882a593Smuzhiyun }
1691*4882a593Smuzhiyun }
1692*4882a593Smuzhiyun spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1693*4882a593Smuzhiyun
1694*4882a593Smuzhiyun info->control.vif = vif;
1695*4882a593Smuzhiyun control.sta = sta ? &sta->sta : NULL;
1696*4882a593Smuzhiyun
1697*4882a593Smuzhiyun __skb_unlink(skb, skbs);
1698*4882a593Smuzhiyun drv_tx(local, &control, skb);
1699*4882a593Smuzhiyun }
1700*4882a593Smuzhiyun
1701*4882a593Smuzhiyun return true;
1702*4882a593Smuzhiyun }
1703*4882a593Smuzhiyun
1704*4882a593Smuzhiyun /*
1705*4882a593Smuzhiyun * Returns false if the frame couldn't be transmitted but was queued instead.
1706*4882a593Smuzhiyun */
__ieee80211_tx(struct ieee80211_local * local,struct sk_buff_head * skbs,int led_len,struct sta_info * sta,bool txpending)1707*4882a593Smuzhiyun static bool __ieee80211_tx(struct ieee80211_local *local,
1708*4882a593Smuzhiyun struct sk_buff_head *skbs, int led_len,
1709*4882a593Smuzhiyun struct sta_info *sta, bool txpending)
1710*4882a593Smuzhiyun {
1711*4882a593Smuzhiyun struct ieee80211_tx_info *info;
1712*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata;
1713*4882a593Smuzhiyun struct ieee80211_vif *vif;
1714*4882a593Smuzhiyun struct sk_buff *skb;
1715*4882a593Smuzhiyun bool result = true;
1716*4882a593Smuzhiyun __le16 fc;
1717*4882a593Smuzhiyun
1718*4882a593Smuzhiyun if (WARN_ON(skb_queue_empty(skbs)))
1719*4882a593Smuzhiyun return true;
1720*4882a593Smuzhiyun
1721*4882a593Smuzhiyun skb = skb_peek(skbs);
1722*4882a593Smuzhiyun fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
1723*4882a593Smuzhiyun info = IEEE80211_SKB_CB(skb);
1724*4882a593Smuzhiyun sdata = vif_to_sdata(info->control.vif);
1725*4882a593Smuzhiyun if (sta && !sta->uploaded)
1726*4882a593Smuzhiyun sta = NULL;
1727*4882a593Smuzhiyun
1728*4882a593Smuzhiyun switch (sdata->vif.type) {
1729*4882a593Smuzhiyun case NL80211_IFTYPE_MONITOR:
1730*4882a593Smuzhiyun if (sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) {
1731*4882a593Smuzhiyun vif = &sdata->vif;
1732*4882a593Smuzhiyun break;
1733*4882a593Smuzhiyun }
1734*4882a593Smuzhiyun sdata = rcu_dereference(local->monitor_sdata);
1735*4882a593Smuzhiyun if (sdata) {
1736*4882a593Smuzhiyun vif = &sdata->vif;
1737*4882a593Smuzhiyun info->hw_queue =
1738*4882a593Smuzhiyun vif->hw_queue[skb_get_queue_mapping(skb)];
1739*4882a593Smuzhiyun } else if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) {
1740*4882a593Smuzhiyun ieee80211_purge_tx_queue(&local->hw, skbs);
1741*4882a593Smuzhiyun return true;
1742*4882a593Smuzhiyun } else
1743*4882a593Smuzhiyun vif = NULL;
1744*4882a593Smuzhiyun break;
1745*4882a593Smuzhiyun case NL80211_IFTYPE_AP_VLAN:
1746*4882a593Smuzhiyun sdata = container_of(sdata->bss,
1747*4882a593Smuzhiyun struct ieee80211_sub_if_data, u.ap);
1748*4882a593Smuzhiyun fallthrough;
1749*4882a593Smuzhiyun default:
1750*4882a593Smuzhiyun vif = &sdata->vif;
1751*4882a593Smuzhiyun break;
1752*4882a593Smuzhiyun }
1753*4882a593Smuzhiyun
1754*4882a593Smuzhiyun result = ieee80211_tx_frags(local, vif, sta, skbs, txpending);
1755*4882a593Smuzhiyun
1756*4882a593Smuzhiyun ieee80211_tpt_led_trig_tx(local, fc, led_len);
1757*4882a593Smuzhiyun
1758*4882a593Smuzhiyun WARN_ON_ONCE(!skb_queue_empty(skbs));
1759*4882a593Smuzhiyun
1760*4882a593Smuzhiyun return result;
1761*4882a593Smuzhiyun }
1762*4882a593Smuzhiyun
1763*4882a593Smuzhiyun /*
1764*4882a593Smuzhiyun * Invoke TX handlers, return 0 on success and non-zero if the
1765*4882a593Smuzhiyun * frame was dropped or queued.
1766*4882a593Smuzhiyun *
1767*4882a593Smuzhiyun * The handlers are split into an early and late part. The latter is everything
1768*4882a593Smuzhiyun * that can be sensitive to reordering, and will be deferred to after packets
1769*4882a593Smuzhiyun * are dequeued from the intermediate queues (when they are enabled).
1770*4882a593Smuzhiyun */
invoke_tx_handlers_early(struct ieee80211_tx_data * tx)1771*4882a593Smuzhiyun static int invoke_tx_handlers_early(struct ieee80211_tx_data *tx)
1772*4882a593Smuzhiyun {
1773*4882a593Smuzhiyun ieee80211_tx_result res = TX_DROP;
1774*4882a593Smuzhiyun
1775*4882a593Smuzhiyun #define CALL_TXH(txh) \
1776*4882a593Smuzhiyun do { \
1777*4882a593Smuzhiyun res = txh(tx); \
1778*4882a593Smuzhiyun if (res != TX_CONTINUE) \
1779*4882a593Smuzhiyun goto txh_done; \
1780*4882a593Smuzhiyun } while (0)
1781*4882a593Smuzhiyun
1782*4882a593Smuzhiyun CALL_TXH(ieee80211_tx_h_dynamic_ps);
1783*4882a593Smuzhiyun CALL_TXH(ieee80211_tx_h_check_assoc);
1784*4882a593Smuzhiyun CALL_TXH(ieee80211_tx_h_ps_buf);
1785*4882a593Smuzhiyun CALL_TXH(ieee80211_tx_h_check_control_port_protocol);
1786*4882a593Smuzhiyun CALL_TXH(ieee80211_tx_h_select_key);
1787*4882a593Smuzhiyun if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL))
1788*4882a593Smuzhiyun CALL_TXH(ieee80211_tx_h_rate_ctrl);
1789*4882a593Smuzhiyun
1790*4882a593Smuzhiyun txh_done:
1791*4882a593Smuzhiyun if (unlikely(res == TX_DROP)) {
1792*4882a593Smuzhiyun I802_DEBUG_INC(tx->local->tx_handlers_drop);
1793*4882a593Smuzhiyun if (tx->skb)
1794*4882a593Smuzhiyun ieee80211_free_txskb(&tx->local->hw, tx->skb);
1795*4882a593Smuzhiyun else
1796*4882a593Smuzhiyun ieee80211_purge_tx_queue(&tx->local->hw, &tx->skbs);
1797*4882a593Smuzhiyun return -1;
1798*4882a593Smuzhiyun } else if (unlikely(res == TX_QUEUED)) {
1799*4882a593Smuzhiyun I802_DEBUG_INC(tx->local->tx_handlers_queued);
1800*4882a593Smuzhiyun return -1;
1801*4882a593Smuzhiyun }
1802*4882a593Smuzhiyun
1803*4882a593Smuzhiyun return 0;
1804*4882a593Smuzhiyun }
1805*4882a593Smuzhiyun
1806*4882a593Smuzhiyun /*
1807*4882a593Smuzhiyun * Late handlers can be called while the sta lock is held. Handlers that can
1808*4882a593Smuzhiyun * cause packets to be generated will cause deadlock!
1809*4882a593Smuzhiyun */
invoke_tx_handlers_late(struct ieee80211_tx_data * tx)1810*4882a593Smuzhiyun static int invoke_tx_handlers_late(struct ieee80211_tx_data *tx)
1811*4882a593Smuzhiyun {
1812*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
1813*4882a593Smuzhiyun ieee80211_tx_result res = TX_CONTINUE;
1814*4882a593Smuzhiyun
1815*4882a593Smuzhiyun if (unlikely(info->flags & IEEE80211_TX_INTFL_RETRANSMISSION)) {
1816*4882a593Smuzhiyun __skb_queue_tail(&tx->skbs, tx->skb);
1817*4882a593Smuzhiyun tx->skb = NULL;
1818*4882a593Smuzhiyun goto txh_done;
1819*4882a593Smuzhiyun }
1820*4882a593Smuzhiyun
1821*4882a593Smuzhiyun CALL_TXH(ieee80211_tx_h_michael_mic_add);
1822*4882a593Smuzhiyun CALL_TXH(ieee80211_tx_h_sequence);
1823*4882a593Smuzhiyun CALL_TXH(ieee80211_tx_h_fragment);
1824*4882a593Smuzhiyun /* handlers after fragment must be aware of tx info fragmentation! */
1825*4882a593Smuzhiyun CALL_TXH(ieee80211_tx_h_stats);
1826*4882a593Smuzhiyun CALL_TXH(ieee80211_tx_h_encrypt);
1827*4882a593Smuzhiyun if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL))
1828*4882a593Smuzhiyun CALL_TXH(ieee80211_tx_h_calculate_duration);
1829*4882a593Smuzhiyun #undef CALL_TXH
1830*4882a593Smuzhiyun
1831*4882a593Smuzhiyun txh_done:
1832*4882a593Smuzhiyun if (unlikely(res == TX_DROP)) {
1833*4882a593Smuzhiyun I802_DEBUG_INC(tx->local->tx_handlers_drop);
1834*4882a593Smuzhiyun if (tx->skb)
1835*4882a593Smuzhiyun ieee80211_free_txskb(&tx->local->hw, tx->skb);
1836*4882a593Smuzhiyun else
1837*4882a593Smuzhiyun ieee80211_purge_tx_queue(&tx->local->hw, &tx->skbs);
1838*4882a593Smuzhiyun return -1;
1839*4882a593Smuzhiyun } else if (unlikely(res == TX_QUEUED)) {
1840*4882a593Smuzhiyun I802_DEBUG_INC(tx->local->tx_handlers_queued);
1841*4882a593Smuzhiyun return -1;
1842*4882a593Smuzhiyun }
1843*4882a593Smuzhiyun
1844*4882a593Smuzhiyun return 0;
1845*4882a593Smuzhiyun }
1846*4882a593Smuzhiyun
invoke_tx_handlers(struct ieee80211_tx_data * tx)1847*4882a593Smuzhiyun static int invoke_tx_handlers(struct ieee80211_tx_data *tx)
1848*4882a593Smuzhiyun {
1849*4882a593Smuzhiyun int r = invoke_tx_handlers_early(tx);
1850*4882a593Smuzhiyun
1851*4882a593Smuzhiyun if (r)
1852*4882a593Smuzhiyun return r;
1853*4882a593Smuzhiyun return invoke_tx_handlers_late(tx);
1854*4882a593Smuzhiyun }
1855*4882a593Smuzhiyun
ieee80211_tx_prepare_skb(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct sk_buff * skb,int band,struct ieee80211_sta ** sta)1856*4882a593Smuzhiyun bool ieee80211_tx_prepare_skb(struct ieee80211_hw *hw,
1857*4882a593Smuzhiyun struct ieee80211_vif *vif, struct sk_buff *skb,
1858*4882a593Smuzhiyun int band, struct ieee80211_sta **sta)
1859*4882a593Smuzhiyun {
1860*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1861*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1862*4882a593Smuzhiyun struct ieee80211_tx_data tx;
1863*4882a593Smuzhiyun struct sk_buff *skb2;
1864*4882a593Smuzhiyun
1865*4882a593Smuzhiyun if (ieee80211_tx_prepare(sdata, &tx, NULL, skb) == TX_DROP)
1866*4882a593Smuzhiyun return false;
1867*4882a593Smuzhiyun
1868*4882a593Smuzhiyun info->band = band;
1869*4882a593Smuzhiyun info->control.vif = vif;
1870*4882a593Smuzhiyun info->hw_queue = vif->hw_queue[skb_get_queue_mapping(skb)];
1871*4882a593Smuzhiyun
1872*4882a593Smuzhiyun if (invoke_tx_handlers(&tx))
1873*4882a593Smuzhiyun return false;
1874*4882a593Smuzhiyun
1875*4882a593Smuzhiyun if (sta) {
1876*4882a593Smuzhiyun if (tx.sta)
1877*4882a593Smuzhiyun *sta = &tx.sta->sta;
1878*4882a593Smuzhiyun else
1879*4882a593Smuzhiyun *sta = NULL;
1880*4882a593Smuzhiyun }
1881*4882a593Smuzhiyun
1882*4882a593Smuzhiyun /* this function isn't suitable for fragmented data frames */
1883*4882a593Smuzhiyun skb2 = __skb_dequeue(&tx.skbs);
1884*4882a593Smuzhiyun if (WARN_ON(skb2 != skb || !skb_queue_empty(&tx.skbs))) {
1885*4882a593Smuzhiyun ieee80211_free_txskb(hw, skb2);
1886*4882a593Smuzhiyun ieee80211_purge_tx_queue(hw, &tx.skbs);
1887*4882a593Smuzhiyun return false;
1888*4882a593Smuzhiyun }
1889*4882a593Smuzhiyun
1890*4882a593Smuzhiyun return true;
1891*4882a593Smuzhiyun }
1892*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_tx_prepare_skb);
1893*4882a593Smuzhiyun
1894*4882a593Smuzhiyun /*
1895*4882a593Smuzhiyun * Returns false if the frame couldn't be transmitted but was queued instead.
1896*4882a593Smuzhiyun */
ieee80211_tx(struct ieee80211_sub_if_data * sdata,struct sta_info * sta,struct sk_buff * skb,bool txpending)1897*4882a593Smuzhiyun static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata,
1898*4882a593Smuzhiyun struct sta_info *sta, struct sk_buff *skb,
1899*4882a593Smuzhiyun bool txpending)
1900*4882a593Smuzhiyun {
1901*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
1902*4882a593Smuzhiyun struct ieee80211_tx_data tx;
1903*4882a593Smuzhiyun ieee80211_tx_result res_prepare;
1904*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1905*4882a593Smuzhiyun bool result = true;
1906*4882a593Smuzhiyun int led_len;
1907*4882a593Smuzhiyun
1908*4882a593Smuzhiyun if (unlikely(skb->len < 10)) {
1909*4882a593Smuzhiyun dev_kfree_skb(skb);
1910*4882a593Smuzhiyun return true;
1911*4882a593Smuzhiyun }
1912*4882a593Smuzhiyun
1913*4882a593Smuzhiyun /* initialises tx */
1914*4882a593Smuzhiyun led_len = skb->len;
1915*4882a593Smuzhiyun res_prepare = ieee80211_tx_prepare(sdata, &tx, sta, skb);
1916*4882a593Smuzhiyun
1917*4882a593Smuzhiyun if (unlikely(res_prepare == TX_DROP)) {
1918*4882a593Smuzhiyun ieee80211_free_txskb(&local->hw, skb);
1919*4882a593Smuzhiyun return true;
1920*4882a593Smuzhiyun } else if (unlikely(res_prepare == TX_QUEUED)) {
1921*4882a593Smuzhiyun return true;
1922*4882a593Smuzhiyun }
1923*4882a593Smuzhiyun
1924*4882a593Smuzhiyun /* set up hw_queue value early */
1925*4882a593Smuzhiyun if (!(info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) ||
1926*4882a593Smuzhiyun !ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
1927*4882a593Smuzhiyun info->hw_queue =
1928*4882a593Smuzhiyun sdata->vif.hw_queue[skb_get_queue_mapping(skb)];
1929*4882a593Smuzhiyun
1930*4882a593Smuzhiyun if (invoke_tx_handlers_early(&tx))
1931*4882a593Smuzhiyun return true;
1932*4882a593Smuzhiyun
1933*4882a593Smuzhiyun if (ieee80211_queue_skb(local, sdata, tx.sta, tx.skb))
1934*4882a593Smuzhiyun return true;
1935*4882a593Smuzhiyun
1936*4882a593Smuzhiyun if (!invoke_tx_handlers_late(&tx))
1937*4882a593Smuzhiyun result = __ieee80211_tx(local, &tx.skbs, led_len,
1938*4882a593Smuzhiyun tx.sta, txpending);
1939*4882a593Smuzhiyun
1940*4882a593Smuzhiyun return result;
1941*4882a593Smuzhiyun }
1942*4882a593Smuzhiyun
1943*4882a593Smuzhiyun /* device xmit handlers */
1944*4882a593Smuzhiyun
1945*4882a593Smuzhiyun enum ieee80211_encrypt {
1946*4882a593Smuzhiyun ENCRYPT_NO,
1947*4882a593Smuzhiyun ENCRYPT_MGMT,
1948*4882a593Smuzhiyun ENCRYPT_DATA,
1949*4882a593Smuzhiyun };
1950*4882a593Smuzhiyun
ieee80211_skb_resize(struct ieee80211_sub_if_data * sdata,struct sk_buff * skb,int head_need,enum ieee80211_encrypt encrypt)1951*4882a593Smuzhiyun static int ieee80211_skb_resize(struct ieee80211_sub_if_data *sdata,
1952*4882a593Smuzhiyun struct sk_buff *skb,
1953*4882a593Smuzhiyun int head_need,
1954*4882a593Smuzhiyun enum ieee80211_encrypt encrypt)
1955*4882a593Smuzhiyun {
1956*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
1957*4882a593Smuzhiyun bool enc_tailroom;
1958*4882a593Smuzhiyun int tail_need = 0;
1959*4882a593Smuzhiyun
1960*4882a593Smuzhiyun enc_tailroom = encrypt == ENCRYPT_MGMT ||
1961*4882a593Smuzhiyun (encrypt == ENCRYPT_DATA &&
1962*4882a593Smuzhiyun sdata->crypto_tx_tailroom_needed_cnt);
1963*4882a593Smuzhiyun
1964*4882a593Smuzhiyun if (enc_tailroom) {
1965*4882a593Smuzhiyun tail_need = IEEE80211_ENCRYPT_TAILROOM;
1966*4882a593Smuzhiyun tail_need -= skb_tailroom(skb);
1967*4882a593Smuzhiyun tail_need = max_t(int, tail_need, 0);
1968*4882a593Smuzhiyun }
1969*4882a593Smuzhiyun
1970*4882a593Smuzhiyun if (skb_cloned(skb) &&
1971*4882a593Smuzhiyun (!ieee80211_hw_check(&local->hw, SUPPORTS_CLONED_SKBS) ||
1972*4882a593Smuzhiyun !skb_clone_writable(skb, ETH_HLEN) || enc_tailroom))
1973*4882a593Smuzhiyun I802_DEBUG_INC(local->tx_expand_skb_head_cloned);
1974*4882a593Smuzhiyun else if (head_need || tail_need)
1975*4882a593Smuzhiyun I802_DEBUG_INC(local->tx_expand_skb_head);
1976*4882a593Smuzhiyun else
1977*4882a593Smuzhiyun return 0;
1978*4882a593Smuzhiyun
1979*4882a593Smuzhiyun if (pskb_expand_head(skb, head_need, tail_need, GFP_ATOMIC)) {
1980*4882a593Smuzhiyun wiphy_debug(local->hw.wiphy,
1981*4882a593Smuzhiyun "failed to reallocate TX buffer\n");
1982*4882a593Smuzhiyun return -ENOMEM;
1983*4882a593Smuzhiyun }
1984*4882a593Smuzhiyun
1985*4882a593Smuzhiyun return 0;
1986*4882a593Smuzhiyun }
1987*4882a593Smuzhiyun
ieee80211_xmit(struct ieee80211_sub_if_data * sdata,struct sta_info * sta,struct sk_buff * skb)1988*4882a593Smuzhiyun void ieee80211_xmit(struct ieee80211_sub_if_data *sdata,
1989*4882a593Smuzhiyun struct sta_info *sta, struct sk_buff *skb)
1990*4882a593Smuzhiyun {
1991*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
1992*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1993*4882a593Smuzhiyun struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1994*4882a593Smuzhiyun int headroom;
1995*4882a593Smuzhiyun enum ieee80211_encrypt encrypt;
1996*4882a593Smuzhiyun
1997*4882a593Smuzhiyun if (info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)
1998*4882a593Smuzhiyun encrypt = ENCRYPT_NO;
1999*4882a593Smuzhiyun else if (ieee80211_is_mgmt(hdr->frame_control))
2000*4882a593Smuzhiyun encrypt = ENCRYPT_MGMT;
2001*4882a593Smuzhiyun else
2002*4882a593Smuzhiyun encrypt = ENCRYPT_DATA;
2003*4882a593Smuzhiyun
2004*4882a593Smuzhiyun headroom = local->tx_headroom;
2005*4882a593Smuzhiyun if (encrypt != ENCRYPT_NO)
2006*4882a593Smuzhiyun headroom += sdata->encrypt_headroom;
2007*4882a593Smuzhiyun headroom -= skb_headroom(skb);
2008*4882a593Smuzhiyun headroom = max_t(int, 0, headroom);
2009*4882a593Smuzhiyun
2010*4882a593Smuzhiyun if (ieee80211_skb_resize(sdata, skb, headroom, encrypt)) {
2011*4882a593Smuzhiyun ieee80211_free_txskb(&local->hw, skb);
2012*4882a593Smuzhiyun return;
2013*4882a593Smuzhiyun }
2014*4882a593Smuzhiyun
2015*4882a593Smuzhiyun /* reload after potential resize */
2016*4882a593Smuzhiyun hdr = (struct ieee80211_hdr *) skb->data;
2017*4882a593Smuzhiyun info->control.vif = &sdata->vif;
2018*4882a593Smuzhiyun
2019*4882a593Smuzhiyun if (ieee80211_vif_is_mesh(&sdata->vif)) {
2020*4882a593Smuzhiyun if (ieee80211_is_data(hdr->frame_control) &&
2021*4882a593Smuzhiyun is_unicast_ether_addr(hdr->addr1)) {
2022*4882a593Smuzhiyun if (mesh_nexthop_resolve(sdata, skb))
2023*4882a593Smuzhiyun return; /* skb queued: don't free */
2024*4882a593Smuzhiyun } else {
2025*4882a593Smuzhiyun ieee80211_mps_set_frame_flags(sdata, NULL, hdr);
2026*4882a593Smuzhiyun }
2027*4882a593Smuzhiyun }
2028*4882a593Smuzhiyun
2029*4882a593Smuzhiyun ieee80211_set_qos_hdr(sdata, skb);
2030*4882a593Smuzhiyun ieee80211_tx(sdata, sta, skb, false);
2031*4882a593Smuzhiyun }
2032*4882a593Smuzhiyun
ieee80211_validate_radiotap_len(struct sk_buff * skb)2033*4882a593Smuzhiyun static bool ieee80211_validate_radiotap_len(struct sk_buff *skb)
2034*4882a593Smuzhiyun {
2035*4882a593Smuzhiyun struct ieee80211_radiotap_header *rthdr =
2036*4882a593Smuzhiyun (struct ieee80211_radiotap_header *)skb->data;
2037*4882a593Smuzhiyun
2038*4882a593Smuzhiyun /* check for not even having the fixed radiotap header part */
2039*4882a593Smuzhiyun if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
2040*4882a593Smuzhiyun return false; /* too short to be possibly valid */
2041*4882a593Smuzhiyun
2042*4882a593Smuzhiyun /* is it a header version we can trust to find length from? */
2043*4882a593Smuzhiyun if (unlikely(rthdr->it_version))
2044*4882a593Smuzhiyun return false; /* only version 0 is supported */
2045*4882a593Smuzhiyun
2046*4882a593Smuzhiyun /* does the skb contain enough to deliver on the alleged length? */
2047*4882a593Smuzhiyun if (unlikely(skb->len < ieee80211_get_radiotap_len(skb->data)))
2048*4882a593Smuzhiyun return false; /* skb too short for claimed rt header extent */
2049*4882a593Smuzhiyun
2050*4882a593Smuzhiyun return true;
2051*4882a593Smuzhiyun }
2052*4882a593Smuzhiyun
ieee80211_parse_tx_radiotap(struct sk_buff * skb,struct net_device * dev)2053*4882a593Smuzhiyun bool ieee80211_parse_tx_radiotap(struct sk_buff *skb,
2054*4882a593Smuzhiyun struct net_device *dev)
2055*4882a593Smuzhiyun {
2056*4882a593Smuzhiyun struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2057*4882a593Smuzhiyun struct ieee80211_radiotap_iterator iterator;
2058*4882a593Smuzhiyun struct ieee80211_radiotap_header *rthdr =
2059*4882a593Smuzhiyun (struct ieee80211_radiotap_header *) skb->data;
2060*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2061*4882a593Smuzhiyun int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len,
2062*4882a593Smuzhiyun NULL);
2063*4882a593Smuzhiyun u16 txflags;
2064*4882a593Smuzhiyun u16 rate = 0;
2065*4882a593Smuzhiyun bool rate_found = false;
2066*4882a593Smuzhiyun u8 rate_retries = 0;
2067*4882a593Smuzhiyun u16 rate_flags = 0;
2068*4882a593Smuzhiyun u8 mcs_known, mcs_flags, mcs_bw;
2069*4882a593Smuzhiyun u16 vht_known;
2070*4882a593Smuzhiyun u8 vht_mcs = 0, vht_nss = 0;
2071*4882a593Smuzhiyun int i;
2072*4882a593Smuzhiyun
2073*4882a593Smuzhiyun if (!ieee80211_validate_radiotap_len(skb))
2074*4882a593Smuzhiyun return false;
2075*4882a593Smuzhiyun
2076*4882a593Smuzhiyun info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
2077*4882a593Smuzhiyun IEEE80211_TX_CTL_DONTFRAG;
2078*4882a593Smuzhiyun
2079*4882a593Smuzhiyun /*
2080*4882a593Smuzhiyun * for every radiotap entry that is present
2081*4882a593Smuzhiyun * (ieee80211_radiotap_iterator_next returns -ENOENT when no more
2082*4882a593Smuzhiyun * entries present, or -EINVAL on error)
2083*4882a593Smuzhiyun */
2084*4882a593Smuzhiyun
2085*4882a593Smuzhiyun while (!ret) {
2086*4882a593Smuzhiyun ret = ieee80211_radiotap_iterator_next(&iterator);
2087*4882a593Smuzhiyun
2088*4882a593Smuzhiyun if (ret)
2089*4882a593Smuzhiyun continue;
2090*4882a593Smuzhiyun
2091*4882a593Smuzhiyun /* see if this argument is something we can use */
2092*4882a593Smuzhiyun switch (iterator.this_arg_index) {
2093*4882a593Smuzhiyun /*
2094*4882a593Smuzhiyun * You must take care when dereferencing iterator.this_arg
2095*4882a593Smuzhiyun * for multibyte types... the pointer is not aligned. Use
2096*4882a593Smuzhiyun * get_unaligned((type *)iterator.this_arg) to dereference
2097*4882a593Smuzhiyun * iterator.this_arg for type "type" safely on all arches.
2098*4882a593Smuzhiyun */
2099*4882a593Smuzhiyun case IEEE80211_RADIOTAP_FLAGS:
2100*4882a593Smuzhiyun if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) {
2101*4882a593Smuzhiyun /*
2102*4882a593Smuzhiyun * this indicates that the skb we have been
2103*4882a593Smuzhiyun * handed has the 32-bit FCS CRC at the end...
2104*4882a593Smuzhiyun * we should react to that by snipping it off
2105*4882a593Smuzhiyun * because it will be recomputed and added
2106*4882a593Smuzhiyun * on transmission
2107*4882a593Smuzhiyun */
2108*4882a593Smuzhiyun if (skb->len < (iterator._max_length + FCS_LEN))
2109*4882a593Smuzhiyun return false;
2110*4882a593Smuzhiyun
2111*4882a593Smuzhiyun skb_trim(skb, skb->len - FCS_LEN);
2112*4882a593Smuzhiyun }
2113*4882a593Smuzhiyun if (*iterator.this_arg & IEEE80211_RADIOTAP_F_WEP)
2114*4882a593Smuzhiyun info->flags &= ~IEEE80211_TX_INTFL_DONT_ENCRYPT;
2115*4882a593Smuzhiyun if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG)
2116*4882a593Smuzhiyun info->flags &= ~IEEE80211_TX_CTL_DONTFRAG;
2117*4882a593Smuzhiyun break;
2118*4882a593Smuzhiyun
2119*4882a593Smuzhiyun case IEEE80211_RADIOTAP_TX_FLAGS:
2120*4882a593Smuzhiyun txflags = get_unaligned_le16(iterator.this_arg);
2121*4882a593Smuzhiyun if (txflags & IEEE80211_RADIOTAP_F_TX_NOACK)
2122*4882a593Smuzhiyun info->flags |= IEEE80211_TX_CTL_NO_ACK;
2123*4882a593Smuzhiyun if (txflags & IEEE80211_RADIOTAP_F_TX_NOSEQNO)
2124*4882a593Smuzhiyun info->control.flags |= IEEE80211_TX_CTRL_NO_SEQNO;
2125*4882a593Smuzhiyun break;
2126*4882a593Smuzhiyun
2127*4882a593Smuzhiyun case IEEE80211_RADIOTAP_RATE:
2128*4882a593Smuzhiyun rate = *iterator.this_arg;
2129*4882a593Smuzhiyun rate_flags = 0;
2130*4882a593Smuzhiyun rate_found = true;
2131*4882a593Smuzhiyun break;
2132*4882a593Smuzhiyun
2133*4882a593Smuzhiyun case IEEE80211_RADIOTAP_DATA_RETRIES:
2134*4882a593Smuzhiyun rate_retries = *iterator.this_arg;
2135*4882a593Smuzhiyun break;
2136*4882a593Smuzhiyun
2137*4882a593Smuzhiyun case IEEE80211_RADIOTAP_MCS:
2138*4882a593Smuzhiyun mcs_known = iterator.this_arg[0];
2139*4882a593Smuzhiyun mcs_flags = iterator.this_arg[1];
2140*4882a593Smuzhiyun if (!(mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_MCS))
2141*4882a593Smuzhiyun break;
2142*4882a593Smuzhiyun
2143*4882a593Smuzhiyun rate_found = true;
2144*4882a593Smuzhiyun rate = iterator.this_arg[2];
2145*4882a593Smuzhiyun rate_flags = IEEE80211_TX_RC_MCS;
2146*4882a593Smuzhiyun
2147*4882a593Smuzhiyun if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_GI &&
2148*4882a593Smuzhiyun mcs_flags & IEEE80211_RADIOTAP_MCS_SGI)
2149*4882a593Smuzhiyun rate_flags |= IEEE80211_TX_RC_SHORT_GI;
2150*4882a593Smuzhiyun
2151*4882a593Smuzhiyun mcs_bw = mcs_flags & IEEE80211_RADIOTAP_MCS_BW_MASK;
2152*4882a593Smuzhiyun if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_BW &&
2153*4882a593Smuzhiyun mcs_bw == IEEE80211_RADIOTAP_MCS_BW_40)
2154*4882a593Smuzhiyun rate_flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
2155*4882a593Smuzhiyun break;
2156*4882a593Smuzhiyun
2157*4882a593Smuzhiyun case IEEE80211_RADIOTAP_VHT:
2158*4882a593Smuzhiyun vht_known = get_unaligned_le16(iterator.this_arg);
2159*4882a593Smuzhiyun rate_found = true;
2160*4882a593Smuzhiyun
2161*4882a593Smuzhiyun rate_flags = IEEE80211_TX_RC_VHT_MCS;
2162*4882a593Smuzhiyun if ((vht_known & IEEE80211_RADIOTAP_VHT_KNOWN_GI) &&
2163*4882a593Smuzhiyun (iterator.this_arg[2] &
2164*4882a593Smuzhiyun IEEE80211_RADIOTAP_VHT_FLAG_SGI))
2165*4882a593Smuzhiyun rate_flags |= IEEE80211_TX_RC_SHORT_GI;
2166*4882a593Smuzhiyun if (vht_known &
2167*4882a593Smuzhiyun IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH) {
2168*4882a593Smuzhiyun if (iterator.this_arg[3] == 1)
2169*4882a593Smuzhiyun rate_flags |=
2170*4882a593Smuzhiyun IEEE80211_TX_RC_40_MHZ_WIDTH;
2171*4882a593Smuzhiyun else if (iterator.this_arg[3] == 4)
2172*4882a593Smuzhiyun rate_flags |=
2173*4882a593Smuzhiyun IEEE80211_TX_RC_80_MHZ_WIDTH;
2174*4882a593Smuzhiyun else if (iterator.this_arg[3] == 11)
2175*4882a593Smuzhiyun rate_flags |=
2176*4882a593Smuzhiyun IEEE80211_TX_RC_160_MHZ_WIDTH;
2177*4882a593Smuzhiyun }
2178*4882a593Smuzhiyun
2179*4882a593Smuzhiyun vht_mcs = iterator.this_arg[4] >> 4;
2180*4882a593Smuzhiyun if (vht_mcs > 11)
2181*4882a593Smuzhiyun vht_mcs = 0;
2182*4882a593Smuzhiyun vht_nss = iterator.this_arg[4] & 0xF;
2183*4882a593Smuzhiyun if (!vht_nss || vht_nss > 8)
2184*4882a593Smuzhiyun vht_nss = 1;
2185*4882a593Smuzhiyun break;
2186*4882a593Smuzhiyun
2187*4882a593Smuzhiyun /*
2188*4882a593Smuzhiyun * Please update the file
2189*4882a593Smuzhiyun * Documentation/networking/mac80211-injection.rst
2190*4882a593Smuzhiyun * when parsing new fields here.
2191*4882a593Smuzhiyun */
2192*4882a593Smuzhiyun
2193*4882a593Smuzhiyun default:
2194*4882a593Smuzhiyun break;
2195*4882a593Smuzhiyun }
2196*4882a593Smuzhiyun }
2197*4882a593Smuzhiyun
2198*4882a593Smuzhiyun if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */
2199*4882a593Smuzhiyun return false;
2200*4882a593Smuzhiyun
2201*4882a593Smuzhiyun if (rate_found) {
2202*4882a593Smuzhiyun struct ieee80211_supported_band *sband =
2203*4882a593Smuzhiyun local->hw.wiphy->bands[info->band];
2204*4882a593Smuzhiyun
2205*4882a593Smuzhiyun info->control.flags |= IEEE80211_TX_CTRL_RATE_INJECT;
2206*4882a593Smuzhiyun
2207*4882a593Smuzhiyun for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
2208*4882a593Smuzhiyun info->control.rates[i].idx = -1;
2209*4882a593Smuzhiyun info->control.rates[i].flags = 0;
2210*4882a593Smuzhiyun info->control.rates[i].count = 0;
2211*4882a593Smuzhiyun }
2212*4882a593Smuzhiyun
2213*4882a593Smuzhiyun if (rate_flags & IEEE80211_TX_RC_MCS) {
2214*4882a593Smuzhiyun info->control.rates[0].idx = rate;
2215*4882a593Smuzhiyun } else if (rate_flags & IEEE80211_TX_RC_VHT_MCS) {
2216*4882a593Smuzhiyun ieee80211_rate_set_vht(info->control.rates, vht_mcs,
2217*4882a593Smuzhiyun vht_nss);
2218*4882a593Smuzhiyun } else if (sband) {
2219*4882a593Smuzhiyun for (i = 0; i < sband->n_bitrates; i++) {
2220*4882a593Smuzhiyun if (rate * 5 != sband->bitrates[i].bitrate)
2221*4882a593Smuzhiyun continue;
2222*4882a593Smuzhiyun
2223*4882a593Smuzhiyun info->control.rates[0].idx = i;
2224*4882a593Smuzhiyun break;
2225*4882a593Smuzhiyun }
2226*4882a593Smuzhiyun }
2227*4882a593Smuzhiyun
2228*4882a593Smuzhiyun if (info->control.rates[0].idx < 0)
2229*4882a593Smuzhiyun info->control.flags &= ~IEEE80211_TX_CTRL_RATE_INJECT;
2230*4882a593Smuzhiyun
2231*4882a593Smuzhiyun info->control.rates[0].flags = rate_flags;
2232*4882a593Smuzhiyun info->control.rates[0].count = min_t(u8, rate_retries + 1,
2233*4882a593Smuzhiyun local->hw.max_rate_tries);
2234*4882a593Smuzhiyun }
2235*4882a593Smuzhiyun
2236*4882a593Smuzhiyun return true;
2237*4882a593Smuzhiyun }
2238*4882a593Smuzhiyun
ieee80211_monitor_start_xmit(struct sk_buff * skb,struct net_device * dev)2239*4882a593Smuzhiyun netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
2240*4882a593Smuzhiyun struct net_device *dev)
2241*4882a593Smuzhiyun {
2242*4882a593Smuzhiyun struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2243*4882a593Smuzhiyun struct ieee80211_chanctx_conf *chanctx_conf;
2244*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2245*4882a593Smuzhiyun struct ieee80211_hdr *hdr;
2246*4882a593Smuzhiyun struct ieee80211_sub_if_data *tmp_sdata, *sdata;
2247*4882a593Smuzhiyun struct cfg80211_chan_def *chandef;
2248*4882a593Smuzhiyun u16 len_rthdr;
2249*4882a593Smuzhiyun int hdrlen;
2250*4882a593Smuzhiyun
2251*4882a593Smuzhiyun memset(info, 0, sizeof(*info));
2252*4882a593Smuzhiyun info->flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2253*4882a593Smuzhiyun IEEE80211_TX_CTL_INJECTED;
2254*4882a593Smuzhiyun
2255*4882a593Smuzhiyun /* Sanity-check the length of the radiotap header */
2256*4882a593Smuzhiyun if (!ieee80211_validate_radiotap_len(skb))
2257*4882a593Smuzhiyun goto fail;
2258*4882a593Smuzhiyun
2259*4882a593Smuzhiyun /* we now know there is a radiotap header with a length we can use */
2260*4882a593Smuzhiyun len_rthdr = ieee80211_get_radiotap_len(skb->data);
2261*4882a593Smuzhiyun
2262*4882a593Smuzhiyun /*
2263*4882a593Smuzhiyun * fix up the pointers accounting for the radiotap
2264*4882a593Smuzhiyun * header still being in there. We are being given
2265*4882a593Smuzhiyun * a precooked IEEE80211 header so no need for
2266*4882a593Smuzhiyun * normal processing
2267*4882a593Smuzhiyun */
2268*4882a593Smuzhiyun skb_set_mac_header(skb, len_rthdr);
2269*4882a593Smuzhiyun /*
2270*4882a593Smuzhiyun * these are just fixed to the end of the rt area since we
2271*4882a593Smuzhiyun * don't have any better information and at this point, nobody cares
2272*4882a593Smuzhiyun */
2273*4882a593Smuzhiyun skb_set_network_header(skb, len_rthdr);
2274*4882a593Smuzhiyun skb_set_transport_header(skb, len_rthdr);
2275*4882a593Smuzhiyun
2276*4882a593Smuzhiyun if (skb->len < len_rthdr + 2)
2277*4882a593Smuzhiyun goto fail;
2278*4882a593Smuzhiyun
2279*4882a593Smuzhiyun hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
2280*4882a593Smuzhiyun hdrlen = ieee80211_hdrlen(hdr->frame_control);
2281*4882a593Smuzhiyun
2282*4882a593Smuzhiyun if (skb->len < len_rthdr + hdrlen)
2283*4882a593Smuzhiyun goto fail;
2284*4882a593Smuzhiyun
2285*4882a593Smuzhiyun /*
2286*4882a593Smuzhiyun * Initialize skb->protocol if the injected frame is a data frame
2287*4882a593Smuzhiyun * carrying a rfc1042 header
2288*4882a593Smuzhiyun */
2289*4882a593Smuzhiyun if (ieee80211_is_data(hdr->frame_control) &&
2290*4882a593Smuzhiyun skb->len >= len_rthdr + hdrlen + sizeof(rfc1042_header) + 2) {
2291*4882a593Smuzhiyun u8 *payload = (u8 *)hdr + hdrlen;
2292*4882a593Smuzhiyun
2293*4882a593Smuzhiyun if (ether_addr_equal(payload, rfc1042_header))
2294*4882a593Smuzhiyun skb->protocol = cpu_to_be16((payload[6] << 8) |
2295*4882a593Smuzhiyun payload[7]);
2296*4882a593Smuzhiyun }
2297*4882a593Smuzhiyun
2298*4882a593Smuzhiyun /*
2299*4882a593Smuzhiyun * Initialize skb->priority for QoS frames. This is put in the TID field
2300*4882a593Smuzhiyun * of the frame before passing it to the driver.
2301*4882a593Smuzhiyun */
2302*4882a593Smuzhiyun if (ieee80211_is_data_qos(hdr->frame_control)) {
2303*4882a593Smuzhiyun u8 *p = ieee80211_get_qos_ctl(hdr);
2304*4882a593Smuzhiyun skb->priority = *p & IEEE80211_QOS_CTL_TAG1D_MASK;
2305*4882a593Smuzhiyun }
2306*4882a593Smuzhiyun
2307*4882a593Smuzhiyun rcu_read_lock();
2308*4882a593Smuzhiyun
2309*4882a593Smuzhiyun /*
2310*4882a593Smuzhiyun * We process outgoing injected frames that have a local address
2311*4882a593Smuzhiyun * we handle as though they are non-injected frames.
2312*4882a593Smuzhiyun * This code here isn't entirely correct, the local MAC address
2313*4882a593Smuzhiyun * isn't always enough to find the interface to use; for proper
2314*4882a593Smuzhiyun * VLAN/WDS support we will need a different mechanism (which
2315*4882a593Smuzhiyun * likely isn't going to be monitor interfaces).
2316*4882a593Smuzhiyun *
2317*4882a593Smuzhiyun * This is necessary, for example, for old hostapd versions that
2318*4882a593Smuzhiyun * don't use nl80211-based management TX/RX.
2319*4882a593Smuzhiyun */
2320*4882a593Smuzhiyun sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2321*4882a593Smuzhiyun
2322*4882a593Smuzhiyun list_for_each_entry_rcu(tmp_sdata, &local->interfaces, list) {
2323*4882a593Smuzhiyun if (!ieee80211_sdata_running(tmp_sdata))
2324*4882a593Smuzhiyun continue;
2325*4882a593Smuzhiyun if (tmp_sdata->vif.type == NL80211_IFTYPE_MONITOR ||
2326*4882a593Smuzhiyun tmp_sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
2327*4882a593Smuzhiyun tmp_sdata->vif.type == NL80211_IFTYPE_WDS)
2328*4882a593Smuzhiyun continue;
2329*4882a593Smuzhiyun if (ether_addr_equal(tmp_sdata->vif.addr, hdr->addr2)) {
2330*4882a593Smuzhiyun sdata = tmp_sdata;
2331*4882a593Smuzhiyun break;
2332*4882a593Smuzhiyun }
2333*4882a593Smuzhiyun }
2334*4882a593Smuzhiyun
2335*4882a593Smuzhiyun chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2336*4882a593Smuzhiyun if (!chanctx_conf) {
2337*4882a593Smuzhiyun tmp_sdata = rcu_dereference(local->monitor_sdata);
2338*4882a593Smuzhiyun if (tmp_sdata)
2339*4882a593Smuzhiyun chanctx_conf =
2340*4882a593Smuzhiyun rcu_dereference(tmp_sdata->vif.chanctx_conf);
2341*4882a593Smuzhiyun }
2342*4882a593Smuzhiyun
2343*4882a593Smuzhiyun if (chanctx_conf)
2344*4882a593Smuzhiyun chandef = &chanctx_conf->def;
2345*4882a593Smuzhiyun else if (!local->use_chanctx)
2346*4882a593Smuzhiyun chandef = &local->_oper_chandef;
2347*4882a593Smuzhiyun else
2348*4882a593Smuzhiyun goto fail_rcu;
2349*4882a593Smuzhiyun
2350*4882a593Smuzhiyun /*
2351*4882a593Smuzhiyun * Frame injection is not allowed if beaconing is not allowed
2352*4882a593Smuzhiyun * or if we need radar detection. Beaconing is usually not allowed when
2353*4882a593Smuzhiyun * the mode or operation (Adhoc, AP, Mesh) does not support DFS.
2354*4882a593Smuzhiyun * Passive scan is also used in world regulatory domains where
2355*4882a593Smuzhiyun * your country is not known and as such it should be treated as
2356*4882a593Smuzhiyun * NO TX unless the channel is explicitly allowed in which case
2357*4882a593Smuzhiyun * your current regulatory domain would not have the passive scan
2358*4882a593Smuzhiyun * flag.
2359*4882a593Smuzhiyun *
2360*4882a593Smuzhiyun * Since AP mode uses monitor interfaces to inject/TX management
2361*4882a593Smuzhiyun * frames we can make AP mode the exception to this rule once it
2362*4882a593Smuzhiyun * supports radar detection as its implementation can deal with
2363*4882a593Smuzhiyun * radar detection by itself. We can do that later by adding a
2364*4882a593Smuzhiyun * monitor flag interfaces used for AP support.
2365*4882a593Smuzhiyun */
2366*4882a593Smuzhiyun if (!cfg80211_reg_can_beacon(local->hw.wiphy, chandef,
2367*4882a593Smuzhiyun sdata->vif.type))
2368*4882a593Smuzhiyun goto fail_rcu;
2369*4882a593Smuzhiyun
2370*4882a593Smuzhiyun info->band = chandef->chan->band;
2371*4882a593Smuzhiyun
2372*4882a593Smuzhiyun /*
2373*4882a593Smuzhiyun * Process the radiotap header. This will now take into account the
2374*4882a593Smuzhiyun * selected chandef above to accurately set injection rates and
2375*4882a593Smuzhiyun * retransmissions.
2376*4882a593Smuzhiyun */
2377*4882a593Smuzhiyun if (!ieee80211_parse_tx_radiotap(skb, dev))
2378*4882a593Smuzhiyun goto fail_rcu;
2379*4882a593Smuzhiyun
2380*4882a593Smuzhiyun /* remove the injection radiotap header */
2381*4882a593Smuzhiyun skb_pull(skb, len_rthdr);
2382*4882a593Smuzhiyun
2383*4882a593Smuzhiyun ieee80211_xmit(sdata, NULL, skb);
2384*4882a593Smuzhiyun rcu_read_unlock();
2385*4882a593Smuzhiyun
2386*4882a593Smuzhiyun return NETDEV_TX_OK;
2387*4882a593Smuzhiyun
2388*4882a593Smuzhiyun fail_rcu:
2389*4882a593Smuzhiyun rcu_read_unlock();
2390*4882a593Smuzhiyun fail:
2391*4882a593Smuzhiyun dev_kfree_skb(skb);
2392*4882a593Smuzhiyun return NETDEV_TX_OK; /* meaning, we dealt with the skb */
2393*4882a593Smuzhiyun }
2394*4882a593Smuzhiyun
ieee80211_is_tdls_setup(struct sk_buff * skb)2395*4882a593Smuzhiyun static inline bool ieee80211_is_tdls_setup(struct sk_buff *skb)
2396*4882a593Smuzhiyun {
2397*4882a593Smuzhiyun u16 ethertype = (skb->data[12] << 8) | skb->data[13];
2398*4882a593Smuzhiyun
2399*4882a593Smuzhiyun return ethertype == ETH_P_TDLS &&
2400*4882a593Smuzhiyun skb->len > 14 &&
2401*4882a593Smuzhiyun skb->data[14] == WLAN_TDLS_SNAP_RFTYPE;
2402*4882a593Smuzhiyun }
2403*4882a593Smuzhiyun
ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data * sdata,struct sk_buff * skb,struct sta_info ** sta_out)2404*4882a593Smuzhiyun int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata,
2405*4882a593Smuzhiyun struct sk_buff *skb,
2406*4882a593Smuzhiyun struct sta_info **sta_out)
2407*4882a593Smuzhiyun {
2408*4882a593Smuzhiyun struct sta_info *sta;
2409*4882a593Smuzhiyun
2410*4882a593Smuzhiyun switch (sdata->vif.type) {
2411*4882a593Smuzhiyun case NL80211_IFTYPE_AP_VLAN:
2412*4882a593Smuzhiyun sta = rcu_dereference(sdata->u.vlan.sta);
2413*4882a593Smuzhiyun if (sta) {
2414*4882a593Smuzhiyun *sta_out = sta;
2415*4882a593Smuzhiyun return 0;
2416*4882a593Smuzhiyun } else if (sdata->wdev.use_4addr) {
2417*4882a593Smuzhiyun return -ENOLINK;
2418*4882a593Smuzhiyun }
2419*4882a593Smuzhiyun fallthrough;
2420*4882a593Smuzhiyun case NL80211_IFTYPE_AP:
2421*4882a593Smuzhiyun case NL80211_IFTYPE_OCB:
2422*4882a593Smuzhiyun case NL80211_IFTYPE_ADHOC:
2423*4882a593Smuzhiyun if (is_multicast_ether_addr(skb->data)) {
2424*4882a593Smuzhiyun *sta_out = ERR_PTR(-ENOENT);
2425*4882a593Smuzhiyun return 0;
2426*4882a593Smuzhiyun }
2427*4882a593Smuzhiyun sta = sta_info_get_bss(sdata, skb->data);
2428*4882a593Smuzhiyun break;
2429*4882a593Smuzhiyun case NL80211_IFTYPE_WDS:
2430*4882a593Smuzhiyun sta = sta_info_get(sdata, sdata->u.wds.remote_addr);
2431*4882a593Smuzhiyun break;
2432*4882a593Smuzhiyun #ifdef CONFIG_MAC80211_MESH
2433*4882a593Smuzhiyun case NL80211_IFTYPE_MESH_POINT:
2434*4882a593Smuzhiyun /* determined much later */
2435*4882a593Smuzhiyun *sta_out = NULL;
2436*4882a593Smuzhiyun return 0;
2437*4882a593Smuzhiyun #endif
2438*4882a593Smuzhiyun case NL80211_IFTYPE_STATION:
2439*4882a593Smuzhiyun if (sdata->wdev.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) {
2440*4882a593Smuzhiyun sta = sta_info_get(sdata, skb->data);
2441*4882a593Smuzhiyun if (sta && test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
2442*4882a593Smuzhiyun if (test_sta_flag(sta,
2443*4882a593Smuzhiyun WLAN_STA_TDLS_PEER_AUTH)) {
2444*4882a593Smuzhiyun *sta_out = sta;
2445*4882a593Smuzhiyun return 0;
2446*4882a593Smuzhiyun }
2447*4882a593Smuzhiyun
2448*4882a593Smuzhiyun /*
2449*4882a593Smuzhiyun * TDLS link during setup - throw out frames to
2450*4882a593Smuzhiyun * peer. Allow TDLS-setup frames to unauthorized
2451*4882a593Smuzhiyun * peers for the special case of a link teardown
2452*4882a593Smuzhiyun * after a TDLS sta is removed due to being
2453*4882a593Smuzhiyun * unreachable.
2454*4882a593Smuzhiyun */
2455*4882a593Smuzhiyun if (!ieee80211_is_tdls_setup(skb))
2456*4882a593Smuzhiyun return -EINVAL;
2457*4882a593Smuzhiyun }
2458*4882a593Smuzhiyun
2459*4882a593Smuzhiyun }
2460*4882a593Smuzhiyun
2461*4882a593Smuzhiyun sta = sta_info_get(sdata, sdata->u.mgd.bssid);
2462*4882a593Smuzhiyun if (!sta)
2463*4882a593Smuzhiyun return -ENOLINK;
2464*4882a593Smuzhiyun break;
2465*4882a593Smuzhiyun default:
2466*4882a593Smuzhiyun return -EINVAL;
2467*4882a593Smuzhiyun }
2468*4882a593Smuzhiyun
2469*4882a593Smuzhiyun *sta_out = sta ?: ERR_PTR(-ENOENT);
2470*4882a593Smuzhiyun return 0;
2471*4882a593Smuzhiyun }
2472*4882a593Smuzhiyun
ieee80211_store_ack_skb(struct ieee80211_local * local,struct sk_buff * skb,u32 * info_flags,u64 * cookie)2473*4882a593Smuzhiyun static u16 ieee80211_store_ack_skb(struct ieee80211_local *local,
2474*4882a593Smuzhiyun struct sk_buff *skb,
2475*4882a593Smuzhiyun u32 *info_flags,
2476*4882a593Smuzhiyun u64 *cookie)
2477*4882a593Smuzhiyun {
2478*4882a593Smuzhiyun struct sk_buff *ack_skb;
2479*4882a593Smuzhiyun u16 info_id = 0;
2480*4882a593Smuzhiyun
2481*4882a593Smuzhiyun if (skb->sk)
2482*4882a593Smuzhiyun ack_skb = skb_clone_sk(skb);
2483*4882a593Smuzhiyun else
2484*4882a593Smuzhiyun ack_skb = skb_clone(skb, GFP_ATOMIC);
2485*4882a593Smuzhiyun
2486*4882a593Smuzhiyun if (ack_skb) {
2487*4882a593Smuzhiyun unsigned long flags;
2488*4882a593Smuzhiyun int id;
2489*4882a593Smuzhiyun
2490*4882a593Smuzhiyun spin_lock_irqsave(&local->ack_status_lock, flags);
2491*4882a593Smuzhiyun id = idr_alloc(&local->ack_status_frames, ack_skb,
2492*4882a593Smuzhiyun 1, 0x2000, GFP_ATOMIC);
2493*4882a593Smuzhiyun spin_unlock_irqrestore(&local->ack_status_lock, flags);
2494*4882a593Smuzhiyun
2495*4882a593Smuzhiyun if (id >= 0) {
2496*4882a593Smuzhiyun info_id = id;
2497*4882a593Smuzhiyun *info_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
2498*4882a593Smuzhiyun if (cookie) {
2499*4882a593Smuzhiyun *cookie = ieee80211_mgmt_tx_cookie(local);
2500*4882a593Smuzhiyun IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
2501*4882a593Smuzhiyun }
2502*4882a593Smuzhiyun } else {
2503*4882a593Smuzhiyun kfree_skb(ack_skb);
2504*4882a593Smuzhiyun }
2505*4882a593Smuzhiyun }
2506*4882a593Smuzhiyun
2507*4882a593Smuzhiyun return info_id;
2508*4882a593Smuzhiyun }
2509*4882a593Smuzhiyun
2510*4882a593Smuzhiyun /**
2511*4882a593Smuzhiyun * ieee80211_build_hdr - build 802.11 header in the given frame
2512*4882a593Smuzhiyun * @sdata: virtual interface to build the header for
2513*4882a593Smuzhiyun * @skb: the skb to build the header in
2514*4882a593Smuzhiyun * @info_flags: skb flags to set
2515*4882a593Smuzhiyun * @sta: the station pointer
2516*4882a593Smuzhiyun * @ctrl_flags: info control flags to set
2517*4882a593Smuzhiyun * @cookie: cookie pointer to fill (if not %NULL)
2518*4882a593Smuzhiyun *
2519*4882a593Smuzhiyun * This function takes the skb with 802.3 header and reformats the header to
2520*4882a593Smuzhiyun * the appropriate IEEE 802.11 header based on which interface the packet is
2521*4882a593Smuzhiyun * being transmitted on.
2522*4882a593Smuzhiyun *
2523*4882a593Smuzhiyun * Note that this function also takes care of the TX status request and
2524*4882a593Smuzhiyun * potential unsharing of the SKB - this needs to be interleaved with the
2525*4882a593Smuzhiyun * header building.
2526*4882a593Smuzhiyun *
2527*4882a593Smuzhiyun * The function requires the read-side RCU lock held
2528*4882a593Smuzhiyun *
2529*4882a593Smuzhiyun * Returns: the (possibly reallocated) skb or an ERR_PTR() code
2530*4882a593Smuzhiyun */
ieee80211_build_hdr(struct ieee80211_sub_if_data * sdata,struct sk_buff * skb,u32 info_flags,struct sta_info * sta,u32 ctrl_flags,u64 * cookie)2531*4882a593Smuzhiyun static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata,
2532*4882a593Smuzhiyun struct sk_buff *skb, u32 info_flags,
2533*4882a593Smuzhiyun struct sta_info *sta, u32 ctrl_flags,
2534*4882a593Smuzhiyun u64 *cookie)
2535*4882a593Smuzhiyun {
2536*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
2537*4882a593Smuzhiyun struct ieee80211_tx_info *info;
2538*4882a593Smuzhiyun int head_need;
2539*4882a593Smuzhiyun u16 ethertype, hdrlen, meshhdrlen = 0;
2540*4882a593Smuzhiyun __le16 fc;
2541*4882a593Smuzhiyun struct ieee80211_hdr hdr;
2542*4882a593Smuzhiyun struct ieee80211s_hdr mesh_hdr __maybe_unused;
2543*4882a593Smuzhiyun struct mesh_path __maybe_unused *mppath = NULL, *mpath = NULL;
2544*4882a593Smuzhiyun const u8 *encaps_data;
2545*4882a593Smuzhiyun int encaps_len, skip_header_bytes;
2546*4882a593Smuzhiyun bool wme_sta = false, authorized = false;
2547*4882a593Smuzhiyun bool tdls_peer;
2548*4882a593Smuzhiyun bool multicast;
2549*4882a593Smuzhiyun u16 info_id = 0;
2550*4882a593Smuzhiyun struct ieee80211_chanctx_conf *chanctx_conf;
2551*4882a593Smuzhiyun struct ieee80211_sub_if_data *ap_sdata;
2552*4882a593Smuzhiyun enum nl80211_band band;
2553*4882a593Smuzhiyun int ret;
2554*4882a593Smuzhiyun
2555*4882a593Smuzhiyun if (IS_ERR(sta))
2556*4882a593Smuzhiyun sta = NULL;
2557*4882a593Smuzhiyun
2558*4882a593Smuzhiyun #ifdef CONFIG_MAC80211_DEBUGFS
2559*4882a593Smuzhiyun if (local->force_tx_status)
2560*4882a593Smuzhiyun info_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
2561*4882a593Smuzhiyun #endif
2562*4882a593Smuzhiyun
2563*4882a593Smuzhiyun /* convert Ethernet header to proper 802.11 header (based on
2564*4882a593Smuzhiyun * operation mode) */
2565*4882a593Smuzhiyun ethertype = (skb->data[12] << 8) | skb->data[13];
2566*4882a593Smuzhiyun fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
2567*4882a593Smuzhiyun
2568*4882a593Smuzhiyun switch (sdata->vif.type) {
2569*4882a593Smuzhiyun case NL80211_IFTYPE_AP_VLAN:
2570*4882a593Smuzhiyun if (sdata->wdev.use_4addr) {
2571*4882a593Smuzhiyun fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
2572*4882a593Smuzhiyun /* RA TA DA SA */
2573*4882a593Smuzhiyun memcpy(hdr.addr1, sta->sta.addr, ETH_ALEN);
2574*4882a593Smuzhiyun memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
2575*4882a593Smuzhiyun memcpy(hdr.addr3, skb->data, ETH_ALEN);
2576*4882a593Smuzhiyun memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
2577*4882a593Smuzhiyun hdrlen = 30;
2578*4882a593Smuzhiyun authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
2579*4882a593Smuzhiyun wme_sta = sta->sta.wme;
2580*4882a593Smuzhiyun }
2581*4882a593Smuzhiyun ap_sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
2582*4882a593Smuzhiyun u.ap);
2583*4882a593Smuzhiyun chanctx_conf = rcu_dereference(ap_sdata->vif.chanctx_conf);
2584*4882a593Smuzhiyun if (!chanctx_conf) {
2585*4882a593Smuzhiyun ret = -ENOTCONN;
2586*4882a593Smuzhiyun goto free;
2587*4882a593Smuzhiyun }
2588*4882a593Smuzhiyun band = chanctx_conf->def.chan->band;
2589*4882a593Smuzhiyun if (sdata->wdev.use_4addr)
2590*4882a593Smuzhiyun break;
2591*4882a593Smuzhiyun fallthrough;
2592*4882a593Smuzhiyun case NL80211_IFTYPE_AP:
2593*4882a593Smuzhiyun if (sdata->vif.type == NL80211_IFTYPE_AP)
2594*4882a593Smuzhiyun chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2595*4882a593Smuzhiyun if (!chanctx_conf) {
2596*4882a593Smuzhiyun ret = -ENOTCONN;
2597*4882a593Smuzhiyun goto free;
2598*4882a593Smuzhiyun }
2599*4882a593Smuzhiyun fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
2600*4882a593Smuzhiyun /* DA BSSID SA */
2601*4882a593Smuzhiyun memcpy(hdr.addr1, skb->data, ETH_ALEN);
2602*4882a593Smuzhiyun memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
2603*4882a593Smuzhiyun memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
2604*4882a593Smuzhiyun hdrlen = 24;
2605*4882a593Smuzhiyun band = chanctx_conf->def.chan->band;
2606*4882a593Smuzhiyun break;
2607*4882a593Smuzhiyun case NL80211_IFTYPE_WDS:
2608*4882a593Smuzhiyun fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
2609*4882a593Smuzhiyun /* RA TA DA SA */
2610*4882a593Smuzhiyun memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN);
2611*4882a593Smuzhiyun memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
2612*4882a593Smuzhiyun memcpy(hdr.addr3, skb->data, ETH_ALEN);
2613*4882a593Smuzhiyun memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
2614*4882a593Smuzhiyun hdrlen = 30;
2615*4882a593Smuzhiyun /*
2616*4882a593Smuzhiyun * This is the exception! WDS style interfaces are prohibited
2617*4882a593Smuzhiyun * when channel contexts are in used so this must be valid
2618*4882a593Smuzhiyun */
2619*4882a593Smuzhiyun band = local->hw.conf.chandef.chan->band;
2620*4882a593Smuzhiyun break;
2621*4882a593Smuzhiyun #ifdef CONFIG_MAC80211_MESH
2622*4882a593Smuzhiyun case NL80211_IFTYPE_MESH_POINT:
2623*4882a593Smuzhiyun if (!is_multicast_ether_addr(skb->data)) {
2624*4882a593Smuzhiyun struct sta_info *next_hop;
2625*4882a593Smuzhiyun bool mpp_lookup = true;
2626*4882a593Smuzhiyun
2627*4882a593Smuzhiyun mpath = mesh_path_lookup(sdata, skb->data);
2628*4882a593Smuzhiyun if (mpath) {
2629*4882a593Smuzhiyun mpp_lookup = false;
2630*4882a593Smuzhiyun next_hop = rcu_dereference(mpath->next_hop);
2631*4882a593Smuzhiyun if (!next_hop ||
2632*4882a593Smuzhiyun !(mpath->flags & (MESH_PATH_ACTIVE |
2633*4882a593Smuzhiyun MESH_PATH_RESOLVING)))
2634*4882a593Smuzhiyun mpp_lookup = true;
2635*4882a593Smuzhiyun }
2636*4882a593Smuzhiyun
2637*4882a593Smuzhiyun if (mpp_lookup) {
2638*4882a593Smuzhiyun mppath = mpp_path_lookup(sdata, skb->data);
2639*4882a593Smuzhiyun if (mppath)
2640*4882a593Smuzhiyun mppath->exp_time = jiffies;
2641*4882a593Smuzhiyun }
2642*4882a593Smuzhiyun
2643*4882a593Smuzhiyun if (mppath && mpath)
2644*4882a593Smuzhiyun mesh_path_del(sdata, mpath->dst);
2645*4882a593Smuzhiyun }
2646*4882a593Smuzhiyun
2647*4882a593Smuzhiyun /*
2648*4882a593Smuzhiyun * Use address extension if it is a packet from
2649*4882a593Smuzhiyun * another interface or if we know the destination
2650*4882a593Smuzhiyun * is being proxied by a portal (i.e. portal address
2651*4882a593Smuzhiyun * differs from proxied address)
2652*4882a593Smuzhiyun */
2653*4882a593Smuzhiyun if (ether_addr_equal(sdata->vif.addr, skb->data + ETH_ALEN) &&
2654*4882a593Smuzhiyun !(mppath && !ether_addr_equal(mppath->mpp, skb->data))) {
2655*4882a593Smuzhiyun hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
2656*4882a593Smuzhiyun skb->data, skb->data + ETH_ALEN);
2657*4882a593Smuzhiyun meshhdrlen = ieee80211_new_mesh_header(sdata, &mesh_hdr,
2658*4882a593Smuzhiyun NULL, NULL);
2659*4882a593Smuzhiyun } else {
2660*4882a593Smuzhiyun /* DS -> MBSS (802.11-2012 13.11.3.3).
2661*4882a593Smuzhiyun * For unicast with unknown forwarding information,
2662*4882a593Smuzhiyun * destination might be in the MBSS or if that fails
2663*4882a593Smuzhiyun * forwarded to another mesh gate. In either case
2664*4882a593Smuzhiyun * resolution will be handled in ieee80211_xmit(), so
2665*4882a593Smuzhiyun * leave the original DA. This also works for mcast */
2666*4882a593Smuzhiyun const u8 *mesh_da = skb->data;
2667*4882a593Smuzhiyun
2668*4882a593Smuzhiyun if (mppath)
2669*4882a593Smuzhiyun mesh_da = mppath->mpp;
2670*4882a593Smuzhiyun else if (mpath)
2671*4882a593Smuzhiyun mesh_da = mpath->dst;
2672*4882a593Smuzhiyun
2673*4882a593Smuzhiyun hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
2674*4882a593Smuzhiyun mesh_da, sdata->vif.addr);
2675*4882a593Smuzhiyun if (is_multicast_ether_addr(mesh_da))
2676*4882a593Smuzhiyun /* DA TA mSA AE:SA */
2677*4882a593Smuzhiyun meshhdrlen = ieee80211_new_mesh_header(
2678*4882a593Smuzhiyun sdata, &mesh_hdr,
2679*4882a593Smuzhiyun skb->data + ETH_ALEN, NULL);
2680*4882a593Smuzhiyun else
2681*4882a593Smuzhiyun /* RA TA mDA mSA AE:DA SA */
2682*4882a593Smuzhiyun meshhdrlen = ieee80211_new_mesh_header(
2683*4882a593Smuzhiyun sdata, &mesh_hdr, skb->data,
2684*4882a593Smuzhiyun skb->data + ETH_ALEN);
2685*4882a593Smuzhiyun
2686*4882a593Smuzhiyun }
2687*4882a593Smuzhiyun chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2688*4882a593Smuzhiyun if (!chanctx_conf) {
2689*4882a593Smuzhiyun ret = -ENOTCONN;
2690*4882a593Smuzhiyun goto free;
2691*4882a593Smuzhiyun }
2692*4882a593Smuzhiyun band = chanctx_conf->def.chan->band;
2693*4882a593Smuzhiyun
2694*4882a593Smuzhiyun /* For injected frames, fill RA right away as nexthop lookup
2695*4882a593Smuzhiyun * will be skipped.
2696*4882a593Smuzhiyun */
2697*4882a593Smuzhiyun if ((ctrl_flags & IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP) &&
2698*4882a593Smuzhiyun is_zero_ether_addr(hdr.addr1))
2699*4882a593Smuzhiyun memcpy(hdr.addr1, skb->data, ETH_ALEN);
2700*4882a593Smuzhiyun break;
2701*4882a593Smuzhiyun #endif
2702*4882a593Smuzhiyun case NL80211_IFTYPE_STATION:
2703*4882a593Smuzhiyun /* we already did checks when looking up the RA STA */
2704*4882a593Smuzhiyun tdls_peer = test_sta_flag(sta, WLAN_STA_TDLS_PEER);
2705*4882a593Smuzhiyun
2706*4882a593Smuzhiyun if (tdls_peer) {
2707*4882a593Smuzhiyun /* DA SA BSSID */
2708*4882a593Smuzhiyun memcpy(hdr.addr1, skb->data, ETH_ALEN);
2709*4882a593Smuzhiyun memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2710*4882a593Smuzhiyun memcpy(hdr.addr3, sdata->u.mgd.bssid, ETH_ALEN);
2711*4882a593Smuzhiyun hdrlen = 24;
2712*4882a593Smuzhiyun } else if (sdata->u.mgd.use_4addr &&
2713*4882a593Smuzhiyun cpu_to_be16(ethertype) != sdata->control_port_protocol) {
2714*4882a593Smuzhiyun fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
2715*4882a593Smuzhiyun IEEE80211_FCTL_TODS);
2716*4882a593Smuzhiyun /* RA TA DA SA */
2717*4882a593Smuzhiyun memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN);
2718*4882a593Smuzhiyun memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
2719*4882a593Smuzhiyun memcpy(hdr.addr3, skb->data, ETH_ALEN);
2720*4882a593Smuzhiyun memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
2721*4882a593Smuzhiyun hdrlen = 30;
2722*4882a593Smuzhiyun } else {
2723*4882a593Smuzhiyun fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
2724*4882a593Smuzhiyun /* BSSID SA DA */
2725*4882a593Smuzhiyun memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN);
2726*4882a593Smuzhiyun memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2727*4882a593Smuzhiyun memcpy(hdr.addr3, skb->data, ETH_ALEN);
2728*4882a593Smuzhiyun hdrlen = 24;
2729*4882a593Smuzhiyun }
2730*4882a593Smuzhiyun chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2731*4882a593Smuzhiyun if (!chanctx_conf) {
2732*4882a593Smuzhiyun ret = -ENOTCONN;
2733*4882a593Smuzhiyun goto free;
2734*4882a593Smuzhiyun }
2735*4882a593Smuzhiyun band = chanctx_conf->def.chan->band;
2736*4882a593Smuzhiyun break;
2737*4882a593Smuzhiyun case NL80211_IFTYPE_OCB:
2738*4882a593Smuzhiyun /* DA SA BSSID */
2739*4882a593Smuzhiyun memcpy(hdr.addr1, skb->data, ETH_ALEN);
2740*4882a593Smuzhiyun memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2741*4882a593Smuzhiyun eth_broadcast_addr(hdr.addr3);
2742*4882a593Smuzhiyun hdrlen = 24;
2743*4882a593Smuzhiyun chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2744*4882a593Smuzhiyun if (!chanctx_conf) {
2745*4882a593Smuzhiyun ret = -ENOTCONN;
2746*4882a593Smuzhiyun goto free;
2747*4882a593Smuzhiyun }
2748*4882a593Smuzhiyun band = chanctx_conf->def.chan->band;
2749*4882a593Smuzhiyun break;
2750*4882a593Smuzhiyun case NL80211_IFTYPE_ADHOC:
2751*4882a593Smuzhiyun /* DA SA BSSID */
2752*4882a593Smuzhiyun memcpy(hdr.addr1, skb->data, ETH_ALEN);
2753*4882a593Smuzhiyun memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2754*4882a593Smuzhiyun memcpy(hdr.addr3, sdata->u.ibss.bssid, ETH_ALEN);
2755*4882a593Smuzhiyun hdrlen = 24;
2756*4882a593Smuzhiyun chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2757*4882a593Smuzhiyun if (!chanctx_conf) {
2758*4882a593Smuzhiyun ret = -ENOTCONN;
2759*4882a593Smuzhiyun goto free;
2760*4882a593Smuzhiyun }
2761*4882a593Smuzhiyun band = chanctx_conf->def.chan->band;
2762*4882a593Smuzhiyun break;
2763*4882a593Smuzhiyun default:
2764*4882a593Smuzhiyun ret = -EINVAL;
2765*4882a593Smuzhiyun goto free;
2766*4882a593Smuzhiyun }
2767*4882a593Smuzhiyun
2768*4882a593Smuzhiyun multicast = is_multicast_ether_addr(hdr.addr1);
2769*4882a593Smuzhiyun
2770*4882a593Smuzhiyun /* sta is always NULL for mesh */
2771*4882a593Smuzhiyun if (sta) {
2772*4882a593Smuzhiyun authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
2773*4882a593Smuzhiyun wme_sta = sta->sta.wme;
2774*4882a593Smuzhiyun } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
2775*4882a593Smuzhiyun /* For mesh, the use of the QoS header is mandatory */
2776*4882a593Smuzhiyun wme_sta = true;
2777*4882a593Smuzhiyun }
2778*4882a593Smuzhiyun
2779*4882a593Smuzhiyun /* receiver does QoS (which also means we do) use it */
2780*4882a593Smuzhiyun if (wme_sta) {
2781*4882a593Smuzhiyun fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
2782*4882a593Smuzhiyun hdrlen += 2;
2783*4882a593Smuzhiyun }
2784*4882a593Smuzhiyun
2785*4882a593Smuzhiyun /*
2786*4882a593Smuzhiyun * Drop unicast frames to unauthorised stations unless they are
2787*4882a593Smuzhiyun * EAPOL frames from the local station.
2788*4882a593Smuzhiyun */
2789*4882a593Smuzhiyun if (unlikely(!ieee80211_vif_is_mesh(&sdata->vif) &&
2790*4882a593Smuzhiyun (sdata->vif.type != NL80211_IFTYPE_OCB) &&
2791*4882a593Smuzhiyun !multicast && !authorized &&
2792*4882a593Smuzhiyun (cpu_to_be16(ethertype) != sdata->control_port_protocol ||
2793*4882a593Smuzhiyun !ether_addr_equal(sdata->vif.addr, skb->data + ETH_ALEN)))) {
2794*4882a593Smuzhiyun #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2795*4882a593Smuzhiyun net_info_ratelimited("%s: dropped frame to %pM (unauthorized port)\n",
2796*4882a593Smuzhiyun sdata->name, hdr.addr1);
2797*4882a593Smuzhiyun #endif
2798*4882a593Smuzhiyun
2799*4882a593Smuzhiyun I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
2800*4882a593Smuzhiyun
2801*4882a593Smuzhiyun ret = -EPERM;
2802*4882a593Smuzhiyun goto free;
2803*4882a593Smuzhiyun }
2804*4882a593Smuzhiyun
2805*4882a593Smuzhiyun if (unlikely(!multicast && ((skb->sk &&
2806*4882a593Smuzhiyun skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS) ||
2807*4882a593Smuzhiyun ctrl_flags & IEEE80211_TX_CTL_REQ_TX_STATUS)))
2808*4882a593Smuzhiyun info_id = ieee80211_store_ack_skb(local, skb, &info_flags,
2809*4882a593Smuzhiyun cookie);
2810*4882a593Smuzhiyun
2811*4882a593Smuzhiyun /*
2812*4882a593Smuzhiyun * If the skb is shared we need to obtain our own copy.
2813*4882a593Smuzhiyun */
2814*4882a593Smuzhiyun if (skb_shared(skb)) {
2815*4882a593Smuzhiyun struct sk_buff *tmp_skb = skb;
2816*4882a593Smuzhiyun
2817*4882a593Smuzhiyun /* can't happen -- skb is a clone if info_id != 0 */
2818*4882a593Smuzhiyun WARN_ON(info_id);
2819*4882a593Smuzhiyun
2820*4882a593Smuzhiyun skb = skb_clone(skb, GFP_ATOMIC);
2821*4882a593Smuzhiyun kfree_skb(tmp_skb);
2822*4882a593Smuzhiyun
2823*4882a593Smuzhiyun if (!skb) {
2824*4882a593Smuzhiyun ret = -ENOMEM;
2825*4882a593Smuzhiyun goto free;
2826*4882a593Smuzhiyun }
2827*4882a593Smuzhiyun }
2828*4882a593Smuzhiyun
2829*4882a593Smuzhiyun hdr.frame_control = fc;
2830*4882a593Smuzhiyun hdr.duration_id = 0;
2831*4882a593Smuzhiyun hdr.seq_ctrl = 0;
2832*4882a593Smuzhiyun
2833*4882a593Smuzhiyun skip_header_bytes = ETH_HLEN;
2834*4882a593Smuzhiyun if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
2835*4882a593Smuzhiyun encaps_data = bridge_tunnel_header;
2836*4882a593Smuzhiyun encaps_len = sizeof(bridge_tunnel_header);
2837*4882a593Smuzhiyun skip_header_bytes -= 2;
2838*4882a593Smuzhiyun } else if (ethertype >= ETH_P_802_3_MIN) {
2839*4882a593Smuzhiyun encaps_data = rfc1042_header;
2840*4882a593Smuzhiyun encaps_len = sizeof(rfc1042_header);
2841*4882a593Smuzhiyun skip_header_bytes -= 2;
2842*4882a593Smuzhiyun } else {
2843*4882a593Smuzhiyun encaps_data = NULL;
2844*4882a593Smuzhiyun encaps_len = 0;
2845*4882a593Smuzhiyun }
2846*4882a593Smuzhiyun
2847*4882a593Smuzhiyun skb_pull(skb, skip_header_bytes);
2848*4882a593Smuzhiyun head_need = hdrlen + encaps_len + meshhdrlen - skb_headroom(skb);
2849*4882a593Smuzhiyun
2850*4882a593Smuzhiyun /*
2851*4882a593Smuzhiyun * So we need to modify the skb header and hence need a copy of
2852*4882a593Smuzhiyun * that. The head_need variable above doesn't, so far, include
2853*4882a593Smuzhiyun * the needed header space that we don't need right away. If we
2854*4882a593Smuzhiyun * can, then we don't reallocate right now but only after the
2855*4882a593Smuzhiyun * frame arrives at the master device (if it does...)
2856*4882a593Smuzhiyun *
2857*4882a593Smuzhiyun * If we cannot, however, then we will reallocate to include all
2858*4882a593Smuzhiyun * the ever needed space. Also, if we need to reallocate it anyway,
2859*4882a593Smuzhiyun * make it big enough for everything we may ever need.
2860*4882a593Smuzhiyun */
2861*4882a593Smuzhiyun
2862*4882a593Smuzhiyun if (head_need > 0 || skb_cloned(skb)) {
2863*4882a593Smuzhiyun head_need += sdata->encrypt_headroom;
2864*4882a593Smuzhiyun head_need += local->tx_headroom;
2865*4882a593Smuzhiyun head_need = max_t(int, 0, head_need);
2866*4882a593Smuzhiyun if (ieee80211_skb_resize(sdata, skb, head_need, ENCRYPT_DATA)) {
2867*4882a593Smuzhiyun ieee80211_free_txskb(&local->hw, skb);
2868*4882a593Smuzhiyun skb = NULL;
2869*4882a593Smuzhiyun return ERR_PTR(-ENOMEM);
2870*4882a593Smuzhiyun }
2871*4882a593Smuzhiyun }
2872*4882a593Smuzhiyun
2873*4882a593Smuzhiyun if (encaps_data)
2874*4882a593Smuzhiyun memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
2875*4882a593Smuzhiyun
2876*4882a593Smuzhiyun #ifdef CONFIG_MAC80211_MESH
2877*4882a593Smuzhiyun if (meshhdrlen > 0)
2878*4882a593Smuzhiyun memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen);
2879*4882a593Smuzhiyun #endif
2880*4882a593Smuzhiyun
2881*4882a593Smuzhiyun if (ieee80211_is_data_qos(fc)) {
2882*4882a593Smuzhiyun __le16 *qos_control;
2883*4882a593Smuzhiyun
2884*4882a593Smuzhiyun qos_control = skb_push(skb, 2);
2885*4882a593Smuzhiyun memcpy(skb_push(skb, hdrlen - 2), &hdr, hdrlen - 2);
2886*4882a593Smuzhiyun /*
2887*4882a593Smuzhiyun * Maybe we could actually set some fields here, for now just
2888*4882a593Smuzhiyun * initialise to zero to indicate no special operation.
2889*4882a593Smuzhiyun */
2890*4882a593Smuzhiyun *qos_control = 0;
2891*4882a593Smuzhiyun } else
2892*4882a593Smuzhiyun memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
2893*4882a593Smuzhiyun
2894*4882a593Smuzhiyun skb_reset_mac_header(skb);
2895*4882a593Smuzhiyun
2896*4882a593Smuzhiyun info = IEEE80211_SKB_CB(skb);
2897*4882a593Smuzhiyun memset(info, 0, sizeof(*info));
2898*4882a593Smuzhiyun
2899*4882a593Smuzhiyun info->flags = info_flags;
2900*4882a593Smuzhiyun info->ack_frame_id = info_id;
2901*4882a593Smuzhiyun info->band = band;
2902*4882a593Smuzhiyun info->control.flags = ctrl_flags;
2903*4882a593Smuzhiyun
2904*4882a593Smuzhiyun return skb;
2905*4882a593Smuzhiyun free:
2906*4882a593Smuzhiyun kfree_skb(skb);
2907*4882a593Smuzhiyun return ERR_PTR(ret);
2908*4882a593Smuzhiyun }
2909*4882a593Smuzhiyun
2910*4882a593Smuzhiyun /*
2911*4882a593Smuzhiyun * fast-xmit overview
2912*4882a593Smuzhiyun *
2913*4882a593Smuzhiyun * The core idea of this fast-xmit is to remove per-packet checks by checking
2914*4882a593Smuzhiyun * them out of band. ieee80211_check_fast_xmit() implements the out-of-band
2915*4882a593Smuzhiyun * checks that are needed to get the sta->fast_tx pointer assigned, after which
2916*4882a593Smuzhiyun * much less work can be done per packet. For example, fragmentation must be
2917*4882a593Smuzhiyun * disabled or the fast_tx pointer will not be set. All the conditions are seen
2918*4882a593Smuzhiyun * in the code here.
2919*4882a593Smuzhiyun *
2920*4882a593Smuzhiyun * Once assigned, the fast_tx data structure also caches the per-packet 802.11
2921*4882a593Smuzhiyun * header and other data to aid packet processing in ieee80211_xmit_fast().
2922*4882a593Smuzhiyun *
2923*4882a593Smuzhiyun * The most difficult part of this is that when any of these assumptions
2924*4882a593Smuzhiyun * change, an external trigger (i.e. a call to ieee80211_clear_fast_xmit(),
2925*4882a593Smuzhiyun * ieee80211_check_fast_xmit() or friends) is required to reset the data,
2926*4882a593Smuzhiyun * since the per-packet code no longer checks the conditions. This is reflected
2927*4882a593Smuzhiyun * by the calls to these functions throughout the rest of the code, and must be
2928*4882a593Smuzhiyun * maintained if any of the TX path checks change.
2929*4882a593Smuzhiyun */
2930*4882a593Smuzhiyun
ieee80211_check_fast_xmit(struct sta_info * sta)2931*4882a593Smuzhiyun void ieee80211_check_fast_xmit(struct sta_info *sta)
2932*4882a593Smuzhiyun {
2933*4882a593Smuzhiyun struct ieee80211_fast_tx build = {}, *fast_tx = NULL, *old;
2934*4882a593Smuzhiyun struct ieee80211_local *local = sta->local;
2935*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = sta->sdata;
2936*4882a593Smuzhiyun struct ieee80211_hdr *hdr = (void *)build.hdr;
2937*4882a593Smuzhiyun struct ieee80211_chanctx_conf *chanctx_conf;
2938*4882a593Smuzhiyun __le16 fc;
2939*4882a593Smuzhiyun
2940*4882a593Smuzhiyun if (!ieee80211_hw_check(&local->hw, SUPPORT_FAST_XMIT))
2941*4882a593Smuzhiyun return;
2942*4882a593Smuzhiyun
2943*4882a593Smuzhiyun /* Locking here protects both the pointer itself, and against concurrent
2944*4882a593Smuzhiyun * invocations winning data access races to, e.g., the key pointer that
2945*4882a593Smuzhiyun * is used.
2946*4882a593Smuzhiyun * Without it, the invocation of this function right after the key
2947*4882a593Smuzhiyun * pointer changes wouldn't be sufficient, as another CPU could access
2948*4882a593Smuzhiyun * the pointer, then stall, and then do the cache update after the CPU
2949*4882a593Smuzhiyun * that invalidated the key.
2950*4882a593Smuzhiyun * With the locking, such scenarios cannot happen as the check for the
2951*4882a593Smuzhiyun * key and the fast-tx assignment are done atomically, so the CPU that
2952*4882a593Smuzhiyun * modifies the key will either wait or other one will see the key
2953*4882a593Smuzhiyun * cleared/changed already.
2954*4882a593Smuzhiyun */
2955*4882a593Smuzhiyun spin_lock_bh(&sta->lock);
2956*4882a593Smuzhiyun if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
2957*4882a593Smuzhiyun !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
2958*4882a593Smuzhiyun sdata->vif.type == NL80211_IFTYPE_STATION)
2959*4882a593Smuzhiyun goto out;
2960*4882a593Smuzhiyun
2961*4882a593Smuzhiyun if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2962*4882a593Smuzhiyun goto out;
2963*4882a593Smuzhiyun
2964*4882a593Smuzhiyun if (test_sta_flag(sta, WLAN_STA_PS_STA) ||
2965*4882a593Smuzhiyun test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
2966*4882a593Smuzhiyun test_sta_flag(sta, WLAN_STA_PS_DELIVER) ||
2967*4882a593Smuzhiyun test_sta_flag(sta, WLAN_STA_CLEAR_PS_FILT))
2968*4882a593Smuzhiyun goto out;
2969*4882a593Smuzhiyun
2970*4882a593Smuzhiyun if (sdata->noack_map)
2971*4882a593Smuzhiyun goto out;
2972*4882a593Smuzhiyun
2973*4882a593Smuzhiyun /* fast-xmit doesn't handle fragmentation at all */
2974*4882a593Smuzhiyun if (local->hw.wiphy->frag_threshold != (u32)-1 &&
2975*4882a593Smuzhiyun !ieee80211_hw_check(&local->hw, SUPPORTS_TX_FRAG))
2976*4882a593Smuzhiyun goto out;
2977*4882a593Smuzhiyun
2978*4882a593Smuzhiyun rcu_read_lock();
2979*4882a593Smuzhiyun chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2980*4882a593Smuzhiyun if (!chanctx_conf) {
2981*4882a593Smuzhiyun rcu_read_unlock();
2982*4882a593Smuzhiyun goto out;
2983*4882a593Smuzhiyun }
2984*4882a593Smuzhiyun build.band = chanctx_conf->def.chan->band;
2985*4882a593Smuzhiyun rcu_read_unlock();
2986*4882a593Smuzhiyun
2987*4882a593Smuzhiyun fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
2988*4882a593Smuzhiyun
2989*4882a593Smuzhiyun switch (sdata->vif.type) {
2990*4882a593Smuzhiyun case NL80211_IFTYPE_ADHOC:
2991*4882a593Smuzhiyun /* DA SA BSSID */
2992*4882a593Smuzhiyun build.da_offs = offsetof(struct ieee80211_hdr, addr1);
2993*4882a593Smuzhiyun build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
2994*4882a593Smuzhiyun memcpy(hdr->addr3, sdata->u.ibss.bssid, ETH_ALEN);
2995*4882a593Smuzhiyun build.hdr_len = 24;
2996*4882a593Smuzhiyun break;
2997*4882a593Smuzhiyun case NL80211_IFTYPE_STATION:
2998*4882a593Smuzhiyun if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
2999*4882a593Smuzhiyun /* DA SA BSSID */
3000*4882a593Smuzhiyun build.da_offs = offsetof(struct ieee80211_hdr, addr1);
3001*4882a593Smuzhiyun build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3002*4882a593Smuzhiyun memcpy(hdr->addr3, sdata->u.mgd.bssid, ETH_ALEN);
3003*4882a593Smuzhiyun build.hdr_len = 24;
3004*4882a593Smuzhiyun break;
3005*4882a593Smuzhiyun }
3006*4882a593Smuzhiyun
3007*4882a593Smuzhiyun if (sdata->u.mgd.use_4addr) {
3008*4882a593Smuzhiyun /* non-regular ethertype cannot use the fastpath */
3009*4882a593Smuzhiyun fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
3010*4882a593Smuzhiyun IEEE80211_FCTL_TODS);
3011*4882a593Smuzhiyun /* RA TA DA SA */
3012*4882a593Smuzhiyun memcpy(hdr->addr1, sdata->u.mgd.bssid, ETH_ALEN);
3013*4882a593Smuzhiyun memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
3014*4882a593Smuzhiyun build.da_offs = offsetof(struct ieee80211_hdr, addr3);
3015*4882a593Smuzhiyun build.sa_offs = offsetof(struct ieee80211_hdr, addr4);
3016*4882a593Smuzhiyun build.hdr_len = 30;
3017*4882a593Smuzhiyun break;
3018*4882a593Smuzhiyun }
3019*4882a593Smuzhiyun fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
3020*4882a593Smuzhiyun /* BSSID SA DA */
3021*4882a593Smuzhiyun memcpy(hdr->addr1, sdata->u.mgd.bssid, ETH_ALEN);
3022*4882a593Smuzhiyun build.da_offs = offsetof(struct ieee80211_hdr, addr3);
3023*4882a593Smuzhiyun build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
3024*4882a593Smuzhiyun build.hdr_len = 24;
3025*4882a593Smuzhiyun break;
3026*4882a593Smuzhiyun case NL80211_IFTYPE_AP_VLAN:
3027*4882a593Smuzhiyun if (sdata->wdev.use_4addr) {
3028*4882a593Smuzhiyun fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
3029*4882a593Smuzhiyun IEEE80211_FCTL_TODS);
3030*4882a593Smuzhiyun /* RA TA DA SA */
3031*4882a593Smuzhiyun memcpy(hdr->addr1, sta->sta.addr, ETH_ALEN);
3032*4882a593Smuzhiyun memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
3033*4882a593Smuzhiyun build.da_offs = offsetof(struct ieee80211_hdr, addr3);
3034*4882a593Smuzhiyun build.sa_offs = offsetof(struct ieee80211_hdr, addr4);
3035*4882a593Smuzhiyun build.hdr_len = 30;
3036*4882a593Smuzhiyun break;
3037*4882a593Smuzhiyun }
3038*4882a593Smuzhiyun fallthrough;
3039*4882a593Smuzhiyun case NL80211_IFTYPE_AP:
3040*4882a593Smuzhiyun fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
3041*4882a593Smuzhiyun /* DA BSSID SA */
3042*4882a593Smuzhiyun build.da_offs = offsetof(struct ieee80211_hdr, addr1);
3043*4882a593Smuzhiyun memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
3044*4882a593Smuzhiyun build.sa_offs = offsetof(struct ieee80211_hdr, addr3);
3045*4882a593Smuzhiyun build.hdr_len = 24;
3046*4882a593Smuzhiyun break;
3047*4882a593Smuzhiyun default:
3048*4882a593Smuzhiyun /* not handled on fast-xmit */
3049*4882a593Smuzhiyun goto out;
3050*4882a593Smuzhiyun }
3051*4882a593Smuzhiyun
3052*4882a593Smuzhiyun if (sta->sta.wme) {
3053*4882a593Smuzhiyun build.hdr_len += 2;
3054*4882a593Smuzhiyun fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3055*4882a593Smuzhiyun }
3056*4882a593Smuzhiyun
3057*4882a593Smuzhiyun /* We store the key here so there's no point in using rcu_dereference()
3058*4882a593Smuzhiyun * but that's fine because the code that changes the pointers will call
3059*4882a593Smuzhiyun * this function after doing so. For a single CPU that would be enough,
3060*4882a593Smuzhiyun * for multiple see the comment above.
3061*4882a593Smuzhiyun */
3062*4882a593Smuzhiyun build.key = rcu_access_pointer(sta->ptk[sta->ptk_idx]);
3063*4882a593Smuzhiyun if (!build.key)
3064*4882a593Smuzhiyun build.key = rcu_access_pointer(sdata->default_unicast_key);
3065*4882a593Smuzhiyun if (build.key) {
3066*4882a593Smuzhiyun bool gen_iv, iv_spc, mmic;
3067*4882a593Smuzhiyun
3068*4882a593Smuzhiyun gen_iv = build.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV;
3069*4882a593Smuzhiyun iv_spc = build.key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3070*4882a593Smuzhiyun mmic = build.key->conf.flags &
3071*4882a593Smuzhiyun (IEEE80211_KEY_FLAG_GENERATE_MMIC |
3072*4882a593Smuzhiyun IEEE80211_KEY_FLAG_PUT_MIC_SPACE);
3073*4882a593Smuzhiyun
3074*4882a593Smuzhiyun /* don't handle software crypto */
3075*4882a593Smuzhiyun if (!(build.key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
3076*4882a593Smuzhiyun goto out;
3077*4882a593Smuzhiyun
3078*4882a593Smuzhiyun /* Key is being removed */
3079*4882a593Smuzhiyun if (build.key->flags & KEY_FLAG_TAINTED)
3080*4882a593Smuzhiyun goto out;
3081*4882a593Smuzhiyun
3082*4882a593Smuzhiyun switch (build.key->conf.cipher) {
3083*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_CCMP:
3084*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_CCMP_256:
3085*4882a593Smuzhiyun if (gen_iv)
3086*4882a593Smuzhiyun build.pn_offs = build.hdr_len;
3087*4882a593Smuzhiyun if (gen_iv || iv_spc)
3088*4882a593Smuzhiyun build.hdr_len += IEEE80211_CCMP_HDR_LEN;
3089*4882a593Smuzhiyun break;
3090*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_GCMP:
3091*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_GCMP_256:
3092*4882a593Smuzhiyun if (gen_iv)
3093*4882a593Smuzhiyun build.pn_offs = build.hdr_len;
3094*4882a593Smuzhiyun if (gen_iv || iv_spc)
3095*4882a593Smuzhiyun build.hdr_len += IEEE80211_GCMP_HDR_LEN;
3096*4882a593Smuzhiyun break;
3097*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_TKIP:
3098*4882a593Smuzhiyun /* cannot handle MMIC or IV generation in xmit-fast */
3099*4882a593Smuzhiyun if (mmic || gen_iv)
3100*4882a593Smuzhiyun goto out;
3101*4882a593Smuzhiyun if (iv_spc)
3102*4882a593Smuzhiyun build.hdr_len += IEEE80211_TKIP_IV_LEN;
3103*4882a593Smuzhiyun break;
3104*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_WEP40:
3105*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_WEP104:
3106*4882a593Smuzhiyun /* cannot handle IV generation in fast-xmit */
3107*4882a593Smuzhiyun if (gen_iv)
3108*4882a593Smuzhiyun goto out;
3109*4882a593Smuzhiyun if (iv_spc)
3110*4882a593Smuzhiyun build.hdr_len += IEEE80211_WEP_IV_LEN;
3111*4882a593Smuzhiyun break;
3112*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_AES_CMAC:
3113*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_BIP_CMAC_256:
3114*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3115*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3116*4882a593Smuzhiyun WARN(1,
3117*4882a593Smuzhiyun "management cipher suite 0x%x enabled for data\n",
3118*4882a593Smuzhiyun build.key->conf.cipher);
3119*4882a593Smuzhiyun goto out;
3120*4882a593Smuzhiyun default:
3121*4882a593Smuzhiyun /* we don't know how to generate IVs for this at all */
3122*4882a593Smuzhiyun if (WARN_ON(gen_iv))
3123*4882a593Smuzhiyun goto out;
3124*4882a593Smuzhiyun /* pure hardware keys are OK, of course */
3125*4882a593Smuzhiyun if (!(build.key->flags & KEY_FLAG_CIPHER_SCHEME))
3126*4882a593Smuzhiyun break;
3127*4882a593Smuzhiyun /* cipher scheme might require space allocation */
3128*4882a593Smuzhiyun if (iv_spc &&
3129*4882a593Smuzhiyun build.key->conf.iv_len > IEEE80211_FAST_XMIT_MAX_IV)
3130*4882a593Smuzhiyun goto out;
3131*4882a593Smuzhiyun if (iv_spc)
3132*4882a593Smuzhiyun build.hdr_len += build.key->conf.iv_len;
3133*4882a593Smuzhiyun }
3134*4882a593Smuzhiyun
3135*4882a593Smuzhiyun fc |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
3136*4882a593Smuzhiyun }
3137*4882a593Smuzhiyun
3138*4882a593Smuzhiyun hdr->frame_control = fc;
3139*4882a593Smuzhiyun
3140*4882a593Smuzhiyun memcpy(build.hdr + build.hdr_len,
3141*4882a593Smuzhiyun rfc1042_header, sizeof(rfc1042_header));
3142*4882a593Smuzhiyun build.hdr_len += sizeof(rfc1042_header);
3143*4882a593Smuzhiyun
3144*4882a593Smuzhiyun fast_tx = kmemdup(&build, sizeof(build), GFP_ATOMIC);
3145*4882a593Smuzhiyun /* if the kmemdup fails, continue w/o fast_tx */
3146*4882a593Smuzhiyun if (!fast_tx)
3147*4882a593Smuzhiyun goto out;
3148*4882a593Smuzhiyun
3149*4882a593Smuzhiyun out:
3150*4882a593Smuzhiyun /* we might have raced against another call to this function */
3151*4882a593Smuzhiyun old = rcu_dereference_protected(sta->fast_tx,
3152*4882a593Smuzhiyun lockdep_is_held(&sta->lock));
3153*4882a593Smuzhiyun rcu_assign_pointer(sta->fast_tx, fast_tx);
3154*4882a593Smuzhiyun if (old)
3155*4882a593Smuzhiyun kfree_rcu(old, rcu_head);
3156*4882a593Smuzhiyun spin_unlock_bh(&sta->lock);
3157*4882a593Smuzhiyun }
3158*4882a593Smuzhiyun
ieee80211_check_fast_xmit_all(struct ieee80211_local * local)3159*4882a593Smuzhiyun void ieee80211_check_fast_xmit_all(struct ieee80211_local *local)
3160*4882a593Smuzhiyun {
3161*4882a593Smuzhiyun struct sta_info *sta;
3162*4882a593Smuzhiyun
3163*4882a593Smuzhiyun rcu_read_lock();
3164*4882a593Smuzhiyun list_for_each_entry_rcu(sta, &local->sta_list, list)
3165*4882a593Smuzhiyun ieee80211_check_fast_xmit(sta);
3166*4882a593Smuzhiyun rcu_read_unlock();
3167*4882a593Smuzhiyun }
3168*4882a593Smuzhiyun
ieee80211_check_fast_xmit_iface(struct ieee80211_sub_if_data * sdata)3169*4882a593Smuzhiyun void ieee80211_check_fast_xmit_iface(struct ieee80211_sub_if_data *sdata)
3170*4882a593Smuzhiyun {
3171*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
3172*4882a593Smuzhiyun struct sta_info *sta;
3173*4882a593Smuzhiyun
3174*4882a593Smuzhiyun rcu_read_lock();
3175*4882a593Smuzhiyun
3176*4882a593Smuzhiyun list_for_each_entry_rcu(sta, &local->sta_list, list) {
3177*4882a593Smuzhiyun if (sdata != sta->sdata &&
3178*4882a593Smuzhiyun (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
3179*4882a593Smuzhiyun continue;
3180*4882a593Smuzhiyun ieee80211_check_fast_xmit(sta);
3181*4882a593Smuzhiyun }
3182*4882a593Smuzhiyun
3183*4882a593Smuzhiyun rcu_read_unlock();
3184*4882a593Smuzhiyun }
3185*4882a593Smuzhiyun
ieee80211_clear_fast_xmit(struct sta_info * sta)3186*4882a593Smuzhiyun void ieee80211_clear_fast_xmit(struct sta_info *sta)
3187*4882a593Smuzhiyun {
3188*4882a593Smuzhiyun struct ieee80211_fast_tx *fast_tx;
3189*4882a593Smuzhiyun
3190*4882a593Smuzhiyun spin_lock_bh(&sta->lock);
3191*4882a593Smuzhiyun fast_tx = rcu_dereference_protected(sta->fast_tx,
3192*4882a593Smuzhiyun lockdep_is_held(&sta->lock));
3193*4882a593Smuzhiyun RCU_INIT_POINTER(sta->fast_tx, NULL);
3194*4882a593Smuzhiyun spin_unlock_bh(&sta->lock);
3195*4882a593Smuzhiyun
3196*4882a593Smuzhiyun if (fast_tx)
3197*4882a593Smuzhiyun kfree_rcu(fast_tx, rcu_head);
3198*4882a593Smuzhiyun }
3199*4882a593Smuzhiyun
ieee80211_amsdu_realloc_pad(struct ieee80211_local * local,struct sk_buff * skb,int headroom)3200*4882a593Smuzhiyun static bool ieee80211_amsdu_realloc_pad(struct ieee80211_local *local,
3201*4882a593Smuzhiyun struct sk_buff *skb, int headroom)
3202*4882a593Smuzhiyun {
3203*4882a593Smuzhiyun if (skb_headroom(skb) < headroom) {
3204*4882a593Smuzhiyun I802_DEBUG_INC(local->tx_expand_skb_head);
3205*4882a593Smuzhiyun
3206*4882a593Smuzhiyun if (pskb_expand_head(skb, headroom, 0, GFP_ATOMIC)) {
3207*4882a593Smuzhiyun wiphy_debug(local->hw.wiphy,
3208*4882a593Smuzhiyun "failed to reallocate TX buffer\n");
3209*4882a593Smuzhiyun return false;
3210*4882a593Smuzhiyun }
3211*4882a593Smuzhiyun }
3212*4882a593Smuzhiyun
3213*4882a593Smuzhiyun return true;
3214*4882a593Smuzhiyun }
3215*4882a593Smuzhiyun
ieee80211_amsdu_prepare_head(struct ieee80211_sub_if_data * sdata,struct ieee80211_fast_tx * fast_tx,struct sk_buff * skb)3216*4882a593Smuzhiyun static bool ieee80211_amsdu_prepare_head(struct ieee80211_sub_if_data *sdata,
3217*4882a593Smuzhiyun struct ieee80211_fast_tx *fast_tx,
3218*4882a593Smuzhiyun struct sk_buff *skb)
3219*4882a593Smuzhiyun {
3220*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
3221*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3222*4882a593Smuzhiyun struct ieee80211_hdr *hdr;
3223*4882a593Smuzhiyun struct ethhdr *amsdu_hdr;
3224*4882a593Smuzhiyun int hdr_len = fast_tx->hdr_len - sizeof(rfc1042_header);
3225*4882a593Smuzhiyun int subframe_len = skb->len - hdr_len;
3226*4882a593Smuzhiyun void *data;
3227*4882a593Smuzhiyun u8 *qc, *h_80211_src, *h_80211_dst;
3228*4882a593Smuzhiyun const u8 *bssid;
3229*4882a593Smuzhiyun
3230*4882a593Smuzhiyun if (info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE)
3231*4882a593Smuzhiyun return false;
3232*4882a593Smuzhiyun
3233*4882a593Smuzhiyun if (info->control.flags & IEEE80211_TX_CTRL_AMSDU)
3234*4882a593Smuzhiyun return true;
3235*4882a593Smuzhiyun
3236*4882a593Smuzhiyun if (!ieee80211_amsdu_realloc_pad(local, skb,
3237*4882a593Smuzhiyun sizeof(*amsdu_hdr) +
3238*4882a593Smuzhiyun local->hw.extra_tx_headroom))
3239*4882a593Smuzhiyun return false;
3240*4882a593Smuzhiyun
3241*4882a593Smuzhiyun data = skb_push(skb, sizeof(*amsdu_hdr));
3242*4882a593Smuzhiyun memmove(data, data + sizeof(*amsdu_hdr), hdr_len);
3243*4882a593Smuzhiyun hdr = data;
3244*4882a593Smuzhiyun amsdu_hdr = data + hdr_len;
3245*4882a593Smuzhiyun /* h_80211_src/dst is addr* field within hdr */
3246*4882a593Smuzhiyun h_80211_src = data + fast_tx->sa_offs;
3247*4882a593Smuzhiyun h_80211_dst = data + fast_tx->da_offs;
3248*4882a593Smuzhiyun
3249*4882a593Smuzhiyun amsdu_hdr->h_proto = cpu_to_be16(subframe_len);
3250*4882a593Smuzhiyun ether_addr_copy(amsdu_hdr->h_source, h_80211_src);
3251*4882a593Smuzhiyun ether_addr_copy(amsdu_hdr->h_dest, h_80211_dst);
3252*4882a593Smuzhiyun
3253*4882a593Smuzhiyun /* according to IEEE 802.11-2012 8.3.2 table 8-19, the outer SA/DA
3254*4882a593Smuzhiyun * fields needs to be changed to BSSID for A-MSDU frames depending
3255*4882a593Smuzhiyun * on FromDS/ToDS values.
3256*4882a593Smuzhiyun */
3257*4882a593Smuzhiyun switch (sdata->vif.type) {
3258*4882a593Smuzhiyun case NL80211_IFTYPE_STATION:
3259*4882a593Smuzhiyun bssid = sdata->u.mgd.bssid;
3260*4882a593Smuzhiyun break;
3261*4882a593Smuzhiyun case NL80211_IFTYPE_AP:
3262*4882a593Smuzhiyun case NL80211_IFTYPE_AP_VLAN:
3263*4882a593Smuzhiyun bssid = sdata->vif.addr;
3264*4882a593Smuzhiyun break;
3265*4882a593Smuzhiyun default:
3266*4882a593Smuzhiyun bssid = NULL;
3267*4882a593Smuzhiyun }
3268*4882a593Smuzhiyun
3269*4882a593Smuzhiyun if (bssid && ieee80211_has_fromds(hdr->frame_control))
3270*4882a593Smuzhiyun ether_addr_copy(h_80211_src, bssid);
3271*4882a593Smuzhiyun
3272*4882a593Smuzhiyun if (bssid && ieee80211_has_tods(hdr->frame_control))
3273*4882a593Smuzhiyun ether_addr_copy(h_80211_dst, bssid);
3274*4882a593Smuzhiyun
3275*4882a593Smuzhiyun qc = ieee80211_get_qos_ctl(hdr);
3276*4882a593Smuzhiyun *qc |= IEEE80211_QOS_CTL_A_MSDU_PRESENT;
3277*4882a593Smuzhiyun
3278*4882a593Smuzhiyun info->control.flags |= IEEE80211_TX_CTRL_AMSDU;
3279*4882a593Smuzhiyun
3280*4882a593Smuzhiyun return true;
3281*4882a593Smuzhiyun }
3282*4882a593Smuzhiyun
ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data * sdata,struct sta_info * sta,struct ieee80211_fast_tx * fast_tx,struct sk_buff * skb)3283*4882a593Smuzhiyun static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,
3284*4882a593Smuzhiyun struct sta_info *sta,
3285*4882a593Smuzhiyun struct ieee80211_fast_tx *fast_tx,
3286*4882a593Smuzhiyun struct sk_buff *skb)
3287*4882a593Smuzhiyun {
3288*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
3289*4882a593Smuzhiyun struct fq *fq = &local->fq;
3290*4882a593Smuzhiyun struct fq_tin *tin;
3291*4882a593Smuzhiyun struct fq_flow *flow;
3292*4882a593Smuzhiyun u8 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
3293*4882a593Smuzhiyun struct ieee80211_txq *txq = sta->sta.txq[tid];
3294*4882a593Smuzhiyun struct txq_info *txqi;
3295*4882a593Smuzhiyun struct sk_buff **frag_tail, *head;
3296*4882a593Smuzhiyun int subframe_len = skb->len - ETH_ALEN;
3297*4882a593Smuzhiyun u8 max_subframes = sta->sta.max_amsdu_subframes;
3298*4882a593Smuzhiyun int max_frags = local->hw.max_tx_fragments;
3299*4882a593Smuzhiyun int max_amsdu_len = sta->sta.max_amsdu_len;
3300*4882a593Smuzhiyun int orig_truesize;
3301*4882a593Smuzhiyun u32 flow_idx;
3302*4882a593Smuzhiyun __be16 len;
3303*4882a593Smuzhiyun void *data;
3304*4882a593Smuzhiyun bool ret = false;
3305*4882a593Smuzhiyun unsigned int orig_len;
3306*4882a593Smuzhiyun int n = 2, nfrags, pad = 0;
3307*4882a593Smuzhiyun u16 hdrlen;
3308*4882a593Smuzhiyun
3309*4882a593Smuzhiyun if (!ieee80211_hw_check(&local->hw, TX_AMSDU))
3310*4882a593Smuzhiyun return false;
3311*4882a593Smuzhiyun
3312*4882a593Smuzhiyun if (skb_is_gso(skb))
3313*4882a593Smuzhiyun return false;
3314*4882a593Smuzhiyun
3315*4882a593Smuzhiyun if (!txq)
3316*4882a593Smuzhiyun return false;
3317*4882a593Smuzhiyun
3318*4882a593Smuzhiyun txqi = to_txq_info(txq);
3319*4882a593Smuzhiyun if (test_bit(IEEE80211_TXQ_NO_AMSDU, &txqi->flags))
3320*4882a593Smuzhiyun return false;
3321*4882a593Smuzhiyun
3322*4882a593Smuzhiyun if (sta->sta.max_rc_amsdu_len)
3323*4882a593Smuzhiyun max_amsdu_len = min_t(int, max_amsdu_len,
3324*4882a593Smuzhiyun sta->sta.max_rc_amsdu_len);
3325*4882a593Smuzhiyun
3326*4882a593Smuzhiyun if (sta->sta.max_tid_amsdu_len[tid])
3327*4882a593Smuzhiyun max_amsdu_len = min_t(int, max_amsdu_len,
3328*4882a593Smuzhiyun sta->sta.max_tid_amsdu_len[tid]);
3329*4882a593Smuzhiyun
3330*4882a593Smuzhiyun flow_idx = fq_flow_idx(fq, skb);
3331*4882a593Smuzhiyun
3332*4882a593Smuzhiyun spin_lock_bh(&fq->lock);
3333*4882a593Smuzhiyun
3334*4882a593Smuzhiyun /* TODO: Ideally aggregation should be done on dequeue to remain
3335*4882a593Smuzhiyun * responsive to environment changes.
3336*4882a593Smuzhiyun */
3337*4882a593Smuzhiyun
3338*4882a593Smuzhiyun tin = &txqi->tin;
3339*4882a593Smuzhiyun flow = fq_flow_classify(fq, tin, flow_idx, skb,
3340*4882a593Smuzhiyun fq_flow_get_default_func);
3341*4882a593Smuzhiyun head = skb_peek_tail(&flow->queue);
3342*4882a593Smuzhiyun if (!head || skb_is_gso(head))
3343*4882a593Smuzhiyun goto out;
3344*4882a593Smuzhiyun
3345*4882a593Smuzhiyun orig_truesize = head->truesize;
3346*4882a593Smuzhiyun orig_len = head->len;
3347*4882a593Smuzhiyun
3348*4882a593Smuzhiyun if (skb->len + head->len > max_amsdu_len)
3349*4882a593Smuzhiyun goto out;
3350*4882a593Smuzhiyun
3351*4882a593Smuzhiyun nfrags = 1 + skb_shinfo(skb)->nr_frags;
3352*4882a593Smuzhiyun nfrags += 1 + skb_shinfo(head)->nr_frags;
3353*4882a593Smuzhiyun frag_tail = &skb_shinfo(head)->frag_list;
3354*4882a593Smuzhiyun while (*frag_tail) {
3355*4882a593Smuzhiyun nfrags += 1 + skb_shinfo(*frag_tail)->nr_frags;
3356*4882a593Smuzhiyun frag_tail = &(*frag_tail)->next;
3357*4882a593Smuzhiyun n++;
3358*4882a593Smuzhiyun }
3359*4882a593Smuzhiyun
3360*4882a593Smuzhiyun if (max_subframes && n > max_subframes)
3361*4882a593Smuzhiyun goto out;
3362*4882a593Smuzhiyun
3363*4882a593Smuzhiyun if (max_frags && nfrags > max_frags)
3364*4882a593Smuzhiyun goto out;
3365*4882a593Smuzhiyun
3366*4882a593Smuzhiyun if (!drv_can_aggregate_in_amsdu(local, head, skb))
3367*4882a593Smuzhiyun goto out;
3368*4882a593Smuzhiyun
3369*4882a593Smuzhiyun if (!ieee80211_amsdu_prepare_head(sdata, fast_tx, head))
3370*4882a593Smuzhiyun goto out;
3371*4882a593Smuzhiyun
3372*4882a593Smuzhiyun /* If n == 2, the "while (*frag_tail)" loop above didn't execute
3373*4882a593Smuzhiyun * and frag_tail should be &skb_shinfo(head)->frag_list.
3374*4882a593Smuzhiyun * However, ieee80211_amsdu_prepare_head() can reallocate it.
3375*4882a593Smuzhiyun * Reload frag_tail to have it pointing to the correct place.
3376*4882a593Smuzhiyun */
3377*4882a593Smuzhiyun if (n == 2)
3378*4882a593Smuzhiyun frag_tail = &skb_shinfo(head)->frag_list;
3379*4882a593Smuzhiyun
3380*4882a593Smuzhiyun /*
3381*4882a593Smuzhiyun * Pad out the previous subframe to a multiple of 4 by adding the
3382*4882a593Smuzhiyun * padding to the next one, that's being added. Note that head->len
3383*4882a593Smuzhiyun * is the length of the full A-MSDU, but that works since each time
3384*4882a593Smuzhiyun * we add a new subframe we pad out the previous one to a multiple
3385*4882a593Smuzhiyun * of 4 and thus it no longer matters in the next round.
3386*4882a593Smuzhiyun */
3387*4882a593Smuzhiyun hdrlen = fast_tx->hdr_len - sizeof(rfc1042_header);
3388*4882a593Smuzhiyun if ((head->len - hdrlen) & 3)
3389*4882a593Smuzhiyun pad = 4 - ((head->len - hdrlen) & 3);
3390*4882a593Smuzhiyun
3391*4882a593Smuzhiyun if (!ieee80211_amsdu_realloc_pad(local, skb, sizeof(rfc1042_header) +
3392*4882a593Smuzhiyun 2 + pad))
3393*4882a593Smuzhiyun goto out_recalc;
3394*4882a593Smuzhiyun
3395*4882a593Smuzhiyun ret = true;
3396*4882a593Smuzhiyun data = skb_push(skb, ETH_ALEN + 2);
3397*4882a593Smuzhiyun memmove(data, data + ETH_ALEN + 2, 2 * ETH_ALEN);
3398*4882a593Smuzhiyun
3399*4882a593Smuzhiyun data += 2 * ETH_ALEN;
3400*4882a593Smuzhiyun len = cpu_to_be16(subframe_len);
3401*4882a593Smuzhiyun memcpy(data, &len, 2);
3402*4882a593Smuzhiyun memcpy(data + 2, rfc1042_header, sizeof(rfc1042_header));
3403*4882a593Smuzhiyun
3404*4882a593Smuzhiyun memset(skb_push(skb, pad), 0, pad);
3405*4882a593Smuzhiyun
3406*4882a593Smuzhiyun head->len += skb->len;
3407*4882a593Smuzhiyun head->data_len += skb->len;
3408*4882a593Smuzhiyun *frag_tail = skb;
3409*4882a593Smuzhiyun
3410*4882a593Smuzhiyun out_recalc:
3411*4882a593Smuzhiyun fq->memory_usage += head->truesize - orig_truesize;
3412*4882a593Smuzhiyun if (head->len != orig_len) {
3413*4882a593Smuzhiyun flow->backlog += head->len - orig_len;
3414*4882a593Smuzhiyun tin->backlog_bytes += head->len - orig_len;
3415*4882a593Smuzhiyun
3416*4882a593Smuzhiyun fq_recalc_backlog(fq, tin, flow);
3417*4882a593Smuzhiyun }
3418*4882a593Smuzhiyun out:
3419*4882a593Smuzhiyun spin_unlock_bh(&fq->lock);
3420*4882a593Smuzhiyun
3421*4882a593Smuzhiyun return ret;
3422*4882a593Smuzhiyun }
3423*4882a593Smuzhiyun
3424*4882a593Smuzhiyun /*
3425*4882a593Smuzhiyun * Can be called while the sta lock is held. Anything that can cause packets to
3426*4882a593Smuzhiyun * be generated will cause deadlock!
3427*4882a593Smuzhiyun */
ieee80211_xmit_fast_finish(struct ieee80211_sub_if_data * sdata,struct sta_info * sta,u8 pn_offs,struct ieee80211_key * key,struct sk_buff * skb)3428*4882a593Smuzhiyun static void ieee80211_xmit_fast_finish(struct ieee80211_sub_if_data *sdata,
3429*4882a593Smuzhiyun struct sta_info *sta, u8 pn_offs,
3430*4882a593Smuzhiyun struct ieee80211_key *key,
3431*4882a593Smuzhiyun struct sk_buff *skb)
3432*4882a593Smuzhiyun {
3433*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3434*4882a593Smuzhiyun struct ieee80211_hdr *hdr = (void *)skb->data;
3435*4882a593Smuzhiyun u8 tid = IEEE80211_NUM_TIDS;
3436*4882a593Smuzhiyun
3437*4882a593Smuzhiyun if (key)
3438*4882a593Smuzhiyun info->control.hw_key = &key->conf;
3439*4882a593Smuzhiyun
3440*4882a593Smuzhiyun ieee80211_tx_stats(skb->dev, skb->len);
3441*4882a593Smuzhiyun
3442*4882a593Smuzhiyun if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
3443*4882a593Smuzhiyun tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
3444*4882a593Smuzhiyun hdr->seq_ctrl = ieee80211_tx_next_seq(sta, tid);
3445*4882a593Smuzhiyun } else {
3446*4882a593Smuzhiyun info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
3447*4882a593Smuzhiyun hdr->seq_ctrl = cpu_to_le16(sdata->sequence_number);
3448*4882a593Smuzhiyun sdata->sequence_number += 0x10;
3449*4882a593Smuzhiyun }
3450*4882a593Smuzhiyun
3451*4882a593Smuzhiyun if (skb_shinfo(skb)->gso_size)
3452*4882a593Smuzhiyun sta->tx_stats.msdu[tid] +=
3453*4882a593Smuzhiyun DIV_ROUND_UP(skb->len, skb_shinfo(skb)->gso_size);
3454*4882a593Smuzhiyun else
3455*4882a593Smuzhiyun sta->tx_stats.msdu[tid]++;
3456*4882a593Smuzhiyun
3457*4882a593Smuzhiyun info->hw_queue = sdata->vif.hw_queue[skb_get_queue_mapping(skb)];
3458*4882a593Smuzhiyun
3459*4882a593Smuzhiyun /* statistics normally done by ieee80211_tx_h_stats (but that
3460*4882a593Smuzhiyun * has to consider fragmentation, so is more complex)
3461*4882a593Smuzhiyun */
3462*4882a593Smuzhiyun sta->tx_stats.bytes[skb_get_queue_mapping(skb)] += skb->len;
3463*4882a593Smuzhiyun sta->tx_stats.packets[skb_get_queue_mapping(skb)]++;
3464*4882a593Smuzhiyun
3465*4882a593Smuzhiyun if (pn_offs) {
3466*4882a593Smuzhiyun u64 pn;
3467*4882a593Smuzhiyun u8 *crypto_hdr = skb->data + pn_offs;
3468*4882a593Smuzhiyun
3469*4882a593Smuzhiyun switch (key->conf.cipher) {
3470*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_CCMP:
3471*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_CCMP_256:
3472*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_GCMP:
3473*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_GCMP_256:
3474*4882a593Smuzhiyun pn = atomic64_inc_return(&key->conf.tx_pn);
3475*4882a593Smuzhiyun crypto_hdr[0] = pn;
3476*4882a593Smuzhiyun crypto_hdr[1] = pn >> 8;
3477*4882a593Smuzhiyun crypto_hdr[3] = 0x20 | (key->conf.keyidx << 6);
3478*4882a593Smuzhiyun crypto_hdr[4] = pn >> 16;
3479*4882a593Smuzhiyun crypto_hdr[5] = pn >> 24;
3480*4882a593Smuzhiyun crypto_hdr[6] = pn >> 32;
3481*4882a593Smuzhiyun crypto_hdr[7] = pn >> 40;
3482*4882a593Smuzhiyun break;
3483*4882a593Smuzhiyun }
3484*4882a593Smuzhiyun }
3485*4882a593Smuzhiyun }
3486*4882a593Smuzhiyun
ieee80211_xmit_fast(struct ieee80211_sub_if_data * sdata,struct sta_info * sta,struct ieee80211_fast_tx * fast_tx,struct sk_buff * skb)3487*4882a593Smuzhiyun static bool ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
3488*4882a593Smuzhiyun struct sta_info *sta,
3489*4882a593Smuzhiyun struct ieee80211_fast_tx *fast_tx,
3490*4882a593Smuzhiyun struct sk_buff *skb)
3491*4882a593Smuzhiyun {
3492*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
3493*4882a593Smuzhiyun u16 ethertype = (skb->data[12] << 8) | skb->data[13];
3494*4882a593Smuzhiyun int extra_head = fast_tx->hdr_len - (ETH_HLEN - 2);
3495*4882a593Smuzhiyun int hw_headroom = sdata->local->hw.extra_tx_headroom;
3496*4882a593Smuzhiyun struct ethhdr eth;
3497*4882a593Smuzhiyun struct ieee80211_tx_info *info;
3498*4882a593Smuzhiyun struct ieee80211_hdr *hdr = (void *)fast_tx->hdr;
3499*4882a593Smuzhiyun struct ieee80211_tx_data tx;
3500*4882a593Smuzhiyun ieee80211_tx_result r;
3501*4882a593Smuzhiyun struct tid_ampdu_tx *tid_tx = NULL;
3502*4882a593Smuzhiyun u8 tid = IEEE80211_NUM_TIDS;
3503*4882a593Smuzhiyun
3504*4882a593Smuzhiyun /* control port protocol needs a lot of special handling */
3505*4882a593Smuzhiyun if (cpu_to_be16(ethertype) == sdata->control_port_protocol)
3506*4882a593Smuzhiyun return false;
3507*4882a593Smuzhiyun
3508*4882a593Smuzhiyun /* only RFC 1042 SNAP */
3509*4882a593Smuzhiyun if (ethertype < ETH_P_802_3_MIN)
3510*4882a593Smuzhiyun return false;
3511*4882a593Smuzhiyun
3512*4882a593Smuzhiyun /* don't handle TX status request here either */
3513*4882a593Smuzhiyun if (skb->sk && skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS)
3514*4882a593Smuzhiyun return false;
3515*4882a593Smuzhiyun
3516*4882a593Smuzhiyun if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
3517*4882a593Smuzhiyun tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
3518*4882a593Smuzhiyun tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
3519*4882a593Smuzhiyun if (tid_tx) {
3520*4882a593Smuzhiyun if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state))
3521*4882a593Smuzhiyun return false;
3522*4882a593Smuzhiyun if (tid_tx->timeout)
3523*4882a593Smuzhiyun tid_tx->last_tx = jiffies;
3524*4882a593Smuzhiyun }
3525*4882a593Smuzhiyun }
3526*4882a593Smuzhiyun
3527*4882a593Smuzhiyun /* after this point (skb is modified) we cannot return false */
3528*4882a593Smuzhiyun
3529*4882a593Smuzhiyun if (skb_shared(skb)) {
3530*4882a593Smuzhiyun struct sk_buff *tmp_skb = skb;
3531*4882a593Smuzhiyun
3532*4882a593Smuzhiyun skb = skb_clone(skb, GFP_ATOMIC);
3533*4882a593Smuzhiyun kfree_skb(tmp_skb);
3534*4882a593Smuzhiyun
3535*4882a593Smuzhiyun if (!skb)
3536*4882a593Smuzhiyun return true;
3537*4882a593Smuzhiyun }
3538*4882a593Smuzhiyun
3539*4882a593Smuzhiyun if ((hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) &&
3540*4882a593Smuzhiyun ieee80211_amsdu_aggregate(sdata, sta, fast_tx, skb))
3541*4882a593Smuzhiyun return true;
3542*4882a593Smuzhiyun
3543*4882a593Smuzhiyun /* will not be crypto-handled beyond what we do here, so use false
3544*4882a593Smuzhiyun * as the may-encrypt argument for the resize to not account for
3545*4882a593Smuzhiyun * more room than we already have in 'extra_head'
3546*4882a593Smuzhiyun */
3547*4882a593Smuzhiyun if (unlikely(ieee80211_skb_resize(sdata, skb,
3548*4882a593Smuzhiyun max_t(int, extra_head + hw_headroom -
3549*4882a593Smuzhiyun skb_headroom(skb), 0),
3550*4882a593Smuzhiyun ENCRYPT_NO))) {
3551*4882a593Smuzhiyun kfree_skb(skb);
3552*4882a593Smuzhiyun return true;
3553*4882a593Smuzhiyun }
3554*4882a593Smuzhiyun
3555*4882a593Smuzhiyun memcpy(ð, skb->data, ETH_HLEN - 2);
3556*4882a593Smuzhiyun hdr = skb_push(skb, extra_head);
3557*4882a593Smuzhiyun memcpy(skb->data, fast_tx->hdr, fast_tx->hdr_len);
3558*4882a593Smuzhiyun memcpy(skb->data + fast_tx->da_offs, eth.h_dest, ETH_ALEN);
3559*4882a593Smuzhiyun memcpy(skb->data + fast_tx->sa_offs, eth.h_source, ETH_ALEN);
3560*4882a593Smuzhiyun
3561*4882a593Smuzhiyun info = IEEE80211_SKB_CB(skb);
3562*4882a593Smuzhiyun memset(info, 0, sizeof(*info));
3563*4882a593Smuzhiyun info->band = fast_tx->band;
3564*4882a593Smuzhiyun info->control.vif = &sdata->vif;
3565*4882a593Smuzhiyun info->flags = IEEE80211_TX_CTL_FIRST_FRAGMENT |
3566*4882a593Smuzhiyun IEEE80211_TX_CTL_DONTFRAG |
3567*4882a593Smuzhiyun (tid_tx ? IEEE80211_TX_CTL_AMPDU : 0);
3568*4882a593Smuzhiyun info->control.flags = IEEE80211_TX_CTRL_FAST_XMIT;
3569*4882a593Smuzhiyun
3570*4882a593Smuzhiyun #ifdef CONFIG_MAC80211_DEBUGFS
3571*4882a593Smuzhiyun if (local->force_tx_status)
3572*4882a593Smuzhiyun info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
3573*4882a593Smuzhiyun #endif
3574*4882a593Smuzhiyun
3575*4882a593Smuzhiyun if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
3576*4882a593Smuzhiyun tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
3577*4882a593Smuzhiyun *ieee80211_get_qos_ctl(hdr) = tid;
3578*4882a593Smuzhiyun }
3579*4882a593Smuzhiyun
3580*4882a593Smuzhiyun __skb_queue_head_init(&tx.skbs);
3581*4882a593Smuzhiyun
3582*4882a593Smuzhiyun tx.flags = IEEE80211_TX_UNICAST;
3583*4882a593Smuzhiyun tx.local = local;
3584*4882a593Smuzhiyun tx.sdata = sdata;
3585*4882a593Smuzhiyun tx.sta = sta;
3586*4882a593Smuzhiyun tx.key = fast_tx->key;
3587*4882a593Smuzhiyun
3588*4882a593Smuzhiyun if (!ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
3589*4882a593Smuzhiyun tx.skb = skb;
3590*4882a593Smuzhiyun r = ieee80211_tx_h_rate_ctrl(&tx);
3591*4882a593Smuzhiyun skb = tx.skb;
3592*4882a593Smuzhiyun tx.skb = NULL;
3593*4882a593Smuzhiyun
3594*4882a593Smuzhiyun if (r != TX_CONTINUE) {
3595*4882a593Smuzhiyun if (r != TX_QUEUED)
3596*4882a593Smuzhiyun kfree_skb(skb);
3597*4882a593Smuzhiyun return true;
3598*4882a593Smuzhiyun }
3599*4882a593Smuzhiyun }
3600*4882a593Smuzhiyun
3601*4882a593Smuzhiyun if (ieee80211_queue_skb(local, sdata, sta, skb))
3602*4882a593Smuzhiyun return true;
3603*4882a593Smuzhiyun
3604*4882a593Smuzhiyun ieee80211_xmit_fast_finish(sdata, sta, fast_tx->pn_offs,
3605*4882a593Smuzhiyun fast_tx->key, skb);
3606*4882a593Smuzhiyun
3607*4882a593Smuzhiyun if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
3608*4882a593Smuzhiyun sdata = container_of(sdata->bss,
3609*4882a593Smuzhiyun struct ieee80211_sub_if_data, u.ap);
3610*4882a593Smuzhiyun
3611*4882a593Smuzhiyun __skb_queue_tail(&tx.skbs, skb);
3612*4882a593Smuzhiyun ieee80211_tx_frags(local, &sdata->vif, sta, &tx.skbs, false);
3613*4882a593Smuzhiyun return true;
3614*4882a593Smuzhiyun }
3615*4882a593Smuzhiyun
ieee80211_tx_dequeue(struct ieee80211_hw * hw,struct ieee80211_txq * txq)3616*4882a593Smuzhiyun struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,
3617*4882a593Smuzhiyun struct ieee80211_txq *txq)
3618*4882a593Smuzhiyun {
3619*4882a593Smuzhiyun struct ieee80211_local *local = hw_to_local(hw);
3620*4882a593Smuzhiyun struct txq_info *txqi = container_of(txq, struct txq_info, txq);
3621*4882a593Smuzhiyun struct ieee80211_hdr *hdr;
3622*4882a593Smuzhiyun struct sk_buff *skb = NULL;
3623*4882a593Smuzhiyun struct fq *fq = &local->fq;
3624*4882a593Smuzhiyun struct fq_tin *tin = &txqi->tin;
3625*4882a593Smuzhiyun struct ieee80211_tx_info *info;
3626*4882a593Smuzhiyun struct ieee80211_tx_data tx;
3627*4882a593Smuzhiyun ieee80211_tx_result r;
3628*4882a593Smuzhiyun struct ieee80211_vif *vif = txq->vif;
3629*4882a593Smuzhiyun
3630*4882a593Smuzhiyun WARN_ON_ONCE(softirq_count() == 0);
3631*4882a593Smuzhiyun
3632*4882a593Smuzhiyun if (!ieee80211_txq_airtime_check(hw, txq))
3633*4882a593Smuzhiyun return NULL;
3634*4882a593Smuzhiyun
3635*4882a593Smuzhiyun begin:
3636*4882a593Smuzhiyun spin_lock_bh(&fq->lock);
3637*4882a593Smuzhiyun
3638*4882a593Smuzhiyun if (test_bit(IEEE80211_TXQ_STOP, &txqi->flags) ||
3639*4882a593Smuzhiyun test_bit(IEEE80211_TXQ_STOP_NETIF_TX, &txqi->flags))
3640*4882a593Smuzhiyun goto out;
3641*4882a593Smuzhiyun
3642*4882a593Smuzhiyun if (vif->txqs_stopped[txq->ac]) {
3643*4882a593Smuzhiyun set_bit(IEEE80211_TXQ_STOP_NETIF_TX, &txqi->flags);
3644*4882a593Smuzhiyun goto out;
3645*4882a593Smuzhiyun }
3646*4882a593Smuzhiyun
3647*4882a593Smuzhiyun /* Make sure fragments stay together. */
3648*4882a593Smuzhiyun skb = __skb_dequeue(&txqi->frags);
3649*4882a593Smuzhiyun if (skb)
3650*4882a593Smuzhiyun goto out;
3651*4882a593Smuzhiyun
3652*4882a593Smuzhiyun skb = fq_tin_dequeue(fq, tin, fq_tin_dequeue_func);
3653*4882a593Smuzhiyun if (!skb)
3654*4882a593Smuzhiyun goto out;
3655*4882a593Smuzhiyun
3656*4882a593Smuzhiyun spin_unlock_bh(&fq->lock);
3657*4882a593Smuzhiyun
3658*4882a593Smuzhiyun hdr = (struct ieee80211_hdr *)skb->data;
3659*4882a593Smuzhiyun info = IEEE80211_SKB_CB(skb);
3660*4882a593Smuzhiyun
3661*4882a593Smuzhiyun memset(&tx, 0, sizeof(tx));
3662*4882a593Smuzhiyun __skb_queue_head_init(&tx.skbs);
3663*4882a593Smuzhiyun tx.local = local;
3664*4882a593Smuzhiyun tx.skb = skb;
3665*4882a593Smuzhiyun tx.sdata = vif_to_sdata(info->control.vif);
3666*4882a593Smuzhiyun
3667*4882a593Smuzhiyun if (txq->sta) {
3668*4882a593Smuzhiyun tx.sta = container_of(txq->sta, struct sta_info, sta);
3669*4882a593Smuzhiyun /*
3670*4882a593Smuzhiyun * Drop unicast frames to unauthorised stations unless they are
3671*4882a593Smuzhiyun * injected frames or EAPOL frames from the local station.
3672*4882a593Smuzhiyun */
3673*4882a593Smuzhiyun if (unlikely(!(info->flags & IEEE80211_TX_CTL_INJECTED) &&
3674*4882a593Smuzhiyun ieee80211_is_data(hdr->frame_control) &&
3675*4882a593Smuzhiyun !ieee80211_vif_is_mesh(&tx.sdata->vif) &&
3676*4882a593Smuzhiyun tx.sdata->vif.type != NL80211_IFTYPE_OCB &&
3677*4882a593Smuzhiyun !is_multicast_ether_addr(hdr->addr1) &&
3678*4882a593Smuzhiyun !test_sta_flag(tx.sta, WLAN_STA_AUTHORIZED) &&
3679*4882a593Smuzhiyun (!(info->control.flags &
3680*4882a593Smuzhiyun IEEE80211_TX_CTRL_PORT_CTRL_PROTO) ||
3681*4882a593Smuzhiyun !ether_addr_equal(tx.sdata->vif.addr,
3682*4882a593Smuzhiyun hdr->addr2)))) {
3683*4882a593Smuzhiyun I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
3684*4882a593Smuzhiyun ieee80211_free_txskb(&local->hw, skb);
3685*4882a593Smuzhiyun goto begin;
3686*4882a593Smuzhiyun }
3687*4882a593Smuzhiyun }
3688*4882a593Smuzhiyun
3689*4882a593Smuzhiyun /*
3690*4882a593Smuzhiyun * The key can be removed while the packet was queued, so need to call
3691*4882a593Smuzhiyun * this here to get the current key.
3692*4882a593Smuzhiyun */
3693*4882a593Smuzhiyun r = ieee80211_tx_h_select_key(&tx);
3694*4882a593Smuzhiyun if (r != TX_CONTINUE) {
3695*4882a593Smuzhiyun ieee80211_free_txskb(&local->hw, skb);
3696*4882a593Smuzhiyun goto begin;
3697*4882a593Smuzhiyun }
3698*4882a593Smuzhiyun
3699*4882a593Smuzhiyun if (test_bit(IEEE80211_TXQ_AMPDU, &txqi->flags))
3700*4882a593Smuzhiyun info->flags |= IEEE80211_TX_CTL_AMPDU;
3701*4882a593Smuzhiyun else
3702*4882a593Smuzhiyun info->flags &= ~IEEE80211_TX_CTL_AMPDU;
3703*4882a593Smuzhiyun
3704*4882a593Smuzhiyun if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP)
3705*4882a593Smuzhiyun goto encap_out;
3706*4882a593Smuzhiyun
3707*4882a593Smuzhiyun if (info->control.flags & IEEE80211_TX_CTRL_FAST_XMIT) {
3708*4882a593Smuzhiyun struct sta_info *sta = container_of(txq->sta, struct sta_info,
3709*4882a593Smuzhiyun sta);
3710*4882a593Smuzhiyun u8 pn_offs = 0;
3711*4882a593Smuzhiyun
3712*4882a593Smuzhiyun if (tx.key &&
3713*4882a593Smuzhiyun (tx.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
3714*4882a593Smuzhiyun pn_offs = ieee80211_hdrlen(hdr->frame_control);
3715*4882a593Smuzhiyun
3716*4882a593Smuzhiyun ieee80211_xmit_fast_finish(sta->sdata, sta, pn_offs,
3717*4882a593Smuzhiyun tx.key, skb);
3718*4882a593Smuzhiyun } else {
3719*4882a593Smuzhiyun if (invoke_tx_handlers_late(&tx))
3720*4882a593Smuzhiyun goto begin;
3721*4882a593Smuzhiyun
3722*4882a593Smuzhiyun skb = __skb_dequeue(&tx.skbs);
3723*4882a593Smuzhiyun
3724*4882a593Smuzhiyun if (!skb_queue_empty(&tx.skbs)) {
3725*4882a593Smuzhiyun spin_lock_bh(&fq->lock);
3726*4882a593Smuzhiyun skb_queue_splice_tail(&tx.skbs, &txqi->frags);
3727*4882a593Smuzhiyun spin_unlock_bh(&fq->lock);
3728*4882a593Smuzhiyun }
3729*4882a593Smuzhiyun }
3730*4882a593Smuzhiyun
3731*4882a593Smuzhiyun if (skb_has_frag_list(skb) &&
3732*4882a593Smuzhiyun !ieee80211_hw_check(&local->hw, TX_FRAG_LIST)) {
3733*4882a593Smuzhiyun if (skb_linearize(skb)) {
3734*4882a593Smuzhiyun ieee80211_free_txskb(&local->hw, skb);
3735*4882a593Smuzhiyun goto begin;
3736*4882a593Smuzhiyun }
3737*4882a593Smuzhiyun }
3738*4882a593Smuzhiyun
3739*4882a593Smuzhiyun switch (tx.sdata->vif.type) {
3740*4882a593Smuzhiyun case NL80211_IFTYPE_MONITOR:
3741*4882a593Smuzhiyun if (tx.sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) {
3742*4882a593Smuzhiyun vif = &tx.sdata->vif;
3743*4882a593Smuzhiyun break;
3744*4882a593Smuzhiyun }
3745*4882a593Smuzhiyun tx.sdata = rcu_dereference(local->monitor_sdata);
3746*4882a593Smuzhiyun if (tx.sdata) {
3747*4882a593Smuzhiyun vif = &tx.sdata->vif;
3748*4882a593Smuzhiyun info->hw_queue =
3749*4882a593Smuzhiyun vif->hw_queue[skb_get_queue_mapping(skb)];
3750*4882a593Smuzhiyun } else if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) {
3751*4882a593Smuzhiyun ieee80211_free_txskb(&local->hw, skb);
3752*4882a593Smuzhiyun goto begin;
3753*4882a593Smuzhiyun } else {
3754*4882a593Smuzhiyun vif = NULL;
3755*4882a593Smuzhiyun }
3756*4882a593Smuzhiyun break;
3757*4882a593Smuzhiyun case NL80211_IFTYPE_AP_VLAN:
3758*4882a593Smuzhiyun tx.sdata = container_of(tx.sdata->bss,
3759*4882a593Smuzhiyun struct ieee80211_sub_if_data, u.ap);
3760*4882a593Smuzhiyun fallthrough;
3761*4882a593Smuzhiyun default:
3762*4882a593Smuzhiyun vif = &tx.sdata->vif;
3763*4882a593Smuzhiyun break;
3764*4882a593Smuzhiyun }
3765*4882a593Smuzhiyun
3766*4882a593Smuzhiyun encap_out:
3767*4882a593Smuzhiyun IEEE80211_SKB_CB(skb)->control.vif = vif;
3768*4882a593Smuzhiyun
3769*4882a593Smuzhiyun if (vif &&
3770*4882a593Smuzhiyun wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL)) {
3771*4882a593Smuzhiyun bool ampdu = txq->ac != IEEE80211_AC_VO;
3772*4882a593Smuzhiyun u32 airtime;
3773*4882a593Smuzhiyun
3774*4882a593Smuzhiyun airtime = ieee80211_calc_expected_tx_airtime(hw, vif, txq->sta,
3775*4882a593Smuzhiyun skb->len, ampdu);
3776*4882a593Smuzhiyun if (airtime) {
3777*4882a593Smuzhiyun airtime = ieee80211_info_set_tx_time_est(info, airtime);
3778*4882a593Smuzhiyun ieee80211_sta_update_pending_airtime(local, tx.sta,
3779*4882a593Smuzhiyun txq->ac,
3780*4882a593Smuzhiyun airtime,
3781*4882a593Smuzhiyun false);
3782*4882a593Smuzhiyun }
3783*4882a593Smuzhiyun }
3784*4882a593Smuzhiyun
3785*4882a593Smuzhiyun return skb;
3786*4882a593Smuzhiyun
3787*4882a593Smuzhiyun out:
3788*4882a593Smuzhiyun spin_unlock_bh(&fq->lock);
3789*4882a593Smuzhiyun
3790*4882a593Smuzhiyun return skb;
3791*4882a593Smuzhiyun }
3792*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_tx_dequeue);
3793*4882a593Smuzhiyun
ieee80211_next_txq(struct ieee80211_hw * hw,u8 ac)3794*4882a593Smuzhiyun struct ieee80211_txq *ieee80211_next_txq(struct ieee80211_hw *hw, u8 ac)
3795*4882a593Smuzhiyun {
3796*4882a593Smuzhiyun struct ieee80211_local *local = hw_to_local(hw);
3797*4882a593Smuzhiyun struct ieee80211_txq *ret = NULL;
3798*4882a593Smuzhiyun struct txq_info *txqi = NULL, *head = NULL;
3799*4882a593Smuzhiyun bool found_eligible_txq = false;
3800*4882a593Smuzhiyun
3801*4882a593Smuzhiyun spin_lock_bh(&local->active_txq_lock[ac]);
3802*4882a593Smuzhiyun
3803*4882a593Smuzhiyun begin:
3804*4882a593Smuzhiyun txqi = list_first_entry_or_null(&local->active_txqs[ac],
3805*4882a593Smuzhiyun struct txq_info,
3806*4882a593Smuzhiyun schedule_order);
3807*4882a593Smuzhiyun if (!txqi)
3808*4882a593Smuzhiyun goto out;
3809*4882a593Smuzhiyun
3810*4882a593Smuzhiyun if (txqi == head) {
3811*4882a593Smuzhiyun if (!found_eligible_txq)
3812*4882a593Smuzhiyun goto out;
3813*4882a593Smuzhiyun else
3814*4882a593Smuzhiyun found_eligible_txq = false;
3815*4882a593Smuzhiyun }
3816*4882a593Smuzhiyun
3817*4882a593Smuzhiyun if (!head)
3818*4882a593Smuzhiyun head = txqi;
3819*4882a593Smuzhiyun
3820*4882a593Smuzhiyun if (txqi->txq.sta) {
3821*4882a593Smuzhiyun struct sta_info *sta = container_of(txqi->txq.sta,
3822*4882a593Smuzhiyun struct sta_info, sta);
3823*4882a593Smuzhiyun bool aql_check = ieee80211_txq_airtime_check(hw, &txqi->txq);
3824*4882a593Smuzhiyun s64 deficit = sta->airtime[txqi->txq.ac].deficit;
3825*4882a593Smuzhiyun
3826*4882a593Smuzhiyun if (aql_check)
3827*4882a593Smuzhiyun found_eligible_txq = true;
3828*4882a593Smuzhiyun
3829*4882a593Smuzhiyun if (deficit < 0)
3830*4882a593Smuzhiyun sta->airtime[txqi->txq.ac].deficit +=
3831*4882a593Smuzhiyun sta->airtime_weight;
3832*4882a593Smuzhiyun
3833*4882a593Smuzhiyun if (deficit < 0 || !aql_check) {
3834*4882a593Smuzhiyun list_move_tail(&txqi->schedule_order,
3835*4882a593Smuzhiyun &local->active_txqs[txqi->txq.ac]);
3836*4882a593Smuzhiyun goto begin;
3837*4882a593Smuzhiyun }
3838*4882a593Smuzhiyun }
3839*4882a593Smuzhiyun
3840*4882a593Smuzhiyun
3841*4882a593Smuzhiyun if (txqi->schedule_round == local->schedule_round[ac])
3842*4882a593Smuzhiyun goto out;
3843*4882a593Smuzhiyun
3844*4882a593Smuzhiyun list_del_init(&txqi->schedule_order);
3845*4882a593Smuzhiyun txqi->schedule_round = local->schedule_round[ac];
3846*4882a593Smuzhiyun ret = &txqi->txq;
3847*4882a593Smuzhiyun
3848*4882a593Smuzhiyun out:
3849*4882a593Smuzhiyun spin_unlock_bh(&local->active_txq_lock[ac]);
3850*4882a593Smuzhiyun return ret;
3851*4882a593Smuzhiyun }
3852*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_next_txq);
3853*4882a593Smuzhiyun
__ieee80211_schedule_txq(struct ieee80211_hw * hw,struct ieee80211_txq * txq,bool force)3854*4882a593Smuzhiyun void __ieee80211_schedule_txq(struct ieee80211_hw *hw,
3855*4882a593Smuzhiyun struct ieee80211_txq *txq,
3856*4882a593Smuzhiyun bool force)
3857*4882a593Smuzhiyun {
3858*4882a593Smuzhiyun struct ieee80211_local *local = hw_to_local(hw);
3859*4882a593Smuzhiyun struct txq_info *txqi = to_txq_info(txq);
3860*4882a593Smuzhiyun
3861*4882a593Smuzhiyun spin_lock_bh(&local->active_txq_lock[txq->ac]);
3862*4882a593Smuzhiyun
3863*4882a593Smuzhiyun if (list_empty(&txqi->schedule_order) &&
3864*4882a593Smuzhiyun (force || !skb_queue_empty(&txqi->frags) ||
3865*4882a593Smuzhiyun txqi->tin.backlog_packets)) {
3866*4882a593Smuzhiyun /* If airtime accounting is active, always enqueue STAs at the
3867*4882a593Smuzhiyun * head of the list to ensure that they only get moved to the
3868*4882a593Smuzhiyun * back by the airtime DRR scheduler once they have a negative
3869*4882a593Smuzhiyun * deficit. A station that already has a negative deficit will
3870*4882a593Smuzhiyun * get immediately moved to the back of the list on the next
3871*4882a593Smuzhiyun * call to ieee80211_next_txq().
3872*4882a593Smuzhiyun */
3873*4882a593Smuzhiyun if (txqi->txq.sta && local->airtime_flags &&
3874*4882a593Smuzhiyun wiphy_ext_feature_isset(local->hw.wiphy,
3875*4882a593Smuzhiyun NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
3876*4882a593Smuzhiyun list_add(&txqi->schedule_order,
3877*4882a593Smuzhiyun &local->active_txqs[txq->ac]);
3878*4882a593Smuzhiyun else
3879*4882a593Smuzhiyun list_add_tail(&txqi->schedule_order,
3880*4882a593Smuzhiyun &local->active_txqs[txq->ac]);
3881*4882a593Smuzhiyun }
3882*4882a593Smuzhiyun
3883*4882a593Smuzhiyun spin_unlock_bh(&local->active_txq_lock[txq->ac]);
3884*4882a593Smuzhiyun }
3885*4882a593Smuzhiyun EXPORT_SYMBOL(__ieee80211_schedule_txq);
3886*4882a593Smuzhiyun
ieee80211_txq_airtime_check(struct ieee80211_hw * hw,struct ieee80211_txq * txq)3887*4882a593Smuzhiyun bool ieee80211_txq_airtime_check(struct ieee80211_hw *hw,
3888*4882a593Smuzhiyun struct ieee80211_txq *txq)
3889*4882a593Smuzhiyun {
3890*4882a593Smuzhiyun struct sta_info *sta;
3891*4882a593Smuzhiyun struct ieee80211_local *local = hw_to_local(hw);
3892*4882a593Smuzhiyun
3893*4882a593Smuzhiyun if (!wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL))
3894*4882a593Smuzhiyun return true;
3895*4882a593Smuzhiyun
3896*4882a593Smuzhiyun if (!txq->sta)
3897*4882a593Smuzhiyun return true;
3898*4882a593Smuzhiyun
3899*4882a593Smuzhiyun sta = container_of(txq->sta, struct sta_info, sta);
3900*4882a593Smuzhiyun if (atomic_read(&sta->airtime[txq->ac].aql_tx_pending) <
3901*4882a593Smuzhiyun sta->airtime[txq->ac].aql_limit_low)
3902*4882a593Smuzhiyun return true;
3903*4882a593Smuzhiyun
3904*4882a593Smuzhiyun if (atomic_read(&local->aql_total_pending_airtime) <
3905*4882a593Smuzhiyun local->aql_threshold &&
3906*4882a593Smuzhiyun atomic_read(&sta->airtime[txq->ac].aql_tx_pending) <
3907*4882a593Smuzhiyun sta->airtime[txq->ac].aql_limit_high)
3908*4882a593Smuzhiyun return true;
3909*4882a593Smuzhiyun
3910*4882a593Smuzhiyun return false;
3911*4882a593Smuzhiyun }
3912*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_txq_airtime_check);
3913*4882a593Smuzhiyun
ieee80211_txq_may_transmit(struct ieee80211_hw * hw,struct ieee80211_txq * txq)3914*4882a593Smuzhiyun bool ieee80211_txq_may_transmit(struct ieee80211_hw *hw,
3915*4882a593Smuzhiyun struct ieee80211_txq *txq)
3916*4882a593Smuzhiyun {
3917*4882a593Smuzhiyun struct ieee80211_local *local = hw_to_local(hw);
3918*4882a593Smuzhiyun struct txq_info *iter, *tmp, *txqi = to_txq_info(txq);
3919*4882a593Smuzhiyun struct sta_info *sta;
3920*4882a593Smuzhiyun u8 ac = txq->ac;
3921*4882a593Smuzhiyun
3922*4882a593Smuzhiyun spin_lock_bh(&local->active_txq_lock[ac]);
3923*4882a593Smuzhiyun
3924*4882a593Smuzhiyun if (!txqi->txq.sta)
3925*4882a593Smuzhiyun goto out;
3926*4882a593Smuzhiyun
3927*4882a593Smuzhiyun if (list_empty(&txqi->schedule_order))
3928*4882a593Smuzhiyun goto out;
3929*4882a593Smuzhiyun
3930*4882a593Smuzhiyun list_for_each_entry_safe(iter, tmp, &local->active_txqs[ac],
3931*4882a593Smuzhiyun schedule_order) {
3932*4882a593Smuzhiyun if (iter == txqi)
3933*4882a593Smuzhiyun break;
3934*4882a593Smuzhiyun
3935*4882a593Smuzhiyun if (!iter->txq.sta) {
3936*4882a593Smuzhiyun list_move_tail(&iter->schedule_order,
3937*4882a593Smuzhiyun &local->active_txqs[ac]);
3938*4882a593Smuzhiyun continue;
3939*4882a593Smuzhiyun }
3940*4882a593Smuzhiyun sta = container_of(iter->txq.sta, struct sta_info, sta);
3941*4882a593Smuzhiyun if (sta->airtime[ac].deficit < 0)
3942*4882a593Smuzhiyun sta->airtime[ac].deficit += sta->airtime_weight;
3943*4882a593Smuzhiyun list_move_tail(&iter->schedule_order, &local->active_txqs[ac]);
3944*4882a593Smuzhiyun }
3945*4882a593Smuzhiyun
3946*4882a593Smuzhiyun sta = container_of(txqi->txq.sta, struct sta_info, sta);
3947*4882a593Smuzhiyun if (sta->airtime[ac].deficit >= 0)
3948*4882a593Smuzhiyun goto out;
3949*4882a593Smuzhiyun
3950*4882a593Smuzhiyun sta->airtime[ac].deficit += sta->airtime_weight;
3951*4882a593Smuzhiyun list_move_tail(&txqi->schedule_order, &local->active_txqs[ac]);
3952*4882a593Smuzhiyun spin_unlock_bh(&local->active_txq_lock[ac]);
3953*4882a593Smuzhiyun
3954*4882a593Smuzhiyun return false;
3955*4882a593Smuzhiyun out:
3956*4882a593Smuzhiyun if (!list_empty(&txqi->schedule_order))
3957*4882a593Smuzhiyun list_del_init(&txqi->schedule_order);
3958*4882a593Smuzhiyun spin_unlock_bh(&local->active_txq_lock[ac]);
3959*4882a593Smuzhiyun
3960*4882a593Smuzhiyun return true;
3961*4882a593Smuzhiyun }
3962*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_txq_may_transmit);
3963*4882a593Smuzhiyun
ieee80211_txq_schedule_start(struct ieee80211_hw * hw,u8 ac)3964*4882a593Smuzhiyun void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac)
3965*4882a593Smuzhiyun {
3966*4882a593Smuzhiyun struct ieee80211_local *local = hw_to_local(hw);
3967*4882a593Smuzhiyun
3968*4882a593Smuzhiyun spin_lock_bh(&local->active_txq_lock[ac]);
3969*4882a593Smuzhiyun local->schedule_round[ac]++;
3970*4882a593Smuzhiyun spin_unlock_bh(&local->active_txq_lock[ac]);
3971*4882a593Smuzhiyun }
3972*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_txq_schedule_start);
3973*4882a593Smuzhiyun
__ieee80211_subif_start_xmit(struct sk_buff * skb,struct net_device * dev,u32 info_flags,u32 ctrl_flags,u64 * cookie)3974*4882a593Smuzhiyun void __ieee80211_subif_start_xmit(struct sk_buff *skb,
3975*4882a593Smuzhiyun struct net_device *dev,
3976*4882a593Smuzhiyun u32 info_flags,
3977*4882a593Smuzhiyun u32 ctrl_flags,
3978*4882a593Smuzhiyun u64 *cookie)
3979*4882a593Smuzhiyun {
3980*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3981*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
3982*4882a593Smuzhiyun struct sta_info *sta;
3983*4882a593Smuzhiyun struct sk_buff *next;
3984*4882a593Smuzhiyun
3985*4882a593Smuzhiyun if (unlikely(skb->len < ETH_HLEN)) {
3986*4882a593Smuzhiyun kfree_skb(skb);
3987*4882a593Smuzhiyun return;
3988*4882a593Smuzhiyun }
3989*4882a593Smuzhiyun
3990*4882a593Smuzhiyun rcu_read_lock();
3991*4882a593Smuzhiyun
3992*4882a593Smuzhiyun if (ieee80211_lookup_ra_sta(sdata, skb, &sta))
3993*4882a593Smuzhiyun goto out_free;
3994*4882a593Smuzhiyun
3995*4882a593Smuzhiyun if (IS_ERR(sta))
3996*4882a593Smuzhiyun sta = NULL;
3997*4882a593Smuzhiyun
3998*4882a593Smuzhiyun if (local->ops->wake_tx_queue) {
3999*4882a593Smuzhiyun u16 queue = __ieee80211_select_queue(sdata, sta, skb);
4000*4882a593Smuzhiyun skb_set_queue_mapping(skb, queue);
4001*4882a593Smuzhiyun skb_get_hash(skb);
4002*4882a593Smuzhiyun }
4003*4882a593Smuzhiyun
4004*4882a593Smuzhiyun if (sta) {
4005*4882a593Smuzhiyun struct ieee80211_fast_tx *fast_tx;
4006*4882a593Smuzhiyun
4007*4882a593Smuzhiyun sk_pacing_shift_update(skb->sk, sdata->local->hw.tx_sk_pacing_shift);
4008*4882a593Smuzhiyun
4009*4882a593Smuzhiyun fast_tx = rcu_dereference(sta->fast_tx);
4010*4882a593Smuzhiyun
4011*4882a593Smuzhiyun if (fast_tx &&
4012*4882a593Smuzhiyun ieee80211_xmit_fast(sdata, sta, fast_tx, skb))
4013*4882a593Smuzhiyun goto out;
4014*4882a593Smuzhiyun }
4015*4882a593Smuzhiyun
4016*4882a593Smuzhiyun if (skb_is_gso(skb)) {
4017*4882a593Smuzhiyun struct sk_buff *segs;
4018*4882a593Smuzhiyun
4019*4882a593Smuzhiyun segs = skb_gso_segment(skb, 0);
4020*4882a593Smuzhiyun if (IS_ERR(segs)) {
4021*4882a593Smuzhiyun goto out_free;
4022*4882a593Smuzhiyun } else if (segs) {
4023*4882a593Smuzhiyun consume_skb(skb);
4024*4882a593Smuzhiyun skb = segs;
4025*4882a593Smuzhiyun }
4026*4882a593Smuzhiyun } else {
4027*4882a593Smuzhiyun /* we cannot process non-linear frames on this path */
4028*4882a593Smuzhiyun if (skb_linearize(skb)) {
4029*4882a593Smuzhiyun kfree_skb(skb);
4030*4882a593Smuzhiyun goto out;
4031*4882a593Smuzhiyun }
4032*4882a593Smuzhiyun
4033*4882a593Smuzhiyun /* the frame could be fragmented, software-encrypted, and other
4034*4882a593Smuzhiyun * things so we cannot really handle checksum offload with it -
4035*4882a593Smuzhiyun * fix it up in software before we handle anything else.
4036*4882a593Smuzhiyun */
4037*4882a593Smuzhiyun if (skb->ip_summed == CHECKSUM_PARTIAL) {
4038*4882a593Smuzhiyun skb_set_transport_header(skb,
4039*4882a593Smuzhiyun skb_checksum_start_offset(skb));
4040*4882a593Smuzhiyun if (skb_checksum_help(skb))
4041*4882a593Smuzhiyun goto out_free;
4042*4882a593Smuzhiyun }
4043*4882a593Smuzhiyun }
4044*4882a593Smuzhiyun
4045*4882a593Smuzhiyun skb_list_walk_safe(skb, skb, next) {
4046*4882a593Smuzhiyun skb_mark_not_on_list(skb);
4047*4882a593Smuzhiyun
4048*4882a593Smuzhiyun if (skb->protocol == sdata->control_port_protocol)
4049*4882a593Smuzhiyun ctrl_flags |= IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP;
4050*4882a593Smuzhiyun
4051*4882a593Smuzhiyun skb = ieee80211_build_hdr(sdata, skb, info_flags,
4052*4882a593Smuzhiyun sta, ctrl_flags, cookie);
4053*4882a593Smuzhiyun if (IS_ERR(skb)) {
4054*4882a593Smuzhiyun kfree_skb_list(next);
4055*4882a593Smuzhiyun goto out;
4056*4882a593Smuzhiyun }
4057*4882a593Smuzhiyun
4058*4882a593Smuzhiyun ieee80211_tx_stats(dev, skb->len);
4059*4882a593Smuzhiyun
4060*4882a593Smuzhiyun ieee80211_xmit(sdata, sta, skb);
4061*4882a593Smuzhiyun }
4062*4882a593Smuzhiyun goto out;
4063*4882a593Smuzhiyun out_free:
4064*4882a593Smuzhiyun kfree_skb(skb);
4065*4882a593Smuzhiyun out:
4066*4882a593Smuzhiyun rcu_read_unlock();
4067*4882a593Smuzhiyun }
4068*4882a593Smuzhiyun
ieee80211_change_da(struct sk_buff * skb,struct sta_info * sta)4069*4882a593Smuzhiyun static int ieee80211_change_da(struct sk_buff *skb, struct sta_info *sta)
4070*4882a593Smuzhiyun {
4071*4882a593Smuzhiyun struct ethhdr *eth;
4072*4882a593Smuzhiyun int err;
4073*4882a593Smuzhiyun
4074*4882a593Smuzhiyun err = skb_ensure_writable(skb, ETH_HLEN);
4075*4882a593Smuzhiyun if (unlikely(err))
4076*4882a593Smuzhiyun return err;
4077*4882a593Smuzhiyun
4078*4882a593Smuzhiyun eth = (void *)skb->data;
4079*4882a593Smuzhiyun ether_addr_copy(eth->h_dest, sta->sta.addr);
4080*4882a593Smuzhiyun
4081*4882a593Smuzhiyun return 0;
4082*4882a593Smuzhiyun }
4083*4882a593Smuzhiyun
ieee80211_multicast_to_unicast(struct sk_buff * skb,struct net_device * dev)4084*4882a593Smuzhiyun static bool ieee80211_multicast_to_unicast(struct sk_buff *skb,
4085*4882a593Smuzhiyun struct net_device *dev)
4086*4882a593Smuzhiyun {
4087*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4088*4882a593Smuzhiyun const struct ethhdr *eth = (void *)skb->data;
4089*4882a593Smuzhiyun const struct vlan_ethhdr *ethvlan = (void *)skb->data;
4090*4882a593Smuzhiyun __be16 ethertype;
4091*4882a593Smuzhiyun
4092*4882a593Smuzhiyun if (likely(!is_multicast_ether_addr(eth->h_dest)))
4093*4882a593Smuzhiyun return false;
4094*4882a593Smuzhiyun
4095*4882a593Smuzhiyun switch (sdata->vif.type) {
4096*4882a593Smuzhiyun case NL80211_IFTYPE_AP_VLAN:
4097*4882a593Smuzhiyun if (sdata->u.vlan.sta)
4098*4882a593Smuzhiyun return false;
4099*4882a593Smuzhiyun if (sdata->wdev.use_4addr)
4100*4882a593Smuzhiyun return false;
4101*4882a593Smuzhiyun fallthrough;
4102*4882a593Smuzhiyun case NL80211_IFTYPE_AP:
4103*4882a593Smuzhiyun /* check runtime toggle for this bss */
4104*4882a593Smuzhiyun if (!sdata->bss->multicast_to_unicast)
4105*4882a593Smuzhiyun return false;
4106*4882a593Smuzhiyun break;
4107*4882a593Smuzhiyun default:
4108*4882a593Smuzhiyun return false;
4109*4882a593Smuzhiyun }
4110*4882a593Smuzhiyun
4111*4882a593Smuzhiyun /* multicast to unicast conversion only for some payload */
4112*4882a593Smuzhiyun ethertype = eth->h_proto;
4113*4882a593Smuzhiyun if (ethertype == htons(ETH_P_8021Q) && skb->len >= VLAN_ETH_HLEN)
4114*4882a593Smuzhiyun ethertype = ethvlan->h_vlan_encapsulated_proto;
4115*4882a593Smuzhiyun switch (ethertype) {
4116*4882a593Smuzhiyun case htons(ETH_P_ARP):
4117*4882a593Smuzhiyun case htons(ETH_P_IP):
4118*4882a593Smuzhiyun case htons(ETH_P_IPV6):
4119*4882a593Smuzhiyun break;
4120*4882a593Smuzhiyun default:
4121*4882a593Smuzhiyun return false;
4122*4882a593Smuzhiyun }
4123*4882a593Smuzhiyun
4124*4882a593Smuzhiyun return true;
4125*4882a593Smuzhiyun }
4126*4882a593Smuzhiyun
4127*4882a593Smuzhiyun static void
ieee80211_convert_to_unicast(struct sk_buff * skb,struct net_device * dev,struct sk_buff_head * queue)4128*4882a593Smuzhiyun ieee80211_convert_to_unicast(struct sk_buff *skb, struct net_device *dev,
4129*4882a593Smuzhiyun struct sk_buff_head *queue)
4130*4882a593Smuzhiyun {
4131*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4132*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
4133*4882a593Smuzhiyun const struct ethhdr *eth = (struct ethhdr *)skb->data;
4134*4882a593Smuzhiyun struct sta_info *sta, *first = NULL;
4135*4882a593Smuzhiyun struct sk_buff *cloned_skb;
4136*4882a593Smuzhiyun
4137*4882a593Smuzhiyun rcu_read_lock();
4138*4882a593Smuzhiyun
4139*4882a593Smuzhiyun list_for_each_entry_rcu(sta, &local->sta_list, list) {
4140*4882a593Smuzhiyun if (sdata != sta->sdata)
4141*4882a593Smuzhiyun /* AP-VLAN mismatch */
4142*4882a593Smuzhiyun continue;
4143*4882a593Smuzhiyun if (unlikely(ether_addr_equal(eth->h_source, sta->sta.addr)))
4144*4882a593Smuzhiyun /* do not send back to source */
4145*4882a593Smuzhiyun continue;
4146*4882a593Smuzhiyun if (!first) {
4147*4882a593Smuzhiyun first = sta;
4148*4882a593Smuzhiyun continue;
4149*4882a593Smuzhiyun }
4150*4882a593Smuzhiyun cloned_skb = skb_clone(skb, GFP_ATOMIC);
4151*4882a593Smuzhiyun if (!cloned_skb)
4152*4882a593Smuzhiyun goto multicast;
4153*4882a593Smuzhiyun if (unlikely(ieee80211_change_da(cloned_skb, sta))) {
4154*4882a593Smuzhiyun dev_kfree_skb(cloned_skb);
4155*4882a593Smuzhiyun goto multicast;
4156*4882a593Smuzhiyun }
4157*4882a593Smuzhiyun __skb_queue_tail(queue, cloned_skb);
4158*4882a593Smuzhiyun }
4159*4882a593Smuzhiyun
4160*4882a593Smuzhiyun if (likely(first)) {
4161*4882a593Smuzhiyun if (unlikely(ieee80211_change_da(skb, first)))
4162*4882a593Smuzhiyun goto multicast;
4163*4882a593Smuzhiyun __skb_queue_tail(queue, skb);
4164*4882a593Smuzhiyun } else {
4165*4882a593Smuzhiyun /* no STA connected, drop */
4166*4882a593Smuzhiyun kfree_skb(skb);
4167*4882a593Smuzhiyun skb = NULL;
4168*4882a593Smuzhiyun }
4169*4882a593Smuzhiyun
4170*4882a593Smuzhiyun goto out;
4171*4882a593Smuzhiyun multicast:
4172*4882a593Smuzhiyun __skb_queue_purge(queue);
4173*4882a593Smuzhiyun __skb_queue_tail(queue, skb);
4174*4882a593Smuzhiyun out:
4175*4882a593Smuzhiyun rcu_read_unlock();
4176*4882a593Smuzhiyun }
4177*4882a593Smuzhiyun
4178*4882a593Smuzhiyun /**
4179*4882a593Smuzhiyun * ieee80211_subif_start_xmit - netif start_xmit function for 802.3 vifs
4180*4882a593Smuzhiyun * @skb: packet to be sent
4181*4882a593Smuzhiyun * @dev: incoming interface
4182*4882a593Smuzhiyun *
4183*4882a593Smuzhiyun * On failure skb will be freed.
4184*4882a593Smuzhiyun */
ieee80211_subif_start_xmit(struct sk_buff * skb,struct net_device * dev)4185*4882a593Smuzhiyun netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
4186*4882a593Smuzhiyun struct net_device *dev)
4187*4882a593Smuzhiyun {
4188*4882a593Smuzhiyun if (unlikely(ieee80211_multicast_to_unicast(skb, dev))) {
4189*4882a593Smuzhiyun struct sk_buff_head queue;
4190*4882a593Smuzhiyun
4191*4882a593Smuzhiyun __skb_queue_head_init(&queue);
4192*4882a593Smuzhiyun ieee80211_convert_to_unicast(skb, dev, &queue);
4193*4882a593Smuzhiyun while ((skb = __skb_dequeue(&queue)))
4194*4882a593Smuzhiyun __ieee80211_subif_start_xmit(skb, dev, 0, 0, NULL);
4195*4882a593Smuzhiyun } else {
4196*4882a593Smuzhiyun __ieee80211_subif_start_xmit(skb, dev, 0, 0, NULL);
4197*4882a593Smuzhiyun }
4198*4882a593Smuzhiyun
4199*4882a593Smuzhiyun return NETDEV_TX_OK;
4200*4882a593Smuzhiyun }
4201*4882a593Smuzhiyun
ieee80211_tx_8023(struct ieee80211_sub_if_data * sdata,struct sk_buff * skb,int led_len,struct sta_info * sta,bool txpending)4202*4882a593Smuzhiyun static bool ieee80211_tx_8023(struct ieee80211_sub_if_data *sdata,
4203*4882a593Smuzhiyun struct sk_buff *skb, int led_len,
4204*4882a593Smuzhiyun struct sta_info *sta,
4205*4882a593Smuzhiyun bool txpending)
4206*4882a593Smuzhiyun {
4207*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
4208*4882a593Smuzhiyun struct ieee80211_tx_control control = {};
4209*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4210*4882a593Smuzhiyun struct ieee80211_sta *pubsta = NULL;
4211*4882a593Smuzhiyun unsigned long flags;
4212*4882a593Smuzhiyun int q = info->hw_queue;
4213*4882a593Smuzhiyun
4214*4882a593Smuzhiyun if (ieee80211_queue_skb(local, sdata, sta, skb))
4215*4882a593Smuzhiyun return true;
4216*4882a593Smuzhiyun
4217*4882a593Smuzhiyun spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
4218*4882a593Smuzhiyun
4219*4882a593Smuzhiyun if (local->queue_stop_reasons[q] ||
4220*4882a593Smuzhiyun (!txpending && !skb_queue_empty(&local->pending[q]))) {
4221*4882a593Smuzhiyun if (txpending)
4222*4882a593Smuzhiyun skb_queue_head(&local->pending[q], skb);
4223*4882a593Smuzhiyun else
4224*4882a593Smuzhiyun skb_queue_tail(&local->pending[q], skb);
4225*4882a593Smuzhiyun
4226*4882a593Smuzhiyun spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
4227*4882a593Smuzhiyun
4228*4882a593Smuzhiyun return false;
4229*4882a593Smuzhiyun }
4230*4882a593Smuzhiyun
4231*4882a593Smuzhiyun spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
4232*4882a593Smuzhiyun
4233*4882a593Smuzhiyun if (sta && sta->uploaded)
4234*4882a593Smuzhiyun pubsta = &sta->sta;
4235*4882a593Smuzhiyun
4236*4882a593Smuzhiyun control.sta = pubsta;
4237*4882a593Smuzhiyun
4238*4882a593Smuzhiyun drv_tx(local, &control, skb);
4239*4882a593Smuzhiyun
4240*4882a593Smuzhiyun return true;
4241*4882a593Smuzhiyun }
4242*4882a593Smuzhiyun
ieee80211_8023_xmit(struct ieee80211_sub_if_data * sdata,struct net_device * dev,struct sta_info * sta,struct ieee80211_key * key,struct sk_buff * skb)4243*4882a593Smuzhiyun static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata,
4244*4882a593Smuzhiyun struct net_device *dev, struct sta_info *sta,
4245*4882a593Smuzhiyun struct ieee80211_key *key, struct sk_buff *skb)
4246*4882a593Smuzhiyun {
4247*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4248*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
4249*4882a593Smuzhiyun struct tid_ampdu_tx *tid_tx;
4250*4882a593Smuzhiyun u8 tid;
4251*4882a593Smuzhiyun
4252*4882a593Smuzhiyun if (local->ops->wake_tx_queue) {
4253*4882a593Smuzhiyun u16 queue = __ieee80211_select_queue(sdata, sta, skb);
4254*4882a593Smuzhiyun skb_set_queue_mapping(skb, queue);
4255*4882a593Smuzhiyun skb_get_hash(skb);
4256*4882a593Smuzhiyun }
4257*4882a593Smuzhiyun
4258*4882a593Smuzhiyun if (unlikely(test_bit(SCAN_SW_SCANNING, &local->scanning)) &&
4259*4882a593Smuzhiyun test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))
4260*4882a593Smuzhiyun goto out_free;
4261*4882a593Smuzhiyun
4262*4882a593Smuzhiyun memset(info, 0, sizeof(*info));
4263*4882a593Smuzhiyun
4264*4882a593Smuzhiyun tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
4265*4882a593Smuzhiyun tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
4266*4882a593Smuzhiyun if (tid_tx) {
4267*4882a593Smuzhiyun if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
4268*4882a593Smuzhiyun /* fall back to non-offload slow path */
4269*4882a593Smuzhiyun __ieee80211_subif_start_xmit(skb, dev, 0, 0, NULL);
4270*4882a593Smuzhiyun return;
4271*4882a593Smuzhiyun }
4272*4882a593Smuzhiyun
4273*4882a593Smuzhiyun info->flags |= IEEE80211_TX_CTL_AMPDU;
4274*4882a593Smuzhiyun if (tid_tx->timeout)
4275*4882a593Smuzhiyun tid_tx->last_tx = jiffies;
4276*4882a593Smuzhiyun }
4277*4882a593Smuzhiyun
4278*4882a593Smuzhiyun if (unlikely(skb->sk &&
4279*4882a593Smuzhiyun skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS))
4280*4882a593Smuzhiyun info->ack_frame_id = ieee80211_store_ack_skb(local, skb,
4281*4882a593Smuzhiyun &info->flags, NULL);
4282*4882a593Smuzhiyun
4283*4882a593Smuzhiyun info->hw_queue = sdata->vif.hw_queue[skb_get_queue_mapping(skb)];
4284*4882a593Smuzhiyun
4285*4882a593Smuzhiyun ieee80211_tx_stats(dev, skb->len);
4286*4882a593Smuzhiyun
4287*4882a593Smuzhiyun sta->tx_stats.bytes[skb_get_queue_mapping(skb)] += skb->len;
4288*4882a593Smuzhiyun sta->tx_stats.packets[skb_get_queue_mapping(skb)]++;
4289*4882a593Smuzhiyun
4290*4882a593Smuzhiyun if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
4291*4882a593Smuzhiyun sdata = container_of(sdata->bss,
4292*4882a593Smuzhiyun struct ieee80211_sub_if_data, u.ap);
4293*4882a593Smuzhiyun
4294*4882a593Smuzhiyun info->flags |= IEEE80211_TX_CTL_HW_80211_ENCAP;
4295*4882a593Smuzhiyun info->control.vif = &sdata->vif;
4296*4882a593Smuzhiyun
4297*4882a593Smuzhiyun if (key)
4298*4882a593Smuzhiyun info->control.hw_key = &key->conf;
4299*4882a593Smuzhiyun
4300*4882a593Smuzhiyun ieee80211_tx_8023(sdata, skb, skb->len, sta, false);
4301*4882a593Smuzhiyun
4302*4882a593Smuzhiyun return;
4303*4882a593Smuzhiyun
4304*4882a593Smuzhiyun out_free:
4305*4882a593Smuzhiyun kfree_skb(skb);
4306*4882a593Smuzhiyun }
4307*4882a593Smuzhiyun
ieee80211_subif_start_xmit_8023(struct sk_buff * skb,struct net_device * dev)4308*4882a593Smuzhiyun netdev_tx_t ieee80211_subif_start_xmit_8023(struct sk_buff *skb,
4309*4882a593Smuzhiyun struct net_device *dev)
4310*4882a593Smuzhiyun {
4311*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4312*4882a593Smuzhiyun struct ethhdr *ehdr = (struct ethhdr *)skb->data;
4313*4882a593Smuzhiyun struct ieee80211_key *key;
4314*4882a593Smuzhiyun struct sta_info *sta;
4315*4882a593Smuzhiyun
4316*4882a593Smuzhiyun if (unlikely(skb->len < ETH_HLEN)) {
4317*4882a593Smuzhiyun kfree_skb(skb);
4318*4882a593Smuzhiyun return NETDEV_TX_OK;
4319*4882a593Smuzhiyun }
4320*4882a593Smuzhiyun
4321*4882a593Smuzhiyun rcu_read_lock();
4322*4882a593Smuzhiyun
4323*4882a593Smuzhiyun if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) {
4324*4882a593Smuzhiyun kfree_skb(skb);
4325*4882a593Smuzhiyun goto out;
4326*4882a593Smuzhiyun }
4327*4882a593Smuzhiyun
4328*4882a593Smuzhiyun if (unlikely(IS_ERR_OR_NULL(sta) || !sta->uploaded ||
4329*4882a593Smuzhiyun !test_sta_flag(sta, WLAN_STA_AUTHORIZED) ||
4330*4882a593Smuzhiyun sdata->control_port_protocol == ehdr->h_proto))
4331*4882a593Smuzhiyun goto skip_offload;
4332*4882a593Smuzhiyun
4333*4882a593Smuzhiyun key = rcu_dereference(sta->ptk[sta->ptk_idx]);
4334*4882a593Smuzhiyun if (!key)
4335*4882a593Smuzhiyun key = rcu_dereference(sdata->default_unicast_key);
4336*4882a593Smuzhiyun
4337*4882a593Smuzhiyun if (key && (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) ||
4338*4882a593Smuzhiyun key->conf.cipher == WLAN_CIPHER_SUITE_TKIP))
4339*4882a593Smuzhiyun goto skip_offload;
4340*4882a593Smuzhiyun
4341*4882a593Smuzhiyun ieee80211_8023_xmit(sdata, dev, sta, key, skb);
4342*4882a593Smuzhiyun goto out;
4343*4882a593Smuzhiyun
4344*4882a593Smuzhiyun skip_offload:
4345*4882a593Smuzhiyun ieee80211_subif_start_xmit(skb, dev);
4346*4882a593Smuzhiyun out:
4347*4882a593Smuzhiyun rcu_read_unlock();
4348*4882a593Smuzhiyun
4349*4882a593Smuzhiyun return NETDEV_TX_OK;
4350*4882a593Smuzhiyun }
4351*4882a593Smuzhiyun
4352*4882a593Smuzhiyun struct sk_buff *
ieee80211_build_data_template(struct ieee80211_sub_if_data * sdata,struct sk_buff * skb,u32 info_flags)4353*4882a593Smuzhiyun ieee80211_build_data_template(struct ieee80211_sub_if_data *sdata,
4354*4882a593Smuzhiyun struct sk_buff *skb, u32 info_flags)
4355*4882a593Smuzhiyun {
4356*4882a593Smuzhiyun struct ieee80211_hdr *hdr;
4357*4882a593Smuzhiyun struct ieee80211_tx_data tx = {
4358*4882a593Smuzhiyun .local = sdata->local,
4359*4882a593Smuzhiyun .sdata = sdata,
4360*4882a593Smuzhiyun };
4361*4882a593Smuzhiyun struct sta_info *sta;
4362*4882a593Smuzhiyun
4363*4882a593Smuzhiyun rcu_read_lock();
4364*4882a593Smuzhiyun
4365*4882a593Smuzhiyun if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) {
4366*4882a593Smuzhiyun kfree_skb(skb);
4367*4882a593Smuzhiyun skb = ERR_PTR(-EINVAL);
4368*4882a593Smuzhiyun goto out;
4369*4882a593Smuzhiyun }
4370*4882a593Smuzhiyun
4371*4882a593Smuzhiyun skb = ieee80211_build_hdr(sdata, skb, info_flags, sta, 0, NULL);
4372*4882a593Smuzhiyun if (IS_ERR(skb))
4373*4882a593Smuzhiyun goto out;
4374*4882a593Smuzhiyun
4375*4882a593Smuzhiyun hdr = (void *)skb->data;
4376*4882a593Smuzhiyun tx.sta = sta_info_get(sdata, hdr->addr1);
4377*4882a593Smuzhiyun tx.skb = skb;
4378*4882a593Smuzhiyun
4379*4882a593Smuzhiyun if (ieee80211_tx_h_select_key(&tx) != TX_CONTINUE) {
4380*4882a593Smuzhiyun rcu_read_unlock();
4381*4882a593Smuzhiyun kfree_skb(skb);
4382*4882a593Smuzhiyun return ERR_PTR(-EINVAL);
4383*4882a593Smuzhiyun }
4384*4882a593Smuzhiyun
4385*4882a593Smuzhiyun out:
4386*4882a593Smuzhiyun rcu_read_unlock();
4387*4882a593Smuzhiyun return skb;
4388*4882a593Smuzhiyun }
4389*4882a593Smuzhiyun
4390*4882a593Smuzhiyun /*
4391*4882a593Smuzhiyun * ieee80211_clear_tx_pending may not be called in a context where
4392*4882a593Smuzhiyun * it is possible that it packets could come in again.
4393*4882a593Smuzhiyun */
ieee80211_clear_tx_pending(struct ieee80211_local * local)4394*4882a593Smuzhiyun void ieee80211_clear_tx_pending(struct ieee80211_local *local)
4395*4882a593Smuzhiyun {
4396*4882a593Smuzhiyun struct sk_buff *skb;
4397*4882a593Smuzhiyun int i;
4398*4882a593Smuzhiyun
4399*4882a593Smuzhiyun for (i = 0; i < local->hw.queues; i++) {
4400*4882a593Smuzhiyun while ((skb = skb_dequeue(&local->pending[i])) != NULL)
4401*4882a593Smuzhiyun ieee80211_free_txskb(&local->hw, skb);
4402*4882a593Smuzhiyun }
4403*4882a593Smuzhiyun }
4404*4882a593Smuzhiyun
4405*4882a593Smuzhiyun /*
4406*4882a593Smuzhiyun * Returns false if the frame couldn't be transmitted but was queued instead,
4407*4882a593Smuzhiyun * which in this case means re-queued -- take as an indication to stop sending
4408*4882a593Smuzhiyun * more pending frames.
4409*4882a593Smuzhiyun */
ieee80211_tx_pending_skb(struct ieee80211_local * local,struct sk_buff * skb)4410*4882a593Smuzhiyun static bool ieee80211_tx_pending_skb(struct ieee80211_local *local,
4411*4882a593Smuzhiyun struct sk_buff *skb)
4412*4882a593Smuzhiyun {
4413*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4414*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata;
4415*4882a593Smuzhiyun struct sta_info *sta;
4416*4882a593Smuzhiyun struct ieee80211_hdr *hdr;
4417*4882a593Smuzhiyun bool result;
4418*4882a593Smuzhiyun struct ieee80211_chanctx_conf *chanctx_conf;
4419*4882a593Smuzhiyun
4420*4882a593Smuzhiyun sdata = vif_to_sdata(info->control.vif);
4421*4882a593Smuzhiyun
4422*4882a593Smuzhiyun if (info->control.flags & IEEE80211_TX_INTCFL_NEED_TXPROCESSING) {
4423*4882a593Smuzhiyun chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
4424*4882a593Smuzhiyun if (unlikely(!chanctx_conf)) {
4425*4882a593Smuzhiyun dev_kfree_skb(skb);
4426*4882a593Smuzhiyun return true;
4427*4882a593Smuzhiyun }
4428*4882a593Smuzhiyun info->band = chanctx_conf->def.chan->band;
4429*4882a593Smuzhiyun result = ieee80211_tx(sdata, NULL, skb, true);
4430*4882a593Smuzhiyun } else if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) {
4431*4882a593Smuzhiyun if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) {
4432*4882a593Smuzhiyun dev_kfree_skb(skb);
4433*4882a593Smuzhiyun return true;
4434*4882a593Smuzhiyun }
4435*4882a593Smuzhiyun
4436*4882a593Smuzhiyun if (IS_ERR(sta) || (sta && !sta->uploaded))
4437*4882a593Smuzhiyun sta = NULL;
4438*4882a593Smuzhiyun
4439*4882a593Smuzhiyun result = ieee80211_tx_8023(sdata, skb, skb->len, sta, true);
4440*4882a593Smuzhiyun } else {
4441*4882a593Smuzhiyun struct sk_buff_head skbs;
4442*4882a593Smuzhiyun
4443*4882a593Smuzhiyun __skb_queue_head_init(&skbs);
4444*4882a593Smuzhiyun __skb_queue_tail(&skbs, skb);
4445*4882a593Smuzhiyun
4446*4882a593Smuzhiyun hdr = (struct ieee80211_hdr *)skb->data;
4447*4882a593Smuzhiyun sta = sta_info_get(sdata, hdr->addr1);
4448*4882a593Smuzhiyun
4449*4882a593Smuzhiyun result = __ieee80211_tx(local, &skbs, skb->len, sta, true);
4450*4882a593Smuzhiyun }
4451*4882a593Smuzhiyun
4452*4882a593Smuzhiyun return result;
4453*4882a593Smuzhiyun }
4454*4882a593Smuzhiyun
4455*4882a593Smuzhiyun /*
4456*4882a593Smuzhiyun * Transmit all pending packets. Called from tasklet.
4457*4882a593Smuzhiyun */
ieee80211_tx_pending(unsigned long data)4458*4882a593Smuzhiyun void ieee80211_tx_pending(unsigned long data)
4459*4882a593Smuzhiyun {
4460*4882a593Smuzhiyun struct ieee80211_local *local = (struct ieee80211_local *)data;
4461*4882a593Smuzhiyun unsigned long flags;
4462*4882a593Smuzhiyun int i;
4463*4882a593Smuzhiyun bool txok;
4464*4882a593Smuzhiyun
4465*4882a593Smuzhiyun rcu_read_lock();
4466*4882a593Smuzhiyun
4467*4882a593Smuzhiyun spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
4468*4882a593Smuzhiyun for (i = 0; i < local->hw.queues; i++) {
4469*4882a593Smuzhiyun /*
4470*4882a593Smuzhiyun * If queue is stopped by something other than due to pending
4471*4882a593Smuzhiyun * frames, or we have no pending frames, proceed to next queue.
4472*4882a593Smuzhiyun */
4473*4882a593Smuzhiyun if (local->queue_stop_reasons[i] ||
4474*4882a593Smuzhiyun skb_queue_empty(&local->pending[i]))
4475*4882a593Smuzhiyun continue;
4476*4882a593Smuzhiyun
4477*4882a593Smuzhiyun while (!skb_queue_empty(&local->pending[i])) {
4478*4882a593Smuzhiyun struct sk_buff *skb = __skb_dequeue(&local->pending[i]);
4479*4882a593Smuzhiyun struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4480*4882a593Smuzhiyun
4481*4882a593Smuzhiyun if (WARN_ON(!info->control.vif)) {
4482*4882a593Smuzhiyun ieee80211_free_txskb(&local->hw, skb);
4483*4882a593Smuzhiyun continue;
4484*4882a593Smuzhiyun }
4485*4882a593Smuzhiyun
4486*4882a593Smuzhiyun spin_unlock_irqrestore(&local->queue_stop_reason_lock,
4487*4882a593Smuzhiyun flags);
4488*4882a593Smuzhiyun
4489*4882a593Smuzhiyun txok = ieee80211_tx_pending_skb(local, skb);
4490*4882a593Smuzhiyun spin_lock_irqsave(&local->queue_stop_reason_lock,
4491*4882a593Smuzhiyun flags);
4492*4882a593Smuzhiyun if (!txok)
4493*4882a593Smuzhiyun break;
4494*4882a593Smuzhiyun }
4495*4882a593Smuzhiyun
4496*4882a593Smuzhiyun if (skb_queue_empty(&local->pending[i]))
4497*4882a593Smuzhiyun ieee80211_propagate_queue_wake(local, i);
4498*4882a593Smuzhiyun }
4499*4882a593Smuzhiyun spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
4500*4882a593Smuzhiyun
4501*4882a593Smuzhiyun rcu_read_unlock();
4502*4882a593Smuzhiyun }
4503*4882a593Smuzhiyun
4504*4882a593Smuzhiyun /* functions for drivers to get certain frames */
4505*4882a593Smuzhiyun
__ieee80211_beacon_add_tim(struct ieee80211_sub_if_data * sdata,struct ps_data * ps,struct sk_buff * skb,bool is_template)4506*4882a593Smuzhiyun static void __ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
4507*4882a593Smuzhiyun struct ps_data *ps, struct sk_buff *skb,
4508*4882a593Smuzhiyun bool is_template)
4509*4882a593Smuzhiyun {
4510*4882a593Smuzhiyun u8 *pos, *tim;
4511*4882a593Smuzhiyun int aid0 = 0;
4512*4882a593Smuzhiyun int i, have_bits = 0, n1, n2;
4513*4882a593Smuzhiyun
4514*4882a593Smuzhiyun /* Generate bitmap for TIM only if there are any STAs in power save
4515*4882a593Smuzhiyun * mode. */
4516*4882a593Smuzhiyun if (atomic_read(&ps->num_sta_ps) > 0)
4517*4882a593Smuzhiyun /* in the hope that this is faster than
4518*4882a593Smuzhiyun * checking byte-for-byte */
4519*4882a593Smuzhiyun have_bits = !bitmap_empty((unsigned long *)ps->tim,
4520*4882a593Smuzhiyun IEEE80211_MAX_AID+1);
4521*4882a593Smuzhiyun if (!is_template) {
4522*4882a593Smuzhiyun if (ps->dtim_count == 0)
4523*4882a593Smuzhiyun ps->dtim_count = sdata->vif.bss_conf.dtim_period - 1;
4524*4882a593Smuzhiyun else
4525*4882a593Smuzhiyun ps->dtim_count--;
4526*4882a593Smuzhiyun }
4527*4882a593Smuzhiyun
4528*4882a593Smuzhiyun tim = pos = skb_put(skb, 6);
4529*4882a593Smuzhiyun *pos++ = WLAN_EID_TIM;
4530*4882a593Smuzhiyun *pos++ = 4;
4531*4882a593Smuzhiyun *pos++ = ps->dtim_count;
4532*4882a593Smuzhiyun *pos++ = sdata->vif.bss_conf.dtim_period;
4533*4882a593Smuzhiyun
4534*4882a593Smuzhiyun if (ps->dtim_count == 0 && !skb_queue_empty(&ps->bc_buf))
4535*4882a593Smuzhiyun aid0 = 1;
4536*4882a593Smuzhiyun
4537*4882a593Smuzhiyun ps->dtim_bc_mc = aid0 == 1;
4538*4882a593Smuzhiyun
4539*4882a593Smuzhiyun if (have_bits) {
4540*4882a593Smuzhiyun /* Find largest even number N1 so that bits numbered 1 through
4541*4882a593Smuzhiyun * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits
4542*4882a593Smuzhiyun * (N2 + 1) x 8 through 2007 are 0. */
4543*4882a593Smuzhiyun n1 = 0;
4544*4882a593Smuzhiyun for (i = 0; i < IEEE80211_MAX_TIM_LEN; i++) {
4545*4882a593Smuzhiyun if (ps->tim[i]) {
4546*4882a593Smuzhiyun n1 = i & 0xfe;
4547*4882a593Smuzhiyun break;
4548*4882a593Smuzhiyun }
4549*4882a593Smuzhiyun }
4550*4882a593Smuzhiyun n2 = n1;
4551*4882a593Smuzhiyun for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) {
4552*4882a593Smuzhiyun if (ps->tim[i]) {
4553*4882a593Smuzhiyun n2 = i;
4554*4882a593Smuzhiyun break;
4555*4882a593Smuzhiyun }
4556*4882a593Smuzhiyun }
4557*4882a593Smuzhiyun
4558*4882a593Smuzhiyun /* Bitmap control */
4559*4882a593Smuzhiyun *pos++ = n1 | aid0;
4560*4882a593Smuzhiyun /* Part Virt Bitmap */
4561*4882a593Smuzhiyun skb_put(skb, n2 - n1);
4562*4882a593Smuzhiyun memcpy(pos, ps->tim + n1, n2 - n1 + 1);
4563*4882a593Smuzhiyun
4564*4882a593Smuzhiyun tim[1] = n2 - n1 + 4;
4565*4882a593Smuzhiyun } else {
4566*4882a593Smuzhiyun *pos++ = aid0; /* Bitmap control */
4567*4882a593Smuzhiyun *pos++ = 0; /* Part Virt Bitmap */
4568*4882a593Smuzhiyun }
4569*4882a593Smuzhiyun }
4570*4882a593Smuzhiyun
ieee80211_beacon_add_tim(struct ieee80211_sub_if_data * sdata,struct ps_data * ps,struct sk_buff * skb,bool is_template)4571*4882a593Smuzhiyun static int ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
4572*4882a593Smuzhiyun struct ps_data *ps, struct sk_buff *skb,
4573*4882a593Smuzhiyun bool is_template)
4574*4882a593Smuzhiyun {
4575*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
4576*4882a593Smuzhiyun
4577*4882a593Smuzhiyun /*
4578*4882a593Smuzhiyun * Not very nice, but we want to allow the driver to call
4579*4882a593Smuzhiyun * ieee80211_beacon_get() as a response to the set_tim()
4580*4882a593Smuzhiyun * callback. That, however, is already invoked under the
4581*4882a593Smuzhiyun * sta_lock to guarantee consistent and race-free update
4582*4882a593Smuzhiyun * of the tim bitmap in mac80211 and the driver.
4583*4882a593Smuzhiyun */
4584*4882a593Smuzhiyun if (local->tim_in_locked_section) {
4585*4882a593Smuzhiyun __ieee80211_beacon_add_tim(sdata, ps, skb, is_template);
4586*4882a593Smuzhiyun } else {
4587*4882a593Smuzhiyun spin_lock_bh(&local->tim_lock);
4588*4882a593Smuzhiyun __ieee80211_beacon_add_tim(sdata, ps, skb, is_template);
4589*4882a593Smuzhiyun spin_unlock_bh(&local->tim_lock);
4590*4882a593Smuzhiyun }
4591*4882a593Smuzhiyun
4592*4882a593Smuzhiyun return 0;
4593*4882a593Smuzhiyun }
4594*4882a593Smuzhiyun
ieee80211_set_beacon_cntdwn(struct ieee80211_sub_if_data * sdata,struct beacon_data * beacon)4595*4882a593Smuzhiyun static void ieee80211_set_beacon_cntdwn(struct ieee80211_sub_if_data *sdata,
4596*4882a593Smuzhiyun struct beacon_data *beacon)
4597*4882a593Smuzhiyun {
4598*4882a593Smuzhiyun struct probe_resp *resp;
4599*4882a593Smuzhiyun u8 *beacon_data;
4600*4882a593Smuzhiyun size_t beacon_data_len;
4601*4882a593Smuzhiyun int i;
4602*4882a593Smuzhiyun u8 count = beacon->cntdwn_current_counter;
4603*4882a593Smuzhiyun
4604*4882a593Smuzhiyun switch (sdata->vif.type) {
4605*4882a593Smuzhiyun case NL80211_IFTYPE_AP:
4606*4882a593Smuzhiyun beacon_data = beacon->tail;
4607*4882a593Smuzhiyun beacon_data_len = beacon->tail_len;
4608*4882a593Smuzhiyun break;
4609*4882a593Smuzhiyun case NL80211_IFTYPE_ADHOC:
4610*4882a593Smuzhiyun beacon_data = beacon->head;
4611*4882a593Smuzhiyun beacon_data_len = beacon->head_len;
4612*4882a593Smuzhiyun break;
4613*4882a593Smuzhiyun case NL80211_IFTYPE_MESH_POINT:
4614*4882a593Smuzhiyun beacon_data = beacon->head;
4615*4882a593Smuzhiyun beacon_data_len = beacon->head_len;
4616*4882a593Smuzhiyun break;
4617*4882a593Smuzhiyun default:
4618*4882a593Smuzhiyun return;
4619*4882a593Smuzhiyun }
4620*4882a593Smuzhiyun
4621*4882a593Smuzhiyun rcu_read_lock();
4622*4882a593Smuzhiyun for (i = 0; i < IEEE80211_MAX_CNTDWN_COUNTERS_NUM; ++i) {
4623*4882a593Smuzhiyun resp = rcu_dereference(sdata->u.ap.probe_resp);
4624*4882a593Smuzhiyun
4625*4882a593Smuzhiyun if (beacon->cntdwn_counter_offsets[i]) {
4626*4882a593Smuzhiyun if (WARN_ON_ONCE(beacon->cntdwn_counter_offsets[i] >=
4627*4882a593Smuzhiyun beacon_data_len)) {
4628*4882a593Smuzhiyun rcu_read_unlock();
4629*4882a593Smuzhiyun return;
4630*4882a593Smuzhiyun }
4631*4882a593Smuzhiyun
4632*4882a593Smuzhiyun beacon_data[beacon->cntdwn_counter_offsets[i]] = count;
4633*4882a593Smuzhiyun }
4634*4882a593Smuzhiyun
4635*4882a593Smuzhiyun if (sdata->vif.type == NL80211_IFTYPE_AP && resp)
4636*4882a593Smuzhiyun resp->data[resp->cntdwn_counter_offsets[i]] = count;
4637*4882a593Smuzhiyun }
4638*4882a593Smuzhiyun rcu_read_unlock();
4639*4882a593Smuzhiyun }
4640*4882a593Smuzhiyun
__ieee80211_beacon_update_cntdwn(struct beacon_data * beacon)4641*4882a593Smuzhiyun static u8 __ieee80211_beacon_update_cntdwn(struct beacon_data *beacon)
4642*4882a593Smuzhiyun {
4643*4882a593Smuzhiyun beacon->cntdwn_current_counter--;
4644*4882a593Smuzhiyun
4645*4882a593Smuzhiyun /* the counter should never reach 0 */
4646*4882a593Smuzhiyun WARN_ON_ONCE(!beacon->cntdwn_current_counter);
4647*4882a593Smuzhiyun
4648*4882a593Smuzhiyun return beacon->cntdwn_current_counter;
4649*4882a593Smuzhiyun }
4650*4882a593Smuzhiyun
ieee80211_beacon_update_cntdwn(struct ieee80211_vif * vif)4651*4882a593Smuzhiyun u8 ieee80211_beacon_update_cntdwn(struct ieee80211_vif *vif)
4652*4882a593Smuzhiyun {
4653*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4654*4882a593Smuzhiyun struct beacon_data *beacon = NULL;
4655*4882a593Smuzhiyun u8 count = 0;
4656*4882a593Smuzhiyun
4657*4882a593Smuzhiyun rcu_read_lock();
4658*4882a593Smuzhiyun
4659*4882a593Smuzhiyun if (sdata->vif.type == NL80211_IFTYPE_AP)
4660*4882a593Smuzhiyun beacon = rcu_dereference(sdata->u.ap.beacon);
4661*4882a593Smuzhiyun else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
4662*4882a593Smuzhiyun beacon = rcu_dereference(sdata->u.ibss.presp);
4663*4882a593Smuzhiyun else if (ieee80211_vif_is_mesh(&sdata->vif))
4664*4882a593Smuzhiyun beacon = rcu_dereference(sdata->u.mesh.beacon);
4665*4882a593Smuzhiyun
4666*4882a593Smuzhiyun if (!beacon)
4667*4882a593Smuzhiyun goto unlock;
4668*4882a593Smuzhiyun
4669*4882a593Smuzhiyun count = __ieee80211_beacon_update_cntdwn(beacon);
4670*4882a593Smuzhiyun
4671*4882a593Smuzhiyun unlock:
4672*4882a593Smuzhiyun rcu_read_unlock();
4673*4882a593Smuzhiyun return count;
4674*4882a593Smuzhiyun }
4675*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_beacon_update_cntdwn);
4676*4882a593Smuzhiyun
ieee80211_beacon_set_cntdwn(struct ieee80211_vif * vif,u8 counter)4677*4882a593Smuzhiyun void ieee80211_beacon_set_cntdwn(struct ieee80211_vif *vif, u8 counter)
4678*4882a593Smuzhiyun {
4679*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4680*4882a593Smuzhiyun struct beacon_data *beacon = NULL;
4681*4882a593Smuzhiyun
4682*4882a593Smuzhiyun rcu_read_lock();
4683*4882a593Smuzhiyun
4684*4882a593Smuzhiyun if (sdata->vif.type == NL80211_IFTYPE_AP)
4685*4882a593Smuzhiyun beacon = rcu_dereference(sdata->u.ap.beacon);
4686*4882a593Smuzhiyun else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
4687*4882a593Smuzhiyun beacon = rcu_dereference(sdata->u.ibss.presp);
4688*4882a593Smuzhiyun else if (ieee80211_vif_is_mesh(&sdata->vif))
4689*4882a593Smuzhiyun beacon = rcu_dereference(sdata->u.mesh.beacon);
4690*4882a593Smuzhiyun
4691*4882a593Smuzhiyun if (!beacon)
4692*4882a593Smuzhiyun goto unlock;
4693*4882a593Smuzhiyun
4694*4882a593Smuzhiyun if (counter < beacon->cntdwn_current_counter)
4695*4882a593Smuzhiyun beacon->cntdwn_current_counter = counter;
4696*4882a593Smuzhiyun
4697*4882a593Smuzhiyun unlock:
4698*4882a593Smuzhiyun rcu_read_unlock();
4699*4882a593Smuzhiyun }
4700*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_beacon_set_cntdwn);
4701*4882a593Smuzhiyun
ieee80211_beacon_cntdwn_is_complete(struct ieee80211_vif * vif)4702*4882a593Smuzhiyun bool ieee80211_beacon_cntdwn_is_complete(struct ieee80211_vif *vif)
4703*4882a593Smuzhiyun {
4704*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4705*4882a593Smuzhiyun struct beacon_data *beacon = NULL;
4706*4882a593Smuzhiyun u8 *beacon_data;
4707*4882a593Smuzhiyun size_t beacon_data_len;
4708*4882a593Smuzhiyun int ret = false;
4709*4882a593Smuzhiyun
4710*4882a593Smuzhiyun if (!ieee80211_sdata_running(sdata))
4711*4882a593Smuzhiyun return false;
4712*4882a593Smuzhiyun
4713*4882a593Smuzhiyun rcu_read_lock();
4714*4882a593Smuzhiyun if (vif->type == NL80211_IFTYPE_AP) {
4715*4882a593Smuzhiyun struct ieee80211_if_ap *ap = &sdata->u.ap;
4716*4882a593Smuzhiyun
4717*4882a593Smuzhiyun beacon = rcu_dereference(ap->beacon);
4718*4882a593Smuzhiyun if (WARN_ON(!beacon || !beacon->tail))
4719*4882a593Smuzhiyun goto out;
4720*4882a593Smuzhiyun beacon_data = beacon->tail;
4721*4882a593Smuzhiyun beacon_data_len = beacon->tail_len;
4722*4882a593Smuzhiyun } else if (vif->type == NL80211_IFTYPE_ADHOC) {
4723*4882a593Smuzhiyun struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
4724*4882a593Smuzhiyun
4725*4882a593Smuzhiyun beacon = rcu_dereference(ifibss->presp);
4726*4882a593Smuzhiyun if (!beacon)
4727*4882a593Smuzhiyun goto out;
4728*4882a593Smuzhiyun
4729*4882a593Smuzhiyun beacon_data = beacon->head;
4730*4882a593Smuzhiyun beacon_data_len = beacon->head_len;
4731*4882a593Smuzhiyun } else if (vif->type == NL80211_IFTYPE_MESH_POINT) {
4732*4882a593Smuzhiyun struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
4733*4882a593Smuzhiyun
4734*4882a593Smuzhiyun beacon = rcu_dereference(ifmsh->beacon);
4735*4882a593Smuzhiyun if (!beacon)
4736*4882a593Smuzhiyun goto out;
4737*4882a593Smuzhiyun
4738*4882a593Smuzhiyun beacon_data = beacon->head;
4739*4882a593Smuzhiyun beacon_data_len = beacon->head_len;
4740*4882a593Smuzhiyun } else {
4741*4882a593Smuzhiyun WARN_ON(1);
4742*4882a593Smuzhiyun goto out;
4743*4882a593Smuzhiyun }
4744*4882a593Smuzhiyun
4745*4882a593Smuzhiyun if (!beacon->cntdwn_counter_offsets[0])
4746*4882a593Smuzhiyun goto out;
4747*4882a593Smuzhiyun
4748*4882a593Smuzhiyun if (WARN_ON_ONCE(beacon->cntdwn_counter_offsets[0] > beacon_data_len))
4749*4882a593Smuzhiyun goto out;
4750*4882a593Smuzhiyun
4751*4882a593Smuzhiyun if (beacon_data[beacon->cntdwn_counter_offsets[0]] == 1)
4752*4882a593Smuzhiyun ret = true;
4753*4882a593Smuzhiyun
4754*4882a593Smuzhiyun out:
4755*4882a593Smuzhiyun rcu_read_unlock();
4756*4882a593Smuzhiyun
4757*4882a593Smuzhiyun return ret;
4758*4882a593Smuzhiyun }
4759*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_beacon_cntdwn_is_complete);
4760*4882a593Smuzhiyun
ieee80211_beacon_protect(struct sk_buff * skb,struct ieee80211_local * local,struct ieee80211_sub_if_data * sdata)4761*4882a593Smuzhiyun static int ieee80211_beacon_protect(struct sk_buff *skb,
4762*4882a593Smuzhiyun struct ieee80211_local *local,
4763*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata)
4764*4882a593Smuzhiyun {
4765*4882a593Smuzhiyun ieee80211_tx_result res;
4766*4882a593Smuzhiyun struct ieee80211_tx_data tx;
4767*4882a593Smuzhiyun struct sk_buff *check_skb;
4768*4882a593Smuzhiyun
4769*4882a593Smuzhiyun memset(&tx, 0, sizeof(tx));
4770*4882a593Smuzhiyun tx.key = rcu_dereference(sdata->default_beacon_key);
4771*4882a593Smuzhiyun if (!tx.key)
4772*4882a593Smuzhiyun return 0;
4773*4882a593Smuzhiyun tx.local = local;
4774*4882a593Smuzhiyun tx.sdata = sdata;
4775*4882a593Smuzhiyun __skb_queue_head_init(&tx.skbs);
4776*4882a593Smuzhiyun __skb_queue_tail(&tx.skbs, skb);
4777*4882a593Smuzhiyun res = ieee80211_tx_h_encrypt(&tx);
4778*4882a593Smuzhiyun check_skb = __skb_dequeue(&tx.skbs);
4779*4882a593Smuzhiyun /* we may crash after this, but it'd be a bug in crypto */
4780*4882a593Smuzhiyun WARN_ON(check_skb != skb);
4781*4882a593Smuzhiyun if (WARN_ON_ONCE(res != TX_CONTINUE))
4782*4882a593Smuzhiyun return -EINVAL;
4783*4882a593Smuzhiyun
4784*4882a593Smuzhiyun return 0;
4785*4882a593Smuzhiyun }
4786*4882a593Smuzhiyun
4787*4882a593Smuzhiyun static struct sk_buff *
__ieee80211_beacon_get(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_mutable_offsets * offs,bool is_template)4788*4882a593Smuzhiyun __ieee80211_beacon_get(struct ieee80211_hw *hw,
4789*4882a593Smuzhiyun struct ieee80211_vif *vif,
4790*4882a593Smuzhiyun struct ieee80211_mutable_offsets *offs,
4791*4882a593Smuzhiyun bool is_template)
4792*4882a593Smuzhiyun {
4793*4882a593Smuzhiyun struct ieee80211_local *local = hw_to_local(hw);
4794*4882a593Smuzhiyun struct beacon_data *beacon = NULL;
4795*4882a593Smuzhiyun struct sk_buff *skb = NULL;
4796*4882a593Smuzhiyun struct ieee80211_tx_info *info;
4797*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = NULL;
4798*4882a593Smuzhiyun enum nl80211_band band;
4799*4882a593Smuzhiyun struct ieee80211_tx_rate_control txrc;
4800*4882a593Smuzhiyun struct ieee80211_chanctx_conf *chanctx_conf;
4801*4882a593Smuzhiyun int csa_off_base = 0;
4802*4882a593Smuzhiyun
4803*4882a593Smuzhiyun rcu_read_lock();
4804*4882a593Smuzhiyun
4805*4882a593Smuzhiyun sdata = vif_to_sdata(vif);
4806*4882a593Smuzhiyun chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
4807*4882a593Smuzhiyun
4808*4882a593Smuzhiyun if (!ieee80211_sdata_running(sdata) || !chanctx_conf)
4809*4882a593Smuzhiyun goto out;
4810*4882a593Smuzhiyun
4811*4882a593Smuzhiyun if (offs)
4812*4882a593Smuzhiyun memset(offs, 0, sizeof(*offs));
4813*4882a593Smuzhiyun
4814*4882a593Smuzhiyun if (sdata->vif.type == NL80211_IFTYPE_AP) {
4815*4882a593Smuzhiyun struct ieee80211_if_ap *ap = &sdata->u.ap;
4816*4882a593Smuzhiyun
4817*4882a593Smuzhiyun beacon = rcu_dereference(ap->beacon);
4818*4882a593Smuzhiyun if (beacon) {
4819*4882a593Smuzhiyun if (beacon->cntdwn_counter_offsets[0]) {
4820*4882a593Smuzhiyun if (!is_template)
4821*4882a593Smuzhiyun ieee80211_beacon_update_cntdwn(vif);
4822*4882a593Smuzhiyun
4823*4882a593Smuzhiyun ieee80211_set_beacon_cntdwn(sdata, beacon);
4824*4882a593Smuzhiyun }
4825*4882a593Smuzhiyun
4826*4882a593Smuzhiyun /*
4827*4882a593Smuzhiyun * headroom, head length,
4828*4882a593Smuzhiyun * tail length and maximum TIM length
4829*4882a593Smuzhiyun */
4830*4882a593Smuzhiyun skb = dev_alloc_skb(local->tx_headroom +
4831*4882a593Smuzhiyun beacon->head_len +
4832*4882a593Smuzhiyun beacon->tail_len + 256 +
4833*4882a593Smuzhiyun local->hw.extra_beacon_tailroom);
4834*4882a593Smuzhiyun if (!skb)
4835*4882a593Smuzhiyun goto out;
4836*4882a593Smuzhiyun
4837*4882a593Smuzhiyun skb_reserve(skb, local->tx_headroom);
4838*4882a593Smuzhiyun skb_put_data(skb, beacon->head, beacon->head_len);
4839*4882a593Smuzhiyun
4840*4882a593Smuzhiyun ieee80211_beacon_add_tim(sdata, &ap->ps, skb,
4841*4882a593Smuzhiyun is_template);
4842*4882a593Smuzhiyun
4843*4882a593Smuzhiyun if (offs) {
4844*4882a593Smuzhiyun offs->tim_offset = beacon->head_len;
4845*4882a593Smuzhiyun offs->tim_length = skb->len - beacon->head_len;
4846*4882a593Smuzhiyun
4847*4882a593Smuzhiyun /* for AP the csa offsets are from tail */
4848*4882a593Smuzhiyun csa_off_base = skb->len;
4849*4882a593Smuzhiyun }
4850*4882a593Smuzhiyun
4851*4882a593Smuzhiyun if (beacon->tail)
4852*4882a593Smuzhiyun skb_put_data(skb, beacon->tail,
4853*4882a593Smuzhiyun beacon->tail_len);
4854*4882a593Smuzhiyun
4855*4882a593Smuzhiyun if (ieee80211_beacon_protect(skb, local, sdata) < 0)
4856*4882a593Smuzhiyun goto out;
4857*4882a593Smuzhiyun } else
4858*4882a593Smuzhiyun goto out;
4859*4882a593Smuzhiyun } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
4860*4882a593Smuzhiyun struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
4861*4882a593Smuzhiyun struct ieee80211_hdr *hdr;
4862*4882a593Smuzhiyun
4863*4882a593Smuzhiyun beacon = rcu_dereference(ifibss->presp);
4864*4882a593Smuzhiyun if (!beacon)
4865*4882a593Smuzhiyun goto out;
4866*4882a593Smuzhiyun
4867*4882a593Smuzhiyun if (beacon->cntdwn_counter_offsets[0]) {
4868*4882a593Smuzhiyun if (!is_template)
4869*4882a593Smuzhiyun __ieee80211_beacon_update_cntdwn(beacon);
4870*4882a593Smuzhiyun
4871*4882a593Smuzhiyun ieee80211_set_beacon_cntdwn(sdata, beacon);
4872*4882a593Smuzhiyun }
4873*4882a593Smuzhiyun
4874*4882a593Smuzhiyun skb = dev_alloc_skb(local->tx_headroom + beacon->head_len +
4875*4882a593Smuzhiyun local->hw.extra_beacon_tailroom);
4876*4882a593Smuzhiyun if (!skb)
4877*4882a593Smuzhiyun goto out;
4878*4882a593Smuzhiyun skb_reserve(skb, local->tx_headroom);
4879*4882a593Smuzhiyun skb_put_data(skb, beacon->head, beacon->head_len);
4880*4882a593Smuzhiyun
4881*4882a593Smuzhiyun hdr = (struct ieee80211_hdr *) skb->data;
4882*4882a593Smuzhiyun hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
4883*4882a593Smuzhiyun IEEE80211_STYPE_BEACON);
4884*4882a593Smuzhiyun } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
4885*4882a593Smuzhiyun struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
4886*4882a593Smuzhiyun
4887*4882a593Smuzhiyun beacon = rcu_dereference(ifmsh->beacon);
4888*4882a593Smuzhiyun if (!beacon)
4889*4882a593Smuzhiyun goto out;
4890*4882a593Smuzhiyun
4891*4882a593Smuzhiyun if (beacon->cntdwn_counter_offsets[0]) {
4892*4882a593Smuzhiyun if (!is_template)
4893*4882a593Smuzhiyun /* TODO: For mesh csa_counter is in TU, so
4894*4882a593Smuzhiyun * decrementing it by one isn't correct, but
4895*4882a593Smuzhiyun * for now we leave it consistent with overall
4896*4882a593Smuzhiyun * mac80211's behavior.
4897*4882a593Smuzhiyun */
4898*4882a593Smuzhiyun __ieee80211_beacon_update_cntdwn(beacon);
4899*4882a593Smuzhiyun
4900*4882a593Smuzhiyun ieee80211_set_beacon_cntdwn(sdata, beacon);
4901*4882a593Smuzhiyun }
4902*4882a593Smuzhiyun
4903*4882a593Smuzhiyun if (ifmsh->sync_ops)
4904*4882a593Smuzhiyun ifmsh->sync_ops->adjust_tsf(sdata, beacon);
4905*4882a593Smuzhiyun
4906*4882a593Smuzhiyun skb = dev_alloc_skb(local->tx_headroom +
4907*4882a593Smuzhiyun beacon->head_len +
4908*4882a593Smuzhiyun 256 + /* TIM IE */
4909*4882a593Smuzhiyun beacon->tail_len +
4910*4882a593Smuzhiyun local->hw.extra_beacon_tailroom);
4911*4882a593Smuzhiyun if (!skb)
4912*4882a593Smuzhiyun goto out;
4913*4882a593Smuzhiyun skb_reserve(skb, local->tx_headroom);
4914*4882a593Smuzhiyun skb_put_data(skb, beacon->head, beacon->head_len);
4915*4882a593Smuzhiyun ieee80211_beacon_add_tim(sdata, &ifmsh->ps, skb, is_template);
4916*4882a593Smuzhiyun
4917*4882a593Smuzhiyun if (offs) {
4918*4882a593Smuzhiyun offs->tim_offset = beacon->head_len;
4919*4882a593Smuzhiyun offs->tim_length = skb->len - beacon->head_len;
4920*4882a593Smuzhiyun }
4921*4882a593Smuzhiyun
4922*4882a593Smuzhiyun skb_put_data(skb, beacon->tail, beacon->tail_len);
4923*4882a593Smuzhiyun } else {
4924*4882a593Smuzhiyun WARN_ON(1);
4925*4882a593Smuzhiyun goto out;
4926*4882a593Smuzhiyun }
4927*4882a593Smuzhiyun
4928*4882a593Smuzhiyun /* CSA offsets */
4929*4882a593Smuzhiyun if (offs && beacon) {
4930*4882a593Smuzhiyun int i;
4931*4882a593Smuzhiyun
4932*4882a593Smuzhiyun for (i = 0; i < IEEE80211_MAX_CNTDWN_COUNTERS_NUM; i++) {
4933*4882a593Smuzhiyun u16 csa_off = beacon->cntdwn_counter_offsets[i];
4934*4882a593Smuzhiyun
4935*4882a593Smuzhiyun if (!csa_off)
4936*4882a593Smuzhiyun continue;
4937*4882a593Smuzhiyun
4938*4882a593Smuzhiyun offs->cntdwn_counter_offs[i] = csa_off_base + csa_off;
4939*4882a593Smuzhiyun }
4940*4882a593Smuzhiyun }
4941*4882a593Smuzhiyun
4942*4882a593Smuzhiyun band = chanctx_conf->def.chan->band;
4943*4882a593Smuzhiyun
4944*4882a593Smuzhiyun info = IEEE80211_SKB_CB(skb);
4945*4882a593Smuzhiyun
4946*4882a593Smuzhiyun info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
4947*4882a593Smuzhiyun info->flags |= IEEE80211_TX_CTL_NO_ACK;
4948*4882a593Smuzhiyun info->band = band;
4949*4882a593Smuzhiyun
4950*4882a593Smuzhiyun memset(&txrc, 0, sizeof(txrc));
4951*4882a593Smuzhiyun txrc.hw = hw;
4952*4882a593Smuzhiyun txrc.sband = local->hw.wiphy->bands[band];
4953*4882a593Smuzhiyun txrc.bss_conf = &sdata->vif.bss_conf;
4954*4882a593Smuzhiyun txrc.skb = skb;
4955*4882a593Smuzhiyun txrc.reported_rate.idx = -1;
4956*4882a593Smuzhiyun if (sdata->beacon_rate_set && sdata->beacon_rateidx_mask[band])
4957*4882a593Smuzhiyun txrc.rate_idx_mask = sdata->beacon_rateidx_mask[band];
4958*4882a593Smuzhiyun else
4959*4882a593Smuzhiyun txrc.rate_idx_mask = sdata->rc_rateidx_mask[band];
4960*4882a593Smuzhiyun txrc.bss = true;
4961*4882a593Smuzhiyun rate_control_get_rate(sdata, NULL, &txrc);
4962*4882a593Smuzhiyun
4963*4882a593Smuzhiyun info->control.vif = vif;
4964*4882a593Smuzhiyun
4965*4882a593Smuzhiyun info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT |
4966*4882a593Smuzhiyun IEEE80211_TX_CTL_ASSIGN_SEQ |
4967*4882a593Smuzhiyun IEEE80211_TX_CTL_FIRST_FRAGMENT;
4968*4882a593Smuzhiyun out:
4969*4882a593Smuzhiyun rcu_read_unlock();
4970*4882a593Smuzhiyun return skb;
4971*4882a593Smuzhiyun
4972*4882a593Smuzhiyun }
4973*4882a593Smuzhiyun
4974*4882a593Smuzhiyun struct sk_buff *
ieee80211_beacon_get_template(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_mutable_offsets * offs)4975*4882a593Smuzhiyun ieee80211_beacon_get_template(struct ieee80211_hw *hw,
4976*4882a593Smuzhiyun struct ieee80211_vif *vif,
4977*4882a593Smuzhiyun struct ieee80211_mutable_offsets *offs)
4978*4882a593Smuzhiyun {
4979*4882a593Smuzhiyun return __ieee80211_beacon_get(hw, vif, offs, true);
4980*4882a593Smuzhiyun }
4981*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_beacon_get_template);
4982*4882a593Smuzhiyun
ieee80211_beacon_get_tim(struct ieee80211_hw * hw,struct ieee80211_vif * vif,u16 * tim_offset,u16 * tim_length)4983*4882a593Smuzhiyun struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
4984*4882a593Smuzhiyun struct ieee80211_vif *vif,
4985*4882a593Smuzhiyun u16 *tim_offset, u16 *tim_length)
4986*4882a593Smuzhiyun {
4987*4882a593Smuzhiyun struct ieee80211_mutable_offsets offs = {};
4988*4882a593Smuzhiyun struct sk_buff *bcn = __ieee80211_beacon_get(hw, vif, &offs, false);
4989*4882a593Smuzhiyun struct sk_buff *copy;
4990*4882a593Smuzhiyun struct ieee80211_supported_band *sband;
4991*4882a593Smuzhiyun int shift;
4992*4882a593Smuzhiyun
4993*4882a593Smuzhiyun if (!bcn)
4994*4882a593Smuzhiyun return bcn;
4995*4882a593Smuzhiyun
4996*4882a593Smuzhiyun if (tim_offset)
4997*4882a593Smuzhiyun *tim_offset = offs.tim_offset;
4998*4882a593Smuzhiyun
4999*4882a593Smuzhiyun if (tim_length)
5000*4882a593Smuzhiyun *tim_length = offs.tim_length;
5001*4882a593Smuzhiyun
5002*4882a593Smuzhiyun if (ieee80211_hw_check(hw, BEACON_TX_STATUS) ||
5003*4882a593Smuzhiyun !hw_to_local(hw)->monitors)
5004*4882a593Smuzhiyun return bcn;
5005*4882a593Smuzhiyun
5006*4882a593Smuzhiyun /* send a copy to monitor interfaces */
5007*4882a593Smuzhiyun copy = skb_copy(bcn, GFP_ATOMIC);
5008*4882a593Smuzhiyun if (!copy)
5009*4882a593Smuzhiyun return bcn;
5010*4882a593Smuzhiyun
5011*4882a593Smuzhiyun shift = ieee80211_vif_get_shift(vif);
5012*4882a593Smuzhiyun sband = ieee80211_get_sband(vif_to_sdata(vif));
5013*4882a593Smuzhiyun if (!sband)
5014*4882a593Smuzhiyun return bcn;
5015*4882a593Smuzhiyun
5016*4882a593Smuzhiyun ieee80211_tx_monitor(hw_to_local(hw), copy, sband, 1, shift, false,
5017*4882a593Smuzhiyun NULL);
5018*4882a593Smuzhiyun
5019*4882a593Smuzhiyun return bcn;
5020*4882a593Smuzhiyun }
5021*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_beacon_get_tim);
5022*4882a593Smuzhiyun
ieee80211_proberesp_get(struct ieee80211_hw * hw,struct ieee80211_vif * vif)5023*4882a593Smuzhiyun struct sk_buff *ieee80211_proberesp_get(struct ieee80211_hw *hw,
5024*4882a593Smuzhiyun struct ieee80211_vif *vif)
5025*4882a593Smuzhiyun {
5026*4882a593Smuzhiyun struct ieee80211_if_ap *ap = NULL;
5027*4882a593Smuzhiyun struct sk_buff *skb = NULL;
5028*4882a593Smuzhiyun struct probe_resp *presp = NULL;
5029*4882a593Smuzhiyun struct ieee80211_hdr *hdr;
5030*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5031*4882a593Smuzhiyun
5032*4882a593Smuzhiyun if (sdata->vif.type != NL80211_IFTYPE_AP)
5033*4882a593Smuzhiyun return NULL;
5034*4882a593Smuzhiyun
5035*4882a593Smuzhiyun rcu_read_lock();
5036*4882a593Smuzhiyun
5037*4882a593Smuzhiyun ap = &sdata->u.ap;
5038*4882a593Smuzhiyun presp = rcu_dereference(ap->probe_resp);
5039*4882a593Smuzhiyun if (!presp)
5040*4882a593Smuzhiyun goto out;
5041*4882a593Smuzhiyun
5042*4882a593Smuzhiyun skb = dev_alloc_skb(presp->len);
5043*4882a593Smuzhiyun if (!skb)
5044*4882a593Smuzhiyun goto out;
5045*4882a593Smuzhiyun
5046*4882a593Smuzhiyun skb_put_data(skb, presp->data, presp->len);
5047*4882a593Smuzhiyun
5048*4882a593Smuzhiyun hdr = (struct ieee80211_hdr *) skb->data;
5049*4882a593Smuzhiyun memset(hdr->addr1, 0, sizeof(hdr->addr1));
5050*4882a593Smuzhiyun
5051*4882a593Smuzhiyun out:
5052*4882a593Smuzhiyun rcu_read_unlock();
5053*4882a593Smuzhiyun return skb;
5054*4882a593Smuzhiyun }
5055*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_proberesp_get);
5056*4882a593Smuzhiyun
ieee80211_get_fils_discovery_tmpl(struct ieee80211_hw * hw,struct ieee80211_vif * vif)5057*4882a593Smuzhiyun struct sk_buff *ieee80211_get_fils_discovery_tmpl(struct ieee80211_hw *hw,
5058*4882a593Smuzhiyun struct ieee80211_vif *vif)
5059*4882a593Smuzhiyun {
5060*4882a593Smuzhiyun struct sk_buff *skb = NULL;
5061*4882a593Smuzhiyun struct fils_discovery_data *tmpl = NULL;
5062*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5063*4882a593Smuzhiyun
5064*4882a593Smuzhiyun if (sdata->vif.type != NL80211_IFTYPE_AP)
5065*4882a593Smuzhiyun return NULL;
5066*4882a593Smuzhiyun
5067*4882a593Smuzhiyun rcu_read_lock();
5068*4882a593Smuzhiyun tmpl = rcu_dereference(sdata->u.ap.fils_discovery);
5069*4882a593Smuzhiyun if (!tmpl) {
5070*4882a593Smuzhiyun rcu_read_unlock();
5071*4882a593Smuzhiyun return NULL;
5072*4882a593Smuzhiyun }
5073*4882a593Smuzhiyun
5074*4882a593Smuzhiyun skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom + tmpl->len);
5075*4882a593Smuzhiyun if (skb) {
5076*4882a593Smuzhiyun skb_reserve(skb, sdata->local->hw.extra_tx_headroom);
5077*4882a593Smuzhiyun skb_put_data(skb, tmpl->data, tmpl->len);
5078*4882a593Smuzhiyun }
5079*4882a593Smuzhiyun
5080*4882a593Smuzhiyun rcu_read_unlock();
5081*4882a593Smuzhiyun return skb;
5082*4882a593Smuzhiyun }
5083*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_get_fils_discovery_tmpl);
5084*4882a593Smuzhiyun
5085*4882a593Smuzhiyun struct sk_buff *
ieee80211_get_unsol_bcast_probe_resp_tmpl(struct ieee80211_hw * hw,struct ieee80211_vif * vif)5086*4882a593Smuzhiyun ieee80211_get_unsol_bcast_probe_resp_tmpl(struct ieee80211_hw *hw,
5087*4882a593Smuzhiyun struct ieee80211_vif *vif)
5088*4882a593Smuzhiyun {
5089*4882a593Smuzhiyun struct sk_buff *skb = NULL;
5090*4882a593Smuzhiyun struct unsol_bcast_probe_resp_data *tmpl = NULL;
5091*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5092*4882a593Smuzhiyun
5093*4882a593Smuzhiyun if (sdata->vif.type != NL80211_IFTYPE_AP)
5094*4882a593Smuzhiyun return NULL;
5095*4882a593Smuzhiyun
5096*4882a593Smuzhiyun rcu_read_lock();
5097*4882a593Smuzhiyun tmpl = rcu_dereference(sdata->u.ap.unsol_bcast_probe_resp);
5098*4882a593Smuzhiyun if (!tmpl) {
5099*4882a593Smuzhiyun rcu_read_unlock();
5100*4882a593Smuzhiyun return NULL;
5101*4882a593Smuzhiyun }
5102*4882a593Smuzhiyun
5103*4882a593Smuzhiyun skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom + tmpl->len);
5104*4882a593Smuzhiyun if (skb) {
5105*4882a593Smuzhiyun skb_reserve(skb, sdata->local->hw.extra_tx_headroom);
5106*4882a593Smuzhiyun skb_put_data(skb, tmpl->data, tmpl->len);
5107*4882a593Smuzhiyun }
5108*4882a593Smuzhiyun
5109*4882a593Smuzhiyun rcu_read_unlock();
5110*4882a593Smuzhiyun return skb;
5111*4882a593Smuzhiyun }
5112*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_get_unsol_bcast_probe_resp_tmpl);
5113*4882a593Smuzhiyun
ieee80211_pspoll_get(struct ieee80211_hw * hw,struct ieee80211_vif * vif)5114*4882a593Smuzhiyun struct sk_buff *ieee80211_pspoll_get(struct ieee80211_hw *hw,
5115*4882a593Smuzhiyun struct ieee80211_vif *vif)
5116*4882a593Smuzhiyun {
5117*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata;
5118*4882a593Smuzhiyun struct ieee80211_if_managed *ifmgd;
5119*4882a593Smuzhiyun struct ieee80211_pspoll *pspoll;
5120*4882a593Smuzhiyun struct ieee80211_local *local;
5121*4882a593Smuzhiyun struct sk_buff *skb;
5122*4882a593Smuzhiyun
5123*4882a593Smuzhiyun if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
5124*4882a593Smuzhiyun return NULL;
5125*4882a593Smuzhiyun
5126*4882a593Smuzhiyun sdata = vif_to_sdata(vif);
5127*4882a593Smuzhiyun ifmgd = &sdata->u.mgd;
5128*4882a593Smuzhiyun local = sdata->local;
5129*4882a593Smuzhiyun
5130*4882a593Smuzhiyun skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll));
5131*4882a593Smuzhiyun if (!skb)
5132*4882a593Smuzhiyun return NULL;
5133*4882a593Smuzhiyun
5134*4882a593Smuzhiyun skb_reserve(skb, local->hw.extra_tx_headroom);
5135*4882a593Smuzhiyun
5136*4882a593Smuzhiyun pspoll = skb_put_zero(skb, sizeof(*pspoll));
5137*4882a593Smuzhiyun pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
5138*4882a593Smuzhiyun IEEE80211_STYPE_PSPOLL);
5139*4882a593Smuzhiyun pspoll->aid = cpu_to_le16(sdata->vif.bss_conf.aid);
5140*4882a593Smuzhiyun
5141*4882a593Smuzhiyun /* aid in PS-Poll has its two MSBs each set to 1 */
5142*4882a593Smuzhiyun pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
5143*4882a593Smuzhiyun
5144*4882a593Smuzhiyun memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN);
5145*4882a593Smuzhiyun memcpy(pspoll->ta, vif->addr, ETH_ALEN);
5146*4882a593Smuzhiyun
5147*4882a593Smuzhiyun return skb;
5148*4882a593Smuzhiyun }
5149*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_pspoll_get);
5150*4882a593Smuzhiyun
ieee80211_nullfunc_get(struct ieee80211_hw * hw,struct ieee80211_vif * vif,bool qos_ok)5151*4882a593Smuzhiyun struct sk_buff *ieee80211_nullfunc_get(struct ieee80211_hw *hw,
5152*4882a593Smuzhiyun struct ieee80211_vif *vif,
5153*4882a593Smuzhiyun bool qos_ok)
5154*4882a593Smuzhiyun {
5155*4882a593Smuzhiyun struct ieee80211_hdr_3addr *nullfunc;
5156*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata;
5157*4882a593Smuzhiyun struct ieee80211_if_managed *ifmgd;
5158*4882a593Smuzhiyun struct ieee80211_local *local;
5159*4882a593Smuzhiyun struct sk_buff *skb;
5160*4882a593Smuzhiyun bool qos = false;
5161*4882a593Smuzhiyun
5162*4882a593Smuzhiyun if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
5163*4882a593Smuzhiyun return NULL;
5164*4882a593Smuzhiyun
5165*4882a593Smuzhiyun sdata = vif_to_sdata(vif);
5166*4882a593Smuzhiyun ifmgd = &sdata->u.mgd;
5167*4882a593Smuzhiyun local = sdata->local;
5168*4882a593Smuzhiyun
5169*4882a593Smuzhiyun if (qos_ok) {
5170*4882a593Smuzhiyun struct sta_info *sta;
5171*4882a593Smuzhiyun
5172*4882a593Smuzhiyun rcu_read_lock();
5173*4882a593Smuzhiyun sta = sta_info_get(sdata, ifmgd->bssid);
5174*4882a593Smuzhiyun qos = sta && sta->sta.wme;
5175*4882a593Smuzhiyun rcu_read_unlock();
5176*4882a593Smuzhiyun }
5177*4882a593Smuzhiyun
5178*4882a593Smuzhiyun skb = dev_alloc_skb(local->hw.extra_tx_headroom +
5179*4882a593Smuzhiyun sizeof(*nullfunc) + 2);
5180*4882a593Smuzhiyun if (!skb)
5181*4882a593Smuzhiyun return NULL;
5182*4882a593Smuzhiyun
5183*4882a593Smuzhiyun skb_reserve(skb, local->hw.extra_tx_headroom);
5184*4882a593Smuzhiyun
5185*4882a593Smuzhiyun nullfunc = skb_put_zero(skb, sizeof(*nullfunc));
5186*4882a593Smuzhiyun nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
5187*4882a593Smuzhiyun IEEE80211_STYPE_NULLFUNC |
5188*4882a593Smuzhiyun IEEE80211_FCTL_TODS);
5189*4882a593Smuzhiyun if (qos) {
5190*4882a593Smuzhiyun __le16 qoshdr = cpu_to_le16(7);
5191*4882a593Smuzhiyun
5192*4882a593Smuzhiyun BUILD_BUG_ON((IEEE80211_STYPE_QOS_NULLFUNC |
5193*4882a593Smuzhiyun IEEE80211_STYPE_NULLFUNC) !=
5194*4882a593Smuzhiyun IEEE80211_STYPE_QOS_NULLFUNC);
5195*4882a593Smuzhiyun nullfunc->frame_control |=
5196*4882a593Smuzhiyun cpu_to_le16(IEEE80211_STYPE_QOS_NULLFUNC);
5197*4882a593Smuzhiyun skb->priority = 7;
5198*4882a593Smuzhiyun skb_set_queue_mapping(skb, IEEE80211_AC_VO);
5199*4882a593Smuzhiyun skb_put_data(skb, &qoshdr, sizeof(qoshdr));
5200*4882a593Smuzhiyun }
5201*4882a593Smuzhiyun
5202*4882a593Smuzhiyun memcpy(nullfunc->addr1, ifmgd->bssid, ETH_ALEN);
5203*4882a593Smuzhiyun memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
5204*4882a593Smuzhiyun memcpy(nullfunc->addr3, ifmgd->bssid, ETH_ALEN);
5205*4882a593Smuzhiyun
5206*4882a593Smuzhiyun return skb;
5207*4882a593Smuzhiyun }
5208*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_nullfunc_get);
5209*4882a593Smuzhiyun
ieee80211_probereq_get(struct ieee80211_hw * hw,const u8 * src_addr,const u8 * ssid,size_t ssid_len,size_t tailroom)5210*4882a593Smuzhiyun struct sk_buff *ieee80211_probereq_get(struct ieee80211_hw *hw,
5211*4882a593Smuzhiyun const u8 *src_addr,
5212*4882a593Smuzhiyun const u8 *ssid, size_t ssid_len,
5213*4882a593Smuzhiyun size_t tailroom)
5214*4882a593Smuzhiyun {
5215*4882a593Smuzhiyun struct ieee80211_local *local = hw_to_local(hw);
5216*4882a593Smuzhiyun struct ieee80211_hdr_3addr *hdr;
5217*4882a593Smuzhiyun struct sk_buff *skb;
5218*4882a593Smuzhiyun size_t ie_ssid_len;
5219*4882a593Smuzhiyun u8 *pos;
5220*4882a593Smuzhiyun
5221*4882a593Smuzhiyun ie_ssid_len = 2 + ssid_len;
5222*4882a593Smuzhiyun
5223*4882a593Smuzhiyun skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*hdr) +
5224*4882a593Smuzhiyun ie_ssid_len + tailroom);
5225*4882a593Smuzhiyun if (!skb)
5226*4882a593Smuzhiyun return NULL;
5227*4882a593Smuzhiyun
5228*4882a593Smuzhiyun skb_reserve(skb, local->hw.extra_tx_headroom);
5229*4882a593Smuzhiyun
5230*4882a593Smuzhiyun hdr = skb_put_zero(skb, sizeof(*hdr));
5231*4882a593Smuzhiyun hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
5232*4882a593Smuzhiyun IEEE80211_STYPE_PROBE_REQ);
5233*4882a593Smuzhiyun eth_broadcast_addr(hdr->addr1);
5234*4882a593Smuzhiyun memcpy(hdr->addr2, src_addr, ETH_ALEN);
5235*4882a593Smuzhiyun eth_broadcast_addr(hdr->addr3);
5236*4882a593Smuzhiyun
5237*4882a593Smuzhiyun pos = skb_put(skb, ie_ssid_len);
5238*4882a593Smuzhiyun *pos++ = WLAN_EID_SSID;
5239*4882a593Smuzhiyun *pos++ = ssid_len;
5240*4882a593Smuzhiyun if (ssid_len)
5241*4882a593Smuzhiyun memcpy(pos, ssid, ssid_len);
5242*4882a593Smuzhiyun pos += ssid_len;
5243*4882a593Smuzhiyun
5244*4882a593Smuzhiyun return skb;
5245*4882a593Smuzhiyun }
5246*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_probereq_get);
5247*4882a593Smuzhiyun
ieee80211_rts_get(struct ieee80211_hw * hw,struct ieee80211_vif * vif,const void * frame,size_t frame_len,const struct ieee80211_tx_info * frame_txctl,struct ieee80211_rts * rts)5248*4882a593Smuzhiyun void ieee80211_rts_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5249*4882a593Smuzhiyun const void *frame, size_t frame_len,
5250*4882a593Smuzhiyun const struct ieee80211_tx_info *frame_txctl,
5251*4882a593Smuzhiyun struct ieee80211_rts *rts)
5252*4882a593Smuzhiyun {
5253*4882a593Smuzhiyun const struct ieee80211_hdr *hdr = frame;
5254*4882a593Smuzhiyun
5255*4882a593Smuzhiyun rts->frame_control =
5256*4882a593Smuzhiyun cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
5257*4882a593Smuzhiyun rts->duration = ieee80211_rts_duration(hw, vif, frame_len,
5258*4882a593Smuzhiyun frame_txctl);
5259*4882a593Smuzhiyun memcpy(rts->ra, hdr->addr1, sizeof(rts->ra));
5260*4882a593Smuzhiyun memcpy(rts->ta, hdr->addr2, sizeof(rts->ta));
5261*4882a593Smuzhiyun }
5262*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_rts_get);
5263*4882a593Smuzhiyun
ieee80211_ctstoself_get(struct ieee80211_hw * hw,struct ieee80211_vif * vif,const void * frame,size_t frame_len,const struct ieee80211_tx_info * frame_txctl,struct ieee80211_cts * cts)5264*4882a593Smuzhiyun void ieee80211_ctstoself_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5265*4882a593Smuzhiyun const void *frame, size_t frame_len,
5266*4882a593Smuzhiyun const struct ieee80211_tx_info *frame_txctl,
5267*4882a593Smuzhiyun struct ieee80211_cts *cts)
5268*4882a593Smuzhiyun {
5269*4882a593Smuzhiyun const struct ieee80211_hdr *hdr = frame;
5270*4882a593Smuzhiyun
5271*4882a593Smuzhiyun cts->frame_control =
5272*4882a593Smuzhiyun cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
5273*4882a593Smuzhiyun cts->duration = ieee80211_ctstoself_duration(hw, vif,
5274*4882a593Smuzhiyun frame_len, frame_txctl);
5275*4882a593Smuzhiyun memcpy(cts->ra, hdr->addr1, sizeof(cts->ra));
5276*4882a593Smuzhiyun }
5277*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_ctstoself_get);
5278*4882a593Smuzhiyun
5279*4882a593Smuzhiyun struct sk_buff *
ieee80211_get_buffered_bc(struct ieee80211_hw * hw,struct ieee80211_vif * vif)5280*4882a593Smuzhiyun ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
5281*4882a593Smuzhiyun struct ieee80211_vif *vif)
5282*4882a593Smuzhiyun {
5283*4882a593Smuzhiyun struct ieee80211_local *local = hw_to_local(hw);
5284*4882a593Smuzhiyun struct sk_buff *skb = NULL;
5285*4882a593Smuzhiyun struct ieee80211_tx_data tx;
5286*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata;
5287*4882a593Smuzhiyun struct ps_data *ps;
5288*4882a593Smuzhiyun struct ieee80211_tx_info *info;
5289*4882a593Smuzhiyun struct ieee80211_chanctx_conf *chanctx_conf;
5290*4882a593Smuzhiyun
5291*4882a593Smuzhiyun sdata = vif_to_sdata(vif);
5292*4882a593Smuzhiyun
5293*4882a593Smuzhiyun rcu_read_lock();
5294*4882a593Smuzhiyun chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
5295*4882a593Smuzhiyun
5296*4882a593Smuzhiyun if (!chanctx_conf)
5297*4882a593Smuzhiyun goto out;
5298*4882a593Smuzhiyun
5299*4882a593Smuzhiyun if (sdata->vif.type == NL80211_IFTYPE_AP) {
5300*4882a593Smuzhiyun struct beacon_data *beacon =
5301*4882a593Smuzhiyun rcu_dereference(sdata->u.ap.beacon);
5302*4882a593Smuzhiyun
5303*4882a593Smuzhiyun if (!beacon || !beacon->head)
5304*4882a593Smuzhiyun goto out;
5305*4882a593Smuzhiyun
5306*4882a593Smuzhiyun ps = &sdata->u.ap.ps;
5307*4882a593Smuzhiyun } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
5308*4882a593Smuzhiyun ps = &sdata->u.mesh.ps;
5309*4882a593Smuzhiyun } else {
5310*4882a593Smuzhiyun goto out;
5311*4882a593Smuzhiyun }
5312*4882a593Smuzhiyun
5313*4882a593Smuzhiyun if (ps->dtim_count != 0 || !ps->dtim_bc_mc)
5314*4882a593Smuzhiyun goto out; /* send buffered bc/mc only after DTIM beacon */
5315*4882a593Smuzhiyun
5316*4882a593Smuzhiyun while (1) {
5317*4882a593Smuzhiyun skb = skb_dequeue(&ps->bc_buf);
5318*4882a593Smuzhiyun if (!skb)
5319*4882a593Smuzhiyun goto out;
5320*4882a593Smuzhiyun local->total_ps_buffered--;
5321*4882a593Smuzhiyun
5322*4882a593Smuzhiyun if (!skb_queue_empty(&ps->bc_buf) && skb->len >= 2) {
5323*4882a593Smuzhiyun struct ieee80211_hdr *hdr =
5324*4882a593Smuzhiyun (struct ieee80211_hdr *) skb->data;
5325*4882a593Smuzhiyun /* more buffered multicast/broadcast frames ==> set
5326*4882a593Smuzhiyun * MoreData flag in IEEE 802.11 header to inform PS
5327*4882a593Smuzhiyun * STAs */
5328*4882a593Smuzhiyun hdr->frame_control |=
5329*4882a593Smuzhiyun cpu_to_le16(IEEE80211_FCTL_MOREDATA);
5330*4882a593Smuzhiyun }
5331*4882a593Smuzhiyun
5332*4882a593Smuzhiyun if (sdata->vif.type == NL80211_IFTYPE_AP)
5333*4882a593Smuzhiyun sdata = IEEE80211_DEV_TO_SUB_IF(skb->dev);
5334*4882a593Smuzhiyun if (!ieee80211_tx_prepare(sdata, &tx, NULL, skb))
5335*4882a593Smuzhiyun break;
5336*4882a593Smuzhiyun ieee80211_free_txskb(hw, skb);
5337*4882a593Smuzhiyun }
5338*4882a593Smuzhiyun
5339*4882a593Smuzhiyun info = IEEE80211_SKB_CB(skb);
5340*4882a593Smuzhiyun
5341*4882a593Smuzhiyun tx.flags |= IEEE80211_TX_PS_BUFFERED;
5342*4882a593Smuzhiyun info->band = chanctx_conf->def.chan->band;
5343*4882a593Smuzhiyun
5344*4882a593Smuzhiyun if (invoke_tx_handlers(&tx))
5345*4882a593Smuzhiyun skb = NULL;
5346*4882a593Smuzhiyun out:
5347*4882a593Smuzhiyun rcu_read_unlock();
5348*4882a593Smuzhiyun
5349*4882a593Smuzhiyun return skb;
5350*4882a593Smuzhiyun }
5351*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_get_buffered_bc);
5352*4882a593Smuzhiyun
ieee80211_reserve_tid(struct ieee80211_sta * pubsta,u8 tid)5353*4882a593Smuzhiyun int ieee80211_reserve_tid(struct ieee80211_sta *pubsta, u8 tid)
5354*4882a593Smuzhiyun {
5355*4882a593Smuzhiyun struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
5356*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = sta->sdata;
5357*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
5358*4882a593Smuzhiyun int ret;
5359*4882a593Smuzhiyun u32 queues;
5360*4882a593Smuzhiyun
5361*4882a593Smuzhiyun lockdep_assert_held(&local->sta_mtx);
5362*4882a593Smuzhiyun
5363*4882a593Smuzhiyun /* only some cases are supported right now */
5364*4882a593Smuzhiyun switch (sdata->vif.type) {
5365*4882a593Smuzhiyun case NL80211_IFTYPE_STATION:
5366*4882a593Smuzhiyun case NL80211_IFTYPE_AP:
5367*4882a593Smuzhiyun case NL80211_IFTYPE_AP_VLAN:
5368*4882a593Smuzhiyun break;
5369*4882a593Smuzhiyun default:
5370*4882a593Smuzhiyun WARN_ON(1);
5371*4882a593Smuzhiyun return -EINVAL;
5372*4882a593Smuzhiyun }
5373*4882a593Smuzhiyun
5374*4882a593Smuzhiyun if (WARN_ON(tid >= IEEE80211_NUM_UPS))
5375*4882a593Smuzhiyun return -EINVAL;
5376*4882a593Smuzhiyun
5377*4882a593Smuzhiyun if (sta->reserved_tid == tid) {
5378*4882a593Smuzhiyun ret = 0;
5379*4882a593Smuzhiyun goto out;
5380*4882a593Smuzhiyun }
5381*4882a593Smuzhiyun
5382*4882a593Smuzhiyun if (sta->reserved_tid != IEEE80211_TID_UNRESERVED) {
5383*4882a593Smuzhiyun sdata_err(sdata, "TID reservation already active\n");
5384*4882a593Smuzhiyun ret = -EALREADY;
5385*4882a593Smuzhiyun goto out;
5386*4882a593Smuzhiyun }
5387*4882a593Smuzhiyun
5388*4882a593Smuzhiyun ieee80211_stop_vif_queues(sdata->local, sdata,
5389*4882a593Smuzhiyun IEEE80211_QUEUE_STOP_REASON_RESERVE_TID);
5390*4882a593Smuzhiyun
5391*4882a593Smuzhiyun synchronize_net();
5392*4882a593Smuzhiyun
5393*4882a593Smuzhiyun /* Tear down BA sessions so we stop aggregating on this TID */
5394*4882a593Smuzhiyun if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION)) {
5395*4882a593Smuzhiyun set_sta_flag(sta, WLAN_STA_BLOCK_BA);
5396*4882a593Smuzhiyun __ieee80211_stop_tx_ba_session(sta, tid,
5397*4882a593Smuzhiyun AGG_STOP_LOCAL_REQUEST);
5398*4882a593Smuzhiyun }
5399*4882a593Smuzhiyun
5400*4882a593Smuzhiyun queues = BIT(sdata->vif.hw_queue[ieee802_1d_to_ac[tid]]);
5401*4882a593Smuzhiyun __ieee80211_flush_queues(local, sdata, queues, false);
5402*4882a593Smuzhiyun
5403*4882a593Smuzhiyun sta->reserved_tid = tid;
5404*4882a593Smuzhiyun
5405*4882a593Smuzhiyun ieee80211_wake_vif_queues(local, sdata,
5406*4882a593Smuzhiyun IEEE80211_QUEUE_STOP_REASON_RESERVE_TID);
5407*4882a593Smuzhiyun
5408*4882a593Smuzhiyun if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION))
5409*4882a593Smuzhiyun clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
5410*4882a593Smuzhiyun
5411*4882a593Smuzhiyun ret = 0;
5412*4882a593Smuzhiyun out:
5413*4882a593Smuzhiyun return ret;
5414*4882a593Smuzhiyun }
5415*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_reserve_tid);
5416*4882a593Smuzhiyun
ieee80211_unreserve_tid(struct ieee80211_sta * pubsta,u8 tid)5417*4882a593Smuzhiyun void ieee80211_unreserve_tid(struct ieee80211_sta *pubsta, u8 tid)
5418*4882a593Smuzhiyun {
5419*4882a593Smuzhiyun struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
5420*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = sta->sdata;
5421*4882a593Smuzhiyun
5422*4882a593Smuzhiyun lockdep_assert_held(&sdata->local->sta_mtx);
5423*4882a593Smuzhiyun
5424*4882a593Smuzhiyun /* only some cases are supported right now */
5425*4882a593Smuzhiyun switch (sdata->vif.type) {
5426*4882a593Smuzhiyun case NL80211_IFTYPE_STATION:
5427*4882a593Smuzhiyun case NL80211_IFTYPE_AP:
5428*4882a593Smuzhiyun case NL80211_IFTYPE_AP_VLAN:
5429*4882a593Smuzhiyun break;
5430*4882a593Smuzhiyun default:
5431*4882a593Smuzhiyun WARN_ON(1);
5432*4882a593Smuzhiyun return;
5433*4882a593Smuzhiyun }
5434*4882a593Smuzhiyun
5435*4882a593Smuzhiyun if (tid != sta->reserved_tid) {
5436*4882a593Smuzhiyun sdata_err(sdata, "TID to unreserve (%d) isn't reserved\n", tid);
5437*4882a593Smuzhiyun return;
5438*4882a593Smuzhiyun }
5439*4882a593Smuzhiyun
5440*4882a593Smuzhiyun sta->reserved_tid = IEEE80211_TID_UNRESERVED;
5441*4882a593Smuzhiyun }
5442*4882a593Smuzhiyun EXPORT_SYMBOL(ieee80211_unreserve_tid);
5443*4882a593Smuzhiyun
__ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data * sdata,struct sk_buff * skb,int tid,enum nl80211_band band)5444*4882a593Smuzhiyun void __ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata,
5445*4882a593Smuzhiyun struct sk_buff *skb, int tid,
5446*4882a593Smuzhiyun enum nl80211_band band)
5447*4882a593Smuzhiyun {
5448*4882a593Smuzhiyun int ac = ieee80211_ac_from_tid(tid);
5449*4882a593Smuzhiyun
5450*4882a593Smuzhiyun skb_reset_mac_header(skb);
5451*4882a593Smuzhiyun skb_set_queue_mapping(skb, ac);
5452*4882a593Smuzhiyun skb->priority = tid;
5453*4882a593Smuzhiyun
5454*4882a593Smuzhiyun skb->dev = sdata->dev;
5455*4882a593Smuzhiyun
5456*4882a593Smuzhiyun /*
5457*4882a593Smuzhiyun * The other path calling ieee80211_xmit is from the tasklet,
5458*4882a593Smuzhiyun * and while we can handle concurrent transmissions locking
5459*4882a593Smuzhiyun * requirements are that we do not come into tx with bhs on.
5460*4882a593Smuzhiyun */
5461*4882a593Smuzhiyun local_bh_disable();
5462*4882a593Smuzhiyun IEEE80211_SKB_CB(skb)->band = band;
5463*4882a593Smuzhiyun ieee80211_xmit(sdata, NULL, skb);
5464*4882a593Smuzhiyun local_bh_enable();
5465*4882a593Smuzhiyun }
5466*4882a593Smuzhiyun
ieee80211_tx_control_port(struct wiphy * wiphy,struct net_device * dev,const u8 * buf,size_t len,const u8 * dest,__be16 proto,bool unencrypted,u64 * cookie)5467*4882a593Smuzhiyun int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev,
5468*4882a593Smuzhiyun const u8 *buf, size_t len,
5469*4882a593Smuzhiyun const u8 *dest, __be16 proto, bool unencrypted,
5470*4882a593Smuzhiyun u64 *cookie)
5471*4882a593Smuzhiyun {
5472*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5473*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
5474*4882a593Smuzhiyun struct sk_buff *skb;
5475*4882a593Smuzhiyun struct ethhdr *ehdr;
5476*4882a593Smuzhiyun u32 ctrl_flags = 0;
5477*4882a593Smuzhiyun u32 flags = 0;
5478*4882a593Smuzhiyun
5479*4882a593Smuzhiyun /* Only accept CONTROL_PORT_PROTOCOL configured in CONNECT/ASSOCIATE
5480*4882a593Smuzhiyun * or Pre-Authentication
5481*4882a593Smuzhiyun */
5482*4882a593Smuzhiyun if (proto != sdata->control_port_protocol &&
5483*4882a593Smuzhiyun proto != cpu_to_be16(ETH_P_PREAUTH))
5484*4882a593Smuzhiyun return -EINVAL;
5485*4882a593Smuzhiyun
5486*4882a593Smuzhiyun if (proto == sdata->control_port_protocol)
5487*4882a593Smuzhiyun ctrl_flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO |
5488*4882a593Smuzhiyun IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP;
5489*4882a593Smuzhiyun
5490*4882a593Smuzhiyun if (unencrypted)
5491*4882a593Smuzhiyun flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
5492*4882a593Smuzhiyun
5493*4882a593Smuzhiyun if (cookie)
5494*4882a593Smuzhiyun ctrl_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
5495*4882a593Smuzhiyun
5496*4882a593Smuzhiyun flags |= IEEE80211_TX_INTFL_NL80211_FRAME_TX |
5497*4882a593Smuzhiyun IEEE80211_TX_CTL_INJECTED;
5498*4882a593Smuzhiyun
5499*4882a593Smuzhiyun skb = dev_alloc_skb(local->hw.extra_tx_headroom +
5500*4882a593Smuzhiyun sizeof(struct ethhdr) + len);
5501*4882a593Smuzhiyun if (!skb)
5502*4882a593Smuzhiyun return -ENOMEM;
5503*4882a593Smuzhiyun
5504*4882a593Smuzhiyun skb_reserve(skb, local->hw.extra_tx_headroom + sizeof(struct ethhdr));
5505*4882a593Smuzhiyun
5506*4882a593Smuzhiyun skb_put_data(skb, buf, len);
5507*4882a593Smuzhiyun
5508*4882a593Smuzhiyun ehdr = skb_push(skb, sizeof(struct ethhdr));
5509*4882a593Smuzhiyun memcpy(ehdr->h_dest, dest, ETH_ALEN);
5510*4882a593Smuzhiyun memcpy(ehdr->h_source, sdata->vif.addr, ETH_ALEN);
5511*4882a593Smuzhiyun ehdr->h_proto = proto;
5512*4882a593Smuzhiyun
5513*4882a593Smuzhiyun skb->dev = dev;
5514*4882a593Smuzhiyun skb->protocol = htons(ETH_P_802_3);
5515*4882a593Smuzhiyun skb_reset_network_header(skb);
5516*4882a593Smuzhiyun skb_reset_mac_header(skb);
5517*4882a593Smuzhiyun
5518*4882a593Smuzhiyun /* mutex lock is only needed for incrementing the cookie counter */
5519*4882a593Smuzhiyun mutex_lock(&local->mtx);
5520*4882a593Smuzhiyun
5521*4882a593Smuzhiyun local_bh_disable();
5522*4882a593Smuzhiyun __ieee80211_subif_start_xmit(skb, skb->dev, flags, ctrl_flags, cookie);
5523*4882a593Smuzhiyun local_bh_enable();
5524*4882a593Smuzhiyun
5525*4882a593Smuzhiyun mutex_unlock(&local->mtx);
5526*4882a593Smuzhiyun
5527*4882a593Smuzhiyun return 0;
5528*4882a593Smuzhiyun }
5529*4882a593Smuzhiyun
ieee80211_probe_mesh_link(struct wiphy * wiphy,struct net_device * dev,const u8 * buf,size_t len)5530*4882a593Smuzhiyun int ieee80211_probe_mesh_link(struct wiphy *wiphy, struct net_device *dev,
5531*4882a593Smuzhiyun const u8 *buf, size_t len)
5532*4882a593Smuzhiyun {
5533*4882a593Smuzhiyun struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5534*4882a593Smuzhiyun struct ieee80211_local *local = sdata->local;
5535*4882a593Smuzhiyun struct sk_buff *skb;
5536*4882a593Smuzhiyun
5537*4882a593Smuzhiyun skb = dev_alloc_skb(local->hw.extra_tx_headroom + len +
5538*4882a593Smuzhiyun 30 + /* header size */
5539*4882a593Smuzhiyun 18); /* 11s header size */
5540*4882a593Smuzhiyun if (!skb)
5541*4882a593Smuzhiyun return -ENOMEM;
5542*4882a593Smuzhiyun
5543*4882a593Smuzhiyun skb_reserve(skb, local->hw.extra_tx_headroom);
5544*4882a593Smuzhiyun skb_put_data(skb, buf, len);
5545*4882a593Smuzhiyun
5546*4882a593Smuzhiyun skb->dev = dev;
5547*4882a593Smuzhiyun skb->protocol = htons(ETH_P_802_3);
5548*4882a593Smuzhiyun skb_reset_network_header(skb);
5549*4882a593Smuzhiyun skb_reset_mac_header(skb);
5550*4882a593Smuzhiyun
5551*4882a593Smuzhiyun local_bh_disable();
5552*4882a593Smuzhiyun __ieee80211_subif_start_xmit(skb, skb->dev, 0,
5553*4882a593Smuzhiyun IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP,
5554*4882a593Smuzhiyun NULL);
5555*4882a593Smuzhiyun local_bh_enable();
5556*4882a593Smuzhiyun
5557*4882a593Smuzhiyun return 0;
5558*4882a593Smuzhiyun }
5559