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