xref: /openbmc/linux/net/mac80211/rx.c (revision 1f012283)
1 // SPDX-License-Identifier: GPL-2.0-only
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-2010	Johannes Berg <johannes@sipsolutions.net>
7  * Copyright 2013-2014  Intel Mobile Communications GmbH
8  * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
9  * Copyright (C) 2018-2021 Intel Corporation
10  */
11 
12 #include <linux/jiffies.h>
13 #include <linux/slab.h>
14 #include <linux/kernel.h>
15 #include <linux/skbuff.h>
16 #include <linux/netdevice.h>
17 #include <linux/etherdevice.h>
18 #include <linux/rcupdate.h>
19 #include <linux/export.h>
20 #include <linux/kcov.h>
21 #include <linux/bitops.h>
22 #include <net/mac80211.h>
23 #include <net/ieee80211_radiotap.h>
24 #include <asm/unaligned.h>
25 
26 #include "ieee80211_i.h"
27 #include "driver-ops.h"
28 #include "led.h"
29 #include "mesh.h"
30 #include "wep.h"
31 #include "wpa.h"
32 #include "tkip.h"
33 #include "wme.h"
34 #include "rate.h"
35 
36 /*
37  * monitor mode reception
38  *
39  * This function cleans up the SKB, i.e. it removes all the stuff
40  * only useful for monitoring.
41  */
42 static struct sk_buff *ieee80211_clean_skb(struct sk_buff *skb,
43 					   unsigned int present_fcs_len,
44 					   unsigned int rtap_space)
45 {
46 	struct ieee80211_hdr *hdr;
47 	unsigned int hdrlen;
48 	__le16 fc;
49 
50 	if (present_fcs_len)
51 		__pskb_trim(skb, skb->len - present_fcs_len);
52 	__pskb_pull(skb, rtap_space);
53 
54 	hdr = (void *)skb->data;
55 	fc = hdr->frame_control;
56 
57 	/*
58 	 * Remove the HT-Control field (if present) on management
59 	 * frames after we've sent the frame to monitoring. We
60 	 * (currently) don't need it, and don't properly parse
61 	 * frames with it present, due to the assumption of a
62 	 * fixed management header length.
63 	 */
64 	if (likely(!ieee80211_is_mgmt(fc) || !ieee80211_has_order(fc)))
65 		return skb;
66 
67 	hdrlen = ieee80211_hdrlen(fc);
68 	hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_ORDER);
69 
70 	if (!pskb_may_pull(skb, hdrlen)) {
71 		dev_kfree_skb(skb);
72 		return NULL;
73 	}
74 
75 	memmove(skb->data + IEEE80211_HT_CTL_LEN, skb->data,
76 		hdrlen - IEEE80211_HT_CTL_LEN);
77 	__pskb_pull(skb, IEEE80211_HT_CTL_LEN);
78 
79 	return skb;
80 }
81 
82 static inline bool should_drop_frame(struct sk_buff *skb, int present_fcs_len,
83 				     unsigned int rtap_space)
84 {
85 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
86 	struct ieee80211_hdr *hdr;
87 
88 	hdr = (void *)(skb->data + rtap_space);
89 
90 	if (status->flag & (RX_FLAG_FAILED_FCS_CRC |
91 			    RX_FLAG_FAILED_PLCP_CRC |
92 			    RX_FLAG_ONLY_MONITOR |
93 			    RX_FLAG_NO_PSDU))
94 		return true;
95 
96 	if (unlikely(skb->len < 16 + present_fcs_len + rtap_space))
97 		return true;
98 
99 	if (ieee80211_is_ctl(hdr->frame_control) &&
100 	    !ieee80211_is_pspoll(hdr->frame_control) &&
101 	    !ieee80211_is_back_req(hdr->frame_control))
102 		return true;
103 
104 	return false;
105 }
106 
107 static int
108 ieee80211_rx_radiotap_hdrlen(struct ieee80211_local *local,
109 			     struct ieee80211_rx_status *status,
110 			     struct sk_buff *skb)
111 {
112 	int len;
113 
114 	/* always present fields */
115 	len = sizeof(struct ieee80211_radiotap_header) + 8;
116 
117 	/* allocate extra bitmaps */
118 	if (status->chains)
119 		len += 4 * hweight8(status->chains);
120 	/* vendor presence bitmap */
121 	if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)
122 		len += 4;
123 
124 	if (ieee80211_have_rx_timestamp(status)) {
125 		len = ALIGN(len, 8);
126 		len += 8;
127 	}
128 	if (ieee80211_hw_check(&local->hw, SIGNAL_DBM))
129 		len += 1;
130 
131 	/* antenna field, if we don't have per-chain info */
132 	if (!status->chains)
133 		len += 1;
134 
135 	/* padding for RX_FLAGS if necessary */
136 	len = ALIGN(len, 2);
137 
138 	if (status->encoding == RX_ENC_HT) /* HT info */
139 		len += 3;
140 
141 	if (status->flag & RX_FLAG_AMPDU_DETAILS) {
142 		len = ALIGN(len, 4);
143 		len += 8;
144 	}
145 
146 	if (status->encoding == RX_ENC_VHT) {
147 		len = ALIGN(len, 2);
148 		len += 12;
149 	}
150 
151 	if (local->hw.radiotap_timestamp.units_pos >= 0) {
152 		len = ALIGN(len, 8);
153 		len += 12;
154 	}
155 
156 	if (status->encoding == RX_ENC_HE &&
157 	    status->flag & RX_FLAG_RADIOTAP_HE) {
158 		len = ALIGN(len, 2);
159 		len += 12;
160 		BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he) != 12);
161 	}
162 
163 	if (status->encoding == RX_ENC_HE &&
164 	    status->flag & RX_FLAG_RADIOTAP_HE_MU) {
165 		len = ALIGN(len, 2);
166 		len += 12;
167 		BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he_mu) != 12);
168 	}
169 
170 	if (status->flag & RX_FLAG_NO_PSDU)
171 		len += 1;
172 
173 	if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
174 		len = ALIGN(len, 2);
175 		len += 4;
176 		BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_lsig) != 4);
177 	}
178 
179 	if (status->chains) {
180 		/* antenna and antenna signal fields */
181 		len += 2 * hweight8(status->chains);
182 	}
183 
184 	if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
185 		struct ieee80211_vendor_radiotap *rtap;
186 		int vendor_data_offset = 0;
187 
188 		/*
189 		 * The position to look at depends on the existence (or non-
190 		 * existence) of other elements, so take that into account...
191 		 */
192 		if (status->flag & RX_FLAG_RADIOTAP_HE)
193 			vendor_data_offset +=
194 				sizeof(struct ieee80211_radiotap_he);
195 		if (status->flag & RX_FLAG_RADIOTAP_HE_MU)
196 			vendor_data_offset +=
197 				sizeof(struct ieee80211_radiotap_he_mu);
198 		if (status->flag & RX_FLAG_RADIOTAP_LSIG)
199 			vendor_data_offset +=
200 				sizeof(struct ieee80211_radiotap_lsig);
201 
202 		rtap = (void *)&skb->data[vendor_data_offset];
203 
204 		/* alignment for fixed 6-byte vendor data header */
205 		len = ALIGN(len, 2);
206 		/* vendor data header */
207 		len += 6;
208 		if (WARN_ON(rtap->align == 0))
209 			rtap->align = 1;
210 		len = ALIGN(len, rtap->align);
211 		len += rtap->len + rtap->pad;
212 	}
213 
214 	return len;
215 }
216 
217 static void __ieee80211_queue_skb_to_iface(struct ieee80211_sub_if_data *sdata,
218 					   struct sta_info *sta,
219 					   struct sk_buff *skb)
220 {
221 	skb_queue_tail(&sdata->skb_queue, skb);
222 	ieee80211_queue_work(&sdata->local->hw, &sdata->work);
223 	if (sta)
224 		sta->rx_stats.packets++;
225 }
226 
227 static void ieee80211_queue_skb_to_iface(struct ieee80211_sub_if_data *sdata,
228 					 struct sta_info *sta,
229 					 struct sk_buff *skb)
230 {
231 	skb->protocol = 0;
232 	__ieee80211_queue_skb_to_iface(sdata, sta, skb);
233 }
234 
235 static void ieee80211_handle_mu_mimo_mon(struct ieee80211_sub_if_data *sdata,
236 					 struct sk_buff *skb,
237 					 int rtap_space)
238 {
239 	struct {
240 		struct ieee80211_hdr_3addr hdr;
241 		u8 category;
242 		u8 action_code;
243 	} __packed __aligned(2) action;
244 
245 	if (!sdata)
246 		return;
247 
248 	BUILD_BUG_ON(sizeof(action) != IEEE80211_MIN_ACTION_SIZE + 1);
249 
250 	if (skb->len < rtap_space + sizeof(action) +
251 		       VHT_MUMIMO_GROUPS_DATA_LEN)
252 		return;
253 
254 	if (!is_valid_ether_addr(sdata->u.mntr.mu_follow_addr))
255 		return;
256 
257 	skb_copy_bits(skb, rtap_space, &action, sizeof(action));
258 
259 	if (!ieee80211_is_action(action.hdr.frame_control))
260 		return;
261 
262 	if (action.category != WLAN_CATEGORY_VHT)
263 		return;
264 
265 	if (action.action_code != WLAN_VHT_ACTION_GROUPID_MGMT)
266 		return;
267 
268 	if (!ether_addr_equal(action.hdr.addr1, sdata->u.mntr.mu_follow_addr))
269 		return;
270 
271 	skb = skb_copy(skb, GFP_ATOMIC);
272 	if (!skb)
273 		return;
274 
275 	ieee80211_queue_skb_to_iface(sdata, NULL, skb);
276 }
277 
278 /*
279  * ieee80211_add_rx_radiotap_header - add radiotap header
280  *
281  * add a radiotap header containing all the fields which the hardware provided.
282  */
283 static void
284 ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
285 				 struct sk_buff *skb,
286 				 struct ieee80211_rate *rate,
287 				 int rtap_len, bool has_fcs)
288 {
289 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
290 	struct ieee80211_radiotap_header *rthdr;
291 	unsigned char *pos;
292 	__le32 *it_present;
293 	u32 it_present_val;
294 	u16 rx_flags = 0;
295 	u16 channel_flags = 0;
296 	int mpdulen, chain;
297 	unsigned long chains = status->chains;
298 	struct ieee80211_vendor_radiotap rtap = {};
299 	struct ieee80211_radiotap_he he = {};
300 	struct ieee80211_radiotap_he_mu he_mu = {};
301 	struct ieee80211_radiotap_lsig lsig = {};
302 
303 	if (status->flag & RX_FLAG_RADIOTAP_HE) {
304 		he = *(struct ieee80211_radiotap_he *)skb->data;
305 		skb_pull(skb, sizeof(he));
306 		WARN_ON_ONCE(status->encoding != RX_ENC_HE);
307 	}
308 
309 	if (status->flag & RX_FLAG_RADIOTAP_HE_MU) {
310 		he_mu = *(struct ieee80211_radiotap_he_mu *)skb->data;
311 		skb_pull(skb, sizeof(he_mu));
312 	}
313 
314 	if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
315 		lsig = *(struct ieee80211_radiotap_lsig *)skb->data;
316 		skb_pull(skb, sizeof(lsig));
317 	}
318 
319 	if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
320 		rtap = *(struct ieee80211_vendor_radiotap *)skb->data;
321 		/* rtap.len and rtap.pad are undone immediately */
322 		skb_pull(skb, sizeof(rtap) + rtap.len + rtap.pad);
323 	}
324 
325 	mpdulen = skb->len;
326 	if (!(has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)))
327 		mpdulen += FCS_LEN;
328 
329 	rthdr = skb_push(skb, rtap_len);
330 	memset(rthdr, 0, rtap_len - rtap.len - rtap.pad);
331 	it_present = &rthdr->it_present;
332 
333 	/* radiotap header, set always present flags */
334 	rthdr->it_len = cpu_to_le16(rtap_len);
335 	it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) |
336 			 BIT(IEEE80211_RADIOTAP_CHANNEL) |
337 			 BIT(IEEE80211_RADIOTAP_RX_FLAGS);
338 
339 	if (!status->chains)
340 		it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA);
341 
342 	for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
343 		it_present_val |=
344 			BIT(IEEE80211_RADIOTAP_EXT) |
345 			BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
346 		put_unaligned_le32(it_present_val, it_present);
347 		it_present++;
348 		it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
349 				 BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
350 	}
351 
352 	if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
353 		it_present_val |= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE) |
354 				  BIT(IEEE80211_RADIOTAP_EXT);
355 		put_unaligned_le32(it_present_val, it_present);
356 		it_present++;
357 		it_present_val = rtap.present;
358 	}
359 
360 	put_unaligned_le32(it_present_val, it_present);
361 
362 	/* This references through an offset into it_optional[] rather
363 	 * than via it_present otherwise later uses of pos will cause
364 	 * the compiler to think we have walked past the end of the
365 	 * struct member.
366 	 */
367 	pos = (void *)&rthdr->it_optional[it_present - rthdr->it_optional];
368 
369 	/* the order of the following fields is important */
370 
371 	/* IEEE80211_RADIOTAP_TSFT */
372 	if (ieee80211_have_rx_timestamp(status)) {
373 		/* padding */
374 		while ((pos - (u8 *)rthdr) & 7)
375 			*pos++ = 0;
376 		put_unaligned_le64(
377 			ieee80211_calculate_rx_timestamp(local, status,
378 							 mpdulen, 0),
379 			pos);
380 		rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_TSFT));
381 		pos += 8;
382 	}
383 
384 	/* IEEE80211_RADIOTAP_FLAGS */
385 	if (has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))
386 		*pos |= IEEE80211_RADIOTAP_F_FCS;
387 	if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
388 		*pos |= IEEE80211_RADIOTAP_F_BADFCS;
389 	if (status->enc_flags & RX_ENC_FLAG_SHORTPRE)
390 		*pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
391 	pos++;
392 
393 	/* IEEE80211_RADIOTAP_RATE */
394 	if (!rate || status->encoding != RX_ENC_LEGACY) {
395 		/*
396 		 * Without rate information don't add it. If we have,
397 		 * MCS information is a separate field in radiotap,
398 		 * added below. The byte here is needed as padding
399 		 * for the channel though, so initialise it to 0.
400 		 */
401 		*pos = 0;
402 	} else {
403 		int shift = 0;
404 		rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_RATE));
405 		if (status->bw == RATE_INFO_BW_10)
406 			shift = 1;
407 		else if (status->bw == RATE_INFO_BW_5)
408 			shift = 2;
409 		*pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift));
410 	}
411 	pos++;
412 
413 	/* IEEE80211_RADIOTAP_CHANNEL */
414 	/* TODO: frequency offset in KHz */
415 	put_unaligned_le16(status->freq, pos);
416 	pos += 2;
417 	if (status->bw == RATE_INFO_BW_10)
418 		channel_flags |= IEEE80211_CHAN_HALF;
419 	else if (status->bw == RATE_INFO_BW_5)
420 		channel_flags |= IEEE80211_CHAN_QUARTER;
421 
422 	if (status->band == NL80211_BAND_5GHZ ||
423 	    status->band == NL80211_BAND_6GHZ)
424 		channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ;
425 	else if (status->encoding != RX_ENC_LEGACY)
426 		channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
427 	else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
428 		channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
429 	else if (rate)
430 		channel_flags |= IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ;
431 	else
432 		channel_flags |= IEEE80211_CHAN_2GHZ;
433 	put_unaligned_le16(channel_flags, pos);
434 	pos += 2;
435 
436 	/* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
437 	if (ieee80211_hw_check(&local->hw, SIGNAL_DBM) &&
438 	    !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
439 		*pos = status->signal;
440 		rthdr->it_present |=
441 			cpu_to_le32(BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL));
442 		pos++;
443 	}
444 
445 	/* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
446 
447 	if (!status->chains) {
448 		/* IEEE80211_RADIOTAP_ANTENNA */
449 		*pos = status->antenna;
450 		pos++;
451 	}
452 
453 	/* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
454 
455 	/* IEEE80211_RADIOTAP_RX_FLAGS */
456 	/* ensure 2 byte alignment for the 2 byte field as required */
457 	if ((pos - (u8 *)rthdr) & 1)
458 		*pos++ = 0;
459 	if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
460 		rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
461 	put_unaligned_le16(rx_flags, pos);
462 	pos += 2;
463 
464 	if (status->encoding == RX_ENC_HT) {
465 		unsigned int stbc;
466 
467 		rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_MCS));
468 		*pos++ = local->hw.radiotap_mcs_details;
469 		*pos = 0;
470 		if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
471 			*pos |= IEEE80211_RADIOTAP_MCS_SGI;
472 		if (status->bw == RATE_INFO_BW_40)
473 			*pos |= IEEE80211_RADIOTAP_MCS_BW_40;
474 		if (status->enc_flags & RX_ENC_FLAG_HT_GF)
475 			*pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
476 		if (status->enc_flags & RX_ENC_FLAG_LDPC)
477 			*pos |= IEEE80211_RADIOTAP_MCS_FEC_LDPC;
478 		stbc = (status->enc_flags & RX_ENC_FLAG_STBC_MASK) >> RX_ENC_FLAG_STBC_SHIFT;
479 		*pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
480 		pos++;
481 		*pos++ = status->rate_idx;
482 	}
483 
484 	if (status->flag & RX_FLAG_AMPDU_DETAILS) {
485 		u16 flags = 0;
486 
487 		/* ensure 4 byte alignment */
488 		while ((pos - (u8 *)rthdr) & 3)
489 			pos++;
490 		rthdr->it_present |=
491 			cpu_to_le32(BIT(IEEE80211_RADIOTAP_AMPDU_STATUS));
492 		put_unaligned_le32(status->ampdu_reference, pos);
493 		pos += 4;
494 		if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
495 			flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
496 		if (status->flag & RX_FLAG_AMPDU_IS_LAST)
497 			flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
498 		if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
499 			flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
500 		if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
501 			flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
502 		if (status->flag & RX_FLAG_AMPDU_EOF_BIT_KNOWN)
503 			flags |= IEEE80211_RADIOTAP_AMPDU_EOF_KNOWN;
504 		if (status->flag & RX_FLAG_AMPDU_EOF_BIT)
505 			flags |= IEEE80211_RADIOTAP_AMPDU_EOF;
506 		put_unaligned_le16(flags, pos);
507 		pos += 2;
508 		if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
509 			*pos++ = status->ampdu_delimiter_crc;
510 		else
511 			*pos++ = 0;
512 		*pos++ = 0;
513 	}
514 
515 	if (status->encoding == RX_ENC_VHT) {
516 		u16 known = local->hw.radiotap_vht_details;
517 
518 		rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_VHT));
519 		put_unaligned_le16(known, pos);
520 		pos += 2;
521 		/* flags */
522 		if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
523 			*pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
524 		/* in VHT, STBC is binary */
525 		if (status->enc_flags & RX_ENC_FLAG_STBC_MASK)
526 			*pos |= IEEE80211_RADIOTAP_VHT_FLAG_STBC;
527 		if (status->enc_flags & RX_ENC_FLAG_BF)
528 			*pos |= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED;
529 		pos++;
530 		/* bandwidth */
531 		switch (status->bw) {
532 		case RATE_INFO_BW_80:
533 			*pos++ = 4;
534 			break;
535 		case RATE_INFO_BW_160:
536 			*pos++ = 11;
537 			break;
538 		case RATE_INFO_BW_40:
539 			*pos++ = 1;
540 			break;
541 		default:
542 			*pos++ = 0;
543 		}
544 		/* MCS/NSS */
545 		*pos = (status->rate_idx << 4) | status->nss;
546 		pos += 4;
547 		/* coding field */
548 		if (status->enc_flags & RX_ENC_FLAG_LDPC)
549 			*pos |= IEEE80211_RADIOTAP_CODING_LDPC_USER0;
550 		pos++;
551 		/* group ID */
552 		pos++;
553 		/* partial_aid */
554 		pos += 2;
555 	}
556 
557 	if (local->hw.radiotap_timestamp.units_pos >= 0) {
558 		u16 accuracy = 0;
559 		u8 flags = IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT;
560 
561 		rthdr->it_present |=
562 			cpu_to_le32(BIT(IEEE80211_RADIOTAP_TIMESTAMP));
563 
564 		/* ensure 8 byte alignment */
565 		while ((pos - (u8 *)rthdr) & 7)
566 			pos++;
567 
568 		put_unaligned_le64(status->device_timestamp, pos);
569 		pos += sizeof(u64);
570 
571 		if (local->hw.radiotap_timestamp.accuracy >= 0) {
572 			accuracy = local->hw.radiotap_timestamp.accuracy;
573 			flags |= IEEE80211_RADIOTAP_TIMESTAMP_FLAG_ACCURACY;
574 		}
575 		put_unaligned_le16(accuracy, pos);
576 		pos += sizeof(u16);
577 
578 		*pos++ = local->hw.radiotap_timestamp.units_pos;
579 		*pos++ = flags;
580 	}
581 
582 	if (status->encoding == RX_ENC_HE &&
583 	    status->flag & RX_FLAG_RADIOTAP_HE) {
584 #define HE_PREP(f, val)	le16_encode_bits(val, IEEE80211_RADIOTAP_HE_##f)
585 
586 		if (status->enc_flags & RX_ENC_FLAG_STBC_MASK) {
587 			he.data6 |= HE_PREP(DATA6_NSTS,
588 					    FIELD_GET(RX_ENC_FLAG_STBC_MASK,
589 						      status->enc_flags));
590 			he.data3 |= HE_PREP(DATA3_STBC, 1);
591 		} else {
592 			he.data6 |= HE_PREP(DATA6_NSTS, status->nss);
593 		}
594 
595 #define CHECK_GI(s) \
596 	BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_GI_##s != \
597 		     (int)NL80211_RATE_INFO_HE_GI_##s)
598 
599 		CHECK_GI(0_8);
600 		CHECK_GI(1_6);
601 		CHECK_GI(3_2);
602 
603 		he.data3 |= HE_PREP(DATA3_DATA_MCS, status->rate_idx);
604 		he.data3 |= HE_PREP(DATA3_DATA_DCM, status->he_dcm);
605 		he.data3 |= HE_PREP(DATA3_CODING,
606 				    !!(status->enc_flags & RX_ENC_FLAG_LDPC));
607 
608 		he.data5 |= HE_PREP(DATA5_GI, status->he_gi);
609 
610 		switch (status->bw) {
611 		case RATE_INFO_BW_20:
612 			he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
613 					    IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_20MHZ);
614 			break;
615 		case RATE_INFO_BW_40:
616 			he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
617 					    IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_40MHZ);
618 			break;
619 		case RATE_INFO_BW_80:
620 			he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
621 					    IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_80MHZ);
622 			break;
623 		case RATE_INFO_BW_160:
624 			he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
625 					    IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_160MHZ);
626 			break;
627 		case RATE_INFO_BW_HE_RU:
628 #define CHECK_RU_ALLOC(s) \
629 	BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_##s##T != \
630 		     NL80211_RATE_INFO_HE_RU_ALLOC_##s + 4)
631 
632 			CHECK_RU_ALLOC(26);
633 			CHECK_RU_ALLOC(52);
634 			CHECK_RU_ALLOC(106);
635 			CHECK_RU_ALLOC(242);
636 			CHECK_RU_ALLOC(484);
637 			CHECK_RU_ALLOC(996);
638 			CHECK_RU_ALLOC(2x996);
639 
640 			he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
641 					    status->he_ru + 4);
642 			break;
643 		default:
644 			WARN_ONCE(1, "Invalid SU BW %d\n", status->bw);
645 		}
646 
647 		/* ensure 2 byte alignment */
648 		while ((pos - (u8 *)rthdr) & 1)
649 			pos++;
650 		rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_HE));
651 		memcpy(pos, &he, sizeof(he));
652 		pos += sizeof(he);
653 	}
654 
655 	if (status->encoding == RX_ENC_HE &&
656 	    status->flag & RX_FLAG_RADIOTAP_HE_MU) {
657 		/* ensure 2 byte alignment */
658 		while ((pos - (u8 *)rthdr) & 1)
659 			pos++;
660 		rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_HE_MU));
661 		memcpy(pos, &he_mu, sizeof(he_mu));
662 		pos += sizeof(he_mu);
663 	}
664 
665 	if (status->flag & RX_FLAG_NO_PSDU) {
666 		rthdr->it_present |=
667 			cpu_to_le32(BIT(IEEE80211_RADIOTAP_ZERO_LEN_PSDU));
668 		*pos++ = status->zero_length_psdu_type;
669 	}
670 
671 	if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
672 		/* ensure 2 byte alignment */
673 		while ((pos - (u8 *)rthdr) & 1)
674 			pos++;
675 		rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_LSIG));
676 		memcpy(pos, &lsig, sizeof(lsig));
677 		pos += sizeof(lsig);
678 	}
679 
680 	for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
681 		*pos++ = status->chain_signal[chain];
682 		*pos++ = chain;
683 	}
684 
685 	if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
686 		/* ensure 2 byte alignment for the vendor field as required */
687 		if ((pos - (u8 *)rthdr) & 1)
688 			*pos++ = 0;
689 		*pos++ = rtap.oui[0];
690 		*pos++ = rtap.oui[1];
691 		*pos++ = rtap.oui[2];
692 		*pos++ = rtap.subns;
693 		put_unaligned_le16(rtap.len, pos);
694 		pos += 2;
695 		/* align the actual payload as requested */
696 		while ((pos - (u8 *)rthdr) & (rtap.align - 1))
697 			*pos++ = 0;
698 		/* data (and possible padding) already follows */
699 	}
700 }
701 
702 static struct sk_buff *
703 ieee80211_make_monitor_skb(struct ieee80211_local *local,
704 			   struct sk_buff **origskb,
705 			   struct ieee80211_rate *rate,
706 			   int rtap_space, bool use_origskb)
707 {
708 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(*origskb);
709 	int rt_hdrlen, needed_headroom;
710 	struct sk_buff *skb;
711 
712 	/* room for the radiotap header based on driver features */
713 	rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, *origskb);
714 	needed_headroom = rt_hdrlen - rtap_space;
715 
716 	if (use_origskb) {
717 		/* only need to expand headroom if necessary */
718 		skb = *origskb;
719 		*origskb = NULL;
720 
721 		/*
722 		 * This shouldn't trigger often because most devices have an
723 		 * RX header they pull before we get here, and that should
724 		 * be big enough for our radiotap information. We should
725 		 * probably export the length to drivers so that we can have
726 		 * them allocate enough headroom to start with.
727 		 */
728 		if (skb_headroom(skb) < needed_headroom &&
729 		    pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
730 			dev_kfree_skb(skb);
731 			return NULL;
732 		}
733 	} else {
734 		/*
735 		 * Need to make a copy and possibly remove radiotap header
736 		 * and FCS from the original.
737 		 */
738 		skb = skb_copy_expand(*origskb, needed_headroom + NET_SKB_PAD,
739 				      0, GFP_ATOMIC);
740 
741 		if (!skb)
742 			return NULL;
743 	}
744 
745 	/* prepend radiotap information */
746 	ieee80211_add_rx_radiotap_header(local, skb, rate, rt_hdrlen, true);
747 
748 	skb_reset_mac_header(skb);
749 	skb->ip_summed = CHECKSUM_UNNECESSARY;
750 	skb->pkt_type = PACKET_OTHERHOST;
751 	skb->protocol = htons(ETH_P_802_2);
752 
753 	return skb;
754 }
755 
756 /*
757  * This function copies a received frame to all monitor interfaces and
758  * returns a cleaned-up SKB that no longer includes the FCS nor the
759  * radiotap header the driver might have added.
760  */
761 static struct sk_buff *
762 ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
763 		     struct ieee80211_rate *rate)
764 {
765 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
766 	struct ieee80211_sub_if_data *sdata;
767 	struct sk_buff *monskb = NULL;
768 	int present_fcs_len = 0;
769 	unsigned int rtap_space = 0;
770 	struct ieee80211_sub_if_data *monitor_sdata =
771 		rcu_dereference(local->monitor_sdata);
772 	bool only_monitor = false;
773 	unsigned int min_head_len;
774 
775 	if (status->flag & RX_FLAG_RADIOTAP_HE)
776 		rtap_space += sizeof(struct ieee80211_radiotap_he);
777 
778 	if (status->flag & RX_FLAG_RADIOTAP_HE_MU)
779 		rtap_space += sizeof(struct ieee80211_radiotap_he_mu);
780 
781 	if (status->flag & RX_FLAG_RADIOTAP_LSIG)
782 		rtap_space += sizeof(struct ieee80211_radiotap_lsig);
783 
784 	if (unlikely(status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)) {
785 		struct ieee80211_vendor_radiotap *rtap =
786 			(void *)(origskb->data + rtap_space);
787 
788 		rtap_space += sizeof(*rtap) + rtap->len + rtap->pad;
789 	}
790 
791 	min_head_len = rtap_space;
792 
793 	/*
794 	 * First, we may need to make a copy of the skb because
795 	 *  (1) we need to modify it for radiotap (if not present), and
796 	 *  (2) the other RX handlers will modify the skb we got.
797 	 *
798 	 * We don't need to, of course, if we aren't going to return
799 	 * the SKB because it has a bad FCS/PLCP checksum.
800 	 */
801 
802 	if (!(status->flag & RX_FLAG_NO_PSDU)) {
803 		if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) {
804 			if (unlikely(origskb->len <= FCS_LEN + rtap_space)) {
805 				/* driver bug */
806 				WARN_ON(1);
807 				dev_kfree_skb(origskb);
808 				return NULL;
809 			}
810 			present_fcs_len = FCS_LEN;
811 		}
812 
813 		/* also consider the hdr->frame_control */
814 		min_head_len += 2;
815 	}
816 
817 	/* ensure that the expected data elements are in skb head */
818 	if (!pskb_may_pull(origskb, min_head_len)) {
819 		dev_kfree_skb(origskb);
820 		return NULL;
821 	}
822 
823 	only_monitor = should_drop_frame(origskb, present_fcs_len, rtap_space);
824 
825 	if (!local->monitors || (status->flag & RX_FLAG_SKIP_MONITOR)) {
826 		if (only_monitor) {
827 			dev_kfree_skb(origskb);
828 			return NULL;
829 		}
830 
831 		return ieee80211_clean_skb(origskb, present_fcs_len,
832 					   rtap_space);
833 	}
834 
835 	ieee80211_handle_mu_mimo_mon(monitor_sdata, origskb, rtap_space);
836 
837 	list_for_each_entry_rcu(sdata, &local->mon_list, u.mntr.list) {
838 		bool last_monitor = list_is_last(&sdata->u.mntr.list,
839 						 &local->mon_list);
840 
841 		if (!monskb)
842 			monskb = ieee80211_make_monitor_skb(local, &origskb,
843 							    rate, rtap_space,
844 							    only_monitor &&
845 							    last_monitor);
846 
847 		if (monskb) {
848 			struct sk_buff *skb;
849 
850 			if (last_monitor) {
851 				skb = monskb;
852 				monskb = NULL;
853 			} else {
854 				skb = skb_clone(monskb, GFP_ATOMIC);
855 			}
856 
857 			if (skb) {
858 				skb->dev = sdata->dev;
859 				dev_sw_netstats_rx_add(skb->dev, skb->len);
860 				netif_receive_skb(skb);
861 			}
862 		}
863 
864 		if (last_monitor)
865 			break;
866 	}
867 
868 	/* this happens if last_monitor was erroneously false */
869 	dev_kfree_skb(monskb);
870 
871 	/* ditto */
872 	if (!origskb)
873 		return NULL;
874 
875 	return ieee80211_clean_skb(origskb, present_fcs_len, rtap_space);
876 }
877 
878 static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
879 {
880 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
881 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
882 	int tid, seqno_idx, security_idx;
883 
884 	/* does the frame have a qos control field? */
885 	if (ieee80211_is_data_qos(hdr->frame_control)) {
886 		u8 *qc = ieee80211_get_qos_ctl(hdr);
887 		/* frame has qos control */
888 		tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
889 		if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
890 			status->rx_flags |= IEEE80211_RX_AMSDU;
891 
892 		seqno_idx = tid;
893 		security_idx = tid;
894 	} else {
895 		/*
896 		 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
897 		 *
898 		 *	Sequence numbers for management frames, QoS data
899 		 *	frames with a broadcast/multicast address in the
900 		 *	Address 1 field, and all non-QoS data frames sent
901 		 *	by QoS STAs are assigned using an additional single
902 		 *	modulo-4096 counter, [...]
903 		 *
904 		 * We also use that counter for non-QoS STAs.
905 		 */
906 		seqno_idx = IEEE80211_NUM_TIDS;
907 		security_idx = 0;
908 		if (ieee80211_is_mgmt(hdr->frame_control))
909 			security_idx = IEEE80211_NUM_TIDS;
910 		tid = 0;
911 	}
912 
913 	rx->seqno_idx = seqno_idx;
914 	rx->security_idx = security_idx;
915 	/* Set skb->priority to 1d tag if highest order bit of TID is not set.
916 	 * For now, set skb->priority to 0 for other cases. */
917 	rx->skb->priority = (tid > 7) ? 0 : tid;
918 }
919 
920 /**
921  * DOC: Packet alignment
922  *
923  * Drivers always need to pass packets that are aligned to two-byte boundaries
924  * to the stack.
925  *
926  * Additionally, should, if possible, align the payload data in a way that
927  * guarantees that the contained IP header is aligned to a four-byte
928  * boundary. In the case of regular frames, this simply means aligning the
929  * payload to a four-byte boundary (because either the IP header is directly
930  * contained, or IV/RFC1042 headers that have a length divisible by four are
931  * in front of it).  If the payload data is not properly aligned and the
932  * architecture doesn't support efficient unaligned operations, mac80211
933  * will align the data.
934  *
935  * With A-MSDU frames, however, the payload data address must yield two modulo
936  * four because there are 14-byte 802.3 headers within the A-MSDU frames that
937  * push the IP header further back to a multiple of four again. Thankfully, the
938  * specs were sane enough this time around to require padding each A-MSDU
939  * subframe to a length that is a multiple of four.
940  *
941  * Padding like Atheros hardware adds which is between the 802.11 header and
942  * the payload is not supported, the driver is required to move the 802.11
943  * header to be directly in front of the payload in that case.
944  */
945 static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
946 {
947 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
948 	WARN_ON_ONCE((unsigned long)rx->skb->data & 1);
949 #endif
950 }
951 
952 
953 /* rx handlers */
954 
955 static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
956 {
957 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
958 
959 	if (is_multicast_ether_addr(hdr->addr1))
960 		return 0;
961 
962 	return ieee80211_is_robust_mgmt_frame(skb);
963 }
964 
965 
966 static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
967 {
968 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
969 
970 	if (!is_multicast_ether_addr(hdr->addr1))
971 		return 0;
972 
973 	return ieee80211_is_robust_mgmt_frame(skb);
974 }
975 
976 
977 /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
978 static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
979 {
980 	struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
981 	struct ieee80211_mmie *mmie;
982 	struct ieee80211_mmie_16 *mmie16;
983 
984 	if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
985 		return -1;
986 
987 	if (!ieee80211_is_robust_mgmt_frame(skb) &&
988 	    !ieee80211_is_beacon(hdr->frame_control))
989 		return -1; /* not a robust management frame */
990 
991 	mmie = (struct ieee80211_mmie *)
992 		(skb->data + skb->len - sizeof(*mmie));
993 	if (mmie->element_id == WLAN_EID_MMIE &&
994 	    mmie->length == sizeof(*mmie) - 2)
995 		return le16_to_cpu(mmie->key_id);
996 
997 	mmie16 = (struct ieee80211_mmie_16 *)
998 		(skb->data + skb->len - sizeof(*mmie16));
999 	if (skb->len >= 24 + sizeof(*mmie16) &&
1000 	    mmie16->element_id == WLAN_EID_MMIE &&
1001 	    mmie16->length == sizeof(*mmie16) - 2)
1002 		return le16_to_cpu(mmie16->key_id);
1003 
1004 	return -1;
1005 }
1006 
1007 static int ieee80211_get_keyid(struct sk_buff *skb,
1008 			       const struct ieee80211_cipher_scheme *cs)
1009 {
1010 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1011 	__le16 fc;
1012 	int hdrlen;
1013 	int minlen;
1014 	u8 key_idx_off;
1015 	u8 key_idx_shift;
1016 	u8 keyid;
1017 
1018 	fc = hdr->frame_control;
1019 	hdrlen = ieee80211_hdrlen(fc);
1020 
1021 	if (cs) {
1022 		minlen = hdrlen + cs->hdr_len;
1023 		key_idx_off = hdrlen + cs->key_idx_off;
1024 		key_idx_shift = cs->key_idx_shift;
1025 	} else {
1026 		/* WEP, TKIP, CCMP and GCMP */
1027 		minlen = hdrlen + IEEE80211_WEP_IV_LEN;
1028 		key_idx_off = hdrlen + 3;
1029 		key_idx_shift = 6;
1030 	}
1031 
1032 	if (unlikely(skb->len < minlen))
1033 		return -EINVAL;
1034 
1035 	skb_copy_bits(skb, key_idx_off, &keyid, 1);
1036 
1037 	if (cs)
1038 		keyid &= cs->key_idx_mask;
1039 	keyid >>= key_idx_shift;
1040 
1041 	/* cs could use more than the usual two bits for the keyid */
1042 	if (unlikely(keyid >= NUM_DEFAULT_KEYS))
1043 		return -EINVAL;
1044 
1045 	return keyid;
1046 }
1047 
1048 static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
1049 {
1050 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1051 	char *dev_addr = rx->sdata->vif.addr;
1052 
1053 	if (ieee80211_is_data(hdr->frame_control)) {
1054 		if (is_multicast_ether_addr(hdr->addr1)) {
1055 			if (ieee80211_has_tods(hdr->frame_control) ||
1056 			    !ieee80211_has_fromds(hdr->frame_control))
1057 				return RX_DROP_MONITOR;
1058 			if (ether_addr_equal(hdr->addr3, dev_addr))
1059 				return RX_DROP_MONITOR;
1060 		} else {
1061 			if (!ieee80211_has_a4(hdr->frame_control))
1062 				return RX_DROP_MONITOR;
1063 			if (ether_addr_equal(hdr->addr4, dev_addr))
1064 				return RX_DROP_MONITOR;
1065 		}
1066 	}
1067 
1068 	/* If there is not an established peer link and this is not a peer link
1069 	 * establisment frame, beacon or probe, drop the frame.
1070 	 */
1071 
1072 	if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
1073 		struct ieee80211_mgmt *mgmt;
1074 
1075 		if (!ieee80211_is_mgmt(hdr->frame_control))
1076 			return RX_DROP_MONITOR;
1077 
1078 		if (ieee80211_is_action(hdr->frame_control)) {
1079 			u8 category;
1080 
1081 			/* make sure category field is present */
1082 			if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
1083 				return RX_DROP_MONITOR;
1084 
1085 			mgmt = (struct ieee80211_mgmt *)hdr;
1086 			category = mgmt->u.action.category;
1087 			if (category != WLAN_CATEGORY_MESH_ACTION &&
1088 			    category != WLAN_CATEGORY_SELF_PROTECTED)
1089 				return RX_DROP_MONITOR;
1090 			return RX_CONTINUE;
1091 		}
1092 
1093 		if (ieee80211_is_probe_req(hdr->frame_control) ||
1094 		    ieee80211_is_probe_resp(hdr->frame_control) ||
1095 		    ieee80211_is_beacon(hdr->frame_control) ||
1096 		    ieee80211_is_auth(hdr->frame_control))
1097 			return RX_CONTINUE;
1098 
1099 		return RX_DROP_MONITOR;
1100 	}
1101 
1102 	return RX_CONTINUE;
1103 }
1104 
1105 static inline bool ieee80211_rx_reorder_ready(struct tid_ampdu_rx *tid_agg_rx,
1106 					      int index)
1107 {
1108 	struct sk_buff_head *frames = &tid_agg_rx->reorder_buf[index];
1109 	struct sk_buff *tail = skb_peek_tail(frames);
1110 	struct ieee80211_rx_status *status;
1111 
1112 	if (tid_agg_rx->reorder_buf_filtered & BIT_ULL(index))
1113 		return true;
1114 
1115 	if (!tail)
1116 		return false;
1117 
1118 	status = IEEE80211_SKB_RXCB(tail);
1119 	if (status->flag & RX_FLAG_AMSDU_MORE)
1120 		return false;
1121 
1122 	return true;
1123 }
1124 
1125 static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
1126 					    struct tid_ampdu_rx *tid_agg_rx,
1127 					    int index,
1128 					    struct sk_buff_head *frames)
1129 {
1130 	struct sk_buff_head *skb_list = &tid_agg_rx->reorder_buf[index];
1131 	struct sk_buff *skb;
1132 	struct ieee80211_rx_status *status;
1133 
1134 	lockdep_assert_held(&tid_agg_rx->reorder_lock);
1135 
1136 	if (skb_queue_empty(skb_list))
1137 		goto no_frame;
1138 
1139 	if (!ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1140 		__skb_queue_purge(skb_list);
1141 		goto no_frame;
1142 	}
1143 
1144 	/* release frames from the reorder ring buffer */
1145 	tid_agg_rx->stored_mpdu_num--;
1146 	while ((skb = __skb_dequeue(skb_list))) {
1147 		status = IEEE80211_SKB_RXCB(skb);
1148 		status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
1149 		__skb_queue_tail(frames, skb);
1150 	}
1151 
1152 no_frame:
1153 	tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
1154 	tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1155 }
1156 
1157 static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
1158 					     struct tid_ampdu_rx *tid_agg_rx,
1159 					     u16 head_seq_num,
1160 					     struct sk_buff_head *frames)
1161 {
1162 	int index;
1163 
1164 	lockdep_assert_held(&tid_agg_rx->reorder_lock);
1165 
1166 	while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
1167 		index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1168 		ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1169 						frames);
1170 	}
1171 }
1172 
1173 /*
1174  * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
1175  * the skb was added to the buffer longer than this time ago, the earlier
1176  * frames that have not yet been received are assumed to be lost and the skb
1177  * can be released for processing. This may also release other skb's from the
1178  * reorder buffer if there are no additional gaps between the frames.
1179  *
1180  * Callers must hold tid_agg_rx->reorder_lock.
1181  */
1182 #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
1183 
1184 static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
1185 					  struct tid_ampdu_rx *tid_agg_rx,
1186 					  struct sk_buff_head *frames)
1187 {
1188 	int index, i, j;
1189 
1190 	lockdep_assert_held(&tid_agg_rx->reorder_lock);
1191 
1192 	/* release the buffer until next missing frame */
1193 	index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1194 	if (!ieee80211_rx_reorder_ready(tid_agg_rx, index) &&
1195 	    tid_agg_rx->stored_mpdu_num) {
1196 		/*
1197 		 * No buffers ready to be released, but check whether any
1198 		 * frames in the reorder buffer have timed out.
1199 		 */
1200 		int skipped = 1;
1201 		for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
1202 		     j = (j + 1) % tid_agg_rx->buf_size) {
1203 			if (!ieee80211_rx_reorder_ready(tid_agg_rx, j)) {
1204 				skipped++;
1205 				continue;
1206 			}
1207 			if (skipped &&
1208 			    !time_after(jiffies, tid_agg_rx->reorder_time[j] +
1209 					HT_RX_REORDER_BUF_TIMEOUT))
1210 				goto set_release_timer;
1211 
1212 			/* don't leave incomplete A-MSDUs around */
1213 			for (i = (index + 1) % tid_agg_rx->buf_size; i != j;
1214 			     i = (i + 1) % tid_agg_rx->buf_size)
1215 				__skb_queue_purge(&tid_agg_rx->reorder_buf[i]);
1216 
1217 			ht_dbg_ratelimited(sdata,
1218 					   "release an RX reorder frame due to timeout on earlier frames\n");
1219 			ieee80211_release_reorder_frame(sdata, tid_agg_rx, j,
1220 							frames);
1221 
1222 			/*
1223 			 * Increment the head seq# also for the skipped slots.
1224 			 */
1225 			tid_agg_rx->head_seq_num =
1226 				(tid_agg_rx->head_seq_num +
1227 				 skipped) & IEEE80211_SN_MASK;
1228 			skipped = 0;
1229 		}
1230 	} else while (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1231 		ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
1232 						frames);
1233 		index =	tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1234 	}
1235 
1236 	if (tid_agg_rx->stored_mpdu_num) {
1237 		j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
1238 
1239 		for (; j != (index - 1) % tid_agg_rx->buf_size;
1240 		     j = (j + 1) % tid_agg_rx->buf_size) {
1241 			if (ieee80211_rx_reorder_ready(tid_agg_rx, j))
1242 				break;
1243 		}
1244 
1245  set_release_timer:
1246 
1247 		if (!tid_agg_rx->removed)
1248 			mod_timer(&tid_agg_rx->reorder_timer,
1249 				  tid_agg_rx->reorder_time[j] + 1 +
1250 				  HT_RX_REORDER_BUF_TIMEOUT);
1251 	} else {
1252 		del_timer(&tid_agg_rx->reorder_timer);
1253 	}
1254 }
1255 
1256 /*
1257  * As this function belongs to the RX path it must be under
1258  * rcu_read_lock protection. It returns false if the frame
1259  * can be processed immediately, true if it was consumed.
1260  */
1261 static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
1262 					     struct tid_ampdu_rx *tid_agg_rx,
1263 					     struct sk_buff *skb,
1264 					     struct sk_buff_head *frames)
1265 {
1266 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1267 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1268 	u16 sc = le16_to_cpu(hdr->seq_ctrl);
1269 	u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
1270 	u16 head_seq_num, buf_size;
1271 	int index;
1272 	bool ret = true;
1273 
1274 	spin_lock(&tid_agg_rx->reorder_lock);
1275 
1276 	/*
1277 	 * Offloaded BA sessions have no known starting sequence number so pick
1278 	 * one from first Rxed frame for this tid after BA was started.
1279 	 */
1280 	if (unlikely(tid_agg_rx->auto_seq)) {
1281 		tid_agg_rx->auto_seq = false;
1282 		tid_agg_rx->ssn = mpdu_seq_num;
1283 		tid_agg_rx->head_seq_num = mpdu_seq_num;
1284 	}
1285 
1286 	buf_size = tid_agg_rx->buf_size;
1287 	head_seq_num = tid_agg_rx->head_seq_num;
1288 
1289 	/*
1290 	 * If the current MPDU's SN is smaller than the SSN, it shouldn't
1291 	 * be reordered.
1292 	 */
1293 	if (unlikely(!tid_agg_rx->started)) {
1294 		if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1295 			ret = false;
1296 			goto out;
1297 		}
1298 		tid_agg_rx->started = true;
1299 	}
1300 
1301 	/* frame with out of date sequence number */
1302 	if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
1303 		dev_kfree_skb(skb);
1304 		goto out;
1305 	}
1306 
1307 	/*
1308 	 * If frame the sequence number exceeds our buffering window
1309 	 * size release some previous frames to make room for this one.
1310 	 */
1311 	if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
1312 		head_seq_num = ieee80211_sn_inc(
1313 				ieee80211_sn_sub(mpdu_seq_num, buf_size));
1314 		/* release stored frames up to new head to stack */
1315 		ieee80211_release_reorder_frames(sdata, tid_agg_rx,
1316 						 head_seq_num, frames);
1317 	}
1318 
1319 	/* Now the new frame is always in the range of the reordering buffer */
1320 
1321 	index = mpdu_seq_num % tid_agg_rx->buf_size;
1322 
1323 	/* check if we already stored this frame */
1324 	if (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
1325 		dev_kfree_skb(skb);
1326 		goto out;
1327 	}
1328 
1329 	/*
1330 	 * If the current MPDU is in the right order and nothing else
1331 	 * is stored we can process it directly, no need to buffer it.
1332 	 * If it is first but there's something stored, we may be able
1333 	 * to release frames after this one.
1334 	 */
1335 	if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
1336 	    tid_agg_rx->stored_mpdu_num == 0) {
1337 		if (!(status->flag & RX_FLAG_AMSDU_MORE))
1338 			tid_agg_rx->head_seq_num =
1339 				ieee80211_sn_inc(tid_agg_rx->head_seq_num);
1340 		ret = false;
1341 		goto out;
1342 	}
1343 
1344 	/* put the frame in the reordering buffer */
1345 	__skb_queue_tail(&tid_agg_rx->reorder_buf[index], skb);
1346 	if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1347 		tid_agg_rx->reorder_time[index] = jiffies;
1348 		tid_agg_rx->stored_mpdu_num++;
1349 		ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames);
1350 	}
1351 
1352  out:
1353 	spin_unlock(&tid_agg_rx->reorder_lock);
1354 	return ret;
1355 }
1356 
1357 /*
1358  * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
1359  * true if the MPDU was buffered, false if it should be processed.
1360  */
1361 static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
1362 				       struct sk_buff_head *frames)
1363 {
1364 	struct sk_buff *skb = rx->skb;
1365 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1366 	struct sta_info *sta = rx->sta;
1367 	struct tid_ampdu_rx *tid_agg_rx;
1368 	u16 sc;
1369 	u8 tid, ack_policy;
1370 
1371 	if (!ieee80211_is_data_qos(hdr->frame_control) ||
1372 	    is_multicast_ether_addr(hdr->addr1))
1373 		goto dont_reorder;
1374 
1375 	/*
1376 	 * filter the QoS data rx stream according to
1377 	 * STA/TID and check if this STA/TID is on aggregation
1378 	 */
1379 
1380 	if (!sta)
1381 		goto dont_reorder;
1382 
1383 	ack_policy = *ieee80211_get_qos_ctl(hdr) &
1384 		     IEEE80211_QOS_CTL_ACK_POLICY_MASK;
1385 	tid = ieee80211_get_tid(hdr);
1386 
1387 	tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
1388 	if (!tid_agg_rx) {
1389 		if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
1390 		    !test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
1391 		    !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
1392 			ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
1393 					     WLAN_BACK_RECIPIENT,
1394 					     WLAN_REASON_QSTA_REQUIRE_SETUP);
1395 		goto dont_reorder;
1396 	}
1397 
1398 	/* qos null data frames are excluded */
1399 	if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
1400 		goto dont_reorder;
1401 
1402 	/* not part of a BA session */
1403 	if (ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
1404 	    ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_NORMAL)
1405 		goto dont_reorder;
1406 
1407 	/* new, potentially un-ordered, ampdu frame - process it */
1408 
1409 	/* reset session timer */
1410 	if (tid_agg_rx->timeout)
1411 		tid_agg_rx->last_rx = jiffies;
1412 
1413 	/* if this mpdu is fragmented - terminate rx aggregation session */
1414 	sc = le16_to_cpu(hdr->seq_ctrl);
1415 	if (sc & IEEE80211_SCTL_FRAG) {
1416 		ieee80211_queue_skb_to_iface(rx->sdata, NULL, skb);
1417 		return;
1418 	}
1419 
1420 	/*
1421 	 * No locking needed -- we will only ever process one
1422 	 * RX packet at a time, and thus own tid_agg_rx. All
1423 	 * other code manipulating it needs to (and does) make
1424 	 * sure that we cannot get to it any more before doing
1425 	 * anything with it.
1426 	 */
1427 	if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
1428 					     frames))
1429 		return;
1430 
1431  dont_reorder:
1432 	__skb_queue_tail(frames, skb);
1433 }
1434 
1435 static ieee80211_rx_result debug_noinline
1436 ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx)
1437 {
1438 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1439 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1440 
1441 	if (status->flag & RX_FLAG_DUP_VALIDATED)
1442 		return RX_CONTINUE;
1443 
1444 	/*
1445 	 * Drop duplicate 802.11 retransmissions
1446 	 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
1447 	 */
1448 
1449 	if (rx->skb->len < 24)
1450 		return RX_CONTINUE;
1451 
1452 	if (ieee80211_is_ctl(hdr->frame_control) ||
1453 	    ieee80211_is_any_nullfunc(hdr->frame_control) ||
1454 	    is_multicast_ether_addr(hdr->addr1))
1455 		return RX_CONTINUE;
1456 
1457 	if (!rx->sta)
1458 		return RX_CONTINUE;
1459 
1460 	if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
1461 		     rx->sta->last_seq_ctrl[rx->seqno_idx] == hdr->seq_ctrl)) {
1462 		I802_DEBUG_INC(rx->local->dot11FrameDuplicateCount);
1463 		rx->sta->rx_stats.num_duplicates++;
1464 		return RX_DROP_UNUSABLE;
1465 	} else if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
1466 		rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
1467 	}
1468 
1469 	return RX_CONTINUE;
1470 }
1471 
1472 static ieee80211_rx_result debug_noinline
1473 ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
1474 {
1475 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
1476 
1477 	/* Drop disallowed frame classes based on STA auth/assoc state;
1478 	 * IEEE 802.11, Chap 5.5.
1479 	 *
1480 	 * mac80211 filters only based on association state, i.e. it drops
1481 	 * Class 3 frames from not associated stations. hostapd sends
1482 	 * deauth/disassoc frames when needed. In addition, hostapd is
1483 	 * responsible for filtering on both auth and assoc states.
1484 	 */
1485 
1486 	if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1487 		return ieee80211_rx_mesh_check(rx);
1488 
1489 	if (unlikely((ieee80211_is_data(hdr->frame_control) ||
1490 		      ieee80211_is_pspoll(hdr->frame_control)) &&
1491 		     rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1492 		     rx->sdata->vif.type != NL80211_IFTYPE_OCB &&
1493 		     (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
1494 		/*
1495 		 * accept port control frames from the AP even when it's not
1496 		 * yet marked ASSOC to prevent a race where we don't set the
1497 		 * assoc bit quickly enough before it sends the first frame
1498 		 */
1499 		if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
1500 		    ieee80211_is_data_present(hdr->frame_control)) {
1501 			unsigned int hdrlen;
1502 			__be16 ethertype;
1503 
1504 			hdrlen = ieee80211_hdrlen(hdr->frame_control);
1505 
1506 			if (rx->skb->len < hdrlen + 8)
1507 				return RX_DROP_MONITOR;
1508 
1509 			skb_copy_bits(rx->skb, hdrlen + 6, &ethertype, 2);
1510 			if (ethertype == rx->sdata->control_port_protocol)
1511 				return RX_CONTINUE;
1512 		}
1513 
1514 		if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
1515 		    cfg80211_rx_spurious_frame(rx->sdata->dev,
1516 					       hdr->addr2,
1517 					       GFP_ATOMIC))
1518 			return RX_DROP_UNUSABLE;
1519 
1520 		return RX_DROP_MONITOR;
1521 	}
1522 
1523 	return RX_CONTINUE;
1524 }
1525 
1526 
1527 static ieee80211_rx_result debug_noinline
1528 ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
1529 {
1530 	struct ieee80211_local *local;
1531 	struct ieee80211_hdr *hdr;
1532 	struct sk_buff *skb;
1533 
1534 	local = rx->local;
1535 	skb = rx->skb;
1536 	hdr = (struct ieee80211_hdr *) skb->data;
1537 
1538 	if (!local->pspolling)
1539 		return RX_CONTINUE;
1540 
1541 	if (!ieee80211_has_fromds(hdr->frame_control))
1542 		/* this is not from AP */
1543 		return RX_CONTINUE;
1544 
1545 	if (!ieee80211_is_data(hdr->frame_control))
1546 		return RX_CONTINUE;
1547 
1548 	if (!ieee80211_has_moredata(hdr->frame_control)) {
1549 		/* AP has no more frames buffered for us */
1550 		local->pspolling = false;
1551 		return RX_CONTINUE;
1552 	}
1553 
1554 	/* more data bit is set, let's request a new frame from the AP */
1555 	ieee80211_send_pspoll(local, rx->sdata);
1556 
1557 	return RX_CONTINUE;
1558 }
1559 
1560 static void sta_ps_start(struct sta_info *sta)
1561 {
1562 	struct ieee80211_sub_if_data *sdata = sta->sdata;
1563 	struct ieee80211_local *local = sdata->local;
1564 	struct ps_data *ps;
1565 	int tid;
1566 
1567 	if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1568 	    sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1569 		ps = &sdata->bss->ps;
1570 	else
1571 		return;
1572 
1573 	atomic_inc(&ps->num_sta_ps);
1574 	set_sta_flag(sta, WLAN_STA_PS_STA);
1575 	if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
1576 		drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
1577 	ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
1578 	       sta->sta.addr, sta->sta.aid);
1579 
1580 	ieee80211_clear_fast_xmit(sta);
1581 
1582 	if (!sta->sta.txq[0])
1583 		return;
1584 
1585 	for (tid = 0; tid < IEEE80211_NUM_TIDS; tid++) {
1586 		struct ieee80211_txq *txq = sta->sta.txq[tid];
1587 
1588 		ieee80211_unschedule_txq(&local->hw, txq, false);
1589 
1590 		if (txq_has_queue(txq))
1591 			set_bit(tid, &sta->txq_buffered_tids);
1592 		else
1593 			clear_bit(tid, &sta->txq_buffered_tids);
1594 	}
1595 }
1596 
1597 static void sta_ps_end(struct sta_info *sta)
1598 {
1599 	ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
1600 	       sta->sta.addr, sta->sta.aid);
1601 
1602 	if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
1603 		/*
1604 		 * Clear the flag only if the other one is still set
1605 		 * so that the TX path won't start TX'ing new frames
1606 		 * directly ... In the case that the driver flag isn't
1607 		 * set ieee80211_sta_ps_deliver_wakeup() will clear it.
1608 		 */
1609 		clear_sta_flag(sta, WLAN_STA_PS_STA);
1610 		ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
1611 		       sta->sta.addr, sta->sta.aid);
1612 		return;
1613 	}
1614 
1615 	set_sta_flag(sta, WLAN_STA_PS_DELIVER);
1616 	clear_sta_flag(sta, WLAN_STA_PS_STA);
1617 	ieee80211_sta_ps_deliver_wakeup(sta);
1618 }
1619 
1620 int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start)
1621 {
1622 	struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1623 	bool in_ps;
1624 
1625 	WARN_ON(!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS));
1626 
1627 	/* Don't let the same PS state be set twice */
1628 	in_ps = test_sta_flag(sta, WLAN_STA_PS_STA);
1629 	if ((start && in_ps) || (!start && !in_ps))
1630 		return -EINVAL;
1631 
1632 	if (start)
1633 		sta_ps_start(sta);
1634 	else
1635 		sta_ps_end(sta);
1636 
1637 	return 0;
1638 }
1639 EXPORT_SYMBOL(ieee80211_sta_ps_transition);
1640 
1641 void ieee80211_sta_pspoll(struct ieee80211_sta *pubsta)
1642 {
1643 	struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1644 
1645 	if (test_sta_flag(sta, WLAN_STA_SP))
1646 		return;
1647 
1648 	if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1649 		ieee80211_sta_ps_deliver_poll_response(sta);
1650 	else
1651 		set_sta_flag(sta, WLAN_STA_PSPOLL);
1652 }
1653 EXPORT_SYMBOL(ieee80211_sta_pspoll);
1654 
1655 void ieee80211_sta_uapsd_trigger(struct ieee80211_sta *pubsta, u8 tid)
1656 {
1657 	struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1658 	int ac = ieee80211_ac_from_tid(tid);
1659 
1660 	/*
1661 	 * If this AC is not trigger-enabled do nothing unless the
1662 	 * driver is calling us after it already checked.
1663 	 *
1664 	 * NB: This could/should check a separate bitmap of trigger-
1665 	 * enabled queues, but for now we only implement uAPSD w/o
1666 	 * TSPEC changes to the ACs, so they're always the same.
1667 	 */
1668 	if (!(sta->sta.uapsd_queues & ieee80211_ac_to_qos_mask[ac]) &&
1669 	    tid != IEEE80211_NUM_TIDS)
1670 		return;
1671 
1672 	/* if we are in a service period, do nothing */
1673 	if (test_sta_flag(sta, WLAN_STA_SP))
1674 		return;
1675 
1676 	if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1677 		ieee80211_sta_ps_deliver_uapsd(sta);
1678 	else
1679 		set_sta_flag(sta, WLAN_STA_UAPSD);
1680 }
1681 EXPORT_SYMBOL(ieee80211_sta_uapsd_trigger);
1682 
1683 static ieee80211_rx_result debug_noinline
1684 ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
1685 {
1686 	struct ieee80211_sub_if_data *sdata = rx->sdata;
1687 	struct ieee80211_hdr *hdr = (void *)rx->skb->data;
1688 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
1689 
1690 	if (!rx->sta)
1691 		return RX_CONTINUE;
1692 
1693 	if (sdata->vif.type != NL80211_IFTYPE_AP &&
1694 	    sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
1695 		return RX_CONTINUE;
1696 
1697 	/*
1698 	 * The device handles station powersave, so don't do anything about
1699 	 * uAPSD and PS-Poll frames (the latter shouldn't even come up from
1700 	 * it to mac80211 since they're handled.)
1701 	 */
1702 	if (ieee80211_hw_check(&sdata->local->hw, AP_LINK_PS))
1703 		return RX_CONTINUE;
1704 
1705 	/*
1706 	 * Don't do anything if the station isn't already asleep. In
1707 	 * the uAPSD case, the station will probably be marked asleep,
1708 	 * in the PS-Poll case the station must be confused ...
1709 	 */
1710 	if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
1711 		return RX_CONTINUE;
1712 
1713 	if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
1714 		ieee80211_sta_pspoll(&rx->sta->sta);
1715 
1716 		/* Free PS Poll skb here instead of returning RX_DROP that would
1717 		 * count as an dropped frame. */
1718 		dev_kfree_skb(rx->skb);
1719 
1720 		return RX_QUEUED;
1721 	} else if (!ieee80211_has_morefrags(hdr->frame_control) &&
1722 		   !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1723 		   ieee80211_has_pm(hdr->frame_control) &&
1724 		   (ieee80211_is_data_qos(hdr->frame_control) ||
1725 		    ieee80211_is_qos_nullfunc(hdr->frame_control))) {
1726 		u8 tid = ieee80211_get_tid(hdr);
1727 
1728 		ieee80211_sta_uapsd_trigger(&rx->sta->sta, tid);
1729 	}
1730 
1731 	return RX_CONTINUE;
1732 }
1733 
1734 static ieee80211_rx_result debug_noinline
1735 ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
1736 {
1737 	struct sta_info *sta = rx->sta;
1738 	struct sk_buff *skb = rx->skb;
1739 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1740 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1741 	int i;
1742 
1743 	if (!sta)
1744 		return RX_CONTINUE;
1745 
1746 	/*
1747 	 * Update last_rx only for IBSS packets which are for the current
1748 	 * BSSID and for station already AUTHORIZED to avoid keeping the
1749 	 * current IBSS network alive in cases where other STAs start
1750 	 * using different BSSID. This will also give the station another
1751 	 * chance to restart the authentication/authorization in case
1752 	 * something went wrong the first time.
1753 	 */
1754 	if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1755 		u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
1756 						NL80211_IFTYPE_ADHOC);
1757 		if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
1758 		    test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
1759 			sta->rx_stats.last_rx = jiffies;
1760 			if (ieee80211_is_data(hdr->frame_control) &&
1761 			    !is_multicast_ether_addr(hdr->addr1))
1762 				sta->rx_stats.last_rate =
1763 					sta_stats_encode_rate(status);
1764 		}
1765 	} else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) {
1766 		sta->rx_stats.last_rx = jiffies;
1767 	} else if (!ieee80211_is_s1g_beacon(hdr->frame_control) &&
1768 		   !is_multicast_ether_addr(hdr->addr1)) {
1769 		/*
1770 		 * Mesh beacons will update last_rx when if they are found to
1771 		 * match the current local configuration when processed.
1772 		 */
1773 		sta->rx_stats.last_rx = jiffies;
1774 		if (ieee80211_is_data(hdr->frame_control))
1775 			sta->rx_stats.last_rate = sta_stats_encode_rate(status);
1776 	}
1777 
1778 	sta->rx_stats.fragments++;
1779 
1780 	u64_stats_update_begin(&rx->sta->rx_stats.syncp);
1781 	sta->rx_stats.bytes += rx->skb->len;
1782 	u64_stats_update_end(&rx->sta->rx_stats.syncp);
1783 
1784 	if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
1785 		sta->rx_stats.last_signal = status->signal;
1786 		ewma_signal_add(&sta->rx_stats_avg.signal, -status->signal);
1787 	}
1788 
1789 	if (status->chains) {
1790 		sta->rx_stats.chains = status->chains;
1791 		for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
1792 			int signal = status->chain_signal[i];
1793 
1794 			if (!(status->chains & BIT(i)))
1795 				continue;
1796 
1797 			sta->rx_stats.chain_signal_last[i] = signal;
1798 			ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
1799 					-signal);
1800 		}
1801 	}
1802 
1803 	if (ieee80211_is_s1g_beacon(hdr->frame_control))
1804 		return RX_CONTINUE;
1805 
1806 	/*
1807 	 * Change STA power saving mode only at the end of a frame
1808 	 * exchange sequence, and only for a data or management
1809 	 * frame as specified in IEEE 802.11-2016 11.2.3.2
1810 	 */
1811 	if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) &&
1812 	    !ieee80211_has_morefrags(hdr->frame_control) &&
1813 	    !is_multicast_ether_addr(hdr->addr1) &&
1814 	    (ieee80211_is_mgmt(hdr->frame_control) ||
1815 	     ieee80211_is_data(hdr->frame_control)) &&
1816 	    !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1817 	    (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1818 	     rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
1819 		if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
1820 			if (!ieee80211_has_pm(hdr->frame_control))
1821 				sta_ps_end(sta);
1822 		} else {
1823 			if (ieee80211_has_pm(hdr->frame_control))
1824 				sta_ps_start(sta);
1825 		}
1826 	}
1827 
1828 	/* mesh power save support */
1829 	if (ieee80211_vif_is_mesh(&rx->sdata->vif))
1830 		ieee80211_mps_rx_h_sta_process(sta, hdr);
1831 
1832 	/*
1833 	 * Drop (qos-)data::nullfunc frames silently, since they
1834 	 * are used only to control station power saving mode.
1835 	 */
1836 	if (ieee80211_is_any_nullfunc(hdr->frame_control)) {
1837 		I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
1838 
1839 		/*
1840 		 * If we receive a 4-addr nullfunc frame from a STA
1841 		 * that was not moved to a 4-addr STA vlan yet send
1842 		 * the event to userspace and for older hostapd drop
1843 		 * the frame to the monitor interface.
1844 		 */
1845 		if (ieee80211_has_a4(hdr->frame_control) &&
1846 		    (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1847 		     (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1848 		      !rx->sdata->u.vlan.sta))) {
1849 			if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
1850 				cfg80211_rx_unexpected_4addr_frame(
1851 					rx->sdata->dev, sta->sta.addr,
1852 					GFP_ATOMIC);
1853 			return RX_DROP_MONITOR;
1854 		}
1855 		/*
1856 		 * Update counter and free packet here to avoid
1857 		 * counting this as a dropped packed.
1858 		 */
1859 		sta->rx_stats.packets++;
1860 		dev_kfree_skb(rx->skb);
1861 		return RX_QUEUED;
1862 	}
1863 
1864 	return RX_CONTINUE;
1865 } /* ieee80211_rx_h_sta_process */
1866 
1867 static struct ieee80211_key *
1868 ieee80211_rx_get_bigtk(struct ieee80211_rx_data *rx, int idx)
1869 {
1870 	struct ieee80211_key *key = NULL;
1871 	struct ieee80211_sub_if_data *sdata = rx->sdata;
1872 	int idx2;
1873 
1874 	/* Make sure key gets set if either BIGTK key index is set so that
1875 	 * ieee80211_drop_unencrypted_mgmt() can properly drop both unprotected
1876 	 * Beacon frames and Beacon frames that claim to use another BIGTK key
1877 	 * index (i.e., a key that we do not have).
1878 	 */
1879 
1880 	if (idx < 0) {
1881 		idx = NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
1882 		idx2 = idx + 1;
1883 	} else {
1884 		if (idx == NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
1885 			idx2 = idx + 1;
1886 		else
1887 			idx2 = idx - 1;
1888 	}
1889 
1890 	if (rx->sta)
1891 		key = rcu_dereference(rx->sta->gtk[idx]);
1892 	if (!key)
1893 		key = rcu_dereference(sdata->keys[idx]);
1894 	if (!key && rx->sta)
1895 		key = rcu_dereference(rx->sta->gtk[idx2]);
1896 	if (!key)
1897 		key = rcu_dereference(sdata->keys[idx2]);
1898 
1899 	return key;
1900 }
1901 
1902 static ieee80211_rx_result debug_noinline
1903 ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
1904 {
1905 	struct sk_buff *skb = rx->skb;
1906 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
1907 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1908 	int keyidx;
1909 	ieee80211_rx_result result = RX_DROP_UNUSABLE;
1910 	struct ieee80211_key *sta_ptk = NULL;
1911 	struct ieee80211_key *ptk_idx = NULL;
1912 	int mmie_keyidx = -1;
1913 	__le16 fc;
1914 	const struct ieee80211_cipher_scheme *cs = NULL;
1915 
1916 	if (ieee80211_is_ext(hdr->frame_control))
1917 		return RX_CONTINUE;
1918 
1919 	/*
1920 	 * Key selection 101
1921 	 *
1922 	 * There are five types of keys:
1923 	 *  - GTK (group keys)
1924 	 *  - IGTK (group keys for management frames)
1925 	 *  - BIGTK (group keys for Beacon frames)
1926 	 *  - PTK (pairwise keys)
1927 	 *  - STK (station-to-station pairwise keys)
1928 	 *
1929 	 * When selecting a key, we have to distinguish between multicast
1930 	 * (including broadcast) and unicast frames, the latter can only
1931 	 * use PTKs and STKs while the former always use GTKs, IGTKs, and
1932 	 * BIGTKs. Unless, of course, actual WEP keys ("pre-RSNA") are used,
1933 	 * then unicast frames can also use key indices like GTKs. Hence, if we
1934 	 * don't have a PTK/STK we check the key index for a WEP key.
1935 	 *
1936 	 * Note that in a regular BSS, multicast frames are sent by the
1937 	 * AP only, associated stations unicast the frame to the AP first
1938 	 * which then multicasts it on their behalf.
1939 	 *
1940 	 * There is also a slight problem in IBSS mode: GTKs are negotiated
1941 	 * with each station, that is something we don't currently handle.
1942 	 * The spec seems to expect that one negotiates the same key with
1943 	 * every station but there's no such requirement; VLANs could be
1944 	 * possible.
1945 	 */
1946 
1947 	/* start without a key */
1948 	rx->key = NULL;
1949 	fc = hdr->frame_control;
1950 
1951 	if (rx->sta) {
1952 		int keyid = rx->sta->ptk_idx;
1953 		sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
1954 
1955 		if (ieee80211_has_protected(fc)) {
1956 			cs = rx->sta->cipher_scheme;
1957 			keyid = ieee80211_get_keyid(rx->skb, cs);
1958 
1959 			if (unlikely(keyid < 0))
1960 				return RX_DROP_UNUSABLE;
1961 
1962 			ptk_idx = rcu_dereference(rx->sta->ptk[keyid]);
1963 		}
1964 	}
1965 
1966 	if (!ieee80211_has_protected(fc))
1967 		mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
1968 
1969 	if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
1970 		rx->key = ptk_idx ? ptk_idx : sta_ptk;
1971 		if ((status->flag & RX_FLAG_DECRYPTED) &&
1972 		    (status->flag & RX_FLAG_IV_STRIPPED))
1973 			return RX_CONTINUE;
1974 		/* Skip decryption if the frame is not protected. */
1975 		if (!ieee80211_has_protected(fc))
1976 			return RX_CONTINUE;
1977 	} else if (mmie_keyidx >= 0 && ieee80211_is_beacon(fc)) {
1978 		/* Broadcast/multicast robust management frame / BIP */
1979 		if ((status->flag & RX_FLAG_DECRYPTED) &&
1980 		    (status->flag & RX_FLAG_IV_STRIPPED))
1981 			return RX_CONTINUE;
1982 
1983 		if (mmie_keyidx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS ||
1984 		    mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS +
1985 		    NUM_DEFAULT_BEACON_KEYS) {
1986 			cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
1987 						     skb->data,
1988 						     skb->len);
1989 			return RX_DROP_MONITOR; /* unexpected BIP keyidx */
1990 		}
1991 
1992 		rx->key = ieee80211_rx_get_bigtk(rx, mmie_keyidx);
1993 		if (!rx->key)
1994 			return RX_CONTINUE; /* Beacon protection not in use */
1995 	} else if (mmie_keyidx >= 0) {
1996 		/* Broadcast/multicast robust management frame / BIP */
1997 		if ((status->flag & RX_FLAG_DECRYPTED) &&
1998 		    (status->flag & RX_FLAG_IV_STRIPPED))
1999 			return RX_CONTINUE;
2000 
2001 		if (mmie_keyidx < NUM_DEFAULT_KEYS ||
2002 		    mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
2003 			return RX_DROP_MONITOR; /* unexpected BIP keyidx */
2004 		if (rx->sta) {
2005 			if (ieee80211_is_group_privacy_action(skb) &&
2006 			    test_sta_flag(rx->sta, WLAN_STA_MFP))
2007 				return RX_DROP_MONITOR;
2008 
2009 			rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
2010 		}
2011 		if (!rx->key)
2012 			rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
2013 	} else if (!ieee80211_has_protected(fc)) {
2014 		/*
2015 		 * The frame was not protected, so skip decryption. However, we
2016 		 * need to set rx->key if there is a key that could have been
2017 		 * used so that the frame may be dropped if encryption would
2018 		 * have been expected.
2019 		 */
2020 		struct ieee80211_key *key = NULL;
2021 		struct ieee80211_sub_if_data *sdata = rx->sdata;
2022 		int i;
2023 
2024 		if (ieee80211_is_beacon(fc)) {
2025 			key = ieee80211_rx_get_bigtk(rx, -1);
2026 		} else if (ieee80211_is_mgmt(fc) &&
2027 			   is_multicast_ether_addr(hdr->addr1)) {
2028 			key = rcu_dereference(rx->sdata->default_mgmt_key);
2029 		} else {
2030 			if (rx->sta) {
2031 				for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
2032 					key = rcu_dereference(rx->sta->gtk[i]);
2033 					if (key)
2034 						break;
2035 				}
2036 			}
2037 			if (!key) {
2038 				for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
2039 					key = rcu_dereference(sdata->keys[i]);
2040 					if (key)
2041 						break;
2042 				}
2043 			}
2044 		}
2045 		if (key)
2046 			rx->key = key;
2047 		return RX_CONTINUE;
2048 	} else {
2049 		/*
2050 		 * The device doesn't give us the IV so we won't be
2051 		 * able to look up the key. That's ok though, we
2052 		 * don't need to decrypt the frame, we just won't
2053 		 * be able to keep statistics accurate.
2054 		 * Except for key threshold notifications, should
2055 		 * we somehow allow the driver to tell us which key
2056 		 * the hardware used if this flag is set?
2057 		 */
2058 		if ((status->flag & RX_FLAG_DECRYPTED) &&
2059 		    (status->flag & RX_FLAG_IV_STRIPPED))
2060 			return RX_CONTINUE;
2061 
2062 		keyidx = ieee80211_get_keyid(rx->skb, cs);
2063 
2064 		if (unlikely(keyidx < 0))
2065 			return RX_DROP_UNUSABLE;
2066 
2067 		/* check per-station GTK first, if multicast packet */
2068 		if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
2069 			rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
2070 
2071 		/* if not found, try default key */
2072 		if (!rx->key) {
2073 			rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
2074 
2075 			/*
2076 			 * RSNA-protected unicast frames should always be
2077 			 * sent with pairwise or station-to-station keys,
2078 			 * but for WEP we allow using a key index as well.
2079 			 */
2080 			if (rx->key &&
2081 			    rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
2082 			    rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
2083 			    !is_multicast_ether_addr(hdr->addr1))
2084 				rx->key = NULL;
2085 		}
2086 	}
2087 
2088 	if (rx->key) {
2089 		if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
2090 			return RX_DROP_MONITOR;
2091 
2092 		/* TODO: add threshold stuff again */
2093 	} else {
2094 		return RX_DROP_MONITOR;
2095 	}
2096 
2097 	switch (rx->key->conf.cipher) {
2098 	case WLAN_CIPHER_SUITE_WEP40:
2099 	case WLAN_CIPHER_SUITE_WEP104:
2100 		result = ieee80211_crypto_wep_decrypt(rx);
2101 		break;
2102 	case WLAN_CIPHER_SUITE_TKIP:
2103 		result = ieee80211_crypto_tkip_decrypt(rx);
2104 		break;
2105 	case WLAN_CIPHER_SUITE_CCMP:
2106 		result = ieee80211_crypto_ccmp_decrypt(
2107 			rx, IEEE80211_CCMP_MIC_LEN);
2108 		break;
2109 	case WLAN_CIPHER_SUITE_CCMP_256:
2110 		result = ieee80211_crypto_ccmp_decrypt(
2111 			rx, IEEE80211_CCMP_256_MIC_LEN);
2112 		break;
2113 	case WLAN_CIPHER_SUITE_AES_CMAC:
2114 		result = ieee80211_crypto_aes_cmac_decrypt(rx);
2115 		break;
2116 	case WLAN_CIPHER_SUITE_BIP_CMAC_256:
2117 		result = ieee80211_crypto_aes_cmac_256_decrypt(rx);
2118 		break;
2119 	case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2120 	case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2121 		result = ieee80211_crypto_aes_gmac_decrypt(rx);
2122 		break;
2123 	case WLAN_CIPHER_SUITE_GCMP:
2124 	case WLAN_CIPHER_SUITE_GCMP_256:
2125 		result = ieee80211_crypto_gcmp_decrypt(rx);
2126 		break;
2127 	default:
2128 		result = ieee80211_crypto_hw_decrypt(rx);
2129 	}
2130 
2131 	/* the hdr variable is invalid after the decrypt handlers */
2132 
2133 	/* either the frame has been decrypted or will be dropped */
2134 	status->flag |= RX_FLAG_DECRYPTED;
2135 
2136 	if (unlikely(ieee80211_is_beacon(fc) && result == RX_DROP_UNUSABLE))
2137 		cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2138 					     skb->data, skb->len);
2139 
2140 	return result;
2141 }
2142 
2143 void ieee80211_init_frag_cache(struct ieee80211_fragment_cache *cache)
2144 {
2145 	int i;
2146 
2147 	for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
2148 		skb_queue_head_init(&cache->entries[i].skb_list);
2149 }
2150 
2151 void ieee80211_destroy_frag_cache(struct ieee80211_fragment_cache *cache)
2152 {
2153 	int i;
2154 
2155 	for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
2156 		__skb_queue_purge(&cache->entries[i].skb_list);
2157 }
2158 
2159 static inline struct ieee80211_fragment_entry *
2160 ieee80211_reassemble_add(struct ieee80211_fragment_cache *cache,
2161 			 unsigned int frag, unsigned int seq, int rx_queue,
2162 			 struct sk_buff **skb)
2163 {
2164 	struct ieee80211_fragment_entry *entry;
2165 
2166 	entry = &cache->entries[cache->next++];
2167 	if (cache->next >= IEEE80211_FRAGMENT_MAX)
2168 		cache->next = 0;
2169 
2170 	__skb_queue_purge(&entry->skb_list);
2171 
2172 	__skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
2173 	*skb = NULL;
2174 	entry->first_frag_time = jiffies;
2175 	entry->seq = seq;
2176 	entry->rx_queue = rx_queue;
2177 	entry->last_frag = frag;
2178 	entry->check_sequential_pn = false;
2179 	entry->extra_len = 0;
2180 
2181 	return entry;
2182 }
2183 
2184 static inline struct ieee80211_fragment_entry *
2185 ieee80211_reassemble_find(struct ieee80211_fragment_cache *cache,
2186 			  unsigned int frag, unsigned int seq,
2187 			  int rx_queue, struct ieee80211_hdr *hdr)
2188 {
2189 	struct ieee80211_fragment_entry *entry;
2190 	int i, idx;
2191 
2192 	idx = cache->next;
2193 	for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
2194 		struct ieee80211_hdr *f_hdr;
2195 		struct sk_buff *f_skb;
2196 
2197 		idx--;
2198 		if (idx < 0)
2199 			idx = IEEE80211_FRAGMENT_MAX - 1;
2200 
2201 		entry = &cache->entries[idx];
2202 		if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
2203 		    entry->rx_queue != rx_queue ||
2204 		    entry->last_frag + 1 != frag)
2205 			continue;
2206 
2207 		f_skb = __skb_peek(&entry->skb_list);
2208 		f_hdr = (struct ieee80211_hdr *) f_skb->data;
2209 
2210 		/*
2211 		 * Check ftype and addresses are equal, else check next fragment
2212 		 */
2213 		if (((hdr->frame_control ^ f_hdr->frame_control) &
2214 		     cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
2215 		    !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
2216 		    !ether_addr_equal(hdr->addr2, f_hdr->addr2))
2217 			continue;
2218 
2219 		if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
2220 			__skb_queue_purge(&entry->skb_list);
2221 			continue;
2222 		}
2223 		return entry;
2224 	}
2225 
2226 	return NULL;
2227 }
2228 
2229 static bool requires_sequential_pn(struct ieee80211_rx_data *rx, __le16 fc)
2230 {
2231 	return rx->key &&
2232 		(rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP ||
2233 		 rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP_256 ||
2234 		 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP ||
2235 		 rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP_256) &&
2236 		ieee80211_has_protected(fc);
2237 }
2238 
2239 static ieee80211_rx_result debug_noinline
2240 ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
2241 {
2242 	struct ieee80211_fragment_cache *cache = &rx->sdata->frags;
2243 	struct ieee80211_hdr *hdr;
2244 	u16 sc;
2245 	__le16 fc;
2246 	unsigned int frag, seq;
2247 	struct ieee80211_fragment_entry *entry;
2248 	struct sk_buff *skb;
2249 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2250 
2251 	hdr = (struct ieee80211_hdr *)rx->skb->data;
2252 	fc = hdr->frame_control;
2253 
2254 	if (ieee80211_is_ctl(fc) || ieee80211_is_ext(fc))
2255 		return RX_CONTINUE;
2256 
2257 	sc = le16_to_cpu(hdr->seq_ctrl);
2258 	frag = sc & IEEE80211_SCTL_FRAG;
2259 
2260 	if (rx->sta)
2261 		cache = &rx->sta->frags;
2262 
2263 	if (likely(!ieee80211_has_morefrags(fc) && frag == 0))
2264 		goto out;
2265 
2266 	if (is_multicast_ether_addr(hdr->addr1))
2267 		return RX_DROP_MONITOR;
2268 
2269 	I802_DEBUG_INC(rx->local->rx_handlers_fragments);
2270 
2271 	if (skb_linearize(rx->skb))
2272 		return RX_DROP_UNUSABLE;
2273 
2274 	/*
2275 	 *  skb_linearize() might change the skb->data and
2276 	 *  previously cached variables (in this case, hdr) need to
2277 	 *  be refreshed with the new data.
2278 	 */
2279 	hdr = (struct ieee80211_hdr *)rx->skb->data;
2280 	seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
2281 
2282 	if (frag == 0) {
2283 		/* This is the first fragment of a new frame. */
2284 		entry = ieee80211_reassemble_add(cache, frag, seq,
2285 						 rx->seqno_idx, &(rx->skb));
2286 		if (requires_sequential_pn(rx, fc)) {
2287 			int queue = rx->security_idx;
2288 
2289 			/* Store CCMP/GCMP PN so that we can verify that the
2290 			 * next fragment has a sequential PN value.
2291 			 */
2292 			entry->check_sequential_pn = true;
2293 			entry->is_protected = true;
2294 			entry->key_color = rx->key->color;
2295 			memcpy(entry->last_pn,
2296 			       rx->key->u.ccmp.rx_pn[queue],
2297 			       IEEE80211_CCMP_PN_LEN);
2298 			BUILD_BUG_ON(offsetof(struct ieee80211_key,
2299 					      u.ccmp.rx_pn) !=
2300 				     offsetof(struct ieee80211_key,
2301 					      u.gcmp.rx_pn));
2302 			BUILD_BUG_ON(sizeof(rx->key->u.ccmp.rx_pn[queue]) !=
2303 				     sizeof(rx->key->u.gcmp.rx_pn[queue]));
2304 			BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN !=
2305 				     IEEE80211_GCMP_PN_LEN);
2306 		} else if (rx->key &&
2307 			   (ieee80211_has_protected(fc) ||
2308 			    (status->flag & RX_FLAG_DECRYPTED))) {
2309 			entry->is_protected = true;
2310 			entry->key_color = rx->key->color;
2311 		}
2312 		return RX_QUEUED;
2313 	}
2314 
2315 	/* This is a fragment for a frame that should already be pending in
2316 	 * fragment cache. Add this fragment to the end of the pending entry.
2317 	 */
2318 	entry = ieee80211_reassemble_find(cache, frag, seq,
2319 					  rx->seqno_idx, hdr);
2320 	if (!entry) {
2321 		I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2322 		return RX_DROP_MONITOR;
2323 	}
2324 
2325 	/* "The receiver shall discard MSDUs and MMPDUs whose constituent
2326 	 *  MPDU PN values are not incrementing in steps of 1."
2327 	 * see IEEE P802.11-REVmc/D5.0, 12.5.3.4.4, item d (for CCMP)
2328 	 * and IEEE P802.11-REVmc/D5.0, 12.5.5.4.4, item d (for GCMP)
2329 	 */
2330 	if (entry->check_sequential_pn) {
2331 		int i;
2332 		u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
2333 
2334 		if (!requires_sequential_pn(rx, fc))
2335 			return RX_DROP_UNUSABLE;
2336 
2337 		/* Prevent mixed key and fragment cache attacks */
2338 		if (entry->key_color != rx->key->color)
2339 			return RX_DROP_UNUSABLE;
2340 
2341 		memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
2342 		for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
2343 			pn[i]++;
2344 			if (pn[i])
2345 				break;
2346 		}
2347 
2348 		rpn = rx->ccm_gcm.pn;
2349 		if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
2350 			return RX_DROP_UNUSABLE;
2351 		memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
2352 	} else if (entry->is_protected &&
2353 		   (!rx->key ||
2354 		    (!ieee80211_has_protected(fc) &&
2355 		     !(status->flag & RX_FLAG_DECRYPTED)) ||
2356 		    rx->key->color != entry->key_color)) {
2357 		/* Drop this as a mixed key or fragment cache attack, even
2358 		 * if for TKIP Michael MIC should protect us, and WEP is a
2359 		 * lost cause anyway.
2360 		 */
2361 		return RX_DROP_UNUSABLE;
2362 	} else if (entry->is_protected && rx->key &&
2363 		   entry->key_color != rx->key->color &&
2364 		   (status->flag & RX_FLAG_DECRYPTED)) {
2365 		return RX_DROP_UNUSABLE;
2366 	}
2367 
2368 	skb_pull(rx->skb, ieee80211_hdrlen(fc));
2369 	__skb_queue_tail(&entry->skb_list, rx->skb);
2370 	entry->last_frag = frag;
2371 	entry->extra_len += rx->skb->len;
2372 	if (ieee80211_has_morefrags(fc)) {
2373 		rx->skb = NULL;
2374 		return RX_QUEUED;
2375 	}
2376 
2377 	rx->skb = __skb_dequeue(&entry->skb_list);
2378 	if (skb_tailroom(rx->skb) < entry->extra_len) {
2379 		I802_DEBUG_INC(rx->local->rx_expand_skb_head_defrag);
2380 		if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
2381 					      GFP_ATOMIC))) {
2382 			I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
2383 			__skb_queue_purge(&entry->skb_list);
2384 			return RX_DROP_UNUSABLE;
2385 		}
2386 	}
2387 	while ((skb = __skb_dequeue(&entry->skb_list))) {
2388 		skb_put_data(rx->skb, skb->data, skb->len);
2389 		dev_kfree_skb(skb);
2390 	}
2391 
2392  out:
2393 	ieee80211_led_rx(rx->local);
2394 	if (rx->sta)
2395 		rx->sta->rx_stats.packets++;
2396 	return RX_CONTINUE;
2397 }
2398 
2399 static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
2400 {
2401 	if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
2402 		return -EACCES;
2403 
2404 	return 0;
2405 }
2406 
2407 static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
2408 {
2409 	struct ieee80211_hdr *hdr = (void *)rx->skb->data;
2410 	struct sk_buff *skb = rx->skb;
2411 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2412 
2413 	/*
2414 	 * Pass through unencrypted frames if the hardware has
2415 	 * decrypted them already.
2416 	 */
2417 	if (status->flag & RX_FLAG_DECRYPTED)
2418 		return 0;
2419 
2420 	/* check mesh EAPOL frames first */
2421 	if (unlikely(rx->sta && ieee80211_vif_is_mesh(&rx->sdata->vif) &&
2422 		     ieee80211_is_data(fc))) {
2423 		struct ieee80211s_hdr *mesh_hdr;
2424 		u16 hdr_len = ieee80211_hdrlen(fc);
2425 		u16 ethertype_offset;
2426 		__be16 ethertype;
2427 
2428 		if (!ether_addr_equal(hdr->addr1, rx->sdata->vif.addr))
2429 			goto drop_check;
2430 
2431 		/* make sure fixed part of mesh header is there, also checks skb len */
2432 		if (!pskb_may_pull(rx->skb, hdr_len + 6))
2433 			goto drop_check;
2434 
2435 		mesh_hdr = (struct ieee80211s_hdr *)(skb->data + hdr_len);
2436 		ethertype_offset = hdr_len + ieee80211_get_mesh_hdrlen(mesh_hdr) +
2437 				   sizeof(rfc1042_header);
2438 
2439 		if (skb_copy_bits(rx->skb, ethertype_offset, &ethertype, 2) == 0 &&
2440 		    ethertype == rx->sdata->control_port_protocol)
2441 			return 0;
2442 	}
2443 
2444 drop_check:
2445 	/* Drop unencrypted frames if key is set. */
2446 	if (unlikely(!ieee80211_has_protected(fc) &&
2447 		     !ieee80211_is_any_nullfunc(fc) &&
2448 		     ieee80211_is_data(fc) && rx->key))
2449 		return -EACCES;
2450 
2451 	return 0;
2452 }
2453 
2454 static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
2455 {
2456 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2457 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
2458 	__le16 fc = hdr->frame_control;
2459 
2460 	/*
2461 	 * Pass through unencrypted frames if the hardware has
2462 	 * decrypted them already.
2463 	 */
2464 	if (status->flag & RX_FLAG_DECRYPTED)
2465 		return 0;
2466 
2467 	if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
2468 		if (unlikely(!ieee80211_has_protected(fc) &&
2469 			     ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
2470 			     rx->key)) {
2471 			if (ieee80211_is_deauth(fc) ||
2472 			    ieee80211_is_disassoc(fc))
2473 				cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2474 							     rx->skb->data,
2475 							     rx->skb->len);
2476 			return -EACCES;
2477 		}
2478 		/* BIP does not use Protected field, so need to check MMIE */
2479 		if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
2480 			     ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
2481 			if (ieee80211_is_deauth(fc) ||
2482 			    ieee80211_is_disassoc(fc))
2483 				cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2484 							     rx->skb->data,
2485 							     rx->skb->len);
2486 			return -EACCES;
2487 		}
2488 		if (unlikely(ieee80211_is_beacon(fc) && rx->key &&
2489 			     ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
2490 			cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
2491 						     rx->skb->data,
2492 						     rx->skb->len);
2493 			return -EACCES;
2494 		}
2495 		/*
2496 		 * When using MFP, Action frames are not allowed prior to
2497 		 * having configured keys.
2498 		 */
2499 		if (unlikely(ieee80211_is_action(fc) && !rx->key &&
2500 			     ieee80211_is_robust_mgmt_frame(rx->skb)))
2501 			return -EACCES;
2502 	}
2503 
2504 	return 0;
2505 }
2506 
2507 static int
2508 __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
2509 {
2510 	struct ieee80211_sub_if_data *sdata = rx->sdata;
2511 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2512 	bool check_port_control = false;
2513 	struct ethhdr *ehdr;
2514 	int ret;
2515 
2516 	*port_control = false;
2517 	if (ieee80211_has_a4(hdr->frame_control) &&
2518 	    sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
2519 		return -1;
2520 
2521 	if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2522 	    !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
2523 
2524 		if (!sdata->u.mgd.use_4addr)
2525 			return -1;
2526 		else if (!ether_addr_equal(hdr->addr1, sdata->vif.addr))
2527 			check_port_control = true;
2528 	}
2529 
2530 	if (is_multicast_ether_addr(hdr->addr1) &&
2531 	    sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
2532 		return -1;
2533 
2534 	ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
2535 	if (ret < 0)
2536 		return ret;
2537 
2538 	ehdr = (struct ethhdr *) rx->skb->data;
2539 	if (ehdr->h_proto == rx->sdata->control_port_protocol)
2540 		*port_control = true;
2541 	else if (check_port_control)
2542 		return -1;
2543 
2544 	return 0;
2545 }
2546 
2547 /*
2548  * requires that rx->skb is a frame with ethernet header
2549  */
2550 static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
2551 {
2552 	static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
2553 		= { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
2554 	struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2555 
2556 	/*
2557 	 * Allow EAPOL frames to us/the PAE group address regardless of
2558 	 * whether the frame was encrypted or not, and always disallow
2559 	 * all other destination addresses for them.
2560 	 */
2561 	if (unlikely(ehdr->h_proto == rx->sdata->control_port_protocol))
2562 		return ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) ||
2563 		       ether_addr_equal(ehdr->h_dest, pae_group_addr);
2564 
2565 	if (ieee80211_802_1x_port_control(rx) ||
2566 	    ieee80211_drop_unencrypted(rx, fc))
2567 		return false;
2568 
2569 	return true;
2570 }
2571 
2572 static void ieee80211_deliver_skb_to_local_stack(struct sk_buff *skb,
2573 						 struct ieee80211_rx_data *rx)
2574 {
2575 	struct ieee80211_sub_if_data *sdata = rx->sdata;
2576 	struct net_device *dev = sdata->dev;
2577 
2578 	if (unlikely((skb->protocol == sdata->control_port_protocol ||
2579 		     (skb->protocol == cpu_to_be16(ETH_P_PREAUTH) &&
2580 		      !sdata->control_port_no_preauth)) &&
2581 		     sdata->control_port_over_nl80211)) {
2582 		struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2583 		bool noencrypt = !(status->flag & RX_FLAG_DECRYPTED);
2584 
2585 		cfg80211_rx_control_port(dev, skb, noencrypt);
2586 		dev_kfree_skb(skb);
2587 	} else {
2588 		struct ethhdr *ehdr = (void *)skb_mac_header(skb);
2589 
2590 		memset(skb->cb, 0, sizeof(skb->cb));
2591 
2592 		/*
2593 		 * 802.1X over 802.11 requires that the authenticator address
2594 		 * be used for EAPOL frames. However, 802.1X allows the use of
2595 		 * the PAE group address instead. If the interface is part of
2596 		 * a bridge and we pass the frame with the PAE group address,
2597 		 * then the bridge will forward it to the network (even if the
2598 		 * client was not associated yet), which isn't supposed to
2599 		 * happen.
2600 		 * To avoid that, rewrite the destination address to our own
2601 		 * address, so that the authenticator (e.g. hostapd) will see
2602 		 * the frame, but bridge won't forward it anywhere else. Note
2603 		 * that due to earlier filtering, the only other address can
2604 		 * be the PAE group address.
2605 		 */
2606 		if (unlikely(skb->protocol == sdata->control_port_protocol &&
2607 			     !ether_addr_equal(ehdr->h_dest, sdata->vif.addr)))
2608 			ether_addr_copy(ehdr->h_dest, sdata->vif.addr);
2609 
2610 		/* deliver to local stack */
2611 		if (rx->list)
2612 			list_add_tail(&skb->list, rx->list);
2613 		else
2614 			netif_receive_skb(skb);
2615 	}
2616 }
2617 
2618 /*
2619  * requires that rx->skb is a frame with ethernet header
2620  */
2621 static void
2622 ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
2623 {
2624 	struct ieee80211_sub_if_data *sdata = rx->sdata;
2625 	struct net_device *dev = sdata->dev;
2626 	struct sk_buff *skb, *xmit_skb;
2627 	struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
2628 	struct sta_info *dsta;
2629 
2630 	skb = rx->skb;
2631 	xmit_skb = NULL;
2632 
2633 	dev_sw_netstats_rx_add(dev, skb->len);
2634 
2635 	if (rx->sta) {
2636 		/* The seqno index has the same property as needed
2637 		 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
2638 		 * for non-QoS-data frames. Here we know it's a data
2639 		 * frame, so count MSDUs.
2640 		 */
2641 		u64_stats_update_begin(&rx->sta->rx_stats.syncp);
2642 		rx->sta->rx_stats.msdu[rx->seqno_idx]++;
2643 		u64_stats_update_end(&rx->sta->rx_stats.syncp);
2644 	}
2645 
2646 	if ((sdata->vif.type == NL80211_IFTYPE_AP ||
2647 	     sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
2648 	    !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
2649 	    ehdr->h_proto != rx->sdata->control_port_protocol &&
2650 	    (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
2651 		if (is_multicast_ether_addr(ehdr->h_dest) &&
2652 		    ieee80211_vif_get_num_mcast_if(sdata) != 0) {
2653 			/*
2654 			 * send multicast frames both to higher layers in
2655 			 * local net stack and back to the wireless medium
2656 			 */
2657 			xmit_skb = skb_copy(skb, GFP_ATOMIC);
2658 			if (!xmit_skb)
2659 				net_info_ratelimited("%s: failed to clone multicast frame\n",
2660 						    dev->name);
2661 		} else if (!is_multicast_ether_addr(ehdr->h_dest) &&
2662 			   !ether_addr_equal(ehdr->h_dest, ehdr->h_source)) {
2663 			dsta = sta_info_get(sdata, ehdr->h_dest);
2664 			if (dsta) {
2665 				/*
2666 				 * The destination station is associated to
2667 				 * this AP (in this VLAN), so send the frame
2668 				 * directly to it and do not pass it to local
2669 				 * net stack.
2670 				 */
2671 				xmit_skb = skb;
2672 				skb = NULL;
2673 			}
2674 		}
2675 	}
2676 
2677 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2678 	if (skb) {
2679 		/* 'align' will only take the values 0 or 2 here since all
2680 		 * frames are required to be aligned to 2-byte boundaries
2681 		 * when being passed to mac80211; the code here works just
2682 		 * as well if that isn't true, but mac80211 assumes it can
2683 		 * access fields as 2-byte aligned (e.g. for ether_addr_equal)
2684 		 */
2685 		int align;
2686 
2687 		align = (unsigned long)(skb->data + sizeof(struct ethhdr)) & 3;
2688 		if (align) {
2689 			if (WARN_ON(skb_headroom(skb) < 3)) {
2690 				dev_kfree_skb(skb);
2691 				skb = NULL;
2692 			} else {
2693 				u8 *data = skb->data;
2694 				size_t len = skb_headlen(skb);
2695 				skb->data -= align;
2696 				memmove(skb->data, data, len);
2697 				skb_set_tail_pointer(skb, len);
2698 			}
2699 		}
2700 	}
2701 #endif
2702 
2703 	if (skb) {
2704 		skb->protocol = eth_type_trans(skb, dev);
2705 		ieee80211_deliver_skb_to_local_stack(skb, rx);
2706 	}
2707 
2708 	if (xmit_skb) {
2709 		/*
2710 		 * Send to wireless media and increase priority by 256 to
2711 		 * keep the received priority instead of reclassifying
2712 		 * the frame (see cfg80211_classify8021d).
2713 		 */
2714 		xmit_skb->priority += 256;
2715 		xmit_skb->protocol = htons(ETH_P_802_3);
2716 		skb_reset_network_header(xmit_skb);
2717 		skb_reset_mac_header(xmit_skb);
2718 		dev_queue_xmit(xmit_skb);
2719 	}
2720 }
2721 
2722 static ieee80211_rx_result debug_noinline
2723 __ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx, u8 data_offset)
2724 {
2725 	struct net_device *dev = rx->sdata->dev;
2726 	struct sk_buff *skb = rx->skb;
2727 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2728 	__le16 fc = hdr->frame_control;
2729 	struct sk_buff_head frame_list;
2730 	struct ethhdr ethhdr;
2731 	const u8 *check_da = ethhdr.h_dest, *check_sa = ethhdr.h_source;
2732 
2733 	if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
2734 		check_da = NULL;
2735 		check_sa = NULL;
2736 	} else switch (rx->sdata->vif.type) {
2737 		case NL80211_IFTYPE_AP:
2738 		case NL80211_IFTYPE_AP_VLAN:
2739 			check_da = NULL;
2740 			break;
2741 		case NL80211_IFTYPE_STATION:
2742 			if (!rx->sta ||
2743 			    !test_sta_flag(rx->sta, WLAN_STA_TDLS_PEER))
2744 				check_sa = NULL;
2745 			break;
2746 		case NL80211_IFTYPE_MESH_POINT:
2747 			check_sa = NULL;
2748 			break;
2749 		default:
2750 			break;
2751 	}
2752 
2753 	skb->dev = dev;
2754 	__skb_queue_head_init(&frame_list);
2755 
2756 	if (ieee80211_data_to_8023_exthdr(skb, &ethhdr,
2757 					  rx->sdata->vif.addr,
2758 					  rx->sdata->vif.type,
2759 					  data_offset, true))
2760 		return RX_DROP_UNUSABLE;
2761 
2762 	ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
2763 				 rx->sdata->vif.type,
2764 				 rx->local->hw.extra_tx_headroom,
2765 				 check_da, check_sa);
2766 
2767 	while (!skb_queue_empty(&frame_list)) {
2768 		rx->skb = __skb_dequeue(&frame_list);
2769 
2770 		if (!ieee80211_frame_allowed(rx, fc)) {
2771 			dev_kfree_skb(rx->skb);
2772 			continue;
2773 		}
2774 
2775 		ieee80211_deliver_skb(rx);
2776 	}
2777 
2778 	return RX_QUEUED;
2779 }
2780 
2781 static ieee80211_rx_result debug_noinline
2782 ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
2783 {
2784 	struct sk_buff *skb = rx->skb;
2785 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2786 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2787 	__le16 fc = hdr->frame_control;
2788 
2789 	if (!(status->rx_flags & IEEE80211_RX_AMSDU))
2790 		return RX_CONTINUE;
2791 
2792 	if (unlikely(!ieee80211_is_data(fc)))
2793 		return RX_CONTINUE;
2794 
2795 	if (unlikely(!ieee80211_is_data_present(fc)))
2796 		return RX_DROP_MONITOR;
2797 
2798 	if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
2799 		switch (rx->sdata->vif.type) {
2800 		case NL80211_IFTYPE_AP_VLAN:
2801 			if (!rx->sdata->u.vlan.sta)
2802 				return RX_DROP_UNUSABLE;
2803 			break;
2804 		case NL80211_IFTYPE_STATION:
2805 			if (!rx->sdata->u.mgd.use_4addr)
2806 				return RX_DROP_UNUSABLE;
2807 			break;
2808 		default:
2809 			return RX_DROP_UNUSABLE;
2810 		}
2811 	}
2812 
2813 	if (is_multicast_ether_addr(hdr->addr1))
2814 		return RX_DROP_UNUSABLE;
2815 
2816 	if (rx->key) {
2817 		/*
2818 		 * We should not receive A-MSDUs on pre-HT connections,
2819 		 * and HT connections cannot use old ciphers. Thus drop
2820 		 * them, as in those cases we couldn't even have SPP
2821 		 * A-MSDUs or such.
2822 		 */
2823 		switch (rx->key->conf.cipher) {
2824 		case WLAN_CIPHER_SUITE_WEP40:
2825 		case WLAN_CIPHER_SUITE_WEP104:
2826 		case WLAN_CIPHER_SUITE_TKIP:
2827 			return RX_DROP_UNUSABLE;
2828 		default:
2829 			break;
2830 		}
2831 	}
2832 
2833 	return __ieee80211_rx_h_amsdu(rx, 0);
2834 }
2835 
2836 #ifdef CONFIG_MAC80211_MESH
2837 static ieee80211_rx_result
2838 ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
2839 {
2840 	struct ieee80211_hdr *fwd_hdr, *hdr;
2841 	struct ieee80211_tx_info *info;
2842 	struct ieee80211s_hdr *mesh_hdr;
2843 	struct sk_buff *skb = rx->skb, *fwd_skb;
2844 	struct ieee80211_local *local = rx->local;
2845 	struct ieee80211_sub_if_data *sdata = rx->sdata;
2846 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2847 	u16 ac, q, hdrlen;
2848 	int tailroom = 0;
2849 
2850 	hdr = (struct ieee80211_hdr *) skb->data;
2851 	hdrlen = ieee80211_hdrlen(hdr->frame_control);
2852 
2853 	/* make sure fixed part of mesh header is there, also checks skb len */
2854 	if (!pskb_may_pull(rx->skb, hdrlen + 6))
2855 		return RX_DROP_MONITOR;
2856 
2857 	mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2858 
2859 	/* make sure full mesh header is there, also checks skb len */
2860 	if (!pskb_may_pull(rx->skb,
2861 			   hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
2862 		return RX_DROP_MONITOR;
2863 
2864 	/* reload pointers */
2865 	hdr = (struct ieee80211_hdr *) skb->data;
2866 	mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
2867 
2868 	if (ieee80211_drop_unencrypted(rx, hdr->frame_control))
2869 		return RX_DROP_MONITOR;
2870 
2871 	/* frame is in RMC, don't forward */
2872 	if (ieee80211_is_data(hdr->frame_control) &&
2873 	    is_multicast_ether_addr(hdr->addr1) &&
2874 	    mesh_rmc_check(rx->sdata, hdr->addr3, mesh_hdr))
2875 		return RX_DROP_MONITOR;
2876 
2877 	if (!ieee80211_is_data(hdr->frame_control))
2878 		return RX_CONTINUE;
2879 
2880 	if (!mesh_hdr->ttl)
2881 		return RX_DROP_MONITOR;
2882 
2883 	if (mesh_hdr->flags & MESH_FLAGS_AE) {
2884 		struct mesh_path *mppath;
2885 		char *proxied_addr;
2886 		char *mpp_addr;
2887 
2888 		if (is_multicast_ether_addr(hdr->addr1)) {
2889 			mpp_addr = hdr->addr3;
2890 			proxied_addr = mesh_hdr->eaddr1;
2891 		} else if ((mesh_hdr->flags & MESH_FLAGS_AE) ==
2892 			    MESH_FLAGS_AE_A5_A6) {
2893 			/* has_a4 already checked in ieee80211_rx_mesh_check */
2894 			mpp_addr = hdr->addr4;
2895 			proxied_addr = mesh_hdr->eaddr2;
2896 		} else {
2897 			return RX_DROP_MONITOR;
2898 		}
2899 
2900 		rcu_read_lock();
2901 		mppath = mpp_path_lookup(sdata, proxied_addr);
2902 		if (!mppath) {
2903 			mpp_path_add(sdata, proxied_addr, mpp_addr);
2904 		} else {
2905 			spin_lock_bh(&mppath->state_lock);
2906 			if (!ether_addr_equal(mppath->mpp, mpp_addr))
2907 				memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
2908 			mppath->exp_time = jiffies;
2909 			spin_unlock_bh(&mppath->state_lock);
2910 		}
2911 		rcu_read_unlock();
2912 	}
2913 
2914 	/* Frame has reached destination.  Don't forward */
2915 	if (!is_multicast_ether_addr(hdr->addr1) &&
2916 	    ether_addr_equal(sdata->vif.addr, hdr->addr3))
2917 		return RX_CONTINUE;
2918 
2919 	ac = ieee80211_select_queue_80211(sdata, skb, hdr);
2920 	q = sdata->vif.hw_queue[ac];
2921 	if (ieee80211_queue_stopped(&local->hw, q)) {
2922 		IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion);
2923 		return RX_DROP_MONITOR;
2924 	}
2925 	skb_set_queue_mapping(skb, q);
2926 
2927 	if (!--mesh_hdr->ttl) {
2928 		if (!is_multicast_ether_addr(hdr->addr1))
2929 			IEEE80211_IFSTA_MESH_CTR_INC(ifmsh,
2930 						     dropped_frames_ttl);
2931 		goto out;
2932 	}
2933 
2934 	if (!ifmsh->mshcfg.dot11MeshForwarding)
2935 		goto out;
2936 
2937 	if (sdata->crypto_tx_tailroom_needed_cnt)
2938 		tailroom = IEEE80211_ENCRYPT_TAILROOM;
2939 
2940 	fwd_skb = skb_copy_expand(skb, local->tx_headroom +
2941 				       sdata->encrypt_headroom,
2942 				  tailroom, GFP_ATOMIC);
2943 	if (!fwd_skb)
2944 		goto out;
2945 
2946 	fwd_hdr =  (struct ieee80211_hdr *) fwd_skb->data;
2947 	fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
2948 	info = IEEE80211_SKB_CB(fwd_skb);
2949 	memset(info, 0, sizeof(*info));
2950 	info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
2951 	info->control.vif = &rx->sdata->vif;
2952 	info->control.jiffies = jiffies;
2953 	if (is_multicast_ether_addr(fwd_hdr->addr1)) {
2954 		IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
2955 		memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
2956 		/* update power mode indication when forwarding */
2957 		ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
2958 	} else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
2959 		/* mesh power mode flags updated in mesh_nexthop_lookup */
2960 		IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
2961 	} else {
2962 		/* unable to resolve next hop */
2963 		mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
2964 				   fwd_hdr->addr3, 0,
2965 				   WLAN_REASON_MESH_PATH_NOFORWARD,
2966 				   fwd_hdr->addr2);
2967 		IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
2968 		kfree_skb(fwd_skb);
2969 		return RX_DROP_MONITOR;
2970 	}
2971 
2972 	IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
2973 	ieee80211_add_pending_skb(local, fwd_skb);
2974  out:
2975 	if (is_multicast_ether_addr(hdr->addr1))
2976 		return RX_CONTINUE;
2977 	return RX_DROP_MONITOR;
2978 }
2979 #endif
2980 
2981 static ieee80211_rx_result debug_noinline
2982 ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
2983 {
2984 	struct ieee80211_sub_if_data *sdata = rx->sdata;
2985 	struct ieee80211_local *local = rx->local;
2986 	struct net_device *dev = sdata->dev;
2987 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
2988 	__le16 fc = hdr->frame_control;
2989 	bool port_control;
2990 	int err;
2991 
2992 	if (unlikely(!ieee80211_is_data(hdr->frame_control)))
2993 		return RX_CONTINUE;
2994 
2995 	if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
2996 		return RX_DROP_MONITOR;
2997 
2998 	/*
2999 	 * Send unexpected-4addr-frame event to hostapd. For older versions,
3000 	 * also drop the frame to cooked monitor interfaces.
3001 	 */
3002 	if (ieee80211_has_a4(hdr->frame_control) &&
3003 	    sdata->vif.type == NL80211_IFTYPE_AP) {
3004 		if (rx->sta &&
3005 		    !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
3006 			cfg80211_rx_unexpected_4addr_frame(
3007 				rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
3008 		return RX_DROP_MONITOR;
3009 	}
3010 
3011 	err = __ieee80211_data_to_8023(rx, &port_control);
3012 	if (unlikely(err))
3013 		return RX_DROP_UNUSABLE;
3014 
3015 	if (!ieee80211_frame_allowed(rx, fc))
3016 		return RX_DROP_MONITOR;
3017 
3018 	/* directly handle TDLS channel switch requests/responses */
3019 	if (unlikely(((struct ethhdr *)rx->skb->data)->h_proto ==
3020 						cpu_to_be16(ETH_P_TDLS))) {
3021 		struct ieee80211_tdls_data *tf = (void *)rx->skb->data;
3022 
3023 		if (pskb_may_pull(rx->skb,
3024 				  offsetof(struct ieee80211_tdls_data, u)) &&
3025 		    tf->payload_type == WLAN_TDLS_SNAP_RFTYPE &&
3026 		    tf->category == WLAN_CATEGORY_TDLS &&
3027 		    (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST ||
3028 		     tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) {
3029 			rx->skb->protocol = cpu_to_be16(ETH_P_TDLS);
3030 			__ieee80211_queue_skb_to_iface(sdata, rx->sta, rx->skb);
3031 			return RX_QUEUED;
3032 		}
3033 	}
3034 
3035 	if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
3036 	    unlikely(port_control) && sdata->bss) {
3037 		sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
3038 				     u.ap);
3039 		dev = sdata->dev;
3040 		rx->sdata = sdata;
3041 	}
3042 
3043 	rx->skb->dev = dev;
3044 
3045 	if (!ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
3046 	    local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
3047 	    !is_multicast_ether_addr(
3048 		    ((struct ethhdr *)rx->skb->data)->h_dest) &&
3049 	    (!local->scanning &&
3050 	     !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)))
3051 		mod_timer(&local->dynamic_ps_timer, jiffies +
3052 			  msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
3053 
3054 	ieee80211_deliver_skb(rx);
3055 
3056 	return RX_QUEUED;
3057 }
3058 
3059 static ieee80211_rx_result debug_noinline
3060 ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
3061 {
3062 	struct sk_buff *skb = rx->skb;
3063 	struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
3064 	struct tid_ampdu_rx *tid_agg_rx;
3065 	u16 start_seq_num;
3066 	u16 tid;
3067 
3068 	if (likely(!ieee80211_is_ctl(bar->frame_control)))
3069 		return RX_CONTINUE;
3070 
3071 	if (ieee80211_is_back_req(bar->frame_control)) {
3072 		struct {
3073 			__le16 control, start_seq_num;
3074 		} __packed bar_data;
3075 		struct ieee80211_event event = {
3076 			.type = BAR_RX_EVENT,
3077 		};
3078 
3079 		if (!rx->sta)
3080 			return RX_DROP_MONITOR;
3081 
3082 		if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
3083 				  &bar_data, sizeof(bar_data)))
3084 			return RX_DROP_MONITOR;
3085 
3086 		tid = le16_to_cpu(bar_data.control) >> 12;
3087 
3088 		if (!test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
3089 		    !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
3090 			ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
3091 					     WLAN_BACK_RECIPIENT,
3092 					     WLAN_REASON_QSTA_REQUIRE_SETUP);
3093 
3094 		tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
3095 		if (!tid_agg_rx)
3096 			return RX_DROP_MONITOR;
3097 
3098 		start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
3099 		event.u.ba.tid = tid;
3100 		event.u.ba.ssn = start_seq_num;
3101 		event.u.ba.sta = &rx->sta->sta;
3102 
3103 		/* reset session timer */
3104 		if (tid_agg_rx->timeout)
3105 			mod_timer(&tid_agg_rx->session_timer,
3106 				  TU_TO_EXP_TIME(tid_agg_rx->timeout));
3107 
3108 		spin_lock(&tid_agg_rx->reorder_lock);
3109 		/* release stored frames up to start of BAR */
3110 		ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
3111 						 start_seq_num, frames);
3112 		spin_unlock(&tid_agg_rx->reorder_lock);
3113 
3114 		drv_event_callback(rx->local, rx->sdata, &event);
3115 
3116 		kfree_skb(skb);
3117 		return RX_QUEUED;
3118 	}
3119 
3120 	/*
3121 	 * After this point, we only want management frames,
3122 	 * so we can drop all remaining control frames to
3123 	 * cooked monitor interfaces.
3124 	 */
3125 	return RX_DROP_MONITOR;
3126 }
3127 
3128 static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
3129 					   struct ieee80211_mgmt *mgmt,
3130 					   size_t len)
3131 {
3132 	struct ieee80211_local *local = sdata->local;
3133 	struct sk_buff *skb;
3134 	struct ieee80211_mgmt *resp;
3135 
3136 	if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
3137 		/* Not to own unicast address */
3138 		return;
3139 	}
3140 
3141 	if (!ether_addr_equal(mgmt->sa, sdata->u.mgd.bssid) ||
3142 	    !ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) {
3143 		/* Not from the current AP or not associated yet. */
3144 		return;
3145 	}
3146 
3147 	if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
3148 		/* Too short SA Query request frame */
3149 		return;
3150 	}
3151 
3152 	skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
3153 	if (skb == NULL)
3154 		return;
3155 
3156 	skb_reserve(skb, local->hw.extra_tx_headroom);
3157 	resp = skb_put_zero(skb, 24);
3158 	memcpy(resp->da, mgmt->sa, ETH_ALEN);
3159 	memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
3160 	memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
3161 	resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3162 					  IEEE80211_STYPE_ACTION);
3163 	skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
3164 	resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
3165 	resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
3166 	memcpy(resp->u.action.u.sa_query.trans_id,
3167 	       mgmt->u.action.u.sa_query.trans_id,
3168 	       WLAN_SA_QUERY_TR_ID_LEN);
3169 
3170 	ieee80211_tx_skb(sdata, skb);
3171 }
3172 
3173 static ieee80211_rx_result debug_noinline
3174 ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
3175 {
3176 	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3177 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3178 
3179 	if (ieee80211_is_s1g_beacon(mgmt->frame_control))
3180 		return RX_CONTINUE;
3181 
3182 	/*
3183 	 * From here on, look only at management frames.
3184 	 * Data and control frames are already handled,
3185 	 * and unknown (reserved) frames are useless.
3186 	 */
3187 	if (rx->skb->len < 24)
3188 		return RX_DROP_MONITOR;
3189 
3190 	if (!ieee80211_is_mgmt(mgmt->frame_control))
3191 		return RX_DROP_MONITOR;
3192 
3193 	if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
3194 	    ieee80211_is_beacon(mgmt->frame_control) &&
3195 	    !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
3196 		int sig = 0;
3197 
3198 		if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
3199 		    !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
3200 			sig = status->signal;
3201 
3202 		cfg80211_report_obss_beacon_khz(rx->local->hw.wiphy,
3203 						rx->skb->data, rx->skb->len,
3204 						ieee80211_rx_status_to_khz(status),
3205 						sig);
3206 		rx->flags |= IEEE80211_RX_BEACON_REPORTED;
3207 	}
3208 
3209 	if (ieee80211_drop_unencrypted_mgmt(rx))
3210 		return RX_DROP_UNUSABLE;
3211 
3212 	return RX_CONTINUE;
3213 }
3214 
3215 static bool
3216 ieee80211_process_rx_twt_action(struct ieee80211_rx_data *rx)
3217 {
3218 	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)rx->skb->data;
3219 	struct ieee80211_sub_if_data *sdata = rx->sdata;
3220 
3221 	/* TWT actions are only supported in AP for the moment */
3222 	if (sdata->vif.type != NL80211_IFTYPE_AP)
3223 		return false;
3224 
3225 	if (!rx->local->ops->add_twt_setup)
3226 		return false;
3227 
3228 	if (!sdata->vif.bss_conf.twt_responder)
3229 		return false;
3230 
3231 	if (!rx->sta)
3232 		return false;
3233 
3234 	switch (mgmt->u.action.u.s1g.action_code) {
3235 	case WLAN_S1G_TWT_SETUP: {
3236 		struct ieee80211_twt_setup *twt;
3237 
3238 		if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE +
3239 				   1 + /* action code */
3240 				   sizeof(struct ieee80211_twt_setup) +
3241 				   2 /* TWT req_type agrt */)
3242 			break;
3243 
3244 		twt = (void *)mgmt->u.action.u.s1g.variable;
3245 		if (twt->element_id != WLAN_EID_S1G_TWT)
3246 			break;
3247 
3248 		if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE +
3249 				   4 + /* action code + token + tlv */
3250 				   twt->length)
3251 			break;
3252 
3253 		return true; /* queue the frame */
3254 	}
3255 	case WLAN_S1G_TWT_TEARDOWN:
3256 		if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE + 2)
3257 			break;
3258 
3259 		return true; /* queue the frame */
3260 	default:
3261 		break;
3262 	}
3263 
3264 	return false;
3265 }
3266 
3267 static ieee80211_rx_result debug_noinline
3268 ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
3269 {
3270 	struct ieee80211_local *local = rx->local;
3271 	struct ieee80211_sub_if_data *sdata = rx->sdata;
3272 	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3273 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3274 	int len = rx->skb->len;
3275 
3276 	if (!ieee80211_is_action(mgmt->frame_control))
3277 		return RX_CONTINUE;
3278 
3279 	/* drop too small frames */
3280 	if (len < IEEE80211_MIN_ACTION_SIZE)
3281 		return RX_DROP_UNUSABLE;
3282 
3283 	if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
3284 	    mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED &&
3285 	    mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
3286 		return RX_DROP_UNUSABLE;
3287 
3288 	switch (mgmt->u.action.category) {
3289 	case WLAN_CATEGORY_HT:
3290 		/* reject HT action frames from stations not supporting HT */
3291 		if (!rx->sta->sta.ht_cap.ht_supported)
3292 			goto invalid;
3293 
3294 		if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3295 		    sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3296 		    sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3297 		    sdata->vif.type != NL80211_IFTYPE_AP &&
3298 		    sdata->vif.type != NL80211_IFTYPE_ADHOC)
3299 			break;
3300 
3301 		/* verify action & smps_control/chanwidth are present */
3302 		if (len < IEEE80211_MIN_ACTION_SIZE + 2)
3303 			goto invalid;
3304 
3305 		switch (mgmt->u.action.u.ht_smps.action) {
3306 		case WLAN_HT_ACTION_SMPS: {
3307 			struct ieee80211_supported_band *sband;
3308 			enum ieee80211_smps_mode smps_mode;
3309 			struct sta_opmode_info sta_opmode = {};
3310 
3311 			if (sdata->vif.type != NL80211_IFTYPE_AP &&
3312 			    sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
3313 				goto handled;
3314 
3315 			/* convert to HT capability */
3316 			switch (mgmt->u.action.u.ht_smps.smps_control) {
3317 			case WLAN_HT_SMPS_CONTROL_DISABLED:
3318 				smps_mode = IEEE80211_SMPS_OFF;
3319 				break;
3320 			case WLAN_HT_SMPS_CONTROL_STATIC:
3321 				smps_mode = IEEE80211_SMPS_STATIC;
3322 				break;
3323 			case WLAN_HT_SMPS_CONTROL_DYNAMIC:
3324 				smps_mode = IEEE80211_SMPS_DYNAMIC;
3325 				break;
3326 			default:
3327 				goto invalid;
3328 			}
3329 
3330 			/* if no change do nothing */
3331 			if (rx->sta->sta.smps_mode == smps_mode)
3332 				goto handled;
3333 			rx->sta->sta.smps_mode = smps_mode;
3334 			sta_opmode.smps_mode =
3335 				ieee80211_smps_mode_to_smps_mode(smps_mode);
3336 			sta_opmode.changed = STA_OPMODE_SMPS_MODE_CHANGED;
3337 
3338 			sband = rx->local->hw.wiphy->bands[status->band];
3339 
3340 			rate_control_rate_update(local, sband, rx->sta,
3341 						 IEEE80211_RC_SMPS_CHANGED);
3342 			cfg80211_sta_opmode_change_notify(sdata->dev,
3343 							  rx->sta->addr,
3344 							  &sta_opmode,
3345 							  GFP_ATOMIC);
3346 			goto handled;
3347 		}
3348 		case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
3349 			struct ieee80211_supported_band *sband;
3350 			u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
3351 			enum ieee80211_sta_rx_bandwidth max_bw, new_bw;
3352 			struct sta_opmode_info sta_opmode = {};
3353 
3354 			/* If it doesn't support 40 MHz it can't change ... */
3355 			if (!(rx->sta->sta.ht_cap.cap &
3356 					IEEE80211_HT_CAP_SUP_WIDTH_20_40))
3357 				goto handled;
3358 
3359 			if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
3360 				max_bw = IEEE80211_STA_RX_BW_20;
3361 			else
3362 				max_bw = ieee80211_sta_cap_rx_bw(rx->sta);
3363 
3364 			/* set cur_max_bandwidth and recalc sta bw */
3365 			rx->sta->cur_max_bandwidth = max_bw;
3366 			new_bw = ieee80211_sta_cur_vht_bw(rx->sta);
3367 
3368 			if (rx->sta->sta.bandwidth == new_bw)
3369 				goto handled;
3370 
3371 			rx->sta->sta.bandwidth = new_bw;
3372 			sband = rx->local->hw.wiphy->bands[status->band];
3373 			sta_opmode.bw =
3374 				ieee80211_sta_rx_bw_to_chan_width(rx->sta);
3375 			sta_opmode.changed = STA_OPMODE_MAX_BW_CHANGED;
3376 
3377 			rate_control_rate_update(local, sband, rx->sta,
3378 						 IEEE80211_RC_BW_CHANGED);
3379 			cfg80211_sta_opmode_change_notify(sdata->dev,
3380 							  rx->sta->addr,
3381 							  &sta_opmode,
3382 							  GFP_ATOMIC);
3383 			goto handled;
3384 		}
3385 		default:
3386 			goto invalid;
3387 		}
3388 
3389 		break;
3390 	case WLAN_CATEGORY_PUBLIC:
3391 		if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3392 			goto invalid;
3393 		if (sdata->vif.type != NL80211_IFTYPE_STATION)
3394 			break;
3395 		if (!rx->sta)
3396 			break;
3397 		if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
3398 			break;
3399 		if (mgmt->u.action.u.ext_chan_switch.action_code !=
3400 				WLAN_PUB_ACTION_EXT_CHANSW_ANN)
3401 			break;
3402 		if (len < offsetof(struct ieee80211_mgmt,
3403 				   u.action.u.ext_chan_switch.variable))
3404 			goto invalid;
3405 		goto queue;
3406 	case WLAN_CATEGORY_VHT:
3407 		if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3408 		    sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3409 		    sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3410 		    sdata->vif.type != NL80211_IFTYPE_AP &&
3411 		    sdata->vif.type != NL80211_IFTYPE_ADHOC)
3412 			break;
3413 
3414 		/* verify action code is present */
3415 		if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3416 			goto invalid;
3417 
3418 		switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
3419 		case WLAN_VHT_ACTION_OPMODE_NOTIF: {
3420 			/* verify opmode is present */
3421 			if (len < IEEE80211_MIN_ACTION_SIZE + 2)
3422 				goto invalid;
3423 			goto queue;
3424 		}
3425 		case WLAN_VHT_ACTION_GROUPID_MGMT: {
3426 			if (len < IEEE80211_MIN_ACTION_SIZE + 25)
3427 				goto invalid;
3428 			goto queue;
3429 		}
3430 		default:
3431 			break;
3432 		}
3433 		break;
3434 	case WLAN_CATEGORY_BACK:
3435 		if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3436 		    sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3437 		    sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3438 		    sdata->vif.type != NL80211_IFTYPE_AP &&
3439 		    sdata->vif.type != NL80211_IFTYPE_ADHOC)
3440 			break;
3441 
3442 		/* verify action_code is present */
3443 		if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3444 			break;
3445 
3446 		switch (mgmt->u.action.u.addba_req.action_code) {
3447 		case WLAN_ACTION_ADDBA_REQ:
3448 			if (len < (IEEE80211_MIN_ACTION_SIZE +
3449 				   sizeof(mgmt->u.action.u.addba_req)))
3450 				goto invalid;
3451 			break;
3452 		case WLAN_ACTION_ADDBA_RESP:
3453 			if (len < (IEEE80211_MIN_ACTION_SIZE +
3454 				   sizeof(mgmt->u.action.u.addba_resp)))
3455 				goto invalid;
3456 			break;
3457 		case WLAN_ACTION_DELBA:
3458 			if (len < (IEEE80211_MIN_ACTION_SIZE +
3459 				   sizeof(mgmt->u.action.u.delba)))
3460 				goto invalid;
3461 			break;
3462 		default:
3463 			goto invalid;
3464 		}
3465 
3466 		goto queue;
3467 	case WLAN_CATEGORY_SPECTRUM_MGMT:
3468 		/* verify action_code is present */
3469 		if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3470 			break;
3471 
3472 		switch (mgmt->u.action.u.measurement.action_code) {
3473 		case WLAN_ACTION_SPCT_MSR_REQ:
3474 			if (status->band != NL80211_BAND_5GHZ)
3475 				break;
3476 
3477 			if (len < (IEEE80211_MIN_ACTION_SIZE +
3478 				   sizeof(mgmt->u.action.u.measurement)))
3479 				break;
3480 
3481 			if (sdata->vif.type != NL80211_IFTYPE_STATION)
3482 				break;
3483 
3484 			ieee80211_process_measurement_req(sdata, mgmt, len);
3485 			goto handled;
3486 		case WLAN_ACTION_SPCT_CHL_SWITCH: {
3487 			u8 *bssid;
3488 			if (len < (IEEE80211_MIN_ACTION_SIZE +
3489 				   sizeof(mgmt->u.action.u.chan_switch)))
3490 				break;
3491 
3492 			if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3493 			    sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3494 			    sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3495 				break;
3496 
3497 			if (sdata->vif.type == NL80211_IFTYPE_STATION)
3498 				bssid = sdata->u.mgd.bssid;
3499 			else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3500 				bssid = sdata->u.ibss.bssid;
3501 			else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
3502 				bssid = mgmt->sa;
3503 			else
3504 				break;
3505 
3506 			if (!ether_addr_equal(mgmt->bssid, bssid))
3507 				break;
3508 
3509 			goto queue;
3510 			}
3511 		}
3512 		break;
3513 	case WLAN_CATEGORY_SELF_PROTECTED:
3514 		if (len < (IEEE80211_MIN_ACTION_SIZE +
3515 			   sizeof(mgmt->u.action.u.self_prot.action_code)))
3516 			break;
3517 
3518 		switch (mgmt->u.action.u.self_prot.action_code) {
3519 		case WLAN_SP_MESH_PEERING_OPEN:
3520 		case WLAN_SP_MESH_PEERING_CLOSE:
3521 		case WLAN_SP_MESH_PEERING_CONFIRM:
3522 			if (!ieee80211_vif_is_mesh(&sdata->vif))
3523 				goto invalid;
3524 			if (sdata->u.mesh.user_mpm)
3525 				/* userspace handles this frame */
3526 				break;
3527 			goto queue;
3528 		case WLAN_SP_MGK_INFORM:
3529 		case WLAN_SP_MGK_ACK:
3530 			if (!ieee80211_vif_is_mesh(&sdata->vif))
3531 				goto invalid;
3532 			break;
3533 		}
3534 		break;
3535 	case WLAN_CATEGORY_MESH_ACTION:
3536 		if (len < (IEEE80211_MIN_ACTION_SIZE +
3537 			   sizeof(mgmt->u.action.u.mesh_action.action_code)))
3538 			break;
3539 
3540 		if (!ieee80211_vif_is_mesh(&sdata->vif))
3541 			break;
3542 		if (mesh_action_is_path_sel(mgmt) &&
3543 		    !mesh_path_sel_is_hwmp(sdata))
3544 			break;
3545 		goto queue;
3546 	case WLAN_CATEGORY_S1G:
3547 		switch (mgmt->u.action.u.s1g.action_code) {
3548 		case WLAN_S1G_TWT_SETUP:
3549 		case WLAN_S1G_TWT_TEARDOWN:
3550 			if (ieee80211_process_rx_twt_action(rx))
3551 				goto queue;
3552 			break;
3553 		default:
3554 			break;
3555 		}
3556 		break;
3557 	}
3558 
3559 	return RX_CONTINUE;
3560 
3561  invalid:
3562 	status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
3563 	/* will return in the next handlers */
3564 	return RX_CONTINUE;
3565 
3566  handled:
3567 	if (rx->sta)
3568 		rx->sta->rx_stats.packets++;
3569 	dev_kfree_skb(rx->skb);
3570 	return RX_QUEUED;
3571 
3572  queue:
3573 	ieee80211_queue_skb_to_iface(sdata, rx->sta, rx->skb);
3574 	return RX_QUEUED;
3575 }
3576 
3577 static ieee80211_rx_result debug_noinline
3578 ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
3579 {
3580 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3581 	int sig = 0;
3582 
3583 	/* skip known-bad action frames and return them in the next handler */
3584 	if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
3585 		return RX_CONTINUE;
3586 
3587 	/*
3588 	 * Getting here means the kernel doesn't know how to handle
3589 	 * it, but maybe userspace does ... include returned frames
3590 	 * so userspace can register for those to know whether ones
3591 	 * it transmitted were processed or returned.
3592 	 */
3593 
3594 	if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
3595 	    !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
3596 		sig = status->signal;
3597 
3598 	if (cfg80211_rx_mgmt_khz(&rx->sdata->wdev,
3599 				 ieee80211_rx_status_to_khz(status), sig,
3600 				 rx->skb->data, rx->skb->len, 0)) {
3601 		if (rx->sta)
3602 			rx->sta->rx_stats.packets++;
3603 		dev_kfree_skb(rx->skb);
3604 		return RX_QUEUED;
3605 	}
3606 
3607 	return RX_CONTINUE;
3608 }
3609 
3610 static ieee80211_rx_result debug_noinline
3611 ieee80211_rx_h_action_post_userspace(struct ieee80211_rx_data *rx)
3612 {
3613 	struct ieee80211_sub_if_data *sdata = rx->sdata;
3614 	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3615 	int len = rx->skb->len;
3616 
3617 	if (!ieee80211_is_action(mgmt->frame_control))
3618 		return RX_CONTINUE;
3619 
3620 	switch (mgmt->u.action.category) {
3621 	case WLAN_CATEGORY_SA_QUERY:
3622 		if (len < (IEEE80211_MIN_ACTION_SIZE +
3623 			   sizeof(mgmt->u.action.u.sa_query)))
3624 			break;
3625 
3626 		switch (mgmt->u.action.u.sa_query.action) {
3627 		case WLAN_ACTION_SA_QUERY_REQUEST:
3628 			if (sdata->vif.type != NL80211_IFTYPE_STATION)
3629 				break;
3630 			ieee80211_process_sa_query_req(sdata, mgmt, len);
3631 			goto handled;
3632 		}
3633 		break;
3634 	}
3635 
3636 	return RX_CONTINUE;
3637 
3638  handled:
3639 	if (rx->sta)
3640 		rx->sta->rx_stats.packets++;
3641 	dev_kfree_skb(rx->skb);
3642 	return RX_QUEUED;
3643 }
3644 
3645 static ieee80211_rx_result debug_noinline
3646 ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
3647 {
3648 	struct ieee80211_local *local = rx->local;
3649 	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
3650 	struct sk_buff *nskb;
3651 	struct ieee80211_sub_if_data *sdata = rx->sdata;
3652 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
3653 
3654 	if (!ieee80211_is_action(mgmt->frame_control))
3655 		return RX_CONTINUE;
3656 
3657 	/*
3658 	 * For AP mode, hostapd is responsible for handling any action
3659 	 * frames that we didn't handle, including returning unknown
3660 	 * ones. For all other modes we will return them to the sender,
3661 	 * setting the 0x80 bit in the action category, as required by
3662 	 * 802.11-2012 9.24.4.
3663 	 * Newer versions of hostapd shall also use the management frame
3664 	 * registration mechanisms, but older ones still use cooked
3665 	 * monitor interfaces so push all frames there.
3666 	 */
3667 	if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
3668 	    (sdata->vif.type == NL80211_IFTYPE_AP ||
3669 	     sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
3670 		return RX_DROP_MONITOR;
3671 
3672 	if (is_multicast_ether_addr(mgmt->da))
3673 		return RX_DROP_MONITOR;
3674 
3675 	/* do not return rejected action frames */
3676 	if (mgmt->u.action.category & 0x80)
3677 		return RX_DROP_UNUSABLE;
3678 
3679 	nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
3680 			       GFP_ATOMIC);
3681 	if (nskb) {
3682 		struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
3683 
3684 		nmgmt->u.action.category |= 0x80;
3685 		memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
3686 		memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
3687 
3688 		memset(nskb->cb, 0, sizeof(nskb->cb));
3689 
3690 		if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
3691 			struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
3692 
3693 			info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
3694 				      IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
3695 				      IEEE80211_TX_CTL_NO_CCK_RATE;
3696 			if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
3697 				info->hw_queue =
3698 					local->hw.offchannel_tx_hw_queue;
3699 		}
3700 
3701 		__ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7,
3702 					    status->band);
3703 	}
3704 	dev_kfree_skb(rx->skb);
3705 	return RX_QUEUED;
3706 }
3707 
3708 static ieee80211_rx_result debug_noinline
3709 ieee80211_rx_h_ext(struct ieee80211_rx_data *rx)
3710 {
3711 	struct ieee80211_sub_if_data *sdata = rx->sdata;
3712 	struct ieee80211_hdr *hdr = (void *)rx->skb->data;
3713 
3714 	if (!ieee80211_is_ext(hdr->frame_control))
3715 		return RX_CONTINUE;
3716 
3717 	if (sdata->vif.type != NL80211_IFTYPE_STATION)
3718 		return RX_DROP_MONITOR;
3719 
3720 	/* for now only beacons are ext, so queue them */
3721 	ieee80211_queue_skb_to_iface(sdata, rx->sta, rx->skb);
3722 
3723 	return RX_QUEUED;
3724 }
3725 
3726 static ieee80211_rx_result debug_noinline
3727 ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
3728 {
3729 	struct ieee80211_sub_if_data *sdata = rx->sdata;
3730 	struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
3731 	__le16 stype;
3732 
3733 	stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
3734 
3735 	if (!ieee80211_vif_is_mesh(&sdata->vif) &&
3736 	    sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3737 	    sdata->vif.type != NL80211_IFTYPE_OCB &&
3738 	    sdata->vif.type != NL80211_IFTYPE_STATION)
3739 		return RX_DROP_MONITOR;
3740 
3741 	switch (stype) {
3742 	case cpu_to_le16(IEEE80211_STYPE_AUTH):
3743 	case cpu_to_le16(IEEE80211_STYPE_BEACON):
3744 	case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
3745 		/* process for all: mesh, mlme, ibss */
3746 		break;
3747 	case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
3748 		if (is_multicast_ether_addr(mgmt->da) &&
3749 		    !is_broadcast_ether_addr(mgmt->da))
3750 			return RX_DROP_MONITOR;
3751 
3752 		/* process only for station/IBSS */
3753 		if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3754 		    sdata->vif.type != NL80211_IFTYPE_ADHOC)
3755 			return RX_DROP_MONITOR;
3756 		break;
3757 	case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
3758 	case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
3759 	case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
3760 		if (is_multicast_ether_addr(mgmt->da) &&
3761 		    !is_broadcast_ether_addr(mgmt->da))
3762 			return RX_DROP_MONITOR;
3763 
3764 		/* process only for station */
3765 		if (sdata->vif.type != NL80211_IFTYPE_STATION)
3766 			return RX_DROP_MONITOR;
3767 		break;
3768 	case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
3769 		/* process only for ibss and mesh */
3770 		if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3771 		    sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
3772 			return RX_DROP_MONITOR;
3773 		break;
3774 	default:
3775 		return RX_DROP_MONITOR;
3776 	}
3777 
3778 	ieee80211_queue_skb_to_iface(sdata, rx->sta, rx->skb);
3779 
3780 	return RX_QUEUED;
3781 }
3782 
3783 static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
3784 					struct ieee80211_rate *rate)
3785 {
3786 	struct ieee80211_sub_if_data *sdata;
3787 	struct ieee80211_local *local = rx->local;
3788 	struct sk_buff *skb = rx->skb, *skb2;
3789 	struct net_device *prev_dev = NULL;
3790 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3791 	int needed_headroom;
3792 
3793 	/*
3794 	 * If cooked monitor has been processed already, then
3795 	 * don't do it again. If not, set the flag.
3796 	 */
3797 	if (rx->flags & IEEE80211_RX_CMNTR)
3798 		goto out_free_skb;
3799 	rx->flags |= IEEE80211_RX_CMNTR;
3800 
3801 	/* If there are no cooked monitor interfaces, just free the SKB */
3802 	if (!local->cooked_mntrs)
3803 		goto out_free_skb;
3804 
3805 	/* vendor data is long removed here */
3806 	status->flag &= ~RX_FLAG_RADIOTAP_VENDOR_DATA;
3807 	/* room for the radiotap header based on driver features */
3808 	needed_headroom = ieee80211_rx_radiotap_hdrlen(local, status, skb);
3809 
3810 	if (skb_headroom(skb) < needed_headroom &&
3811 	    pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
3812 		goto out_free_skb;
3813 
3814 	/* prepend radiotap information */
3815 	ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
3816 					 false);
3817 
3818 	skb_reset_mac_header(skb);
3819 	skb->ip_summed = CHECKSUM_UNNECESSARY;
3820 	skb->pkt_type = PACKET_OTHERHOST;
3821 	skb->protocol = htons(ETH_P_802_2);
3822 
3823 	list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3824 		if (!ieee80211_sdata_running(sdata))
3825 			continue;
3826 
3827 		if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
3828 		    !(sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES))
3829 			continue;
3830 
3831 		if (prev_dev) {
3832 			skb2 = skb_clone(skb, GFP_ATOMIC);
3833 			if (skb2) {
3834 				skb2->dev = prev_dev;
3835 				netif_receive_skb(skb2);
3836 			}
3837 		}
3838 
3839 		prev_dev = sdata->dev;
3840 		dev_sw_netstats_rx_add(sdata->dev, skb->len);
3841 	}
3842 
3843 	if (prev_dev) {
3844 		skb->dev = prev_dev;
3845 		netif_receive_skb(skb);
3846 		return;
3847 	}
3848 
3849  out_free_skb:
3850 	dev_kfree_skb(skb);
3851 }
3852 
3853 static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
3854 					 ieee80211_rx_result res)
3855 {
3856 	switch (res) {
3857 	case RX_DROP_MONITOR:
3858 		I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3859 		if (rx->sta)
3860 			rx->sta->rx_stats.dropped++;
3861 		fallthrough;
3862 	case RX_CONTINUE: {
3863 		struct ieee80211_rate *rate = NULL;
3864 		struct ieee80211_supported_band *sband;
3865 		struct ieee80211_rx_status *status;
3866 
3867 		status = IEEE80211_SKB_RXCB((rx->skb));
3868 
3869 		sband = rx->local->hw.wiphy->bands[status->band];
3870 		if (status->encoding == RX_ENC_LEGACY)
3871 			rate = &sband->bitrates[status->rate_idx];
3872 
3873 		ieee80211_rx_cooked_monitor(rx, rate);
3874 		break;
3875 		}
3876 	case RX_DROP_UNUSABLE:
3877 		I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
3878 		if (rx->sta)
3879 			rx->sta->rx_stats.dropped++;
3880 		dev_kfree_skb(rx->skb);
3881 		break;
3882 	case RX_QUEUED:
3883 		I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
3884 		break;
3885 	}
3886 }
3887 
3888 static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
3889 				  struct sk_buff_head *frames)
3890 {
3891 	ieee80211_rx_result res = RX_DROP_MONITOR;
3892 	struct sk_buff *skb;
3893 
3894 #define CALL_RXH(rxh)			\
3895 	do {				\
3896 		res = rxh(rx);		\
3897 		if (res != RX_CONTINUE)	\
3898 			goto rxh_next;  \
3899 	} while (0)
3900 
3901 	/* Lock here to avoid hitting all of the data used in the RX
3902 	 * path (e.g. key data, station data, ...) concurrently when
3903 	 * a frame is released from the reorder buffer due to timeout
3904 	 * from the timer, potentially concurrently with RX from the
3905 	 * driver.
3906 	 */
3907 	spin_lock_bh(&rx->local->rx_path_lock);
3908 
3909 	while ((skb = __skb_dequeue(frames))) {
3910 		/*
3911 		 * all the other fields are valid across frames
3912 		 * that belong to an aMPDU since they are on the
3913 		 * same TID from the same station
3914 		 */
3915 		rx->skb = skb;
3916 
3917 		CALL_RXH(ieee80211_rx_h_check_more_data);
3918 		CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll);
3919 		CALL_RXH(ieee80211_rx_h_sta_process);
3920 		CALL_RXH(ieee80211_rx_h_decrypt);
3921 		CALL_RXH(ieee80211_rx_h_defragment);
3922 		CALL_RXH(ieee80211_rx_h_michael_mic_verify);
3923 		/* must be after MMIC verify so header is counted in MPDU mic */
3924 #ifdef CONFIG_MAC80211_MESH
3925 		if (ieee80211_vif_is_mesh(&rx->sdata->vif))
3926 			CALL_RXH(ieee80211_rx_h_mesh_fwding);
3927 #endif
3928 		CALL_RXH(ieee80211_rx_h_amsdu);
3929 		CALL_RXH(ieee80211_rx_h_data);
3930 
3931 		/* special treatment -- needs the queue */
3932 		res = ieee80211_rx_h_ctrl(rx, frames);
3933 		if (res != RX_CONTINUE)
3934 			goto rxh_next;
3935 
3936 		CALL_RXH(ieee80211_rx_h_mgmt_check);
3937 		CALL_RXH(ieee80211_rx_h_action);
3938 		CALL_RXH(ieee80211_rx_h_userspace_mgmt);
3939 		CALL_RXH(ieee80211_rx_h_action_post_userspace);
3940 		CALL_RXH(ieee80211_rx_h_action_return);
3941 		CALL_RXH(ieee80211_rx_h_ext);
3942 		CALL_RXH(ieee80211_rx_h_mgmt);
3943 
3944  rxh_next:
3945 		ieee80211_rx_handlers_result(rx, res);
3946 
3947 #undef CALL_RXH
3948 	}
3949 
3950 	spin_unlock_bh(&rx->local->rx_path_lock);
3951 }
3952 
3953 static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
3954 {
3955 	struct sk_buff_head reorder_release;
3956 	ieee80211_rx_result res = RX_DROP_MONITOR;
3957 
3958 	__skb_queue_head_init(&reorder_release);
3959 
3960 #define CALL_RXH(rxh)			\
3961 	do {				\
3962 		res = rxh(rx);		\
3963 		if (res != RX_CONTINUE)	\
3964 			goto rxh_next;  \
3965 	} while (0)
3966 
3967 	CALL_RXH(ieee80211_rx_h_check_dup);
3968 	CALL_RXH(ieee80211_rx_h_check);
3969 
3970 	ieee80211_rx_reorder_ampdu(rx, &reorder_release);
3971 
3972 	ieee80211_rx_handlers(rx, &reorder_release);
3973 	return;
3974 
3975  rxh_next:
3976 	ieee80211_rx_handlers_result(rx, res);
3977 
3978 #undef CALL_RXH
3979 }
3980 
3981 /*
3982  * This function makes calls into the RX path, therefore
3983  * it has to be invoked under RCU read lock.
3984  */
3985 void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
3986 {
3987 	struct sk_buff_head frames;
3988 	struct ieee80211_rx_data rx = {
3989 		.sta = sta,
3990 		.sdata = sta->sdata,
3991 		.local = sta->local,
3992 		/* This is OK -- must be QoS data frame */
3993 		.security_idx = tid,
3994 		.seqno_idx = tid,
3995 	};
3996 	struct tid_ampdu_rx *tid_agg_rx;
3997 
3998 	tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
3999 	if (!tid_agg_rx)
4000 		return;
4001 
4002 	__skb_queue_head_init(&frames);
4003 
4004 	spin_lock(&tid_agg_rx->reorder_lock);
4005 	ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
4006 	spin_unlock(&tid_agg_rx->reorder_lock);
4007 
4008 	if (!skb_queue_empty(&frames)) {
4009 		struct ieee80211_event event = {
4010 			.type = BA_FRAME_TIMEOUT,
4011 			.u.ba.tid = tid,
4012 			.u.ba.sta = &sta->sta,
4013 		};
4014 		drv_event_callback(rx.local, rx.sdata, &event);
4015 	}
4016 
4017 	ieee80211_rx_handlers(&rx, &frames);
4018 }
4019 
4020 void ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta *pubsta, u8 tid,
4021 					  u16 ssn, u64 filtered,
4022 					  u16 received_mpdus)
4023 {
4024 	struct sta_info *sta;
4025 	struct tid_ampdu_rx *tid_agg_rx;
4026 	struct sk_buff_head frames;
4027 	struct ieee80211_rx_data rx = {
4028 		/* This is OK -- must be QoS data frame */
4029 		.security_idx = tid,
4030 		.seqno_idx = tid,
4031 	};
4032 	int i, diff;
4033 
4034 	if (WARN_ON(!pubsta || tid >= IEEE80211_NUM_TIDS))
4035 		return;
4036 
4037 	__skb_queue_head_init(&frames);
4038 
4039 	sta = container_of(pubsta, struct sta_info, sta);
4040 
4041 	rx.sta = sta;
4042 	rx.sdata = sta->sdata;
4043 	rx.local = sta->local;
4044 
4045 	rcu_read_lock();
4046 	tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
4047 	if (!tid_agg_rx)
4048 		goto out;
4049 
4050 	spin_lock_bh(&tid_agg_rx->reorder_lock);
4051 
4052 	if (received_mpdus >= IEEE80211_SN_MODULO >> 1) {
4053 		int release;
4054 
4055 		/* release all frames in the reorder buffer */
4056 		release = (tid_agg_rx->head_seq_num + tid_agg_rx->buf_size) %
4057 			   IEEE80211_SN_MODULO;
4058 		ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx,
4059 						 release, &frames);
4060 		/* update ssn to match received ssn */
4061 		tid_agg_rx->head_seq_num = ssn;
4062 	} else {
4063 		ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx, ssn,
4064 						 &frames);
4065 	}
4066 
4067 	/* handle the case that received ssn is behind the mac ssn.
4068 	 * it can be tid_agg_rx->buf_size behind and still be valid */
4069 	diff = (tid_agg_rx->head_seq_num - ssn) & IEEE80211_SN_MASK;
4070 	if (diff >= tid_agg_rx->buf_size) {
4071 		tid_agg_rx->reorder_buf_filtered = 0;
4072 		goto release;
4073 	}
4074 	filtered = filtered >> diff;
4075 	ssn += diff;
4076 
4077 	/* update bitmap */
4078 	for (i = 0; i < tid_agg_rx->buf_size; i++) {
4079 		int index = (ssn + i) % tid_agg_rx->buf_size;
4080 
4081 		tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
4082 		if (filtered & BIT_ULL(i))
4083 			tid_agg_rx->reorder_buf_filtered |= BIT_ULL(index);
4084 	}
4085 
4086 	/* now process also frames that the filter marking released */
4087 	ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
4088 
4089 release:
4090 	spin_unlock_bh(&tid_agg_rx->reorder_lock);
4091 
4092 	ieee80211_rx_handlers(&rx, &frames);
4093 
4094  out:
4095 	rcu_read_unlock();
4096 }
4097 EXPORT_SYMBOL(ieee80211_mark_rx_ba_filtered_frames);
4098 
4099 /* main receive path */
4100 
4101 static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
4102 {
4103 	struct ieee80211_sub_if_data *sdata = rx->sdata;
4104 	struct sk_buff *skb = rx->skb;
4105 	struct ieee80211_hdr *hdr = (void *)skb->data;
4106 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4107 	u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
4108 	bool multicast = is_multicast_ether_addr(hdr->addr1) ||
4109 			 ieee80211_is_s1g_beacon(hdr->frame_control);
4110 
4111 	switch (sdata->vif.type) {
4112 	case NL80211_IFTYPE_STATION:
4113 		if (!bssid && !sdata->u.mgd.use_4addr)
4114 			return false;
4115 		if (ieee80211_is_robust_mgmt_frame(skb) && !rx->sta)
4116 			return false;
4117 		if (multicast)
4118 			return true;
4119 		return ether_addr_equal(sdata->vif.addr, hdr->addr1);
4120 	case NL80211_IFTYPE_ADHOC:
4121 		if (!bssid)
4122 			return false;
4123 		if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
4124 		    ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2) ||
4125 		    !is_valid_ether_addr(hdr->addr2))
4126 			return false;
4127 		if (ieee80211_is_beacon(hdr->frame_control))
4128 			return true;
4129 		if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid))
4130 			return false;
4131 		if (!multicast &&
4132 		    !ether_addr_equal(sdata->vif.addr, hdr->addr1))
4133 			return false;
4134 		if (!rx->sta) {
4135 			int rate_idx;
4136 			if (status->encoding != RX_ENC_LEGACY)
4137 				rate_idx = 0; /* TODO: HT/VHT rates */
4138 			else
4139 				rate_idx = status->rate_idx;
4140 			ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
4141 						 BIT(rate_idx));
4142 		}
4143 		return true;
4144 	case NL80211_IFTYPE_OCB:
4145 		if (!bssid)
4146 			return false;
4147 		if (!ieee80211_is_data_present(hdr->frame_control))
4148 			return false;
4149 		if (!is_broadcast_ether_addr(bssid))
4150 			return false;
4151 		if (!multicast &&
4152 		    !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1))
4153 			return false;
4154 		if (!rx->sta) {
4155 			int rate_idx;
4156 			if (status->encoding != RX_ENC_LEGACY)
4157 				rate_idx = 0; /* TODO: HT rates */
4158 			else
4159 				rate_idx = status->rate_idx;
4160 			ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2,
4161 						BIT(rate_idx));
4162 		}
4163 		return true;
4164 	case NL80211_IFTYPE_MESH_POINT:
4165 		if (ether_addr_equal(sdata->vif.addr, hdr->addr2))
4166 			return false;
4167 		if (multicast)
4168 			return true;
4169 		return ether_addr_equal(sdata->vif.addr, hdr->addr1);
4170 	case NL80211_IFTYPE_AP_VLAN:
4171 	case NL80211_IFTYPE_AP:
4172 		if (!bssid)
4173 			return ether_addr_equal(sdata->vif.addr, hdr->addr1);
4174 
4175 		if (!ieee80211_bssid_match(bssid, sdata->vif.addr)) {
4176 			/*
4177 			 * Accept public action frames even when the
4178 			 * BSSID doesn't match, this is used for P2P
4179 			 * and location updates. Note that mac80211
4180 			 * itself never looks at these frames.
4181 			 */
4182 			if (!multicast &&
4183 			    !ether_addr_equal(sdata->vif.addr, hdr->addr1))
4184 				return false;
4185 			if (ieee80211_is_public_action(hdr, skb->len))
4186 				return true;
4187 			return ieee80211_is_beacon(hdr->frame_control);
4188 		}
4189 
4190 		if (!ieee80211_has_tods(hdr->frame_control)) {
4191 			/* ignore data frames to TDLS-peers */
4192 			if (ieee80211_is_data(hdr->frame_control))
4193 				return false;
4194 			/* ignore action frames to TDLS-peers */
4195 			if (ieee80211_is_action(hdr->frame_control) &&
4196 			    !is_broadcast_ether_addr(bssid) &&
4197 			    !ether_addr_equal(bssid, hdr->addr1))
4198 				return false;
4199 		}
4200 
4201 		/*
4202 		 * 802.11-2016 Table 9-26 says that for data frames, A1 must be
4203 		 * the BSSID - we've checked that already but may have accepted
4204 		 * the wildcard (ff:ff:ff:ff:ff:ff).
4205 		 *
4206 		 * It also says:
4207 		 *	The BSSID of the Data frame is determined as follows:
4208 		 *	a) If the STA is contained within an AP or is associated
4209 		 *	   with an AP, the BSSID is the address currently in use
4210 		 *	   by the STA contained in the AP.
4211 		 *
4212 		 * So we should not accept data frames with an address that's
4213 		 * multicast.
4214 		 *
4215 		 * Accepting it also opens a security problem because stations
4216 		 * could encrypt it with the GTK and inject traffic that way.
4217 		 */
4218 		if (ieee80211_is_data(hdr->frame_control) && multicast)
4219 			return false;
4220 
4221 		return true;
4222 	case NL80211_IFTYPE_P2P_DEVICE:
4223 		return ieee80211_is_public_action(hdr, skb->len) ||
4224 		       ieee80211_is_probe_req(hdr->frame_control) ||
4225 		       ieee80211_is_probe_resp(hdr->frame_control) ||
4226 		       ieee80211_is_beacon(hdr->frame_control);
4227 	case NL80211_IFTYPE_NAN:
4228 		/* Currently no frames on NAN interface are allowed */
4229 		return false;
4230 	default:
4231 		break;
4232 	}
4233 
4234 	WARN_ON_ONCE(1);
4235 	return false;
4236 }
4237 
4238 void ieee80211_check_fast_rx(struct sta_info *sta)
4239 {
4240 	struct ieee80211_sub_if_data *sdata = sta->sdata;
4241 	struct ieee80211_local *local = sdata->local;
4242 	struct ieee80211_key *key;
4243 	struct ieee80211_fast_rx fastrx = {
4244 		.dev = sdata->dev,
4245 		.vif_type = sdata->vif.type,
4246 		.control_port_protocol = sdata->control_port_protocol,
4247 	}, *old, *new = NULL;
4248 	bool set_offload = false;
4249 	bool assign = false;
4250 	bool offload;
4251 
4252 	/* use sparse to check that we don't return without updating */
4253 	__acquire(check_fast_rx);
4254 
4255 	BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != sizeof(rfc1042_header));
4256 	BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != ETH_ALEN);
4257 	ether_addr_copy(fastrx.rfc1042_hdr, rfc1042_header);
4258 	ether_addr_copy(fastrx.vif_addr, sdata->vif.addr);
4259 
4260 	fastrx.uses_rss = ieee80211_hw_check(&local->hw, USES_RSS);
4261 
4262 	/* fast-rx doesn't do reordering */
4263 	if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
4264 	    !ieee80211_hw_check(&local->hw, SUPPORTS_REORDERING_BUFFER))
4265 		goto clear;
4266 
4267 	switch (sdata->vif.type) {
4268 	case NL80211_IFTYPE_STATION:
4269 		if (sta->sta.tdls) {
4270 			fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
4271 			fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
4272 			fastrx.expected_ds_bits = 0;
4273 		} else {
4274 			fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
4275 			fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr3);
4276 			fastrx.expected_ds_bits =
4277 				cpu_to_le16(IEEE80211_FCTL_FROMDS);
4278 		}
4279 
4280 		if (sdata->u.mgd.use_4addr && !sta->sta.tdls) {
4281 			fastrx.expected_ds_bits |=
4282 				cpu_to_le16(IEEE80211_FCTL_TODS);
4283 			fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
4284 			fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
4285 		}
4286 
4287 		if (!sdata->u.mgd.powersave)
4288 			break;
4289 
4290 		/* software powersave is a huge mess, avoid all of it */
4291 		if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
4292 			goto clear;
4293 		if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
4294 		    !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
4295 			goto clear;
4296 		break;
4297 	case NL80211_IFTYPE_AP_VLAN:
4298 	case NL80211_IFTYPE_AP:
4299 		/* parallel-rx requires this, at least with calls to
4300 		 * ieee80211_sta_ps_transition()
4301 		 */
4302 		if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
4303 			goto clear;
4304 		fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
4305 		fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
4306 		fastrx.expected_ds_bits = cpu_to_le16(IEEE80211_FCTL_TODS);
4307 
4308 		fastrx.internal_forward =
4309 			!(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
4310 			(sdata->vif.type != NL80211_IFTYPE_AP_VLAN ||
4311 			 !sdata->u.vlan.sta);
4312 
4313 		if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
4314 		    sdata->u.vlan.sta) {
4315 			fastrx.expected_ds_bits |=
4316 				cpu_to_le16(IEEE80211_FCTL_FROMDS);
4317 			fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
4318 			fastrx.internal_forward = 0;
4319 		}
4320 
4321 		break;
4322 	default:
4323 		goto clear;
4324 	}
4325 
4326 	if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
4327 		goto clear;
4328 
4329 	rcu_read_lock();
4330 	key = rcu_dereference(sta->ptk[sta->ptk_idx]);
4331 	if (!key)
4332 		key = rcu_dereference(sdata->default_unicast_key);
4333 	if (key) {
4334 		switch (key->conf.cipher) {
4335 		case WLAN_CIPHER_SUITE_TKIP:
4336 			/* we don't want to deal with MMIC in fast-rx */
4337 			goto clear_rcu;
4338 		case WLAN_CIPHER_SUITE_CCMP:
4339 		case WLAN_CIPHER_SUITE_CCMP_256:
4340 		case WLAN_CIPHER_SUITE_GCMP:
4341 		case WLAN_CIPHER_SUITE_GCMP_256:
4342 			break;
4343 		default:
4344 			/* We also don't want to deal with
4345 			 * WEP or cipher scheme.
4346 			 */
4347 			goto clear_rcu;
4348 		}
4349 
4350 		fastrx.key = true;
4351 		fastrx.icv_len = key->conf.icv_len;
4352 	}
4353 
4354 	assign = true;
4355  clear_rcu:
4356 	rcu_read_unlock();
4357  clear:
4358 	__release(check_fast_rx);
4359 
4360 	if (assign)
4361 		new = kmemdup(&fastrx, sizeof(fastrx), GFP_KERNEL);
4362 
4363 	offload = assign &&
4364 		  (sdata->vif.offload_flags & IEEE80211_OFFLOAD_DECAP_ENABLED);
4365 
4366 	if (offload)
4367 		set_offload = !test_and_set_sta_flag(sta, WLAN_STA_DECAP_OFFLOAD);
4368 	else
4369 		set_offload = test_and_clear_sta_flag(sta, WLAN_STA_DECAP_OFFLOAD);
4370 
4371 	if (set_offload)
4372 		drv_sta_set_decap_offload(local, sdata, &sta->sta, assign);
4373 
4374 	spin_lock_bh(&sta->lock);
4375 	old = rcu_dereference_protected(sta->fast_rx, true);
4376 	rcu_assign_pointer(sta->fast_rx, new);
4377 	spin_unlock_bh(&sta->lock);
4378 
4379 	if (old)
4380 		kfree_rcu(old, rcu_head);
4381 }
4382 
4383 void ieee80211_clear_fast_rx(struct sta_info *sta)
4384 {
4385 	struct ieee80211_fast_rx *old;
4386 
4387 	spin_lock_bh(&sta->lock);
4388 	old = rcu_dereference_protected(sta->fast_rx, true);
4389 	RCU_INIT_POINTER(sta->fast_rx, NULL);
4390 	spin_unlock_bh(&sta->lock);
4391 
4392 	if (old)
4393 		kfree_rcu(old, rcu_head);
4394 }
4395 
4396 void __ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
4397 {
4398 	struct ieee80211_local *local = sdata->local;
4399 	struct sta_info *sta;
4400 
4401 	lockdep_assert_held(&local->sta_mtx);
4402 
4403 	list_for_each_entry(sta, &local->sta_list, list) {
4404 		if (sdata != sta->sdata &&
4405 		    (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
4406 			continue;
4407 		ieee80211_check_fast_rx(sta);
4408 	}
4409 }
4410 
4411 void ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
4412 {
4413 	struct ieee80211_local *local = sdata->local;
4414 
4415 	mutex_lock(&local->sta_mtx);
4416 	__ieee80211_check_fast_rx_iface(sdata);
4417 	mutex_unlock(&local->sta_mtx);
4418 }
4419 
4420 static void ieee80211_rx_8023(struct ieee80211_rx_data *rx,
4421 			      struct ieee80211_fast_rx *fast_rx,
4422 			      int orig_len)
4423 {
4424 	struct ieee80211_sta_rx_stats *stats;
4425 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
4426 	struct sta_info *sta = rx->sta;
4427 	struct sk_buff *skb = rx->skb;
4428 	void *sa = skb->data + ETH_ALEN;
4429 	void *da = skb->data;
4430 
4431 	stats = &sta->rx_stats;
4432 	if (fast_rx->uses_rss)
4433 		stats = this_cpu_ptr(sta->pcpu_rx_stats);
4434 
4435 	/* statistics part of ieee80211_rx_h_sta_process() */
4436 	if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
4437 		stats->last_signal = status->signal;
4438 		if (!fast_rx->uses_rss)
4439 			ewma_signal_add(&sta->rx_stats_avg.signal,
4440 					-status->signal);
4441 	}
4442 
4443 	if (status->chains) {
4444 		int i;
4445 
4446 		stats->chains = status->chains;
4447 		for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
4448 			int signal = status->chain_signal[i];
4449 
4450 			if (!(status->chains & BIT(i)))
4451 				continue;
4452 
4453 			stats->chain_signal_last[i] = signal;
4454 			if (!fast_rx->uses_rss)
4455 				ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
4456 						-signal);
4457 		}
4458 	}
4459 	/* end of statistics */
4460 
4461 	stats->last_rx = jiffies;
4462 	stats->last_rate = sta_stats_encode_rate(status);
4463 
4464 	stats->fragments++;
4465 	stats->packets++;
4466 
4467 	skb->dev = fast_rx->dev;
4468 
4469 	dev_sw_netstats_rx_add(fast_rx->dev, skb->len);
4470 
4471 	/* The seqno index has the same property as needed
4472 	 * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
4473 	 * for non-QoS-data frames. Here we know it's a data
4474 	 * frame, so count MSDUs.
4475 	 */
4476 	u64_stats_update_begin(&stats->syncp);
4477 	stats->msdu[rx->seqno_idx]++;
4478 	stats->bytes += orig_len;
4479 	u64_stats_update_end(&stats->syncp);
4480 
4481 	if (fast_rx->internal_forward) {
4482 		struct sk_buff *xmit_skb = NULL;
4483 		if (is_multicast_ether_addr(da)) {
4484 			xmit_skb = skb_copy(skb, GFP_ATOMIC);
4485 		} else if (!ether_addr_equal(da, sa) &&
4486 			   sta_info_get(rx->sdata, da)) {
4487 			xmit_skb = skb;
4488 			skb = NULL;
4489 		}
4490 
4491 		if (xmit_skb) {
4492 			/*
4493 			 * Send to wireless media and increase priority by 256
4494 			 * to keep the received priority instead of
4495 			 * reclassifying the frame (see cfg80211_classify8021d).
4496 			 */
4497 			xmit_skb->priority += 256;
4498 			xmit_skb->protocol = htons(ETH_P_802_3);
4499 			skb_reset_network_header(xmit_skb);
4500 			skb_reset_mac_header(xmit_skb);
4501 			dev_queue_xmit(xmit_skb);
4502 		}
4503 
4504 		if (!skb)
4505 			return;
4506 	}
4507 
4508 	/* deliver to local stack */
4509 	skb->protocol = eth_type_trans(skb, fast_rx->dev);
4510 	memset(skb->cb, 0, sizeof(skb->cb));
4511 	if (rx->list)
4512 		list_add_tail(&skb->list, rx->list);
4513 	else
4514 		netif_receive_skb(skb);
4515 
4516 }
4517 
4518 static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,
4519 				     struct ieee80211_fast_rx *fast_rx)
4520 {
4521 	struct sk_buff *skb = rx->skb;
4522 	struct ieee80211_hdr *hdr = (void *)skb->data;
4523 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4524 	struct sta_info *sta = rx->sta;
4525 	int orig_len = skb->len;
4526 	int hdrlen = ieee80211_hdrlen(hdr->frame_control);
4527 	int snap_offs = hdrlen;
4528 	struct {
4529 		u8 snap[sizeof(rfc1042_header)];
4530 		__be16 proto;
4531 	} *payload __aligned(2);
4532 	struct {
4533 		u8 da[ETH_ALEN];
4534 		u8 sa[ETH_ALEN];
4535 	} addrs __aligned(2);
4536 	struct ieee80211_sta_rx_stats *stats = &sta->rx_stats;
4537 
4538 	/* for parallel-rx, we need to have DUP_VALIDATED, otherwise we write
4539 	 * to a common data structure; drivers can implement that per queue
4540 	 * but we don't have that information in mac80211
4541 	 */
4542 	if (!(status->flag & RX_FLAG_DUP_VALIDATED))
4543 		return false;
4544 
4545 #define FAST_RX_CRYPT_FLAGS	(RX_FLAG_PN_VALIDATED | RX_FLAG_DECRYPTED)
4546 
4547 	/* If using encryption, we also need to have:
4548 	 *  - PN_VALIDATED: similar, but the implementation is tricky
4549 	 *  - DECRYPTED: necessary for PN_VALIDATED
4550 	 */
4551 	if (fast_rx->key &&
4552 	    (status->flag & FAST_RX_CRYPT_FLAGS) != FAST_RX_CRYPT_FLAGS)
4553 		return false;
4554 
4555 	if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
4556 		return false;
4557 
4558 	if (unlikely(ieee80211_is_frag(hdr)))
4559 		return false;
4560 
4561 	/* Since our interface address cannot be multicast, this
4562 	 * implicitly also rejects multicast frames without the
4563 	 * explicit check.
4564 	 *
4565 	 * We shouldn't get any *data* frames not addressed to us
4566 	 * (AP mode will accept multicast *management* frames), but
4567 	 * punting here will make it go through the full checks in
4568 	 * ieee80211_accept_frame().
4569 	 */
4570 	if (!ether_addr_equal(fast_rx->vif_addr, hdr->addr1))
4571 		return false;
4572 
4573 	if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FROMDS |
4574 					      IEEE80211_FCTL_TODS)) !=
4575 	    fast_rx->expected_ds_bits)
4576 		return false;
4577 
4578 	/* assign the key to drop unencrypted frames (later)
4579 	 * and strip the IV/MIC if necessary
4580 	 */
4581 	if (fast_rx->key && !(status->flag & RX_FLAG_IV_STRIPPED)) {
4582 		/* GCMP header length is the same */
4583 		snap_offs += IEEE80211_CCMP_HDR_LEN;
4584 	}
4585 
4586 	if (!(status->rx_flags & IEEE80211_RX_AMSDU)) {
4587 		if (!pskb_may_pull(skb, snap_offs + sizeof(*payload)))
4588 			goto drop;
4589 
4590 		payload = (void *)(skb->data + snap_offs);
4591 
4592 		if (!ether_addr_equal(payload->snap, fast_rx->rfc1042_hdr))
4593 			return false;
4594 
4595 		/* Don't handle these here since they require special code.
4596 		 * Accept AARP and IPX even though they should come with a
4597 		 * bridge-tunnel header - but if we get them this way then
4598 		 * there's little point in discarding them.
4599 		 */
4600 		if (unlikely(payload->proto == cpu_to_be16(ETH_P_TDLS) ||
4601 			     payload->proto == fast_rx->control_port_protocol))
4602 			return false;
4603 	}
4604 
4605 	/* after this point, don't punt to the slowpath! */
4606 
4607 	if (rx->key && !(status->flag & RX_FLAG_MIC_STRIPPED) &&
4608 	    pskb_trim(skb, skb->len - fast_rx->icv_len))
4609 		goto drop;
4610 
4611 	if (rx->key && !ieee80211_has_protected(hdr->frame_control))
4612 		goto drop;
4613 
4614 	if (status->rx_flags & IEEE80211_RX_AMSDU) {
4615 		if (__ieee80211_rx_h_amsdu(rx, snap_offs - hdrlen) !=
4616 		    RX_QUEUED)
4617 			goto drop;
4618 
4619 		return true;
4620 	}
4621 
4622 	/* do the header conversion - first grab the addresses */
4623 	ether_addr_copy(addrs.da, skb->data + fast_rx->da_offs);
4624 	ether_addr_copy(addrs.sa, skb->data + fast_rx->sa_offs);
4625 	/* remove the SNAP but leave the ethertype */
4626 	skb_pull(skb, snap_offs + sizeof(rfc1042_header));
4627 	/* push the addresses in front */
4628 	memcpy(skb_push(skb, sizeof(addrs)), &addrs, sizeof(addrs));
4629 
4630 	ieee80211_rx_8023(rx, fast_rx, orig_len);
4631 
4632 	return true;
4633  drop:
4634 	dev_kfree_skb(skb);
4635 	if (fast_rx->uses_rss)
4636 		stats = this_cpu_ptr(sta->pcpu_rx_stats);
4637 
4638 	stats->dropped++;
4639 	return true;
4640 }
4641 
4642 /*
4643  * This function returns whether or not the SKB
4644  * was destined for RX processing or not, which,
4645  * if consume is true, is equivalent to whether
4646  * or not the skb was consumed.
4647  */
4648 static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
4649 					    struct sk_buff *skb, bool consume)
4650 {
4651 	struct ieee80211_local *local = rx->local;
4652 	struct ieee80211_sub_if_data *sdata = rx->sdata;
4653 
4654 	rx->skb = skb;
4655 
4656 	/* See if we can do fast-rx; if we have to copy we already lost,
4657 	 * so punt in that case. We should never have to deliver a data
4658 	 * frame to multiple interfaces anyway.
4659 	 *
4660 	 * We skip the ieee80211_accept_frame() call and do the necessary
4661 	 * checking inside ieee80211_invoke_fast_rx().
4662 	 */
4663 	if (consume && rx->sta) {
4664 		struct ieee80211_fast_rx *fast_rx;
4665 
4666 		fast_rx = rcu_dereference(rx->sta->fast_rx);
4667 		if (fast_rx && ieee80211_invoke_fast_rx(rx, fast_rx))
4668 			return true;
4669 	}
4670 
4671 	if (!ieee80211_accept_frame(rx))
4672 		return false;
4673 
4674 	if (!consume) {
4675 		skb = skb_copy(skb, GFP_ATOMIC);
4676 		if (!skb) {
4677 			if (net_ratelimit())
4678 				wiphy_debug(local->hw.wiphy,
4679 					"failed to copy skb for %s\n",
4680 					sdata->name);
4681 			return true;
4682 		}
4683 
4684 		rx->skb = skb;
4685 	}
4686 
4687 	ieee80211_invoke_rx_handlers(rx);
4688 	return true;
4689 }
4690 
4691 static void __ieee80211_rx_handle_8023(struct ieee80211_hw *hw,
4692 				       struct ieee80211_sta *pubsta,
4693 				       struct sk_buff *skb,
4694 				       struct list_head *list)
4695 {
4696 	struct ieee80211_local *local = hw_to_local(hw);
4697 	struct ieee80211_fast_rx *fast_rx;
4698 	struct ieee80211_rx_data rx;
4699 
4700 	memset(&rx, 0, sizeof(rx));
4701 	rx.skb = skb;
4702 	rx.local = local;
4703 	rx.list = list;
4704 
4705 	I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
4706 
4707 	/* drop frame if too short for header */
4708 	if (skb->len < sizeof(struct ethhdr))
4709 		goto drop;
4710 
4711 	if (!pubsta)
4712 		goto drop;
4713 
4714 	rx.sta = container_of(pubsta, struct sta_info, sta);
4715 	rx.sdata = rx.sta->sdata;
4716 
4717 	fast_rx = rcu_dereference(rx.sta->fast_rx);
4718 	if (!fast_rx)
4719 		goto drop;
4720 
4721 	ieee80211_rx_8023(&rx, fast_rx, skb->len);
4722 	return;
4723 
4724 drop:
4725 	dev_kfree_skb(skb);
4726 }
4727 
4728 /*
4729  * This is the actual Rx frames handler. as it belongs to Rx path it must
4730  * be called with rcu_read_lock protection.
4731  */
4732 static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
4733 					 struct ieee80211_sta *pubsta,
4734 					 struct sk_buff *skb,
4735 					 struct list_head *list)
4736 {
4737 	struct ieee80211_local *local = hw_to_local(hw);
4738 	struct ieee80211_sub_if_data *sdata;
4739 	struct ieee80211_hdr *hdr;
4740 	__le16 fc;
4741 	struct ieee80211_rx_data rx;
4742 	struct ieee80211_sub_if_data *prev;
4743 	struct rhlist_head *tmp;
4744 	int err = 0;
4745 
4746 	fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
4747 	memset(&rx, 0, sizeof(rx));
4748 	rx.skb = skb;
4749 	rx.local = local;
4750 	rx.list = list;
4751 
4752 	if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
4753 		I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
4754 
4755 	if (ieee80211_is_mgmt(fc)) {
4756 		/* drop frame if too short for header */
4757 		if (skb->len < ieee80211_hdrlen(fc))
4758 			err = -ENOBUFS;
4759 		else
4760 			err = skb_linearize(skb);
4761 	} else {
4762 		err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
4763 	}
4764 
4765 	if (err) {
4766 		dev_kfree_skb(skb);
4767 		return;
4768 	}
4769 
4770 	hdr = (struct ieee80211_hdr *)skb->data;
4771 	ieee80211_parse_qos(&rx);
4772 	ieee80211_verify_alignment(&rx);
4773 
4774 	if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
4775 		     ieee80211_is_beacon(hdr->frame_control) ||
4776 		     ieee80211_is_s1g_beacon(hdr->frame_control)))
4777 		ieee80211_scan_rx(local, skb);
4778 
4779 	if (ieee80211_is_data(fc)) {
4780 		struct sta_info *sta, *prev_sta;
4781 
4782 		if (pubsta) {
4783 			rx.sta = container_of(pubsta, struct sta_info, sta);
4784 			rx.sdata = rx.sta->sdata;
4785 			if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4786 				return;
4787 			goto out;
4788 		}
4789 
4790 		prev_sta = NULL;
4791 
4792 		for_each_sta_info(local, hdr->addr2, sta, tmp) {
4793 			if (!prev_sta) {
4794 				prev_sta = sta;
4795 				continue;
4796 			}
4797 
4798 			rx.sta = prev_sta;
4799 			rx.sdata = prev_sta->sdata;
4800 			ieee80211_prepare_and_rx_handle(&rx, skb, false);
4801 
4802 			prev_sta = sta;
4803 		}
4804 
4805 		if (prev_sta) {
4806 			rx.sta = prev_sta;
4807 			rx.sdata = prev_sta->sdata;
4808 
4809 			if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4810 				return;
4811 			goto out;
4812 		}
4813 	}
4814 
4815 	prev = NULL;
4816 
4817 	list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4818 		if (!ieee80211_sdata_running(sdata))
4819 			continue;
4820 
4821 		if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
4822 		    sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
4823 			continue;
4824 
4825 		/*
4826 		 * frame is destined for this interface, but if it's
4827 		 * not also for the previous one we handle that after
4828 		 * the loop to avoid copying the SKB once too much
4829 		 */
4830 
4831 		if (!prev) {
4832 			prev = sdata;
4833 			continue;
4834 		}
4835 
4836 		rx.sta = sta_info_get_bss(prev, hdr->addr2);
4837 		rx.sdata = prev;
4838 		ieee80211_prepare_and_rx_handle(&rx, skb, false);
4839 
4840 		prev = sdata;
4841 	}
4842 
4843 	if (prev) {
4844 		rx.sta = sta_info_get_bss(prev, hdr->addr2);
4845 		rx.sdata = prev;
4846 
4847 		if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
4848 			return;
4849 	}
4850 
4851  out:
4852 	dev_kfree_skb(skb);
4853 }
4854 
4855 /*
4856  * This is the receive path handler. It is called by a low level driver when an
4857  * 802.11 MPDU is received from the hardware.
4858  */
4859 void ieee80211_rx_list(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
4860 		       struct sk_buff *skb, struct list_head *list)
4861 {
4862 	struct ieee80211_local *local = hw_to_local(hw);
4863 	struct ieee80211_rate *rate = NULL;
4864 	struct ieee80211_supported_band *sband;
4865 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
4866 
4867 	WARN_ON_ONCE(softirq_count() == 0);
4868 
4869 	if (WARN_ON(status->band >= NUM_NL80211_BANDS))
4870 		goto drop;
4871 
4872 	sband = local->hw.wiphy->bands[status->band];
4873 	if (WARN_ON(!sband))
4874 		goto drop;
4875 
4876 	/*
4877 	 * If we're suspending, it is possible although not too likely
4878 	 * that we'd be receiving frames after having already partially
4879 	 * quiesced the stack. We can't process such frames then since
4880 	 * that might, for example, cause stations to be added or other
4881 	 * driver callbacks be invoked.
4882 	 */
4883 	if (unlikely(local->quiescing || local->suspended))
4884 		goto drop;
4885 
4886 	/* We might be during a HW reconfig, prevent Rx for the same reason */
4887 	if (unlikely(local->in_reconfig))
4888 		goto drop;
4889 
4890 	/*
4891 	 * The same happens when we're not even started,
4892 	 * but that's worth a warning.
4893 	 */
4894 	if (WARN_ON(!local->started))
4895 		goto drop;
4896 
4897 	if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
4898 		/*
4899 		 * Validate the rate, unless a PLCP error means that
4900 		 * we probably can't have a valid rate here anyway.
4901 		 */
4902 
4903 		switch (status->encoding) {
4904 		case RX_ENC_HT:
4905 			/*
4906 			 * rate_idx is MCS index, which can be [0-76]
4907 			 * as documented on:
4908 			 *
4909 			 * https://wireless.wiki.kernel.org/en/developers/Documentation/ieee80211/802.11n
4910 			 *
4911 			 * Anything else would be some sort of driver or
4912 			 * hardware error. The driver should catch hardware
4913 			 * errors.
4914 			 */
4915 			if (WARN(status->rate_idx > 76,
4916 				 "Rate marked as an HT rate but passed "
4917 				 "status->rate_idx is not "
4918 				 "an MCS index [0-76]: %d (0x%02x)\n",
4919 				 status->rate_idx,
4920 				 status->rate_idx))
4921 				goto drop;
4922 			break;
4923 		case RX_ENC_VHT:
4924 			if (WARN_ONCE(status->rate_idx > 9 ||
4925 				      !status->nss ||
4926 				      status->nss > 8,
4927 				      "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
4928 				      status->rate_idx, status->nss))
4929 				goto drop;
4930 			break;
4931 		case RX_ENC_HE:
4932 			if (WARN_ONCE(status->rate_idx > 11 ||
4933 				      !status->nss ||
4934 				      status->nss > 8,
4935 				      "Rate marked as an HE rate but data is invalid: MCS: %d, NSS: %d\n",
4936 				      status->rate_idx, status->nss))
4937 				goto drop;
4938 			break;
4939 		default:
4940 			WARN_ON_ONCE(1);
4941 			fallthrough;
4942 		case RX_ENC_LEGACY:
4943 			if (WARN_ON(status->rate_idx >= sband->n_bitrates))
4944 				goto drop;
4945 			rate = &sband->bitrates[status->rate_idx];
4946 		}
4947 	}
4948 
4949 	status->rx_flags = 0;
4950 
4951 	kcov_remote_start_common(skb_get_kcov_handle(skb));
4952 
4953 	/*
4954 	 * Frames with failed FCS/PLCP checksum are not returned,
4955 	 * all other frames are returned without radiotap header
4956 	 * if it was previously present.
4957 	 * Also, frames with less than 16 bytes are dropped.
4958 	 */
4959 	if (!(status->flag & RX_FLAG_8023))
4960 		skb = ieee80211_rx_monitor(local, skb, rate);
4961 	if (skb) {
4962 		ieee80211_tpt_led_trig_rx(local,
4963 					  ((struct ieee80211_hdr *)skb->data)->frame_control,
4964 					  skb->len);
4965 
4966 		if (status->flag & RX_FLAG_8023)
4967 			__ieee80211_rx_handle_8023(hw, pubsta, skb, list);
4968 		else
4969 			__ieee80211_rx_handle_packet(hw, pubsta, skb, list);
4970 	}
4971 
4972 	kcov_remote_stop();
4973 	return;
4974  drop:
4975 	kfree_skb(skb);
4976 }
4977 EXPORT_SYMBOL(ieee80211_rx_list);
4978 
4979 void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
4980 		       struct sk_buff *skb, struct napi_struct *napi)
4981 {
4982 	struct sk_buff *tmp;
4983 	LIST_HEAD(list);
4984 
4985 
4986 	/*
4987 	 * key references and virtual interfaces are protected using RCU
4988 	 * and this requires that we are in a read-side RCU section during
4989 	 * receive processing
4990 	 */
4991 	rcu_read_lock();
4992 	ieee80211_rx_list(hw, pubsta, skb, &list);
4993 	rcu_read_unlock();
4994 
4995 	if (!napi) {
4996 		netif_receive_skb_list(&list);
4997 		return;
4998 	}
4999 
5000 	list_for_each_entry_safe(skb, tmp, &list, list) {
5001 		skb_list_del_init(skb);
5002 		napi_gro_receive(napi, skb);
5003 	}
5004 }
5005 EXPORT_SYMBOL(ieee80211_rx_napi);
5006 
5007 /* This is a version of the rx handler that can be called from hard irq
5008  * context. Post the skb on the queue and schedule the tasklet */
5009 void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
5010 {
5011 	struct ieee80211_local *local = hw_to_local(hw);
5012 
5013 	BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
5014 
5015 	skb->pkt_type = IEEE80211_RX_MSG;
5016 	skb_queue_tail(&local->skb_queue, skb);
5017 	tasklet_schedule(&local->tasklet);
5018 }
5019 EXPORT_SYMBOL(ieee80211_rx_irqsafe);
5020