blob: 1d8343fca6d4f632f3ed353adb77e89929220892 [file] [log] [blame]
Johannes Berge2ebc742007-07-27 15:43:22 +02001/*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
5 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
Johannes Bergd98ad832014-09-03 15:24:57 +03006 * Copyright 2013-2014 Intel Mobile Communications GmbH
Johannes Berge2ebc742007-07-27 15:43:22 +02007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 *
13 * Transmit and frame generation functions.
14 */
15
16#include <linux/kernel.h>
17#include <linux/slab.h>
18#include <linux/skbuff.h>
19#include <linux/etherdevice.h>
20#include <linux/bitmap.h>
Johannes Bergd4e46a32007-09-14 11:10:24 -040021#include <linux/rcupdate.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040022#include <linux/export.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070023#include <net/net_namespace.h>
Johannes Berge2ebc742007-07-27 15:43:22 +020024#include <net/ieee80211_radiotap.h>
25#include <net/cfg80211.h>
26#include <net/mac80211.h>
27#include <asm/unaligned.h>
Michal Kaziorfa962b92016-05-19 10:37:49 +020028#include <net/fq_impl.h>
Johannes Berge2ebc742007-07-27 15:43:22 +020029
30#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020031#include "driver-ops.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040032#include "led.h"
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +010033#include "mesh.h"
Johannes Berge2ebc742007-07-27 15:43:22 +020034#include "wep.h"
35#include "wpa.h"
36#include "wme.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040037#include "rate.h"
Johannes Berge2ebc742007-07-27 15:43:22 +020038
Johannes Berge2ebc742007-07-27 15:43:22 +020039/* misc utils */
40
Johannes Berg5a490512015-04-22 17:10:38 +020041static inline void ieee80211_tx_stats(struct net_device *dev, u32 len)
42{
43 struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
44
45 u64_stats_update_begin(&tstats->syncp);
46 tstats->tx_packets++;
47 tstats->tx_bytes += len;
48 u64_stats_update_end(&tstats->syncp);
49}
50
Johannes Berg252b86c2011-11-16 15:28:55 +010051static __le16 ieee80211_duration(struct ieee80211_tx_data *tx,
52 struct sk_buff *skb, int group_addr,
Johannes Berg03f93c32008-06-25 14:36:27 +030053 int next_frag_len)
Johannes Berge2ebc742007-07-27 15:43:22 +020054{
Simon Wunderlich2103dec2013-07-08 16:55:53 +020055 int rate, mrate, erp, dur, i, shift = 0;
Johannes Berg2e92e6f2008-05-15 12:55:27 +020056 struct ieee80211_rate *txrate;
Johannes Berge2ebc742007-07-27 15:43:22 +020057 struct ieee80211_local *local = tx->local;
Johannes Berg8318d782008-01-24 19:38:38 +010058 struct ieee80211_supported_band *sband;
Harvey Harrison358c8d92008-07-15 18:44:13 -070059 struct ieee80211_hdr *hdr;
Johannes Berg252b86c2011-11-16 15:28:55 +010060 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Simon Wunderlich2103dec2013-07-08 16:55:53 +020061 struct ieee80211_chanctx_conf *chanctx_conf;
62 u32 rate_flags = 0;
63
64 rcu_read_lock();
65 chanctx_conf = rcu_dereference(tx->sdata->vif.chanctx_conf);
66 if (chanctx_conf) {
67 shift = ieee80211_chandef_get_shift(&chanctx_conf->def);
68 rate_flags = ieee80211_chandef_rate_flags(&chanctx_conf->def);
69 }
70 rcu_read_unlock();
Johannes Berge6a98542008-10-21 12:40:02 +020071
72 /* assume HW handles this */
Felix Fietkau336004e2014-11-21 23:29:14 +010073 if (tx->rate.flags & (IEEE80211_TX_RC_MCS | IEEE80211_TX_RC_VHT_MCS))
Johannes Berge6a98542008-10-21 12:40:02 +020074 return 0;
75
76 /* uh huh? */
Felix Fietkau0d528d82013-04-22 16:14:41 +020077 if (WARN_ON_ONCE(tx->rate.idx < 0))
Johannes Berge6a98542008-10-21 12:40:02 +020078 return 0;
Johannes Berge2ebc742007-07-27 15:43:22 +020079
Johannes Berg2d565772012-07-23 15:12:51 +020080 sband = local->hw.wiphy->bands[info->band];
Felix Fietkau0d528d82013-04-22 16:14:41 +020081 txrate = &sband->bitrates[tx->rate.idx];
Johannes Berg8318d782008-01-24 19:38:38 +010082
Johannes Berge6a98542008-10-21 12:40:02 +020083 erp = txrate->flags & IEEE80211_RATE_ERP_G;
Johannes Berge2ebc742007-07-27 15:43:22 +020084
85 /*
86 * data and mgmt (except PS Poll):
87 * - during CFP: 32768
88 * - during contention period:
89 * if addr1 is group address: 0
90 * if more fragments = 0 and addr1 is individual address: time to
91 * transmit one ACK plus SIFS
92 * if more fragments = 1 and addr1 is individual address: time to
93 * transmit next fragment plus 2 x ACK plus 3 x SIFS
94 *
95 * IEEE 802.11, 9.6:
96 * - control response frame (CTS or ACK) shall be transmitted using the
97 * same rate as the immediately previous frame in the frame exchange
98 * sequence, if this rate belongs to the PHY mandatory rates, or else
99 * at the highest possible rate belonging to the PHY rates in the
100 * BSSBasicRateSet
101 */
Johannes Berg252b86c2011-11-16 15:28:55 +0100102 hdr = (struct ieee80211_hdr *)skb->data;
Harvey Harrison358c8d92008-07-15 18:44:13 -0700103 if (ieee80211_is_ctl(hdr->frame_control)) {
Johannes Berge2ebc742007-07-27 15:43:22 +0200104 /* TODO: These control frames are not currently sent by
Johannes Bergccd7b362008-09-11 00:01:56 +0200105 * mac80211, but should they be implemented, this function
Johannes Berge2ebc742007-07-27 15:43:22 +0200106 * needs to be updated to support duration field calculation.
107 *
108 * RTS: time needed to transmit pending data/mgmt frame plus
109 * one CTS frame plus one ACK frame plus 3 x SIFS
110 * CTS: duration of immediately previous RTS minus time
111 * required to transmit CTS and its SIFS
112 * ACK: 0 if immediately previous directed data/mgmt had
113 * more=0, with more=1 duration in ACK frame is duration
114 * from previous frame minus time needed to transmit ACK
115 * and its SIFS
116 * PS Poll: BIT(15) | BIT(14) | aid
117 */
118 return 0;
119 }
120
121 /* data/mgmt */
122 if (0 /* FIX: data/mgmt during CFP */)
Johannes Berg03f93c32008-06-25 14:36:27 +0300123 return cpu_to_le16(32768);
Johannes Berge2ebc742007-07-27 15:43:22 +0200124
125 if (group_addr) /* Group address as the destination - no ACK */
126 return 0;
127
128 /* Individual destination address:
129 * IEEE 802.11, Ch. 9.6 (after IEEE 802.11g changes)
130 * CTS and ACK frames shall be transmitted using the highest rate in
131 * basic rate set that is less than or equal to the rate of the
132 * immediately previous frame and that is using the same modulation
133 * (CCK or OFDM). If no basic rate set matches with these requirements,
134 * the highest mandatory rate of the PHY that is less than or equal to
135 * the rate of the previous frame is used.
136 * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps
137 */
138 rate = -1;
Johannes Berg8318d782008-01-24 19:38:38 +0100139 /* use lowest available if everything fails */
140 mrate = sband->bitrates[0].bitrate;
141 for (i = 0; i < sband->n_bitrates; i++) {
142 struct ieee80211_rate *r = &sband->bitrates[i];
143
144 if (r->bitrate > txrate->bitrate)
Johannes Berge2ebc742007-07-27 15:43:22 +0200145 break;
146
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200147 if ((rate_flags & r->flags) != rate_flags)
148 continue;
149
Johannes Bergbda39332008-10-11 01:51:51 +0200150 if (tx->sdata->vif.bss_conf.basic_rates & BIT(i))
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200151 rate = DIV_ROUND_UP(r->bitrate, 1 << shift);
Johannes Berge2ebc742007-07-27 15:43:22 +0200152
Johannes Berg8318d782008-01-24 19:38:38 +0100153 switch (sband->band) {
Johannes Berg57fbcce2016-04-12 15:56:15 +0200154 case NL80211_BAND_2GHZ: {
Johannes Berg8318d782008-01-24 19:38:38 +0100155 u32 flag;
156 if (tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
157 flag = IEEE80211_RATE_MANDATORY_G;
158 else
159 flag = IEEE80211_RATE_MANDATORY_B;
160 if (r->flags & flag)
161 mrate = r->bitrate;
162 break;
163 }
Johannes Berg57fbcce2016-04-12 15:56:15 +0200164 case NL80211_BAND_5GHZ:
Johannes Berg8318d782008-01-24 19:38:38 +0100165 if (r->flags & IEEE80211_RATE_MANDATORY_A)
166 mrate = r->bitrate;
167 break;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200168 case NL80211_BAND_60GHZ:
Vladimir Kondratiev3a0c52a2012-07-02 09:32:32 +0300169 /* TODO, for now fall through */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200170 case NUM_NL80211_BANDS:
Johannes Berg8318d782008-01-24 19:38:38 +0100171 WARN_ON(1);
172 break;
173 }
Johannes Berge2ebc742007-07-27 15:43:22 +0200174 }
175 if (rate == -1) {
176 /* No matching basic rate found; use highest suitable mandatory
177 * PHY rate */
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200178 rate = DIV_ROUND_UP(mrate, 1 << shift);
Johannes Berge2ebc742007-07-27 15:43:22 +0200179 }
180
Simon Wunderlich6674f212011-11-21 21:34:30 +0100181 /* Don't calculate ACKs for QoS Frames with NoAck Policy set */
182 if (ieee80211_is_data_qos(hdr->frame_control) &&
Claudio Pisac26a0e12012-05-28 13:06:25 +0100183 *(ieee80211_get_qos_ctl(hdr)) & IEEE80211_QOS_CTL_ACK_POLICY_NOACK)
Simon Wunderlich6674f212011-11-21 21:34:30 +0100184 dur = 0;
185 else
186 /* Time needed to transmit ACK
187 * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up
188 * to closest integer */
Michal Kazior4ee73f32012-04-11 08:47:56 +0200189 dur = ieee80211_frame_duration(sband->band, 10, rate, erp,
Simon Wunderlich438b61b2013-07-08 16:55:51 +0200190 tx->sdata->vif.bss_conf.use_short_preamble,
191 shift);
Johannes Berge2ebc742007-07-27 15:43:22 +0200192
193 if (next_frag_len) {
194 /* Frame is fragmented: duration increases with time needed to
195 * transmit next fragment plus ACK and 2 x SIFS. */
196 dur *= 2; /* ACK + SIFS */
197 /* next fragment */
Michal Kazior4ee73f32012-04-11 08:47:56 +0200198 dur += ieee80211_frame_duration(sband->band, next_frag_len,
Johannes Berg8318d782008-01-24 19:38:38 +0100199 txrate->bitrate, erp,
Simon Wunderlich438b61b2013-07-08 16:55:51 +0200200 tx->sdata->vif.bss_conf.use_short_preamble,
201 shift);
Johannes Berge2ebc742007-07-27 15:43:22 +0200202 }
203
Johannes Berg03f93c32008-06-25 14:36:27 +0300204 return cpu_to_le16(dur);
Johannes Berge2ebc742007-07-27 15:43:22 +0200205}
206
Johannes Berge2ebc742007-07-27 15:43:22 +0200207/* tx handlers */
Kalle Valo5c1b98a2010-01-12 10:42:46 +0200208static ieee80211_tx_result debug_noinline
209ieee80211_tx_h_dynamic_ps(struct ieee80211_tx_data *tx)
210{
211 struct ieee80211_local *local = tx->local;
Kalle Valo0c742112010-01-12 10:42:53 +0200212 struct ieee80211_if_managed *ifmgd;
Kalle Valo5c1b98a2010-01-12 10:42:46 +0200213
214 /* driver doesn't support power save */
Johannes Berg30686bf2015-06-02 21:39:54 +0200215 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
Kalle Valo5c1b98a2010-01-12 10:42:46 +0200216 return TX_CONTINUE;
217
218 /* hardware does dynamic power save */
Johannes Berg30686bf2015-06-02 21:39:54 +0200219 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
Kalle Valo5c1b98a2010-01-12 10:42:46 +0200220 return TX_CONTINUE;
221
222 /* dynamic power save disabled */
223 if (local->hw.conf.dynamic_ps_timeout <= 0)
224 return TX_CONTINUE;
225
226 /* we are scanning, don't enable power save */
227 if (local->scanning)
228 return TX_CONTINUE;
229
230 if (!local->ps_sdata)
231 return TX_CONTINUE;
232
233 /* No point if we're going to suspend */
234 if (local->quiescing)
235 return TX_CONTINUE;
236
Kalle Valo0c742112010-01-12 10:42:53 +0200237 /* dynamic ps is supported only in managed mode */
238 if (tx->sdata->vif.type != NL80211_IFTYPE_STATION)
239 return TX_CONTINUE;
240
241 ifmgd = &tx->sdata->u.mgd;
242
243 /*
244 * Don't wakeup from power save if u-apsd is enabled, voip ac has
245 * u-apsd enabled and the frame is in voip class. This effectively
246 * means that even if all access categories have u-apsd enabled, in
247 * practise u-apsd is only used with the voip ac. This is a
248 * workaround for the case when received voip class packets do not
249 * have correct qos tag for some reason, due the network or the
250 * peer application.
251 *
Eliad Pellerdc41e4d2012-03-14 16:15:03 +0200252 * Note: ifmgd->uapsd_queues access is racy here. If the value is
Kalle Valo0c742112010-01-12 10:42:53 +0200253 * changed via debugfs, user needs to reassociate manually to have
254 * everything in sync.
255 */
Johannes Berg4875d30d2012-03-27 14:18:37 +0200256 if ((ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED) &&
257 (ifmgd->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) &&
258 skb_get_queue_mapping(tx->skb) == IEEE80211_AC_VO)
Kalle Valo0c742112010-01-12 10:42:53 +0200259 return TX_CONTINUE;
260
Kalle Valo5c1b98a2010-01-12 10:42:46 +0200261 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
262 ieee80211_stop_queues_by_reason(&local->hw,
Johannes Berg445ea4e2013-02-13 12:25:28 +0100263 IEEE80211_MAX_QUEUE_MAP,
Luciano Coelhocca07b02014-06-13 16:30:05 +0300264 IEEE80211_QUEUE_STOP_REASON_PS,
265 false);
Vivek Natarajandb285692011-02-18 17:18:03 +0530266 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
Kalle Valo5c1b98a2010-01-12 10:42:46 +0200267 ieee80211_queue_work(&local->hw,
268 &local->dynamic_ps_disable_work);
269 }
270
Luciano Coelho5db1c072011-05-03 21:40:08 +0300271 /* Don't restart the timer if we're not disassociated */
272 if (!ifmgd->associated)
273 return TX_CONTINUE;
274
Kalle Valo5c1b98a2010-01-12 10:42:46 +0200275 mod_timer(&local->dynamic_ps_timer, jiffies +
276 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
277
278 return TX_CONTINUE;
279}
Johannes Berge2ebc742007-07-27 15:43:22 +0200280
Johannes Bergd9e8a702008-06-30 15:10:44 +0200281static ieee80211_tx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +0100282ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
Johannes Berge2ebc742007-07-27 15:43:22 +0200283{
Harvey Harrison358c8d92008-07-15 18:44:13 -0700284
Johannes Berge039fa42008-05-15 12:55:29 +0200285 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
Johannes Berge039fa42008-05-15 12:55:29 +0200286 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200287 bool assoc = false;
Johannes Berge2ebc742007-07-27 15:43:22 +0200288
Johannes Berge039fa42008-05-15 12:55:29 +0200289 if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100290 return TX_CONTINUE;
Johannes Berg58d41852007-09-26 17:53:18 +0200291
Ben Greearb23b0252011-02-04 11:54:17 -0800292 if (unlikely(test_bit(SCAN_SW_SCANNING, &tx->local->scanning)) &&
293 test_bit(SDATA_STATE_OFFCHANNEL, &tx->sdata->state) &&
Kalle Valoa9a6fff2009-03-18 14:06:44 +0200294 !ieee80211_is_probe_req(hdr->frame_control) &&
295 !ieee80211_is_nullfunc(hdr->frame_control))
296 /*
297 * When software scanning only nullfunc frames (to notify
298 * the sleep state to the AP) and probe requests (for the
299 * active scan) are allowed, all other frames should not be
300 * sent and we should not get here, but if we do
301 * nonetheless, drop them to avoid sending them
302 * off-channel. See the link below and
303 * ieee80211_start_scan() for more.
304 *
305 * http://article.gmane.org/gmane.linux.kernel.wireless.general/30089
306 */
Johannes Berg9ae54c82008-01-31 19:48:20 +0100307 return TX_DROP;
Johannes Berge2ebc742007-07-27 15:43:22 +0200308
Rostislav Lisovy239281f2014-11-03 10:33:19 +0100309 if (tx->sdata->vif.type == NL80211_IFTYPE_OCB)
310 return TX_CONTINUE;
311
Bill Jordan1be7fe82010-10-01 11:20:41 -0400312 if (tx->sdata->vif.type == NL80211_IFTYPE_WDS)
313 return TX_CONTINUE;
314
Johannes Berg5cf121c2008-02-25 16:27:43 +0100315 if (tx->flags & IEEE80211_TX_PS_BUFFERED)
Johannes Berg9ae54c82008-01-31 19:48:20 +0100316 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200317
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200318 if (tx->sta)
319 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
Johannes Berge2ebc742007-07-27 15:43:22 +0200320
Johannes Berg5cf121c2008-02-25 16:27:43 +0100321 if (likely(tx->flags & IEEE80211_TX_UNICAST)) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200322 if (unlikely(!assoc &&
Harvey Harrison358c8d92008-07-15 18:44:13 -0700323 ieee80211_is_data(hdr->frame_control))) {
Johannes Berge2ebc742007-07-27 15:43:22 +0200324#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200325 sdata_info(tx->sdata,
326 "dropped data frame to not associated station %pM\n",
327 hdr->addr1);
328#endif
Johannes Berge2ebc742007-07-27 15:43:22 +0200329 I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
Johannes Berg9ae54c82008-01-31 19:48:20 +0100330 return TX_DROP;
Johannes Berge2ebc742007-07-27 15:43:22 +0200331 }
Johannes Berg29623892011-12-14 12:20:31 +0100332 } else if (unlikely(tx->sdata->vif.type == NL80211_IFTYPE_AP &&
333 ieee80211_is_data(hdr->frame_control) &&
Felix Fietkau030ef8f2012-04-23 19:49:02 +0200334 !atomic_read(&tx->sdata->u.ap.num_mcast_sta))) {
Johannes Berg29623892011-12-14 12:20:31 +0100335 /*
336 * No associated STAs - no need to send multicast
337 * frames.
338 */
339 return TX_DROP;
Johannes Berge2ebc742007-07-27 15:43:22 +0200340 }
341
Johannes Berg9ae54c82008-01-31 19:48:20 +0100342 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200343}
344
Johannes Berge2ebc742007-07-27 15:43:22 +0200345/* This function is called whenever the AP is about to exceed the maximum limit
346 * of buffered frames for power saving STAs. This situation should not really
347 * happen often during normal operation, so dropping the oldest buffered packet
348 * from each queue should be OK to make some room for new frames. */
349static void purge_old_ps_buffers(struct ieee80211_local *local)
350{
351 int total = 0, purged = 0;
352 struct sk_buff *skb;
353 struct ieee80211_sub_if_data *sdata;
354 struct sta_info *sta;
355
Johannes Berg79010422007-09-18 17:29:21 -0400356 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Marco Porschd012a602012-10-10 12:39:50 -0700357 struct ps_data *ps;
358
359 if (sdata->vif.type == NL80211_IFTYPE_AP)
360 ps = &sdata->u.ap.ps;
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100361 else if (ieee80211_vif_is_mesh(&sdata->vif))
362 ps = &sdata->u.mesh.ps;
Marco Porschd012a602012-10-10 12:39:50 -0700363 else
Johannes Berge2ebc742007-07-27 15:43:22 +0200364 continue;
Marco Porschd012a602012-10-10 12:39:50 -0700365
366 skb = skb_dequeue(&ps->bc_buf);
Johannes Berge2ebc742007-07-27 15:43:22 +0200367 if (skb) {
368 purged++;
369 dev_kfree_skb(skb);
370 }
Marco Porschd012a602012-10-10 12:39:50 -0700371 total += skb_queue_len(&ps->bc_buf);
Johannes Berge2ebc742007-07-27 15:43:22 +0200372 }
Johannes Berge2ebc742007-07-27 15:43:22 +0200373
Johannes Berg948d8872011-09-29 16:04:29 +0200374 /*
375 * Drop one frame from each station from the lowest-priority
376 * AC that has frames at all.
377 */
Johannes Bergd0709a62008-02-25 16:27:46 +0100378 list_for_each_entry_rcu(sta, &local->sta_list, list) {
Johannes Berg948d8872011-09-29 16:04:29 +0200379 int ac;
380
381 for (ac = IEEE80211_AC_BK; ac >= IEEE80211_AC_VO; ac--) {
382 skb = skb_dequeue(&sta->ps_tx_buf[ac]);
383 total += skb_queue_len(&sta->ps_tx_buf[ac]);
384 if (skb) {
385 purged++;
Felix Fietkauc3e77242012-10-08 14:39:33 +0200386 ieee80211_free_txskb(&local->hw, skb);
Johannes Berg948d8872011-09-29 16:04:29 +0200387 break;
388 }
Johannes Berge2ebc742007-07-27 15:43:22 +0200389 }
Johannes Berge2ebc742007-07-27 15:43:22 +0200390 }
Johannes Bergd0709a62008-02-25 16:27:46 +0100391
Johannes Berge2ebc742007-07-27 15:43:22 +0200392 local->total_ps_buffered = total;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200393 ps_dbg_hw(&local->hw, "PS buffers full - purged %d frames\n", purged);
Johannes Berge2ebc742007-07-27 15:43:22 +0200394}
395
Johannes Berg9ae54c82008-01-31 19:48:20 +0100396static ieee80211_tx_result
Johannes Berg5cf121c2008-02-25 16:27:43 +0100397ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx)
Johannes Berge2ebc742007-07-27 15:43:22 +0200398{
Johannes Berge039fa42008-05-15 12:55:29 +0200399 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
Harvey Harrison358c8d92008-07-15 18:44:13 -0700400 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
Marco Porschd012a602012-10-10 12:39:50 -0700401 struct ps_data *ps;
Johannes Berge039fa42008-05-15 12:55:29 +0200402
Johannes Berg7d54d0dd2007-12-19 01:31:25 +0100403 /*
404 * broadcast/multicast frame
405 *
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100406 * If any of the associated/peer stations is in power save mode,
Johannes Berg7d54d0dd2007-12-19 01:31:25 +0100407 * the frame is buffered to be sent after DTIM beacon frame.
408 * This is done either by the hardware or us.
409 */
410
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100411 /* powersaving STAs currently only in AP/VLAN/mesh mode */
Marco Porschd012a602012-10-10 12:39:50 -0700412 if (tx->sdata->vif.type == NL80211_IFTYPE_AP ||
413 tx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
414 if (!tx->sdata->bss)
415 return TX_CONTINUE;
416
417 ps = &tx->sdata->bss->ps;
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100418 } else if (ieee80211_vif_is_mesh(&tx->sdata->vif)) {
419 ps = &tx->sdata->u.mesh.ps;
Marco Porschd012a602012-10-10 12:39:50 -0700420 } else {
Johannes Berg3e122be2008-07-09 14:40:34 +0200421 return TX_CONTINUE;
Marco Porschd012a602012-10-10 12:39:50 -0700422 }
423
Johannes Berg3e122be2008-07-09 14:40:34 +0200424
425 /* no buffering for ordered frames */
Harvey Harrison358c8d92008-07-15 18:44:13 -0700426 if (ieee80211_has_order(hdr->frame_control))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100427 return TX_CONTINUE;
Johannes Berg7d54d0dd2007-12-19 01:31:25 +0100428
Johannes Berg08b99392014-07-07 12:01:11 +0200429 if (ieee80211_is_probe_req(hdr->frame_control))
430 return TX_CONTINUE;
431
Johannes Berg30686bf2015-06-02 21:39:54 +0200432 if (ieee80211_hw_check(&tx->local->hw, QUEUE_CONTROL))
Johannes Bergf4d57942013-05-28 17:24:15 +0200433 info->hw_queue = tx->sdata->vif.cab_queue;
434
Johannes Berg7d54d0dd2007-12-19 01:31:25 +0100435 /* no stations in PS mode */
Marco Porschd012a602012-10-10 12:39:50 -0700436 if (!atomic_read(&ps->num_sta_ps))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100437 return TX_CONTINUE;
Johannes Berg7d54d0dd2007-12-19 01:31:25 +0100438
Johannes Berg62b517c2009-10-29 12:19:21 +0100439 info->flags |= IEEE80211_TX_CTL_SEND_AFTER_DTIM;
Johannes Berg62b12082009-08-10 16:04:15 +0200440
Johannes Berg62b517c2009-10-29 12:19:21 +0100441 /* device releases frame after DTIM beacon */
Johannes Berg30686bf2015-06-02 21:39:54 +0200442 if (!ieee80211_hw_check(&tx->local->hw, HOST_BROADCAST_PS_BUFFERING))
Johannes Berg62b12082009-08-10 16:04:15 +0200443 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200444
Johannes Berg62b12082009-08-10 16:04:15 +0200445 /* buffered in mac80211 */
446 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
447 purge_old_ps_buffers(tx->local);
Johannes Berg7d54d0dd2007-12-19 01:31:25 +0100448
Marco Porschd012a602012-10-10 12:39:50 -0700449 if (skb_queue_len(&ps->bc_buf) >= AP_MAX_BC_BUFFER) {
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200450 ps_dbg(tx->sdata,
451 "BC TX buffer full - dropping the oldest frame\n");
Marco Porschd012a602012-10-10 12:39:50 -0700452 dev_kfree_skb(skb_dequeue(&ps->bc_buf));
Johannes Berg62b12082009-08-10 16:04:15 +0200453 } else
454 tx->local->total_ps_buffered++;
455
Marco Porschd012a602012-10-10 12:39:50 -0700456 skb_queue_tail(&ps->bc_buf, tx->skb);
Johannes Berg62b12082009-08-10 16:04:15 +0200457
458 return TX_QUEUED;
Johannes Berge2ebc742007-07-27 15:43:22 +0200459}
460
Jouni Malinenfb733332009-01-08 13:32:00 +0200461static int ieee80211_use_mfp(__le16 fc, struct sta_info *sta,
462 struct sk_buff *skb)
463{
464 if (!ieee80211_is_mgmt(fc))
465 return 0;
466
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200467 if (sta == NULL || !test_sta_flag(sta, WLAN_STA_MFP))
Jouni Malinenfb733332009-01-08 13:32:00 +0200468 return 0;
469
Johannes Bergd8ca16d2014-01-23 16:20:29 +0100470 if (!ieee80211_is_robust_mgmt_frame(skb))
Jouni Malinenfb733332009-01-08 13:32:00 +0200471 return 0;
472
473 return 1;
474}
475
Johannes Berg9ae54c82008-01-31 19:48:20 +0100476static ieee80211_tx_result
Johannes Berg5cf121c2008-02-25 16:27:43 +0100477ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
Johannes Berge2ebc742007-07-27 15:43:22 +0200478{
479 struct sta_info *sta = tx->sta;
Johannes Berge039fa42008-05-15 12:55:29 +0200480 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
Johannes Berg08b99392014-07-07 12:01:11 +0200481 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
Juuso Oikarinen3393a602010-04-19 10:12:52 +0300482 struct ieee80211_local *local = tx->local;
Johannes Berge2ebc742007-07-27 15:43:22 +0200483
Johannes Berg02f2f1a2012-02-27 12:18:30 +0100484 if (unlikely(!sta))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100485 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200486
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200487 if (unlikely((test_sta_flag(sta, WLAN_STA_PS_STA) ||
Johannes Berg5ac2e352014-05-27 16:32:27 +0200488 test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
489 test_sta_flag(sta, WLAN_STA_PS_DELIVER)) &&
Johannes Berg02f2f1a2012-02-27 12:18:30 +0100490 !(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER))) {
Johannes Berg948d8872011-09-29 16:04:29 +0200491 int ac = skb_get_queue_mapping(tx->skb);
492
Johannes Berg08b99392014-07-07 12:01:11 +0200493 if (ieee80211_is_mgmt(hdr->frame_control) &&
494 !ieee80211_is_bufferable_mmpdu(hdr->frame_control)) {
495 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER;
496 return TX_CONTINUE;
497 }
498
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200499 ps_dbg(sta->sdata, "STA %pM aid %d: PS buffer for AC %d\n",
500 sta->sta.addr, sta->sta.aid, ac);
Johannes Berge2ebc742007-07-27 15:43:22 +0200501 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
502 purge_old_ps_buffers(tx->local);
Emmanuel Grumbach1d147bf2014-02-20 09:22:11 +0200503
504 /* sync with ieee80211_sta_ps_deliver_wakeup */
505 spin_lock(&sta->ps_lock);
506 /*
507 * STA woke up the meantime and all the frames on ps_tx_buf have
508 * been queued to pending queue. No reordering can happen, go
509 * ahead and Tx the packet.
510 */
511 if (!test_sta_flag(sta, WLAN_STA_PS_STA) &&
Johannes Berg5ac2e352014-05-27 16:32:27 +0200512 !test_sta_flag(sta, WLAN_STA_PS_DRIVER) &&
513 !test_sta_flag(sta, WLAN_STA_PS_DELIVER)) {
Emmanuel Grumbach1d147bf2014-02-20 09:22:11 +0200514 spin_unlock(&sta->ps_lock);
515 return TX_CONTINUE;
516 }
517
Johannes Berg948d8872011-09-29 16:04:29 +0200518 if (skb_queue_len(&sta->ps_tx_buf[ac]) >= STA_MAX_TX_BUFFER) {
519 struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf[ac]);
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200520 ps_dbg(tx->sdata,
521 "STA %pM TX buffer for AC %d full - dropping oldest frame\n",
522 sta->sta.addr, ac);
Felix Fietkauc3e77242012-10-08 14:39:33 +0200523 ieee80211_free_txskb(&local->hw, old);
Johannes Berge2ebc742007-07-27 15:43:22 +0200524 } else
525 tx->local->total_ps_buffered++;
Johannes Berg004c8722008-02-20 11:21:35 +0100526
Johannes Berge039fa42008-05-15 12:55:29 +0200527 info->control.jiffies = jiffies;
Johannes Berg5061b0c2009-07-14 00:33:34 +0200528 info->control.vif = &tx->sdata->vif;
Johannes Berg8f77f382009-06-07 21:58:37 +0200529 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
Johannes Berg03c8c062014-01-09 01:45:28 +0100530 info->flags &= ~IEEE80211_TX_TEMPORARY_FLAGS;
Johannes Berg948d8872011-09-29 16:04:29 +0200531 skb_queue_tail(&sta->ps_tx_buf[ac], tx->skb);
Emmanuel Grumbach1d147bf2014-02-20 09:22:11 +0200532 spin_unlock(&sta->ps_lock);
Juuso Oikarinen3393a602010-04-19 10:12:52 +0300533
534 if (!timer_pending(&local->sta_cleanup))
535 mod_timer(&local->sta_cleanup,
536 round_jiffies(jiffies +
537 STA_INFO_CLEANUP_INTERVAL));
538
Johannes Bergc868cb352011-09-29 16:04:27 +0200539 /*
540 * We queued up some frames, so the TIM bit might
541 * need to be set, recalculate it.
542 */
543 sta_info_recalc_tim(sta);
544
Johannes Berg9ae54c82008-01-31 19:48:20 +0100545 return TX_QUEUED;
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200546 } else if (unlikely(test_sta_flag(sta, WLAN_STA_PS_STA))) {
547 ps_dbg(tx->sdata,
548 "STA %pM in PS mode, but polling/in SP -> send frame\n",
549 sta->sta.addr);
Johannes Berge2ebc742007-07-27 15:43:22 +0200550 }
Johannes Berge2ebc742007-07-27 15:43:22 +0200551
Johannes Berg9ae54c82008-01-31 19:48:20 +0100552 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200553}
554
Johannes Bergd9e8a702008-06-30 15:10:44 +0200555static ieee80211_tx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +0100556ieee80211_tx_h_ps_buf(struct ieee80211_tx_data *tx)
Johannes Berge2ebc742007-07-27 15:43:22 +0200557{
Johannes Berg5cf121c2008-02-25 16:27:43 +0100558 if (unlikely(tx->flags & IEEE80211_TX_PS_BUFFERED))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100559 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200560
Johannes Berg5cf121c2008-02-25 16:27:43 +0100561 if (tx->flags & IEEE80211_TX_UNICAST)
Johannes Berge2ebc742007-07-27 15:43:22 +0200562 return ieee80211_tx_h_unicast_ps_buf(tx);
563 else
564 return ieee80211_tx_h_multicast_ps_buf(tx);
565}
566
Johannes Bergd9e8a702008-06-30 15:10:44 +0200567static ieee80211_tx_result debug_noinline
Johannes Berga621fa42010-08-27 14:26:54 +0300568ieee80211_tx_h_check_control_port_protocol(struct ieee80211_tx_data *tx)
569{
570 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
571
Johannes Bergaf61a162013-07-02 18:09:12 +0200572 if (unlikely(tx->sdata->control_port_protocol == tx->skb->protocol)) {
573 if (tx->sdata->control_port_no_encrypt)
574 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
575 info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO;
Jouni Malinen9c1c98a2015-02-26 15:50:50 +0200576 info->flags |= IEEE80211_TX_CTL_USE_MINRATE;
Johannes Bergaf61a162013-07-02 18:09:12 +0200577 }
Johannes Berga621fa42010-08-27 14:26:54 +0300578
579 return TX_CONTINUE;
580}
581
582static ieee80211_tx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +0100583ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
Johannes Berge2ebc742007-07-27 15:43:22 +0200584{
Johannes Berg46e6de12012-07-04 18:10:07 +0200585 struct ieee80211_key *key;
Johannes Berge039fa42008-05-15 12:55:29 +0200586 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
Harvey Harrison358c8d92008-07-15 18:44:13 -0700587 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
Johannes Bergd4e46a32007-09-14 11:10:24 -0400588
Johannes Berg3b8d81e02009-06-17 17:43:56 +0200589 if (unlikely(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT))
Johannes Berge2ebc742007-07-27 15:43:22 +0200590 tx->key = NULL;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200591 else if (tx->sta &&
592 (key = rcu_dereference(tx->sta->ptk[tx->sta->ptk_idx])))
Johannes Bergd4e46a32007-09-14 11:10:24 -0400593 tx->key = key;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200594 else if (ieee80211_is_mgmt(hdr->frame_control) &&
Jouni Malinenecbcd322010-03-29 23:35:23 -0700595 is_multicast_ether_addr(hdr->addr1) &&
Johannes Bergd8ca16d2014-01-23 16:20:29 +0100596 ieee80211_is_robust_mgmt_frame(tx->skb) &&
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200597 (key = rcu_dereference(tx->sdata->default_mgmt_key)))
598 tx->key = key;
Johannes Bergf7e01042010-12-09 19:49:02 +0100599 else if (is_multicast_ether_addr(hdr->addr1) &&
600 (key = rcu_dereference(tx->sdata->default_multicast_key)))
601 tx->key = key;
602 else if (!is_multicast_ether_addr(hdr->addr1) &&
603 (key = rcu_dereference(tx->sdata->default_unicast_key)))
Johannes Bergd4e46a32007-09-14 11:10:24 -0400604 tx->key = key;
Johannes Berge8f4fb72015-03-20 11:37:36 +0100605 else
Johannes Berg46e6de12012-07-04 18:10:07 +0200606 tx->key = NULL;
Johannes Berge2ebc742007-07-27 15:43:22 +0200607
608 if (tx->key) {
Johannes Berg813d7662010-01-17 01:47:58 +0100609 bool skip_hw = false;
610
Johannes Berg011bfcc2007-09-17 01:29:25 -0400611 /* TODO: add threshold stuff again */
Johannes Berg176e4f82007-12-18 15:27:47 +0100612
Johannes Berg97359d12010-08-10 09:46:38 +0200613 switch (tx->key->conf.cipher) {
614 case WLAN_CIPHER_SUITE_WEP40:
615 case WLAN_CIPHER_SUITE_WEP104:
Johannes Berg97359d12010-08-10 09:46:38 +0200616 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrison358c8d92008-07-15 18:44:13 -0700617 if (!ieee80211_is_data_present(hdr->frame_control))
Johannes Berg176e4f82007-12-18 15:27:47 +0100618 tx->key = NULL;
619 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200620 case WLAN_CIPHER_SUITE_CCMP:
Jouni Malinen2b2ba0d2015-01-24 19:52:07 +0200621 case WLAN_CIPHER_SUITE_CCMP_256:
Jouni Malinen00b9cfa2015-01-24 19:52:06 +0200622 case WLAN_CIPHER_SUITE_GCMP:
623 case WLAN_CIPHER_SUITE_GCMP_256:
Jouni Malinenfb733332009-01-08 13:32:00 +0200624 if (!ieee80211_is_data_present(hdr->frame_control) &&
625 !ieee80211_use_mfp(hdr->frame_control, tx->sta,
626 tx->skb))
627 tx->key = NULL;
Kalle Valo3b43a182010-01-23 20:27:14 +0200628 else
629 skip_hw = (tx->key->conf.flags &
Johannes Berge548c492012-09-04 17:08:23 +0200630 IEEE80211_KEY_FLAG_SW_MGMT_TX) &&
Kalle Valo3b43a182010-01-23 20:27:14 +0200631 ieee80211_is_mgmt(hdr->frame_control);
Jouni Malinenfb733332009-01-08 13:32:00 +0200632 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200633 case WLAN_CIPHER_SUITE_AES_CMAC:
Jouni Malinen56c52da2015-01-24 19:52:08 +0200634 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
Jouni Malinen8ade5382015-01-24 19:52:09 +0200635 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
636 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200637 if (!ieee80211_is_mgmt(hdr->frame_control))
638 tx->key = NULL;
639 break;
Johannes Berg176e4f82007-12-18 15:27:47 +0100640 }
Johannes Berg813d7662010-01-17 01:47:58 +0100641
Johannes Berge54faf22013-01-29 11:41:38 +0100642 if (unlikely(tx->key && tx->key->flags & KEY_FLAG_TAINTED &&
643 !ieee80211_is_deauth(hdr->frame_control)))
Johannes Berg95acac62011-07-12 12:30:59 +0200644 return TX_DROP;
645
Johannes Bergf12553e2010-01-22 22:07:59 +0100646 if (!skip_hw && tx->key &&
Johannes Berg382b1652010-01-25 11:36:16 +0100647 tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
Johannes Berg813d7662010-01-17 01:47:58 +0100648 info->control.hw_key = &tx->key->conf;
Johannes Berge2ebc742007-07-27 15:43:22 +0200649 }
650
Johannes Berg9ae54c82008-01-31 19:48:20 +0100651 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200652}
653
Johannes Bergd9e8a702008-06-30 15:10:44 +0200654static ieee80211_tx_result debug_noinline
Johannes Berg5cf121c2008-02-25 16:27:43 +0100655ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
Johannes Berge2ebc742007-07-27 15:43:22 +0200656{
Johannes Berge039fa42008-05-15 12:55:29 +0200657 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
Johannes Berge6a98542008-10-21 12:40:02 +0200658 struct ieee80211_hdr *hdr = (void *)tx->skb->data;
659 struct ieee80211_supported_band *sband;
Shanyu Zhaoa2c40242010-04-27 11:15:12 -0700660 u32 len;
Johannes Berge6a98542008-10-21 12:40:02 +0200661 struct ieee80211_tx_rate_control txrc;
Felix Fietkau0d528d82013-04-22 16:14:41 +0200662 struct ieee80211_sta_rates *ratetbl = NULL;
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200663 bool assoc = false;
Johannes Berge6a98542008-10-21 12:40:02 +0200664
665 memset(&txrc, 0, sizeof(txrc));
Johannes Berg8318d782008-01-24 19:38:38 +0100666
Johannes Berg2d565772012-07-23 15:12:51 +0200667 sband = tx->local->hw.wiphy->bands[info->band];
Johannes Berge2ebc742007-07-27 15:43:22 +0200668
Shanyu Zhaoa2c40242010-04-27 11:15:12 -0700669 len = min_t(u32, tx->skb->len + FCS_LEN,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200670 tx->local->hw.wiphy->frag_threshold);
Johannes Berg58d41852007-09-26 17:53:18 +0200671
Johannes Berge6a98542008-10-21 12:40:02 +0200672 /* set up the tx rate control struct we give the RC algo */
Johannes Berg005e4722012-02-26 11:24:35 +0100673 txrc.hw = &tx->local->hw;
Johannes Berge6a98542008-10-21 12:40:02 +0200674 txrc.sband = sband;
675 txrc.bss_conf = &tx->sdata->vif.bss_conf;
676 txrc.skb = tx->skb;
677 txrc.reported_rate.idx = -1;
Johannes Berg2d565772012-07-23 15:12:51 +0200678 txrc.rate_idx_mask = tx->sdata->rc_rateidx_mask[info->band];
Jouni Malinen37eb0b12010-01-06 13:09:08 +0200679 if (txrc.rate_idx_mask == (1 << sband->n_bitrates) - 1)
680 txrc.max_rate_idx = -1;
681 else
682 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +0200683
684 if (tx->sdata->rc_has_mcs_mask[info->band])
685 txrc.rate_idx_mcs_mask =
686 tx->sdata->rc_rateidx_mcs_mask[info->band];
687
Felix Fietkau8f0729b2010-11-11 15:07:23 +0100688 txrc.bss = (tx->sdata->vif.type == NL80211_IFTYPE_AP ||
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -0800689 tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
Bertold Van den Bergh5765f9f2015-08-05 16:02:28 +0200690 tx->sdata->vif.type == NL80211_IFTYPE_ADHOC ||
691 tx->sdata->vif.type == NL80211_IFTYPE_OCB);
Johannes Berg58d41852007-09-26 17:53:18 +0200692
Johannes Berge6a98542008-10-21 12:40:02 +0200693 /* set up RTS protection if desired */
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200694 if (len > tx->local->hw.wiphy->rts_threshold) {
Felix Fietkau0d528d82013-04-22 16:14:41 +0200695 txrc.rts = true;
Johannes Berge2ebc742007-07-27 15:43:22 +0200696 }
Johannes Berge6a98542008-10-21 12:40:02 +0200697
Felix Fietkau0d528d82013-04-22 16:14:41 +0200698 info->control.use_rts = txrc.rts;
Felix Fietkau991fec02013-04-16 13:38:43 +0200699 info->control.use_cts_prot = tx->sdata->vif.bss_conf.use_cts_prot;
700
Johannes Berge6a98542008-10-21 12:40:02 +0200701 /*
702 * Use short preamble if the BSS can handle it, but not for
703 * management frames unless we know the receiver can handle
704 * that -- the management frame might be to a station that
705 * just wants a probe response.
706 */
707 if (tx->sdata->vif.bss_conf.use_short_preamble &&
708 (ieee80211_is_data(hdr->frame_control) ||
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200709 (tx->sta && test_sta_flag(tx->sta, WLAN_STA_SHORT_PREAMBLE))))
Felix Fietkau0d528d82013-04-22 16:14:41 +0200710 txrc.short_preamble = true;
711
712 info->control.short_preamble = txrc.short_preamble;
Johannes Berge6a98542008-10-21 12:40:02 +0200713
Sven Eckelmanndfdfc2b2016-01-26 17:11:13 +0100714 /* don't ask rate control when rate already injected via radiotap */
715 if (info->control.flags & IEEE80211_TX_CTRL_RATE_INJECT)
716 return TX_CONTINUE;
717
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200718 if (tx->sta)
719 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
Johannes Berge6a98542008-10-21 12:40:02 +0200720
Luis R. Rodriguezb770b432009-07-16 10:15:09 -0700721 /*
722 * Lets not bother rate control if we're associated and cannot
723 * talk to the sta. This should not happen.
724 */
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200725 if (WARN(test_bit(SCAN_SW_SCANNING, &tx->local->scanning) && assoc &&
Luis R. Rodriguezb770b432009-07-16 10:15:09 -0700726 !rate_usable_index_exists(sband, &tx->sta->sta),
727 "%s: Dropped data frame as no usable bitrate found while "
728 "scanning and associated. Target station: "
729 "%pM on %d GHz band\n",
Johannes Berg47846c92009-11-25 17:46:19 +0100730 tx->sdata->name, hdr->addr1,
Johannes Berg2d565772012-07-23 15:12:51 +0200731 info->band ? 5 : 2))
Luis R. Rodriguezb770b432009-07-16 10:15:09 -0700732 return TX_DROP;
733
734 /*
735 * If we're associated with the sta at this point we know we can at
736 * least send the frame at the lowest bit rate.
737 */
Johannes Berge6a98542008-10-21 12:40:02 +0200738 rate_control_get_rate(tx->sdata, tx->sta, &txrc);
739
Felix Fietkau0d528d82013-04-22 16:14:41 +0200740 if (tx->sta && !info->control.skip_table)
741 ratetbl = rcu_dereference(tx->sta->sta.rates);
742
743 if (unlikely(info->control.rates[0].idx < 0)) {
744 if (ratetbl) {
745 struct ieee80211_tx_rate rate = {
746 .idx = ratetbl->rate[0].idx,
747 .flags = ratetbl->rate[0].flags,
748 .count = ratetbl->rate[0].count
749 };
750
751 if (ratetbl->rate[0].idx < 0)
752 return TX_DROP;
753
754 tx->rate = rate;
755 } else {
756 return TX_DROP;
757 }
758 } else {
759 tx->rate = info->control.rates[0];
760 }
Johannes Berge6a98542008-10-21 12:40:02 +0200761
Helmut Schaac1ce5a72010-12-01 16:34:45 +0100762 if (txrc.reported_rate.idx < 0) {
Felix Fietkau0d528d82013-04-22 16:14:41 +0200763 txrc.reported_rate = tx->rate;
Helmut Schaac1ce5a72010-12-01 16:34:45 +0100764 if (tx->sta && ieee80211_is_data(hdr->frame_control))
Johannes Berge5a9f8d2015-10-16 17:54:47 +0200765 tx->sta->tx_stats.last_rate = txrc.reported_rate;
Helmut Schaac1ce5a72010-12-01 16:34:45 +0100766 } else if (tx->sta)
Johannes Berge5a9f8d2015-10-16 17:54:47 +0200767 tx->sta->tx_stats.last_rate = txrc.reported_rate;
Johannes Berge6a98542008-10-21 12:40:02 +0200768
Felix Fietkau0d528d82013-04-22 16:14:41 +0200769 if (ratetbl)
770 return TX_CONTINUE;
771
Johannes Berge6a98542008-10-21 12:40:02 +0200772 if (unlikely(!info->control.rates[0].count))
773 info->control.rates[0].count = 1;
774
Gábor Stefanik99551512009-04-23 19:36:14 +0200775 if (WARN_ON_ONCE((info->control.rates[0].count > 1) &&
776 (info->flags & IEEE80211_TX_CTL_NO_ACK)))
777 info->control.rates[0].count = 1;
778
Johannes Berg9ae54c82008-01-31 19:48:20 +0100779 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200780}
781
Felix Fietkauba8c3d62015-03-27 21:30:37 +0100782static __le16 ieee80211_tx_next_seq(struct sta_info *sta, int tid)
783{
784 u16 *seq = &sta->tid_seq[tid];
785 __le16 ret = cpu_to_le16(*seq);
786
787 /* Increase the sequence number. */
788 *seq = (*seq + 0x10) & IEEE80211_SCTL_SEQ;
789
790 return ret;
791}
792
Johannes Bergd9e8a702008-06-30 15:10:44 +0200793static ieee80211_tx_result debug_noinline
Johannes Bergf591fa52008-07-10 11:21:26 +0200794ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx)
795{
796 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
797 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
Johannes Bergf591fa52008-07-10 11:21:26 +0200798 u8 *qc;
799 int tid;
800
Johannes Berg25d834e2008-09-12 22:52:47 +0200801 /*
802 * Packet injection may want to control the sequence
803 * number, if we have no matching interface then we
804 * neither assign one ourselves nor ask the driver to.
805 */
Johannes Berg5061b0c2009-07-14 00:33:34 +0200806 if (unlikely(info->control.vif->type == NL80211_IFTYPE_MONITOR))
Johannes Berg25d834e2008-09-12 22:52:47 +0200807 return TX_CONTINUE;
808
Johannes Bergf591fa52008-07-10 11:21:26 +0200809 if (unlikely(ieee80211_is_ctl(hdr->frame_control)))
810 return TX_CONTINUE;
811
812 if (ieee80211_hdrlen(hdr->frame_control) < 24)
813 return TX_CONTINUE;
814
Johannes Berg49a59542011-09-29 16:04:41 +0200815 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
816 return TX_CONTINUE;
817
Johannes Berg94778282008-10-10 13:21:59 +0200818 /*
819 * Anything but QoS data that has a sequence number field
820 * (is long enough) gets a sequence number from the global
Bob Copelandc4c205f2013-08-23 09:35:38 -0400821 * counter. QoS data frames with a multicast destination
822 * also use the global counter (802.11-2012 9.3.2.10).
Johannes Berg94778282008-10-10 13:21:59 +0200823 */
Bob Copelandc4c205f2013-08-23 09:35:38 -0400824 if (!ieee80211_is_data_qos(hdr->frame_control) ||
825 is_multicast_ether_addr(hdr->addr1)) {
Johannes Berg94778282008-10-10 13:21:59 +0200826 /* driver should assign sequence number */
Johannes Bergf591fa52008-07-10 11:21:26 +0200827 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
Johannes Berg94778282008-10-10 13:21:59 +0200828 /* for pure STA mode without beacons, we can do it */
829 hdr->seq_ctrl = cpu_to_le16(tx->sdata->sequence_number);
830 tx->sdata->sequence_number += 0x10;
Johannes Berg79c892b2014-11-21 14:26:31 +0100831 if (tx->sta)
Johannes Berge5a9f8d2015-10-16 17:54:47 +0200832 tx->sta->tx_stats.msdu[IEEE80211_NUM_TIDS]++;
Johannes Bergf591fa52008-07-10 11:21:26 +0200833 return TX_CONTINUE;
834 }
835
836 /*
837 * This should be true for injected/management frames only, for
838 * management frames we have set the IEEE80211_TX_CTL_ASSIGN_SEQ
839 * above since they are not QoS-data frames.
840 */
841 if (!tx->sta)
842 return TX_CONTINUE;
843
844 /* include per-STA, per-TID sequence counter */
845
846 qc = ieee80211_get_qos_ctl(hdr);
847 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
Johannes Berge5a9f8d2015-10-16 17:54:47 +0200848 tx->sta->tx_stats.msdu[tid]++;
Johannes Bergf591fa52008-07-10 11:21:26 +0200849
Felix Fietkauba8c3d62015-03-27 21:30:37 +0100850 if (!tx->sta->sta.txq[0])
851 hdr->seq_ctrl = ieee80211_tx_next_seq(tx->sta, tid);
Johannes Bergf591fa52008-07-10 11:21:26 +0200852
853 return TX_CONTINUE;
854}
855
Johannes Berg252b86c2011-11-16 15:28:55 +0100856static int ieee80211_fragment(struct ieee80211_tx_data *tx,
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100857 struct sk_buff *skb, int hdrlen,
858 int frag_threshold)
859{
Johannes Berg252b86c2011-11-16 15:28:55 +0100860 struct ieee80211_local *local = tx->local;
Johannes Berga1a3fce2011-11-16 15:28:56 +0100861 struct ieee80211_tx_info *info;
Johannes Berg252b86c2011-11-16 15:28:55 +0100862 struct sk_buff *tmp;
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100863 int per_fragm = frag_threshold - hdrlen - FCS_LEN;
864 int pos = hdrlen + per_fragm;
865 int rem = skb->len - hdrlen - per_fragm;
866
867 if (WARN_ON(rem < 0))
868 return -EINVAL;
869
Johannes Berg252b86c2011-11-16 15:28:55 +0100870 /* first fragment was already added to queue by caller */
871
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100872 while (rem) {
873 int fraglen = per_fragm;
874
875 if (fraglen > rem)
876 fraglen = rem;
877 rem -= fraglen;
878 tmp = dev_alloc_skb(local->tx_headroom +
879 frag_threshold +
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200880 tx->sdata->encrypt_headroom +
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100881 IEEE80211_ENCRYPT_TAILROOM);
882 if (!tmp)
883 return -ENOMEM;
Johannes Berg252b86c2011-11-16 15:28:55 +0100884
885 __skb_queue_tail(&tx->skbs, tmp);
886
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200887 skb_reserve(tmp,
888 local->tx_headroom + tx->sdata->encrypt_headroom);
889
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100890 /* copy control information */
891 memcpy(tmp->cb, skb->cb, sizeof(tmp->cb));
Johannes Berga1a3fce2011-11-16 15:28:56 +0100892
893 info = IEEE80211_SKB_CB(tmp);
894 info->flags &= ~(IEEE80211_TX_CTL_CLEAR_PS_FILT |
895 IEEE80211_TX_CTL_FIRST_FRAGMENT);
896
897 if (rem)
898 info->flags |= IEEE80211_TX_CTL_MORE_FRAMES;
899
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100900 skb_copy_queue_mapping(tmp, skb);
901 tmp->priority = skb->priority;
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100902 tmp->dev = skb->dev;
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100903
904 /* copy header and data */
905 memcpy(skb_put(tmp, hdrlen), skb->data, hdrlen);
906 memcpy(skb_put(tmp, fraglen), skb->data + pos, fraglen);
907
908 pos += fraglen;
909 }
910
Johannes Berg252b86c2011-11-16 15:28:55 +0100911 /* adjust first fragment's length */
Johannes Berg338f9772014-02-01 00:16:23 +0100912 skb_trim(skb, hdrlen + per_fragm);
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100913 return 0;
914}
915
Johannes Bergf591fa52008-07-10 11:21:26 +0200916static ieee80211_tx_result debug_noinline
Johannes Berge2454942008-05-15 12:55:28 +0200917ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
918{
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100919 struct sk_buff *skb = tx->skb;
920 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
921 struct ieee80211_hdr *hdr = (void *)skb->data;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200922 int frag_threshold = tx->local->hw.wiphy->frag_threshold;
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100923 int hdrlen;
924 int fragnum;
Johannes Berge2454942008-05-15 12:55:28 +0200925
Johannes Berg252b86c2011-11-16 15:28:55 +0100926 /* no matter what happens, tx->skb moves to tx->skbs */
927 __skb_queue_tail(&tx->skbs, skb);
928 tx->skb = NULL;
929
Johannes Berga26eb272011-10-07 14:01:25 +0200930 if (info->flags & IEEE80211_TX_CTL_DONTFRAG)
931 return TX_CONTINUE;
932
933 if (tx->local->ops->set_frag_threshold)
Johannes Berge2454942008-05-15 12:55:28 +0200934 return TX_CONTINUE;
935
Johannes Bergeefce912008-05-17 00:57:13 +0200936 /*
937 * Warn when submitting a fragmented A-MPDU frame and drop it.
Johannes Berg3b8d81e02009-06-17 17:43:56 +0200938 * This scenario is handled in ieee80211_tx_prepare but extra
Ron Rindjunsky8d5e0d52008-06-12 15:42:29 +0300939 * caution taken here as fragmented ampdu may cause Tx stop.
Johannes Bergeefce912008-05-17 00:57:13 +0200940 */
Sujith8b30b1f2008-10-24 09:55:27 +0530941 if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU))
Johannes Bergeefce912008-05-17 00:57:13 +0200942 return TX_DROP;
943
Harvey Harrison065e96052008-06-22 16:45:27 -0700944 hdrlen = ieee80211_hdrlen(hdr->frame_control);
Johannes Berge2454942008-05-15 12:55:28 +0200945
Johannes Berga26eb272011-10-07 14:01:25 +0200946 /* internal error, why isn't DONTFRAG set? */
Johannes Berg8ccd8f22009-04-29 23:35:56 +0200947 if (WARN_ON(skb->len + FCS_LEN <= frag_threshold))
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100948 return TX_DROP;
Johannes Berge2454942008-05-15 12:55:28 +0200949
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100950 /*
951 * Now fragment the frame. This will allocate all the fragments and
952 * chain them (using skb as the first fragment) to skb->next.
953 * During transmission, we will remove the successfully transmitted
954 * fragments from this list. When the low-level driver rejects one
955 * of the fragments then we will simply pretend to accept the skb
956 * but store it away as pending.
957 */
Johannes Berg252b86c2011-11-16 15:28:55 +0100958 if (ieee80211_fragment(tx, skb, hdrlen, frag_threshold))
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100959 return TX_DROP;
Johannes Berge2454942008-05-15 12:55:28 +0200960
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100961 /* update duration/seq/flags of fragments */
962 fragnum = 0;
Johannes Berg252b86c2011-11-16 15:28:55 +0100963
964 skb_queue_walk(&tx->skbs, skb) {
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100965 const __le16 morefrags = cpu_to_le16(IEEE80211_FCTL_MOREFRAGS);
Johannes Berge2454942008-05-15 12:55:28 +0200966
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100967 hdr = (void *)skb->data;
968 info = IEEE80211_SKB_CB(skb);
Johannes Berge6a98542008-10-21 12:40:02 +0200969
Johannes Berg252b86c2011-11-16 15:28:55 +0100970 if (!skb_queue_is_last(&tx->skbs, skb)) {
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100971 hdr->frame_control |= morefrags;
Johannes Berge6a98542008-10-21 12:40:02 +0200972 /*
973 * No multi-rate retries for fragmented frames, that
974 * would completely throw off the NAV at other STAs.
975 */
976 info->control.rates[1].idx = -1;
977 info->control.rates[2].idx = -1;
978 info->control.rates[3].idx = -1;
Thomas Huehne3e1a0b2012-07-02 19:46:16 +0200979 BUILD_BUG_ON(IEEE80211_TX_MAX_RATES != 4);
Johannes Berge6a98542008-10-21 12:40:02 +0200980 info->flags &= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE;
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100981 } else {
982 hdr->frame_control &= ~morefrags;
Johannes Berge6a98542008-10-21 12:40:02 +0200983 }
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100984 hdr->seq_ctrl |= cpu_to_le16(fragnum & IEEE80211_SCTL_FRAG);
985 fragnum++;
Johannes Berg252b86c2011-11-16 15:28:55 +0100986 }
Johannes Berge2454942008-05-15 12:55:28 +0200987
988 return TX_CONTINUE;
Johannes Berge2454942008-05-15 12:55:28 +0200989}
990
Johannes Bergd9e8a702008-06-30 15:10:44 +0200991static ieee80211_tx_result debug_noinline
Johannes Bergfeff1f22009-08-10 16:01:54 +0200992ieee80211_tx_h_stats(struct ieee80211_tx_data *tx)
993{
Johannes Berg252b86c2011-11-16 15:28:55 +0100994 struct sk_buff *skb;
Johannes Berg560d2682013-02-05 10:55:21 +0100995 int ac = -1;
Johannes Bergfeff1f22009-08-10 16:01:54 +0200996
997 if (!tx->sta)
998 return TX_CONTINUE;
999
Johannes Berg252b86c2011-11-16 15:28:55 +01001000 skb_queue_walk(&tx->skbs, skb) {
Johannes Berg560d2682013-02-05 10:55:21 +01001001 ac = skb_get_queue_mapping(skb);
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001002 tx->sta->tx_stats.bytes[ac] += skb->len;
Johannes Berg252b86c2011-11-16 15:28:55 +01001003 }
Johannes Berg560d2682013-02-05 10:55:21 +01001004 if (ac >= 0)
Johannes Berge5a9f8d2015-10-16 17:54:47 +02001005 tx->sta->tx_stats.packets[ac]++;
Johannes Bergfeff1f22009-08-10 16:01:54 +02001006
1007 return TX_CONTINUE;
1008}
1009
1010static ieee80211_tx_result debug_noinline
Johannes Berge2454942008-05-15 12:55:28 +02001011ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx)
1012{
1013 if (!tx->key)
1014 return TX_CONTINUE;
1015
Johannes Berg97359d12010-08-10 09:46:38 +02001016 switch (tx->key->conf.cipher) {
1017 case WLAN_CIPHER_SUITE_WEP40:
1018 case WLAN_CIPHER_SUITE_WEP104:
Johannes Berge2454942008-05-15 12:55:28 +02001019 return ieee80211_crypto_wep_encrypt(tx);
Johannes Berg97359d12010-08-10 09:46:38 +02001020 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berge2454942008-05-15 12:55:28 +02001021 return ieee80211_crypto_tkip_encrypt(tx);
Johannes Berg97359d12010-08-10 09:46:38 +02001022 case WLAN_CIPHER_SUITE_CCMP:
Jouni Malinen2b2ba0d2015-01-24 19:52:07 +02001023 return ieee80211_crypto_ccmp_encrypt(
1024 tx, IEEE80211_CCMP_MIC_LEN);
1025 case WLAN_CIPHER_SUITE_CCMP_256:
1026 return ieee80211_crypto_ccmp_encrypt(
1027 tx, IEEE80211_CCMP_256_MIC_LEN);
Johannes Berg97359d12010-08-10 09:46:38 +02001028 case WLAN_CIPHER_SUITE_AES_CMAC:
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001029 return ieee80211_crypto_aes_cmac_encrypt(tx);
Jouni Malinen56c52da2015-01-24 19:52:08 +02001030 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
1031 return ieee80211_crypto_aes_cmac_256_encrypt(tx);
Jouni Malinen8ade5382015-01-24 19:52:09 +02001032 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
1033 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
1034 return ieee80211_crypto_aes_gmac_encrypt(tx);
Jouni Malinen00b9cfa2015-01-24 19:52:06 +02001035 case WLAN_CIPHER_SUITE_GCMP:
1036 case WLAN_CIPHER_SUITE_GCMP_256:
1037 return ieee80211_crypto_gcmp_encrypt(tx);
Johannes Berg3ffc2a92010-08-27 14:26:52 +03001038 default:
Yoni Divinskyd32a1022012-01-16 15:18:59 +02001039 return ieee80211_crypto_hw_encrypt(tx);
Johannes Berge2454942008-05-15 12:55:28 +02001040 }
1041
Johannes Berge2454942008-05-15 12:55:28 +02001042 return TX_DROP;
1043}
1044
Johannes Bergd9e8a702008-06-30 15:10:44 +02001045static ieee80211_tx_result debug_noinline
Johannes Berg03f93c32008-06-25 14:36:27 +03001046ieee80211_tx_h_calculate_duration(struct ieee80211_tx_data *tx)
1047{
Johannes Berg252b86c2011-11-16 15:28:55 +01001048 struct sk_buff *skb;
Johannes Berg2de8e0d2009-03-23 17:28:35 +01001049 struct ieee80211_hdr *hdr;
1050 int next_len;
1051 bool group_addr;
Johannes Berg03f93c32008-06-25 14:36:27 +03001052
Johannes Berg252b86c2011-11-16 15:28:55 +01001053 skb_queue_walk(&tx->skbs, skb) {
Johannes Berg2de8e0d2009-03-23 17:28:35 +01001054 hdr = (void *) skb->data;
Jouni Malinen7e0aae42009-05-19 19:25:58 +03001055 if (unlikely(ieee80211_is_pspoll(hdr->frame_control)))
1056 break; /* must not overwrite AID */
Johannes Berg252b86c2011-11-16 15:28:55 +01001057 if (!skb_queue_is_last(&tx->skbs, skb)) {
1058 struct sk_buff *next = skb_queue_next(&tx->skbs, skb);
1059 next_len = next->len;
1060 } else
1061 next_len = 0;
Johannes Berg2de8e0d2009-03-23 17:28:35 +01001062 group_addr = is_multicast_ether_addr(hdr->addr1);
Johannes Berg03f93c32008-06-25 14:36:27 +03001063
Johannes Berg2de8e0d2009-03-23 17:28:35 +01001064 hdr->duration_id =
Johannes Berg252b86c2011-11-16 15:28:55 +01001065 ieee80211_duration(tx, skb, group_addr, next_len);
1066 }
Johannes Berg03f93c32008-06-25 14:36:27 +03001067
1068 return TX_CONTINUE;
1069}
1070
Johannes Berge2ebc742007-07-27 15:43:22 +02001071/* actual transmit path */
1072
Johannes Berga622ab72010-06-10 10:21:39 +02001073static bool ieee80211_tx_prep_agg(struct ieee80211_tx_data *tx,
1074 struct sk_buff *skb,
1075 struct ieee80211_tx_info *info,
1076 struct tid_ampdu_tx *tid_tx,
1077 int tid)
1078{
1079 bool queued = false;
Nikolay Martynov285fa692011-11-22 21:50:28 -05001080 bool reset_agg_timer = false;
Helmut Schaaaa454582012-03-07 17:20:30 +01001081 struct sk_buff *purge_skb = NULL;
Johannes Berga622ab72010-06-10 10:21:39 +02001082
1083 if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
1084 info->flags |= IEEE80211_TX_CTL_AMPDU;
Nikolay Martynov285fa692011-11-22 21:50:28 -05001085 reset_agg_timer = true;
Johannes Berg0ab33702010-06-10 10:21:42 +02001086 } else if (test_bit(HT_AGG_STATE_WANT_START, &tid_tx->state)) {
1087 /*
1088 * nothing -- this aggregation session is being started
1089 * but that might still fail with the driver
1090 */
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001091 } else if (!tx->sta->sta.txq[tid]) {
Johannes Berga622ab72010-06-10 10:21:39 +02001092 spin_lock(&tx->sta->lock);
1093 /*
1094 * Need to re-check now, because we may get here
1095 *
1096 * 1) in the window during which the setup is actually
1097 * already done, but not marked yet because not all
1098 * packets are spliced over to the driver pending
1099 * queue yet -- if this happened we acquire the lock
1100 * either before or after the splice happens, but
1101 * need to recheck which of these cases happened.
1102 *
1103 * 2) during session teardown, if the OPERATIONAL bit
1104 * was cleared due to the teardown but the pointer
1105 * hasn't been assigned NULL yet (or we loaded it
1106 * before it was assigned) -- in this case it may
1107 * now be NULL which means we should just let the
1108 * packet pass through because splicing the frames
1109 * back is already done.
1110 */
Johannes Berg40b275b2011-05-13 14:15:49 +02001111 tid_tx = rcu_dereference_protected_tid_tx(tx->sta, tid);
Johannes Berga622ab72010-06-10 10:21:39 +02001112
1113 if (!tid_tx) {
1114 /* do nothing, let packet pass through */
1115 } else if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
1116 info->flags |= IEEE80211_TX_CTL_AMPDU;
Nikolay Martynov285fa692011-11-22 21:50:28 -05001117 reset_agg_timer = true;
Johannes Berga622ab72010-06-10 10:21:39 +02001118 } else {
1119 queued = true;
Emmanuel Grumbachf6d46712016-03-17 16:51:42 +02001120 if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER) {
1121 clear_sta_flag(tx->sta, WLAN_STA_SP);
1122 ps_dbg(tx->sta->sdata,
1123 "STA %pM aid %d: SP frame queued, close the SP w/o telling the peer\n",
1124 tx->sta->sta.addr, tx->sta->sta.aid);
1125 }
Johannes Berga622ab72010-06-10 10:21:39 +02001126 info->control.vif = &tx->sdata->vif;
1127 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
Emmanuel Grumbachfacde7f2016-03-17 16:51:41 +02001128 info->flags &= ~IEEE80211_TX_TEMPORARY_FLAGS;
Johannes Berga622ab72010-06-10 10:21:39 +02001129 __skb_queue_tail(&tid_tx->pending, skb);
Helmut Schaaaa454582012-03-07 17:20:30 +01001130 if (skb_queue_len(&tid_tx->pending) > STA_MAX_TX_BUFFER)
1131 purge_skb = __skb_dequeue(&tid_tx->pending);
Johannes Berga622ab72010-06-10 10:21:39 +02001132 }
1133 spin_unlock(&tx->sta->lock);
Helmut Schaaaa454582012-03-07 17:20:30 +01001134
1135 if (purge_skb)
Felix Fietkauc3e77242012-10-08 14:39:33 +02001136 ieee80211_free_txskb(&tx->local->hw, purge_skb);
Johannes Berga622ab72010-06-10 10:21:39 +02001137 }
1138
Nikolay Martynov285fa692011-11-22 21:50:28 -05001139 /* reset session timer */
1140 if (reset_agg_timer && tid_tx->timeout)
Felix Fietkau12d3952f2012-03-18 22:58:06 +01001141 tid_tx->last_tx = jiffies;
Nikolay Martynov285fa692011-11-22 21:50:28 -05001142
Johannes Berga622ab72010-06-10 10:21:39 +02001143 return queued;
1144}
1145
Johannes Berg58d41852007-09-26 17:53:18 +02001146/*
1147 * initialises @tx
Johannes Berg7c107702015-03-20 14:18:27 +01001148 * pass %NULL for the station if unknown, a valid pointer if known
1149 * or an ERR_PTR() if the station is known not to exist
Johannes Berg58d41852007-09-26 17:53:18 +02001150 */
Johannes Berg9ae54c82008-01-31 19:48:20 +01001151static ieee80211_tx_result
Johannes Berg3b8d81e02009-06-17 17:43:56 +02001152ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata,
1153 struct ieee80211_tx_data *tx,
Johannes Berg7c107702015-03-20 14:18:27 +01001154 struct sta_info *sta, struct sk_buff *skb)
Johannes Berge2ebc742007-07-27 15:43:22 +02001155{
Johannes Berg3b8d81e02009-06-17 17:43:56 +02001156 struct ieee80211_local *local = sdata->local;
Johannes Berg58d41852007-09-26 17:53:18 +02001157 struct ieee80211_hdr *hdr;
Johannes Berge039fa42008-05-15 12:55:29 +02001158 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Johannes Berg68f2b512011-10-07 14:01:24 +02001159 int tid;
Johannes Berga622ab72010-06-10 10:21:39 +02001160 u8 *qc;
Johannes Berge2ebc742007-07-27 15:43:22 +02001161
1162 memset(tx, 0, sizeof(*tx));
1163 tx->skb = skb;
Johannes Berge2ebc742007-07-27 15:43:22 +02001164 tx->local = local;
Johannes Berg3b8d81e02009-06-17 17:43:56 +02001165 tx->sdata = sdata;
Johannes Berg252b86c2011-11-16 15:28:55 +01001166 __skb_queue_head_init(&tx->skbs);
Johannes Berge2ebc742007-07-27 15:43:22 +02001167
Johannes Bergcd8ffc82009-03-23 17:28:41 +01001168 /*
1169 * If this flag is set to true anywhere, and we get here,
1170 * we are doing the needed processing, so remove the flag
1171 * now.
1172 */
1173 info->flags &= ~IEEE80211_TX_INTFL_NEED_TXPROCESSING;
1174
Johannes Berg58d41852007-09-26 17:53:18 +02001175 hdr = (struct ieee80211_hdr *) skb->data;
1176
Johannes Berg7c107702015-03-20 14:18:27 +01001177 if (likely(sta)) {
1178 if (!IS_ERR(sta))
1179 tx->sta = sta;
1180 } else {
1181 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
1182 tx->sta = rcu_dereference(sdata->u.vlan.sta);
1183 if (!tx->sta && sdata->wdev.use_4addr)
1184 return TX_DROP;
1185 } else if (info->flags & (IEEE80211_TX_INTFL_NL80211_FRAME_TX |
1186 IEEE80211_TX_CTL_INJECTED) ||
1187 tx->sdata->control_port_protocol == tx->skb->protocol) {
1188 tx->sta = sta_info_get_bss(sdata, hdr->addr1);
1189 }
1190 if (!tx->sta && !is_multicast_ether_addr(hdr->addr1))
1191 tx->sta = sta_info_get(sdata, hdr->addr1);
Felix Fietkau3f0e0b22010-01-08 18:15:13 +01001192 }
Johannes Berg58d41852007-09-26 17:53:18 +02001193
Johannes Bergcd8ffc82009-03-23 17:28:41 +01001194 if (tx->sta && ieee80211_is_data_qos(hdr->frame_control) &&
Johannes Berg49a59542011-09-29 16:04:41 +02001195 !ieee80211_is_qos_nullfunc(hdr->frame_control) &&
Johannes Berg30686bf2015-06-02 21:39:54 +02001196 ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
1197 !ieee80211_hw_check(&local->hw, TX_AMPDU_SETUP_IN_HW)) {
Johannes Bergcd8ffc82009-03-23 17:28:41 +01001198 struct tid_ampdu_tx *tid_tx;
1199
Sujith8b30b1f2008-10-24 09:55:27 +05301200 qc = ieee80211_get_qos_ctl(hdr);
1201 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
1202
Johannes Berga622ab72010-06-10 10:21:39 +02001203 tid_tx = rcu_dereference(tx->sta->ampdu_mlme.tid_tx[tid]);
1204 if (tid_tx) {
1205 bool queued;
Johannes Bergcd8ffc82009-03-23 17:28:41 +01001206
Johannes Berga622ab72010-06-10 10:21:39 +02001207 queued = ieee80211_tx_prep_agg(tx, skb, info,
1208 tid_tx, tid);
1209
1210 if (unlikely(queued))
1211 return TX_QUEUED;
1212 }
Sujith8b30b1f2008-10-24 09:55:27 +05301213 }
1214
Jiri Slabybadffb72007-08-28 17:01:54 -04001215 if (is_multicast_ether_addr(hdr->addr1)) {
Johannes Berg5cf121c2008-02-25 16:27:43 +01001216 tx->flags &= ~IEEE80211_TX_UNICAST;
Johannes Berge039fa42008-05-15 12:55:29 +02001217 info->flags |= IEEE80211_TX_CTL_NO_ACK;
Simon Wunderlich6fd67e92011-11-18 14:20:42 +01001218 } else
Johannes Berg5cf121c2008-02-25 16:27:43 +01001219 tx->flags |= IEEE80211_TX_UNICAST;
Johannes Berg58d41852007-09-26 17:53:18 +02001220
Johannes Berga26eb272011-10-07 14:01:25 +02001221 if (!(info->flags & IEEE80211_TX_CTL_DONTFRAG)) {
1222 if (!(tx->flags & IEEE80211_TX_UNICAST) ||
1223 skb->len + FCS_LEN <= local->hw.wiphy->frag_threshold ||
1224 info->flags & IEEE80211_TX_CTL_AMPDU)
1225 info->flags |= IEEE80211_TX_CTL_DONTFRAG;
Johannes Berg58d41852007-09-26 17:53:18 +02001226 }
1227
Johannes Berge2ebc742007-07-27 15:43:22 +02001228 if (!tx->sta)
Johannes Berge039fa42008-05-15 12:55:29 +02001229 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
Felix Fietkauf7418bc2015-09-24 14:59:49 +02001230 else if (test_and_clear_sta_flag(tx->sta, WLAN_STA_CLEAR_PS_FILT)) {
Johannes Berge039fa42008-05-15 12:55:29 +02001231 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
Felix Fietkauf7418bc2015-09-24 14:59:49 +02001232 ieee80211_check_fast_xmit(tx->sta);
1233 }
Johannes Berg58d41852007-09-26 17:53:18 +02001234
Johannes Berge039fa42008-05-15 12:55:29 +02001235 info->flags |= IEEE80211_TX_CTL_FIRST_FRAGMENT;
Johannes Berge2ebc742007-07-27 15:43:22 +02001236
Johannes Berg9ae54c82008-01-31 19:48:20 +01001237 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +02001238}
1239
Michal Kazior80a83cf2016-05-19 10:37:48 +02001240static struct txq_info *ieee80211_get_txq(struct ieee80211_local *local,
1241 struct ieee80211_vif *vif,
1242 struct ieee80211_sta *pubsta,
1243 struct sk_buff *skb)
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001244{
1245 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001246 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001247 struct ieee80211_txq *txq = NULL;
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001248
Felix Fietkauc3732a72016-02-28 15:19:53 +01001249 if ((info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) ||
1250 (info->control.flags & IEEE80211_TX_CTRL_PS_RESPONSE))
Michal Kazior80a83cf2016-05-19 10:37:48 +02001251 return NULL;
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001252
1253 if (!ieee80211_is_data(hdr->frame_control))
Michal Kazior80a83cf2016-05-19 10:37:48 +02001254 return NULL;
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001255
1256 if (pubsta) {
1257 u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
1258
1259 txq = pubsta->txq[tid];
1260 } else if (vif) {
1261 txq = vif->txq;
1262 }
1263
1264 if (!txq)
Michal Kazior80a83cf2016-05-19 10:37:48 +02001265 return NULL;
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001266
Michal Kazior80a83cf2016-05-19 10:37:48 +02001267 return to_txq_info(txq);
1268}
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001269
Michal Kaziorfa962b92016-05-19 10:37:49 +02001270static struct sk_buff *fq_tin_dequeue_func(struct fq *fq,
1271 struct fq_tin *tin,
1272 struct fq_flow *flow)
1273{
1274 return fq_flow_dequeue(fq, flow);
1275}
1276
1277static void fq_skb_free_func(struct fq *fq,
1278 struct fq_tin *tin,
1279 struct fq_flow *flow,
1280 struct sk_buff *skb)
1281{
1282 struct ieee80211_local *local;
1283
1284 local = container_of(fq, struct ieee80211_local, fq);
1285 ieee80211_free_txskb(&local->hw, skb);
1286}
1287
1288static struct fq_flow *fq_flow_get_default_func(struct fq *fq,
1289 struct fq_tin *tin,
1290 int idx,
1291 struct sk_buff *skb)
1292{
1293 struct txq_info *txqi;
1294
1295 txqi = container_of(tin, struct txq_info, tin);
1296 return &txqi->def_flow;
1297}
1298
Michal Kazior80a83cf2016-05-19 10:37:48 +02001299static void ieee80211_txq_enqueue(struct ieee80211_local *local,
1300 struct txq_info *txqi,
1301 struct sk_buff *skb)
1302{
Michal Kaziorfa962b92016-05-19 10:37:49 +02001303 struct fq *fq = &local->fq;
1304 struct fq_tin *tin = &txqi->tin;
Michal Kazior80a83cf2016-05-19 10:37:48 +02001305
Michal Kaziorfa962b92016-05-19 10:37:49 +02001306 fq_tin_enqueue(fq, tin, skb,
1307 fq_skb_free_func,
1308 fq_flow_get_default_func);
1309}
Michal Kazior80a83cf2016-05-19 10:37:48 +02001310
Michal Kaziorfa962b92016-05-19 10:37:49 +02001311void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata,
1312 struct sta_info *sta,
1313 struct txq_info *txqi, int tid)
1314{
1315 fq_tin_init(&txqi->tin);
1316 fq_flow_init(&txqi->def_flow);
1317
1318 txqi->txq.vif = &sdata->vif;
1319
1320 if (sta) {
1321 txqi->txq.sta = &sta->sta;
1322 sta->sta.txq[tid] = &txqi->txq;
1323 txqi->txq.tid = tid;
1324 txqi->txq.ac = ieee802_1d_to_ac[tid & 7];
1325 } else {
1326 sdata->vif.txq = &txqi->txq;
1327 txqi->txq.tid = 0;
1328 txqi->txq.ac = IEEE80211_AC_BE;
Michal Kazior80a83cf2016-05-19 10:37:48 +02001329 }
Michal Kaziorfa962b92016-05-19 10:37:49 +02001330}
Michal Kazior80a83cf2016-05-19 10:37:48 +02001331
Michal Kaziorfa962b92016-05-19 10:37:49 +02001332void ieee80211_txq_purge(struct ieee80211_local *local,
1333 struct txq_info *txqi)
1334{
1335 struct fq *fq = &local->fq;
1336 struct fq_tin *tin = &txqi->tin;
1337
1338 fq_tin_reset(fq, tin, fq_skb_free_func);
1339}
1340
1341int ieee80211_txq_setup_flows(struct ieee80211_local *local)
1342{
1343 struct fq *fq = &local->fq;
1344 int ret;
1345
1346 if (!local->ops->wake_tx_queue)
1347 return 0;
1348
1349 ret = fq_init(fq, 4096);
1350 if (ret)
1351 return ret;
1352
1353 return 0;
1354}
1355
1356void ieee80211_txq_teardown_flows(struct ieee80211_local *local)
1357{
1358 struct fq *fq = &local->fq;
1359
1360 if (!local->ops->wake_tx_queue)
1361 return;
1362
1363 fq_reset(fq, fq_skb_free_func);
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001364}
1365
1366struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,
1367 struct ieee80211_txq *txq)
1368{
1369 struct ieee80211_local *local = hw_to_local(hw);
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001370 struct txq_info *txqi = container_of(txq, struct txq_info, txq);
1371 struct ieee80211_hdr *hdr;
1372 struct sk_buff *skb = NULL;
Michal Kaziorfa962b92016-05-19 10:37:49 +02001373 struct fq *fq = &local->fq;
1374 struct fq_tin *tin = &txqi->tin;
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001375
Michal Kaziorfa962b92016-05-19 10:37:49 +02001376 spin_lock_bh(&fq->lock);
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001377
1378 if (test_bit(IEEE80211_TXQ_STOP, &txqi->flags))
1379 goto out;
1380
Michal Kaziorfa962b92016-05-19 10:37:49 +02001381 skb = fq_tin_dequeue(fq, tin, fq_tin_dequeue_func);
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001382 if (!skb)
1383 goto out;
1384
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001385 hdr = (struct ieee80211_hdr *)skb->data;
1386 if (txq->sta && ieee80211_is_data_qos(hdr->frame_control)) {
1387 struct sta_info *sta = container_of(txq->sta, struct sta_info,
1388 sta);
1389 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1390
1391 hdr->seq_ctrl = ieee80211_tx_next_seq(sta, txq->tid);
1392 if (test_bit(IEEE80211_TXQ_AMPDU, &txqi->flags))
1393 info->flags |= IEEE80211_TX_CTL_AMPDU;
1394 else
1395 info->flags &= ~IEEE80211_TX_CTL_AMPDU;
1396 }
1397
1398out:
Michal Kaziorfa962b92016-05-19 10:37:49 +02001399 spin_unlock_bh(&fq->lock);
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001400
Felix Fietkau6e0456b2016-03-03 22:59:00 +01001401 if (skb && skb_has_frag_list(skb) &&
1402 !ieee80211_hw_check(&local->hw, TX_FRAG_LIST))
1403 skb_linearize(skb);
1404
Felix Fietkauba8c3d62015-03-27 21:30:37 +01001405 return skb;
1406}
1407EXPORT_SYMBOL(ieee80211_tx_dequeue);
1408
Johannes Berg11127e92011-11-16 16:02:47 +01001409static bool ieee80211_tx_frags(struct ieee80211_local *local,
1410 struct ieee80211_vif *vif,
1411 struct ieee80211_sta *sta,
1412 struct sk_buff_head *skbs,
1413 bool txpending)
Johannes Berge2ebc742007-07-27 15:43:22 +02001414{
Michal Kazior80a83cf2016-05-19 10:37:48 +02001415 struct ieee80211_tx_control control = {};
Michal Kaziorfa962b92016-05-19 10:37:49 +02001416 struct fq *fq = &local->fq;
Johannes Berg252b86c2011-11-16 15:28:55 +01001417 struct sk_buff *skb, *tmp;
Michal Kazior80a83cf2016-05-19 10:37:48 +02001418 struct txq_info *txqi;
Johannes Berg3b8d81e02009-06-17 17:43:56 +02001419 unsigned long flags;
Johannes Berge2ebc742007-07-27 15:43:22 +02001420
Johannes Berg252b86c2011-11-16 15:28:55 +01001421 skb_queue_walk_safe(skbs, skb, tmp) {
Johannes Berg3a25a8c2012-04-03 16:28:50 +02001422 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1423 int q = info->hw_queue;
1424
1425#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1426 if (WARN_ON_ONCE(q >= local->hw.queues)) {
1427 __skb_unlink(skb, skbs);
Felix Fietkauc3e77242012-10-08 14:39:33 +02001428 ieee80211_free_txskb(&local->hw, skb);
Johannes Berg3a25a8c2012-04-03 16:28:50 +02001429 continue;
1430 }
1431#endif
Johannes Berg3b8d81e02009-06-17 17:43:56 +02001432
Michal Kazior80a83cf2016-05-19 10:37:48 +02001433 txqi = ieee80211_get_txq(local, vif, sta, skb);
1434 if (txqi) {
1435 info->control.vif = vif;
1436
1437 __skb_unlink(skb, skbs);
1438
Michal Kaziorfa962b92016-05-19 10:37:49 +02001439 spin_lock_bh(&fq->lock);
Michal Kazior80a83cf2016-05-19 10:37:48 +02001440 ieee80211_txq_enqueue(local, txqi, skb);
Michal Kaziorfa962b92016-05-19 10:37:49 +02001441 spin_unlock_bh(&fq->lock);
Michal Kazior80a83cf2016-05-19 10:37:48 +02001442
1443 drv_wake_tx_queue(local, txqi);
1444
1445 continue;
1446 }
1447
Johannes Berg3b8d81e02009-06-17 17:43:56 +02001448 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
Johannes Berg3b8d81e02009-06-17 17:43:56 +02001449 if (local->queue_stop_reasons[q] ||
Johannes Berg7bb45682011-02-24 14:42:06 +01001450 (!txpending && !skb_queue_empty(&local->pending[q]))) {
Seth Forshee6c17b772013-02-11 11:21:07 -06001451 if (unlikely(info->flags &
Seth Forsheea7679ed2013-02-25 14:58:05 -06001452 IEEE80211_TX_INTFL_OFFCHAN_TX_OK)) {
1453 if (local->queue_stop_reasons[q] &
1454 ~BIT(IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL)) {
1455 /*
1456 * Drop off-channel frames if queues
1457 * are stopped for any reason other
1458 * than off-channel operation. Never
1459 * queue them.
1460 */
1461 spin_unlock_irqrestore(
1462 &local->queue_stop_reason_lock,
1463 flags);
1464 ieee80211_purge_tx_queue(&local->hw,
1465 skbs);
1466 return true;
1467 }
1468 } else {
1469
Seth Forshee6c17b772013-02-11 11:21:07 -06001470 /*
Seth Forsheea7679ed2013-02-25 14:58:05 -06001471 * Since queue is stopped, queue up frames for
1472 * later transmission from the tx-pending
1473 * tasklet when the queue is woken again.
Seth Forshee6c17b772013-02-11 11:21:07 -06001474 */
Seth Forsheea7679ed2013-02-25 14:58:05 -06001475 if (txpending)
1476 skb_queue_splice_init(skbs,
1477 &local->pending[q]);
1478 else
1479 skb_queue_splice_tail_init(skbs,
1480 &local->pending[q]);
1481
1482 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1483 flags);
1484 return false;
Seth Forshee6c17b772013-02-11 11:21:07 -06001485 }
Johannes Berg7bb45682011-02-24 14:42:06 +01001486 }
Johannes Berg3b8d81e02009-06-17 17:43:56 +02001487 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
Tomas Winklerf8e79dd2008-07-24 18:46:44 +03001488
Johannes Berg11127e92011-11-16 16:02:47 +01001489 info->control.vif = vif;
Michal Kazior80a83cf2016-05-19 10:37:48 +02001490 control.sta = sta;
Johannes Bergec25acc2010-07-22 17:11:28 +02001491
Johannes Berg252b86c2011-11-16 15:28:55 +01001492 __skb_unlink(skb, skbs);
Michal Kazior80a83cf2016-05-19 10:37:48 +02001493 drv_tx(local, &control, skb);
Johannes Berge2ebc742007-07-27 15:43:22 +02001494 }
Johannes Berg2de8e0d2009-03-23 17:28:35 +01001495
Johannes Berg11127e92011-11-16 16:02:47 +01001496 return true;
1497}
1498
1499/*
1500 * Returns false if the frame couldn't be transmitted but was queued instead.
1501 */
1502static bool __ieee80211_tx(struct ieee80211_local *local,
1503 struct sk_buff_head *skbs, int led_len,
1504 struct sta_info *sta, bool txpending)
1505{
1506 struct ieee80211_tx_info *info;
1507 struct ieee80211_sub_if_data *sdata;
1508 struct ieee80211_vif *vif;
1509 struct ieee80211_sta *pubsta;
1510 struct sk_buff *skb;
1511 bool result = true;
1512 __le16 fc;
1513
1514 if (WARN_ON(skb_queue_empty(skbs)))
1515 return true;
1516
1517 skb = skb_peek(skbs);
1518 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
1519 info = IEEE80211_SKB_CB(skb);
1520 sdata = vif_to_sdata(info->control.vif);
1521 if (sta && !sta->uploaded)
1522 sta = NULL;
1523
1524 if (sta)
1525 pubsta = &sta->sta;
1526 else
1527 pubsta = NULL;
1528
1529 switch (sdata->vif.type) {
1530 case NL80211_IFTYPE_MONITOR:
Johannes Bergc82b5a72013-07-14 23:39:20 +03001531 if (sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE) {
1532 vif = &sdata->vif;
1533 break;
1534 }
Johannes Berg4b6f1dd2012-04-03 14:35:57 +02001535 sdata = rcu_dereference(local->monitor_sdata);
Johannes Berg3a25a8c2012-04-03 16:28:50 +02001536 if (sdata) {
Johannes Berg4b6f1dd2012-04-03 14:35:57 +02001537 vif = &sdata->vif;
Johannes Berg3a25a8c2012-04-03 16:28:50 +02001538 info->hw_queue =
1539 vif->hw_queue[skb_get_queue_mapping(skb)];
Johannes Berg30686bf2015-06-02 21:39:54 +02001540 } else if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) {
Johannes Berg63b4d8b2015-11-24 15:41:50 +01001541 ieee80211_purge_tx_queue(&local->hw, skbs);
Johannes Berg3a25a8c2012-04-03 16:28:50 +02001542 return true;
1543 } else
Johannes Berg4b6f1dd2012-04-03 14:35:57 +02001544 vif = NULL;
Johannes Berg11127e92011-11-16 16:02:47 +01001545 break;
1546 case NL80211_IFTYPE_AP_VLAN:
1547 sdata = container_of(sdata->bss,
1548 struct ieee80211_sub_if_data, u.ap);
1549 /* fall through */
1550 default:
1551 vif = &sdata->vif;
1552 break;
1553 }
1554
Johannes Bergcb831b52012-07-02 15:40:18 +02001555 result = ieee80211_tx_frags(local, vif, pubsta, skbs,
1556 txpending);
Johannes Berg11127e92011-11-16 16:02:47 +01001557
Johannes Berg74e4dbf2011-11-16 15:28:57 +01001558 ieee80211_tpt_led_trig_tx(local, fc, led_len);
Johannes Berg74e4dbf2011-11-16 15:28:57 +01001559
Johannes Berg4db4e0a2011-11-24 14:47:36 +01001560 WARN_ON_ONCE(!skb_queue_empty(skbs));
Johannes Berg252b86c2011-11-16 15:28:55 +01001561
Johannes Berg11127e92011-11-16 16:02:47 +01001562 return result;
Johannes Berge2ebc742007-07-27 15:43:22 +02001563}
1564
Johannes Berg97b045d2008-06-20 01:22:30 +02001565/*
1566 * Invoke TX handlers, return 0 on success and non-zero if the
1567 * frame was dropped or queued.
1568 */
1569static int invoke_tx_handlers(struct ieee80211_tx_data *tx)
1570{
Johannes Berg252b86c2011-11-16 15:28:55 +01001571 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
Johannes Berg97b045d2008-06-20 01:22:30 +02001572 ieee80211_tx_result res = TX_DROP;
Johannes Berg97b045d2008-06-20 01:22:30 +02001573
Johannes Berg9aa4aee2009-10-29 08:43:48 +01001574#define CALL_TXH(txh) \
1575 do { \
1576 res = txh(tx); \
1577 if (res != TX_CONTINUE) \
1578 goto txh_done; \
1579 } while (0)
Johannes Berg97b045d2008-06-20 01:22:30 +02001580
Kalle Valo5c1b98a2010-01-12 10:42:46 +02001581 CALL_TXH(ieee80211_tx_h_dynamic_ps);
Johannes Berg9aa4aee2009-10-29 08:43:48 +01001582 CALL_TXH(ieee80211_tx_h_check_assoc);
1583 CALL_TXH(ieee80211_tx_h_ps_buf);
Johannes Berga621fa42010-08-27 14:26:54 +03001584 CALL_TXH(ieee80211_tx_h_check_control_port_protocol);
Johannes Berg9aa4aee2009-10-29 08:43:48 +01001585 CALL_TXH(ieee80211_tx_h_select_key);
Johannes Berg30686bf2015-06-02 21:39:54 +02001586 if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL))
Johannes Bergaf65cd962009-11-17 18:18:36 +01001587 CALL_TXH(ieee80211_tx_h_rate_ctrl);
Johannes Bergc6fcf6b2010-01-17 01:47:59 +01001588
Johannes Bergaa5b5492011-12-02 22:08:52 +01001589 if (unlikely(info->flags & IEEE80211_TX_INTFL_RETRANSMISSION)) {
1590 __skb_queue_tail(&tx->skbs, tx->skb);
1591 tx->skb = NULL;
Johannes Bergc6fcf6b2010-01-17 01:47:59 +01001592 goto txh_done;
Johannes Bergaa5b5492011-12-02 22:08:52 +01001593 }
Johannes Bergc6fcf6b2010-01-17 01:47:59 +01001594
1595 CALL_TXH(ieee80211_tx_h_michael_mic_add);
Johannes Berg9aa4aee2009-10-29 08:43:48 +01001596 CALL_TXH(ieee80211_tx_h_sequence);
1597 CALL_TXH(ieee80211_tx_h_fragment);
Johannes Bergd9e8a702008-06-30 15:10:44 +02001598 /* handlers after fragment must be aware of tx info fragmentation! */
Johannes Berg9aa4aee2009-10-29 08:43:48 +01001599 CALL_TXH(ieee80211_tx_h_stats);
1600 CALL_TXH(ieee80211_tx_h_encrypt);
Johannes Berg30686bf2015-06-02 21:39:54 +02001601 if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL))
Arik Nemtsov8fd369e2011-01-31 22:29:12 +02001602 CALL_TXH(ieee80211_tx_h_calculate_duration);
Johannes Bergd9e8a702008-06-30 15:10:44 +02001603#undef CALL_TXH
1604
1605 txh_done:
Johannes Berg97b045d2008-06-20 01:22:30 +02001606 if (unlikely(res == TX_DROP)) {
Tomas Winkler5479d0e2008-06-28 03:15:03 +03001607 I802_DEBUG_INC(tx->local->tx_handlers_drop);
Johannes Berg252b86c2011-11-16 15:28:55 +01001608 if (tx->skb)
Felix Fietkauc3e77242012-10-08 14:39:33 +02001609 ieee80211_free_txskb(&tx->local->hw, tx->skb);
Johannes Berg252b86c2011-11-16 15:28:55 +01001610 else
Felix Fietkau1f98ab72012-11-10 03:44:14 +01001611 ieee80211_purge_tx_queue(&tx->local->hw, &tx->skbs);
Johannes Berg97b045d2008-06-20 01:22:30 +02001612 return -1;
1613 } else if (unlikely(res == TX_QUEUED)) {
Tomas Winkler5479d0e2008-06-28 03:15:03 +03001614 I802_DEBUG_INC(tx->local->tx_handlers_queued);
Johannes Berg97b045d2008-06-20 01:22:30 +02001615 return -1;
1616 }
1617
1618 return 0;
1619}
1620
Felix Fietkau06be6b12013-10-14 18:01:00 +02001621bool ieee80211_tx_prepare_skb(struct ieee80211_hw *hw,
1622 struct ieee80211_vif *vif, struct sk_buff *skb,
1623 int band, struct ieee80211_sta **sta)
1624{
1625 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1626 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1627 struct ieee80211_tx_data tx;
Johannes Berg88724a82015-03-01 09:10:12 +02001628 struct sk_buff *skb2;
Felix Fietkau06be6b12013-10-14 18:01:00 +02001629
Johannes Berg7c107702015-03-20 14:18:27 +01001630 if (ieee80211_tx_prepare(sdata, &tx, NULL, skb) == TX_DROP)
Felix Fietkau06be6b12013-10-14 18:01:00 +02001631 return false;
1632
1633 info->band = band;
1634 info->control.vif = vif;
1635 info->hw_queue = vif->hw_queue[skb_get_queue_mapping(skb)];
1636
1637 if (invoke_tx_handlers(&tx))
1638 return false;
1639
1640 if (sta) {
1641 if (tx.sta)
1642 *sta = &tx.sta->sta;
1643 else
1644 *sta = NULL;
1645 }
1646
Johannes Berg88724a82015-03-01 09:10:12 +02001647 /* this function isn't suitable for fragmented data frames */
1648 skb2 = __skb_dequeue(&tx.skbs);
1649 if (WARN_ON(skb2 != skb || !skb_queue_empty(&tx.skbs))) {
1650 ieee80211_free_txskb(hw, skb2);
1651 ieee80211_purge_tx_queue(hw, &tx.skbs);
1652 return false;
1653 }
1654
Felix Fietkau06be6b12013-10-14 18:01:00 +02001655 return true;
1656}
1657EXPORT_SYMBOL(ieee80211_tx_prepare_skb);
1658
Johannes Berg7bb45682011-02-24 14:42:06 +01001659/*
1660 * Returns false if the frame couldn't be transmitted but was queued instead.
1661 */
1662static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata,
Johannes Berg7c107702015-03-20 14:18:27 +01001663 struct sta_info *sta, struct sk_buff *skb,
1664 bool txpending)
Johannes Berge2ebc742007-07-27 15:43:22 +02001665{
Johannes Berg3b8d81e02009-06-17 17:43:56 +02001666 struct ieee80211_local *local = sdata->local;
Johannes Berg5cf121c2008-02-25 16:27:43 +01001667 struct ieee80211_tx_data tx;
Johannes Berg97b045d2008-06-20 01:22:30 +02001668 ieee80211_tx_result res_prepare;
Johannes Berge039fa42008-05-15 12:55:29 +02001669 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Johannes Berg7bb45682011-02-24 14:42:06 +01001670 bool result = true;
Johannes Berg74e4dbf2011-11-16 15:28:57 +01001671 int led_len;
Johannes Berge2ebc742007-07-27 15:43:22 +02001672
Johannes Berge2ebc742007-07-27 15:43:22 +02001673 if (unlikely(skb->len < 10)) {
1674 dev_kfree_skb(skb);
Johannes Berg7bb45682011-02-24 14:42:06 +01001675 return true;
Johannes Berge2ebc742007-07-27 15:43:22 +02001676 }
1677
Johannes Berg58d41852007-09-26 17:53:18 +02001678 /* initialises tx */
Johannes Berg74e4dbf2011-11-16 15:28:57 +01001679 led_len = skb->len;
Johannes Berg7c107702015-03-20 14:18:27 +01001680 res_prepare = ieee80211_tx_prepare(sdata, &tx, sta, skb);
Johannes Berge2ebc742007-07-27 15:43:22 +02001681
Johannes Bergcd8ffc82009-03-23 17:28:41 +01001682 if (unlikely(res_prepare == TX_DROP)) {
Felix Fietkauc3e77242012-10-08 14:39:33 +02001683 ieee80211_free_txskb(&local->hw, skb);
Johannes Berg55de9082012-07-26 17:24:39 +02001684 return true;
Johannes Bergcd8ffc82009-03-23 17:28:41 +01001685 } else if (unlikely(res_prepare == TX_QUEUED)) {
Johannes Berg55de9082012-07-26 17:24:39 +02001686 return true;
Johannes Berge2ebc742007-07-27 15:43:22 +02001687 }
1688
Johannes Berg3a25a8c2012-04-03 16:28:50 +02001689 /* set up hw_queue value early */
1690 if (!(info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) ||
Johannes Berg30686bf2015-06-02 21:39:54 +02001691 !ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
Johannes Berg3a25a8c2012-04-03 16:28:50 +02001692 info->hw_queue =
1693 sdata->vif.hw_queue[skb_get_queue_mapping(skb)];
1694
Johannes Berg7bb45682011-02-24 14:42:06 +01001695 if (!invoke_tx_handlers(&tx))
Johannes Berg74e4dbf2011-11-16 15:28:57 +01001696 result = __ieee80211_tx(local, &tx.skbs, led_len,
1697 tx.sta, txpending);
Johannes Berg55de9082012-07-26 17:24:39 +02001698
Johannes Berg7bb45682011-02-24 14:42:06 +01001699 return result;
Johannes Berge2ebc742007-07-27 15:43:22 +02001700}
1701
1702/* device xmit handlers */
1703
Yogesh Ashok Powar3bff1862011-06-28 18:41:37 +05301704static int ieee80211_skb_resize(struct ieee80211_sub_if_data *sdata,
Johannes Berg23c07522008-05-29 10:38:53 +02001705 struct sk_buff *skb,
1706 int head_need, bool may_encrypt)
1707{
Yogesh Ashok Powar3bff1862011-06-28 18:41:37 +05301708 struct ieee80211_local *local = sdata->local;
Johannes Berg23c07522008-05-29 10:38:53 +02001709 int tail_need = 0;
1710
Yogesh Ashok Powar3bff1862011-06-28 18:41:37 +05301711 if (may_encrypt && sdata->crypto_tx_tailroom_needed_cnt) {
Johannes Berg23c07522008-05-29 10:38:53 +02001712 tail_need = IEEE80211_ENCRYPT_TAILROOM;
1713 tail_need -= skb_tailroom(skb);
1714 tail_need = max_t(int, tail_need, 0);
1715 }
1716
Ido Yarivc70f59a2014-07-29 15:39:14 +03001717 if (skb_cloned(skb) &&
Johannes Berg30686bf2015-06-02 21:39:54 +02001718 (!ieee80211_hw_check(&local->hw, SUPPORTS_CLONED_SKBS) ||
Ido Yarivc70f59a2014-07-29 15:39:14 +03001719 !skb_clone_writable(skb, ETH_HLEN) ||
Johannes Berg17c18bf2015-03-21 15:25:43 +01001720 (may_encrypt && sdata->crypto_tx_tailroom_needed_cnt)))
Johannes Berg23c07522008-05-29 10:38:53 +02001721 I802_DEBUG_INC(local->tx_expand_skb_head_cloned);
Felix Fietkau4cd06a32010-12-18 19:30:49 +01001722 else if (head_need || tail_need)
Johannes Berg23c07522008-05-29 10:38:53 +02001723 I802_DEBUG_INC(local->tx_expand_skb_head);
Felix Fietkau4cd06a32010-12-18 19:30:49 +01001724 else
1725 return 0;
Johannes Berg23c07522008-05-29 10:38:53 +02001726
1727 if (pskb_expand_head(skb, head_need, tail_need, GFP_ATOMIC)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001728 wiphy_debug(local->hw.wiphy,
1729 "failed to reallocate TX buffer\n");
Johannes Berg23c07522008-05-29 10:38:53 +02001730 return -ENOMEM;
1731 }
1732
Johannes Berg23c07522008-05-29 10:38:53 +02001733 return 0;
1734}
1735
Johannes Berg7c107702015-03-20 14:18:27 +01001736void ieee80211_xmit(struct ieee80211_sub_if_data *sdata,
1737 struct sta_info *sta, struct sk_buff *skb)
Johannes Berge2ebc742007-07-27 15:43:22 +02001738{
Johannes Berg3b8d81e02009-06-17 17:43:56 +02001739 struct ieee80211_local *local = sdata->local;
Johannes Berge039fa42008-05-15 12:55:29 +02001740 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +02001741 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
Johannes Berge2ebc742007-07-27 15:43:22 +02001742 int headroom;
Johannes Berg23c07522008-05-29 10:38:53 +02001743 bool may_encrypt;
Johannes Berge2ebc742007-07-27 15:43:22 +02001744
Johannes Berg3b8d81e02009-06-17 17:43:56 +02001745 may_encrypt = !(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT);
Johannes Berg23c07522008-05-29 10:38:53 +02001746
Johannes Berg3b8d81e02009-06-17 17:43:56 +02001747 headroom = local->tx_headroom;
Johannes Berg23c07522008-05-29 10:38:53 +02001748 if (may_encrypt)
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001749 headroom += sdata->encrypt_headroom;
Johannes Berg23c07522008-05-29 10:38:53 +02001750 headroom -= skb_headroom(skb);
1751 headroom = max_t(int, 0, headroom);
1752
Yogesh Ashok Powar3bff1862011-06-28 18:41:37 +05301753 if (ieee80211_skb_resize(sdata, skb, headroom, may_encrypt)) {
Felix Fietkauc3e77242012-10-08 14:39:33 +02001754 ieee80211_free_txskb(&local->hw, skb);
Johannes Berg3b8d81e02009-06-17 17:43:56 +02001755 return;
Johannes Berge2ebc742007-07-27 15:43:22 +02001756 }
1757
Steve deRosier740c1aa2010-09-11 20:01:31 -07001758 hdr = (struct ieee80211_hdr *) skb->data;
Johannes Berg5061b0c2009-07-14 00:33:34 +02001759 info->control.vif = &sdata->vif;
Johannes Bergcd8ffc82009-03-23 17:28:41 +01001760
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001761 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1762 if (ieee80211_is_data(hdr->frame_control) &&
1763 is_unicast_ether_addr(hdr->addr1)) {
Johannes Bergbf7cd942013-02-15 14:40:31 +01001764 if (mesh_nexthop_resolve(sdata, skb))
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001765 return; /* skb queued: don't free */
1766 } else {
1767 ieee80211_mps_set_frame_flags(sdata, NULL, hdr);
1768 }
Johannes Berg98aed9f2012-03-27 14:18:36 +02001769 }
Javier Cardonacca89492009-08-10 17:29:29 -07001770
Javier Cardona2154c81c2011-09-07 17:49:53 -07001771 ieee80211_set_qos_hdr(sdata, skb);
Johannes Berg7c107702015-03-20 14:18:27 +01001772 ieee80211_tx(sdata, sta, skb, false);
Johannes Berge2ebc742007-07-27 15:43:22 +02001773}
1774
Sven Eckelmanndfdfc2b2016-01-26 17:11:13 +01001775static bool ieee80211_parse_tx_radiotap(struct ieee80211_local *local,
1776 struct sk_buff *skb)
Johannes Berg73b9f032011-10-07 14:01:26 +02001777{
1778 struct ieee80211_radiotap_iterator iterator;
1779 struct ieee80211_radiotap_header *rthdr =
1780 (struct ieee80211_radiotap_header *) skb->data;
1781 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Sven Eckelmanndfdfc2b2016-01-26 17:11:13 +01001782 struct ieee80211_supported_band *sband =
1783 local->hw.wiphy->bands[info->band];
Johannes Berg73b9f032011-10-07 14:01:26 +02001784 int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len,
1785 NULL);
1786 u16 txflags;
Sven Eckelmanndfdfc2b2016-01-26 17:11:13 +01001787 u16 rate = 0;
1788 bool rate_found = false;
1789 u8 rate_retries = 0;
1790 u16 rate_flags = 0;
Sven Eckelmannf66b60f2016-02-24 16:25:49 +01001791 u8 mcs_known, mcs_flags, mcs_bw;
Lorenzo Bianconi646e76b2016-02-23 15:43:35 +01001792 u16 vht_known;
1793 u8 vht_mcs = 0, vht_nss = 0;
Sven Eckelmanndfdfc2b2016-01-26 17:11:13 +01001794 int i;
Johannes Berg73b9f032011-10-07 14:01:26 +02001795
1796 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
1797 IEEE80211_TX_CTL_DONTFRAG;
1798
1799 /*
1800 * for every radiotap entry that is present
1801 * (ieee80211_radiotap_iterator_next returns -ENOENT when no more
1802 * entries present, or -EINVAL on error)
1803 */
1804
1805 while (!ret) {
1806 ret = ieee80211_radiotap_iterator_next(&iterator);
1807
1808 if (ret)
1809 continue;
1810
1811 /* see if this argument is something we can use */
1812 switch (iterator.this_arg_index) {
1813 /*
1814 * You must take care when dereferencing iterator.this_arg
1815 * for multibyte types... the pointer is not aligned. Use
1816 * get_unaligned((type *)iterator.this_arg) to dereference
1817 * iterator.this_arg for type "type" safely on all arches.
1818 */
1819 case IEEE80211_RADIOTAP_FLAGS:
1820 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) {
1821 /*
1822 * this indicates that the skb we have been
1823 * handed has the 32-bit FCS CRC at the end...
1824 * we should react to that by snipping it off
1825 * because it will be recomputed and added
1826 * on transmission
1827 */
1828 if (skb->len < (iterator._max_length + FCS_LEN))
1829 return false;
1830
1831 skb_trim(skb, skb->len - FCS_LEN);
1832 }
1833 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_WEP)
1834 info->flags &= ~IEEE80211_TX_INTFL_DONT_ENCRYPT;
1835 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG)
1836 info->flags &= ~IEEE80211_TX_CTL_DONTFRAG;
1837 break;
1838
1839 case IEEE80211_RADIOTAP_TX_FLAGS:
1840 txflags = get_unaligned_le16(iterator.this_arg);
1841 if (txflags & IEEE80211_RADIOTAP_F_TX_NOACK)
1842 info->flags |= IEEE80211_TX_CTL_NO_ACK;
1843 break;
1844
Sven Eckelmanndfdfc2b2016-01-26 17:11:13 +01001845 case IEEE80211_RADIOTAP_RATE:
1846 rate = *iterator.this_arg;
1847 rate_flags = 0;
1848 rate_found = true;
1849 break;
1850
1851 case IEEE80211_RADIOTAP_DATA_RETRIES:
1852 rate_retries = *iterator.this_arg;
1853 break;
1854
1855 case IEEE80211_RADIOTAP_MCS:
1856 mcs_known = iterator.this_arg[0];
1857 mcs_flags = iterator.this_arg[1];
1858 if (!(mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_MCS))
1859 break;
1860
1861 rate_found = true;
1862 rate = iterator.this_arg[2];
1863 rate_flags = IEEE80211_TX_RC_MCS;
1864
1865 if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_GI &&
1866 mcs_flags & IEEE80211_RADIOTAP_MCS_SGI)
1867 rate_flags |= IEEE80211_TX_RC_SHORT_GI;
1868
Sven Eckelmannf66b60f2016-02-24 16:25:49 +01001869 mcs_bw = mcs_flags & IEEE80211_RADIOTAP_MCS_BW_MASK;
Sven Eckelmanndfdfc2b2016-01-26 17:11:13 +01001870 if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_BW &&
Sven Eckelmannf66b60f2016-02-24 16:25:49 +01001871 mcs_bw == IEEE80211_RADIOTAP_MCS_BW_40)
Sven Eckelmanndfdfc2b2016-01-26 17:11:13 +01001872 rate_flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
1873 break;
1874
Lorenzo Bianconi646e76b2016-02-23 15:43:35 +01001875 case IEEE80211_RADIOTAP_VHT:
1876 vht_known = get_unaligned_le16(iterator.this_arg);
1877 rate_found = true;
1878
1879 rate_flags = IEEE80211_TX_RC_VHT_MCS;
1880 if ((vht_known & IEEE80211_RADIOTAP_VHT_KNOWN_GI) &&
1881 (iterator.this_arg[2] &
1882 IEEE80211_RADIOTAP_VHT_FLAG_SGI))
1883 rate_flags |= IEEE80211_TX_RC_SHORT_GI;
1884 if (vht_known &
1885 IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH) {
1886 if (iterator.this_arg[3] == 1)
1887 rate_flags |=
1888 IEEE80211_TX_RC_40_MHZ_WIDTH;
1889 else if (iterator.this_arg[3] == 4)
1890 rate_flags |=
1891 IEEE80211_TX_RC_80_MHZ_WIDTH;
1892 else if (iterator.this_arg[3] == 11)
1893 rate_flags |=
1894 IEEE80211_TX_RC_160_MHZ_WIDTH;
1895 }
1896
1897 vht_mcs = iterator.this_arg[4] >> 4;
1898 vht_nss = iterator.this_arg[4] & 0xF;
1899 break;
1900
Johannes Berg73b9f032011-10-07 14:01:26 +02001901 /*
1902 * Please update the file
1903 * Documentation/networking/mac80211-injection.txt
1904 * when parsing new fields here.
1905 */
1906
1907 default:
1908 break;
1909 }
1910 }
1911
1912 if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */
1913 return false;
1914
Sven Eckelmanndfdfc2b2016-01-26 17:11:13 +01001915 if (rate_found) {
1916 info->control.flags |= IEEE80211_TX_CTRL_RATE_INJECT;
1917
1918 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
1919 info->control.rates[i].idx = -1;
1920 info->control.rates[i].flags = 0;
1921 info->control.rates[i].count = 0;
1922 }
1923
1924 if (rate_flags & IEEE80211_TX_RC_MCS) {
1925 info->control.rates[0].idx = rate;
Lorenzo Bianconi646e76b2016-02-23 15:43:35 +01001926 } else if (rate_flags & IEEE80211_TX_RC_VHT_MCS) {
1927 ieee80211_rate_set_vht(info->control.rates, vht_mcs,
1928 vht_nss);
Sven Eckelmanndfdfc2b2016-01-26 17:11:13 +01001929 } else {
1930 for (i = 0; i < sband->n_bitrates; i++) {
1931 if (rate * 5 != sband->bitrates[i].bitrate)
1932 continue;
1933
1934 info->control.rates[0].idx = i;
1935 break;
1936 }
1937 }
1938
Felix Fietkau07310a62016-03-02 15:54:51 +01001939 if (info->control.rates[0].idx < 0)
1940 info->control.flags &= ~IEEE80211_TX_CTRL_RATE_INJECT;
1941
Sven Eckelmanndfdfc2b2016-01-26 17:11:13 +01001942 info->control.rates[0].flags = rate_flags;
1943 info->control.rates[0].count = min_t(u8, rate_retries + 1,
1944 local->hw.max_rate_tries);
1945 }
1946
Johannes Berg73b9f032011-10-07 14:01:26 +02001947 /*
1948 * remove the radiotap header
1949 * iterator->_max_length was sanity-checked against
1950 * skb->len by iterator init
1951 */
1952 skb_pull(skb, iterator._max_length);
1953
1954 return true;
1955}
1956
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +00001957netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
1958 struct net_device *dev)
Johannes Berge2ebc742007-07-27 15:43:22 +02001959{
1960 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg55de9082012-07-26 17:24:39 +02001961 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berge2ebc742007-07-27 15:43:22 +02001962 struct ieee80211_radiotap_header *prthdr =
1963 (struct ieee80211_radiotap_header *)skb->data;
Johannes Berg3b8d81e02009-06-17 17:43:56 +02001964 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Helmut Schaaf75f5c62011-08-01 11:32:52 +02001965 struct ieee80211_hdr *hdr;
Johannes Berg5d9cf4a2011-10-07 14:01:23 +02001966 struct ieee80211_sub_if_data *tmp_sdata, *sdata;
Janusz Dziedzicb4932832014-06-05 08:12:57 +02001967 struct cfg80211_chan_def *chandef;
Andy Green9b8a74e2007-07-27 15:43:24 +02001968 u16 len_rthdr;
Johannes Berg5d9cf4a2011-10-07 14:01:23 +02001969 int hdrlen;
Johannes Berge2ebc742007-07-27 15:43:22 +02001970
Andy Green9b8a74e2007-07-27 15:43:24 +02001971 /* check for not even having the fixed radiotap header part */
1972 if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
1973 goto fail; /* too short to be possibly valid */
1974
1975 /* is it a header version we can trust to find length from? */
1976 if (unlikely(prthdr->it_version))
1977 goto fail; /* only version 0 is supported */
1978
1979 /* then there must be a radiotap header with a length we can use */
1980 len_rthdr = ieee80211_get_radiotap_len(skb->data);
1981
1982 /* does the skb contain enough to deliver on the alleged length? */
1983 if (unlikely(skb->len < len_rthdr))
1984 goto fail; /* skb too short for claimed rt header extent */
Johannes Berge2ebc742007-07-27 15:43:22 +02001985
Johannes Berge2ebc742007-07-27 15:43:22 +02001986 /*
1987 * fix up the pointers accounting for the radiotap
1988 * header still being in there. We are being given
1989 * a precooked IEEE80211 header so no need for
1990 * normal processing
1991 */
Andy Green9b8a74e2007-07-27 15:43:24 +02001992 skb_set_mac_header(skb, len_rthdr);
Johannes Berge2ebc742007-07-27 15:43:22 +02001993 /*
Andy Green9b8a74e2007-07-27 15:43:24 +02001994 * these are just fixed to the end of the rt area since we
1995 * don't have any better information and at this point, nobody cares
Johannes Berge2ebc742007-07-27 15:43:22 +02001996 */
Andy Green9b8a74e2007-07-27 15:43:24 +02001997 skb_set_network_header(skb, len_rthdr);
1998 skb_set_transport_header(skb, len_rthdr);
Johannes Berge2ebc742007-07-27 15:43:22 +02001999
Johannes Berg5d9cf4a2011-10-07 14:01:23 +02002000 if (skb->len < len_rthdr + 2)
2001 goto fail;
2002
2003 hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
2004 hdrlen = ieee80211_hdrlen(hdr->frame_control);
2005
2006 if (skb->len < len_rthdr + hdrlen)
2007 goto fail;
2008
Helmut Schaaf75f5c62011-08-01 11:32:52 +02002009 /*
2010 * Initialize skb->protocol if the injected frame is a data frame
2011 * carrying a rfc1042 header
2012 */
Johannes Berg5d9cf4a2011-10-07 14:01:23 +02002013 if (ieee80211_is_data(hdr->frame_control) &&
2014 skb->len >= len_rthdr + hdrlen + sizeof(rfc1042_header) + 2) {
2015 u8 *payload = (u8 *)hdr + hdrlen;
2016
Joe Perchesb203ca32012-05-08 18:56:52 +00002017 if (ether_addr_equal(payload, rfc1042_header))
Johannes Berg5d9cf4a2011-10-07 14:01:23 +02002018 skb->protocol = cpu_to_be16((payload[6] << 8) |
2019 payload[7]);
Helmut Schaaf75f5c62011-08-01 11:32:52 +02002020 }
2021
Johannes Berg3b8d81e02009-06-17 17:43:56 +02002022 memset(info, 0, sizeof(*info));
2023
Johannes Berg5d9cf4a2011-10-07 14:01:23 +02002024 info->flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
Johannes Berg73b9f032011-10-07 14:01:26 +02002025 IEEE80211_TX_CTL_INJECTED;
2026
Johannes Berg5d9cf4a2011-10-07 14:01:23 +02002027 rcu_read_lock();
2028
2029 /*
2030 * We process outgoing injected frames that have a local address
2031 * we handle as though they are non-injected frames.
2032 * This code here isn't entirely correct, the local MAC address
2033 * isn't always enough to find the interface to use; for proper
2034 * VLAN/WDS support we will need a different mechanism (which
2035 * likely isn't going to be monitor interfaces).
2036 */
2037 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2038
2039 list_for_each_entry_rcu(tmp_sdata, &local->interfaces, list) {
2040 if (!ieee80211_sdata_running(tmp_sdata))
2041 continue;
2042 if (tmp_sdata->vif.type == NL80211_IFTYPE_MONITOR ||
2043 tmp_sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
2044 tmp_sdata->vif.type == NL80211_IFTYPE_WDS)
2045 continue;
Joe Perchesb203ca32012-05-08 18:56:52 +00002046 if (ether_addr_equal(tmp_sdata->vif.addr, hdr->addr2)) {
Johannes Berg5d9cf4a2011-10-07 14:01:23 +02002047 sdata = tmp_sdata;
2048 break;
2049 }
2050 }
Johannes Berg7351c6b2009-11-19 01:08:30 +01002051
Johannes Berg55de9082012-07-26 17:24:39 +02002052 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2053 if (!chanctx_conf) {
2054 tmp_sdata = rcu_dereference(local->monitor_sdata);
2055 if (tmp_sdata)
2056 chanctx_conf =
2057 rcu_dereference(tmp_sdata->vif.chanctx_conf);
2058 }
Johannes Berg55de9082012-07-26 17:24:39 +02002059
Felix Fietkaub4a7ff72013-01-13 23:10:26 +01002060 if (chanctx_conf)
Janusz Dziedzicb4932832014-06-05 08:12:57 +02002061 chandef = &chanctx_conf->def;
Felix Fietkaub4a7ff72013-01-13 23:10:26 +01002062 else if (!local->use_chanctx)
Janusz Dziedzicb4932832014-06-05 08:12:57 +02002063 chandef = &local->_oper_chandef;
Felix Fietkaub4a7ff72013-01-13 23:10:26 +01002064 else
2065 goto fail_rcu;
Johannes Berg55de9082012-07-26 17:24:39 +02002066
2067 /*
2068 * Frame injection is not allowed if beaconing is not allowed
2069 * or if we need radar detection. Beaconing is usually not allowed when
2070 * the mode or operation (Adhoc, AP, Mesh) does not support DFS.
2071 * Passive scan is also used in world regulatory domains where
2072 * your country is not known and as such it should be treated as
2073 * NO TX unless the channel is explicitly allowed in which case
2074 * your current regulatory domain would not have the passive scan
2075 * flag.
2076 *
2077 * Since AP mode uses monitor interfaces to inject/TX management
2078 * frames we can make AP mode the exception to this rule once it
2079 * supports radar detection as its implementation can deal with
2080 * radar detection by itself. We can do that later by adding a
2081 * monitor flag interfaces used for AP support.
2082 */
Janusz Dziedzicb4932832014-06-05 08:12:57 +02002083 if (!cfg80211_reg_can_beacon(local->hw.wiphy, chandef,
2084 sdata->vif.type))
Johannes Berg55de9082012-07-26 17:24:39 +02002085 goto fail_rcu;
2086
Johannes Berg73c4e192014-11-09 18:50:09 +02002087 info->band = chandef->chan->band;
Lorenzo Bianconi109843b02016-02-19 12:18:01 +01002088
2089 /* process and remove the injection radiotap header */
2090 if (!ieee80211_parse_tx_radiotap(local, skb))
2091 goto fail_rcu;
2092
Johannes Berg7c107702015-03-20 14:18:27 +01002093 ieee80211_xmit(sdata, NULL, skb);
Johannes Berg5d9cf4a2011-10-07 14:01:23 +02002094 rcu_read_unlock();
2095
Johannes Berge2ebc742007-07-27 15:43:22 +02002096 return NETDEV_TX_OK;
Andy Green9b8a74e2007-07-27 15:43:24 +02002097
Johannes Berg55de9082012-07-26 17:24:39 +02002098fail_rcu:
2099 rcu_read_unlock();
Andy Green9b8a74e2007-07-27 15:43:24 +02002100fail:
2101 dev_kfree_skb(skb);
2102 return NETDEV_TX_OK; /* meaning, we dealt with the skb */
Johannes Berge2ebc742007-07-27 15:43:22 +02002103}
2104
Johannes Berg97ffe752015-03-21 09:13:45 +01002105static inline bool ieee80211_is_tdls_setup(struct sk_buff *skb)
Matti Gottliebad38bfc2013-11-18 19:06:45 +02002106{
Johannes Berg97ffe752015-03-21 09:13:45 +01002107 u16 ethertype = (skb->data[12] << 8) | skb->data[13];
Matti Gottliebad38bfc2013-11-18 19:06:45 +02002108
Johannes Berg97ffe752015-03-21 09:13:45 +01002109 return ethertype == ETH_P_TDLS &&
2110 skb->len > 14 &&
2111 skb->data[14] == WLAN_TDLS_SNAP_RFTYPE;
2112}
2113
2114static int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata,
2115 struct sk_buff *skb,
2116 struct sta_info **sta_out)
2117{
2118 struct sta_info *sta;
2119
2120 switch (sdata->vif.type) {
2121 case NL80211_IFTYPE_AP_VLAN:
2122 sta = rcu_dereference(sdata->u.vlan.sta);
2123 if (sta) {
2124 *sta_out = sta;
2125 return 0;
2126 } else if (sdata->wdev.use_4addr) {
2127 return -ENOLINK;
2128 }
2129 /* fall through */
2130 case NL80211_IFTYPE_AP:
2131 case NL80211_IFTYPE_OCB:
2132 case NL80211_IFTYPE_ADHOC:
2133 if (is_multicast_ether_addr(skb->data)) {
2134 *sta_out = ERR_PTR(-ENOENT);
2135 return 0;
2136 }
2137 sta = sta_info_get_bss(sdata, skb->data);
2138 break;
2139 case NL80211_IFTYPE_WDS:
2140 sta = sta_info_get(sdata, sdata->u.wds.remote_addr);
2141 break;
2142#ifdef CONFIG_MAC80211_MESH
2143 case NL80211_IFTYPE_MESH_POINT:
2144 /* determined much later */
2145 *sta_out = NULL;
2146 return 0;
2147#endif
2148 case NL80211_IFTYPE_STATION:
2149 if (sdata->wdev.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) {
2150 sta = sta_info_get(sdata, skb->data);
2151 if (sta) {
2152 bool tdls_peer, tdls_auth;
2153
2154 tdls_peer = test_sta_flag(sta,
2155 WLAN_STA_TDLS_PEER);
2156 tdls_auth = test_sta_flag(sta,
2157 WLAN_STA_TDLS_PEER_AUTH);
2158
2159 if (tdls_peer && tdls_auth) {
2160 *sta_out = sta;
2161 return 0;
2162 }
2163
2164 /*
2165 * TDLS link during setup - throw out frames to
2166 * peer. Allow TDLS-setup frames to unauthorized
2167 * peers for the special case of a link teardown
2168 * after a TDLS sta is removed due to being
2169 * unreachable.
2170 */
2171 if (tdls_peer && !tdls_auth &&
2172 !ieee80211_is_tdls_setup(skb))
2173 return -EINVAL;
2174 }
2175
2176 }
2177
2178 sta = sta_info_get(sdata, sdata->u.mgd.bssid);
2179 if (!sta)
2180 return -ENOLINK;
2181 break;
2182 default:
2183 return -EINVAL;
2184 }
2185
2186 *sta_out = sta ?: ERR_PTR(-ENOENT);
2187 return 0;
Matti Gottliebad38bfc2013-11-18 19:06:45 +02002188}
2189
Johannes Berge2ebc742007-07-27 15:43:22 +02002190/**
Johannes Berg4c9451e2014-11-09 18:50:10 +02002191 * ieee80211_build_hdr - build 802.11 header in the given frame
2192 * @sdata: virtual interface to build the header for
2193 * @skb: the skb to build the header in
Liad Kaufman24d342c2014-11-09 18:50:07 +02002194 * @info_flags: skb flags to set
Johannes Berge2ebc742007-07-27 15:43:22 +02002195 *
Johannes Berg4c9451e2014-11-09 18:50:10 +02002196 * This function takes the skb with 802.3 header and reformats the header to
2197 * the appropriate IEEE 802.11 header based on which interface the packet is
2198 * being transmitted on.
Johannes Berge2ebc742007-07-27 15:43:22 +02002199 *
Johannes Berg4c9451e2014-11-09 18:50:10 +02002200 * Note that this function also takes care of the TX status request and
2201 * potential unsharing of the SKB - this needs to be interleaved with the
2202 * header building.
2203 *
2204 * The function requires the read-side RCU lock held
2205 *
2206 * Returns: the (possibly reallocated) skb or an ERR_PTR() code
Johannes Berge2ebc742007-07-27 15:43:22 +02002207 */
Johannes Berg4c9451e2014-11-09 18:50:10 +02002208static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata,
Johannes Berg7c107702015-03-20 14:18:27 +01002209 struct sk_buff *skb, u32 info_flags,
Johannes Berg97ffe752015-03-21 09:13:45 +01002210 struct sta_info *sta)
Johannes Berge2ebc742007-07-27 15:43:22 +02002211{
Johannes Berg133b8222008-09-16 14:18:59 +02002212 struct ieee80211_local *local = sdata->local;
Felix Fietkau489ee912010-12-18 19:30:48 +01002213 struct ieee80211_tx_info *info;
Johannes Bergdcf33962012-07-30 15:11:56 +02002214 int head_need;
Harvey Harrison065e96052008-06-22 16:45:27 -07002215 u16 ethertype, hdrlen, meshhdrlen = 0;
2216 __le16 fc;
Johannes Berge2ebc742007-07-27 15:43:22 +02002217 struct ieee80211_hdr hdr;
Wey-Yi Guyff67bb82010-08-21 07:23:29 -07002218 struct ieee80211s_hdr mesh_hdr __maybe_unused;
Chun-Yeow Yeohb8bacc12012-05-30 09:30:41 +08002219 struct mesh_path __maybe_unused *mppath = NULL, *mpath = NULL;
Johannes Berge2ebc742007-07-27 15:43:22 +02002220 const u8 *encaps_data;
2221 int encaps_len, skip_header_bytes;
Jiri Slabye8bf9642007-08-28 17:01:54 -04002222 int nh_pos, h_pos;
Johannes Berg97ffe752015-03-21 09:13:45 +01002223 bool wme_sta = false, authorized = false;
2224 bool tdls_peer;
Johannes Berga729cff2011-11-06 14:13:34 +01002225 bool multicast;
Johannes Berga729cff2011-11-06 14:13:34 +01002226 u16 info_id = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02002227 struct ieee80211_chanctx_conf *chanctx_conf;
2228 struct ieee80211_sub_if_data *ap_sdata;
Johannes Berg57fbcce2016-04-12 15:56:15 +02002229 enum nl80211_band band;
Johannes Berg4c9451e2014-11-09 18:50:10 +02002230 int ret;
Johannes Berge2ebc742007-07-27 15:43:22 +02002231
Johannes Berg97ffe752015-03-21 09:13:45 +01002232 if (IS_ERR(sta))
2233 sta = NULL;
2234
Johannes Berge2ebc742007-07-27 15:43:22 +02002235 /* convert Ethernet header to proper 802.11 header (based on
2236 * operation mode) */
2237 ethertype = (skb->data[12] << 8) | skb->data[13];
Harvey Harrison065e96052008-06-22 16:45:27 -07002238 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
Johannes Berge2ebc742007-07-27 15:43:22 +02002239
Johannes Berg51fb61e2007-12-19 01:31:27 +01002240 switch (sdata->vif.type) {
Johannes Berg05c914f2008-09-11 00:01:58 +02002241 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg97ffe752015-03-21 09:13:45 +01002242 if (sdata->wdev.use_4addr) {
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002243 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
2244 /* RA TA DA SA */
2245 memcpy(hdr.addr1, sta->sta.addr, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +01002246 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002247 memcpy(hdr.addr3, skb->data, ETH_ALEN);
2248 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
2249 hdrlen = 30;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002250 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
Johannes Berga74a8c82014-07-22 14:50:47 +02002251 wme_sta = sta->sta.wme;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002252 }
Johannes Berg55de9082012-07-26 17:24:39 +02002253 ap_sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
2254 u.ap);
2255 chanctx_conf = rcu_dereference(ap_sdata->vif.chanctx_conf);
Johannes Berg4c9451e2014-11-09 18:50:10 +02002256 if (!chanctx_conf) {
2257 ret = -ENOTCONN;
2258 goto free;
2259 }
Johannes Berg4bf88532012-11-09 11:39:59 +01002260 band = chanctx_conf->def.chan->band;
Johannes Berg97ffe752015-03-21 09:13:45 +01002261 if (sdata->wdev.use_4addr)
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002262 break;
2263 /* fall through */
2264 case NL80211_IFTYPE_AP:
Arnd Bergmannfe801232013-01-25 14:14:33 +00002265 if (sdata->vif.type == NL80211_IFTYPE_AP)
2266 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
Johannes Berg4c9451e2014-11-09 18:50:10 +02002267 if (!chanctx_conf) {
2268 ret = -ENOTCONN;
2269 goto free;
2270 }
Harvey Harrison065e96052008-06-22 16:45:27 -07002271 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
Johannes Berge2ebc742007-07-27 15:43:22 +02002272 /* DA BSSID SA */
2273 memcpy(hdr.addr1, skb->data, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +01002274 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
Johannes Berge2ebc742007-07-27 15:43:22 +02002275 memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
2276 hdrlen = 24;
Johannes Berg4bf88532012-11-09 11:39:59 +01002277 band = chanctx_conf->def.chan->band;
Johannes Bergcf966832007-08-28 17:01:54 -04002278 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02002279 case NL80211_IFTYPE_WDS:
Harvey Harrison065e96052008-06-22 16:45:27 -07002280 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
Johannes Berge2ebc742007-07-27 15:43:22 +02002281 /* RA TA DA SA */
2282 memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +01002283 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
Johannes Berge2ebc742007-07-27 15:43:22 +02002284 memcpy(hdr.addr3, skb->data, ETH_ALEN);
2285 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
2286 hdrlen = 30;
Johannes Berg55de9082012-07-26 17:24:39 +02002287 /*
2288 * This is the exception! WDS style interfaces are prohibited
2289 * when channel contexts are in used so this must be valid
2290 */
Karl Beldan675a0b02013-03-25 16:26:57 +01002291 band = local->hw.conf.chandef.chan->band;
Johannes Bergcf966832007-08-28 17:01:54 -04002292 break;
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01002293#ifdef CONFIG_MAC80211_MESH
Johannes Berg05c914f2008-09-11 00:01:58 +02002294 case NL80211_IFTYPE_MESH_POINT:
Chun-Yeow Yeohb8bacc12012-05-30 09:30:41 +08002295 if (!is_multicast_ether_addr(skb->data)) {
Chun-Yeow Yeoh163df6c2013-02-19 10:04:50 +08002296 struct sta_info *next_hop;
2297 bool mpp_lookup = true;
2298
Johannes Bergbf7cd942013-02-15 14:40:31 +01002299 mpath = mesh_path_lookup(sdata, skb->data);
Chun-Yeow Yeoh163df6c2013-02-19 10:04:50 +08002300 if (mpath) {
2301 mpp_lookup = false;
2302 next_hop = rcu_dereference(mpath->next_hop);
2303 if (!next_hop ||
2304 !(mpath->flags & (MESH_PATH_ACTIVE |
2305 MESH_PATH_RESOLVING)))
2306 mpp_lookup = true;
2307 }
2308
Henning Roggeab1c7902016-02-03 13:58:37 +01002309 if (mpp_lookup) {
Johannes Bergbf7cd942013-02-15 14:40:31 +01002310 mppath = mpp_path_lookup(sdata, skb->data);
Henning Roggeab1c7902016-02-03 13:58:37 +01002311 if (mppath)
2312 mppath->exp_time = jiffies;
2313 }
Chun-Yeow Yeoh163df6c2013-02-19 10:04:50 +08002314
2315 if (mppath && mpath)
Bob Copeland2bdaf382016-02-28 20:03:56 -05002316 mesh_path_del(sdata, mpath->dst);
Chun-Yeow Yeohb8bacc12012-05-30 09:30:41 +08002317 }
YanBo79617de2008-09-22 13:30:32 +08002318
Joel A Fernandesf76b57b2010-12-28 19:28:11 -06002319 /*
Joel A Fernandes9d525012011-01-10 00:44:23 -06002320 * Use address extension if it is a packet from
2321 * another interface or if we know the destination
2322 * is being proxied by a portal (i.e. portal address
2323 * differs from proxied address)
Joel A Fernandesf76b57b2010-12-28 19:28:11 -06002324 */
Joe Perchesb203ca32012-05-08 18:56:52 +00002325 if (ether_addr_equal(sdata->vif.addr, skb->data + ETH_ALEN) &&
2326 !(mppath && !ether_addr_equal(mppath->mpp, skb->data))) {
Javier Cardona3c5772a2009-08-10 12:15:48 -07002327 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
2328 skb->data, skb->data + ETH_ALEN);
Johannes Bergbf7cd942013-02-15 14:40:31 +01002329 meshhdrlen = ieee80211_new_mesh_header(sdata, &mesh_hdr,
2330 NULL, NULL);
YanBo79617de2008-09-22 13:30:32 +08002331 } else {
Thomas Pedersen27f01122012-08-20 11:28:25 -07002332 /* DS -> MBSS (802.11-2012 13.11.3.3).
2333 * For unicast with unknown forwarding information,
2334 * destination might be in the MBSS or if that fails
2335 * forwarded to another mesh gate. In either case
2336 * resolution will be handled in ieee80211_xmit(), so
2337 * leave the original DA. This also works for mcast */
2338 const u8 *mesh_da = skb->data;
YanBo79617de2008-09-22 13:30:32 +08002339
Thomas Pedersen27f01122012-08-20 11:28:25 -07002340 if (mppath)
2341 mesh_da = mppath->mpp;
2342 else if (mpath)
2343 mesh_da = mpath->dst;
Thomas Pedersen27f01122012-08-20 11:28:25 -07002344
Javier Cardona3c5772a2009-08-10 12:15:48 -07002345 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
Johannes Berg47846c92009-11-25 17:46:19 +01002346 mesh_da, sdata->vif.addr);
Thomas Pedersen27f01122012-08-20 11:28:25 -07002347 if (is_multicast_ether_addr(mesh_da))
2348 /* DA TA mSA AE:SA */
Johannes Bergbf7cd942013-02-15 14:40:31 +01002349 meshhdrlen = ieee80211_new_mesh_header(
2350 sdata, &mesh_hdr,
2351 skb->data + ETH_ALEN, NULL);
Javier Cardona3c5772a2009-08-10 12:15:48 -07002352 else
Thomas Pedersen27f01122012-08-20 11:28:25 -07002353 /* RA TA mDA mSA AE:DA SA */
Johannes Bergbf7cd942013-02-15 14:40:31 +01002354 meshhdrlen = ieee80211_new_mesh_header(
2355 sdata, &mesh_hdr, skb->data,
2356 skb->data + ETH_ALEN);
YanBo79617de2008-09-22 13:30:32 +08002357
YanBo79617de2008-09-22 13:30:32 +08002358 }
Johannes Berg55de9082012-07-26 17:24:39 +02002359 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
Johannes Berg4c9451e2014-11-09 18:50:10 +02002360 if (!chanctx_conf) {
2361 ret = -ENOTCONN;
2362 goto free;
2363 }
Johannes Berg4bf88532012-11-09 11:39:59 +01002364 band = chanctx_conf->def.chan->band;
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01002365 break;
2366#endif
Johannes Berg05c914f2008-09-11 00:01:58 +02002367 case NL80211_IFTYPE_STATION:
Johannes Berg97ffe752015-03-21 09:13:45 +01002368 /* we already did checks when looking up the RA STA */
2369 tdls_peer = test_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002370
Johannes Berg97ffe752015-03-21 09:13:45 +01002371 if (tdls_peer) {
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002372 /* DA SA BSSID */
2373 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2374 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2375 memcpy(hdr.addr3, sdata->u.mgd.bssid, ETH_ALEN);
2376 hdrlen = 24;
2377 } else if (sdata->u.mgd.use_4addr &&
2378 cpu_to_be16(ethertype) != sdata->control_port_protocol) {
2379 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
2380 IEEE80211_FCTL_TODS);
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002381 /* RA TA DA SA */
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002382 memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +01002383 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002384 memcpy(hdr.addr3, skb->data, ETH_ALEN);
2385 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
2386 hdrlen = 30;
2387 } else {
2388 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
2389 /* BSSID SA DA */
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002390 memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN);
Felix Fietkauf14543ee2009-11-10 20:10:05 +01002391 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2392 memcpy(hdr.addr3, skb->data, ETH_ALEN);
2393 hdrlen = 24;
2394 }
Johannes Berg55de9082012-07-26 17:24:39 +02002395 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
Johannes Berg4c9451e2014-11-09 18:50:10 +02002396 if (!chanctx_conf) {
2397 ret = -ENOTCONN;
2398 goto free;
2399 }
Johannes Berg4bf88532012-11-09 11:39:59 +01002400 band = chanctx_conf->def.chan->band;
Johannes Bergcf966832007-08-28 17:01:54 -04002401 break;
Rostislav Lisovy239281f2014-11-03 10:33:19 +01002402 case NL80211_IFTYPE_OCB:
2403 /* DA SA BSSID */
2404 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2405 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
2406 eth_broadcast_addr(hdr.addr3);
2407 hdrlen = 24;
2408 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
Johannes Berg4c9451e2014-11-09 18:50:10 +02002409 if (!chanctx_conf) {
2410 ret = -ENOTCONN;
2411 goto free;
2412 }
Rostislav Lisovy239281f2014-11-03 10:33:19 +01002413 band = chanctx_conf->def.chan->band;
2414 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02002415 case NL80211_IFTYPE_ADHOC:
Johannes Berge2ebc742007-07-27 15:43:22 +02002416 /* DA SA BSSID */
2417 memcpy(hdr.addr1, skb->data, ETH_ALEN);
2418 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +01002419 memcpy(hdr.addr3, sdata->u.ibss.bssid, ETH_ALEN);
Johannes Berge2ebc742007-07-27 15:43:22 +02002420 hdrlen = 24;
Johannes Berg55de9082012-07-26 17:24:39 +02002421 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
Johannes Berg4c9451e2014-11-09 18:50:10 +02002422 if (!chanctx_conf) {
2423 ret = -ENOTCONN;
2424 goto free;
2425 }
Johannes Berg4bf88532012-11-09 11:39:59 +01002426 band = chanctx_conf->def.chan->band;
Johannes Bergcf966832007-08-28 17:01:54 -04002427 break;
2428 default:
Johannes Berg4c9451e2014-11-09 18:50:10 +02002429 ret = -EINVAL;
2430 goto free;
Johannes Berge2ebc742007-07-27 15:43:22 +02002431 }
2432
Johannes Berga729cff2011-11-06 14:13:34 +01002433 multicast = is_multicast_ether_addr(hdr.addr1);
Johannes Berge2ebc742007-07-27 15:43:22 +02002434
Johannes Berg97ffe752015-03-21 09:13:45 +01002435 /* sta is always NULL for mesh */
2436 if (sta) {
2437 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
2438 wme_sta = sta->sta.wme;
2439 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
2440 /* For mesh, the use of the QoS header is mandatory */
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002441 wme_sta = true;
Johannes Berge2ebc742007-07-27 15:43:22 +02002442 }
2443
Johannes Berg527871d2015-03-21 08:09:55 +01002444 /* receiver does QoS (which also means we do) use it */
2445 if (wme_sta) {
Harvey Harrison065e96052008-06-22 16:45:27 -07002446 fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002447 hdrlen += 2;
2448 }
2449
2450 /*
Johannes Berg238814f2008-01-28 17:19:37 +01002451 * Drop unicast frames to unauthorised stations unless they are
2452 * EAPOL frames from the local station.
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002453 */
Johannes Berg55182e42011-10-12 17:28:21 +02002454 if (unlikely(!ieee80211_vif_is_mesh(&sdata->vif) &&
Rostislav Lisovy239281f2014-11-03 10:33:19 +01002455 (sdata->vif.type != NL80211_IFTYPE_OCB) &&
Sergey Ryazanova6ececf2013-08-30 01:35:09 +04002456 !multicast && !authorized &&
Johannes Berg55182e42011-10-12 17:28:21 +02002457 (cpu_to_be16(ethertype) != sdata->control_port_protocol ||
Joe Perchesb203ca32012-05-08 18:56:52 +00002458 !ether_addr_equal(sdata->vif.addr, skb->data + ETH_ALEN)))) {
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002459#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002460 net_info_ratelimited("%s: dropped frame to %pM (unauthorized port)\n",
Johannes Berg4c9451e2014-11-09 18:50:10 +02002461 sdata->name, hdr.addr1);
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002462#endif
2463
2464 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
2465
Johannes Berg4c9451e2014-11-09 18:50:10 +02002466 ret = -EPERM;
2467 goto free;
Johannes Bergce3edf6d02007-12-19 01:31:22 +01002468 }
2469
Johannes Berga729cff2011-11-06 14:13:34 +01002470 if (unlikely(!multicast && skb->sk &&
2471 skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS)) {
Alexander Duyckbf7fa552014-09-10 18:05:42 -04002472 struct sk_buff *ack_skb = skb_clone_sk(skb);
Johannes Berga729cff2011-11-06 14:13:34 +01002473
Alexander Duyckbf7fa552014-09-10 18:05:42 -04002474 if (ack_skb) {
Johannes Berga729cff2011-11-06 14:13:34 +01002475 unsigned long flags;
Tejun Heo9475af62013-02-27 17:04:59 -08002476 int id;
Johannes Berga729cff2011-11-06 14:13:34 +01002477
2478 spin_lock_irqsave(&local->ack_status_lock, flags);
Alexander Duyckbf7fa552014-09-10 18:05:42 -04002479 id = idr_alloc(&local->ack_status_frames, ack_skb,
Tejun Heo9475af62013-02-27 17:04:59 -08002480 1, 0x10000, GFP_ATOMIC);
Johannes Berga729cff2011-11-06 14:13:34 +01002481 spin_unlock_irqrestore(&local->ack_status_lock, flags);
2482
Tejun Heo9475af62013-02-27 17:04:59 -08002483 if (id >= 0) {
Johannes Berga729cff2011-11-06 14:13:34 +01002484 info_id = id;
2485 info_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
Johannes Berga729cff2011-11-06 14:13:34 +01002486 } else {
Alexander Duyckbf7fa552014-09-10 18:05:42 -04002487 kfree_skb(ack_skb);
Johannes Berga729cff2011-11-06 14:13:34 +01002488 }
Johannes Berga729cff2011-11-06 14:13:34 +01002489 }
2490 }
2491
Helmut Schaa7e244702010-12-02 18:44:09 +01002492 /*
2493 * If the skb is shared we need to obtain our own copy.
2494 */
2495 if (skb_shared(skb)) {
Johannes Berga729cff2011-11-06 14:13:34 +01002496 struct sk_buff *tmp_skb = skb;
2497
2498 /* can't happen -- skb is a clone if info_id != 0 */
2499 WARN_ON(info_id);
2500
Felix Fietkauf8a0a782010-12-18 19:30:50 +01002501 skb = skb_clone(skb, GFP_ATOMIC);
Helmut Schaa7e244702010-12-02 18:44:09 +01002502 kfree_skb(tmp_skb);
2503
Johannes Berg4c9451e2014-11-09 18:50:10 +02002504 if (!skb) {
2505 ret = -ENOMEM;
2506 goto free;
2507 }
Helmut Schaa7e244702010-12-02 18:44:09 +01002508 }
2509
Harvey Harrison065e96052008-06-22 16:45:27 -07002510 hdr.frame_control = fc;
Johannes Berge2ebc742007-07-27 15:43:22 +02002511 hdr.duration_id = 0;
2512 hdr.seq_ctrl = 0;
2513
2514 skip_header_bytes = ETH_HLEN;
2515 if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
2516 encaps_data = bridge_tunnel_header;
2517 encaps_len = sizeof(bridge_tunnel_header);
2518 skip_header_bytes -= 2;
Simon Hormane5c5d222013-03-28 13:38:25 +09002519 } else if (ethertype >= ETH_P_802_3_MIN) {
Johannes Berge2ebc742007-07-27 15:43:22 +02002520 encaps_data = rfc1042_header;
2521 encaps_len = sizeof(rfc1042_header);
2522 skip_header_bytes -= 2;
2523 } else {
2524 encaps_data = NULL;
2525 encaps_len = 0;
2526 }
2527
Helmut Schaa7e244702010-12-02 18:44:09 +01002528 nh_pos = skb_network_header(skb) - skb->data;
2529 h_pos = skb_transport_header(skb) - skb->data;
2530
Johannes Berge2ebc742007-07-27 15:43:22 +02002531 skb_pull(skb, skip_header_bytes);
2532 nh_pos -= skip_header_bytes;
2533 h_pos -= skip_header_bytes;
2534
Johannes Berg23c07522008-05-29 10:38:53 +02002535 head_need = hdrlen + encaps_len + meshhdrlen - skb_headroom(skb);
Johannes Berge2ebc742007-07-27 15:43:22 +02002536
Johannes Berg23c07522008-05-29 10:38:53 +02002537 /*
2538 * So we need to modify the skb header and hence need a copy of
2539 * that. The head_need variable above doesn't, so far, include
2540 * the needed header space that we don't need right away. If we
2541 * can, then we don't reallocate right now but only after the
2542 * frame arrives at the master device (if it does...)
2543 *
2544 * If we cannot, however, then we will reallocate to include all
2545 * the ever needed space. Also, if we need to reallocate it anyway,
2546 * make it big enough for everything we may ever need.
2547 */
Johannes Berge2ebc742007-07-27 15:43:22 +02002548
David S. Miller3a5be7d2008-06-18 01:19:51 -07002549 if (head_need > 0 || skb_cloned(skb)) {
Max Stepanov2475b1cc2013-03-24 14:23:27 +02002550 head_need += sdata->encrypt_headroom;
Johannes Berg23c07522008-05-29 10:38:53 +02002551 head_need += local->tx_headroom;
2552 head_need = max_t(int, 0, head_need);
Felix Fietkauc3e77242012-10-08 14:39:33 +02002553 if (ieee80211_skb_resize(sdata, skb, head_need, true)) {
2554 ieee80211_free_txskb(&local->hw, skb);
Johannes Berg1c963be2012-11-07 14:02:30 +01002555 skb = NULL;
Johannes Berg4c9451e2014-11-09 18:50:10 +02002556 return ERR_PTR(-ENOMEM);
Felix Fietkauc3e77242012-10-08 14:39:33 +02002557 }
Johannes Berge2ebc742007-07-27 15:43:22 +02002558 }
2559
2560 if (encaps_data) {
2561 memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
2562 nh_pos += encaps_len;
2563 h_pos += encaps_len;
2564 }
Johannes Bergc29b9b92007-09-14 11:10:24 -04002565
Yuri Ershove4ab7eb2010-06-29 15:08:06 +04002566#ifdef CONFIG_MAC80211_MESH
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01002567 if (meshhdrlen > 0) {
2568 memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen);
2569 nh_pos += meshhdrlen;
2570 h_pos += meshhdrlen;
2571 }
Yuri Ershove4ab7eb2010-06-29 15:08:06 +04002572#endif
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01002573
Harvey Harrison065e96052008-06-22 16:45:27 -07002574 if (ieee80211_is_data_qos(fc)) {
Johannes Bergc29b9b92007-09-14 11:10:24 -04002575 __le16 *qos_control;
2576
Weilong Chenf359d3f2013-12-18 15:44:16 +08002577 qos_control = (__le16 *) skb_push(skb, 2);
Johannes Bergc29b9b92007-09-14 11:10:24 -04002578 memcpy(skb_push(skb, hdrlen - 2), &hdr, hdrlen - 2);
2579 /*
2580 * Maybe we could actually set some fields here, for now just
2581 * initialise to zero to indicate no special operation.
2582 */
2583 *qos_control = 0;
2584 } else
2585 memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
2586
Johannes Berge2ebc742007-07-27 15:43:22 +02002587 nh_pos += hdrlen;
2588 h_pos += hdrlen;
2589
Johannes Berge2ebc742007-07-27 15:43:22 +02002590 /* Update skb pointers to various headers since this modified frame
2591 * is going to go through Linux networking code that may potentially
2592 * need things like pointer to IP header. */
Zhang Shengjud57a5442016-03-03 01:16:56 +00002593 skb_reset_mac_header(skb);
Johannes Berge2ebc742007-07-27 15:43:22 +02002594 skb_set_network_header(skb, nh_pos);
2595 skb_set_transport_header(skb, h_pos);
2596
Felix Fietkau489ee912010-12-18 19:30:48 +01002597 info = IEEE80211_SKB_CB(skb);
Johannes Berg3b8d81e02009-06-17 17:43:56 +02002598 memset(info, 0, sizeof(*info));
2599
Johannes Berga729cff2011-11-06 14:13:34 +01002600 info->flags = info_flags;
2601 info->ack_frame_id = info_id;
Johannes Berg73c4e192014-11-09 18:50:09 +02002602 info->band = band;
Johannes Berga729cff2011-11-06 14:13:34 +01002603
Johannes Berg4c9451e2014-11-09 18:50:10 +02002604 return skb;
2605 free:
2606 kfree_skb(skb);
2607 return ERR_PTR(ret);
Johannes Berge2ebc742007-07-27 15:43:22 +02002608}
2609
Johannes Berg17c18bf2015-03-21 15:25:43 +01002610/*
2611 * fast-xmit overview
2612 *
2613 * The core idea of this fast-xmit is to remove per-packet checks by checking
2614 * them out of band. ieee80211_check_fast_xmit() implements the out-of-band
2615 * checks that are needed to get the sta->fast_tx pointer assigned, after which
2616 * much less work can be done per packet. For example, fragmentation must be
2617 * disabled or the fast_tx pointer will not be set. All the conditions are seen
2618 * in the code here.
2619 *
2620 * Once assigned, the fast_tx data structure also caches the per-packet 802.11
2621 * header and other data to aid packet processing in ieee80211_xmit_fast().
2622 *
2623 * The most difficult part of this is that when any of these assumptions
2624 * change, an external trigger (i.e. a call to ieee80211_clear_fast_xmit(),
2625 * ieee80211_check_fast_xmit() or friends) is required to reset the data,
2626 * since the per-packet code no longer checks the conditions. This is reflected
2627 * by the calls to these functions throughout the rest of the code, and must be
2628 * maintained if any of the TX path checks change.
2629 */
2630
2631void ieee80211_check_fast_xmit(struct sta_info *sta)
2632{
2633 struct ieee80211_fast_tx build = {}, *fast_tx = NULL, *old;
2634 struct ieee80211_local *local = sta->local;
2635 struct ieee80211_sub_if_data *sdata = sta->sdata;
2636 struct ieee80211_hdr *hdr = (void *)build.hdr;
2637 struct ieee80211_chanctx_conf *chanctx_conf;
2638 __le16 fc;
2639
Johannes Berg30686bf2015-06-02 21:39:54 +02002640 if (!ieee80211_hw_check(&local->hw, SUPPORT_FAST_XMIT))
Johannes Berg17c18bf2015-03-21 15:25:43 +01002641 return;
2642
2643 /* Locking here protects both the pointer itself, and against concurrent
2644 * invocations winning data access races to, e.g., the key pointer that
2645 * is used.
2646 * Without it, the invocation of this function right after the key
2647 * pointer changes wouldn't be sufficient, as another CPU could access
2648 * the pointer, then stall, and then do the cache update after the CPU
2649 * that invalidated the key.
2650 * With the locking, such scenarios cannot happen as the check for the
2651 * key and the fast-tx assignment are done atomically, so the CPU that
2652 * modifies the key will either wait or other one will see the key
2653 * cleared/changed already.
2654 */
2655 spin_lock_bh(&sta->lock);
Johannes Berg30686bf2015-06-02 21:39:54 +02002656 if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
2657 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
Johannes Berg17c18bf2015-03-21 15:25:43 +01002658 sdata->vif.type == NL80211_IFTYPE_STATION)
2659 goto out;
2660
2661 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2662 goto out;
2663
2664 if (test_sta_flag(sta, WLAN_STA_PS_STA) ||
2665 test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
Felix Fietkauf7418bc2015-09-24 14:59:49 +02002666 test_sta_flag(sta, WLAN_STA_PS_DELIVER) ||
2667 test_sta_flag(sta, WLAN_STA_CLEAR_PS_FILT))
Johannes Berg17c18bf2015-03-21 15:25:43 +01002668 goto out;
2669
2670 if (sdata->noack_map)
2671 goto out;
2672
2673 /* fast-xmit doesn't handle fragmentation at all */
Johannes Berg725b8122015-04-10 14:02:08 +02002674 if (local->hw.wiphy->frag_threshold != (u32)-1 &&
2675 !local->ops->set_frag_threshold)
Johannes Berg17c18bf2015-03-21 15:25:43 +01002676 goto out;
2677
2678 rcu_read_lock();
2679 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2680 if (!chanctx_conf) {
2681 rcu_read_unlock();
2682 goto out;
2683 }
2684 build.band = chanctx_conf->def.chan->band;
2685 rcu_read_unlock();
2686
2687 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
2688
2689 switch (sdata->vif.type) {
Johannes Berg3ffd8842015-04-14 10:28:37 +02002690 case NL80211_IFTYPE_ADHOC:
2691 /* DA SA BSSID */
2692 build.da_offs = offsetof(struct ieee80211_hdr, addr1);
2693 build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
2694 memcpy(hdr->addr3, sdata->u.ibss.bssid, ETH_ALEN);
2695 build.hdr_len = 24;
2696 break;
Johannes Berg17c18bf2015-03-21 15:25:43 +01002697 case NL80211_IFTYPE_STATION:
2698 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
2699 /* DA SA BSSID */
2700 build.da_offs = offsetof(struct ieee80211_hdr, addr1);
2701 build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
2702 memcpy(hdr->addr3, sdata->u.mgd.bssid, ETH_ALEN);
2703 build.hdr_len = 24;
2704 break;
2705 }
2706
2707 if (sdata->u.mgd.use_4addr) {
2708 /* non-regular ethertype cannot use the fastpath */
2709 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
2710 IEEE80211_FCTL_TODS);
2711 /* RA TA DA SA */
2712 memcpy(hdr->addr1, sdata->u.mgd.bssid, ETH_ALEN);
2713 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
2714 build.da_offs = offsetof(struct ieee80211_hdr, addr3);
2715 build.sa_offs = offsetof(struct ieee80211_hdr, addr4);
2716 build.hdr_len = 30;
2717 break;
2718 }
2719 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
2720 /* BSSID SA DA */
2721 memcpy(hdr->addr1, sdata->u.mgd.bssid, ETH_ALEN);
2722 build.da_offs = offsetof(struct ieee80211_hdr, addr3);
2723 build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
2724 build.hdr_len = 24;
2725 break;
2726 case NL80211_IFTYPE_AP_VLAN:
2727 if (sdata->wdev.use_4addr) {
2728 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
2729 IEEE80211_FCTL_TODS);
2730 /* RA TA DA SA */
2731 memcpy(hdr->addr1, sta->sta.addr, ETH_ALEN);
2732 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
2733 build.da_offs = offsetof(struct ieee80211_hdr, addr3);
2734 build.sa_offs = offsetof(struct ieee80211_hdr, addr4);
2735 build.hdr_len = 30;
2736 break;
2737 }
2738 /* fall through */
2739 case NL80211_IFTYPE_AP:
2740 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
2741 /* DA BSSID SA */
2742 build.da_offs = offsetof(struct ieee80211_hdr, addr1);
2743 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
2744 build.sa_offs = offsetof(struct ieee80211_hdr, addr3);
2745 build.hdr_len = 24;
2746 break;
2747 default:
2748 /* not handled on fast-xmit */
2749 goto out;
2750 }
2751
2752 if (sta->sta.wme) {
2753 build.hdr_len += 2;
2754 fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
2755 }
2756
2757 /* We store the key here so there's no point in using rcu_dereference()
2758 * but that's fine because the code that changes the pointers will call
2759 * this function after doing so. For a single CPU that would be enough,
2760 * for multiple see the comment above.
2761 */
2762 build.key = rcu_access_pointer(sta->ptk[sta->ptk_idx]);
2763 if (!build.key)
2764 build.key = rcu_access_pointer(sdata->default_unicast_key);
2765 if (build.key) {
Johannes Berge495c242015-04-10 14:03:17 +02002766 bool gen_iv, iv_spc, mmic;
Johannes Berg17c18bf2015-03-21 15:25:43 +01002767
2768 gen_iv = build.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV;
2769 iv_spc = build.key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE;
Johannes Berge495c242015-04-10 14:03:17 +02002770 mmic = build.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC;
Johannes Berg17c18bf2015-03-21 15:25:43 +01002771
2772 /* don't handle software crypto */
2773 if (!(build.key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
2774 goto out;
2775
2776 switch (build.key->conf.cipher) {
2777 case WLAN_CIPHER_SUITE_CCMP:
2778 case WLAN_CIPHER_SUITE_CCMP_256:
2779 /* add fixed key ID */
2780 if (gen_iv) {
2781 (build.hdr + build.hdr_len)[3] =
2782 0x20 | (build.key->conf.keyidx << 6);
2783 build.pn_offs = build.hdr_len;
2784 }
2785 if (gen_iv || iv_spc)
2786 build.hdr_len += IEEE80211_CCMP_HDR_LEN;
2787 break;
2788 case WLAN_CIPHER_SUITE_GCMP:
2789 case WLAN_CIPHER_SUITE_GCMP_256:
2790 /* add fixed key ID */
2791 if (gen_iv) {
2792 (build.hdr + build.hdr_len)[3] =
2793 0x20 | (build.key->conf.keyidx << 6);
2794 build.pn_offs = build.hdr_len;
2795 }
2796 if (gen_iv || iv_spc)
2797 build.hdr_len += IEEE80211_GCMP_HDR_LEN;
2798 break;
Johannes Berge495c242015-04-10 14:03:17 +02002799 case WLAN_CIPHER_SUITE_TKIP:
2800 /* cannot handle MMIC or IV generation in xmit-fast */
2801 if (mmic || gen_iv)
2802 goto out;
2803 if (iv_spc)
2804 build.hdr_len += IEEE80211_TKIP_IV_LEN;
2805 break;
2806 case WLAN_CIPHER_SUITE_WEP40:
2807 case WLAN_CIPHER_SUITE_WEP104:
2808 /* cannot handle IV generation in fast-xmit */
2809 if (gen_iv)
2810 goto out;
2811 if (iv_spc)
2812 build.hdr_len += IEEE80211_WEP_IV_LEN;
2813 break;
2814 case WLAN_CIPHER_SUITE_AES_CMAC:
2815 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
2816 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2817 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2818 WARN(1,
2819 "management cipher suite 0x%x enabled for data\n",
2820 build.key->conf.cipher);
Johannes Berg17c18bf2015-03-21 15:25:43 +01002821 goto out;
Johannes Berge495c242015-04-10 14:03:17 +02002822 default:
2823 /* we don't know how to generate IVs for this at all */
2824 if (WARN_ON(gen_iv))
2825 goto out;
2826 /* pure hardware keys are OK, of course */
2827 if (!(build.key->flags & KEY_FLAG_CIPHER_SCHEME))
2828 break;
2829 /* cipher scheme might require space allocation */
2830 if (iv_spc &&
2831 build.key->conf.iv_len > IEEE80211_FAST_XMIT_MAX_IV)
2832 goto out;
2833 if (iv_spc)
2834 build.hdr_len += build.key->conf.iv_len;
Johannes Berg17c18bf2015-03-21 15:25:43 +01002835 }
2836
2837 fc |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
2838 }
2839
2840 hdr->frame_control = fc;
2841
2842 memcpy(build.hdr + build.hdr_len,
2843 rfc1042_header, sizeof(rfc1042_header));
2844 build.hdr_len += sizeof(rfc1042_header);
2845
2846 fast_tx = kmemdup(&build, sizeof(build), GFP_ATOMIC);
2847 /* if the kmemdup fails, continue w/o fast_tx */
2848 if (!fast_tx)
2849 goto out;
2850
2851 out:
2852 /* we might have raced against another call to this function */
2853 old = rcu_dereference_protected(sta->fast_tx,
2854 lockdep_is_held(&sta->lock));
2855 rcu_assign_pointer(sta->fast_tx, fast_tx);
2856 if (old)
2857 kfree_rcu(old, rcu_head);
2858 spin_unlock_bh(&sta->lock);
2859}
2860
2861void ieee80211_check_fast_xmit_all(struct ieee80211_local *local)
2862{
2863 struct sta_info *sta;
2864
2865 rcu_read_lock();
2866 list_for_each_entry_rcu(sta, &local->sta_list, list)
2867 ieee80211_check_fast_xmit(sta);
2868 rcu_read_unlock();
2869}
2870
2871void ieee80211_check_fast_xmit_iface(struct ieee80211_sub_if_data *sdata)
2872{
2873 struct ieee80211_local *local = sdata->local;
2874 struct sta_info *sta;
2875
2876 rcu_read_lock();
2877
2878 list_for_each_entry_rcu(sta, &local->sta_list, list) {
2879 if (sdata != sta->sdata &&
2880 (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
2881 continue;
2882 ieee80211_check_fast_xmit(sta);
2883 }
2884
2885 rcu_read_unlock();
2886}
2887
2888void ieee80211_clear_fast_xmit(struct sta_info *sta)
2889{
2890 struct ieee80211_fast_tx *fast_tx;
2891
2892 spin_lock_bh(&sta->lock);
2893 fast_tx = rcu_dereference_protected(sta->fast_tx,
2894 lockdep_is_held(&sta->lock));
2895 RCU_INIT_POINTER(sta->fast_tx, NULL);
2896 spin_unlock_bh(&sta->lock);
2897
2898 if (fast_tx)
2899 kfree_rcu(fast_tx, rcu_head);
2900}
2901
Felix Fietkau6e0456b2016-03-03 22:59:00 +01002902static bool ieee80211_amsdu_realloc_pad(struct ieee80211_local *local,
2903 struct sk_buff *skb, int headroom,
2904 int *subframe_len)
2905{
2906 int amsdu_len = *subframe_len + sizeof(struct ethhdr);
2907 int padding = (4 - amsdu_len) & 3;
2908
2909 if (skb_headroom(skb) < headroom || skb_tailroom(skb) < padding) {
2910 I802_DEBUG_INC(local->tx_expand_skb_head);
2911
2912 if (pskb_expand_head(skb, headroom, padding, GFP_ATOMIC)) {
2913 wiphy_debug(local->hw.wiphy,
2914 "failed to reallocate TX buffer\n");
2915 return false;
2916 }
2917 }
2918
2919 if (padding) {
2920 *subframe_len += padding;
2921 memset(skb_put(skb, padding), 0, padding);
2922 }
2923
2924 return true;
2925}
2926
2927static bool ieee80211_amsdu_prepare_head(struct ieee80211_sub_if_data *sdata,
2928 struct ieee80211_fast_tx *fast_tx,
2929 struct sk_buff *skb)
2930{
2931 struct ieee80211_local *local = sdata->local;
2932 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2933 struct ieee80211_hdr *hdr;
2934 struct ethhdr amsdu_hdr;
2935 int hdr_len = fast_tx->hdr_len - sizeof(rfc1042_header);
2936 int subframe_len = skb->len - hdr_len;
2937 void *data;
2938 u8 *qc;
2939
2940 if (info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE)
2941 return false;
2942
2943 if (info->control.flags & IEEE80211_TX_CTRL_AMSDU)
2944 return true;
2945
2946 if (!ieee80211_amsdu_realloc_pad(local, skb, sizeof(amsdu_hdr),
2947 &subframe_len))
2948 return false;
2949
2950 amsdu_hdr.h_proto = cpu_to_be16(subframe_len);
2951 memcpy(amsdu_hdr.h_source, skb->data + fast_tx->sa_offs, ETH_ALEN);
2952 memcpy(amsdu_hdr.h_dest, skb->data + fast_tx->da_offs, ETH_ALEN);
2953
2954 data = skb_push(skb, sizeof(amsdu_hdr));
2955 memmove(data, data + sizeof(amsdu_hdr), hdr_len);
2956 memcpy(data + hdr_len, &amsdu_hdr, sizeof(amsdu_hdr));
2957
2958 hdr = data;
2959 qc = ieee80211_get_qos_ctl(hdr);
2960 *qc |= IEEE80211_QOS_CTL_A_MSDU_PRESENT;
2961
2962 info->control.flags |= IEEE80211_TX_CTRL_AMSDU;
2963
2964 return true;
2965}
2966
2967static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata,
2968 struct sta_info *sta,
2969 struct ieee80211_fast_tx *fast_tx,
2970 struct sk_buff *skb)
2971{
2972 struct ieee80211_local *local = sdata->local;
Michal Kaziorfa962b92016-05-19 10:37:49 +02002973 struct fq *fq = &local->fq;
2974 struct fq_tin *tin;
2975 struct fq_flow *flow;
Felix Fietkau6e0456b2016-03-03 22:59:00 +01002976 u8 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
2977 struct ieee80211_txq *txq = sta->sta.txq[tid];
2978 struct txq_info *txqi;
2979 struct sk_buff **frag_tail, *head;
2980 int subframe_len = skb->len - ETH_ALEN;
2981 u8 max_subframes = sta->sta.max_amsdu_subframes;
2982 int max_frags = local->hw.max_tx_fragments;
2983 int max_amsdu_len = sta->sta.max_amsdu_len;
2984 __be16 len;
2985 void *data;
2986 bool ret = false;
Michal Kaziorfa962b92016-05-19 10:37:49 +02002987 unsigned int orig_len;
Felix Fietkau6e0456b2016-03-03 22:59:00 +01002988 int n = 1, nfrags;
2989
2990 if (!ieee80211_hw_check(&local->hw, TX_AMSDU))
2991 return false;
2992
2993 if (!txq)
2994 return false;
2995
2996 txqi = to_txq_info(txq);
2997 if (test_bit(IEEE80211_TXQ_NO_AMSDU, &txqi->flags))
2998 return false;
2999
3000 if (sta->sta.max_rc_amsdu_len)
3001 max_amsdu_len = min_t(int, max_amsdu_len,
3002 sta->sta.max_rc_amsdu_len);
3003
Michal Kaziorfa962b92016-05-19 10:37:49 +02003004 spin_lock_bh(&fq->lock);
Felix Fietkau6e0456b2016-03-03 22:59:00 +01003005
Michal Kaziorfa962b92016-05-19 10:37:49 +02003006 /* TODO: Ideally aggregation should be done on dequeue to remain
3007 * responsive to environment changes.
3008 */
3009
3010 tin = &txqi->tin;
3011 flow = fq_flow_classify(fq, tin, skb, fq_flow_get_default_func);
3012 head = skb_peek_tail(&flow->queue);
Felix Fietkau6e0456b2016-03-03 22:59:00 +01003013 if (!head)
3014 goto out;
3015
Michal Kaziorfa962b92016-05-19 10:37:49 +02003016 orig_len = head->len;
3017
Felix Fietkau6e0456b2016-03-03 22:59:00 +01003018 if (skb->len + head->len > max_amsdu_len)
3019 goto out;
3020
3021 if (!ieee80211_amsdu_prepare_head(sdata, fast_tx, head))
3022 goto out;
3023
3024 nfrags = 1 + skb_shinfo(skb)->nr_frags;
3025 nfrags += 1 + skb_shinfo(head)->nr_frags;
3026 frag_tail = &skb_shinfo(head)->frag_list;
3027 while (*frag_tail) {
3028 nfrags += 1 + skb_shinfo(*frag_tail)->nr_frags;
3029 frag_tail = &(*frag_tail)->next;
3030 n++;
3031 }
3032
3033 if (max_subframes && n > max_subframes)
3034 goto out;
3035
3036 if (max_frags && nfrags > max_frags)
3037 goto out;
3038
3039 if (!ieee80211_amsdu_realloc_pad(local, skb, sizeof(rfc1042_header) + 2,
3040 &subframe_len))
3041 goto out;
3042
3043 ret = true;
3044 data = skb_push(skb, ETH_ALEN + 2);
3045 memmove(data, data + ETH_ALEN + 2, 2 * ETH_ALEN);
3046
3047 data += 2 * ETH_ALEN;
3048 len = cpu_to_be16(subframe_len);
3049 memcpy(data, &len, 2);
3050 memcpy(data + 2, rfc1042_header, sizeof(rfc1042_header));
3051
3052 head->len += skb->len;
3053 head->data_len += skb->len;
3054 *frag_tail = skb;
3055
Michal Kaziorfa962b92016-05-19 10:37:49 +02003056 flow->backlog += head->len - orig_len;
3057 tin->backlog_bytes += head->len - orig_len;
3058
3059 fq_recalc_backlog(fq, tin, flow);
3060
Felix Fietkau6e0456b2016-03-03 22:59:00 +01003061out:
Michal Kaziorfa962b92016-05-19 10:37:49 +02003062 spin_unlock_bh(&fq->lock);
Felix Fietkau6e0456b2016-03-03 22:59:00 +01003063
3064 return ret;
3065}
3066
Johannes Berg17c18bf2015-03-21 15:25:43 +01003067static bool ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
3068 struct net_device *dev, struct sta_info *sta,
3069 struct ieee80211_fast_tx *fast_tx,
3070 struct sk_buff *skb)
3071{
3072 struct ieee80211_local *local = sdata->local;
3073 u16 ethertype = (skb->data[12] << 8) | skb->data[13];
3074 int extra_head = fast_tx->hdr_len - (ETH_HLEN - 2);
3075 int hw_headroom = sdata->local->hw.extra_tx_headroom;
3076 struct ethhdr eth;
3077 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3078 struct ieee80211_hdr *hdr = (void *)fast_tx->hdr;
3079 struct ieee80211_tx_data tx;
3080 ieee80211_tx_result r;
3081 struct tid_ampdu_tx *tid_tx = NULL;
3082 u8 tid = IEEE80211_NUM_TIDS;
3083
3084 /* control port protocol needs a lot of special handling */
3085 if (cpu_to_be16(ethertype) == sdata->control_port_protocol)
3086 return false;
3087
3088 /* only RFC 1042 SNAP */
3089 if (ethertype < ETH_P_802_3_MIN)
3090 return false;
3091
3092 /* don't handle TX status request here either */
3093 if (skb->sk && skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS)
3094 return false;
3095
3096 if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
3097 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
3098 tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
Johannes Berg472be002015-06-09 16:45:08 +02003099 if (tid_tx) {
3100 if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state))
3101 return false;
3102 if (tid_tx->timeout)
3103 tid_tx->last_tx = jiffies;
3104 }
Johannes Berg17c18bf2015-03-21 15:25:43 +01003105 }
3106
3107 /* after this point (skb is modified) we cannot return false */
3108
3109 if (skb_shared(skb)) {
3110 struct sk_buff *tmp_skb = skb;
3111
3112 skb = skb_clone(skb, GFP_ATOMIC);
3113 kfree_skb(tmp_skb);
3114
3115 if (!skb)
3116 return true;
3117 }
3118
Johannes Berg5a490512015-04-22 17:10:38 +02003119 ieee80211_tx_stats(dev, skb->len + extra_head);
Johannes Berg17c18bf2015-03-21 15:25:43 +01003120
Felix Fietkau6e0456b2016-03-03 22:59:00 +01003121 if ((hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) &&
3122 ieee80211_amsdu_aggregate(sdata, sta, fast_tx, skb))
3123 return true;
3124
Johannes Berg17c18bf2015-03-21 15:25:43 +01003125 /* will not be crypto-handled beyond what we do here, so use false
3126 * as the may-encrypt argument for the resize to not account for
3127 * more room than we already have in 'extra_head'
3128 */
3129 if (unlikely(ieee80211_skb_resize(sdata, skb,
3130 max_t(int, extra_head + hw_headroom -
3131 skb_headroom(skb), 0),
3132 false))) {
3133 kfree_skb(skb);
3134 return true;
3135 }
3136
3137 memcpy(&eth, skb->data, ETH_HLEN - 2);
3138 hdr = (void *)skb_push(skb, extra_head);
3139 memcpy(skb->data, fast_tx->hdr, fast_tx->hdr_len);
3140 memcpy(skb->data + fast_tx->da_offs, eth.h_dest, ETH_ALEN);
3141 memcpy(skb->data + fast_tx->sa_offs, eth.h_source, ETH_ALEN);
3142
3143 memset(info, 0, sizeof(*info));
3144 info->band = fast_tx->band;
3145 info->control.vif = &sdata->vif;
3146 info->flags = IEEE80211_TX_CTL_FIRST_FRAGMENT |
3147 IEEE80211_TX_CTL_DONTFRAG |
3148 (tid_tx ? IEEE80211_TX_CTL_AMPDU : 0);
3149
3150 if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
3151 *ieee80211_get_qos_ctl(hdr) = tid;
Felix Fietkau50f36ae2015-09-24 14:59:48 +02003152 if (!sta->sta.txq[0])
3153 hdr->seq_ctrl = ieee80211_tx_next_seq(sta, tid);
Johannes Berg17c18bf2015-03-21 15:25:43 +01003154 } else {
3155 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
3156 hdr->seq_ctrl = cpu_to_le16(sdata->sequence_number);
3157 sdata->sequence_number += 0x10;
3158 }
3159
Johannes Bergccc6bb92015-06-23 11:50:52 +02003160 if (skb_shinfo(skb)->gso_size)
Johannes Berge5a9f8d2015-10-16 17:54:47 +02003161 sta->tx_stats.msdu[tid] +=
Johannes Bergccc6bb92015-06-23 11:50:52 +02003162 DIV_ROUND_UP(skb->len, skb_shinfo(skb)->gso_size);
3163 else
Johannes Berge5a9f8d2015-10-16 17:54:47 +02003164 sta->tx_stats.msdu[tid]++;
Johannes Berg17c18bf2015-03-21 15:25:43 +01003165
3166 info->hw_queue = sdata->vif.hw_queue[skb_get_queue_mapping(skb)];
3167
3168 __skb_queue_head_init(&tx.skbs);
3169
3170 tx.flags = IEEE80211_TX_UNICAST;
3171 tx.local = local;
3172 tx.sdata = sdata;
3173 tx.sta = sta;
3174 tx.key = fast_tx->key;
3175
3176 if (fast_tx->key)
3177 info->control.hw_key = &fast_tx->key->conf;
3178
Johannes Berg30686bf2015-06-02 21:39:54 +02003179 if (!ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
Johannes Berg17c18bf2015-03-21 15:25:43 +01003180 tx.skb = skb;
3181 r = ieee80211_tx_h_rate_ctrl(&tx);
3182 skb = tx.skb;
3183 tx.skb = NULL;
3184
3185 if (r != TX_CONTINUE) {
3186 if (r != TX_QUEUED)
3187 kfree_skb(skb);
3188 return true;
3189 }
3190 }
3191
3192 /* statistics normally done by ieee80211_tx_h_stats (but that
3193 * has to consider fragmentation, so is more complex)
3194 */
Johannes Berge5a9f8d2015-10-16 17:54:47 +02003195 sta->tx_stats.bytes[skb_get_queue_mapping(skb)] += skb->len;
3196 sta->tx_stats.packets[skb_get_queue_mapping(skb)]++;
Johannes Berg17c18bf2015-03-21 15:25:43 +01003197
3198 if (fast_tx->pn_offs) {
3199 u64 pn;
3200 u8 *crypto_hdr = skb->data + fast_tx->pn_offs;
3201
3202 switch (fast_tx->key->conf.cipher) {
3203 case WLAN_CIPHER_SUITE_CCMP:
3204 case WLAN_CIPHER_SUITE_CCMP_256:
Johannes Berg17c18bf2015-03-21 15:25:43 +01003205 case WLAN_CIPHER_SUITE_GCMP:
3206 case WLAN_CIPHER_SUITE_GCMP_256:
Johannes Bergdb388a52015-06-01 15:36:51 +02003207 pn = atomic64_inc_return(&fast_tx->key->conf.tx_pn);
Johannes Berg17c18bf2015-03-21 15:25:43 +01003208 crypto_hdr[0] = pn;
3209 crypto_hdr[1] = pn >> 8;
3210 crypto_hdr[4] = pn >> 16;
3211 crypto_hdr[5] = pn >> 24;
3212 crypto_hdr[6] = pn >> 32;
3213 crypto_hdr[7] = pn >> 40;
3214 break;
3215 }
3216 }
3217
3218 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
3219 sdata = container_of(sdata->bss,
3220 struct ieee80211_sub_if_data, u.ap);
3221
3222 __skb_queue_tail(&tx.skbs, skb);
3223 ieee80211_tx_frags(local, &sdata->vif, &sta->sta, &tx.skbs, false);
3224 return true;
3225}
3226
Johannes Berg4c9451e2014-11-09 18:50:10 +02003227void __ieee80211_subif_start_xmit(struct sk_buff *skb,
3228 struct net_device *dev,
3229 u32 info_flags)
3230{
3231 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg97ffe752015-03-21 09:13:45 +01003232 struct sta_info *sta;
Johannes Berg80616c02015-04-14 14:50:41 +02003233 struct sk_buff *next;
Johannes Berg4c9451e2014-11-09 18:50:10 +02003234
3235 if (unlikely(skb->len < ETH_HLEN)) {
3236 kfree_skb(skb);
3237 return;
3238 }
3239
3240 rcu_read_lock();
3241
Johannes Berg2d981fd2015-04-10 14:10:10 +02003242 if (ieee80211_lookup_ra_sta(sdata, skb, &sta))
3243 goto out_free;
Johannes Berg4c9451e2014-11-09 18:50:10 +02003244
Johannes Berg17c18bf2015-03-21 15:25:43 +01003245 if (!IS_ERR_OR_NULL(sta)) {
3246 struct ieee80211_fast_tx *fast_tx;
3247
3248 fast_tx = rcu_dereference(sta->fast_tx);
3249
3250 if (fast_tx &&
3251 ieee80211_xmit_fast(sdata, dev, sta, fast_tx, skb))
3252 goto out;
3253 }
3254
Johannes Berg80616c02015-04-14 14:50:41 +02003255 if (skb_is_gso(skb)) {
3256 struct sk_buff *segs;
Johannes Berg680a0da2015-04-13 16:58:25 +02003257
Johannes Berg80616c02015-04-14 14:50:41 +02003258 segs = skb_gso_segment(skb, 0);
3259 if (IS_ERR(segs)) {
Johannes Berg2d981fd2015-04-10 14:10:10 +02003260 goto out_free;
Johannes Berg80616c02015-04-14 14:50:41 +02003261 } else if (segs) {
3262 consume_skb(skb);
3263 skb = segs;
3264 }
3265 } else {
3266 /* we cannot process non-linear frames on this path */
3267 if (skb_linearize(skb)) {
3268 kfree_skb(skb);
3269 goto out;
3270 }
3271
3272 /* the frame could be fragmented, software-encrypted, and other
3273 * things so we cannot really handle checksum offload with it -
3274 * fix it up in software before we handle anything else.
3275 */
3276 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Johannes Bergf603f1f2015-05-05 15:25:33 +02003277 skb_set_transport_header(skb,
3278 skb_checksum_start_offset(skb));
Johannes Berg80616c02015-04-14 14:50:41 +02003279 if (skb_checksum_help(skb))
3280 goto out_free;
3281 }
Johannes Berg2d981fd2015-04-10 14:10:10 +02003282 }
3283
Johannes Berg80616c02015-04-14 14:50:41 +02003284 next = skb;
3285 while (next) {
3286 skb = next;
3287 next = skb->next;
Johannes Berg4c9451e2014-11-09 18:50:10 +02003288
Johannes Berg80616c02015-04-14 14:50:41 +02003289 skb->prev = NULL;
3290 skb->next = NULL;
Johannes Berg4c9451e2014-11-09 18:50:10 +02003291
Johannes Berg80616c02015-04-14 14:50:41 +02003292 skb = ieee80211_build_hdr(sdata, skb, info_flags, sta);
3293 if (IS_ERR(skb))
3294 goto out;
3295
Johannes Berg5a490512015-04-22 17:10:38 +02003296 ieee80211_tx_stats(dev, skb->len);
Johannes Berg80616c02015-04-14 14:50:41 +02003297
3298 ieee80211_xmit(sdata, sta, skb);
3299 }
Johannes Berg2d981fd2015-04-10 14:10:10 +02003300 goto out;
3301 out_free:
3302 kfree_skb(skb);
Johannes Berg4c9451e2014-11-09 18:50:10 +02003303 out:
3304 rcu_read_unlock();
3305}
3306
3307/**
3308 * ieee80211_subif_start_xmit - netif start_xmit function for 802.3 vifs
3309 * @skb: packet to be sent
3310 * @dev: incoming interface
3311 *
3312 * On failure skb will be freed.
3313 */
Liad Kaufman24d342c2014-11-09 18:50:07 +02003314netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
3315 struct net_device *dev)
3316{
3317 __ieee80211_subif_start_xmit(skb, dev, 0);
3318 return NETDEV_TX_OK;
3319}
Johannes Berge2ebc742007-07-27 15:43:22 +02003320
Johannes Berg7528ec52014-11-09 18:50:11 +02003321struct sk_buff *
3322ieee80211_build_data_template(struct ieee80211_sub_if_data *sdata,
3323 struct sk_buff *skb, u32 info_flags)
3324{
3325 struct ieee80211_hdr *hdr;
3326 struct ieee80211_tx_data tx = {
3327 .local = sdata->local,
3328 .sdata = sdata,
3329 };
Johannes Berg97ffe752015-03-21 09:13:45 +01003330 struct sta_info *sta;
Johannes Berg7528ec52014-11-09 18:50:11 +02003331
3332 rcu_read_lock();
3333
Johannes Berg97ffe752015-03-21 09:13:45 +01003334 if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) {
3335 kfree_skb(skb);
3336 skb = ERR_PTR(-EINVAL);
3337 goto out;
3338 }
3339
3340 skb = ieee80211_build_hdr(sdata, skb, info_flags, sta);
Johannes Berg7528ec52014-11-09 18:50:11 +02003341 if (IS_ERR(skb))
3342 goto out;
3343
3344 hdr = (void *)skb->data;
3345 tx.sta = sta_info_get(sdata, hdr->addr1);
3346 tx.skb = skb;
3347
3348 if (ieee80211_tx_h_select_key(&tx) != TX_CONTINUE) {
3349 rcu_read_unlock();
3350 kfree_skb(skb);
3351 return ERR_PTR(-EINVAL);
3352 }
3353
3354out:
3355 rcu_read_unlock();
3356 return skb;
3357}
3358
Johannes Berge2530082008-05-17 00:57:14 +02003359/*
3360 * ieee80211_clear_tx_pending may not be called in a context where
3361 * it is possible that it packets could come in again.
3362 */
Johannes Berge2ebc742007-07-27 15:43:22 +02003363void ieee80211_clear_tx_pending(struct ieee80211_local *local)
3364{
Felix Fietkau1f98ab72012-11-10 03:44:14 +01003365 struct sk_buff *skb;
Johannes Berg2de8e0d2009-03-23 17:28:35 +01003366 int i;
Johannes Berge2ebc742007-07-27 15:43:22 +02003367
Felix Fietkau1f98ab72012-11-10 03:44:14 +01003368 for (i = 0; i < local->hw.queues; i++) {
3369 while ((skb = skb_dequeue(&local->pending[i])) != NULL)
3370 ieee80211_free_txskb(&local->hw, skb);
3371 }
Johannes Berge2ebc742007-07-27 15:43:22 +02003372}
3373
Johannes Berg7bb45682011-02-24 14:42:06 +01003374/*
3375 * Returns false if the frame couldn't be transmitted but was queued instead,
3376 * which in this case means re-queued -- take as an indication to stop sending
3377 * more pending frames.
3378 */
Johannes Bergcd8ffc82009-03-23 17:28:41 +01003379static bool ieee80211_tx_pending_skb(struct ieee80211_local *local,
3380 struct sk_buff *skb)
3381{
3382 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3383 struct ieee80211_sub_if_data *sdata;
3384 struct sta_info *sta;
3385 struct ieee80211_hdr *hdr;
Johannes Berg7bb45682011-02-24 14:42:06 +01003386 bool result;
Johannes Berg55de9082012-07-26 17:24:39 +02003387 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Bergcd8ffc82009-03-23 17:28:41 +01003388
Johannes Berg5061b0c2009-07-14 00:33:34 +02003389 sdata = vif_to_sdata(info->control.vif);
Johannes Bergcd8ffc82009-03-23 17:28:41 +01003390
3391 if (info->flags & IEEE80211_TX_INTFL_NEED_TXPROCESSING) {
Johannes Berg55de9082012-07-26 17:24:39 +02003392 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3393 if (unlikely(!chanctx_conf)) {
3394 dev_kfree_skb(skb);
3395 return true;
3396 }
Johannes Berg73c4e192014-11-09 18:50:09 +02003397 info->band = chanctx_conf->def.chan->band;
Johannes Berg7c107702015-03-20 14:18:27 +01003398 result = ieee80211_tx(sdata, NULL, skb, true);
Johannes Bergcd8ffc82009-03-23 17:28:41 +01003399 } else {
Johannes Berg252b86c2011-11-16 15:28:55 +01003400 struct sk_buff_head skbs;
3401
3402 __skb_queue_head_init(&skbs);
3403 __skb_queue_tail(&skbs, skb);
3404
Johannes Bergcd8ffc82009-03-23 17:28:41 +01003405 hdr = (struct ieee80211_hdr *)skb->data;
Johannes Bergabe60632009-11-25 17:46:18 +01003406 sta = sta_info_get(sdata, hdr->addr1);
Johannes Bergcd8ffc82009-03-23 17:28:41 +01003407
Johannes Berg74e4dbf2011-11-16 15:28:57 +01003408 result = __ieee80211_tx(local, &skbs, skb->len, sta, true);
Johannes Bergcd8ffc82009-03-23 17:28:41 +01003409 }
3410
Johannes Bergcd8ffc82009-03-23 17:28:41 +01003411 return result;
3412}
3413
Johannes Berge2530082008-05-17 00:57:14 +02003414/*
Johannes Berg3b8d81e02009-06-17 17:43:56 +02003415 * Transmit all pending packets. Called from tasklet.
Johannes Berge2530082008-05-17 00:57:14 +02003416 */
Johannes Berge2ebc742007-07-27 15:43:22 +02003417void ieee80211_tx_pending(unsigned long data)
3418{
3419 struct ieee80211_local *local = (struct ieee80211_local *)data;
Johannes Berg2a577d92009-03-23 17:28:37 +01003420 unsigned long flags;
Johannes Bergcd8ffc82009-03-23 17:28:41 +01003421 int i;
Johannes Berg3b8d81e02009-06-17 17:43:56 +02003422 bool txok;
Johannes Berge2ebc742007-07-27 15:43:22 +02003423
Johannes Bergf0e72852009-03-23 17:28:36 +01003424 rcu_read_lock();
Johannes Berg2a577d92009-03-23 17:28:37 +01003425
Johannes Berg3b8d81e02009-06-17 17:43:56 +02003426 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
Johannes Berg176be722009-03-12 23:49:28 +01003427 for (i = 0; i < local->hw.queues; i++) {
Johannes Berg2a577d92009-03-23 17:28:37 +01003428 /*
3429 * If queue is stopped by something other than due to pending
3430 * frames, or we have no pending frames, proceed to next queue.
3431 */
Johannes Berg3b8d81e02009-06-17 17:43:56 +02003432 if (local->queue_stop_reasons[i] ||
Johannes Berg2a577d92009-03-23 17:28:37 +01003433 skb_queue_empty(&local->pending[i]))
Johannes Berge2ebc742007-07-27 15:43:22 +02003434 continue;
Johannes Berge2530082008-05-17 00:57:14 +02003435
Johannes Berg2a577d92009-03-23 17:28:37 +01003436 while (!skb_queue_empty(&local->pending[i])) {
Johannes Berg3b8d81e02009-06-17 17:43:56 +02003437 struct sk_buff *skb = __skb_dequeue(&local->pending[i]);
Johannes Berg5061b0c2009-07-14 00:33:34 +02003438 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Johannes Berg5061b0c2009-07-14 00:33:34 +02003439
Johannes Berga7bc3762009-07-27 10:33:31 +02003440 if (WARN_ON(!info->control.vif)) {
Felix Fietkauc3e77242012-10-08 14:39:33 +02003441 ieee80211_free_txskb(&local->hw, skb);
Johannes Berga7bc3762009-07-27 10:33:31 +02003442 continue;
3443 }
3444
Johannes Berg3b8d81e02009-06-17 17:43:56 +02003445 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
3446 flags);
Johannes Berg2a577d92009-03-23 17:28:37 +01003447
Johannes Berg3b8d81e02009-06-17 17:43:56 +02003448 txok = ieee80211_tx_pending_skb(local, skb);
Johannes Berg3b8d81e02009-06-17 17:43:56 +02003449 spin_lock_irqsave(&local->queue_stop_reason_lock,
3450 flags);
3451 if (!txok)
Johannes Berg2a577d92009-03-23 17:28:37 +01003452 break;
Johannes Berge2ebc742007-07-27 15:43:22 +02003453 }
Johannes Berg7236fe22010-03-22 13:42:43 -07003454
3455 if (skb_queue_empty(&local->pending[i]))
Johannes Berg3a25a8c2012-04-03 16:28:50 +02003456 ieee80211_propagate_queue_wake(local, i);
Johannes Berge2ebc742007-07-27 15:43:22 +02003457 }
Johannes Berg3b8d81e02009-06-17 17:43:56 +02003458 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
Johannes Berg2a577d92009-03-23 17:28:37 +01003459
Johannes Bergf0e72852009-03-23 17:28:36 +01003460 rcu_read_unlock();
Johannes Berge2ebc742007-07-27 15:43:22 +02003461}
3462
3463/* functions for drivers to get certain frames */
3464
Marco Porscheac70c12013-01-07 16:04:50 +01003465static void __ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
Andrei Otcheretianski6ec8c332014-05-09 14:11:49 +03003466 struct ps_data *ps, struct sk_buff *skb,
3467 bool is_template)
Johannes Berge2ebc742007-07-27 15:43:22 +02003468{
3469 u8 *pos, *tim;
3470 int aid0 = 0;
3471 int i, have_bits = 0, n1, n2;
3472
3473 /* Generate bitmap for TIM only if there are any STAs in power save
3474 * mode. */
Marco Porschd012a602012-10-10 12:39:50 -07003475 if (atomic_read(&ps->num_sta_ps) > 0)
Johannes Berge2ebc742007-07-27 15:43:22 +02003476 /* in the hope that this is faster than
3477 * checking byte-for-byte */
Weilong Chenf359d3f2013-12-18 15:44:16 +08003478 have_bits = !bitmap_empty((unsigned long *)ps->tim,
Johannes Berge2ebc742007-07-27 15:43:22 +02003479 IEEE80211_MAX_AID+1);
Andrei Otcheretianski6ec8c332014-05-09 14:11:49 +03003480 if (!is_template) {
3481 if (ps->dtim_count == 0)
3482 ps->dtim_count = sdata->vif.bss_conf.dtim_period - 1;
3483 else
3484 ps->dtim_count--;
3485 }
Johannes Berge2ebc742007-07-27 15:43:22 +02003486
3487 tim = pos = (u8 *) skb_put(skb, 6);
3488 *pos++ = WLAN_EID_TIM;
3489 *pos++ = 4;
Marco Porschd012a602012-10-10 12:39:50 -07003490 *pos++ = ps->dtim_count;
Johannes Berg88600202012-02-13 15:17:18 +01003491 *pos++ = sdata->vif.bss_conf.dtim_period;
Johannes Berge2ebc742007-07-27 15:43:22 +02003492
Marco Porschd012a602012-10-10 12:39:50 -07003493 if (ps->dtim_count == 0 && !skb_queue_empty(&ps->bc_buf))
Johannes Berge2ebc742007-07-27 15:43:22 +02003494 aid0 = 1;
3495
Marco Porschd012a602012-10-10 12:39:50 -07003496 ps->dtim_bc_mc = aid0 == 1;
Christian Lamparter512119b2011-01-31 20:48:44 +02003497
Johannes Berge2ebc742007-07-27 15:43:22 +02003498 if (have_bits) {
3499 /* Find largest even number N1 so that bits numbered 1 through
3500 * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits
3501 * (N2 + 1) x 8 through 2007 are 0. */
3502 n1 = 0;
3503 for (i = 0; i < IEEE80211_MAX_TIM_LEN; i++) {
Marco Porschd012a602012-10-10 12:39:50 -07003504 if (ps->tim[i]) {
Johannes Berge2ebc742007-07-27 15:43:22 +02003505 n1 = i & 0xfe;
3506 break;
3507 }
3508 }
3509 n2 = n1;
3510 for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) {
Marco Porschd012a602012-10-10 12:39:50 -07003511 if (ps->tim[i]) {
Johannes Berge2ebc742007-07-27 15:43:22 +02003512 n2 = i;
3513 break;
3514 }
3515 }
3516
3517 /* Bitmap control */
3518 *pos++ = n1 | aid0;
3519 /* Part Virt Bitmap */
Eliad Peller5220da32011-11-24 16:50:00 +02003520 skb_put(skb, n2 - n1);
Marco Porschd012a602012-10-10 12:39:50 -07003521 memcpy(pos, ps->tim + n1, n2 - n1 + 1);
Johannes Berge2ebc742007-07-27 15:43:22 +02003522
3523 tim[1] = n2 - n1 + 4;
Johannes Berge2ebc742007-07-27 15:43:22 +02003524 } else {
3525 *pos++ = aid0; /* Bitmap control */
3526 *pos++ = 0; /* Part Virt Bitmap */
3527 }
Johannes Berge2ebc742007-07-27 15:43:22 +02003528}
3529
Marco Porscheac70c12013-01-07 16:04:50 +01003530static int ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
Andrei Otcheretianski6ec8c332014-05-09 14:11:49 +03003531 struct ps_data *ps, struct sk_buff *skb,
3532 bool is_template)
Marco Porscheac70c12013-01-07 16:04:50 +01003533{
3534 struct ieee80211_local *local = sdata->local;
3535
3536 /*
3537 * Not very nice, but we want to allow the driver to call
3538 * ieee80211_beacon_get() as a response to the set_tim()
3539 * callback. That, however, is already invoked under the
3540 * sta_lock to guarantee consistent and race-free update
3541 * of the tim bitmap in mac80211 and the driver.
3542 */
3543 if (local->tim_in_locked_section) {
Andrei Otcheretianski6ec8c332014-05-09 14:11:49 +03003544 __ieee80211_beacon_add_tim(sdata, ps, skb, is_template);
Marco Porscheac70c12013-01-07 16:04:50 +01003545 } else {
Johannes Berg1b917312013-02-22 12:55:01 +01003546 spin_lock_bh(&local->tim_lock);
Andrei Otcheretianski6ec8c332014-05-09 14:11:49 +03003547 __ieee80211_beacon_add_tim(sdata, ps, skb, is_template);
Johannes Berg1b917312013-02-22 12:55:01 +01003548 spin_unlock_bh(&local->tim_lock);
Marco Porscheac70c12013-01-07 16:04:50 +01003549 }
3550
3551 return 0;
3552}
3553
Andrei Otcheretianski1af586c2014-05-09 14:11:50 +03003554static void ieee80211_set_csa(struct ieee80211_sub_if_data *sdata,
3555 struct beacon_data *beacon)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003556{
3557 struct probe_resp *resp;
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003558 u8 *beacon_data;
3559 size_t beacon_data_len;
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003560 int i;
Michal Kazioraf296bd2014-06-05 14:21:36 +02003561 u8 count = beacon->csa_current_counter;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003562
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003563 switch (sdata->vif.type) {
3564 case NL80211_IFTYPE_AP:
3565 beacon_data = beacon->tail;
3566 beacon_data_len = beacon->tail_len;
3567 break;
3568 case NL80211_IFTYPE_ADHOC:
3569 beacon_data = beacon->head;
3570 beacon_data_len = beacon->head_len;
3571 break;
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -07003572 case NL80211_IFTYPE_MESH_POINT:
3573 beacon_data = beacon->head;
3574 beacon_data_len = beacon->head_len;
3575 break;
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003576 default:
3577 return;
3578 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003579
Michal Kazioraf296bd2014-06-05 14:21:36 +02003580 rcu_read_lock();
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003581 for (i = 0; i < IEEE80211_MAX_CSA_COUNTERS_NUM; ++i) {
Michal Kazioraf296bd2014-06-05 14:21:36 +02003582 resp = rcu_dereference(sdata->u.ap.probe_resp);
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003583
Michal Kazioraf296bd2014-06-05 14:21:36 +02003584 if (beacon->csa_counter_offsets[i]) {
3585 if (WARN_ON_ONCE(beacon->csa_counter_offsets[i] >=
3586 beacon_data_len)) {
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003587 rcu_read_unlock();
3588 return;
3589 }
Michal Kazioraf296bd2014-06-05 14:21:36 +02003590
3591 beacon_data[beacon->csa_counter_offsets[i]] = count;
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003592 }
Michal Kazioraf296bd2014-06-05 14:21:36 +02003593
3594 if (sdata->vif.type == NL80211_IFTYPE_AP && resp)
3595 resp->data[resp->csa_counter_offsets[i]] = count;
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003596 }
Michal Kazioraf296bd2014-06-05 14:21:36 +02003597 rcu_read_unlock();
Andrei Otcheretianski1af586c2014-05-09 14:11:50 +03003598}
3599
Wojciech Dubowike996ec22015-06-10 13:06:53 +02003600static u8 __ieee80211_csa_update_counter(struct beacon_data *beacon)
3601{
3602 beacon->csa_current_counter--;
3603
3604 /* the counter should never reach 0 */
3605 WARN_ON_ONCE(!beacon->csa_current_counter);
3606
3607 return beacon->csa_current_counter;
3608}
3609
Andrei Otcheretianski1af586c2014-05-09 14:11:50 +03003610u8 ieee80211_csa_update_counter(struct ieee80211_vif *vif)
3611{
3612 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
Michal Kazioraf296bd2014-06-05 14:21:36 +02003613 struct beacon_data *beacon = NULL;
3614 u8 count = 0;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003615
Michal Kazioraf296bd2014-06-05 14:21:36 +02003616 rcu_read_lock();
3617
3618 if (sdata->vif.type == NL80211_IFTYPE_AP)
3619 beacon = rcu_dereference(sdata->u.ap.beacon);
3620 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3621 beacon = rcu_dereference(sdata->u.ibss.presp);
3622 else if (ieee80211_vif_is_mesh(&sdata->vif))
3623 beacon = rcu_dereference(sdata->u.mesh.beacon);
3624
3625 if (!beacon)
3626 goto unlock;
3627
Wojciech Dubowike996ec22015-06-10 13:06:53 +02003628 count = __ieee80211_csa_update_counter(beacon);
Andrei Otcheretianski1af586c2014-05-09 14:11:50 +03003629
Michal Kazioraf296bd2014-06-05 14:21:36 +02003630unlock:
3631 rcu_read_unlock();
3632 return count;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003633}
Andrei Otcheretianski1af586c2014-05-09 14:11:50 +03003634EXPORT_SYMBOL(ieee80211_csa_update_counter);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003635
3636bool ieee80211_csa_is_complete(struct ieee80211_vif *vif)
3637{
3638 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3639 struct beacon_data *beacon = NULL;
3640 u8 *beacon_data;
3641 size_t beacon_data_len;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003642 int ret = false;
3643
3644 if (!ieee80211_sdata_running(sdata))
3645 return false;
3646
3647 rcu_read_lock();
3648 if (vif->type == NL80211_IFTYPE_AP) {
3649 struct ieee80211_if_ap *ap = &sdata->u.ap;
3650
3651 beacon = rcu_dereference(ap->beacon);
3652 if (WARN_ON(!beacon || !beacon->tail))
3653 goto out;
3654 beacon_data = beacon->tail;
3655 beacon_data_len = beacon->tail_len;
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003656 } else if (vif->type == NL80211_IFTYPE_ADHOC) {
3657 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
3658
3659 beacon = rcu_dereference(ifibss->presp);
3660 if (!beacon)
3661 goto out;
3662
3663 beacon_data = beacon->head;
3664 beacon_data_len = beacon->head_len;
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -07003665 } else if (vif->type == NL80211_IFTYPE_MESH_POINT) {
3666 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3667
3668 beacon = rcu_dereference(ifmsh->beacon);
3669 if (!beacon)
3670 goto out;
3671
3672 beacon_data = beacon->head;
3673 beacon_data_len = beacon->head_len;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003674 } else {
3675 WARN_ON(1);
3676 goto out;
3677 }
3678
Michal Kazior10d78f22014-06-05 14:21:37 +02003679 if (!beacon->csa_counter_offsets[0])
3680 goto out;
3681
Michal Kazioraf296bd2014-06-05 14:21:36 +02003682 if (WARN_ON_ONCE(beacon->csa_counter_offsets[0] > beacon_data_len))
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003683 goto out;
3684
Michal Kazioraf296bd2014-06-05 14:21:36 +02003685 if (beacon_data[beacon->csa_counter_offsets[0]] == 1)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003686 ret = true;
3687 out:
3688 rcu_read_unlock();
3689
3690 return ret;
3691}
3692EXPORT_SYMBOL(ieee80211_csa_is_complete);
3693
Andrei Otcheretianski6ec8c332014-05-09 14:11:49 +03003694static struct sk_buff *
3695__ieee80211_beacon_get(struct ieee80211_hw *hw,
3696 struct ieee80211_vif *vif,
3697 struct ieee80211_mutable_offsets *offs,
3698 bool is_template)
Johannes Berge2ebc742007-07-27 15:43:22 +02003699{
3700 struct ieee80211_local *local = hw_to_local(hw);
Michal Kazioraf296bd2014-06-05 14:21:36 +02003701 struct beacon_data *beacon = NULL;
Johannes Berg9d139c82008-07-09 14:40:37 +02003702 struct sk_buff *skb = NULL;
Johannes Berge039fa42008-05-15 12:55:29 +02003703 struct ieee80211_tx_info *info;
Johannes Berge2ebc742007-07-27 15:43:22 +02003704 struct ieee80211_sub_if_data *sdata = NULL;
Johannes Berg57fbcce2016-04-12 15:56:15 +02003705 enum nl80211_band band;
Jouni Malinene00cfce2009-12-29 12:59:19 +02003706 struct ieee80211_tx_rate_control txrc;
Johannes Berg55de9082012-07-26 17:24:39 +02003707 struct ieee80211_chanctx_conf *chanctx_conf;
Andrei Otcheretianski1af586c2014-05-09 14:11:50 +03003708 int csa_off_base = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01003709
Johannes Berg5dfdaf52007-12-19 02:03:33 +01003710 rcu_read_lock();
Johannes Berge2ebc742007-07-27 15:43:22 +02003711
Johannes Berg32bfd352007-12-19 01:31:26 +01003712 sdata = vif_to_sdata(vif);
Johannes Berg55de9082012-07-26 17:24:39 +02003713 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
Johannes Berge2ebc742007-07-27 15:43:22 +02003714
Johannes Berg55de9082012-07-26 17:24:39 +02003715 if (!ieee80211_sdata_running(sdata) || !chanctx_conf)
Felix Fietkaueb3e5542011-01-24 19:28:49 +01003716 goto out;
3717
Andrei Otcheretianski6ec8c332014-05-09 14:11:49 +03003718 if (offs)
3719 memset(offs, 0, sizeof(*offs));
Johannes Bergeddcbb942009-10-29 08:30:35 +01003720
Johannes Berg05c914f2008-09-11 00:01:58 +02003721 if (sdata->vif.type == NL80211_IFTYPE_AP) {
Marco Porschd012a602012-10-10 12:39:50 -07003722 struct ieee80211_if_ap *ap = &sdata->u.ap;
Marco Porschd012a602012-10-10 12:39:50 -07003723
Michal Kazioraf296bd2014-06-05 14:21:36 +02003724 beacon = rcu_dereference(ap->beacon);
Dan Carpenter3ad97fb2011-02-07 22:03:35 +03003725 if (beacon) {
Michal Kazior10d78f22014-06-05 14:21:37 +02003726 if (beacon->csa_counter_offsets[0]) {
Andrei Otcheretianski1af586c2014-05-09 14:11:50 +03003727 if (!is_template)
Wojciech Dubowike996ec22015-06-10 13:06:53 +02003728 __ieee80211_csa_update_counter(beacon);
Andrei Otcheretianski1af586c2014-05-09 14:11:50 +03003729
3730 ieee80211_set_csa(sdata, beacon);
3731 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003732
Johannes Berg902acc72008-02-23 15:17:19 +01003733 /*
3734 * headroom, head length,
3735 * tail length and maximum TIM length
3736 */
3737 skb = dev_alloc_skb(local->tx_headroom +
3738 beacon->head_len +
Felix Fietkau70dabeb2013-12-14 13:54:53 +01003739 beacon->tail_len + 256 +
3740 local->hw.extra_beacon_tailroom);
Johannes Berg902acc72008-02-23 15:17:19 +01003741 if (!skb)
3742 goto out;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01003743
Johannes Berg902acc72008-02-23 15:17:19 +01003744 skb_reserve(skb, local->tx_headroom);
3745 memcpy(skb_put(skb, beacon->head_len), beacon->head,
3746 beacon->head_len);
3747
Andrei Otcheretianski6ec8c332014-05-09 14:11:49 +03003748 ieee80211_beacon_add_tim(sdata, &ap->ps, skb,
3749 is_template);
Johannes Berg902acc72008-02-23 15:17:19 +01003750
Andrei Otcheretianski6ec8c332014-05-09 14:11:49 +03003751 if (offs) {
3752 offs->tim_offset = beacon->head_len;
3753 offs->tim_length = skb->len - beacon->head_len;
Andrei Otcheretianski1af586c2014-05-09 14:11:50 +03003754
3755 /* for AP the csa offsets are from tail */
3756 csa_off_base = skb->len;
Andrei Otcheretianski6ec8c332014-05-09 14:11:49 +03003757 }
Johannes Bergeddcbb942009-10-29 08:30:35 +01003758
Johannes Berg902acc72008-02-23 15:17:19 +01003759 if (beacon->tail)
3760 memcpy(skb_put(skb, beacon->tail_len),
3761 beacon->tail, beacon->tail_len);
Johannes Berg9d139c82008-07-09 14:40:37 +02003762 } else
3763 goto out;
Johannes Berg05c914f2008-09-11 00:01:58 +02003764 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
Johannes Berg46900292009-02-15 12:44:28 +01003765 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
Johannes Berg9d139c82008-07-09 14:40:37 +02003766 struct ieee80211_hdr *hdr;
Johannes Berg902acc72008-02-23 15:17:19 +01003767
Michal Kazioraf296bd2014-06-05 14:21:36 +02003768 beacon = rcu_dereference(ifibss->presp);
3769 if (!beacon)
Johannes Berg9d139c82008-07-09 14:40:37 +02003770 goto out;
3771
Michal Kazior10d78f22014-06-05 14:21:37 +02003772 if (beacon->csa_counter_offsets[0]) {
Andrei Otcheretianski1af586c2014-05-09 14:11:50 +03003773 if (!is_template)
Wojciech Dubowike996ec22015-06-10 13:06:53 +02003774 __ieee80211_csa_update_counter(beacon);
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003775
Michal Kazioraf296bd2014-06-05 14:21:36 +02003776 ieee80211_set_csa(sdata, beacon);
Andrei Otcheretianski1af586c2014-05-09 14:11:50 +03003777 }
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003778
Michal Kazioraf296bd2014-06-05 14:21:36 +02003779 skb = dev_alloc_skb(local->tx_headroom + beacon->head_len +
Felix Fietkau70dabeb2013-12-14 13:54:53 +01003780 local->hw.extra_beacon_tailroom);
Johannes Berg9d139c82008-07-09 14:40:37 +02003781 if (!skb)
3782 goto out;
Johannes Bergc3ffeab2013-03-07 20:54:29 +01003783 skb_reserve(skb, local->tx_headroom);
Michal Kazioraf296bd2014-06-05 14:21:36 +02003784 memcpy(skb_put(skb, beacon->head_len), beacon->head,
3785 beacon->head_len);
Johannes Berg9d139c82008-07-09 14:40:37 +02003786
3787 hdr = (struct ieee80211_hdr *) skb->data;
Harvey Harrisone7827a72008-07-15 18:44:13 -07003788 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3789 IEEE80211_STYPE_BEACON);
Johannes Berg902acc72008-02-23 15:17:19 +01003790 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
Javier Cardonadbf498f2012-03-31 11:31:32 -07003791 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Johannes Berg472dbc42008-09-11 00:01:49 +02003792
Michal Kazioraf296bd2014-06-05 14:21:36 +02003793 beacon = rcu_dereference(ifmsh->beacon);
3794 if (!beacon)
Johannes Bergac1bd842011-01-18 13:45:32 +01003795 goto out;
Johannes Bergac1bd842011-01-18 13:45:32 +01003796
Michal Kazior10d78f22014-06-05 14:21:37 +02003797 if (beacon->csa_counter_offsets[0]) {
Andrei Otcheretianski1af586c2014-05-09 14:11:50 +03003798 if (!is_template)
3799 /* TODO: For mesh csa_counter is in TU, so
3800 * decrementing it by one isn't correct, but
3801 * for now we leave it consistent with overall
3802 * mac80211's behavior.
3803 */
Wojciech Dubowike996ec22015-06-10 13:06:53 +02003804 __ieee80211_csa_update_counter(beacon);
Andrei Otcheretianski1af586c2014-05-09 14:11:50 +03003805
Michal Kazioraf296bd2014-06-05 14:21:36 +02003806 ieee80211_set_csa(sdata, beacon);
Andrei Otcheretianski1af586c2014-05-09 14:11:50 +03003807 }
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -07003808
Javier Cardonadbf498f2012-03-31 11:31:32 -07003809 if (ifmsh->sync_ops)
Michal Kazioraf296bd2014-06-05 14:21:36 +02003810 ifmsh->sync_ops->adjust_tbtt(sdata, beacon);
Javier Cardonadbf498f2012-03-31 11:31:32 -07003811
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -07003812 skb = dev_alloc_skb(local->tx_headroom +
Michal Kazioraf296bd2014-06-05 14:21:36 +02003813 beacon->head_len +
Marco Porsch3f52b7e2013-01-30 18:14:08 +01003814 256 + /* TIM IE */
Michal Kazioraf296bd2014-06-05 14:21:36 +02003815 beacon->tail_len +
Felix Fietkau70dabeb2013-12-14 13:54:53 +01003816 local->hw.extra_beacon_tailroom);
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01003817 if (!skb)
3818 goto out;
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08003819 skb_reserve(skb, local->tx_headroom);
Michal Kazioraf296bd2014-06-05 14:21:36 +02003820 memcpy(skb_put(skb, beacon->head_len), beacon->head,
3821 beacon->head_len);
Andrei Otcheretianski6ec8c332014-05-09 14:11:49 +03003822 ieee80211_beacon_add_tim(sdata, &ifmsh->ps, skb, is_template);
3823
3824 if (offs) {
Michal Kazioraf296bd2014-06-05 14:21:36 +02003825 offs->tim_offset = beacon->head_len;
3826 offs->tim_length = skb->len - beacon->head_len;
Andrei Otcheretianski6ec8c332014-05-09 14:11:49 +03003827 }
3828
Michal Kazioraf296bd2014-06-05 14:21:36 +02003829 memcpy(skb_put(skb, beacon->tail_len), beacon->tail,
3830 beacon->tail_len);
Johannes Berg9d139c82008-07-09 14:40:37 +02003831 } else {
3832 WARN_ON(1);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01003833 goto out;
Johannes Berge2ebc742007-07-27 15:43:22 +02003834 }
3835
Andrei Otcheretianski1af586c2014-05-09 14:11:50 +03003836 /* CSA offsets */
Michal Kazioraf296bd2014-06-05 14:21:36 +02003837 if (offs && beacon) {
Andrei Otcheretianski1af586c2014-05-09 14:11:50 +03003838 int i;
3839
3840 for (i = 0; i < IEEE80211_MAX_CSA_COUNTERS_NUM; i++) {
Michal Kazioraf296bd2014-06-05 14:21:36 +02003841 u16 csa_off = beacon->csa_counter_offsets[i];
Andrei Otcheretianski1af586c2014-05-09 14:11:50 +03003842
3843 if (!csa_off)
3844 continue;
3845
3846 offs->csa_counter_offs[i] = csa_off_base + csa_off;
3847 }
3848 }
3849
Johannes Berg4bf88532012-11-09 11:39:59 +01003850 band = chanctx_conf->def.chan->band;
Johannes Berg55de9082012-07-26 17:24:39 +02003851
Johannes Berge039fa42008-05-15 12:55:29 +02003852 info = IEEE80211_SKB_CB(skb);
Johannes Berge2ebc742007-07-27 15:43:22 +02003853
Johannes Berg3b8d81e02009-06-17 17:43:56 +02003854 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
Jouni Malinene00cfce2009-12-29 12:59:19 +02003855 info->flags |= IEEE80211_TX_CTL_NO_ACK;
Johannes Berge039fa42008-05-15 12:55:29 +02003856 info->band = band;
Jouni Malinene00cfce2009-12-29 12:59:19 +02003857
3858 memset(&txrc, 0, sizeof(txrc));
3859 txrc.hw = hw;
Johannes Berge31583c2012-07-26 14:07:46 +02003860 txrc.sband = local->hw.wiphy->bands[band];
Jouni Malinene00cfce2009-12-29 12:59:19 +02003861 txrc.bss_conf = &sdata->vif.bss_conf;
3862 txrc.skb = skb;
3863 txrc.reported_rate.idx = -1;
Jouni Malinen37eb0b12010-01-06 13:09:08 +02003864 txrc.rate_idx_mask = sdata->rc_rateidx_mask[band];
Johannes Berge31583c2012-07-26 14:07:46 +02003865 if (txrc.rate_idx_mask == (1 << txrc.sband->n_bitrates) - 1)
Jouni Malinen37eb0b12010-01-06 13:09:08 +02003866 txrc.max_rate_idx = -1;
3867 else
3868 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
Felix Fietkau8f0729b2010-11-11 15:07:23 +01003869 txrc.bss = true;
Jouni Malinene00cfce2009-12-29 12:59:19 +02003870 rate_control_get_rate(sdata, NULL, &txrc);
Johannes Berge039fa42008-05-15 12:55:29 +02003871
3872 info->control.vif = vif;
Johannes Bergf591fa52008-07-10 11:21:26 +02003873
John W. Linvillea472e712010-05-06 14:45:17 -04003874 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT |
3875 IEEE80211_TX_CTL_ASSIGN_SEQ |
3876 IEEE80211_TX_CTL_FIRST_FRAGMENT;
Johannes Berge6a98542008-10-21 12:40:02 +02003877 out:
Johannes Berg5dfdaf52007-12-19 02:03:33 +01003878 rcu_read_unlock();
Johannes Berge2ebc742007-07-27 15:43:22 +02003879 return skb;
Andrei Otcheretianski6ec8c332014-05-09 14:11:49 +03003880
3881}
3882
3883struct sk_buff *
3884ieee80211_beacon_get_template(struct ieee80211_hw *hw,
3885 struct ieee80211_vif *vif,
3886 struct ieee80211_mutable_offsets *offs)
3887{
3888 return __ieee80211_beacon_get(hw, vif, offs, true);
3889}
3890EXPORT_SYMBOL(ieee80211_beacon_get_template);
3891
3892struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
3893 struct ieee80211_vif *vif,
3894 u16 *tim_offset, u16 *tim_length)
3895{
3896 struct ieee80211_mutable_offsets offs = {};
3897 struct sk_buff *bcn = __ieee80211_beacon_get(hw, vif, &offs, false);
Helmut Schaa35afa582015-09-09 09:46:32 +02003898 struct sk_buff *copy;
3899 struct ieee80211_supported_band *sband;
3900 int shift;
3901
3902 if (!bcn)
3903 return bcn;
Andrei Otcheretianski6ec8c332014-05-09 14:11:49 +03003904
3905 if (tim_offset)
3906 *tim_offset = offs.tim_offset;
3907
3908 if (tim_length)
3909 *tim_length = offs.tim_length;
3910
Helmut Schaa35afa582015-09-09 09:46:32 +02003911 if (ieee80211_hw_check(hw, BEACON_TX_STATUS) ||
3912 !hw_to_local(hw)->monitors)
3913 return bcn;
3914
3915 /* send a copy to monitor interfaces */
3916 copy = skb_copy(bcn, GFP_ATOMIC);
3917 if (!copy)
3918 return bcn;
3919
3920 shift = ieee80211_vif_get_shift(vif);
3921 sband = hw->wiphy->bands[ieee80211_get_sdata_band(vif_to_sdata(vif))];
3922 ieee80211_tx_monitor(hw_to_local(hw), copy, sband, 1, shift, false);
3923
Andrei Otcheretianski6ec8c332014-05-09 14:11:49 +03003924 return bcn;
Johannes Berge2ebc742007-07-27 15:43:22 +02003925}
Johannes Bergeddcbb942009-10-29 08:30:35 +01003926EXPORT_SYMBOL(ieee80211_beacon_get_tim);
Johannes Berge2ebc742007-07-27 15:43:22 +02003927
Arik Nemtsov02945822011-11-10 11:28:57 +02003928struct sk_buff *ieee80211_proberesp_get(struct ieee80211_hw *hw,
3929 struct ieee80211_vif *vif)
3930{
3931 struct ieee80211_if_ap *ap = NULL;
Eyal Shapiraaa7a0082012-08-06 14:26:16 +03003932 struct sk_buff *skb = NULL;
3933 struct probe_resp *presp = NULL;
Arik Nemtsov02945822011-11-10 11:28:57 +02003934 struct ieee80211_hdr *hdr;
3935 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3936
3937 if (sdata->vif.type != NL80211_IFTYPE_AP)
3938 return NULL;
3939
3940 rcu_read_lock();
3941
3942 ap = &sdata->u.ap;
3943 presp = rcu_dereference(ap->probe_resp);
3944 if (!presp)
3945 goto out;
3946
Eyal Shapiraaa7a0082012-08-06 14:26:16 +03003947 skb = dev_alloc_skb(presp->len);
Arik Nemtsov02945822011-11-10 11:28:57 +02003948 if (!skb)
3949 goto out;
3950
Eyal Shapiraaa7a0082012-08-06 14:26:16 +03003951 memcpy(skb_put(skb, presp->len), presp->data, presp->len);
3952
Arik Nemtsov02945822011-11-10 11:28:57 +02003953 hdr = (struct ieee80211_hdr *) skb->data;
3954 memset(hdr->addr1, 0, sizeof(hdr->addr1));
3955
3956out:
3957 rcu_read_unlock();
3958 return skb;
3959}
3960EXPORT_SYMBOL(ieee80211_proberesp_get);
3961
Kalle Valo7044cc52010-01-05 20:16:19 +02003962struct sk_buff *ieee80211_pspoll_get(struct ieee80211_hw *hw,
3963 struct ieee80211_vif *vif)
3964{
3965 struct ieee80211_sub_if_data *sdata;
3966 struct ieee80211_if_managed *ifmgd;
3967 struct ieee80211_pspoll *pspoll;
3968 struct ieee80211_local *local;
3969 struct sk_buff *skb;
3970
3971 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
3972 return NULL;
3973
3974 sdata = vif_to_sdata(vif);
3975 ifmgd = &sdata->u.mgd;
3976 local = sdata->local;
3977
3978 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll));
Joe Perchesd15b8452011-08-29 14:17:31 -07003979 if (!skb)
Kalle Valo7044cc52010-01-05 20:16:19 +02003980 return NULL;
Joe Perchesd15b8452011-08-29 14:17:31 -07003981
Kalle Valo7044cc52010-01-05 20:16:19 +02003982 skb_reserve(skb, local->hw.extra_tx_headroom);
3983
3984 pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll));
3985 memset(pspoll, 0, sizeof(*pspoll));
3986 pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
3987 IEEE80211_STYPE_PSPOLL);
3988 pspoll->aid = cpu_to_le16(ifmgd->aid);
3989
3990 /* aid in PS-Poll has its two MSBs each set to 1 */
3991 pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
3992
3993 memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN);
3994 memcpy(pspoll->ta, vif->addr, ETH_ALEN);
3995
3996 return skb;
3997}
3998EXPORT_SYMBOL(ieee80211_pspoll_get);
3999
4000struct sk_buff *ieee80211_nullfunc_get(struct ieee80211_hw *hw,
4001 struct ieee80211_vif *vif)
4002{
4003 struct ieee80211_hdr_3addr *nullfunc;
4004 struct ieee80211_sub_if_data *sdata;
4005 struct ieee80211_if_managed *ifmgd;
4006 struct ieee80211_local *local;
4007 struct sk_buff *skb;
4008
4009 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
4010 return NULL;
4011
4012 sdata = vif_to_sdata(vif);
4013 ifmgd = &sdata->u.mgd;
4014 local = sdata->local;
4015
4016 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*nullfunc));
Joe Perchesd15b8452011-08-29 14:17:31 -07004017 if (!skb)
Kalle Valo7044cc52010-01-05 20:16:19 +02004018 return NULL;
Joe Perchesd15b8452011-08-29 14:17:31 -07004019
Kalle Valo7044cc52010-01-05 20:16:19 +02004020 skb_reserve(skb, local->hw.extra_tx_headroom);
4021
4022 nullfunc = (struct ieee80211_hdr_3addr *) skb_put(skb,
4023 sizeof(*nullfunc));
4024 memset(nullfunc, 0, sizeof(*nullfunc));
4025 nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
4026 IEEE80211_STYPE_NULLFUNC |
4027 IEEE80211_FCTL_TODS);
4028 memcpy(nullfunc->addr1, ifmgd->bssid, ETH_ALEN);
4029 memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
4030 memcpy(nullfunc->addr3, ifmgd->bssid, ETH_ALEN);
4031
4032 return skb;
4033}
4034EXPORT_SYMBOL(ieee80211_nullfunc_get);
4035
Kalle Valo05e54ea2010-01-05 20:16:38 +02004036struct sk_buff *ieee80211_probereq_get(struct ieee80211_hw *hw,
Johannes Berga344d672014-06-12 22:24:31 +02004037 const u8 *src_addr,
Kalle Valo05e54ea2010-01-05 20:16:38 +02004038 const u8 *ssid, size_t ssid_len,
Johannes Bergb9a9ada2012-11-29 13:00:10 +01004039 size_t tailroom)
Kalle Valo05e54ea2010-01-05 20:16:38 +02004040{
Johannes Berga344d672014-06-12 22:24:31 +02004041 struct ieee80211_local *local = hw_to_local(hw);
Kalle Valo05e54ea2010-01-05 20:16:38 +02004042 struct ieee80211_hdr_3addr *hdr;
4043 struct sk_buff *skb;
4044 size_t ie_ssid_len;
4045 u8 *pos;
4046
Kalle Valo05e54ea2010-01-05 20:16:38 +02004047 ie_ssid_len = 2 + ssid_len;
4048
4049 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*hdr) +
Johannes Bergb9a9ada2012-11-29 13:00:10 +01004050 ie_ssid_len + tailroom);
Joe Perchesd15b8452011-08-29 14:17:31 -07004051 if (!skb)
Kalle Valo05e54ea2010-01-05 20:16:38 +02004052 return NULL;
Kalle Valo05e54ea2010-01-05 20:16:38 +02004053
4054 skb_reserve(skb, local->hw.extra_tx_headroom);
4055
4056 hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr));
4057 memset(hdr, 0, sizeof(*hdr));
4058 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
4059 IEEE80211_STYPE_PROBE_REQ);
Johannes Berge83e6542012-07-13 16:23:07 +02004060 eth_broadcast_addr(hdr->addr1);
Johannes Berga344d672014-06-12 22:24:31 +02004061 memcpy(hdr->addr2, src_addr, ETH_ALEN);
Johannes Berge83e6542012-07-13 16:23:07 +02004062 eth_broadcast_addr(hdr->addr3);
Kalle Valo05e54ea2010-01-05 20:16:38 +02004063
4064 pos = skb_put(skb, ie_ssid_len);
4065 *pos++ = WLAN_EID_SSID;
4066 *pos++ = ssid_len;
Stanislaw Gruszka88c868c2012-03-29 16:30:41 +02004067 if (ssid_len)
Kalle Valo05e54ea2010-01-05 20:16:38 +02004068 memcpy(pos, ssid, ssid_len);
4069 pos += ssid_len;
4070
Kalle Valo05e54ea2010-01-05 20:16:38 +02004071 return skb;
4072}
4073EXPORT_SYMBOL(ieee80211_probereq_get);
4074
Johannes Berg32bfd352007-12-19 01:31:26 +01004075void ieee80211_rts_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
Johannes Berge2ebc742007-07-27 15:43:22 +02004076 const void *frame, size_t frame_len,
Johannes Berge039fa42008-05-15 12:55:29 +02004077 const struct ieee80211_tx_info *frame_txctl,
Johannes Berge2ebc742007-07-27 15:43:22 +02004078 struct ieee80211_rts *rts)
4079{
4080 const struct ieee80211_hdr *hdr = frame;
Johannes Berge2ebc742007-07-27 15:43:22 +02004081
Harvey Harrison065e96052008-06-22 16:45:27 -07004082 rts->frame_control =
4083 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
Johannes Berg32bfd352007-12-19 01:31:26 +01004084 rts->duration = ieee80211_rts_duration(hw, vif, frame_len,
4085 frame_txctl);
Johannes Berge2ebc742007-07-27 15:43:22 +02004086 memcpy(rts->ra, hdr->addr1, sizeof(rts->ra));
4087 memcpy(rts->ta, hdr->addr2, sizeof(rts->ta));
4088}
4089EXPORT_SYMBOL(ieee80211_rts_get);
4090
Johannes Berg32bfd352007-12-19 01:31:26 +01004091void ieee80211_ctstoself_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
Johannes Berge2ebc742007-07-27 15:43:22 +02004092 const void *frame, size_t frame_len,
Johannes Berge039fa42008-05-15 12:55:29 +02004093 const struct ieee80211_tx_info *frame_txctl,
Johannes Berge2ebc742007-07-27 15:43:22 +02004094 struct ieee80211_cts *cts)
4095{
4096 const struct ieee80211_hdr *hdr = frame;
Johannes Berge2ebc742007-07-27 15:43:22 +02004097
Harvey Harrison065e96052008-06-22 16:45:27 -07004098 cts->frame_control =
4099 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
Johannes Berg32bfd352007-12-19 01:31:26 +01004100 cts->duration = ieee80211_ctstoself_duration(hw, vif,
4101 frame_len, frame_txctl);
Johannes Berge2ebc742007-07-27 15:43:22 +02004102 memcpy(cts->ra, hdr->addr1, sizeof(cts->ra));
4103}
4104EXPORT_SYMBOL(ieee80211_ctstoself_get);
4105
4106struct sk_buff *
Johannes Berg32bfd352007-12-19 01:31:26 +01004107ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
Johannes Berge039fa42008-05-15 12:55:29 +02004108 struct ieee80211_vif *vif)
Johannes Berge2ebc742007-07-27 15:43:22 +02004109{
4110 struct ieee80211_local *local = hw_to_local(hw);
Tomas Winkler747cf5e2008-05-27 17:50:51 +03004111 struct sk_buff *skb = NULL;
Johannes Berg5cf121c2008-02-25 16:27:43 +01004112 struct ieee80211_tx_data tx;
Johannes Berge2ebc742007-07-27 15:43:22 +02004113 struct ieee80211_sub_if_data *sdata;
Marco Porschd012a602012-10-10 12:39:50 -07004114 struct ps_data *ps;
Johannes Berge039fa42008-05-15 12:55:29 +02004115 struct ieee80211_tx_info *info;
Johannes Berg55de9082012-07-26 17:24:39 +02004116 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berge2ebc742007-07-27 15:43:22 +02004117
Johannes Berg32bfd352007-12-19 01:31:26 +01004118 sdata = vif_to_sdata(vif);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01004119
Johannes Berg5dfdaf52007-12-19 02:03:33 +01004120 rcu_read_lock();
Johannes Berg55de9082012-07-26 17:24:39 +02004121 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01004122
Marco Porschd012a602012-10-10 12:39:50 -07004123 if (!chanctx_conf)
Tomas Winkler747cf5e2008-05-27 17:50:51 +03004124 goto out;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01004125
Marco Porschd012a602012-10-10 12:39:50 -07004126 if (sdata->vif.type == NL80211_IFTYPE_AP) {
4127 struct beacon_data *beacon =
4128 rcu_dereference(sdata->u.ap.beacon);
4129
4130 if (!beacon || !beacon->head)
4131 goto out;
4132
4133 ps = &sdata->u.ap.ps;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01004134 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
4135 ps = &sdata->u.mesh.ps;
Marco Porschd012a602012-10-10 12:39:50 -07004136 } else {
4137 goto out;
4138 }
4139
4140 if (ps->dtim_count != 0 || !ps->dtim_bc_mc)
Tomas Winkler747cf5e2008-05-27 17:50:51 +03004141 goto out; /* send buffered bc/mc only after DTIM beacon */
Johannes Berge039fa42008-05-15 12:55:29 +02004142
Johannes Berge2ebc742007-07-27 15:43:22 +02004143 while (1) {
Marco Porschd012a602012-10-10 12:39:50 -07004144 skb = skb_dequeue(&ps->bc_buf);
Johannes Berge2ebc742007-07-27 15:43:22 +02004145 if (!skb)
Tomas Winkler747cf5e2008-05-27 17:50:51 +03004146 goto out;
Johannes Berge2ebc742007-07-27 15:43:22 +02004147 local->total_ps_buffered--;
4148
Marco Porschd012a602012-10-10 12:39:50 -07004149 if (!skb_queue_empty(&ps->bc_buf) && skb->len >= 2) {
Johannes Berge2ebc742007-07-27 15:43:22 +02004150 struct ieee80211_hdr *hdr =
4151 (struct ieee80211_hdr *) skb->data;
4152 /* more buffered multicast/broadcast frames ==> set
4153 * MoreData flag in IEEE 802.11 header to inform PS
4154 * STAs */
4155 hdr->frame_control |=
4156 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
4157 }
4158
Michael Braun112c44b2014-03-06 15:08:43 +01004159 if (sdata->vif.type == NL80211_IFTYPE_AP)
Marco Porsch7cbf9d02013-03-01 16:01:18 +01004160 sdata = IEEE80211_DEV_TO_SUB_IF(skb->dev);
Johannes Berg7c107702015-03-20 14:18:27 +01004161 if (!ieee80211_tx_prepare(sdata, &tx, NULL, skb))
Johannes Berge2ebc742007-07-27 15:43:22 +02004162 break;
4163 dev_kfree_skb_any(skb);
4164 }
Johannes Berge039fa42008-05-15 12:55:29 +02004165
4166 info = IEEE80211_SKB_CB(skb);
4167
Johannes Berg5cf121c2008-02-25 16:27:43 +01004168 tx.flags |= IEEE80211_TX_PS_BUFFERED;
Johannes Berg4bf88532012-11-09 11:39:59 +01004169 info->band = chanctx_conf->def.chan->band;
Johannes Berge2ebc742007-07-27 15:43:22 +02004170
Johannes Berg97b045d2008-06-20 01:22:30 +02004171 if (invoke_tx_handlers(&tx))
Johannes Berge2ebc742007-07-27 15:43:22 +02004172 skb = NULL;
Johannes Berg97b045d2008-06-20 01:22:30 +02004173 out:
Johannes Bergd0709a62008-02-25 16:27:46 +01004174 rcu_read_unlock();
Johannes Berge2ebc742007-07-27 15:43:22 +02004175
4176 return skb;
4177}
4178EXPORT_SYMBOL(ieee80211_get_buffered_bc);
Johannes Berg3b8d81e02009-06-17 17:43:56 +02004179
Liad Kaufmanb6da9112014-11-19 13:47:38 +02004180int ieee80211_reserve_tid(struct ieee80211_sta *pubsta, u8 tid)
4181{
4182 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
4183 struct ieee80211_sub_if_data *sdata = sta->sdata;
4184 struct ieee80211_local *local = sdata->local;
4185 int ret;
4186 u32 queues;
4187
4188 lockdep_assert_held(&local->sta_mtx);
4189
4190 /* only some cases are supported right now */
4191 switch (sdata->vif.type) {
4192 case NL80211_IFTYPE_STATION:
4193 case NL80211_IFTYPE_AP:
4194 case NL80211_IFTYPE_AP_VLAN:
4195 break;
4196 default:
4197 WARN_ON(1);
4198 return -EINVAL;
4199 }
4200
4201 if (WARN_ON(tid >= IEEE80211_NUM_UPS))
4202 return -EINVAL;
4203
4204 if (sta->reserved_tid == tid) {
4205 ret = 0;
4206 goto out;
4207 }
4208
4209 if (sta->reserved_tid != IEEE80211_TID_UNRESERVED) {
4210 sdata_err(sdata, "TID reservation already active\n");
4211 ret = -EALREADY;
4212 goto out;
4213 }
4214
4215 ieee80211_stop_vif_queues(sdata->local, sdata,
4216 IEEE80211_QUEUE_STOP_REASON_RESERVE_TID);
4217
4218 synchronize_net();
4219
4220 /* Tear down BA sessions so we stop aggregating on this TID */
Johannes Berg30686bf2015-06-02 21:39:54 +02004221 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION)) {
Liad Kaufmanb6da9112014-11-19 13:47:38 +02004222 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
4223 __ieee80211_stop_tx_ba_session(sta, tid,
4224 AGG_STOP_LOCAL_REQUEST);
4225 }
4226
4227 queues = BIT(sdata->vif.hw_queue[ieee802_1d_to_ac[tid]]);
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02004228 __ieee80211_flush_queues(local, sdata, queues, false);
Liad Kaufmanb6da9112014-11-19 13:47:38 +02004229
4230 sta->reserved_tid = tid;
4231
4232 ieee80211_wake_vif_queues(local, sdata,
4233 IEEE80211_QUEUE_STOP_REASON_RESERVE_TID);
4234
Johannes Berg30686bf2015-06-02 21:39:54 +02004235 if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION))
Liad Kaufmanb6da9112014-11-19 13:47:38 +02004236 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
4237
4238 ret = 0;
4239 out:
4240 return ret;
4241}
4242EXPORT_SYMBOL(ieee80211_reserve_tid);
4243
4244void ieee80211_unreserve_tid(struct ieee80211_sta *pubsta, u8 tid)
4245{
4246 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
4247 struct ieee80211_sub_if_data *sdata = sta->sdata;
4248
4249 lockdep_assert_held(&sdata->local->sta_mtx);
4250
4251 /* only some cases are supported right now */
4252 switch (sdata->vif.type) {
4253 case NL80211_IFTYPE_STATION:
4254 case NL80211_IFTYPE_AP:
4255 case NL80211_IFTYPE_AP_VLAN:
4256 break;
4257 default:
4258 WARN_ON(1);
4259 return;
4260 }
4261
4262 if (tid != sta->reserved_tid) {
4263 sdata_err(sdata, "TID to unreserve (%d) isn't reserved\n", tid);
4264 return;
4265 }
4266
4267 sta->reserved_tid = IEEE80211_TID_UNRESERVED;
4268}
4269EXPORT_SYMBOL(ieee80211_unreserve_tid);
4270
Johannes Berg55de9082012-07-26 17:24:39 +02004271void __ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata,
4272 struct sk_buff *skb, int tid,
Johannes Berg57fbcce2016-04-12 15:56:15 +02004273 enum nl80211_band band)
Johannes Berg3b8d81e02009-06-17 17:43:56 +02004274{
Christian Lamparter353d09c2012-07-07 15:07:13 +02004275 int ac = ieee802_1d_to_ac[tid & 7];
Johannes Berg3a25a8c2012-04-03 16:28:50 +02004276
Zhang Shengjud57a5442016-03-03 01:16:56 +00004277 skb_reset_mac_header(skb);
4278 skb_reset_network_header(skb);
4279 skb_reset_transport_header(skb);
Johannes Berg3b8d81e02009-06-17 17:43:56 +02004280
Johannes Berg3a25a8c2012-04-03 16:28:50 +02004281 skb_set_queue_mapping(skb, ac);
Helmut Schaacf6bb792011-12-15 10:18:34 +01004282 skb->priority = tid;
Johannes Bergcf0277e2010-01-05 18:00:58 +01004283
Johannes Berg89afe612013-02-13 15:39:57 +01004284 skb->dev = sdata->dev;
4285
Johannes Berg3d34deb2009-06-18 17:25:11 +02004286 /*
4287 * The other path calling ieee80211_xmit is from the tasklet,
4288 * and while we can handle concurrent transmissions locking
4289 * requirements are that we do not come into tx with bhs on.
4290 */
4291 local_bh_disable();
Johannes Berg73c4e192014-11-09 18:50:09 +02004292 IEEE80211_SKB_CB(skb)->band = band;
Johannes Berg7c107702015-03-20 14:18:27 +01004293 ieee80211_xmit(sdata, NULL, skb);
Johannes Berg3d34deb2009-06-18 17:25:11 +02004294 local_bh_enable();
Johannes Berg3b8d81e02009-06-17 17:43:56 +02004295}