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