Commit | Line | Data |
---|---|---|
e2ebc74d JB |
1 | /* |
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> | |
d98ad83e | 6 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
e2ebc74d JB |
7 | * |
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> | |
d4e46a3d | 21 | #include <linux/rcupdate.h> |
bc3b2d7f | 22 | #include <linux/export.h> |
881d966b | 23 | #include <net/net_namespace.h> |
e2ebc74d JB |
24 | #include <net/ieee80211_radiotap.h> |
25 | #include <net/cfg80211.h> | |
26 | #include <net/mac80211.h> | |
27 | #include <asm/unaligned.h> | |
fa962b92 | 28 | #include <net/fq_impl.h> |
e2ebc74d JB |
29 | |
30 | #include "ieee80211_i.h" | |
24487981 | 31 | #include "driver-ops.h" |
2c8dccc7 | 32 | #include "led.h" |
33b64eb2 | 33 | #include "mesh.h" |
e2ebc74d JB |
34 | #include "wep.h" |
35 | #include "wpa.h" | |
36 | #include "wme.h" | |
2c8dccc7 | 37 | #include "rate.h" |
e2ebc74d | 38 | |
e2ebc74d JB |
39 | /* misc utils */ |
40 | ||
5a490510 JB |
41 | static 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 | ||
252b86c4 JB |
51 | static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, |
52 | struct sk_buff *skb, int group_addr, | |
03f93c3d | 53 | int next_frag_len) |
e2ebc74d | 54 | { |
2103dec1 | 55 | int rate, mrate, erp, dur, i, shift = 0; |
2e92e6f2 | 56 | struct ieee80211_rate *txrate; |
e2ebc74d | 57 | struct ieee80211_local *local = tx->local; |
8318d78a | 58 | struct ieee80211_supported_band *sband; |
358c8d9d | 59 | struct ieee80211_hdr *hdr; |
252b86c4 | 60 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
2103dec1 SW |
61 | 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(); | |
e6a9854b JB |
71 | |
72 | /* assume HW handles this */ | |
336004e2 | 73 | if (tx->rate.flags & (IEEE80211_TX_RC_MCS | IEEE80211_TX_RC_VHT_MCS)) |
e6a9854b JB |
74 | return 0; |
75 | ||
76 | /* uh huh? */ | |
0d528d85 | 77 | if (WARN_ON_ONCE(tx->rate.idx < 0)) |
e6a9854b | 78 | return 0; |
e2ebc74d | 79 | |
2d56577b | 80 | sband = local->hw.wiphy->bands[info->band]; |
0d528d85 | 81 | txrate = &sband->bitrates[tx->rate.idx]; |
8318d78a | 82 | |
e6a9854b | 83 | erp = txrate->flags & IEEE80211_RATE_ERP_G; |
e2ebc74d JB |
84 | |
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 | */ | |
252b86c4 | 102 | hdr = (struct ieee80211_hdr *)skb->data; |
358c8d9d | 103 | if (ieee80211_is_ctl(hdr->frame_control)) { |
e2ebc74d | 104 | /* TODO: These control frames are not currently sent by |
ccd7b362 | 105 | * mac80211, but should they be implemented, this function |
e2ebc74d JB |
106 | * 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 */) | |
03f93c3d | 123 | return cpu_to_le16(32768); |
e2ebc74d JB |
124 | |
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; | |
8318d78a JB |
139 | /* 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]; | |
e2ebc74d | 143 | |
8318d78a JB |
144 | if (r->bitrate > txrate->bitrate) |
145 | break; | |
e2ebc74d | 146 | |
2103dec1 SW |
147 | if ((rate_flags & r->flags) != rate_flags) |
148 | continue; | |
149 | ||
bda3933a | 150 | if (tx->sdata->vif.bss_conf.basic_rates & BIT(i)) |
2103dec1 | 151 | rate = DIV_ROUND_UP(r->bitrate, 1 << shift); |
8318d78a JB |
152 | |
153 | switch (sband->band) { | |
57fbcce3 | 154 | case NL80211_BAND_2GHZ: { |
8318d78a JB |
155 | 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 | } | |
57fbcce3 | 164 | case NL80211_BAND_5GHZ: |
8318d78a JB |
165 | if (r->flags & IEEE80211_RATE_MANDATORY_A) |
166 | mrate = r->bitrate; | |
167 | break; | |
57fbcce3 | 168 | case NL80211_BAND_60GHZ: |
3a0c52a6 | 169 | /* TODO, for now fall through */ |
57fbcce3 | 170 | case NUM_NL80211_BANDS: |
8318d78a JB |
171 | WARN_ON(1); |
172 | break; | |
173 | } | |
e2ebc74d JB |
174 | } |
175 | if (rate == -1) { | |
176 | /* No matching basic rate found; use highest suitable mandatory | |
177 | * PHY rate */ | |
2103dec1 | 178 | rate = DIV_ROUND_UP(mrate, 1 << shift); |
e2ebc74d JB |
179 | } |
180 | ||
6674f210 SW |
181 | /* Don't calculate ACKs for QoS Frames with NoAck Policy set */ |
182 | if (ieee80211_is_data_qos(hdr->frame_control) && | |
c26a0e10 | 183 | *(ieee80211_get_qos_ctl(hdr)) & IEEE80211_QOS_CTL_ACK_POLICY_NOACK) |
6674f210 SW |
184 | 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 */ | |
4ee73f33 | 189 | dur = ieee80211_frame_duration(sband->band, 10, rate, erp, |
438b61b7 SW |
190 | tx->sdata->vif.bss_conf.use_short_preamble, |
191 | shift); | |
e2ebc74d JB |
192 | |
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 */ | |
4ee73f33 | 198 | dur += ieee80211_frame_duration(sband->band, next_frag_len, |
8318d78a | 199 | txrate->bitrate, erp, |
438b61b7 SW |
200 | tx->sdata->vif.bss_conf.use_short_preamble, |
201 | shift); | |
e2ebc74d JB |
202 | } |
203 | ||
03f93c3d | 204 | return cpu_to_le16(dur); |
e2ebc74d JB |
205 | } |
206 | ||
e2ebc74d | 207 | /* tx handlers */ |
5c1b98a5 KV |
208 | static ieee80211_tx_result debug_noinline |
209 | ieee80211_tx_h_dynamic_ps(struct ieee80211_tx_data *tx) | |
210 | { | |
211 | struct ieee80211_local *local = tx->local; | |
0c74211d | 212 | struct ieee80211_if_managed *ifmgd; |
5c1b98a5 KV |
213 | |
214 | /* driver doesn't support power save */ | |
30686bf7 | 215 | if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) |
5c1b98a5 KV |
216 | return TX_CONTINUE; |
217 | ||
218 | /* hardware does dynamic power save */ | |
30686bf7 | 219 | if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) |
5c1b98a5 KV |
220 | 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 | ||
0c74211d KV |
237 | /* 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 | * | |
dc41e4d4 | 252 | * Note: ifmgd->uapsd_queues access is racy here. If the value is |
0c74211d KV |
253 | * changed via debugfs, user needs to reassociate manually to have |
254 | * everything in sync. | |
255 | */ | |
4875d30d JB |
256 | 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) | |
0c74211d KV |
259 | return TX_CONTINUE; |
260 | ||
5c1b98a5 KV |
261 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
262 | ieee80211_stop_queues_by_reason(&local->hw, | |
445ea4e8 | 263 | IEEE80211_MAX_QUEUE_MAP, |
cca07b00 LC |
264 | IEEE80211_QUEUE_STOP_REASON_PS, |
265 | false); | |
db28569a | 266 | ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED; |
5c1b98a5 KV |
267 | ieee80211_queue_work(&local->hw, |
268 | &local->dynamic_ps_disable_work); | |
269 | } | |
270 | ||
5db1c07c LC |
271 | /* Don't restart the timer if we're not disassociated */ |
272 | if (!ifmgd->associated) | |
273 | return TX_CONTINUE; | |
274 | ||
5c1b98a5 KV |
275 | mod_timer(&local->dynamic_ps_timer, jiffies + |
276 | msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout)); | |
277 | ||
278 | return TX_CONTINUE; | |
279 | } | |
e2ebc74d | 280 | |
d9e8a70f | 281 | static ieee80211_tx_result debug_noinline |
5cf121c3 | 282 | ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx) |
e2ebc74d | 283 | { |
358c8d9d | 284 | |
e039fa4a | 285 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; |
e039fa4a | 286 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); |
c2c98fde | 287 | bool assoc = false; |
e2ebc74d | 288 | |
e039fa4a | 289 | if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED)) |
9ae54c84 | 290 | return TX_CONTINUE; |
58d4185e | 291 | |
b23b025f BG |
292 | if (unlikely(test_bit(SCAN_SW_SCANNING, &tx->local->scanning)) && |
293 | test_bit(SDATA_STATE_OFFCHANNEL, &tx->sdata->state) && | |
a9a6ffff KV |
294 | !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 | */ | |
9ae54c84 | 307 | return TX_DROP; |
e2ebc74d | 308 | |
239281f8 RL |
309 | if (tx->sdata->vif.type == NL80211_IFTYPE_OCB) |
310 | return TX_CONTINUE; | |
311 | ||
1be7fe8d BJ |
312 | if (tx->sdata->vif.type == NL80211_IFTYPE_WDS) |
313 | return TX_CONTINUE; | |
314 | ||
5cf121c3 | 315 | if (tx->flags & IEEE80211_TX_PS_BUFFERED) |
9ae54c84 | 316 | return TX_CONTINUE; |
e2ebc74d | 317 | |
c2c98fde JB |
318 | if (tx->sta) |
319 | assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC); | |
e2ebc74d | 320 | |
5cf121c3 | 321 | if (likely(tx->flags & IEEE80211_TX_UNICAST)) { |
c2c98fde | 322 | if (unlikely(!assoc && |
358c8d9d | 323 | ieee80211_is_data(hdr->frame_control))) { |
e2ebc74d | 324 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
bdcbd8e0 JB |
325 | sdata_info(tx->sdata, |
326 | "dropped data frame to not associated station %pM\n", | |
327 | hdr->addr1); | |
328 | #endif | |
e2ebc74d | 329 | I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc); |
9ae54c84 | 330 | return TX_DROP; |
e2ebc74d | 331 | } |
29623892 JB |
332 | } else if (unlikely(tx->sdata->vif.type == NL80211_IFTYPE_AP && |
333 | ieee80211_is_data(hdr->frame_control) && | |
030ef8f8 | 334 | !atomic_read(&tx->sdata->u.ap.num_mcast_sta))) { |
29623892 JB |
335 | /* |
336 | * No associated STAs - no need to send multicast | |
337 | * frames. | |
338 | */ | |
339 | return TX_DROP; | |
e2ebc74d JB |
340 | } |
341 | ||
9ae54c84 | 342 | return TX_CONTINUE; |
e2ebc74d JB |
343 | } |
344 | ||
e2ebc74d JB |
345 | /* 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. */ | |
349 | static 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 | ||
79010420 | 356 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
d012a605 MP |
357 | struct ps_data *ps; |
358 | ||
359 | if (sdata->vif.type == NL80211_IFTYPE_AP) | |
360 | ps = &sdata->u.ap.ps; | |
3f52b7e3 MP |
361 | else if (ieee80211_vif_is_mesh(&sdata->vif)) |
362 | ps = &sdata->u.mesh.ps; | |
d012a605 | 363 | else |
e2ebc74d | 364 | continue; |
d012a605 MP |
365 | |
366 | skb = skb_dequeue(&ps->bc_buf); | |
e2ebc74d JB |
367 | if (skb) { |
368 | purged++; | |
369 | dev_kfree_skb(skb); | |
370 | } | |
d012a605 | 371 | total += skb_queue_len(&ps->bc_buf); |
e2ebc74d | 372 | } |
e2ebc74d | 373 | |
948d887d JB |
374 | /* |
375 | * Drop one frame from each station from the lowest-priority | |
376 | * AC that has frames at all. | |
377 | */ | |
d0709a65 | 378 | list_for_each_entry_rcu(sta, &local->sta_list, list) { |
948d887d JB |
379 | 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++; | |
c3e7724b | 386 | ieee80211_free_txskb(&local->hw, skb); |
948d887d JB |
387 | break; |
388 | } | |
e2ebc74d | 389 | } |
e2ebc74d | 390 | } |
d0709a65 | 391 | |
e2ebc74d | 392 | local->total_ps_buffered = total; |
bdcbd8e0 | 393 | ps_dbg_hw(&local->hw, "PS buffers full - purged %d frames\n", purged); |
e2ebc74d JB |
394 | } |
395 | ||
9ae54c84 | 396 | static ieee80211_tx_result |
5cf121c3 | 397 | ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx) |
e2ebc74d | 398 | { |
e039fa4a | 399 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); |
358c8d9d | 400 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; |
d012a605 | 401 | struct ps_data *ps; |
e039fa4a | 402 | |
7d54d0dd JB |
403 | /* |
404 | * broadcast/multicast frame | |
405 | * | |
3f52b7e3 | 406 | * If any of the associated/peer stations is in power save mode, |
7d54d0dd JB |
407 | * the frame is buffered to be sent after DTIM beacon frame. |
408 | * This is done either by the hardware or us. | |
409 | */ | |
410 | ||
3f52b7e3 | 411 | /* powersaving STAs currently only in AP/VLAN/mesh mode */ |
d012a605 MP |
412 | 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; | |
3f52b7e3 MP |
418 | } else if (ieee80211_vif_is_mesh(&tx->sdata->vif)) { |
419 | ps = &tx->sdata->u.mesh.ps; | |
d012a605 | 420 | } else { |
3e122be0 | 421 | return TX_CONTINUE; |
d012a605 MP |
422 | } |
423 | ||
3e122be0 JB |
424 | |
425 | /* no buffering for ordered frames */ | |
358c8d9d | 426 | if (ieee80211_has_order(hdr->frame_control)) |
9ae54c84 | 427 | return TX_CONTINUE; |
7d54d0dd | 428 | |
08b99399 JB |
429 | if (ieee80211_is_probe_req(hdr->frame_control)) |
430 | return TX_CONTINUE; | |
431 | ||
30686bf7 | 432 | if (ieee80211_hw_check(&tx->local->hw, QUEUE_CONTROL)) |
f4d57941 JB |
433 | info->hw_queue = tx->sdata->vif.cab_queue; |
434 | ||
7d54d0dd | 435 | /* no stations in PS mode */ |
d012a605 | 436 | if (!atomic_read(&ps->num_sta_ps)) |
9ae54c84 | 437 | return TX_CONTINUE; |
7d54d0dd | 438 | |
62b517cb | 439 | info->flags |= IEEE80211_TX_CTL_SEND_AFTER_DTIM; |
62b1208e | 440 | |
62b517cb | 441 | /* device releases frame after DTIM beacon */ |
30686bf7 | 442 | if (!ieee80211_hw_check(&tx->local->hw, HOST_BROADCAST_PS_BUFFERING)) |
62b1208e | 443 | return TX_CONTINUE; |
62b1208e | 444 | |
7d54d0dd | 445 | /* buffered in mac80211 */ |
62b1208e JB |
446 | if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER) |
447 | purge_old_ps_buffers(tx->local); | |
448 | ||
d012a605 | 449 | if (skb_queue_len(&ps->bc_buf) >= AP_MAX_BC_BUFFER) { |
bdcbd8e0 JB |
450 | ps_dbg(tx->sdata, |
451 | "BC TX buffer full - dropping the oldest frame\n"); | |
d012a605 | 452 | dev_kfree_skb(skb_dequeue(&ps->bc_buf)); |
62b1208e JB |
453 | } else |
454 | tx->local->total_ps_buffered++; | |
e2ebc74d | 455 | |
d012a605 | 456 | skb_queue_tail(&ps->bc_buf, tx->skb); |
7d54d0dd | 457 | |
62b1208e | 458 | return TX_QUEUED; |
e2ebc74d JB |
459 | } |
460 | ||
fb733336 JM |
461 | static 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 | ||
c2c98fde | 467 | if (sta == NULL || !test_sta_flag(sta, WLAN_STA_MFP)) |
fb733336 JM |
468 | return 0; |
469 | ||
d8ca16db | 470 | if (!ieee80211_is_robust_mgmt_frame(skb)) |
fb733336 JM |
471 | return 0; |
472 | ||
473 | return 1; | |
474 | } | |
475 | ||
9ae54c84 | 476 | static ieee80211_tx_result |
5cf121c3 | 477 | ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx) |
e2ebc74d JB |
478 | { |
479 | struct sta_info *sta = tx->sta; | |
e039fa4a | 480 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); |
08b99399 | 481 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; |
3393a608 | 482 | struct ieee80211_local *local = tx->local; |
e2ebc74d | 483 | |
02f2f1a9 | 484 | if (unlikely(!sta)) |
9ae54c84 | 485 | return TX_CONTINUE; |
e2ebc74d | 486 | |
c2c98fde | 487 | if (unlikely((test_sta_flag(sta, WLAN_STA_PS_STA) || |
5ac2e350 JB |
488 | test_sta_flag(sta, WLAN_STA_PS_DRIVER) || |
489 | test_sta_flag(sta, WLAN_STA_PS_DELIVER)) && | |
02f2f1a9 | 490 | !(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER))) { |
948d887d JB |
491 | int ac = skb_get_queue_mapping(tx->skb); |
492 | ||
08b99399 JB |
493 | 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 | ||
bdcbd8e0 JB |
499 | ps_dbg(sta->sdata, "STA %pM aid %d: PS buffer for AC %d\n", |
500 | sta->sta.addr, sta->sta.aid, ac); | |
e2ebc74d JB |
501 | if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER) |
502 | purge_old_ps_buffers(tx->local); | |
1d147bfa EG |
503 | |
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) && | |
5ac2e350 JB |
512 | !test_sta_flag(sta, WLAN_STA_PS_DRIVER) && |
513 | !test_sta_flag(sta, WLAN_STA_PS_DELIVER)) { | |
1d147bfa EG |
514 | spin_unlock(&sta->ps_lock); |
515 | return TX_CONTINUE; | |
516 | } | |
517 | ||
948d887d JB |
518 | 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]); | |
bdcbd8e0 JB |
520 | ps_dbg(tx->sdata, |
521 | "STA %pM TX buffer for AC %d full - dropping oldest frame\n", | |
522 | sta->sta.addr, ac); | |
c3e7724b | 523 | ieee80211_free_txskb(&local->hw, old); |
e2ebc74d JB |
524 | } else |
525 | tx->local->total_ps_buffered++; | |
004c872e | 526 | |
e039fa4a | 527 | info->control.jiffies = jiffies; |
5061b0c2 | 528 | info->control.vif = &tx->sdata->vif; |
8f77f384 | 529 | info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING; |
03c8c06f | 530 | info->flags &= ~IEEE80211_TX_TEMPORARY_FLAGS; |
948d887d | 531 | skb_queue_tail(&sta->ps_tx_buf[ac], tx->skb); |
1d147bfa | 532 | spin_unlock(&sta->ps_lock); |
3393a608 JO |
533 | |
534 | if (!timer_pending(&local->sta_cleanup)) | |
535 | mod_timer(&local->sta_cleanup, | |
536 | round_jiffies(jiffies + | |
537 | STA_INFO_CLEANUP_INTERVAL)); | |
538 | ||
c868cb35 JB |
539 | /* |
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 | ||
9ae54c84 | 545 | return TX_QUEUED; |
bdcbd8e0 JB |
546 | } 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); | |
e2ebc74d | 550 | } |
e2ebc74d | 551 | |
9ae54c84 | 552 | return TX_CONTINUE; |
e2ebc74d JB |
553 | } |
554 | ||
d9e8a70f | 555 | static ieee80211_tx_result debug_noinline |
5cf121c3 | 556 | ieee80211_tx_h_ps_buf(struct ieee80211_tx_data *tx) |
e2ebc74d | 557 | { |
5cf121c3 | 558 | if (unlikely(tx->flags & IEEE80211_TX_PS_BUFFERED)) |
9ae54c84 | 559 | return TX_CONTINUE; |
e2ebc74d | 560 | |
5cf121c3 | 561 | if (tx->flags & IEEE80211_TX_UNICAST) |
e2ebc74d JB |
562 | return ieee80211_tx_h_unicast_ps_buf(tx); |
563 | else | |
564 | return ieee80211_tx_h_multicast_ps_buf(tx); | |
565 | } | |
566 | ||
a621fa4d JB |
567 | static ieee80211_tx_result debug_noinline |
568 | ieee80211_tx_h_check_control_port_protocol(struct ieee80211_tx_data *tx) | |
569 | { | |
570 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); | |
571 | ||
af61a165 JB |
572 | 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; | |
9c1c98a3 | 576 | info->flags |= IEEE80211_TX_CTL_USE_MINRATE; |
af61a165 | 577 | } |
a621fa4d JB |
578 | |
579 | return TX_CONTINUE; | |
580 | } | |
581 | ||
d9e8a70f | 582 | static ieee80211_tx_result debug_noinline |
5cf121c3 | 583 | ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx) |
e2ebc74d | 584 | { |
46e6de15 | 585 | struct ieee80211_key *key; |
e039fa4a | 586 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); |
358c8d9d | 587 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; |
d4e46a3d | 588 | |
3b8d81e0 | 589 | if (unlikely(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)) |
e2ebc74d | 590 | tx->key = NULL; |
2475b1cc MS |
591 | else if (tx->sta && |
592 | (key = rcu_dereference(tx->sta->ptk[tx->sta->ptk_idx]))) | |
d4e46a3d | 593 | tx->key = key; |
3cfcf6ac | 594 | else if (ieee80211_is_mgmt(hdr->frame_control) && |
ecbcd324 | 595 | is_multicast_ether_addr(hdr->addr1) && |
d8ca16db | 596 | ieee80211_is_robust_mgmt_frame(tx->skb) && |
3cfcf6ac JM |
597 | (key = rcu_dereference(tx->sdata->default_mgmt_key))) |
598 | tx->key = key; | |
f7e0104c JB |
599 | 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))) | |
d4e46a3d | 604 | tx->key = key; |
e8f4fb7c | 605 | else |
4922f71f | 606 | tx->key = NULL; |
e2ebc74d JB |
607 | |
608 | if (tx->key) { | |
813d7669 JB |
609 | bool skip_hw = false; |
610 | ||
011bfcc4 | 611 | /* TODO: add threshold stuff again */ |
176e4f84 | 612 | |
97359d12 JB |
613 | switch (tx->key->conf.cipher) { |
614 | case WLAN_CIPHER_SUITE_WEP40: | |
615 | case WLAN_CIPHER_SUITE_WEP104: | |
97359d12 | 616 | case WLAN_CIPHER_SUITE_TKIP: |
358c8d9d | 617 | if (!ieee80211_is_data_present(hdr->frame_control)) |
176e4f84 JB |
618 | tx->key = NULL; |
619 | break; | |
97359d12 | 620 | case WLAN_CIPHER_SUITE_CCMP: |
2b2ba0db | 621 | case WLAN_CIPHER_SUITE_CCMP_256: |
00b9cfa3 JM |
622 | case WLAN_CIPHER_SUITE_GCMP: |
623 | case WLAN_CIPHER_SUITE_GCMP_256: | |
fb733336 JM |
624 | if (!ieee80211_is_data_present(hdr->frame_control) && |
625 | !ieee80211_use_mfp(hdr->frame_control, tx->sta, | |
626 | tx->skb)) | |
627 | tx->key = NULL; | |
3b43a187 KV |
628 | else |
629 | skip_hw = (tx->key->conf.flags & | |
e548c49e | 630 | IEEE80211_KEY_FLAG_SW_MGMT_TX) && |
3b43a187 | 631 | ieee80211_is_mgmt(hdr->frame_control); |
fb733336 | 632 | break; |
97359d12 | 633 | case WLAN_CIPHER_SUITE_AES_CMAC: |
56c52da2 | 634 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
8ade538b JM |
635 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
636 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: | |
3cfcf6ac JM |
637 | if (!ieee80211_is_mgmt(hdr->frame_control)) |
638 | tx->key = NULL; | |
639 | break; | |
176e4f84 | 640 | } |
813d7669 | 641 | |
e54faf29 JB |
642 | if (unlikely(tx->key && tx->key->flags & KEY_FLAG_TAINTED && |
643 | !ieee80211_is_deauth(hdr->frame_control))) | |
95acac61 JB |
644 | return TX_DROP; |
645 | ||
f12553eb | 646 | if (!skip_hw && tx->key && |
382b1655 | 647 | tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) |
813d7669 | 648 | info->control.hw_key = &tx->key->conf; |
e2ebc74d JB |
649 | } |
650 | ||
9ae54c84 | 651 | return TX_CONTINUE; |
e2ebc74d JB |
652 | } |
653 | ||
d9e8a70f | 654 | static ieee80211_tx_result debug_noinline |
5cf121c3 | 655 | ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx) |
e2ebc74d | 656 | { |
e039fa4a | 657 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); |
e6a9854b JB |
658 | struct ieee80211_hdr *hdr = (void *)tx->skb->data; |
659 | struct ieee80211_supported_band *sband; | |
a2c40249 | 660 | u32 len; |
e6a9854b | 661 | struct ieee80211_tx_rate_control txrc; |
0d528d85 | 662 | struct ieee80211_sta_rates *ratetbl = NULL; |
c2c98fde | 663 | bool assoc = false; |
8318d78a | 664 | |
e6a9854b | 665 | memset(&txrc, 0, sizeof(txrc)); |
e2ebc74d | 666 | |
2d56577b | 667 | sband = tx->local->hw.wiphy->bands[info->band]; |
58d4185e | 668 | |
a2c40249 | 669 | len = min_t(u32, tx->skb->len + FCS_LEN, |
b9a5f8ca | 670 | tx->local->hw.wiphy->frag_threshold); |
e6a9854b JB |
671 | |
672 | /* set up the tx rate control struct we give the RC algo */ | |
005e472b | 673 | txrc.hw = &tx->local->hw; |
e6a9854b JB |
674 | txrc.sband = sband; |
675 | txrc.bss_conf = &tx->sdata->vif.bss_conf; | |
676 | txrc.skb = tx->skb; | |
677 | txrc.reported_rate.idx = -1; | |
2d56577b | 678 | txrc.rate_idx_mask = tx->sdata->rc_rateidx_mask[info->band]; |
37eb0b16 JM |
679 | 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; | |
2ffbe6d3 FF |
683 | |
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 | ||
8f0729b1 | 688 | txrc.bss = (tx->sdata->vif.type == NL80211_IFTYPE_AP || |
4bb62344 | 689 | tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT || |
5765f9f6 BVB |
690 | tx->sdata->vif.type == NL80211_IFTYPE_ADHOC || |
691 | tx->sdata->vif.type == NL80211_IFTYPE_OCB); | |
e6a9854b JB |
692 | |
693 | /* set up RTS protection if desired */ | |
b9a5f8ca | 694 | if (len > tx->local->hw.wiphy->rts_threshold) { |
0d528d85 | 695 | txrc.rts = true; |
e2ebc74d | 696 | } |
e2ebc74d | 697 | |
0d528d85 | 698 | info->control.use_rts = txrc.rts; |
991fec09 FF |
699 | info->control.use_cts_prot = tx->sdata->vif.bss_conf.use_cts_prot; |
700 | ||
e6a9854b JB |
701 | /* |
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) || | |
c2c98fde | 709 | (tx->sta && test_sta_flag(tx->sta, WLAN_STA_SHORT_PREAMBLE)))) |
0d528d85 FF |
710 | txrc.short_preamble = true; |
711 | ||
712 | info->control.short_preamble = txrc.short_preamble; | |
e2ebc74d | 713 | |
dfdfc2be SE |
714 | /* 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 | ||
c2c98fde JB |
718 | if (tx->sta) |
719 | assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC); | |
b770b43e LR |
720 | |
721 | /* | |
722 | * Lets not bother rate control if we're associated and cannot | |
723 | * talk to the sta. This should not happen. | |
724 | */ | |
c2c98fde | 725 | if (WARN(test_bit(SCAN_SW_SCANNING, &tx->local->scanning) && assoc && |
b770b43e LR |
726 | !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", | |
47846c9b | 730 | tx->sdata->name, hdr->addr1, |
2d56577b | 731 | info->band ? 5 : 2)) |
b770b43e | 732 | return TX_DROP; |
2e92e6f2 | 733 | |
b770b43e LR |
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 | */ | |
e6a9854b JB |
738 | rate_control_get_rate(tx->sdata, tx->sta, &txrc); |
739 | ||
0d528d85 FF |
740 | 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 | } | |
e6a9854b | 761 | |
c1ce5a74 | 762 | if (txrc.reported_rate.idx < 0) { |
0d528d85 | 763 | txrc.reported_rate = tx->rate; |
c1ce5a74 | 764 | if (tx->sta && ieee80211_is_data(hdr->frame_control)) |
e5a9f8d0 | 765 | tx->sta->tx_stats.last_rate = txrc.reported_rate; |
c1ce5a74 | 766 | } else if (tx->sta) |
e5a9f8d0 | 767 | tx->sta->tx_stats.last_rate = txrc.reported_rate; |
e039fa4a | 768 | |
0d528d85 FF |
769 | if (ratetbl) |
770 | return TX_CONTINUE; | |
771 | ||
e6a9854b JB |
772 | if (unlikely(!info->control.rates[0].count)) |
773 | info->control.rates[0].count = 1; | |
e2ebc74d | 774 | |
9955151d GS |
775 | 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 | ||
e6a9854b JB |
779 | return TX_CONTINUE; |
780 | } | |
781 | ||
ba8c3d6f FF |
782 | static __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 | ||
f591fa5d JB |
793 | static ieee80211_tx_result debug_noinline |
794 | ieee80211_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; | |
f591fa5d JB |
798 | u8 *qc; |
799 | int tid; | |
800 | ||
25d834e1 JB |
801 | /* |
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 | */ | |
5061b0c2 | 806 | if (unlikely(info->control.vif->type == NL80211_IFTYPE_MONITOR)) |
25d834e1 JB |
807 | return TX_CONTINUE; |
808 | ||
f591fa5d JB |
809 | 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 | ||
49a59543 JB |
815 | if (ieee80211_is_qos_nullfunc(hdr->frame_control)) |
816 | return TX_CONTINUE; | |
817 | ||
94778280 JB |
818 | /* |
819 | * Anything but QoS data that has a sequence number field | |
820 | * (is long enough) gets a sequence number from the global | |
c4c205f3 BC |
821 | * counter. QoS data frames with a multicast destination |
822 | * also use the global counter (802.11-2012 9.3.2.10). | |
94778280 | 823 | */ |
c4c205f3 BC |
824 | if (!ieee80211_is_data_qos(hdr->frame_control) || |
825 | is_multicast_ether_addr(hdr->addr1)) { | |
94778280 | 826 | /* driver should assign sequence number */ |
f591fa5d | 827 | info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ; |
94778280 JB |
828 | /* 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; | |
79c892b8 | 831 | if (tx->sta) |
e5a9f8d0 | 832 | tx->sta->tx_stats.msdu[IEEE80211_NUM_TIDS]++; |
f591fa5d JB |
833 | 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; | |
e5a9f8d0 | 848 | tx->sta->tx_stats.msdu[tid]++; |
f591fa5d | 849 | |
ba8c3d6f FF |
850 | if (!tx->sta->sta.txq[0]) |
851 | hdr->seq_ctrl = ieee80211_tx_next_seq(tx->sta, tid); | |
f591fa5d JB |
852 | |
853 | return TX_CONTINUE; | |
854 | } | |
855 | ||
252b86c4 | 856 | static int ieee80211_fragment(struct ieee80211_tx_data *tx, |
2de8e0d9 JB |
857 | struct sk_buff *skb, int hdrlen, |
858 | int frag_threshold) | |
859 | { | |
252b86c4 | 860 | struct ieee80211_local *local = tx->local; |
a1a3fcec | 861 | struct ieee80211_tx_info *info; |
252b86c4 | 862 | struct sk_buff *tmp; |
2de8e0d9 JB |
863 | 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 | ||
252b86c4 JB |
870 | /* first fragment was already added to queue by caller */ |
871 | ||
2de8e0d9 JB |
872 | 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 + | |
2475b1cc | 880 | tx->sdata->encrypt_headroom + |
2de8e0d9 JB |
881 | IEEE80211_ENCRYPT_TAILROOM); |
882 | if (!tmp) | |
883 | return -ENOMEM; | |
252b86c4 JB |
884 | |
885 | __skb_queue_tail(&tx->skbs, tmp); | |
886 | ||
2475b1cc MS |
887 | skb_reserve(tmp, |
888 | local->tx_headroom + tx->sdata->encrypt_headroom); | |
889 | ||
2de8e0d9 JB |
890 | /* copy control information */ |
891 | memcpy(tmp->cb, skb->cb, sizeof(tmp->cb)); | |
a1a3fcec JB |
892 | |
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 | ||
2de8e0d9 JB |
900 | skb_copy_queue_mapping(tmp, skb); |
901 | tmp->priority = skb->priority; | |
2de8e0d9 | 902 | tmp->dev = skb->dev; |
2de8e0d9 JB |
903 | |
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 | ||
252b86c4 | 911 | /* adjust first fragment's length */ |
338f977f | 912 | skb_trim(skb, hdrlen + per_fragm); |
2de8e0d9 JB |
913 | return 0; |
914 | } | |
915 | ||
d9e8a70f | 916 | static ieee80211_tx_result debug_noinline |
e2454948 JB |
917 | ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx) |
918 | { | |
2de8e0d9 JB |
919 | struct sk_buff *skb = tx->skb; |
920 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | |
921 | struct ieee80211_hdr *hdr = (void *)skb->data; | |
b9a5f8ca | 922 | int frag_threshold = tx->local->hw.wiphy->frag_threshold; |
2de8e0d9 JB |
923 | int hdrlen; |
924 | int fragnum; | |
e2454948 | 925 | |
252b86c4 JB |
926 | /* no matter what happens, tx->skb moves to tx->skbs */ |
927 | __skb_queue_tail(&tx->skbs, skb); | |
928 | tx->skb = NULL; | |
929 | ||
a26eb27a JB |
930 | if (info->flags & IEEE80211_TX_CTL_DONTFRAG) |
931 | return TX_CONTINUE; | |
932 | ||
933 | if (tx->local->ops->set_frag_threshold) | |
e2454948 JB |
934 | return TX_CONTINUE; |
935 | ||
eefce91a JB |
936 | /* |
937 | * Warn when submitting a fragmented A-MPDU frame and drop it. | |
3b8d81e0 | 938 | * This scenario is handled in ieee80211_tx_prepare but extra |
8d5e0d58 | 939 | * caution taken here as fragmented ampdu may cause Tx stop. |
eefce91a | 940 | */ |
8b30b1fe | 941 | if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU)) |
eefce91a JB |
942 | return TX_DROP; |
943 | ||
065e9605 | 944 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
e2454948 | 945 | |
a26eb27a | 946 | /* internal error, why isn't DONTFRAG set? */ |
8ccd8f21 | 947 | if (WARN_ON(skb->len + FCS_LEN <= frag_threshold)) |
2de8e0d9 | 948 | return TX_DROP; |
e6a9854b | 949 | |
2de8e0d9 JB |
950 | /* |
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 | */ | |
252b86c4 | 958 | if (ieee80211_fragment(tx, skb, hdrlen, frag_threshold)) |
2de8e0d9 | 959 | return TX_DROP; |
e6a9854b | 960 | |
2de8e0d9 JB |
961 | /* update duration/seq/flags of fragments */ |
962 | fragnum = 0; | |
252b86c4 JB |
963 | |
964 | skb_queue_walk(&tx->skbs, skb) { | |
2de8e0d9 | 965 | const __le16 morefrags = cpu_to_le16(IEEE80211_FCTL_MOREFRAGS); |
e6a9854b | 966 | |
2de8e0d9 JB |
967 | hdr = (void *)skb->data; |
968 | info = IEEE80211_SKB_CB(skb); | |
e6a9854b | 969 | |
252b86c4 | 970 | if (!skb_queue_is_last(&tx->skbs, skb)) { |
2de8e0d9 | 971 | hdr->frame_control |= morefrags; |
e6a9854b JB |
972 | /* |
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; | |
e3e1a0bc | 979 | BUILD_BUG_ON(IEEE80211_TX_MAX_RATES != 4); |
e6a9854b | 980 | info->flags &= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE; |
2de8e0d9 JB |
981 | } else { |
982 | hdr->frame_control &= ~morefrags; | |
e6a9854b | 983 | } |
2de8e0d9 JB |
984 | hdr->seq_ctrl |= cpu_to_le16(fragnum & IEEE80211_SCTL_FRAG); |
985 | fragnum++; | |
252b86c4 | 986 | } |
e2ebc74d | 987 | |
9ae54c84 | 988 | return TX_CONTINUE; |
e2ebc74d JB |
989 | } |
990 | ||
feff1f2f JB |
991 | static ieee80211_tx_result debug_noinline |
992 | ieee80211_tx_h_stats(struct ieee80211_tx_data *tx) | |
993 | { | |
252b86c4 | 994 | struct sk_buff *skb; |
560d2682 | 995 | int ac = -1; |
feff1f2f JB |
996 | |
997 | if (!tx->sta) | |
998 | return TX_CONTINUE; | |
999 | ||
252b86c4 | 1000 | skb_queue_walk(&tx->skbs, skb) { |
560d2682 | 1001 | ac = skb_get_queue_mapping(skb); |
e5a9f8d0 | 1002 | tx->sta->tx_stats.bytes[ac] += skb->len; |
252b86c4 | 1003 | } |
560d2682 | 1004 | if (ac >= 0) |
e5a9f8d0 | 1005 | tx->sta->tx_stats.packets[ac]++; |
feff1f2f JB |
1006 | |
1007 | return TX_CONTINUE; | |
1008 | } | |
1009 | ||
d9e8a70f | 1010 | static ieee80211_tx_result debug_noinline |
e2454948 JB |
1011 | ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx) |
1012 | { | |
1013 | if (!tx->key) | |
1014 | return TX_CONTINUE; | |
1015 | ||
97359d12 JB |
1016 | switch (tx->key->conf.cipher) { |
1017 | case WLAN_CIPHER_SUITE_WEP40: | |
1018 | case WLAN_CIPHER_SUITE_WEP104: | |
e2454948 | 1019 | return ieee80211_crypto_wep_encrypt(tx); |
97359d12 | 1020 | case WLAN_CIPHER_SUITE_TKIP: |
e2454948 | 1021 | return ieee80211_crypto_tkip_encrypt(tx); |
97359d12 | 1022 | case WLAN_CIPHER_SUITE_CCMP: |
2b2ba0db JM |
1023 | 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); | |
97359d12 | 1028 | case WLAN_CIPHER_SUITE_AES_CMAC: |
3cfcf6ac | 1029 | return ieee80211_crypto_aes_cmac_encrypt(tx); |
56c52da2 JM |
1030 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
1031 | return ieee80211_crypto_aes_cmac_256_encrypt(tx); | |
8ade538b JM |
1032 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
1033 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: | |
1034 | return ieee80211_crypto_aes_gmac_encrypt(tx); | |
00b9cfa3 JM |
1035 | case WLAN_CIPHER_SUITE_GCMP: |
1036 | case WLAN_CIPHER_SUITE_GCMP_256: | |
1037 | return ieee80211_crypto_gcmp_encrypt(tx); | |
3ffc2a90 | 1038 | default: |
d32a1028 | 1039 | return ieee80211_crypto_hw_encrypt(tx); |
e2454948 JB |
1040 | } |
1041 | ||
e2454948 JB |
1042 | return TX_DROP; |
1043 | } | |
1044 | ||
d9e8a70f | 1045 | static ieee80211_tx_result debug_noinline |
03f93c3d JB |
1046 | ieee80211_tx_h_calculate_duration(struct ieee80211_tx_data *tx) |
1047 | { | |
252b86c4 | 1048 | struct sk_buff *skb; |
2de8e0d9 JB |
1049 | struct ieee80211_hdr *hdr; |
1050 | int next_len; | |
1051 | bool group_addr; | |
03f93c3d | 1052 | |
252b86c4 | 1053 | skb_queue_walk(&tx->skbs, skb) { |
2de8e0d9 | 1054 | hdr = (void *) skb->data; |
7e0aae47 JM |
1055 | if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) |
1056 | break; /* must not overwrite AID */ | |
252b86c4 JB |
1057 | 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; | |
2de8e0d9 | 1062 | group_addr = is_multicast_ether_addr(hdr->addr1); |
03f93c3d | 1063 | |
2de8e0d9 | 1064 | hdr->duration_id = |
252b86c4 JB |
1065 | ieee80211_duration(tx, skb, group_addr, next_len); |
1066 | } | |
03f93c3d JB |
1067 | |
1068 | return TX_CONTINUE; | |
1069 | } | |
1070 | ||
e2ebc74d JB |
1071 | /* actual transmit path */ |
1072 | ||
a622ab72 JB |
1073 | static 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; | |
285fa695 | 1080 | bool reset_agg_timer = false; |
aa454580 | 1081 | struct sk_buff *purge_skb = NULL; |
a622ab72 JB |
1082 | |
1083 | if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) { | |
1084 | info->flags |= IEEE80211_TX_CTL_AMPDU; | |
285fa695 | 1085 | reset_agg_timer = true; |
0ab33703 JB |
1086 | } 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 | */ | |
ba8c3d6f | 1091 | } else if (!tx->sta->sta.txq[tid]) { |
a622ab72 JB |
1092 | 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 | */ | |
40b275b6 | 1111 | tid_tx = rcu_dereference_protected_tid_tx(tx->sta, tid); |
a622ab72 JB |
1112 | |
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; | |
285fa695 | 1117 | reset_agg_timer = true; |
a622ab72 JB |
1118 | } else { |
1119 | queued = true; | |
f6d4671a EG |
1120 | 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 | } | |
a622ab72 JB |
1126 | info->control.vif = &tx->sdata->vif; |
1127 | info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING; | |
facde7f3 | 1128 | info->flags &= ~IEEE80211_TX_TEMPORARY_FLAGS; |
a622ab72 | 1129 | __skb_queue_tail(&tid_tx->pending, skb); |
aa454580 HS |
1130 | if (skb_queue_len(&tid_tx->pending) > STA_MAX_TX_BUFFER) |
1131 | purge_skb = __skb_dequeue(&tid_tx->pending); | |
a622ab72 JB |
1132 | } |
1133 | spin_unlock(&tx->sta->lock); | |
aa454580 HS |
1134 | |
1135 | if (purge_skb) | |
c3e7724b | 1136 | ieee80211_free_txskb(&tx->local->hw, purge_skb); |
a622ab72 JB |
1137 | } |
1138 | ||
285fa695 NM |
1139 | /* reset session timer */ |
1140 | if (reset_agg_timer && tid_tx->timeout) | |
12d3952f | 1141 | tid_tx->last_tx = jiffies; |
285fa695 | 1142 | |
a622ab72 JB |
1143 | return queued; |
1144 | } | |
1145 | ||
58d4185e JB |
1146 | /* |
1147 | * initialises @tx | |
7c10770f JB |
1148 | * 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 | |
58d4185e | 1150 | */ |
9ae54c84 | 1151 | static ieee80211_tx_result |
3b8d81e0 JB |
1152 | ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata, |
1153 | struct ieee80211_tx_data *tx, | |
7c10770f | 1154 | struct sta_info *sta, struct sk_buff *skb) |
e2ebc74d | 1155 | { |
3b8d81e0 | 1156 | struct ieee80211_local *local = sdata->local; |
58d4185e | 1157 | struct ieee80211_hdr *hdr; |
e039fa4a | 1158 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
68f2b517 | 1159 | int tid; |
a622ab72 | 1160 | u8 *qc; |
e2ebc74d JB |
1161 | |
1162 | memset(tx, 0, sizeof(*tx)); | |
1163 | tx->skb = skb; | |
e2ebc74d | 1164 | tx->local = local; |
3b8d81e0 | 1165 | tx->sdata = sdata; |
252b86c4 | 1166 | __skb_queue_head_init(&tx->skbs); |
e2ebc74d | 1167 | |
cd8ffc80 JB |
1168 | /* |
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 | ||
58d4185e JB |
1175 | hdr = (struct ieee80211_hdr *) skb->data; |
1176 | ||
7c10770f JB |
1177 | 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); | |
3f0e0b22 | 1192 | } |
58d4185e | 1193 | |
cd8ffc80 | 1194 | if (tx->sta && ieee80211_is_data_qos(hdr->frame_control) && |
49a59543 | 1195 | !ieee80211_is_qos_nullfunc(hdr->frame_control) && |
30686bf7 JB |
1196 | ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) && |
1197 | !ieee80211_hw_check(&local->hw, TX_AMPDU_SETUP_IN_HW)) { | |
cd8ffc80 JB |
1198 | struct tid_ampdu_tx *tid_tx; |
1199 | ||
8b30b1fe S |
1200 | qc = ieee80211_get_qos_ctl(hdr); |
1201 | tid = *qc & IEEE80211_QOS_CTL_TID_MASK; | |
1202 | ||
a622ab72 JB |
1203 | tid_tx = rcu_dereference(tx->sta->ampdu_mlme.tid_tx[tid]); |
1204 | if (tid_tx) { | |
1205 | bool queued; | |
cd8ffc80 | 1206 | |
a622ab72 JB |
1207 | queued = ieee80211_tx_prep_agg(tx, skb, info, |
1208 | tid_tx, tid); | |
1209 | ||
1210 | if (unlikely(queued)) | |
1211 | return TX_QUEUED; | |
1212 | } | |
8b30b1fe S |
1213 | } |
1214 | ||
badffb72 | 1215 | if (is_multicast_ether_addr(hdr->addr1)) { |
5cf121c3 | 1216 | tx->flags &= ~IEEE80211_TX_UNICAST; |
e039fa4a | 1217 | info->flags |= IEEE80211_TX_CTL_NO_ACK; |
6fd67e93 | 1218 | } else |
5cf121c3 | 1219 | tx->flags |= IEEE80211_TX_UNICAST; |
58d4185e | 1220 | |
a26eb27a JB |
1221 | 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; | |
58d4185e JB |
1226 | } |
1227 | ||
e2ebc74d | 1228 | if (!tx->sta) |
e039fa4a | 1229 | info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT; |
f7418bc1 | 1230 | else if (test_and_clear_sta_flag(tx->sta, WLAN_STA_CLEAR_PS_FILT)) { |
e039fa4a | 1231 | info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT; |
f7418bc1 FF |
1232 | ieee80211_check_fast_xmit(tx->sta); |
1233 | } | |
58d4185e | 1234 | |
e039fa4a | 1235 | info->flags |= IEEE80211_TX_CTL_FIRST_FRAGMENT; |
e2ebc74d | 1236 | |
9ae54c84 | 1237 | return TX_CONTINUE; |
e2ebc74d JB |
1238 | } |
1239 | ||
80a83cfc MK |
1240 | static 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) | |
ba8c3d6f FF |
1244 | { |
1245 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | |
ba8c3d6f | 1246 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
ba8c3d6f | 1247 | struct ieee80211_txq *txq = NULL; |
ba8c3d6f | 1248 | |
c3732a7b FF |
1249 | if ((info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) || |
1250 | (info->control.flags & IEEE80211_TX_CTRL_PS_RESPONSE)) | |
80a83cfc | 1251 | return NULL; |
ba8c3d6f FF |
1252 | |
1253 | if (!ieee80211_is_data(hdr->frame_control)) | |
80a83cfc | 1254 | return NULL; |
ba8c3d6f FF |
1255 | |
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) | |
80a83cfc | 1265 | return NULL; |
ba8c3d6f | 1266 | |
80a83cfc MK |
1267 | return to_txq_info(txq); |
1268 | } | |
ba8c3d6f | 1269 | |
fa962b92 MK |
1270 | static 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 | ||
1277 | static 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 | ||
1288 | static 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 | ||
80a83cfc MK |
1299 | static void ieee80211_txq_enqueue(struct ieee80211_local *local, |
1300 | struct txq_info *txqi, | |
1301 | struct sk_buff *skb) | |
1302 | { | |
fa962b92 MK |
1303 | struct fq *fq = &local->fq; |
1304 | struct fq_tin *tin = &txqi->tin; | |
f2ac7e30 | 1305 | |
fa962b92 MK |
1306 | fq_tin_enqueue(fq, tin, skb, |
1307 | fq_skb_free_func, | |
1308 | fq_flow_get_default_func); | |
1309 | } | |
ba8c3d6f | 1310 | |
fa962b92 MK |
1311 | void 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; | |
80a83cfc | 1329 | } |
fa962b92 | 1330 | } |
ba8c3d6f | 1331 | |
fa962b92 MK |
1332 | void 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 | ||
1341 | int 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 | ||
1356 | void 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); | |
ba8c3d6f FF |
1364 | } |
1365 | ||
1366 | struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw, | |
1367 | struct ieee80211_txq *txq) | |
1368 | { | |
1369 | struct ieee80211_local *local = hw_to_local(hw); | |
ba8c3d6f FF |
1370 | struct txq_info *txqi = container_of(txq, struct txq_info, txq); |
1371 | struct ieee80211_hdr *hdr; | |
1372 | struct sk_buff *skb = NULL; | |
fa962b92 MK |
1373 | struct fq *fq = &local->fq; |
1374 | struct fq_tin *tin = &txqi->tin; | |
ba8c3d6f | 1375 | |
fa962b92 | 1376 | spin_lock_bh(&fq->lock); |
ba8c3d6f FF |
1377 | |
1378 | if (test_bit(IEEE80211_TXQ_STOP, &txqi->flags)) | |
1379 | goto out; | |
1380 | ||
fa962b92 | 1381 | skb = fq_tin_dequeue(fq, tin, fq_tin_dequeue_func); |
ba8c3d6f FF |
1382 | if (!skb) |
1383 | goto out; | |
1384 | ||
ba8c3d6f FF |
1385 | 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 | ||
1398 | out: | |
fa962b92 | 1399 | spin_unlock_bh(&fq->lock); |
ba8c3d6f | 1400 | |
6e0456b5 FF |
1401 | if (skb && skb_has_frag_list(skb) && |
1402 | !ieee80211_hw_check(&local->hw, TX_FRAG_LIST)) | |
1403 | skb_linearize(skb); | |
1404 | ||
ba8c3d6f FF |
1405 | return skb; |
1406 | } | |
1407 | EXPORT_SYMBOL(ieee80211_tx_dequeue); | |
1408 | ||
11127e91 JB |
1409 | static 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) | |
e2ebc74d | 1414 | { |
80a83cfc | 1415 | struct ieee80211_tx_control control = {}; |
fa962b92 | 1416 | struct fq *fq = &local->fq; |
252b86c4 | 1417 | struct sk_buff *skb, *tmp; |
80a83cfc | 1418 | struct txq_info *txqi; |
3b8d81e0 | 1419 | unsigned long flags; |
e2ebc74d | 1420 | |
252b86c4 | 1421 | skb_queue_walk_safe(skbs, skb, tmp) { |
3a25a8c8 JB |
1422 | 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); | |
c3e7724b | 1428 | ieee80211_free_txskb(&local->hw, skb); |
3a25a8c8 JB |
1429 | continue; |
1430 | } | |
1431 | #endif | |
3b8d81e0 | 1432 | |
80a83cfc MK |
1433 | txqi = ieee80211_get_txq(local, vif, sta, skb); |
1434 | if (txqi) { | |
1435 | info->control.vif = vif; | |
1436 | ||
1437 | __skb_unlink(skb, skbs); | |
1438 | ||
fa962b92 | 1439 | spin_lock_bh(&fq->lock); |
80a83cfc | 1440 | ieee80211_txq_enqueue(local, txqi, skb); |
fa962b92 | 1441 | spin_unlock_bh(&fq->lock); |
80a83cfc MK |
1442 | |
1443 | drv_wake_tx_queue(local, txqi); | |
1444 | ||
1445 | continue; | |
1446 | } | |
1447 | ||
3b8d81e0 | 1448 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
3b8d81e0 | 1449 | if (local->queue_stop_reasons[q] || |
7bb45683 | 1450 | (!txpending && !skb_queue_empty(&local->pending[q]))) { |
6c17b77b | 1451 | if (unlikely(info->flags & |
a7679ed5 SF |
1452 | 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 | ||
6c17b77b | 1470 | /* |
a7679ed5 SF |
1471 | * Since queue is stopped, queue up frames for |
1472 | * later transmission from the tx-pending | |
1473 | * tasklet when the queue is woken again. | |
6c17b77b | 1474 | */ |
a7679ed5 SF |
1475 | 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; | |
6c17b77b | 1485 | } |
7bb45683 | 1486 | } |
3b8d81e0 | 1487 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
f8e79ddd | 1488 | |
11127e91 | 1489 | info->control.vif = vif; |
80a83cfc | 1490 | control.sta = sta; |
f0e72851 | 1491 | |
11127e91 | 1492 | __skb_unlink(skb, skbs); |
80a83cfc | 1493 | drv_tx(local, &control, skb); |
11127e91 | 1494 | } |
5061b0c2 | 1495 | |
11127e91 JB |
1496 | return true; |
1497 | } | |
1498 | ||
1499 | /* | |
1500 | * Returns false if the frame couldn't be transmitted but was queued instead. | |
1501 | */ | |
1502 | static 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; | |
5061b0c2 | 1513 | |
11127e91 JB |
1514 | if (WARN_ON(skb_queue_empty(skbs))) |
1515 | return true; | |
ec25acc4 | 1516 | |
11127e91 JB |
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: | |
c82b5a74 JB |
1531 | if (sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE) { |
1532 | vif = &sdata->vif; | |
1533 | break; | |
1534 | } | |
4b6f1dd6 | 1535 | sdata = rcu_dereference(local->monitor_sdata); |
3a25a8c8 | 1536 | if (sdata) { |
4b6f1dd6 | 1537 | vif = &sdata->vif; |
3a25a8c8 JB |
1538 | info->hw_queue = |
1539 | vif->hw_queue[skb_get_queue_mapping(skb)]; | |
30686bf7 | 1540 | } else if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) { |
63b4d8b3 | 1541 | ieee80211_purge_tx_queue(&local->hw, skbs); |
3a25a8c8 JB |
1542 | return true; |
1543 | } else | |
4b6f1dd6 | 1544 | vif = NULL; |
11127e91 JB |
1545 | 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; | |
e2ebc74d | 1553 | } |
2de8e0d9 | 1554 | |
cb831b53 JB |
1555 | result = ieee80211_tx_frags(local, vif, pubsta, skbs, |
1556 | txpending); | |
11127e91 | 1557 | |
74e4dbfd | 1558 | ieee80211_tpt_led_trig_tx(local, fc, led_len); |
74e4dbfd | 1559 | |
4db4e0a1 | 1560 | WARN_ON_ONCE(!skb_queue_empty(skbs)); |
252b86c4 | 1561 | |
11127e91 | 1562 | return result; |
e2ebc74d JB |
1563 | } |
1564 | ||
97b045d6 JB |
1565 | /* |
1566 | * Invoke TX handlers, return 0 on success and non-zero if the | |
1567 | * frame was dropped or queued. | |
1568 | */ | |
1569 | static int invoke_tx_handlers(struct ieee80211_tx_data *tx) | |
1570 | { | |
252b86c4 | 1571 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); |
97b045d6 | 1572 | ieee80211_tx_result res = TX_DROP; |
97b045d6 | 1573 | |
9aa4aee3 JB |
1574 | #define CALL_TXH(txh) \ |
1575 | do { \ | |
1576 | res = txh(tx); \ | |
1577 | if (res != TX_CONTINUE) \ | |
1578 | goto txh_done; \ | |
1579 | } while (0) | |
1580 | ||
5c1b98a5 | 1581 | CALL_TXH(ieee80211_tx_h_dynamic_ps); |
9aa4aee3 JB |
1582 | CALL_TXH(ieee80211_tx_h_check_assoc); |
1583 | CALL_TXH(ieee80211_tx_h_ps_buf); | |
a621fa4d | 1584 | CALL_TXH(ieee80211_tx_h_check_control_port_protocol); |
9aa4aee3 | 1585 | CALL_TXH(ieee80211_tx_h_select_key); |
30686bf7 | 1586 | if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL)) |
af65cd96 | 1587 | CALL_TXH(ieee80211_tx_h_rate_ctrl); |
c6fcf6bc | 1588 | |
aa5b5492 JB |
1589 | if (unlikely(info->flags & IEEE80211_TX_INTFL_RETRANSMISSION)) { |
1590 | __skb_queue_tail(&tx->skbs, tx->skb); | |
1591 | tx->skb = NULL; | |
c6fcf6bc | 1592 | goto txh_done; |
aa5b5492 | 1593 | } |
c6fcf6bc JB |
1594 | |
1595 | CALL_TXH(ieee80211_tx_h_michael_mic_add); | |
9aa4aee3 JB |
1596 | CALL_TXH(ieee80211_tx_h_sequence); |
1597 | CALL_TXH(ieee80211_tx_h_fragment); | |
d9e8a70f | 1598 | /* handlers after fragment must be aware of tx info fragmentation! */ |
9aa4aee3 JB |
1599 | CALL_TXH(ieee80211_tx_h_stats); |
1600 | CALL_TXH(ieee80211_tx_h_encrypt); | |
30686bf7 | 1601 | if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL)) |
8fd369ee | 1602 | CALL_TXH(ieee80211_tx_h_calculate_duration); |
d9e8a70f | 1603 | #undef CALL_TXH |
97b045d6 | 1604 | |
d9e8a70f | 1605 | txh_done: |
97b045d6 | 1606 | if (unlikely(res == TX_DROP)) { |
5479d0e7 | 1607 | I802_DEBUG_INC(tx->local->tx_handlers_drop); |
252b86c4 | 1608 | if (tx->skb) |
c3e7724b | 1609 | ieee80211_free_txskb(&tx->local->hw, tx->skb); |
252b86c4 | 1610 | else |
1f98ab7f | 1611 | ieee80211_purge_tx_queue(&tx->local->hw, &tx->skbs); |
97b045d6 JB |
1612 | return -1; |
1613 | } else if (unlikely(res == TX_QUEUED)) { | |
5479d0e7 | 1614 | I802_DEBUG_INC(tx->local->tx_handlers_queued); |
97b045d6 JB |
1615 | return -1; |
1616 | } | |
1617 | ||
1618 | return 0; | |
1619 | } | |
1620 | ||
06be6b14 FF |
1621 | bool 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; | |
88724a81 | 1628 | struct sk_buff *skb2; |
06be6b14 | 1629 | |
7c10770f | 1630 | if (ieee80211_tx_prepare(sdata, &tx, NULL, skb) == TX_DROP) |
06be6b14 FF |
1631 | 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 | ||
88724a81 JB |
1647 | /* 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 | ||
06be6b14 FF |
1655 | return true; |
1656 | } | |
1657 | EXPORT_SYMBOL(ieee80211_tx_prepare_skb); | |
1658 | ||
7bb45683 JB |
1659 | /* |
1660 | * Returns false if the frame couldn't be transmitted but was queued instead. | |
1661 | */ | |
1662 | static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata, | |
7c10770f JB |
1663 | struct sta_info *sta, struct sk_buff *skb, |
1664 | bool txpending) | |
e2ebc74d | 1665 | { |
3b8d81e0 | 1666 | struct ieee80211_local *local = sdata->local; |
5cf121c3 | 1667 | struct ieee80211_tx_data tx; |
97b045d6 | 1668 | ieee80211_tx_result res_prepare; |
e039fa4a | 1669 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
7bb45683 | 1670 | bool result = true; |
74e4dbfd | 1671 | int led_len; |
e2ebc74d | 1672 | |
e2ebc74d JB |
1673 | if (unlikely(skb->len < 10)) { |
1674 | dev_kfree_skb(skb); | |
7bb45683 | 1675 | return true; |
e2ebc74d JB |
1676 | } |
1677 | ||
58d4185e | 1678 | /* initialises tx */ |
74e4dbfd | 1679 | led_len = skb->len; |
7c10770f | 1680 | res_prepare = ieee80211_tx_prepare(sdata, &tx, sta, skb); |
e2ebc74d | 1681 | |
cd8ffc80 | 1682 | if (unlikely(res_prepare == TX_DROP)) { |
c3e7724b | 1683 | ieee80211_free_txskb(&local->hw, skb); |
55de908a | 1684 | return true; |
cd8ffc80 | 1685 | } else if (unlikely(res_prepare == TX_QUEUED)) { |
55de908a | 1686 | return true; |
e2ebc74d JB |
1687 | } |
1688 | ||
3a25a8c8 JB |
1689 | /* set up hw_queue value early */ |
1690 | if (!(info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) || | |
30686bf7 | 1691 | !ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) |
3a25a8c8 JB |
1692 | info->hw_queue = |
1693 | sdata->vif.hw_queue[skb_get_queue_mapping(skb)]; | |
1694 | ||
7bb45683 | 1695 | if (!invoke_tx_handlers(&tx)) |
74e4dbfd JB |
1696 | result = __ieee80211_tx(local, &tx.skbs, led_len, |
1697 | tx.sta, txpending); | |
55de908a | 1698 | |
7bb45683 | 1699 | return result; |
e2ebc74d JB |
1700 | } |
1701 | ||
1702 | /* device xmit handlers */ | |
1703 | ||
3bff1865 | 1704 | static int ieee80211_skb_resize(struct ieee80211_sub_if_data *sdata, |
23c0752a JB |
1705 | struct sk_buff *skb, |
1706 | int head_need, bool may_encrypt) | |
1707 | { | |
3bff1865 | 1708 | struct ieee80211_local *local = sdata->local; |
23c0752a JB |
1709 | int tail_need = 0; |
1710 | ||
3bff1865 | 1711 | if (may_encrypt && sdata->crypto_tx_tailroom_needed_cnt) { |
23c0752a JB |
1712 | tail_need = IEEE80211_ENCRYPT_TAILROOM; |
1713 | tail_need -= skb_tailroom(skb); | |
1714 | tail_need = max_t(int, tail_need, 0); | |
1715 | } | |
1716 | ||
c70f59a2 | 1717 | if (skb_cloned(skb) && |
30686bf7 | 1718 | (!ieee80211_hw_check(&local->hw, SUPPORTS_CLONED_SKBS) || |
c70f59a2 | 1719 | !skb_clone_writable(skb, ETH_HLEN) || |
17c18bf8 | 1720 | (may_encrypt && sdata->crypto_tx_tailroom_needed_cnt))) |
23c0752a | 1721 | I802_DEBUG_INC(local->tx_expand_skb_head_cloned); |
4cd06a34 | 1722 | else if (head_need || tail_need) |
23c0752a | 1723 | I802_DEBUG_INC(local->tx_expand_skb_head); |
4cd06a34 FF |
1724 | else |
1725 | return 0; | |
23c0752a JB |
1726 | |
1727 | if (pskb_expand_head(skb, head_need, tail_need, GFP_ATOMIC)) { | |
0fb9a9ec JP |
1728 | wiphy_debug(local->hw.wiphy, |
1729 | "failed to reallocate TX buffer\n"); | |
23c0752a JB |
1730 | return -ENOMEM; |
1731 | } | |
1732 | ||
23c0752a JB |
1733 | return 0; |
1734 | } | |
1735 | ||
7c10770f JB |
1736 | void ieee80211_xmit(struct ieee80211_sub_if_data *sdata, |
1737 | struct sta_info *sta, struct sk_buff *skb) | |
e2ebc74d | 1738 | { |
3b8d81e0 | 1739 | struct ieee80211_local *local = sdata->local; |
e039fa4a | 1740 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
e32f85f7 | 1741 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
e2ebc74d | 1742 | int headroom; |
23c0752a | 1743 | bool may_encrypt; |
e2ebc74d | 1744 | |
3b8d81e0 | 1745 | may_encrypt = !(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT); |
23c0752a | 1746 | |
3b8d81e0 | 1747 | headroom = local->tx_headroom; |
23c0752a | 1748 | if (may_encrypt) |
2475b1cc | 1749 | headroom += sdata->encrypt_headroom; |
23c0752a JB |
1750 | headroom -= skb_headroom(skb); |
1751 | headroom = max_t(int, 0, headroom); | |
1752 | ||
3bff1865 | 1753 | if (ieee80211_skb_resize(sdata, skb, headroom, may_encrypt)) { |
c3e7724b | 1754 | ieee80211_free_txskb(&local->hw, skb); |
3b8d81e0 | 1755 | return; |
e2ebc74d JB |
1756 | } |
1757 | ||
740c1aa3 | 1758 | hdr = (struct ieee80211_hdr *) skb->data; |
5061b0c2 | 1759 | info->control.vif = &sdata->vif; |
e2ebc74d | 1760 | |
3f52b7e3 MP |
1761 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
1762 | if (ieee80211_is_data(hdr->frame_control) && | |
1763 | is_unicast_ether_addr(hdr->addr1)) { | |
bf7cd94d | 1764 | if (mesh_nexthop_resolve(sdata, skb)) |
3f52b7e3 MP |
1765 | return; /* skb queued: don't free */ |
1766 | } else { | |
1767 | ieee80211_mps_set_frame_flags(sdata, NULL, hdr); | |
1768 | } | |
98aed9fd | 1769 | } |
cca89496 | 1770 | |
2154c81c | 1771 | ieee80211_set_qos_hdr(sdata, skb); |
7c10770f | 1772 | ieee80211_tx(sdata, sta, skb, false); |
e2ebc74d JB |
1773 | } |
1774 | ||
dfdfc2be SE |
1775 | static bool ieee80211_parse_tx_radiotap(struct ieee80211_local *local, |
1776 | struct sk_buff *skb) | |
73b9f03a JB |
1777 | { |
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); | |
dfdfc2be SE |
1782 | struct ieee80211_supported_band *sband = |
1783 | local->hw.wiphy->bands[info->band]; | |
73b9f03a JB |
1784 | int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len, |
1785 | NULL); | |
1786 | u16 txflags; | |
dfdfc2be SE |
1787 | u16 rate = 0; |
1788 | bool rate_found = false; | |
1789 | u8 rate_retries = 0; | |
1790 | u16 rate_flags = 0; | |
f66b60f6 | 1791 | u8 mcs_known, mcs_flags, mcs_bw; |
646e76bb LB |
1792 | u16 vht_known; |
1793 | u8 vht_mcs = 0, vht_nss = 0; | |
dfdfc2be | 1794 | int i; |
73b9f03a JB |
1795 | |
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 | ||
dfdfc2be SE |
1845 | 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 | ||
f66b60f6 | 1869 | mcs_bw = mcs_flags & IEEE80211_RADIOTAP_MCS_BW_MASK; |
dfdfc2be | 1870 | if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_BW && |
f66b60f6 | 1871 | mcs_bw == IEEE80211_RADIOTAP_MCS_BW_40) |
dfdfc2be SE |
1872 | rate_flags |= IEEE80211_TX_RC_40_MHZ_WIDTH; |
1873 | break; | |
1874 | ||
646e76bb LB |
1875 | 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 | ||
73b9f03a JB |
1901 | /* |
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 | ||
dfdfc2be SE |
1915 | 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; | |
646e76bb LB |
1926 | } else if (rate_flags & IEEE80211_TX_RC_VHT_MCS) { |
1927 | ieee80211_rate_set_vht(info->control.rates, vht_mcs, | |
1928 | vht_nss); | |
dfdfc2be SE |
1929 | } 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 | ||
07310a63 FF |
1939 | if (info->control.rates[0].idx < 0) |
1940 | info->control.flags &= ~IEEE80211_TX_CTRL_RATE_INJECT; | |
1941 | ||
dfdfc2be SE |
1942 | 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 | ||
73b9f03a JB |
1947 | /* |
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 | ||
d0cf9c0d SH |
1957 | netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb, |
1958 | struct net_device *dev) | |
e2ebc74d JB |
1959 | { |
1960 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
55de908a | 1961 | struct ieee80211_chanctx_conf *chanctx_conf; |
e2ebc74d JB |
1962 | struct ieee80211_radiotap_header *prthdr = |
1963 | (struct ieee80211_radiotap_header *)skb->data; | |
3b8d81e0 | 1964 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
f75f5c6f | 1965 | struct ieee80211_hdr *hdr; |
5d9cf4a5 | 1966 | struct ieee80211_sub_if_data *tmp_sdata, *sdata; |
b4932836 | 1967 | struct cfg80211_chan_def *chandef; |
9b8a74e3 | 1968 | u16 len_rthdr; |
5d9cf4a5 | 1969 | int hdrlen; |
e2ebc74d | 1970 | |
9b8a74e3 AG |
1971 | /* 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 */ | |
e2ebc74d | 1985 | |
e2ebc74d JB |
1986 | /* |
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 | */ | |
9b8a74e3 | 1992 | skb_set_mac_header(skb, len_rthdr); |
e2ebc74d | 1993 | /* |
9b8a74e3 AG |
1994 | * 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 | |
e2ebc74d | 1996 | */ |
9b8a74e3 AG |
1997 | skb_set_network_header(skb, len_rthdr); |
1998 | skb_set_transport_header(skb, len_rthdr); | |
e2ebc74d | 1999 | |
5d9cf4a5 JB |
2000 | 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 | ||
f75f5c6f HS |
2009 | /* |
2010 | * Initialize skb->protocol if the injected frame is a data frame | |
2011 | * carrying a rfc1042 header | |
2012 | */ | |
5d9cf4a5 JB |
2013 | if (ieee80211_is_data(hdr->frame_control) && |
2014 | skb->len >= len_rthdr + hdrlen + sizeof(rfc1042_header) + 2) { | |
2015 | u8 *payload = (u8 *)hdr + hdrlen; | |
2016 | ||
b203ca39 | 2017 | if (ether_addr_equal(payload, rfc1042_header)) |
5d9cf4a5 JB |
2018 | skb->protocol = cpu_to_be16((payload[6] << 8) | |
2019 | payload[7]); | |
f75f5c6f HS |
2020 | } |
2021 | ||
3b8d81e0 JB |
2022 | memset(info, 0, sizeof(*info)); |
2023 | ||
5d9cf4a5 | 2024 | info->flags = IEEE80211_TX_CTL_REQ_TX_STATUS | |
73b9f03a JB |
2025 | IEEE80211_TX_CTL_INJECTED; |
2026 | ||
5d9cf4a5 JB |
2027 | 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; | |
b203ca39 | 2046 | if (ether_addr_equal(tmp_sdata->vif.addr, hdr->addr2)) { |
5d9cf4a5 JB |
2047 | sdata = tmp_sdata; |
2048 | break; | |
2049 | } | |
2050 | } | |
7351c6bd | 2051 | |
55de908a JB |
2052 | 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 | } | |
55de908a | 2059 | |
b4a7ff75 | 2060 | if (chanctx_conf) |
b4932836 | 2061 | chandef = &chanctx_conf->def; |
b4a7ff75 | 2062 | else if (!local->use_chanctx) |
b4932836 | 2063 | chandef = &local->_oper_chandef; |
b4a7ff75 FF |
2064 | else |
2065 | goto fail_rcu; | |
55de908a JB |
2066 | |
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 | */ | |
b4932836 JD |
2083 | if (!cfg80211_reg_can_beacon(local->hw.wiphy, chandef, |
2084 | sdata->vif.type)) | |
55de908a JB |
2085 | goto fail_rcu; |
2086 | ||
73c4e195 | 2087 | info->band = chandef->chan->band; |
109843b0 LB |
2088 | |
2089 | /* process and remove the injection radiotap header */ | |
2090 | if (!ieee80211_parse_tx_radiotap(local, skb)) | |
2091 | goto fail_rcu; | |
2092 | ||
7c10770f | 2093 | ieee80211_xmit(sdata, NULL, skb); |
5d9cf4a5 JB |
2094 | rcu_read_unlock(); |
2095 | ||
e2ebc74d | 2096 | return NETDEV_TX_OK; |
9b8a74e3 | 2097 | |
55de908a JB |
2098 | fail_rcu: |
2099 | rcu_read_unlock(); | |
9b8a74e3 AG |
2100 | fail: |
2101 | dev_kfree_skb(skb); | |
2102 | return NETDEV_TX_OK; /* meaning, we dealt with the skb */ | |
e2ebc74d JB |
2103 | } |
2104 | ||
97ffe757 | 2105 | static inline bool ieee80211_is_tdls_setup(struct sk_buff *skb) |
ad38bfc9 | 2106 | { |
97ffe757 | 2107 | u16 ethertype = (skb->data[12] << 8) | skb->data[13]; |
ad38bfc9 | 2108 | |
97ffe757 JB |
2109 | return ethertype == ETH_P_TDLS && |
2110 | skb->len > 14 && | |
2111 | skb->data[14] == WLAN_TDLS_SNAP_RFTYPE; | |
2112 | } | |
2113 | ||
2114 | static 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; | |
ad38bfc9 MG |
2188 | } |
2189 | ||
e2ebc74d | 2190 | /** |
4c9451ed JB |
2191 | * 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 | |
24d342c5 | 2194 | * @info_flags: skb flags to set |
e2ebc74d | 2195 | * |
4c9451ed JB |
2196 | * 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. | |
2199 | * | |
2200 | * 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. | |
e2ebc74d | 2203 | * |
4c9451ed JB |
2204 | * The function requires the read-side RCU lock held |
2205 | * | |
2206 | * Returns: the (possibly reallocated) skb or an ERR_PTR() code | |
e2ebc74d | 2207 | */ |
4c9451ed | 2208 | static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, |
7c10770f | 2209 | struct sk_buff *skb, u32 info_flags, |
97ffe757 | 2210 | struct sta_info *sta) |
e2ebc74d | 2211 | { |
133b8226 | 2212 | struct ieee80211_local *local = sdata->local; |
489ee919 | 2213 | struct ieee80211_tx_info *info; |
dcf33963 | 2214 | int head_need; |
065e9605 HH |
2215 | u16 ethertype, hdrlen, meshhdrlen = 0; |
2216 | __le16 fc; | |
e2ebc74d | 2217 | struct ieee80211_hdr hdr; |
ff67bb86 | 2218 | struct ieee80211s_hdr mesh_hdr __maybe_unused; |
b8bacc18 | 2219 | struct mesh_path __maybe_unused *mppath = NULL, *mpath = NULL; |
e2ebc74d JB |
2220 | const u8 *encaps_data; |
2221 | int encaps_len, skip_header_bytes; | |
e8bf9649 | 2222 | int nh_pos, h_pos; |
97ffe757 JB |
2223 | bool wme_sta = false, authorized = false; |
2224 | bool tdls_peer; | |
a729cff8 | 2225 | bool multicast; |
a729cff8 | 2226 | u16 info_id = 0; |
55de908a JB |
2227 | struct ieee80211_chanctx_conf *chanctx_conf; |
2228 | struct ieee80211_sub_if_data *ap_sdata; | |
57fbcce3 | 2229 | enum nl80211_band band; |
4c9451ed | 2230 | int ret; |
e2ebc74d | 2231 | |
97ffe757 JB |
2232 | if (IS_ERR(sta)) |
2233 | sta = NULL; | |
2234 | ||
e2ebc74d JB |
2235 | /* convert Ethernet header to proper 802.11 header (based on |
2236 | * operation mode) */ | |
2237 | ethertype = (skb->data[12] << 8) | skb->data[13]; | |
065e9605 | 2238 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA); |
e2ebc74d | 2239 | |
51fb61e7 | 2240 | switch (sdata->vif.type) { |
05c914fe | 2241 | case NL80211_IFTYPE_AP_VLAN: |
97ffe757 | 2242 | if (sdata->wdev.use_4addr) { |
f14543ee FF |
2243 | fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); |
2244 | /* RA TA DA SA */ | |
2245 | memcpy(hdr.addr1, sta->sta.addr, ETH_ALEN); | |
47846c9b | 2246 | memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN); |
f14543ee FF |
2247 | memcpy(hdr.addr3, skb->data, ETH_ALEN); |
2248 | memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN); | |
2249 | hdrlen = 30; | |
c2c98fde | 2250 | authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED); |
a74a8c84 | 2251 | wme_sta = sta->sta.wme; |
f14543ee | 2252 | } |
55de908a JB |
2253 | ap_sdata = container_of(sdata->bss, struct ieee80211_sub_if_data, |
2254 | u.ap); | |
2255 | chanctx_conf = rcu_dereference(ap_sdata->vif.chanctx_conf); | |
4c9451ed JB |
2256 | if (!chanctx_conf) { |
2257 | ret = -ENOTCONN; | |
2258 | goto free; | |
2259 | } | |
4bf88530 | 2260 | band = chanctx_conf->def.chan->band; |
97ffe757 | 2261 | if (sdata->wdev.use_4addr) |
f14543ee FF |
2262 | break; |
2263 | /* fall through */ | |
2264 | case NL80211_IFTYPE_AP: | |
fe80123d AB |
2265 | if (sdata->vif.type == NL80211_IFTYPE_AP) |
2266 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); | |
4c9451ed JB |
2267 | if (!chanctx_conf) { |
2268 | ret = -ENOTCONN; | |
2269 | goto free; | |
2270 | } | |
065e9605 | 2271 | fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS); |
e2ebc74d JB |
2272 | /* DA BSSID SA */ |
2273 | memcpy(hdr.addr1, skb->data, ETH_ALEN); | |
47846c9b | 2274 | memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN); |
e2ebc74d JB |
2275 | memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN); |
2276 | hdrlen = 24; | |
4bf88530 | 2277 | band = chanctx_conf->def.chan->band; |
cf966838 | 2278 | break; |
05c914fe | 2279 | case NL80211_IFTYPE_WDS: |
065e9605 | 2280 | fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); |
e2ebc74d JB |
2281 | /* RA TA DA SA */ |
2282 | memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN); | |
47846c9b | 2283 | memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN); |
e2ebc74d JB |
2284 | memcpy(hdr.addr3, skb->data, ETH_ALEN); |
2285 | memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN); | |
2286 | hdrlen = 30; | |
55de908a JB |
2287 | /* |
2288 | * This is the exception! WDS style interfaces are prohibited | |
2289 | * when channel contexts are in used so this must be valid | |
2290 | */ | |
675a0b04 | 2291 | band = local->hw.conf.chandef.chan->band; |
cf966838 | 2292 | break; |
33b64eb2 | 2293 | #ifdef CONFIG_MAC80211_MESH |
05c914fe | 2294 | case NL80211_IFTYPE_MESH_POINT: |
b8bacc18 | 2295 | if (!is_multicast_ether_addr(skb->data)) { |
163df6cf CYY |
2296 | struct sta_info *next_hop; |
2297 | bool mpp_lookup = true; | |
2298 | ||
bf7cd94d | 2299 | mpath = mesh_path_lookup(sdata, skb->data); |
163df6cf CYY |
2300 | 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 | ||
ab1c7906 | 2309 | if (mpp_lookup) { |
bf7cd94d | 2310 | mppath = mpp_path_lookup(sdata, skb->data); |
ab1c7906 HR |
2311 | if (mppath) |
2312 | mppath->exp_time = jiffies; | |
2313 | } | |
163df6cf CYY |
2314 | |
2315 | if (mppath && mpath) | |
2bdaf386 | 2316 | mesh_path_del(sdata, mpath->dst); |
b8bacc18 | 2317 | } |
79617dee | 2318 | |
f76b57b4 | 2319 | /* |
9d52501b JF |
2320 | * 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) | |
f76b57b4 | 2324 | */ |
b203ca39 JP |
2325 | if (ether_addr_equal(sdata->vif.addr, skb->data + ETH_ALEN) && |
2326 | !(mppath && !ether_addr_equal(mppath->mpp, skb->data))) { | |
3c5772a5 JC |
2327 | hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc, |
2328 | skb->data, skb->data + ETH_ALEN); | |
bf7cd94d JB |
2329 | meshhdrlen = ieee80211_new_mesh_header(sdata, &mesh_hdr, |
2330 | NULL, NULL); | |
79617dee | 2331 | } else { |
27f01124 TP |
2332 | /* 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; | |
2339 | ||
2340 | if (mppath) | |
2341 | mesh_da = mppath->mpp; | |
2342 | else if (mpath) | |
2343 | mesh_da = mpath->dst; | |
79617dee | 2344 | |
3c5772a5 | 2345 | hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc, |
47846c9b | 2346 | mesh_da, sdata->vif.addr); |
27f01124 TP |
2347 | if (is_multicast_ether_addr(mesh_da)) |
2348 | /* DA TA mSA AE:SA */ | |
bf7cd94d JB |
2349 | meshhdrlen = ieee80211_new_mesh_header( |
2350 | sdata, &mesh_hdr, | |
2351 | skb->data + ETH_ALEN, NULL); | |
3c5772a5 | 2352 | else |
27f01124 | 2353 | /* RA TA mDA mSA AE:DA SA */ |
bf7cd94d JB |
2354 | meshhdrlen = ieee80211_new_mesh_header( |
2355 | sdata, &mesh_hdr, skb->data, | |
2356 | skb->data + ETH_ALEN); | |
79617dee | 2357 | |
79617dee | 2358 | } |
55de908a | 2359 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
4c9451ed JB |
2360 | if (!chanctx_conf) { |
2361 | ret = -ENOTCONN; | |
2362 | goto free; | |
2363 | } | |
4bf88530 | 2364 | band = chanctx_conf->def.chan->band; |
33b64eb2 LCC |
2365 | break; |
2366 | #endif | |
05c914fe | 2367 | case NL80211_IFTYPE_STATION: |
97ffe757 JB |
2368 | /* we already did checks when looking up the RA STA */ |
2369 | tdls_peer = test_sta_flag(sta, WLAN_STA_TDLS_PEER); | |
941c93cd | 2370 | |
97ffe757 | 2371 | if (tdls_peer) { |
941c93cd AN |
2372 | /* 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); | |
f14543ee | 2381 | /* RA TA DA SA */ |
941c93cd | 2382 | memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN); |
47846c9b | 2383 | memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN); |
f14543ee FF |
2384 | 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 */ | |
941c93cd | 2390 | memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN); |
f14543ee FF |
2391 | memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); |
2392 | memcpy(hdr.addr3, skb->data, ETH_ALEN); | |
2393 | hdrlen = 24; | |
2394 | } | |
55de908a | 2395 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
4c9451ed JB |
2396 | if (!chanctx_conf) { |
2397 | ret = -ENOTCONN; | |
2398 | goto free; | |
2399 | } | |
4bf88530 | 2400 | band = chanctx_conf->def.chan->band; |
cf966838 | 2401 | break; |
239281f8 RL |
2402 | 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); | |
4c9451ed JB |
2409 | if (!chanctx_conf) { |
2410 | ret = -ENOTCONN; | |
2411 | goto free; | |
2412 | } | |
239281f8 RL |
2413 | band = chanctx_conf->def.chan->band; |
2414 | break; | |
05c914fe | 2415 | case NL80211_IFTYPE_ADHOC: |
e2ebc74d JB |
2416 | /* DA SA BSSID */ |
2417 | memcpy(hdr.addr1, skb->data, ETH_ALEN); | |
2418 | memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); | |
46900298 | 2419 | memcpy(hdr.addr3, sdata->u.ibss.bssid, ETH_ALEN); |
e2ebc74d | 2420 | hdrlen = 24; |
55de908a | 2421 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
4c9451ed JB |
2422 | if (!chanctx_conf) { |
2423 | ret = -ENOTCONN; | |
2424 | goto free; | |
2425 | } | |
4bf88530 | 2426 | band = chanctx_conf->def.chan->band; |
cf966838 JB |
2427 | break; |
2428 | default: | |
4c9451ed JB |
2429 | ret = -EINVAL; |
2430 | goto free; | |
e2ebc74d JB |
2431 | } |
2432 | ||
a729cff8 | 2433 | multicast = is_multicast_ether_addr(hdr.addr1); |
e2ebc74d | 2434 | |
97ffe757 JB |
2435 | /* 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 */ | |
c2c98fde | 2441 | wme_sta = true; |
97ffe757 | 2442 | } |
4777be41 | 2443 | |
527871d7 JB |
2444 | /* receiver does QoS (which also means we do) use it */ |
2445 | if (wme_sta) { | |
065e9605 | 2446 | fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA); |
ce3edf6d JB |
2447 | hdrlen += 2; |
2448 | } | |
2449 | ||
2450 | /* | |
238814fd JB |
2451 | * Drop unicast frames to unauthorised stations unless they are |
2452 | * EAPOL frames from the local station. | |
ce3edf6d | 2453 | */ |
55182e4a | 2454 | if (unlikely(!ieee80211_vif_is_mesh(&sdata->vif) && |
239281f8 | 2455 | (sdata->vif.type != NL80211_IFTYPE_OCB) && |
a6ececf4 | 2456 | !multicast && !authorized && |
55182e4a | 2457 | (cpu_to_be16(ethertype) != sdata->control_port_protocol || |
b203ca39 | 2458 | !ether_addr_equal(sdata->vif.addr, skb->data + ETH_ALEN)))) { |
ce3edf6d | 2459 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
bdcbd8e0 | 2460 | net_info_ratelimited("%s: dropped frame to %pM (unauthorized port)\n", |
4c9451ed | 2461 | sdata->name, hdr.addr1); |
ce3edf6d JB |
2462 | #endif |
2463 | ||
2464 | I802_DEBUG_INC(local->tx_handlers_drop_unauth_port); | |
2465 | ||
4c9451ed JB |
2466 | ret = -EPERM; |
2467 | goto free; | |
ce3edf6d JB |
2468 | } |
2469 | ||
a729cff8 JB |
2470 | if (unlikely(!multicast && skb->sk && |
2471 | skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS)) { | |
bf7fa551 | 2472 | struct sk_buff *ack_skb = skb_clone_sk(skb); |
a729cff8 | 2473 | |
bf7fa551 | 2474 | if (ack_skb) { |
a729cff8 | 2475 | unsigned long flags; |
9475af6e | 2476 | int id; |
a729cff8 JB |
2477 | |
2478 | spin_lock_irqsave(&local->ack_status_lock, flags); | |
bf7fa551 | 2479 | id = idr_alloc(&local->ack_status_frames, ack_skb, |
9475af6e | 2480 | 1, 0x10000, GFP_ATOMIC); |
a729cff8 JB |
2481 | spin_unlock_irqrestore(&local->ack_status_lock, flags); |
2482 | ||
9475af6e | 2483 | if (id >= 0) { |
a729cff8 JB |
2484 | info_id = id; |
2485 | info_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; | |
a729cff8 | 2486 | } else { |
bf7fa551 | 2487 | kfree_skb(ack_skb); |
a729cff8 | 2488 | } |
a729cff8 JB |
2489 | } |
2490 | } | |
2491 | ||
7e244707 HS |
2492 | /* |
2493 | * If the skb is shared we need to obtain our own copy. | |
2494 | */ | |
2495 | if (skb_shared(skb)) { | |
a729cff8 JB |
2496 | 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 | ||
f8a0a781 | 2501 | skb = skb_clone(skb, GFP_ATOMIC); |
7e244707 HS |
2502 | kfree_skb(tmp_skb); |
2503 | ||
4c9451ed JB |
2504 | if (!skb) { |
2505 | ret = -ENOMEM; | |
2506 | goto free; | |
2507 | } | |
7e244707 HS |
2508 | } |
2509 | ||
065e9605 | 2510 | hdr.frame_control = fc; |
e2ebc74d JB |
2511 | 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; | |
e5c5d22e | 2519 | } else if (ethertype >= ETH_P_802_3_MIN) { |
e2ebc74d JB |
2520 | 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 | ||
7e244707 HS |
2528 | nh_pos = skb_network_header(skb) - skb->data; |
2529 | h_pos = skb_transport_header(skb) - skb->data; | |
2530 | ||
e2ebc74d JB |
2531 | skb_pull(skb, skip_header_bytes); |
2532 | nh_pos -= skip_header_bytes; | |
2533 | h_pos -= skip_header_bytes; | |
2534 | ||
23c0752a | 2535 | head_need = hdrlen + encaps_len + meshhdrlen - skb_headroom(skb); |
e2ebc74d | 2536 | |
23c0752a JB |
2537 | /* |
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 | */ | |
e2ebc74d | 2548 | |
3a5be7d4 | 2549 | if (head_need > 0 || skb_cloned(skb)) { |
2475b1cc | 2550 | head_need += sdata->encrypt_headroom; |
23c0752a JB |
2551 | head_need += local->tx_headroom; |
2552 | head_need = max_t(int, 0, head_need); | |
c3e7724b FF |
2553 | if (ieee80211_skb_resize(sdata, skb, head_need, true)) { |
2554 | ieee80211_free_txskb(&local->hw, skb); | |
1c963bec | 2555 | skb = NULL; |
4c9451ed | 2556 | return ERR_PTR(-ENOMEM); |
c3e7724b | 2557 | } |
e2ebc74d JB |
2558 | } |
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 | } | |
c29b9b9b | 2565 | |
e4ab7eb0 | 2566 | #ifdef CONFIG_MAC80211_MESH |
33b64eb2 LCC |
2567 | if (meshhdrlen > 0) { |
2568 | memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen); | |
2569 | nh_pos += meshhdrlen; | |
2570 | h_pos += meshhdrlen; | |
2571 | } | |
e4ab7eb0 | 2572 | #endif |
33b64eb2 | 2573 | |
065e9605 | 2574 | if (ieee80211_is_data_qos(fc)) { |
c29b9b9b JB |
2575 | __le16 *qos_control; |
2576 | ||
f359d3fe | 2577 | qos_control = (__le16 *) skb_push(skb, 2); |
c29b9b9b JB |
2578 | 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 | ||
e2ebc74d JB |
2587 | nh_pos += hdrlen; |
2588 | h_pos += hdrlen; | |
2589 | ||
e2ebc74d JB |
2590 | /* 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. */ | |
d57a544d | 2593 | skb_reset_mac_header(skb); |
e2ebc74d JB |
2594 | skb_set_network_header(skb, nh_pos); |
2595 | skb_set_transport_header(skb, h_pos); | |
2596 | ||
489ee919 | 2597 | info = IEEE80211_SKB_CB(skb); |
3b8d81e0 JB |
2598 | memset(info, 0, sizeof(*info)); |
2599 | ||
a729cff8 JB |
2600 | info->flags = info_flags; |
2601 | info->ack_frame_id = info_id; | |
73c4e195 | 2602 | info->band = band; |
a729cff8 | 2603 | |
4c9451ed JB |
2604 | return skb; |
2605 | free: | |
2606 | kfree_skb(skb); | |
2607 | return ERR_PTR(ret); | |
2608 | } | |
2609 | ||
17c18bf8 JB |
2610 | /* |
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 | ||
2631 | void 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 | ||
30686bf7 | 2640 | if (!ieee80211_hw_check(&local->hw, SUPPORT_FAST_XMIT)) |
17c18bf8 JB |
2641 | 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); | |
30686bf7 JB |
2656 | if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) && |
2657 | !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) && | |
17c18bf8 JB |
2658 | 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) || | |
f7418bc1 FF |
2666 | test_sta_flag(sta, WLAN_STA_PS_DELIVER) || |
2667 | test_sta_flag(sta, WLAN_STA_CLEAR_PS_FILT)) | |
17c18bf8 JB |
2668 | goto out; |
2669 | ||
2670 | if (sdata->noack_map) | |
2671 | goto out; | |
2672 | ||
2673 | /* fast-xmit doesn't handle fragmentation at all */ | |
725b812c JB |
2674 | if (local->hw.wiphy->frag_threshold != (u32)-1 && |
2675 | !local->ops->set_frag_threshold) | |
17c18bf8 JB |
2676 | 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) { | |
3ffd8840 JB |
2690 | 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; | |
17c18bf8 JB |
2697 | 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) { | |
e495c247 | 2766 | bool gen_iv, iv_spc, mmic; |
17c18bf8 JB |
2767 | |
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; | |
e495c247 | 2770 | mmic = build.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC; |
17c18bf8 JB |
2771 | |
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; | |
e495c247 JB |
2799 | 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); | |
17c18bf8 | 2821 | goto out; |
e495c247 JB |
2822 | 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; | |
17c18bf8 JB |
2835 | } |
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 | ||
2861 | void 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 | ||
2871 | void 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 | ||
2888 | void 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 | ||
6e0456b5 FF |
2902 | static 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 | ||
2927 | static 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 | ||
2967 | static 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; | |
fa962b92 MK |
2973 | struct fq *fq = &local->fq; |
2974 | struct fq_tin *tin; | |
2975 | struct fq_flow *flow; | |
6e0456b5 FF |
2976 | 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; | |
fa962b92 | 2987 | unsigned int orig_len; |
6e0456b5 FF |
2988 | 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 | ||
fa962b92 | 3004 | spin_lock_bh(&fq->lock); |
6e0456b5 | 3005 | |
fa962b92 MK |
3006 | /* 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); | |
6e0456b5 FF |
3013 | if (!head) |
3014 | goto out; | |
3015 | ||
fa962b92 MK |
3016 | orig_len = head->len; |
3017 | ||
6e0456b5 FF |
3018 | 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 | ||
fa962b92 MK |
3056 | flow->backlog += head->len - orig_len; |
3057 | tin->backlog_bytes += head->len - orig_len; | |
3058 | ||
3059 | fq_recalc_backlog(fq, tin, flow); | |
3060 | ||
6e0456b5 | 3061 | out: |
fa962b92 | 3062 | spin_unlock_bh(&fq->lock); |
6e0456b5 FF |
3063 | |
3064 | return ret; | |
3065 | } | |
3066 | ||
17c18bf8 JB |
3067 | static 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]); | |
472be00d JB |
3099 | 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 | } | |
17c18bf8 JB |
3105 | } |
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 | ||
5a490510 | 3119 | ieee80211_tx_stats(dev, skb->len + extra_head); |
17c18bf8 | 3120 | |
6e0456b5 FF |
3121 | if ((hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) && |
3122 | ieee80211_amsdu_aggregate(sdata, sta, fast_tx, skb)) | |
3123 | return true; | |
3124 | ||
17c18bf8 JB |
3125 | /* 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(ð, 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; | |
50f36ae6 FF |
3152 | if (!sta->sta.txq[0]) |
3153 | hdr->seq_ctrl = ieee80211_tx_next_seq(sta, tid); | |
17c18bf8 JB |
3154 | } 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 | ||
ccc6bb96 | 3160 | if (skb_shinfo(skb)->gso_size) |
e5a9f8d0 | 3161 | sta->tx_stats.msdu[tid] += |
ccc6bb96 JB |
3162 | DIV_ROUND_UP(skb->len, skb_shinfo(skb)->gso_size); |
3163 | else | |
e5a9f8d0 | 3164 | sta->tx_stats.msdu[tid]++; |
17c18bf8 JB |
3165 | |
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 | ||
30686bf7 | 3179 | if (!ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) { |
17c18bf8 JB |
3180 | 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 | */ | |
e5a9f8d0 JB |
3195 | sta->tx_stats.bytes[skb_get_queue_mapping(skb)] += skb->len; |
3196 | sta->tx_stats.packets[skb_get_queue_mapping(skb)]++; | |
17c18bf8 JB |
3197 | |
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: | |
17c18bf8 JB |
3205 | case WLAN_CIPHER_SUITE_GCMP: |
3206 | case WLAN_CIPHER_SUITE_GCMP_256: | |
db388a56 | 3207 | pn = atomic64_inc_return(&fast_tx->key->conf.tx_pn); |
17c18bf8 JB |
3208 | 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 | ||
4c9451ed JB |
3227 | void __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); | |
97ffe757 | 3232 | struct sta_info *sta; |
80616c0d | 3233 | struct sk_buff *next; |
4c9451ed JB |
3234 | |
3235 | if (unlikely(skb->len < ETH_HLEN)) { | |
3236 | kfree_skb(skb); | |
3237 | return; | |
3238 | } | |
3239 | ||
3240 | rcu_read_lock(); | |
e2ebc74d | 3241 | |
2d981fdd JB |
3242 | if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) |
3243 | goto out_free; | |
4c9451ed | 3244 | |
17c18bf8 JB |
3245 | 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 | ||
80616c0d JB |
3255 | if (skb_is_gso(skb)) { |
3256 | struct sk_buff *segs; | |
680a0dab | 3257 | |
80616c0d JB |
3258 | segs = skb_gso_segment(skb, 0); |
3259 | if (IS_ERR(segs)) { | |
2d981fdd | 3260 | goto out_free; |
80616c0d JB |
3261 | } 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) { | |
f603f1f3 JB |
3277 | skb_set_transport_header(skb, |
3278 | skb_checksum_start_offset(skb)); | |
80616c0d JB |
3279 | if (skb_checksum_help(skb)) |
3280 | goto out_free; | |
3281 | } | |
2d981fdd JB |
3282 | } |
3283 | ||
80616c0d JB |
3284 | next = skb; |
3285 | while (next) { | |
3286 | skb = next; | |
3287 | next = skb->next; | |
4c9451ed | 3288 | |
80616c0d JB |
3289 | skb->prev = NULL; |
3290 | skb->next = NULL; | |
3291 | ||
3292 | skb = ieee80211_build_hdr(sdata, skb, info_flags, sta); | |
3293 | if (IS_ERR(skb)) | |
3294 | goto out; | |
e2ebc74d | 3295 | |
5a490510 | 3296 | ieee80211_tx_stats(dev, skb->len); |
80616c0d JB |
3297 | |
3298 | ieee80211_xmit(sdata, sta, skb); | |
3299 | } | |
2d981fdd JB |
3300 | goto out; |
3301 | out_free: | |
3302 | kfree_skb(skb); | |
4c9451ed | 3303 | out: |
55de908a | 3304 | rcu_read_unlock(); |
e2ebc74d JB |
3305 | } |
3306 | ||
4c9451ed JB |
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 | */ | |
24d342c5 LK |
3314 | netdev_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 | } | |
e2ebc74d | 3320 | |
7528ec57 JB |
3321 | struct sk_buff * |
3322 | ieee80211_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 | }; | |
97ffe757 | 3330 | struct sta_info *sta; |
7528ec57 JB |
3331 | |
3332 | rcu_read_lock(); | |
3333 | ||
97ffe757 JB |
3334 | 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); | |
7528ec57 JB |
3341 | 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 | ||
3354 | out: | |
3355 | rcu_read_unlock(); | |
3356 | return skb; | |
3357 | } | |
3358 | ||
e2530083 JB |
3359 | /* |
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 | */ | |
e2ebc74d JB |
3363 | void ieee80211_clear_tx_pending(struct ieee80211_local *local) |
3364 | { | |
1f98ab7f | 3365 | struct sk_buff *skb; |
2de8e0d9 | 3366 | int i; |
e2ebc74d | 3367 | |
1f98ab7f FF |
3368 | 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 | } | |
e2ebc74d JB |
3372 | } |
3373 | ||
7bb45683 JB |
3374 | /* |
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 | */ | |
cd8ffc80 JB |
3379 | static 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; | |
7bb45683 | 3386 | bool result; |
55de908a | 3387 | struct ieee80211_chanctx_conf *chanctx_conf; |
cd8ffc80 | 3388 | |
5061b0c2 | 3389 | sdata = vif_to_sdata(info->control.vif); |
cd8ffc80 JB |
3390 | |
3391 | if (info->flags & IEEE80211_TX_INTFL_NEED_TXPROCESSING) { | |
55de908a JB |
3392 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
3393 | if (unlikely(!chanctx_conf)) { | |
3394 | dev_kfree_skb(skb); | |
3395 | return true; | |
3396 | } | |
73c4e195 | 3397 | info->band = chanctx_conf->def.chan->band; |
7c10770f | 3398 | result = ieee80211_tx(sdata, NULL, skb, true); |
cd8ffc80 | 3399 | } else { |
252b86c4 JB |
3400 | struct sk_buff_head skbs; |
3401 | ||
3402 | __skb_queue_head_init(&skbs); | |
3403 | __skb_queue_tail(&skbs, skb); | |
3404 | ||
cd8ffc80 | 3405 | hdr = (struct ieee80211_hdr *)skb->data; |
abe60632 | 3406 | sta = sta_info_get(sdata, hdr->addr1); |
cd8ffc80 | 3407 | |
74e4dbfd | 3408 | result = __ieee80211_tx(local, &skbs, skb->len, sta, true); |
cd8ffc80 JB |
3409 | } |
3410 | ||
cd8ffc80 JB |
3411 | return result; |
3412 | } | |
3413 | ||
e2530083 | 3414 | /* |
3b8d81e0 | 3415 | * Transmit all pending packets. Called from tasklet. |
e2530083 | 3416 | */ |
e2ebc74d JB |
3417 | void ieee80211_tx_pending(unsigned long data) |
3418 | { | |
3419 | struct ieee80211_local *local = (struct ieee80211_local *)data; | |
2a577d98 | 3420 | unsigned long flags; |
cd8ffc80 | 3421 | int i; |
3b8d81e0 | 3422 | bool txok; |
e2ebc74d | 3423 | |
f0e72851 | 3424 | rcu_read_lock(); |
e2530083 | 3425 | |
3b8d81e0 | 3426 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
2a577d98 JB |
3427 | for (i = 0; i < local->hw.queues; i++) { |
3428 | /* | |
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 | */ | |
3b8d81e0 | 3432 | if (local->queue_stop_reasons[i] || |
2a577d98 | 3433 | skb_queue_empty(&local->pending[i])) |
e2ebc74d | 3434 | continue; |
e2530083 | 3435 | |
2a577d98 | 3436 | while (!skb_queue_empty(&local->pending[i])) { |
3b8d81e0 | 3437 | struct sk_buff *skb = __skb_dequeue(&local->pending[i]); |
5061b0c2 | 3438 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
5061b0c2 | 3439 | |
a7bc376c | 3440 | if (WARN_ON(!info->control.vif)) { |
c3e7724b | 3441 | ieee80211_free_txskb(&local->hw, skb); |
a7bc376c JB |
3442 | continue; |
3443 | } | |
3444 | ||
3b8d81e0 JB |
3445 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, |
3446 | flags); | |
3447 | ||
3448 | txok = ieee80211_tx_pending_skb(local, skb); | |
3b8d81e0 JB |
3449 | spin_lock_irqsave(&local->queue_stop_reason_lock, |
3450 | flags); | |
3451 | if (!txok) | |
2a577d98 | 3452 | break; |
e2ebc74d | 3453 | } |
7236fe29 JB |
3454 | |
3455 | if (skb_queue_empty(&local->pending[i])) | |
3a25a8c8 | 3456 | ieee80211_propagate_queue_wake(local, i); |
e2ebc74d | 3457 | } |
3b8d81e0 | 3458 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
2a577d98 | 3459 | |
f0e72851 | 3460 | rcu_read_unlock(); |
e2ebc74d JB |
3461 | } |
3462 | ||
3463 | /* functions for drivers to get certain frames */ | |
3464 | ||
eac70c13 | 3465 | static void __ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata, |
6ec8c332 AO |
3466 | struct ps_data *ps, struct sk_buff *skb, |
3467 | bool is_template) | |
e2ebc74d JB |
3468 | { |
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. */ | |
d012a605 | 3475 | if (atomic_read(&ps->num_sta_ps) > 0) |
e2ebc74d JB |
3476 | /* in the hope that this is faster than |
3477 | * checking byte-for-byte */ | |
f359d3fe | 3478 | have_bits = !bitmap_empty((unsigned long *)ps->tim, |
e2ebc74d | 3479 | IEEE80211_MAX_AID+1); |
6ec8c332 AO |
3480 | 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 | } | |
e2ebc74d JB |
3486 | |
3487 | tim = pos = (u8 *) skb_put(skb, 6); | |
3488 | *pos++ = WLAN_EID_TIM; | |
3489 | *pos++ = 4; | |
d012a605 | 3490 | *pos++ = ps->dtim_count; |
8860020e | 3491 | *pos++ = sdata->vif.bss_conf.dtim_period; |
e2ebc74d | 3492 | |
d012a605 | 3493 | if (ps->dtim_count == 0 && !skb_queue_empty(&ps->bc_buf)) |
e2ebc74d JB |
3494 | aid0 = 1; |
3495 | ||
d012a605 | 3496 | ps->dtim_bc_mc = aid0 == 1; |
512119b3 | 3497 | |
e2ebc74d JB |
3498 | 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++) { | |
d012a605 | 3504 | if (ps->tim[i]) { |
e2ebc74d JB |
3505 | n1 = i & 0xfe; |
3506 | break; | |
3507 | } | |
3508 | } | |
3509 | n2 = n1; | |
3510 | for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) { | |
d012a605 | 3511 | if (ps->tim[i]) { |
e2ebc74d JB |
3512 | n2 = i; |
3513 | break; | |
3514 | } | |
3515 | } | |
3516 | ||
3517 | /* Bitmap control */ | |
3518 | *pos++ = n1 | aid0; | |
3519 | /* Part Virt Bitmap */ | |
5220da39 | 3520 | skb_put(skb, n2 - n1); |
d012a605 | 3521 | memcpy(pos, ps->tim + n1, n2 - n1 + 1); |
e2ebc74d JB |
3522 | |
3523 | tim[1] = n2 - n1 + 4; | |
e2ebc74d JB |
3524 | } else { |
3525 | *pos++ = aid0; /* Bitmap control */ | |
3526 | *pos++ = 0; /* Part Virt Bitmap */ | |
3527 | } | |
e2ebc74d JB |
3528 | } |
3529 | ||
eac70c13 | 3530 | static int ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata, |
6ec8c332 AO |
3531 | struct ps_data *ps, struct sk_buff *skb, |
3532 | bool is_template) | |
eac70c13 MP |
3533 | { |
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) { | |
6ec8c332 | 3544 | __ieee80211_beacon_add_tim(sdata, ps, skb, is_template); |
eac70c13 | 3545 | } else { |
1b91731d | 3546 | spin_lock_bh(&local->tim_lock); |
6ec8c332 | 3547 | __ieee80211_beacon_add_tim(sdata, ps, skb, is_template); |
1b91731d | 3548 | spin_unlock_bh(&local->tim_lock); |
eac70c13 MP |
3549 | } |
3550 | ||
3551 | return 0; | |
3552 | } | |
3553 | ||
1af586c9 AO |
3554 | static void ieee80211_set_csa(struct ieee80211_sub_if_data *sdata, |
3555 | struct beacon_data *beacon) | |
73da7d5b SW |
3556 | { |
3557 | struct probe_resp *resp; | |
cd7760e6 SW |
3558 | u8 *beacon_data; |
3559 | size_t beacon_data_len; | |
0d06d9ba | 3560 | int i; |
af296bdb | 3561 | u8 count = beacon->csa_current_counter; |
cd7760e6 SW |
3562 | |
3563 | 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; | |
b8456a14 CYY |
3572 | case NL80211_IFTYPE_MESH_POINT: |
3573 | beacon_data = beacon->head; | |
3574 | beacon_data_len = beacon->head_len; | |
3575 | break; | |
cd7760e6 SW |
3576 | default: |
3577 | return; | |
3578 | } | |
73da7d5b | 3579 | |
af296bdb | 3580 | rcu_read_lock(); |
0d06d9ba | 3581 | for (i = 0; i < IEEE80211_MAX_CSA_COUNTERS_NUM; ++i) { |
af296bdb | 3582 | resp = rcu_dereference(sdata->u.ap.probe_resp); |
0d06d9ba | 3583 | |
af296bdb MK |
3584 | if (beacon->csa_counter_offsets[i]) { |
3585 | if (WARN_ON_ONCE(beacon->csa_counter_offsets[i] >= | |
3586 | beacon_data_len)) { | |
0d06d9ba AO |
3587 | rcu_read_unlock(); |
3588 | return; | |
3589 | } | |
af296bdb MK |
3590 | |
3591 | beacon_data[beacon->csa_counter_offsets[i]] = count; | |
73da7d5b | 3592 | } |
af296bdb MK |
3593 | |
3594 | if (sdata->vif.type == NL80211_IFTYPE_AP && resp) | |
3595 | resp->data[resp->csa_counter_offsets[i]] = count; | |
73da7d5b | 3596 | } |
af296bdb | 3597 | rcu_read_unlock(); |
1af586c9 AO |
3598 | } |
3599 | ||
e996ec2a WD |
3600 | static 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 | ||
1af586c9 AO |
3610 | u8 ieee80211_csa_update_counter(struct ieee80211_vif *vif) |
3611 | { | |
3612 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
af296bdb MK |
3613 | struct beacon_data *beacon = NULL; |
3614 | u8 count = 0; | |
0d06d9ba | 3615 | |
af296bdb MK |
3616 | 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 | ||
e996ec2a | 3628 | count = __ieee80211_csa_update_counter(beacon); |
1af586c9 | 3629 | |
af296bdb MK |
3630 | unlock: |
3631 | rcu_read_unlock(); | |
3632 | return count; | |
73da7d5b | 3633 | } |
1af586c9 | 3634 | EXPORT_SYMBOL(ieee80211_csa_update_counter); |
73da7d5b SW |
3635 | |
3636 | bool 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; | |
73da7d5b SW |
3642 | 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; | |
cd7760e6 SW |
3656 | } 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 | ||
b8456a14 CYY |
3663 | beacon_data = beacon->head; |
3664 | beacon_data_len = beacon->head_len; | |
3665 | } 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 | ||
cd7760e6 SW |
3672 | beacon_data = beacon->head; |
3673 | beacon_data_len = beacon->head_len; | |
73da7d5b SW |
3674 | } else { |
3675 | WARN_ON(1); | |
3676 | goto out; | |
3677 | } | |
3678 | ||
10d78f27 MK |
3679 | if (!beacon->csa_counter_offsets[0]) |
3680 | goto out; | |
3681 | ||
af296bdb | 3682 | if (WARN_ON_ONCE(beacon->csa_counter_offsets[0] > beacon_data_len)) |
73da7d5b SW |
3683 | goto out; |
3684 | ||
af296bdb | 3685 | if (beacon_data[beacon->csa_counter_offsets[0]] == 1) |
73da7d5b SW |
3686 | ret = true; |
3687 | out: | |
3688 | rcu_read_unlock(); | |
3689 | ||
3690 | return ret; | |
3691 | } | |
3692 | EXPORT_SYMBOL(ieee80211_csa_is_complete); | |
3693 | ||
6ec8c332 AO |
3694 | static 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) | |
e2ebc74d JB |
3699 | { |
3700 | struct ieee80211_local *local = hw_to_local(hw); | |
af296bdb | 3701 | struct beacon_data *beacon = NULL; |
9d139c81 | 3702 | struct sk_buff *skb = NULL; |
e039fa4a | 3703 | struct ieee80211_tx_info *info; |
e2ebc74d | 3704 | struct ieee80211_sub_if_data *sdata = NULL; |
57fbcce3 | 3705 | enum nl80211_band band; |
e00cfce0 | 3706 | struct ieee80211_tx_rate_control txrc; |
55de908a | 3707 | struct ieee80211_chanctx_conf *chanctx_conf; |
1af586c9 | 3708 | int csa_off_base = 0; |
8318d78a | 3709 | |
5dfdaf58 | 3710 | rcu_read_lock(); |
e2ebc74d | 3711 | |
32bfd35d | 3712 | sdata = vif_to_sdata(vif); |
55de908a | 3713 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
e2ebc74d | 3714 | |
55de908a | 3715 | if (!ieee80211_sdata_running(sdata) || !chanctx_conf) |
eb3e554b FF |
3716 | goto out; |
3717 | ||
6ec8c332 AO |
3718 | if (offs) |
3719 | memset(offs, 0, sizeof(*offs)); | |
eddcbb94 | 3720 | |
05c914fe | 3721 | if (sdata->vif.type == NL80211_IFTYPE_AP) { |
d012a605 | 3722 | struct ieee80211_if_ap *ap = &sdata->u.ap; |
d012a605 | 3723 | |
af296bdb | 3724 | beacon = rcu_dereference(ap->beacon); |
3ad97fbc | 3725 | if (beacon) { |
10d78f27 | 3726 | if (beacon->csa_counter_offsets[0]) { |
1af586c9 | 3727 | if (!is_template) |
e996ec2a | 3728 | __ieee80211_csa_update_counter(beacon); |
1af586c9 AO |
3729 | |
3730 | ieee80211_set_csa(sdata, beacon); | |
3731 | } | |
73da7d5b | 3732 | |
902acc78 JB |
3733 | /* |
3734 | * headroom, head length, | |
3735 | * tail length and maximum TIM length | |
3736 | */ | |
3737 | skb = dev_alloc_skb(local->tx_headroom + | |
3738 | beacon->head_len + | |
70dabeb7 FF |
3739 | beacon->tail_len + 256 + |
3740 | local->hw.extra_beacon_tailroom); | |
902acc78 JB |
3741 | if (!skb) |
3742 | goto out; | |
33b64eb2 | 3743 | |
902acc78 JB |
3744 | skb_reserve(skb, local->tx_headroom); |
3745 | memcpy(skb_put(skb, beacon->head_len), beacon->head, | |
3746 | beacon->head_len); | |
33b64eb2 | 3747 | |
6ec8c332 AO |
3748 | ieee80211_beacon_add_tim(sdata, &ap->ps, skb, |
3749 | is_template); | |
33b64eb2 | 3750 | |
6ec8c332 AO |
3751 | if (offs) { |
3752 | offs->tim_offset = beacon->head_len; | |
3753 | offs->tim_length = skb->len - beacon->head_len; | |
1af586c9 AO |
3754 | |
3755 | /* for AP the csa offsets are from tail */ | |
3756 | csa_off_base = skb->len; | |
6ec8c332 | 3757 | } |
eddcbb94 | 3758 | |
902acc78 JB |
3759 | if (beacon->tail) |
3760 | memcpy(skb_put(skb, beacon->tail_len), | |
3761 | beacon->tail, beacon->tail_len); | |
9d139c81 JB |
3762 | } else |
3763 | goto out; | |
05c914fe | 3764 | } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { |
46900298 | 3765 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
9d139c81 | 3766 | struct ieee80211_hdr *hdr; |
33b64eb2 | 3767 | |
af296bdb MK |
3768 | beacon = rcu_dereference(ifibss->presp); |
3769 | if (!beacon) | |
9d139c81 JB |
3770 | goto out; |
3771 | ||
10d78f27 | 3772 | if (beacon->csa_counter_offsets[0]) { |
1af586c9 | 3773 | if (!is_template) |
e996ec2a | 3774 | __ieee80211_csa_update_counter(beacon); |
cd7760e6 | 3775 | |
af296bdb | 3776 | ieee80211_set_csa(sdata, beacon); |
1af586c9 | 3777 | } |
cd7760e6 | 3778 | |
af296bdb | 3779 | skb = dev_alloc_skb(local->tx_headroom + beacon->head_len + |
70dabeb7 | 3780 | local->hw.extra_beacon_tailroom); |
9d139c81 JB |
3781 | if (!skb) |
3782 | goto out; | |
c3ffeab4 | 3783 | skb_reserve(skb, local->tx_headroom); |
af296bdb MK |
3784 | memcpy(skb_put(skb, beacon->head_len), beacon->head, |
3785 | beacon->head_len); | |
9d139c81 JB |
3786 | |
3787 | hdr = (struct ieee80211_hdr *) skb->data; | |
e7827a70 HH |
3788 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
3789 | IEEE80211_STYPE_BEACON); | |
902acc78 | 3790 | } else if (ieee80211_vif_is_mesh(&sdata->vif)) { |
dbf498fb | 3791 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
472dbc45 | 3792 | |
af296bdb MK |
3793 | beacon = rcu_dereference(ifmsh->beacon); |
3794 | if (!beacon) | |
ac1bd846 | 3795 | goto out; |
ac1bd846 | 3796 | |
10d78f27 | 3797 | if (beacon->csa_counter_offsets[0]) { |
1af586c9 AO |
3798 | 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 | */ | |
e996ec2a | 3804 | __ieee80211_csa_update_counter(beacon); |
1af586c9 | 3805 | |
af296bdb | 3806 | ieee80211_set_csa(sdata, beacon); |
1af586c9 | 3807 | } |
b8456a14 | 3808 | |
dbf498fb | 3809 | if (ifmsh->sync_ops) |
af296bdb | 3810 | ifmsh->sync_ops->adjust_tbtt(sdata, beacon); |
dbf498fb | 3811 | |
3b69a9c5 | 3812 | skb = dev_alloc_skb(local->tx_headroom + |
af296bdb | 3813 | beacon->head_len + |
3f52b7e3 | 3814 | 256 + /* TIM IE */ |
af296bdb | 3815 | beacon->tail_len + |
70dabeb7 | 3816 | local->hw.extra_beacon_tailroom); |
902acc78 JB |
3817 | if (!skb) |
3818 | goto out; | |
2b5e1967 | 3819 | skb_reserve(skb, local->tx_headroom); |
af296bdb MK |
3820 | memcpy(skb_put(skb, beacon->head_len), beacon->head, |
3821 | beacon->head_len); | |
6ec8c332 AO |
3822 | ieee80211_beacon_add_tim(sdata, &ifmsh->ps, skb, is_template); |
3823 | ||
3824 | if (offs) { | |
af296bdb MK |
3825 | offs->tim_offset = beacon->head_len; |
3826 | offs->tim_length = skb->len - beacon->head_len; | |
6ec8c332 AO |
3827 | } |
3828 | ||
af296bdb MK |
3829 | memcpy(skb_put(skb, beacon->tail_len), beacon->tail, |
3830 | beacon->tail_len); | |
9d139c81 JB |
3831 | } else { |
3832 | WARN_ON(1); | |
5dfdaf58 | 3833 | goto out; |
e2ebc74d JB |
3834 | } |
3835 | ||
1af586c9 | 3836 | /* CSA offsets */ |
af296bdb | 3837 | if (offs && beacon) { |
1af586c9 AO |
3838 | int i; |
3839 | ||
3840 | for (i = 0; i < IEEE80211_MAX_CSA_COUNTERS_NUM; i++) { | |
af296bdb | 3841 | u16 csa_off = beacon->csa_counter_offsets[i]; |
1af586c9 AO |
3842 | |
3843 | if (!csa_off) | |
3844 | continue; | |
3845 | ||
3846 | offs->csa_counter_offs[i] = csa_off_base + csa_off; | |
3847 | } | |
3848 | } | |
3849 | ||
4bf88530 | 3850 | band = chanctx_conf->def.chan->band; |
55de908a | 3851 | |
e039fa4a JB |
3852 | info = IEEE80211_SKB_CB(skb); |
3853 | ||
3b8d81e0 | 3854 | info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
e00cfce0 | 3855 | info->flags |= IEEE80211_TX_CTL_NO_ACK; |
e039fa4a | 3856 | info->band = band; |
e00cfce0 JM |
3857 | |
3858 | memset(&txrc, 0, sizeof(txrc)); | |
3859 | txrc.hw = hw; | |
e31583cd | 3860 | txrc.sband = local->hw.wiphy->bands[band]; |
e00cfce0 JM |
3861 | txrc.bss_conf = &sdata->vif.bss_conf; |
3862 | txrc.skb = skb; | |
3863 | txrc.reported_rate.idx = -1; | |
37eb0b16 | 3864 | txrc.rate_idx_mask = sdata->rc_rateidx_mask[band]; |
e31583cd | 3865 | if (txrc.rate_idx_mask == (1 << txrc.sband->n_bitrates) - 1) |
37eb0b16 JM |
3866 | txrc.max_rate_idx = -1; |
3867 | else | |
3868 | txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1; | |
8f0729b1 | 3869 | txrc.bss = true; |
e00cfce0 | 3870 | rate_control_get_rate(sdata, NULL, &txrc); |
e039fa4a JB |
3871 | |
3872 | info->control.vif = vif; | |
f591fa5d | 3873 | |
a472e71b JL |
3874 | info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT | |
3875 | IEEE80211_TX_CTL_ASSIGN_SEQ | | |
3876 | IEEE80211_TX_CTL_FIRST_FRAGMENT; | |
e6a9854b | 3877 | out: |
5dfdaf58 | 3878 | rcu_read_unlock(); |
e2ebc74d | 3879 | return skb; |
6ec8c332 AO |
3880 | |
3881 | } | |
3882 | ||
3883 | struct sk_buff * | |
3884 | ieee80211_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 | } | |
3890 | EXPORT_SYMBOL(ieee80211_beacon_get_template); | |
3891 | ||
3892 | struct 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); | |
35afa588 HS |
3898 | struct sk_buff *copy; |
3899 | struct ieee80211_supported_band *sband; | |
3900 | int shift; | |
3901 | ||
3902 | if (!bcn) | |
3903 | return bcn; | |
6ec8c332 AO |
3904 | |
3905 | if (tim_offset) | |
3906 | *tim_offset = offs.tim_offset; | |
3907 | ||
3908 | if (tim_length) | |
3909 | *tim_length = offs.tim_length; | |
3910 | ||
35afa588 HS |
3911 | 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 | ||
6ec8c332 | 3924 | return bcn; |
e2ebc74d | 3925 | } |
eddcbb94 | 3926 | EXPORT_SYMBOL(ieee80211_beacon_get_tim); |
e2ebc74d | 3927 | |
02945821 AN |
3928 | struct sk_buff *ieee80211_proberesp_get(struct ieee80211_hw *hw, |
3929 | struct ieee80211_vif *vif) | |
3930 | { | |
3931 | struct ieee80211_if_ap *ap = NULL; | |
aa7a0080 ES |
3932 | struct sk_buff *skb = NULL; |
3933 | struct probe_resp *presp = NULL; | |
02945821 AN |
3934 | 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 | ||
aa7a0080 | 3947 | skb = dev_alloc_skb(presp->len); |
02945821 AN |
3948 | if (!skb) |
3949 | goto out; | |
3950 | ||
aa7a0080 ES |
3951 | memcpy(skb_put(skb, presp->len), presp->data, presp->len); |
3952 | ||
02945821 AN |
3953 | hdr = (struct ieee80211_hdr *) skb->data; |
3954 | memset(hdr->addr1, 0, sizeof(hdr->addr1)); | |
3955 | ||
3956 | out: | |
3957 | rcu_read_unlock(); | |
3958 | return skb; | |
3959 | } | |
3960 | EXPORT_SYMBOL(ieee80211_proberesp_get); | |
3961 | ||
7044cc56 KV |
3962 | struct 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)); | |
d15b8459 | 3979 | if (!skb) |
7044cc56 | 3980 | return NULL; |
d15b8459 | 3981 | |
7044cc56 KV |
3982 | 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 | } | |
3998 | EXPORT_SYMBOL(ieee80211_pspoll_get); | |
3999 | ||
4000 | struct 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)); | |
d15b8459 | 4017 | if (!skb) |
7044cc56 | 4018 | return NULL; |
d15b8459 | 4019 | |
7044cc56 KV |
4020 | 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 | } | |
4034 | EXPORT_SYMBOL(ieee80211_nullfunc_get); | |
4035 | ||
05e54ea6 | 4036 | struct sk_buff *ieee80211_probereq_get(struct ieee80211_hw *hw, |
a344d677 | 4037 | const u8 *src_addr, |
05e54ea6 | 4038 | const u8 *ssid, size_t ssid_len, |
b9a9ada1 | 4039 | size_t tailroom) |
05e54ea6 | 4040 | { |
a344d677 | 4041 | struct ieee80211_local *local = hw_to_local(hw); |
05e54ea6 KV |
4042 | struct ieee80211_hdr_3addr *hdr; |
4043 | struct sk_buff *skb; | |
4044 | size_t ie_ssid_len; | |
4045 | u8 *pos; | |
4046 | ||
05e54ea6 KV |
4047 | ie_ssid_len = 2 + ssid_len; |
4048 | ||
4049 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*hdr) + | |
b9a9ada1 | 4050 | ie_ssid_len + tailroom); |
d15b8459 | 4051 | if (!skb) |
05e54ea6 | 4052 | return NULL; |
05e54ea6 KV |
4053 | |
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); | |
e83e6541 | 4060 | eth_broadcast_addr(hdr->addr1); |
a344d677 | 4061 | memcpy(hdr->addr2, src_addr, ETH_ALEN); |
e83e6541 | 4062 | eth_broadcast_addr(hdr->addr3); |
05e54ea6 KV |
4063 | |
4064 | pos = skb_put(skb, ie_ssid_len); | |
4065 | *pos++ = WLAN_EID_SSID; | |
4066 | *pos++ = ssid_len; | |
88c868c4 | 4067 | if (ssid_len) |
05e54ea6 KV |
4068 | memcpy(pos, ssid, ssid_len); |
4069 | pos += ssid_len; | |
4070 | ||
05e54ea6 KV |
4071 | return skb; |
4072 | } | |
4073 | EXPORT_SYMBOL(ieee80211_probereq_get); | |
4074 | ||
32bfd35d | 4075 | void ieee80211_rts_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
e2ebc74d | 4076 | const void *frame, size_t frame_len, |
e039fa4a | 4077 | const struct ieee80211_tx_info *frame_txctl, |
e2ebc74d JB |
4078 | struct ieee80211_rts *rts) |
4079 | { | |
4080 | const struct ieee80211_hdr *hdr = frame; | |
e2ebc74d | 4081 | |
065e9605 HH |
4082 | rts->frame_control = |
4083 | cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS); | |
32bfd35d JB |
4084 | rts->duration = ieee80211_rts_duration(hw, vif, frame_len, |
4085 | frame_txctl); | |
e2ebc74d JB |
4086 | memcpy(rts->ra, hdr->addr1, sizeof(rts->ra)); |
4087 | memcpy(rts->ta, hdr->addr2, sizeof(rts->ta)); | |
4088 | } | |
4089 | EXPORT_SYMBOL(ieee80211_rts_get); | |
4090 | ||
32bfd35d | 4091 | void ieee80211_ctstoself_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
e2ebc74d | 4092 | const void *frame, size_t frame_len, |
e039fa4a | 4093 | const struct ieee80211_tx_info *frame_txctl, |
e2ebc74d JB |
4094 | struct ieee80211_cts *cts) |
4095 | { | |
4096 | const struct ieee80211_hdr *hdr = frame; | |
e2ebc74d | 4097 | |
065e9605 HH |
4098 | cts->frame_control = |
4099 | cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS); | |
32bfd35d JB |
4100 | cts->duration = ieee80211_ctstoself_duration(hw, vif, |
4101 | frame_len, frame_txctl); | |
e2ebc74d JB |
4102 | memcpy(cts->ra, hdr->addr1, sizeof(cts->ra)); |
4103 | } | |
4104 | EXPORT_SYMBOL(ieee80211_ctstoself_get); | |
4105 | ||
4106 | struct sk_buff * | |
32bfd35d | 4107 | ieee80211_get_buffered_bc(struct ieee80211_hw *hw, |
e039fa4a | 4108 | struct ieee80211_vif *vif) |
e2ebc74d JB |
4109 | { |
4110 | struct ieee80211_local *local = hw_to_local(hw); | |
747cf5e9 | 4111 | struct sk_buff *skb = NULL; |
5cf121c3 | 4112 | struct ieee80211_tx_data tx; |
e2ebc74d | 4113 | struct ieee80211_sub_if_data *sdata; |
d012a605 | 4114 | struct ps_data *ps; |
e039fa4a | 4115 | struct ieee80211_tx_info *info; |
55de908a | 4116 | struct ieee80211_chanctx_conf *chanctx_conf; |
e2ebc74d | 4117 | |
32bfd35d | 4118 | sdata = vif_to_sdata(vif); |
5dfdaf58 | 4119 | |
5dfdaf58 | 4120 | rcu_read_lock(); |
55de908a | 4121 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
5dfdaf58 | 4122 | |
d012a605 MP |
4123 | if (!chanctx_conf) |
4124 | goto out; | |
4125 | ||
4126 | 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; | |
3f52b7e3 MP |
4134 | } else if (ieee80211_vif_is_mesh(&sdata->vif)) { |
4135 | ps = &sdata->u.mesh.ps; | |
d012a605 | 4136 | } else { |
747cf5e9 | 4137 | goto out; |
d012a605 | 4138 | } |
5dfdaf58 | 4139 | |
d012a605 | 4140 | if (ps->dtim_count != 0 || !ps->dtim_bc_mc) |
747cf5e9 | 4141 | goto out; /* send buffered bc/mc only after DTIM beacon */ |
e039fa4a | 4142 | |
e2ebc74d | 4143 | while (1) { |
d012a605 | 4144 | skb = skb_dequeue(&ps->bc_buf); |
e2ebc74d | 4145 | if (!skb) |
747cf5e9 | 4146 | goto out; |
e2ebc74d JB |
4147 | local->total_ps_buffered--; |
4148 | ||
d012a605 | 4149 | if (!skb_queue_empty(&ps->bc_buf) && skb->len >= 2) { |
e2ebc74d JB |
4150 | 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 | ||
112c44b2 | 4159 | if (sdata->vif.type == NL80211_IFTYPE_AP) |
7cbf9d01 | 4160 | sdata = IEEE80211_DEV_TO_SUB_IF(skb->dev); |
7c10770f | 4161 | if (!ieee80211_tx_prepare(sdata, &tx, NULL, skb)) |
e2ebc74d JB |
4162 | break; |
4163 | dev_kfree_skb_any(skb); | |
4164 | } | |
e039fa4a JB |
4165 | |
4166 | info = IEEE80211_SKB_CB(skb); | |
4167 | ||
5cf121c3 | 4168 | tx.flags |= IEEE80211_TX_PS_BUFFERED; |
4bf88530 | 4169 | info->band = chanctx_conf->def.chan->band; |
e2ebc74d | 4170 | |
97b045d6 | 4171 | if (invoke_tx_handlers(&tx)) |
e2ebc74d | 4172 | skb = NULL; |
97b045d6 | 4173 | out: |
d0709a65 | 4174 | rcu_read_unlock(); |
e2ebc74d JB |
4175 | |
4176 | return skb; | |
4177 | } | |
4178 | EXPORT_SYMBOL(ieee80211_get_buffered_bc); | |
3b8d81e0 | 4179 | |
b6da911b LK |
4180 | int 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 */ | |
30686bf7 | 4221 | if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION)) { |
b6da911b LK |
4222 | 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]]); | |
3b24f4c6 | 4228 | __ieee80211_flush_queues(local, sdata, queues, false); |
b6da911b LK |
4229 | |
4230 | sta->reserved_tid = tid; | |
4231 | ||
4232 | ieee80211_wake_vif_queues(local, sdata, | |
4233 | IEEE80211_QUEUE_STOP_REASON_RESERVE_TID); | |
4234 | ||
30686bf7 | 4235 | if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION)) |
b6da911b LK |
4236 | clear_sta_flag(sta, WLAN_STA_BLOCK_BA); |
4237 | ||
4238 | ret = 0; | |
4239 | out: | |
4240 | return ret; | |
4241 | } | |
4242 | EXPORT_SYMBOL(ieee80211_reserve_tid); | |
4243 | ||
4244 | void 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 | } | |
4269 | EXPORT_SYMBOL(ieee80211_unreserve_tid); | |
4270 | ||
55de908a JB |
4271 | void __ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata, |
4272 | struct sk_buff *skb, int tid, | |
57fbcce3 | 4273 | enum nl80211_band band) |
3b8d81e0 | 4274 | { |
353d09c6 | 4275 | int ac = ieee802_1d_to_ac[tid & 7]; |
3a25a8c8 | 4276 | |
d57a544d ZS |
4277 | skb_reset_mac_header(skb); |
4278 | skb_reset_network_header(skb); | |
4279 | skb_reset_transport_header(skb); | |
3b8d81e0 | 4280 | |
3a25a8c8 | 4281 | skb_set_queue_mapping(skb, ac); |
cf6bb79a | 4282 | skb->priority = tid; |
cf0277e7 | 4283 | |
89afe614 JB |
4284 | skb->dev = sdata->dev; |
4285 | ||
3d34deb6 JB |
4286 | /* |
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(); | |
73c4e195 | 4292 | IEEE80211_SKB_CB(skb)->band = band; |
7c10770f | 4293 | ieee80211_xmit(sdata, NULL, skb); |
3d34deb6 | 4294 | local_bh_enable(); |
3b8d81e0 | 4295 | } |