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