| lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright 2002-2005, Instant802 Networks, Inc. | 
 | 3 |  * Copyright 2005-2006, Devicescape Software, Inc. | 
 | 4 |  * Copyright 2006-2007	Jiri Benc <jbenc@suse.cz> | 
 | 5 |  * Copyright 2007-2010	Johannes Berg <johannes@sipsolutions.net> | 
 | 6 |  * | 
 | 7 |  * This program is free software; you can redistribute it and/or modify | 
 | 8 |  * it under the terms of the GNU General Public License version 2 as | 
 | 9 |  * published by the Free Software Foundation. | 
 | 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 <net/mac80211.h> | 
 | 21 | #include <net/ieee80211_radiotap.h> | 
 | 22 | #include <asm/unaligned.h> | 
 | 23 |  | 
 | 24 | #include "ieee80211_i.h" | 
 | 25 | #include "driver-ops.h" | 
 | 26 | #include "led.h" | 
 | 27 | #include "mesh.h" | 
 | 28 | #include "wep.h" | 
 | 29 | #include "wpa.h" | 
 | 30 | #include "tkip.h" | 
 | 31 | #include "wme.h" | 
 | 32 | #include "rate.h" | 
 | 33 |  | 
 | 34 | /* | 
 | 35 |  * monitor mode reception | 
 | 36 |  * | 
 | 37 |  * This function cleans up the SKB, i.e. it removes all the stuff | 
 | 38 |  * only useful for monitoring. | 
 | 39 |  */ | 
 | 40 | static struct sk_buff *remove_monitor_info(struct ieee80211_local *local, | 
 | 41 | 					   struct sk_buff *skb) | 
 | 42 | { | 
 | 43 | 	if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) { | 
 | 44 | 		if (likely(skb->len > FCS_LEN)) | 
 | 45 | 			__pskb_trim(skb, skb->len - FCS_LEN); | 
 | 46 | 		else { | 
 | 47 | 			/* driver bug */ | 
 | 48 | 			WARN_ON(1); | 
 | 49 | 			dev_kfree_skb(skb); | 
 | 50 | 			skb = NULL; | 
 | 51 | 		} | 
 | 52 | 	} | 
 | 53 |  | 
 | 54 | 	return skb; | 
 | 55 | } | 
 | 56 |  | 
 | 57 | static inline int should_drop_frame(struct sk_buff *skb, | 
 | 58 | 				    int present_fcs_len) | 
 | 59 | { | 
 | 60 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); | 
 | 61 | 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | 
 | 62 |  | 
 | 63 | 	if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC)) | 
 | 64 | 		return 1; | 
 | 65 | 	if (unlikely(skb->len < 16 + present_fcs_len)) | 
 | 66 | 		return 1; | 
 | 67 | 	if (ieee80211_is_ctl(hdr->frame_control) && | 
 | 68 | 	    !ieee80211_is_pspoll(hdr->frame_control) && | 
 | 69 | 	    !ieee80211_is_back_req(hdr->frame_control)) | 
 | 70 | 		return 1; | 
 | 71 | 	return 0; | 
 | 72 | } | 
 | 73 |  | 
 | 74 | static int | 
 | 75 | ieee80211_rx_radiotap_len(struct ieee80211_local *local, | 
 | 76 | 			  struct ieee80211_rx_status *status) | 
 | 77 | { | 
 | 78 | 	int len; | 
 | 79 |  | 
 | 80 | 	/* always present fields */ | 
 | 81 | 	len = sizeof(struct ieee80211_radiotap_header) + 9; | 
 | 82 |  | 
 | 83 | 	if (status->flag & RX_FLAG_MACTIME_MPDU) | 
 | 84 | 		len += 8; | 
 | 85 | 	if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) | 
 | 86 | 		len += 1; | 
 | 87 |  | 
 | 88 | 	if (len & 1) /* padding for RX_FLAGS if necessary */ | 
 | 89 | 		len++; | 
 | 90 |  | 
 | 91 | 	if (status->flag & RX_FLAG_HT) /* HT info */ | 
 | 92 | 		len += 3; | 
 | 93 |  | 
 | 94 | 	return len; | 
 | 95 | } | 
 | 96 |  | 
 | 97 | /* | 
 | 98 |  * ieee80211_add_rx_radiotap_header - add radiotap header | 
 | 99 |  * | 
 | 100 |  * add a radiotap header containing all the fields which the hardware provided. | 
 | 101 |  */ | 
 | 102 | static void | 
 | 103 | ieee80211_add_rx_radiotap_header(struct ieee80211_local *local, | 
 | 104 | 				 struct sk_buff *skb, | 
 | 105 | 				 struct ieee80211_rate *rate, | 
 | 106 | 				 int rtap_len, bool has_fcs) | 
 | 107 | { | 
 | 108 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); | 
 | 109 | 	struct ieee80211_radiotap_header *rthdr; | 
 | 110 | 	unsigned char *pos; | 
 | 111 | 	u16 rx_flags = 0; | 
 | 112 |  | 
 | 113 | 	rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len); | 
 | 114 | 	memset(rthdr, 0, rtap_len); | 
 | 115 |  | 
 | 116 | 	/* radiotap header, set always present flags */ | 
 | 117 | 	rthdr->it_present = | 
 | 118 | 		cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) | | 
 | 119 | 			    (1 << IEEE80211_RADIOTAP_CHANNEL) | | 
 | 120 | 			    (1 << IEEE80211_RADIOTAP_ANTENNA) | | 
 | 121 | 			    (1 << IEEE80211_RADIOTAP_RX_FLAGS)); | 
 | 122 | 	rthdr->it_len = cpu_to_le16(rtap_len); | 
 | 123 |  | 
 | 124 | 	pos = (unsigned char *)(rthdr+1); | 
 | 125 |  | 
 | 126 | 	/* the order of the following fields is important */ | 
 | 127 |  | 
 | 128 | 	/* IEEE80211_RADIOTAP_TSFT */ | 
 | 129 | 	if (status->flag & RX_FLAG_MACTIME_MPDU) { | 
 | 130 | 		put_unaligned_le64(status->mactime, pos); | 
 | 131 | 		rthdr->it_present |= | 
 | 132 | 			cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT); | 
 | 133 | 		pos += 8; | 
 | 134 | 	} | 
 | 135 |  | 
 | 136 | 	/* IEEE80211_RADIOTAP_FLAGS */ | 
 | 137 | 	if (has_fcs && (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)) | 
 | 138 | 		*pos |= IEEE80211_RADIOTAP_F_FCS; | 
 | 139 | 	if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC)) | 
 | 140 | 		*pos |= IEEE80211_RADIOTAP_F_BADFCS; | 
 | 141 | 	if (status->flag & RX_FLAG_SHORTPRE) | 
 | 142 | 		*pos |= IEEE80211_RADIOTAP_F_SHORTPRE; | 
 | 143 | 	pos++; | 
 | 144 |  | 
 | 145 | 	/* IEEE80211_RADIOTAP_RATE */ | 
 | 146 | 	if (!rate || status->flag & RX_FLAG_HT) { | 
 | 147 | 		/* | 
 | 148 | 		 * Without rate information don't add it. If we have, | 
 | 149 | 		 * MCS information is a separate field in radiotap, | 
 | 150 | 		 * added below. The byte here is needed as padding | 
 | 151 | 		 * for the channel though, so initialise it to 0. | 
 | 152 | 		 */ | 
 | 153 | 		*pos = 0; | 
 | 154 | 	} else { | 
 | 155 | 		rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE); | 
 | 156 | 		*pos = rate->bitrate / 5; | 
 | 157 | 	} | 
 | 158 | 	pos++; | 
 | 159 |  | 
 | 160 | 	/* IEEE80211_RADIOTAP_CHANNEL */ | 
 | 161 | 	put_unaligned_le16(status->freq, pos); | 
 | 162 | 	pos += 2; | 
 | 163 | 	if (status->band == IEEE80211_BAND_5GHZ) | 
 | 164 | 		put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ, | 
 | 165 | 				   pos); | 
 | 166 | 	else if (status->flag & RX_FLAG_HT) | 
 | 167 | 		put_unaligned_le16(IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ, | 
 | 168 | 				   pos); | 
 | 169 | 	else if (rate && rate->flags & IEEE80211_RATE_ERP_G) | 
 | 170 | 		put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ, | 
 | 171 | 				   pos); | 
 | 172 | 	else if (rate) | 
 | 173 | 		put_unaligned_le16(IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ, | 
 | 174 | 				   pos); | 
 | 175 | 	else | 
 | 176 | 		put_unaligned_le16(IEEE80211_CHAN_2GHZ, pos); | 
 | 177 | 	pos += 2; | 
 | 178 |  | 
 | 179 | 	/* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */ | 
 | 180 | 	if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM && | 
 | 181 | 	    !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) { | 
 | 182 | 		*pos = status->signal; | 
 | 183 | 		rthdr->it_present |= | 
 | 184 | 			cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL); | 
 | 185 | 		pos++; | 
 | 186 | 	} | 
 | 187 |  | 
 | 188 | 	/* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */ | 
 | 189 |  | 
 | 190 | 	/* IEEE80211_RADIOTAP_ANTENNA */ | 
 | 191 | 	*pos = status->antenna; | 
 | 192 | 	pos++; | 
 | 193 |  | 
 | 194 | 	/* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */ | 
 | 195 |  | 
 | 196 | 	/* IEEE80211_RADIOTAP_RX_FLAGS */ | 
 | 197 | 	/* ensure 2 byte alignment for the 2 byte field as required */ | 
 | 198 | 	if ((pos - (u8 *)rthdr) & 1) | 
 | 199 | 		pos++; | 
 | 200 | 	if (status->flag & RX_FLAG_FAILED_PLCP_CRC) | 
 | 201 | 		rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP; | 
 | 202 | 	put_unaligned_le16(rx_flags, pos); | 
 | 203 | 	pos += 2; | 
 | 204 |  | 
 | 205 | 	if (status->flag & RX_FLAG_HT) { | 
 | 206 | 		rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS); | 
 | 207 | 		*pos++ = IEEE80211_RADIOTAP_MCS_HAVE_MCS | | 
 | 208 | 			 IEEE80211_RADIOTAP_MCS_HAVE_GI | | 
 | 209 | 			 IEEE80211_RADIOTAP_MCS_HAVE_BW; | 
 | 210 | 		*pos = 0; | 
 | 211 | 		if (status->flag & RX_FLAG_SHORT_GI) | 
 | 212 | 			*pos |= IEEE80211_RADIOTAP_MCS_SGI; | 
 | 213 | 		if (status->flag & RX_FLAG_40MHZ) | 
 | 214 | 			*pos |= IEEE80211_RADIOTAP_MCS_BW_40; | 
 | 215 | 		pos++; | 
 | 216 | 		*pos++ = status->rate_idx; | 
 | 217 | 	} | 
 | 218 | } | 
 | 219 |  | 
 | 220 | /* | 
 | 221 |  * This function copies a received frame to all monitor interfaces and | 
 | 222 |  * returns a cleaned-up SKB that no longer includes the FCS nor the | 
 | 223 |  * radiotap header the driver might have added. | 
 | 224 |  */ | 
 | 225 | static struct sk_buff * | 
 | 226 | ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb, | 
 | 227 | 		     struct ieee80211_rate *rate) | 
 | 228 | { | 
 | 229 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb); | 
 | 230 | 	struct ieee80211_sub_if_data *sdata; | 
 | 231 | 	int needed_headroom; | 
 | 232 | 	struct sk_buff *skb, *skb2; | 
 | 233 | 	struct net_device *prev_dev = NULL; | 
 | 234 | 	int present_fcs_len = 0; | 
 | 235 |  | 
 | 236 | 	/* | 
 | 237 | 	 * First, we may need to make a copy of the skb because | 
 | 238 | 	 *  (1) we need to modify it for radiotap (if not present), and | 
 | 239 | 	 *  (2) the other RX handlers will modify the skb we got. | 
 | 240 | 	 * | 
 | 241 | 	 * We don't need to, of course, if we aren't going to return | 
 | 242 | 	 * the SKB because it has a bad FCS/PLCP checksum. | 
 | 243 | 	 */ | 
 | 244 |  | 
 | 245 | 	/* room for the radiotap header based on driver features */ | 
 | 246 | 	needed_headroom = ieee80211_rx_radiotap_len(local, status); | 
 | 247 |  | 
 | 248 | 	if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) | 
 | 249 | 		present_fcs_len = FCS_LEN; | 
 | 250 |  | 
 | 251 | 	/* make sure hdr->frame_control is on the linear part */ | 
 | 252 | 	if (!pskb_may_pull(origskb, 2)) { | 
 | 253 | 		dev_kfree_skb(origskb); | 
 | 254 | 		return NULL; | 
 | 255 | 	} | 
 | 256 |  | 
 | 257 | 	if (!local->monitors) { | 
 | 258 | 		if (should_drop_frame(origskb, present_fcs_len)) { | 
 | 259 | 			dev_kfree_skb(origskb); | 
 | 260 | 			return NULL; | 
 | 261 | 		} | 
 | 262 |  | 
 | 263 | 		return remove_monitor_info(local, origskb); | 
 | 264 | 	} | 
 | 265 |  | 
 | 266 | 	if (should_drop_frame(origskb, present_fcs_len)) { | 
 | 267 | 		/* only need to expand headroom if necessary */ | 
 | 268 | 		skb = origskb; | 
 | 269 | 		origskb = NULL; | 
 | 270 |  | 
 | 271 | 		/* | 
 | 272 | 		 * This shouldn't trigger often because most devices have an | 
 | 273 | 		 * RX header they pull before we get here, and that should | 
 | 274 | 		 * be big enough for our radiotap information. We should | 
 | 275 | 		 * probably export the length to drivers so that we can have | 
 | 276 | 		 * them allocate enough headroom to start with. | 
 | 277 | 		 */ | 
 | 278 | 		if (skb_headroom(skb) < needed_headroom && | 
 | 279 | 		    pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) { | 
 | 280 | 			dev_kfree_skb(skb); | 
 | 281 | 			return NULL; | 
 | 282 | 		} | 
 | 283 | 	} else { | 
 | 284 | 		/* | 
 | 285 | 		 * Need to make a copy and possibly remove radiotap header | 
 | 286 | 		 * and FCS from the original. | 
 | 287 | 		 */ | 
 | 288 | 		skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC); | 
 | 289 |  | 
 | 290 | 		origskb = remove_monitor_info(local, origskb); | 
 | 291 |  | 
 | 292 | 		if (!skb) | 
 | 293 | 			return origskb; | 
 | 294 | 	} | 
 | 295 |  | 
 | 296 | 	/* prepend radiotap information */ | 
 | 297 | 	ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom, | 
 | 298 | 					 true); | 
 | 299 |  | 
 | 300 | 	skb_reset_mac_header(skb); | 
 | 301 | 	skb->ip_summed = CHECKSUM_UNNECESSARY; | 
 | 302 | 	skb->pkt_type = PACKET_OTHERHOST; | 
 | 303 | 	skb->protocol = htons(ETH_P_802_2); | 
 | 304 |  | 
 | 305 | 	list_for_each_entry_rcu(sdata, &local->interfaces, list) { | 
 | 306 | 		if (sdata->vif.type != NL80211_IFTYPE_MONITOR) | 
 | 307 | 			continue; | 
 | 308 |  | 
 | 309 | 		if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) | 
 | 310 | 			continue; | 
 | 311 |  | 
 | 312 | 		if (!ieee80211_sdata_running(sdata)) | 
 | 313 | 			continue; | 
 | 314 |  | 
 | 315 | 		if (prev_dev) { | 
 | 316 | 			skb2 = skb_clone(skb, GFP_ATOMIC); | 
 | 317 | 			if (skb2) { | 
 | 318 | 				skb2->dev = prev_dev; | 
 | 319 | 				netif_receive_skb(skb2); | 
 | 320 | 			} | 
 | 321 | 		} | 
 | 322 |  | 
 | 323 | 		prev_dev = sdata->dev; | 
 | 324 | 		sdata->dev->stats.rx_packets++; | 
 | 325 | 		sdata->dev->stats.rx_bytes += skb->len; | 
 | 326 | 	} | 
 | 327 |  | 
 | 328 | 	if (prev_dev) { | 
 | 329 | 		skb->dev = prev_dev; | 
 | 330 | 		netif_receive_skb(skb); | 
 | 331 | 	} else | 
 | 332 | 		dev_kfree_skb(skb); | 
 | 333 |  | 
 | 334 | 	return origskb; | 
 | 335 | } | 
 | 336 |  | 
 | 337 |  | 
 | 338 | static void ieee80211_parse_qos(struct ieee80211_rx_data *rx) | 
 | 339 | { | 
 | 340 | 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; | 
 | 341 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); | 
 | 342 | 	int tid, seqno_idx, security_idx; | 
 | 343 |  | 
 | 344 | 	/* does the frame have a qos control field? */ | 
 | 345 | 	if (ieee80211_is_data_qos(hdr->frame_control)) { | 
 | 346 | 		u8 *qc = ieee80211_get_qos_ctl(hdr); | 
 | 347 | 		/* frame has qos control */ | 
 | 348 | 		tid = *qc & IEEE80211_QOS_CTL_TID_MASK; | 
 | 349 | 		if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT) | 
 | 350 | 			status->rx_flags |= IEEE80211_RX_AMSDU; | 
 | 351 |  | 
 | 352 | 		seqno_idx = tid; | 
 | 353 | 		security_idx = tid; | 
 | 354 | 	} else { | 
 | 355 | 		/* | 
 | 356 | 		 * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"): | 
 | 357 | 		 * | 
 | 358 | 		 *	Sequence numbers for management frames, QoS data | 
 | 359 | 		 *	frames with a broadcast/multicast address in the | 
 | 360 | 		 *	Address 1 field, and all non-QoS data frames sent | 
 | 361 | 		 *	by QoS STAs are assigned using an additional single | 
 | 362 | 		 *	modulo-4096 counter, [...] | 
 | 363 | 		 * | 
 | 364 | 		 * We also use that counter for non-QoS STAs. | 
 | 365 | 		 */ | 
 | 366 | 		seqno_idx = NUM_RX_DATA_QUEUES; | 
 | 367 | 		security_idx = 0; | 
 | 368 | 		if (ieee80211_is_mgmt(hdr->frame_control)) | 
 | 369 | 			security_idx = NUM_RX_DATA_QUEUES; | 
 | 370 | 		tid = 0; | 
 | 371 | 	} | 
 | 372 |  | 
 | 373 | 	rx->seqno_idx = seqno_idx; | 
 | 374 | 	rx->security_idx = security_idx; | 
 | 375 | 	/* Set skb->priority to 1d tag if highest order bit of TID is not set. | 
 | 376 | 	 * For now, set skb->priority to 0 for other cases. */ | 
 | 377 | 	rx->skb->priority = (tid > 7) ? 0 : tid; | 
 | 378 | } | 
 | 379 |  | 
 | 380 | /** | 
 | 381 |  * DOC: Packet alignment | 
 | 382 |  * | 
 | 383 |  * Drivers always need to pass packets that are aligned to two-byte boundaries | 
 | 384 |  * to the stack. | 
 | 385 |  * | 
 | 386 |  * Additionally, should, if possible, align the payload data in a way that | 
 | 387 |  * guarantees that the contained IP header is aligned to a four-byte | 
 | 388 |  * boundary. In the case of regular frames, this simply means aligning the | 
 | 389 |  * payload to a four-byte boundary (because either the IP header is directly | 
 | 390 |  * contained, or IV/RFC1042 headers that have a length divisible by four are | 
 | 391 |  * in front of it).  If the payload data is not properly aligned and the | 
 | 392 |  * architecture doesn't support efficient unaligned operations, mac80211 | 
 | 393 |  * will align the data. | 
 | 394 |  * | 
 | 395 |  * With A-MSDU frames, however, the payload data address must yield two modulo | 
 | 396 |  * four because there are 14-byte 802.3 headers within the A-MSDU frames that | 
 | 397 |  * push the IP header further back to a multiple of four again. Thankfully, the | 
 | 398 |  * specs were sane enough this time around to require padding each A-MSDU | 
 | 399 |  * subframe to a length that is a multiple of four. | 
 | 400 |  * | 
 | 401 |  * Padding like Atheros hardware adds which is between the 802.11 header and | 
 | 402 |  * the payload is not supported, the driver is required to move the 802.11 | 
 | 403 |  * header to be directly in front of the payload in that case. | 
 | 404 |  */ | 
 | 405 | static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx) | 
 | 406 | { | 
 | 407 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG | 
 | 408 | 	WARN_ONCE((unsigned long)rx->skb->data & 1, | 
 | 409 | 		  "unaligned packet at 0x%p\n", rx->skb->data); | 
 | 410 | #endif | 
 | 411 | } | 
 | 412 |  | 
 | 413 |  | 
 | 414 | /* rx handlers */ | 
 | 415 |  | 
 | 416 | static ieee80211_rx_result debug_noinline | 
 | 417 | ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx) | 
 | 418 | { | 
 | 419 | 	struct ieee80211_local *local = rx->local; | 
 | 420 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); | 
 | 421 | 	struct sk_buff *skb = rx->skb; | 
 | 422 |  | 
 | 423 | 	if (likely(!(status->rx_flags & IEEE80211_RX_IN_SCAN) && | 
 | 424 | 		   !local->sched_scanning)) | 
 | 425 | 		return RX_CONTINUE; | 
 | 426 |  | 
 | 427 | 	if (test_bit(SCAN_HW_SCANNING, &local->scanning) || | 
 | 428 | 	    test_bit(SCAN_SW_SCANNING, &local->scanning) || | 
 | 429 | 	    local->sched_scanning) | 
 | 430 | 		return ieee80211_scan_rx(rx->sdata, skb); | 
 | 431 |  | 
 | 432 | 	/* scanning finished during invoking of handlers */ | 
 | 433 | 	I802_DEBUG_INC(local->rx_handlers_drop_passive_scan); | 
 | 434 | 	return RX_DROP_UNUSABLE; | 
 | 435 | } | 
 | 436 |  | 
 | 437 |  | 
 | 438 | static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb) | 
 | 439 | { | 
 | 440 | 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | 
 | 441 |  | 
 | 442 | 	if (skb->len < 24 || is_multicast_ether_addr(hdr->addr1)) | 
 | 443 | 		return 0; | 
 | 444 |  | 
 | 445 | 	return ieee80211_is_robust_mgmt_frame(hdr); | 
 | 446 | } | 
 | 447 |  | 
 | 448 |  | 
 | 449 | static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb) | 
 | 450 | { | 
 | 451 | 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | 
 | 452 |  | 
 | 453 | 	if (skb->len < 24 || !is_multicast_ether_addr(hdr->addr1)) | 
 | 454 | 		return 0; | 
 | 455 |  | 
 | 456 | 	return ieee80211_is_robust_mgmt_frame(hdr); | 
 | 457 | } | 
 | 458 |  | 
 | 459 |  | 
 | 460 | /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */ | 
 | 461 | static int ieee80211_get_mmie_keyidx(struct sk_buff *skb) | 
 | 462 | { | 
 | 463 | 	struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data; | 
 | 464 | 	struct ieee80211_mmie *mmie; | 
 | 465 |  | 
 | 466 | 	if (skb->len < 24 + sizeof(*mmie) || | 
 | 467 | 	    !is_multicast_ether_addr(hdr->da)) | 
 | 468 | 		return -1; | 
 | 469 |  | 
 | 470 | 	if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *) hdr)) | 
 | 471 | 		return -1; /* not a robust management frame */ | 
 | 472 |  | 
 | 473 | 	mmie = (struct ieee80211_mmie *) | 
 | 474 | 		(skb->data + skb->len - sizeof(*mmie)); | 
 | 475 | 	if (mmie->element_id != WLAN_EID_MMIE || | 
 | 476 | 	    mmie->length != sizeof(*mmie) - 2) | 
 | 477 | 		return -1; | 
 | 478 |  | 
 | 479 | 	return le16_to_cpu(mmie->key_id); | 
 | 480 | } | 
 | 481 |  | 
 | 482 |  | 
 | 483 | static ieee80211_rx_result | 
 | 484 | ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx) | 
 | 485 | { | 
 | 486 | 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; | 
 | 487 | 	char *dev_addr = rx->sdata->vif.addr; | 
 | 488 |  | 
 | 489 | 	if (ieee80211_is_data(hdr->frame_control)) { | 
 | 490 | 		if (is_multicast_ether_addr(hdr->addr1)) { | 
 | 491 | 			if (ieee80211_has_tods(hdr->frame_control) || | 
 | 492 | 				!ieee80211_has_fromds(hdr->frame_control)) | 
 | 493 | 				return RX_DROP_MONITOR; | 
 | 494 | 			if (compare_ether_addr(hdr->addr3, dev_addr) == 0) | 
 | 495 | 				return RX_DROP_MONITOR; | 
 | 496 | 		} else { | 
 | 497 | 			if (!ieee80211_has_a4(hdr->frame_control)) | 
 | 498 | 				return RX_DROP_MONITOR; | 
 | 499 | 			if (compare_ether_addr(hdr->addr4, dev_addr) == 0) | 
 | 500 | 				return RX_DROP_MONITOR; | 
 | 501 | 		} | 
 | 502 | 	} | 
 | 503 |  | 
 | 504 | 	/* If there is not an established peer link and this is not a peer link | 
 | 505 | 	 * establisment frame, beacon or probe, drop the frame. | 
 | 506 | 	 */ | 
 | 507 |  | 
 | 508 | 	if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) { | 
 | 509 | 		struct ieee80211_mgmt *mgmt; | 
 | 510 |  | 
 | 511 | 		if (!ieee80211_is_mgmt(hdr->frame_control)) | 
 | 512 | 			return RX_DROP_MONITOR; | 
 | 513 |  | 
 | 514 | 		if (ieee80211_is_action(hdr->frame_control)) { | 
 | 515 | 			u8 category; | 
 | 516 |  | 
 | 517 | 			/* make sure category field is present */ | 
 | 518 | 			if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE) | 
 | 519 | 				return RX_DROP_MONITOR; | 
 | 520 |  | 
 | 521 | 			mgmt = (struct ieee80211_mgmt *)hdr; | 
 | 522 | 			category = mgmt->u.action.category; | 
 | 523 | 			if (category != WLAN_CATEGORY_MESH_ACTION && | 
 | 524 | 				category != WLAN_CATEGORY_SELF_PROTECTED) | 
 | 525 | 				return RX_DROP_MONITOR; | 
 | 526 | 			return RX_CONTINUE; | 
 | 527 | 		} | 
 | 528 |  | 
 | 529 | 		if (ieee80211_is_probe_req(hdr->frame_control) || | 
 | 530 | 		    ieee80211_is_probe_resp(hdr->frame_control) || | 
 | 531 | 		    ieee80211_is_beacon(hdr->frame_control) || | 
 | 532 | 		    ieee80211_is_auth(hdr->frame_control)) | 
 | 533 | 			return RX_CONTINUE; | 
 | 534 |  | 
 | 535 | 		return RX_DROP_MONITOR; | 
 | 536 |  | 
 | 537 | 	} | 
 | 538 |  | 
 | 539 | 	return RX_CONTINUE; | 
 | 540 | } | 
 | 541 |  | 
 | 542 | #define SEQ_MODULO 0x1000 | 
 | 543 | #define SEQ_MASK   0xfff | 
 | 544 |  | 
 | 545 | static inline int seq_less(u16 sq1, u16 sq2) | 
 | 546 | { | 
 | 547 | 	return ((sq1 - sq2) & SEQ_MASK) > (SEQ_MODULO >> 1); | 
 | 548 | } | 
 | 549 |  | 
 | 550 | static inline u16 seq_inc(u16 sq) | 
 | 551 | { | 
 | 552 | 	return (sq + 1) & SEQ_MASK; | 
 | 553 | } | 
 | 554 |  | 
 | 555 | static inline u16 seq_sub(u16 sq1, u16 sq2) | 
 | 556 | { | 
 | 557 | 	return (sq1 - sq2) & SEQ_MASK; | 
 | 558 | } | 
 | 559 |  | 
 | 560 |  | 
 | 561 | static void ieee80211_release_reorder_frame(struct ieee80211_hw *hw, | 
 | 562 | 					    struct tid_ampdu_rx *tid_agg_rx, | 
 | 563 | 					    int index) | 
 | 564 | { | 
 | 565 | 	struct ieee80211_local *local = hw_to_local(hw); | 
 | 566 | 	struct sk_buff *skb = tid_agg_rx->reorder_buf[index]; | 
 | 567 | 	struct ieee80211_rx_status *status; | 
 | 568 |  | 
 | 569 | 	lockdep_assert_held(&tid_agg_rx->reorder_lock); | 
 | 570 |  | 
 | 571 | 	if (!skb) | 
 | 572 | 		goto no_frame; | 
 | 573 |  | 
 | 574 | 	/* release the frame from the reorder ring buffer */ | 
 | 575 | 	tid_agg_rx->stored_mpdu_num--; | 
 | 576 | 	tid_agg_rx->reorder_buf[index] = NULL; | 
 | 577 | 	status = IEEE80211_SKB_RXCB(skb); | 
 | 578 | 	status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE; | 
 | 579 | 	skb_queue_tail(&local->rx_skb_queue, skb); | 
 | 580 |  | 
 | 581 | no_frame: | 
 | 582 | 	tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num); | 
 | 583 | } | 
 | 584 |  | 
 | 585 | static void ieee80211_release_reorder_frames(struct ieee80211_hw *hw, | 
 | 586 | 					     struct tid_ampdu_rx *tid_agg_rx, | 
 | 587 | 					     u16 head_seq_num) | 
 | 588 | { | 
 | 589 | 	int index; | 
 | 590 |  | 
 | 591 | 	lockdep_assert_held(&tid_agg_rx->reorder_lock); | 
 | 592 |  | 
 | 593 | 	while (seq_less(tid_agg_rx->head_seq_num, head_seq_num)) { | 
 | 594 | 		index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) % | 
 | 595 | 							tid_agg_rx->buf_size; | 
 | 596 | 		ieee80211_release_reorder_frame(hw, tid_agg_rx, index); | 
 | 597 | 	} | 
 | 598 | } | 
 | 599 |  | 
 | 600 | /* | 
 | 601 |  * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If | 
 | 602 |  * the skb was added to the buffer longer than this time ago, the earlier | 
 | 603 |  * frames that have not yet been received are assumed to be lost and the skb | 
 | 604 |  * can be released for processing. This may also release other skb's from the | 
 | 605 |  * reorder buffer if there are no additional gaps between the frames. | 
 | 606 |  * | 
 | 607 |  * Callers must hold tid_agg_rx->reorder_lock. | 
 | 608 |  */ | 
 | 609 | #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10) | 
 | 610 |  | 
 | 611 | static void ieee80211_sta_reorder_release(struct ieee80211_hw *hw, | 
 | 612 | 					  struct tid_ampdu_rx *tid_agg_rx) | 
 | 613 | { | 
 | 614 | 	int index, j; | 
 | 615 |  | 
 | 616 | 	lockdep_assert_held(&tid_agg_rx->reorder_lock); | 
 | 617 |  | 
 | 618 | 	/* release the buffer until next missing frame */ | 
 | 619 | 	index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) % | 
 | 620 | 						tid_agg_rx->buf_size; | 
 | 621 | 	if (!tid_agg_rx->reorder_buf[index] && | 
 | 622 | 	    tid_agg_rx->stored_mpdu_num) { | 
 | 623 | 		/* | 
 | 624 | 		 * No buffers ready to be released, but check whether any | 
 | 625 | 		 * frames in the reorder buffer have timed out. | 
 | 626 | 		 */ | 
 | 627 | 		int skipped = 1; | 
 | 628 | 		for (j = (index + 1) % tid_agg_rx->buf_size; j != index; | 
 | 629 | 		     j = (j + 1) % tid_agg_rx->buf_size) { | 
 | 630 | 			if (!tid_agg_rx->reorder_buf[j]) { | 
 | 631 | 				skipped++; | 
 | 632 | 				continue; | 
 | 633 | 			} | 
 | 634 | 			if (skipped && | 
 | 635 | 			    !time_after(jiffies, tid_agg_rx->reorder_time[j] + | 
 | 636 | 					HT_RX_REORDER_BUF_TIMEOUT)) | 
 | 637 | 				goto set_release_timer; | 
 | 638 |  | 
 | 639 | #ifdef CONFIG_MAC80211_HT_DEBUG | 
 | 640 | 			if (net_ratelimit()) | 
 | 641 | 				wiphy_debug(hw->wiphy, | 
 | 642 | 					    "release an RX reorder frame due to timeout on earlier frames\n"); | 
 | 643 | #endif | 
 | 644 | 			ieee80211_release_reorder_frame(hw, tid_agg_rx, j); | 
 | 645 |  | 
 | 646 | 			/* | 
 | 647 | 			 * Increment the head seq# also for the skipped slots. | 
 | 648 | 			 */ | 
 | 649 | 			tid_agg_rx->head_seq_num = | 
 | 650 | 				(tid_agg_rx->head_seq_num + skipped) & SEQ_MASK; | 
 | 651 | 			skipped = 0; | 
 | 652 | 		} | 
 | 653 | 	} else while (tid_agg_rx->reorder_buf[index]) { | 
 | 654 | 		ieee80211_release_reorder_frame(hw, tid_agg_rx, index); | 
 | 655 | 		index =	seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) % | 
 | 656 | 							tid_agg_rx->buf_size; | 
 | 657 | 	} | 
 | 658 |  | 
 | 659 | 	if (tid_agg_rx->stored_mpdu_num) { | 
 | 660 | 		j = index = seq_sub(tid_agg_rx->head_seq_num, | 
 | 661 | 				    tid_agg_rx->ssn) % tid_agg_rx->buf_size; | 
 | 662 |  | 
 | 663 | 		for (; j != (index - 1) % tid_agg_rx->buf_size; | 
 | 664 | 		     j = (j + 1) % tid_agg_rx->buf_size) { | 
 | 665 | 			if (tid_agg_rx->reorder_buf[j]) | 
 | 666 | 				break; | 
 | 667 | 		} | 
 | 668 |  | 
 | 669 |  set_release_timer: | 
 | 670 |  | 
 | 671 | 		if (!tid_agg_rx->removed) | 
 | 672 | 			mod_timer(&tid_agg_rx->reorder_timer, | 
 | 673 | 				  tid_agg_rx->reorder_time[j] + 1 + | 
 | 674 | 				  HT_RX_REORDER_BUF_TIMEOUT); | 
 | 675 | 	} else { | 
 | 676 | 		del_timer(&tid_agg_rx->reorder_timer); | 
 | 677 | 	} | 
 | 678 | } | 
 | 679 |  | 
 | 680 | /* | 
 | 681 |  * As this function belongs to the RX path it must be under | 
 | 682 |  * rcu_read_lock protection. It returns false if the frame | 
 | 683 |  * can be processed immediately, true if it was consumed. | 
 | 684 |  */ | 
 | 685 | static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw, | 
 | 686 | 					     struct tid_ampdu_rx *tid_agg_rx, | 
 | 687 | 					     struct sk_buff *skb) | 
 | 688 | { | 
 | 689 | 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | 
 | 690 | 	u16 sc = le16_to_cpu(hdr->seq_ctrl); | 
 | 691 | 	u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4; | 
 | 692 | 	u16 head_seq_num, buf_size; | 
 | 693 | 	int index; | 
 | 694 | 	bool ret = true; | 
 | 695 |  | 
 | 696 | 	spin_lock(&tid_agg_rx->reorder_lock); | 
 | 697 |  | 
 | 698 | 	buf_size = tid_agg_rx->buf_size; | 
 | 699 | 	head_seq_num = tid_agg_rx->head_seq_num; | 
 | 700 |  | 
 | 701 | 	/* frame with out of date sequence number */ | 
 | 702 | 	if (seq_less(mpdu_seq_num, head_seq_num)) { | 
 | 703 | 		dev_kfree_skb(skb); | 
 | 704 | 		goto out; | 
 | 705 | 	} | 
 | 706 |  | 
 | 707 | 	/* | 
 | 708 | 	 * If frame the sequence number exceeds our buffering window | 
 | 709 | 	 * size release some previous frames to make room for this one. | 
 | 710 | 	 */ | 
 | 711 | 	if (!seq_less(mpdu_seq_num, head_seq_num + buf_size)) { | 
 | 712 | 		head_seq_num = seq_inc(seq_sub(mpdu_seq_num, buf_size)); | 
 | 713 | 		/* release stored frames up to new head to stack */ | 
 | 714 | 		ieee80211_release_reorder_frames(hw, tid_agg_rx, head_seq_num); | 
 | 715 | 	} | 
 | 716 |  | 
 | 717 | 	/* Now the new frame is always in the range of the reordering buffer */ | 
 | 718 |  | 
 | 719 | 	index = seq_sub(mpdu_seq_num, tid_agg_rx->ssn) % tid_agg_rx->buf_size; | 
 | 720 |  | 
 | 721 | 	/* check if we already stored this frame */ | 
 | 722 | 	if (tid_agg_rx->reorder_buf[index]) { | 
 | 723 | 		dev_kfree_skb(skb); | 
 | 724 | 		goto out; | 
 | 725 | 	} | 
 | 726 |  | 
 | 727 | 	/* | 
 | 728 | 	 * If the current MPDU is in the right order and nothing else | 
 | 729 | 	 * is stored we can process it directly, no need to buffer it. | 
 | 730 | 	 * If it is first but there's something stored, we may be able | 
 | 731 | 	 * to release frames after this one. | 
 | 732 | 	 */ | 
 | 733 | 	if (mpdu_seq_num == tid_agg_rx->head_seq_num && | 
 | 734 | 	    tid_agg_rx->stored_mpdu_num == 0) { | 
 | 735 | 		tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num); | 
 | 736 | 		ret = false; | 
 | 737 | 		goto out; | 
 | 738 | 	} | 
 | 739 |  | 
 | 740 | 	/* put the frame in the reordering buffer */ | 
 | 741 | 	tid_agg_rx->reorder_buf[index] = skb; | 
 | 742 | 	tid_agg_rx->reorder_time[index] = jiffies; | 
 | 743 | 	tid_agg_rx->stored_mpdu_num++; | 
 | 744 | 	ieee80211_sta_reorder_release(hw, tid_agg_rx); | 
 | 745 |  | 
 | 746 |  out: | 
 | 747 | 	spin_unlock(&tid_agg_rx->reorder_lock); | 
 | 748 | 	return ret; | 
 | 749 | } | 
 | 750 |  | 
 | 751 | /* | 
 | 752 |  * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns | 
 | 753 |  * true if the MPDU was buffered, false if it should be processed. | 
 | 754 |  */ | 
 | 755 | static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx) | 
 | 756 | { | 
 | 757 | 	struct sk_buff *skb = rx->skb; | 
 | 758 | 	struct ieee80211_local *local = rx->local; | 
 | 759 | 	struct ieee80211_hw *hw = &local->hw; | 
 | 760 | 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | 
 | 761 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); | 
 | 762 | 	struct sta_info *sta = rx->sta; | 
 | 763 | 	struct tid_ampdu_rx *tid_agg_rx; | 
 | 764 | 	u16 sc; | 
 | 765 | 	u8 tid, ack_policy; | 
 | 766 |  | 
 | 767 | 	if (!ieee80211_is_data_qos(hdr->frame_control) || | 
 | 768 | 	    is_multicast_ether_addr(hdr->addr1)) | 
 | 769 | 		goto dont_reorder; | 
 | 770 |  | 
 | 771 | 	/* | 
 | 772 | 	 * filter the QoS data rx stream according to | 
 | 773 | 	 * STA/TID and check if this STA/TID is on aggregation | 
 | 774 | 	 */ | 
 | 775 |  | 
 | 776 | 	if (!sta) | 
 | 777 | 		goto dont_reorder; | 
 | 778 |  | 
 | 779 | 	ack_policy = *ieee80211_get_qos_ctl(hdr) & | 
 | 780 | 		     IEEE80211_QOS_CTL_ACK_POLICY_MASK; | 
 | 781 | 	tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK; | 
 | 782 |  | 
 | 783 | 	tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]); | 
 | 784 | 	if (!tid_agg_rx) | 
 | 785 | 		goto dont_reorder; | 
 | 786 |  | 
 | 787 | 	/* qos null data frames are excluded */ | 
 | 788 | 	if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC))) | 
 | 789 | 		goto dont_reorder; | 
 | 790 |  | 
 | 791 | 	/* not part of a BA session */ | 
 | 792 | 	if (ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK && | 
 | 793 | 	    ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_NORMAL) | 
 | 794 | 		goto dont_reorder; | 
 | 795 |  | 
 | 796 | 	/* not actually part of this BA session */ | 
 | 797 | 	if (!(status->rx_flags & IEEE80211_RX_RA_MATCH)) | 
 | 798 | 		goto dont_reorder; | 
 | 799 |  | 
 | 800 | 	/* new, potentially un-ordered, ampdu frame - process it */ | 
 | 801 |  | 
 | 802 | 	/* reset session timer */ | 
 | 803 | 	if (tid_agg_rx->timeout) | 
 | 804 | 		mod_timer(&tid_agg_rx->session_timer, | 
 | 805 | 			  TU_TO_EXP_TIME(tid_agg_rx->timeout)); | 
 | 806 |  | 
 | 807 | 	/* if this mpdu is fragmented - terminate rx aggregation session */ | 
 | 808 | 	sc = le16_to_cpu(hdr->seq_ctrl); | 
 | 809 | 	if (sc & IEEE80211_SCTL_FRAG) { | 
 | 810 | 		skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME; | 
 | 811 | 		skb_queue_tail(&rx->sdata->skb_queue, skb); | 
 | 812 | 		ieee80211_queue_work(&local->hw, &rx->sdata->work); | 
 | 813 | 		return; | 
 | 814 | 	} | 
 | 815 |  | 
 | 816 | 	/* | 
 | 817 | 	 * No locking needed -- we will only ever process one | 
 | 818 | 	 * RX packet at a time, and thus own tid_agg_rx. All | 
 | 819 | 	 * other code manipulating it needs to (and does) make | 
 | 820 | 	 * sure that we cannot get to it any more before doing | 
 | 821 | 	 * anything with it. | 
 | 822 | 	 */ | 
 | 823 | 	if (ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb)) | 
 | 824 | 		return; | 
 | 825 |  | 
 | 826 |  dont_reorder: | 
 | 827 | 	skb_queue_tail(&local->rx_skb_queue, skb); | 
 | 828 | } | 
 | 829 |  | 
 | 830 | static ieee80211_rx_result debug_noinline | 
 | 831 | ieee80211_rx_h_check(struct ieee80211_rx_data *rx) | 
 | 832 | { | 
 | 833 | 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; | 
 | 834 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); | 
 | 835 |  | 
 | 836 | 	/* | 
 | 837 | 	 * Drop duplicate 802.11 retransmissions | 
 | 838 | 	 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery") | 
 | 839 | 	 */ | 
 | 840 | 	if (rx->skb->len >= 24 && rx->sta && | 
 | 841 | 	    !ieee80211_is_ctl(hdr->frame_control) && | 
 | 842 | 	    !ieee80211_is_qos_nullfunc(hdr->frame_control) && | 
 | 843 | 	    !is_multicast_ether_addr(hdr->addr1)) { | 
 | 844 | 		if (unlikely(ieee80211_has_retry(hdr->frame_control) && | 
 | 845 | 			     rx->sta->last_seq_ctrl[rx->seqno_idx] == | 
 | 846 | 			     hdr->seq_ctrl)) { | 
 | 847 | 			if (status->rx_flags & IEEE80211_RX_RA_MATCH) { | 
 | 848 | 				rx->local->dot11FrameDuplicateCount++; | 
 | 849 | 				rx->sta->num_duplicates++; | 
 | 850 | 			} | 
 | 851 | 			return RX_DROP_UNUSABLE; | 
 | 852 | 		} else | 
 | 853 | 			rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl; | 
 | 854 | 	} | 
 | 855 |  | 
 | 856 | 	if (unlikely(rx->skb->len < 16)) { | 
 | 857 | 		I802_DEBUG_INC(rx->local->rx_handlers_drop_short); | 
 | 858 | 		return RX_DROP_MONITOR; | 
 | 859 | 	} | 
 | 860 |  | 
 | 861 | 	/* Drop disallowed frame classes based on STA auth/assoc state; | 
 | 862 | 	 * IEEE 802.11, Chap 5.5. | 
 | 863 | 	 * | 
 | 864 | 	 * mac80211 filters only based on association state, i.e. it drops | 
 | 865 | 	 * Class 3 frames from not associated stations. hostapd sends | 
 | 866 | 	 * deauth/disassoc frames when needed. In addition, hostapd is | 
 | 867 | 	 * responsible for filtering on both auth and assoc states. | 
 | 868 | 	 */ | 
 | 869 |  | 
 | 870 | 	if (ieee80211_vif_is_mesh(&rx->sdata->vif)) | 
 | 871 | 		return ieee80211_rx_mesh_check(rx); | 
 | 872 |  | 
 | 873 | 	if (unlikely((ieee80211_is_data(hdr->frame_control) || | 
 | 874 | 		      ieee80211_is_pspoll(hdr->frame_control)) && | 
 | 875 | 		     rx->sdata->vif.type != NL80211_IFTYPE_ADHOC && | 
 | 876 | 		     rx->sdata->vif.type != NL80211_IFTYPE_WDS && | 
 | 877 | 		     (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) { | 
 | 878 | 		/* | 
 | 879 | 		 * accept port control frames from the AP even when it's not | 
 | 880 | 		 * yet marked ASSOC to prevent a race where we don't set the | 
 | 881 | 		 * assoc bit quickly enough before it sends the first frame | 
 | 882 | 		 */ | 
 | 883 | 		if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION && | 
 | 884 | 		    ieee80211_is_data_present(hdr->frame_control)) { | 
 | 885 | 			unsigned int hdrlen; | 
 | 886 | 			__be16 ethertype; | 
 | 887 |  | 
 | 888 | 			hdrlen = ieee80211_hdrlen(hdr->frame_control); | 
 | 889 |  | 
 | 890 | 			if (rx->skb->len < hdrlen + 8) | 
 | 891 | 				return RX_DROP_MONITOR; | 
 | 892 |  | 
 | 893 | 			skb_copy_bits(rx->skb, hdrlen + 6, ðertype, 2); | 
 | 894 | 			if (ethertype == rx->sdata->control_port_protocol) | 
 | 895 | 				return RX_CONTINUE; | 
 | 896 | 		} | 
 | 897 |  | 
 | 898 | 		if (rx->sdata->vif.type == NL80211_IFTYPE_AP && | 
 | 899 | 		    cfg80211_rx_spurious_frame(rx->sdata->dev, | 
 | 900 | 					       hdr->addr2, | 
 | 901 | 					       GFP_ATOMIC)) | 
 | 902 | 			return RX_DROP_UNUSABLE; | 
 | 903 |  | 
 | 904 | 		return RX_DROP_MONITOR; | 
 | 905 | 	} | 
 | 906 |  | 
 | 907 | 	return RX_CONTINUE; | 
 | 908 | } | 
 | 909 |  | 
 | 910 |  | 
 | 911 | static ieee80211_rx_result debug_noinline | 
 | 912 | ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx) | 
 | 913 | { | 
 | 914 | 	struct sk_buff *skb = rx->skb; | 
 | 915 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); | 
 | 916 | 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | 
 | 917 | 	int keyidx; | 
 | 918 | 	int hdrlen; | 
 | 919 | 	ieee80211_rx_result result = RX_DROP_UNUSABLE; | 
 | 920 | 	struct ieee80211_key *sta_ptk = NULL; | 
 | 921 | 	int mmie_keyidx = -1; | 
 | 922 | 	__le16 fc; | 
 | 923 |  | 
 | 924 | 	/* | 
 | 925 | 	 * Key selection 101 | 
 | 926 | 	 * | 
 | 927 | 	 * There are four types of keys: | 
 | 928 | 	 *  - GTK (group keys) | 
 | 929 | 	 *  - IGTK (group keys for management frames) | 
 | 930 | 	 *  - PTK (pairwise keys) | 
 | 931 | 	 *  - STK (station-to-station pairwise keys) | 
 | 932 | 	 * | 
 | 933 | 	 * When selecting a key, we have to distinguish between multicast | 
 | 934 | 	 * (including broadcast) and unicast frames, the latter can only | 
 | 935 | 	 * use PTKs and STKs while the former always use GTKs and IGTKs. | 
 | 936 | 	 * Unless, of course, actual WEP keys ("pre-RSNA") are used, then | 
 | 937 | 	 * unicast frames can also use key indices like GTKs. Hence, if we | 
 | 938 | 	 * don't have a PTK/STK we check the key index for a WEP key. | 
 | 939 | 	 * | 
 | 940 | 	 * Note that in a regular BSS, multicast frames are sent by the | 
 | 941 | 	 * AP only, associated stations unicast the frame to the AP first | 
 | 942 | 	 * which then multicasts it on their behalf. | 
 | 943 | 	 * | 
 | 944 | 	 * There is also a slight problem in IBSS mode: GTKs are negotiated | 
 | 945 | 	 * with each station, that is something we don't currently handle. | 
 | 946 | 	 * The spec seems to expect that one negotiates the same key with | 
 | 947 | 	 * every station but there's no such requirement; VLANs could be | 
 | 948 | 	 * possible. | 
 | 949 | 	 */ | 
 | 950 |  | 
 | 951 | 	/* | 
 | 952 | 	 * No point in finding a key and decrypting if the frame is neither | 
 | 953 | 	 * addressed to us nor a multicast frame. | 
 | 954 | 	 */ | 
 | 955 | 	if (!(status->rx_flags & IEEE80211_RX_RA_MATCH)) | 
 | 956 | 		return RX_CONTINUE; | 
 | 957 |  | 
 | 958 | 	/* start without a key */ | 
 | 959 | 	rx->key = NULL; | 
 | 960 |  | 
 | 961 | 	if (rx->sta) | 
 | 962 | 		sta_ptk = rcu_dereference(rx->sta->ptk); | 
 | 963 |  | 
 | 964 | 	fc = hdr->frame_control; | 
 | 965 |  | 
 | 966 | 	if (!ieee80211_has_protected(fc)) | 
 | 967 | 		mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb); | 
 | 968 |  | 
 | 969 | 	if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) { | 
 | 970 | 		rx->key = sta_ptk; | 
 | 971 | 		if ((status->flag & RX_FLAG_DECRYPTED) && | 
 | 972 | 		    (status->flag & RX_FLAG_IV_STRIPPED)) | 
 | 973 | 			return RX_CONTINUE; | 
 | 974 | 		/* Skip decryption if the frame is not protected. */ | 
 | 975 | 		if (!ieee80211_has_protected(fc)) | 
 | 976 | 			return RX_CONTINUE; | 
 | 977 | 	} else if (mmie_keyidx >= 0) { | 
 | 978 | 		/* Broadcast/multicast robust management frame / BIP */ | 
 | 979 | 		if ((status->flag & RX_FLAG_DECRYPTED) && | 
 | 980 | 		    (status->flag & RX_FLAG_IV_STRIPPED)) | 
 | 981 | 			return RX_CONTINUE; | 
 | 982 |  | 
 | 983 | 		if (mmie_keyidx < NUM_DEFAULT_KEYS || | 
 | 984 | 		    mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) | 
 | 985 | 			return RX_DROP_MONITOR; /* unexpected BIP keyidx */ | 
 | 986 | 		if (rx->sta) | 
 | 987 | 			rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]); | 
 | 988 | 		if (!rx->key) | 
 | 989 | 			rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]); | 
 | 990 | 	} else if (!ieee80211_has_protected(fc)) { | 
 | 991 | 		/* | 
 | 992 | 		 * The frame was not protected, so skip decryption. However, we | 
 | 993 | 		 * need to set rx->key if there is a key that could have been | 
 | 994 | 		 * used so that the frame may be dropped if encryption would | 
 | 995 | 		 * have been expected. | 
 | 996 | 		 */ | 
 | 997 | 		struct ieee80211_key *key = NULL; | 
 | 998 | 		struct ieee80211_sub_if_data *sdata = rx->sdata; | 
 | 999 | 		int i; | 
 | 1000 |  | 
 | 1001 | 		if (ieee80211_is_mgmt(fc) && | 
 | 1002 | 		    is_multicast_ether_addr(hdr->addr1) && | 
 | 1003 | 		    (key = rcu_dereference(rx->sdata->default_mgmt_key))) | 
 | 1004 | 			rx->key = key; | 
 | 1005 | 		else { | 
 | 1006 | 			if (rx->sta) { | 
 | 1007 | 				for (i = 0; i < NUM_DEFAULT_KEYS; i++) { | 
 | 1008 | 					key = rcu_dereference(rx->sta->gtk[i]); | 
 | 1009 | 					if (key) | 
 | 1010 | 						break; | 
 | 1011 | 				} | 
 | 1012 | 			} | 
 | 1013 | 			if (!key) { | 
 | 1014 | 				for (i = 0; i < NUM_DEFAULT_KEYS; i++) { | 
 | 1015 | 					key = rcu_dereference(sdata->keys[i]); | 
 | 1016 | 					if (key) | 
 | 1017 | 						break; | 
 | 1018 | 				} | 
 | 1019 | 			} | 
 | 1020 | 			if (key) | 
 | 1021 | 				rx->key = key; | 
 | 1022 | 		} | 
 | 1023 | 		return RX_CONTINUE; | 
 | 1024 | 	} else { | 
 | 1025 | 		u8 keyid; | 
 | 1026 | 		/* | 
 | 1027 | 		 * The device doesn't give us the IV so we won't be | 
 | 1028 | 		 * able to look up the key. That's ok though, we | 
 | 1029 | 		 * don't need to decrypt the frame, we just won't | 
 | 1030 | 		 * be able to keep statistics accurate. | 
 | 1031 | 		 * Except for key threshold notifications, should | 
 | 1032 | 		 * we somehow allow the driver to tell us which key | 
 | 1033 | 		 * the hardware used if this flag is set? | 
 | 1034 | 		 */ | 
 | 1035 | 		if ((status->flag & RX_FLAG_DECRYPTED) && | 
 | 1036 | 		    (status->flag & RX_FLAG_IV_STRIPPED)) | 
 | 1037 | 			return RX_CONTINUE; | 
 | 1038 |  | 
 | 1039 | 		hdrlen = ieee80211_hdrlen(fc); | 
 | 1040 |  | 
 | 1041 | 		if (rx->skb->len < 8 + hdrlen) | 
 | 1042 | 			return RX_DROP_UNUSABLE; /* TODO: count this? */ | 
 | 1043 |  | 
 | 1044 | 		/* | 
 | 1045 | 		 * no need to call ieee80211_wep_get_keyidx, | 
 | 1046 | 		 * it verifies a bunch of things we've done already | 
 | 1047 | 		 */ | 
 | 1048 | 		skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1); | 
 | 1049 | 		keyidx = keyid >> 6; | 
 | 1050 |  | 
 | 1051 | 		/* check per-station GTK first, if multicast packet */ | 
 | 1052 | 		if (is_multicast_ether_addr(hdr->addr1) && rx->sta) | 
 | 1053 | 			rx->key = rcu_dereference(rx->sta->gtk[keyidx]); | 
 | 1054 |  | 
 | 1055 | 		/* if not found, try default key */ | 
 | 1056 | 		if (!rx->key) { | 
 | 1057 | 			rx->key = rcu_dereference(rx->sdata->keys[keyidx]); | 
 | 1058 |  | 
 | 1059 | 			/* | 
 | 1060 | 			 * RSNA-protected unicast frames should always be | 
 | 1061 | 			 * sent with pairwise or station-to-station keys, | 
 | 1062 | 			 * but for WEP we allow using a key index as well. | 
 | 1063 | 			 */ | 
 | 1064 | 			if (rx->key && | 
 | 1065 | 			    rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 && | 
 | 1066 | 			    rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 && | 
 | 1067 | 			    !is_multicast_ether_addr(hdr->addr1)) | 
 | 1068 | 				rx->key = NULL; | 
 | 1069 | 		} | 
 | 1070 | 	} | 
 | 1071 |  | 
 | 1072 | 	if (rx->key) { | 
 | 1073 | 		if (unlikely(rx->key->flags & KEY_FLAG_TAINTED)) | 
 | 1074 | 			return RX_DROP_MONITOR; | 
 | 1075 |  | 
 | 1076 | 		rx->key->tx_rx_count++; | 
 | 1077 | 		/* TODO: add threshold stuff again */ | 
 | 1078 | 	} else { | 
 | 1079 | 		return RX_DROP_MONITOR; | 
 | 1080 | 	} | 
 | 1081 |  | 
 | 1082 | 	switch (rx->key->conf.cipher) { | 
 | 1083 | 	case WLAN_CIPHER_SUITE_WEP40: | 
 | 1084 | 	case WLAN_CIPHER_SUITE_WEP104: | 
 | 1085 | 		result = ieee80211_crypto_wep_decrypt(rx); | 
 | 1086 | 		break; | 
 | 1087 | 	case WLAN_CIPHER_SUITE_TKIP: | 
 | 1088 | 		result = ieee80211_crypto_tkip_decrypt(rx); | 
 | 1089 | 		break; | 
 | 1090 | 	case WLAN_CIPHER_SUITE_CCMP: | 
 | 1091 | 		result = ieee80211_crypto_ccmp_decrypt(rx); | 
 | 1092 | 		break; | 
 | 1093 | 	case WLAN_CIPHER_SUITE_AES_CMAC: | 
 | 1094 | 		result = ieee80211_crypto_aes_cmac_decrypt(rx); | 
 | 1095 | 		break; | 
 | 1096 | 	default: | 
 | 1097 | 		/* | 
 | 1098 | 		 * We can reach here only with HW-only algorithms | 
 | 1099 | 		 * but why didn't it decrypt the frame?! | 
 | 1100 | 		 */ | 
 | 1101 | 		return RX_DROP_UNUSABLE; | 
 | 1102 | 	} | 
 | 1103 |  | 
 | 1104 | 	/* the hdr variable is invalid after the decrypt handlers */ | 
 | 1105 |  | 
 | 1106 | 	/* either the frame has been decrypted or will be dropped */ | 
 | 1107 | 	status->flag |= RX_FLAG_DECRYPTED; | 
 | 1108 |  | 
 | 1109 | 	return result; | 
 | 1110 | } | 
 | 1111 |  | 
 | 1112 | static ieee80211_rx_result debug_noinline | 
 | 1113 | ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx) | 
 | 1114 | { | 
 | 1115 | 	struct ieee80211_local *local; | 
 | 1116 | 	struct ieee80211_hdr *hdr; | 
 | 1117 | 	struct sk_buff *skb; | 
 | 1118 |  | 
 | 1119 | 	local = rx->local; | 
 | 1120 | 	skb = rx->skb; | 
 | 1121 | 	hdr = (struct ieee80211_hdr *) skb->data; | 
 | 1122 |  | 
 | 1123 | 	if (!local->pspolling) | 
 | 1124 | 		return RX_CONTINUE; | 
 | 1125 |  | 
 | 1126 | 	if (!ieee80211_has_fromds(hdr->frame_control)) | 
 | 1127 | 		/* this is not from AP */ | 
 | 1128 | 		return RX_CONTINUE; | 
 | 1129 |  | 
 | 1130 | 	if (!ieee80211_is_data(hdr->frame_control)) | 
 | 1131 | 		return RX_CONTINUE; | 
 | 1132 |  | 
 | 1133 | 	if (!ieee80211_has_moredata(hdr->frame_control)) { | 
 | 1134 | 		/* AP has no more frames buffered for us */ | 
 | 1135 | 		local->pspolling = false; | 
 | 1136 | 		return RX_CONTINUE; | 
 | 1137 | 	} | 
 | 1138 |  | 
 | 1139 | 	/* more data bit is set, let's request a new frame from the AP */ | 
 | 1140 | 	ieee80211_send_pspoll(local, rx->sdata); | 
 | 1141 |  | 
 | 1142 | 	return RX_CONTINUE; | 
 | 1143 | } | 
 | 1144 |  | 
 | 1145 | static void ap_sta_ps_start(struct sta_info *sta) | 
 | 1146 | { | 
 | 1147 | 	struct ieee80211_sub_if_data *sdata = sta->sdata; | 
 | 1148 | 	struct ieee80211_local *local = sdata->local; | 
 | 1149 |  | 
 | 1150 | 	atomic_inc(&sdata->bss->num_sta_ps); | 
 | 1151 | 	set_sta_flag(sta, WLAN_STA_PS_STA); | 
 | 1152 | 	if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS)) | 
 | 1153 | 		drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta); | 
 | 1154 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG | 
 | 1155 | 	printk(KERN_DEBUG "%s: STA %pM aid %d enters power save mode\n", | 
 | 1156 | 	       sdata->name, sta->sta.addr, sta->sta.aid); | 
 | 1157 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ | 
 | 1158 | } | 
 | 1159 |  | 
 | 1160 | static void ap_sta_ps_end(struct sta_info *sta) | 
 | 1161 | { | 
 | 1162 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG | 
 | 1163 | 	printk(KERN_DEBUG "%s: STA %pM aid %d exits power save mode\n", | 
 | 1164 | 	       sta->sdata->name, sta->sta.addr, sta->sta.aid); | 
 | 1165 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ | 
 | 1166 |  | 
 | 1167 | 	if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) { | 
 | 1168 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG | 
 | 1169 | 		printk(KERN_DEBUG "%s: STA %pM aid %d driver-ps-blocked\n", | 
 | 1170 | 		       sta->sdata->name, sta->sta.addr, sta->sta.aid); | 
 | 1171 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ | 
 | 1172 | 		return; | 
 | 1173 | 	} | 
 | 1174 |  | 
 | 1175 | 	ieee80211_sta_ps_deliver_wakeup(sta); | 
 | 1176 | } | 
 | 1177 |  | 
 | 1178 | int ieee80211_sta_ps_transition(struct ieee80211_sta *sta, bool start) | 
 | 1179 | { | 
 | 1180 | 	struct sta_info *sta_inf = container_of(sta, struct sta_info, sta); | 
 | 1181 | 	bool in_ps; | 
 | 1182 |  | 
 | 1183 | 	WARN_ON(!(sta_inf->local->hw.flags & IEEE80211_HW_AP_LINK_PS)); | 
 | 1184 |  | 
 | 1185 | 	/* Don't let the same PS state be set twice */ | 
 | 1186 | 	in_ps = test_sta_flag(sta_inf, WLAN_STA_PS_STA); | 
 | 1187 | 	if ((start && in_ps) || (!start && !in_ps)) | 
 | 1188 | 		return -EINVAL; | 
 | 1189 |  | 
 | 1190 | 	if (start) | 
 | 1191 | 		ap_sta_ps_start(sta_inf); | 
 | 1192 | 	else | 
 | 1193 | 		ap_sta_ps_end(sta_inf); | 
 | 1194 |  | 
 | 1195 | 	return 0; | 
 | 1196 | } | 
 | 1197 | EXPORT_SYMBOL(ieee80211_sta_ps_transition); | 
 | 1198 |  | 
 | 1199 | static ieee80211_rx_result debug_noinline | 
 | 1200 | ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx) | 
 | 1201 | { | 
 | 1202 | 	struct ieee80211_sub_if_data *sdata = rx->sdata; | 
 | 1203 | 	struct ieee80211_hdr *hdr = (void *)rx->skb->data; | 
 | 1204 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); | 
 | 1205 | 	int tid, ac; | 
 | 1206 |  | 
 | 1207 | 	if (!rx->sta || !(status->rx_flags & IEEE80211_RX_RA_MATCH)) | 
 | 1208 | 		return RX_CONTINUE; | 
 | 1209 |  | 
 | 1210 | 	if (sdata->vif.type != NL80211_IFTYPE_AP && | 
 | 1211 | 	    sdata->vif.type != NL80211_IFTYPE_AP_VLAN) | 
 | 1212 | 		return RX_CONTINUE; | 
 | 1213 |  | 
 | 1214 | 	/* | 
 | 1215 | 	 * The device handles station powersave, so don't do anything about | 
 | 1216 | 	 * uAPSD and PS-Poll frames (the latter shouldn't even come up from | 
 | 1217 | 	 * it to mac80211 since they're handled.) | 
 | 1218 | 	 */ | 
 | 1219 | 	if (sdata->local->hw.flags & IEEE80211_HW_AP_LINK_PS) | 
 | 1220 | 		return RX_CONTINUE; | 
 | 1221 |  | 
 | 1222 | 	/* | 
 | 1223 | 	 * Don't do anything if the station isn't already asleep. In | 
 | 1224 | 	 * the uAPSD case, the station will probably be marked asleep, | 
 | 1225 | 	 * in the PS-Poll case the station must be confused ... | 
 | 1226 | 	 */ | 
 | 1227 | 	if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA)) | 
 | 1228 | 		return RX_CONTINUE; | 
 | 1229 |  | 
 | 1230 | 	if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) { | 
 | 1231 | 		if (!test_sta_flag(rx->sta, WLAN_STA_SP)) { | 
 | 1232 | 			if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER)) | 
 | 1233 | 				ieee80211_sta_ps_deliver_poll_response(rx->sta); | 
 | 1234 | 			else | 
 | 1235 | 				set_sta_flag(rx->sta, WLAN_STA_PSPOLL); | 
 | 1236 | 		} | 
 | 1237 |  | 
 | 1238 | 		/* Free PS Poll skb here instead of returning RX_DROP that would | 
 | 1239 | 		 * count as an dropped frame. */ | 
 | 1240 | 		dev_kfree_skb(rx->skb); | 
 | 1241 |  | 
 | 1242 | 		return RX_QUEUED; | 
 | 1243 | 	} else if (!ieee80211_has_morefrags(hdr->frame_control) && | 
 | 1244 | 		   !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) && | 
 | 1245 | 		   ieee80211_has_pm(hdr->frame_control) && | 
 | 1246 | 		   (ieee80211_is_data_qos(hdr->frame_control) || | 
 | 1247 | 		    ieee80211_is_qos_nullfunc(hdr->frame_control))) { | 
 | 1248 | 		tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK; | 
 | 1249 | 		ac = ieee802_1d_to_ac[tid & 7]; | 
 | 1250 |  | 
 | 1251 | 		/* | 
 | 1252 | 		 * If this AC is not trigger-enabled do nothing. | 
 | 1253 | 		 * | 
 | 1254 | 		 * NB: This could/should check a separate bitmap of trigger- | 
 | 1255 | 		 * enabled queues, but for now we only implement uAPSD w/o | 
 | 1256 | 		 * TSPEC changes to the ACs, so they're always the same. | 
 | 1257 | 		 */ | 
 | 1258 | 		if (!(rx->sta->sta.uapsd_queues & BIT(ac))) | 
 | 1259 | 			return RX_CONTINUE; | 
 | 1260 |  | 
 | 1261 | 		/* if we are in a service period, do nothing */ | 
 | 1262 | 		if (test_sta_flag(rx->sta, WLAN_STA_SP)) | 
 | 1263 | 			return RX_CONTINUE; | 
 | 1264 |  | 
 | 1265 | 		if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER)) | 
 | 1266 | 			ieee80211_sta_ps_deliver_uapsd(rx->sta); | 
 | 1267 | 		else | 
 | 1268 | 			set_sta_flag(rx->sta, WLAN_STA_UAPSD); | 
 | 1269 | 	} | 
 | 1270 |  | 
 | 1271 | 	return RX_CONTINUE; | 
 | 1272 | } | 
 | 1273 |  | 
 | 1274 | static ieee80211_rx_result debug_noinline | 
 | 1275 | ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx) | 
 | 1276 | { | 
 | 1277 | 	struct sta_info *sta = rx->sta; | 
 | 1278 | 	struct sk_buff *skb = rx->skb; | 
 | 1279 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); | 
 | 1280 | 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | 
 | 1281 |  | 
 | 1282 | 	if (!sta) | 
 | 1283 | 		return RX_CONTINUE; | 
 | 1284 |  | 
 | 1285 | 	/* | 
 | 1286 | 	 * Update last_rx only for IBSS packets which are for the current | 
 | 1287 | 	 * BSSID to avoid keeping the current IBSS network alive in cases | 
 | 1288 | 	 * where other STAs start using different BSSID. | 
 | 1289 | 	 */ | 
 | 1290 | 	if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) { | 
 | 1291 | 		u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len, | 
 | 1292 | 						NL80211_IFTYPE_ADHOC); | 
 | 1293 | 		if (compare_ether_addr(bssid, rx->sdata->u.ibss.bssid) == 0) { | 
 | 1294 | 			sta->last_rx = jiffies; | 
 | 1295 | 			if (ieee80211_is_data(hdr->frame_control)) { | 
 | 1296 | 				sta->last_rx_rate_idx = status->rate_idx; | 
 | 1297 | 				sta->last_rx_rate_flag = status->flag; | 
 | 1298 | 			} | 
 | 1299 | 		} | 
 | 1300 | 	} else if (!is_multicast_ether_addr(hdr->addr1)) { | 
 | 1301 | 		/* | 
 | 1302 | 		 * Mesh beacons will update last_rx when if they are found to | 
 | 1303 | 		 * match the current local configuration when processed. | 
 | 1304 | 		 */ | 
 | 1305 | 		sta->last_rx = jiffies; | 
 | 1306 | 		if (ieee80211_is_data(hdr->frame_control)) { | 
 | 1307 | 			sta->last_rx_rate_idx = status->rate_idx; | 
 | 1308 | 			sta->last_rx_rate_flag = status->flag; | 
 | 1309 | 		} | 
 | 1310 | 	} | 
 | 1311 |  | 
 | 1312 | 	if (!(status->rx_flags & IEEE80211_RX_RA_MATCH)) | 
 | 1313 | 		return RX_CONTINUE; | 
 | 1314 |  | 
 | 1315 | 	if (rx->sdata->vif.type == NL80211_IFTYPE_STATION) | 
 | 1316 | 		ieee80211_sta_rx_notify(rx->sdata, hdr); | 
 | 1317 |  | 
 | 1318 | 	sta->rx_fragments++; | 
 | 1319 | 	sta->rx_bytes += rx->skb->len; | 
 | 1320 | 	if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) { | 
 | 1321 | 		sta->last_signal = status->signal; | 
 | 1322 | 		ewma_add(&sta->avg_signal, -status->signal); | 
 | 1323 | 	} | 
 | 1324 |  | 
 | 1325 | 	/* | 
 | 1326 | 	 * Change STA power saving mode only at the end of a frame | 
 | 1327 | 	 * exchange sequence. | 
 | 1328 | 	 */ | 
 | 1329 | 	if (!(sta->local->hw.flags & IEEE80211_HW_AP_LINK_PS) && | 
 | 1330 | 	    !ieee80211_has_morefrags(hdr->frame_control) && | 
 | 1331 | 	    !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) && | 
 | 1332 | 	    (rx->sdata->vif.type == NL80211_IFTYPE_AP || | 
 | 1333 | 	     rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) { | 
 | 1334 | 		if (test_sta_flag(sta, WLAN_STA_PS_STA)) { | 
 | 1335 | 			/* | 
 | 1336 | 			 * Ignore doze->wake transitions that are | 
 | 1337 | 			 * indicated by non-data frames, the standard | 
 | 1338 | 			 * is unclear here, but for example going to | 
 | 1339 | 			 * PS mode and then scanning would cause a | 
 | 1340 | 			 * doze->wake transition for the probe request, | 
 | 1341 | 			 * and that is clearly undesirable. | 
 | 1342 | 			 */ | 
 | 1343 | 			if (ieee80211_is_data(hdr->frame_control) && | 
 | 1344 | 			    !ieee80211_has_pm(hdr->frame_control)) | 
 | 1345 | 				ap_sta_ps_end(sta); | 
 | 1346 | 		} else { | 
 | 1347 | 			if (ieee80211_has_pm(hdr->frame_control)) | 
 | 1348 | 				ap_sta_ps_start(sta); | 
 | 1349 | 		} | 
 | 1350 | 	} | 
 | 1351 |  | 
 | 1352 | 	/* | 
 | 1353 | 	 * Drop (qos-)data::nullfunc frames silently, since they | 
 | 1354 | 	 * are used only to control station power saving mode. | 
 | 1355 | 	 */ | 
 | 1356 | 	if (ieee80211_is_nullfunc(hdr->frame_control) || | 
 | 1357 | 	    ieee80211_is_qos_nullfunc(hdr->frame_control)) { | 
 | 1358 | 		I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc); | 
 | 1359 |  | 
 | 1360 | 		/* | 
 | 1361 | 		 * If we receive a 4-addr nullfunc frame from a STA | 
 | 1362 | 		 * that was not moved to a 4-addr STA vlan yet send | 
 | 1363 | 		 * the event to userspace and for older hostapd drop | 
 | 1364 | 		 * the frame to the monitor interface. | 
 | 1365 | 		 */ | 
 | 1366 | 		if (ieee80211_has_a4(hdr->frame_control) && | 
 | 1367 | 		    (rx->sdata->vif.type == NL80211_IFTYPE_AP || | 
 | 1368 | 		     (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN && | 
 | 1369 | 		      !rx->sdata->u.vlan.sta))) { | 
 | 1370 | 			if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT)) | 
 | 1371 | 				cfg80211_rx_unexpected_4addr_frame( | 
 | 1372 | 					rx->sdata->dev, sta->sta.addr, | 
 | 1373 | 					GFP_ATOMIC); | 
 | 1374 | 			return RX_DROP_MONITOR; | 
 | 1375 | 		} | 
 | 1376 | 		/* | 
 | 1377 | 		 * Update counter and free packet here to avoid | 
 | 1378 | 		 * counting this as a dropped packed. | 
 | 1379 | 		 */ | 
 | 1380 | 		sta->rx_packets++; | 
 | 1381 | 		dev_kfree_skb(rx->skb); | 
 | 1382 | 		return RX_QUEUED; | 
 | 1383 | 	} | 
 | 1384 |  | 
 | 1385 | 	return RX_CONTINUE; | 
 | 1386 | } /* ieee80211_rx_h_sta_process */ | 
 | 1387 |  | 
 | 1388 | static inline struct ieee80211_fragment_entry * | 
 | 1389 | ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata, | 
 | 1390 | 			 unsigned int frag, unsigned int seq, int rx_queue, | 
 | 1391 | 			 struct sk_buff **skb) | 
 | 1392 | { | 
 | 1393 | 	struct ieee80211_fragment_entry *entry; | 
 | 1394 | 	int idx; | 
 | 1395 |  | 
 | 1396 | 	idx = sdata->fragment_next; | 
 | 1397 | 	entry = &sdata->fragments[sdata->fragment_next++]; | 
 | 1398 | 	if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX) | 
 | 1399 | 		sdata->fragment_next = 0; | 
 | 1400 |  | 
 | 1401 | 	if (!skb_queue_empty(&entry->skb_list)) { | 
 | 1402 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG | 
 | 1403 | 		struct ieee80211_hdr *hdr = | 
 | 1404 | 			(struct ieee80211_hdr *) entry->skb_list.next->data; | 
 | 1405 | 		printk(KERN_DEBUG "%s: RX reassembly removed oldest " | 
 | 1406 | 		       "fragment entry (idx=%d age=%lu seq=%d last_frag=%d " | 
 | 1407 | 		       "addr1=%pM addr2=%pM\n", | 
 | 1408 | 		       sdata->name, idx, | 
 | 1409 | 		       jiffies - entry->first_frag_time, entry->seq, | 
 | 1410 | 		       entry->last_frag, hdr->addr1, hdr->addr2); | 
 | 1411 | #endif | 
 | 1412 | 		__skb_queue_purge(&entry->skb_list); | 
 | 1413 | 	} | 
 | 1414 |  | 
 | 1415 | 	__skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */ | 
 | 1416 | 	*skb = NULL; | 
 | 1417 | 	entry->first_frag_time = jiffies; | 
 | 1418 | 	entry->seq = seq; | 
 | 1419 | 	entry->rx_queue = rx_queue; | 
 | 1420 | 	entry->last_frag = frag; | 
 | 1421 | 	entry->ccmp = 0; | 
 | 1422 | 	entry->extra_len = 0; | 
 | 1423 |  | 
 | 1424 | 	return entry; | 
 | 1425 | } | 
 | 1426 |  | 
 | 1427 | static inline struct ieee80211_fragment_entry * | 
 | 1428 | ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata, | 
 | 1429 | 			  unsigned int frag, unsigned int seq, | 
 | 1430 | 			  int rx_queue, struct ieee80211_hdr *hdr) | 
 | 1431 | { | 
 | 1432 | 	struct ieee80211_fragment_entry *entry; | 
 | 1433 | 	int i, idx; | 
 | 1434 |  | 
 | 1435 | 	idx = sdata->fragment_next; | 
 | 1436 | 	for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) { | 
 | 1437 | 		struct ieee80211_hdr *f_hdr; | 
 | 1438 |  | 
 | 1439 | 		idx--; | 
 | 1440 | 		if (idx < 0) | 
 | 1441 | 			idx = IEEE80211_FRAGMENT_MAX - 1; | 
 | 1442 |  | 
 | 1443 | 		entry = &sdata->fragments[idx]; | 
 | 1444 | 		if (skb_queue_empty(&entry->skb_list) || entry->seq != seq || | 
 | 1445 | 		    entry->rx_queue != rx_queue || | 
 | 1446 | 		    entry->last_frag + 1 != frag) | 
 | 1447 | 			continue; | 
 | 1448 |  | 
 | 1449 | 		f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data; | 
 | 1450 |  | 
 | 1451 | 		/* | 
 | 1452 | 		 * Check ftype and addresses are equal, else check next fragment | 
 | 1453 | 		 */ | 
 | 1454 | 		if (((hdr->frame_control ^ f_hdr->frame_control) & | 
 | 1455 | 		     cpu_to_le16(IEEE80211_FCTL_FTYPE)) || | 
 | 1456 | 		    compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 || | 
 | 1457 | 		    compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0) | 
 | 1458 | 			continue; | 
 | 1459 |  | 
 | 1460 | 		if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) { | 
 | 1461 | 			__skb_queue_purge(&entry->skb_list); | 
 | 1462 | 			continue; | 
 | 1463 | 		} | 
 | 1464 | 		return entry; | 
 | 1465 | 	} | 
 | 1466 |  | 
 | 1467 | 	return NULL; | 
 | 1468 | } | 
 | 1469 |  | 
 | 1470 | static ieee80211_rx_result debug_noinline | 
 | 1471 | ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx) | 
 | 1472 | { | 
 | 1473 | 	struct ieee80211_hdr *hdr; | 
 | 1474 | 	u16 sc; | 
 | 1475 | 	__le16 fc; | 
 | 1476 | 	unsigned int frag, seq; | 
 | 1477 | 	struct ieee80211_fragment_entry *entry; | 
 | 1478 | 	struct sk_buff *skb; | 
 | 1479 | 	struct ieee80211_rx_status *status; | 
 | 1480 |  | 
 | 1481 | 	hdr = (struct ieee80211_hdr *)rx->skb->data; | 
 | 1482 | 	fc = hdr->frame_control; | 
 | 1483 |  | 
 | 1484 | 	if (ieee80211_is_ctl(fc)) | 
 | 1485 | 		return RX_CONTINUE; | 
 | 1486 |  | 
 | 1487 | 	sc = le16_to_cpu(hdr->seq_ctrl); | 
 | 1488 | 	frag = sc & IEEE80211_SCTL_FRAG; | 
 | 1489 |  | 
 | 1490 | 	if (is_multicast_ether_addr(hdr->addr1)) { | 
 | 1491 | 		rx->local->dot11MulticastReceivedFrameCount++; | 
 | 1492 | 		goto out_no_led; | 
 | 1493 | 	} | 
 | 1494 |  | 
 | 1495 | 	if (likely(!ieee80211_has_morefrags(fc) && frag == 0)) | 
 | 1496 | 		goto out; | 
 | 1497 |  | 
 | 1498 | 	I802_DEBUG_INC(rx->local->rx_handlers_fragments); | 
 | 1499 |  | 
 | 1500 | 	if (skb_linearize(rx->skb)) | 
 | 1501 | 		return RX_DROP_UNUSABLE; | 
 | 1502 |  | 
 | 1503 | 	/* | 
 | 1504 | 	 *  skb_linearize() might change the skb->data and | 
 | 1505 | 	 *  previously cached variables (in this case, hdr) need to | 
 | 1506 | 	 *  be refreshed with the new data. | 
 | 1507 | 	 */ | 
 | 1508 | 	hdr = (struct ieee80211_hdr *)rx->skb->data; | 
 | 1509 | 	seq = (sc & IEEE80211_SCTL_SEQ) >> 4; | 
 | 1510 |  | 
 | 1511 | 	if (frag == 0) { | 
 | 1512 | 		/* This is the first fragment of a new frame. */ | 
 | 1513 | 		entry = ieee80211_reassemble_add(rx->sdata, frag, seq, | 
 | 1514 | 						 rx->seqno_idx, &(rx->skb)); | 
 | 1515 | 		if (rx->key && rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP && | 
 | 1516 | 		    ieee80211_has_protected(fc)) { | 
 | 1517 | 			int queue = rx->security_idx; | 
 | 1518 | 			/* Store CCMP PN so that we can verify that the next | 
 | 1519 | 			 * fragment has a sequential PN value. */ | 
 | 1520 | 			entry->ccmp = 1; | 
 | 1521 | 			memcpy(entry->last_pn, | 
 | 1522 | 			       rx->key->u.ccmp.rx_pn[queue], | 
 | 1523 | 			       CCMP_PN_LEN); | 
 | 1524 | 		} | 
 | 1525 | 		return RX_QUEUED; | 
 | 1526 | 	} | 
 | 1527 |  | 
 | 1528 | 	/* This is a fragment for a frame that should already be pending in | 
 | 1529 | 	 * fragment cache. Add this fragment to the end of the pending entry. | 
 | 1530 | 	 */ | 
 | 1531 | 	entry = ieee80211_reassemble_find(rx->sdata, frag, seq, | 
 | 1532 | 					  rx->seqno_idx, hdr); | 
 | 1533 | 	if (!entry) { | 
 | 1534 | 		I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag); | 
 | 1535 | 		return RX_DROP_MONITOR; | 
 | 1536 | 	} | 
 | 1537 |  | 
 | 1538 | 	/* Verify that MPDUs within one MSDU have sequential PN values. | 
 | 1539 | 	 * (IEEE 802.11i, 8.3.3.4.5) */ | 
 | 1540 | 	if (entry->ccmp) { | 
 | 1541 | 		int i; | 
 | 1542 | 		u8 pn[CCMP_PN_LEN], *rpn; | 
 | 1543 | 		int queue; | 
 | 1544 | 		if (!rx->key || rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP) | 
 | 1545 | 			return RX_DROP_UNUSABLE; | 
 | 1546 | 		memcpy(pn, entry->last_pn, CCMP_PN_LEN); | 
 | 1547 | 		for (i = CCMP_PN_LEN - 1; i >= 0; i--) { | 
 | 1548 | 			pn[i]++; | 
 | 1549 | 			if (pn[i]) | 
 | 1550 | 				break; | 
 | 1551 | 		} | 
 | 1552 | 		queue = rx->security_idx; | 
 | 1553 | 		rpn = rx->key->u.ccmp.rx_pn[queue]; | 
 | 1554 | 		if (memcmp(pn, rpn, CCMP_PN_LEN)) | 
 | 1555 | 			return RX_DROP_UNUSABLE; | 
 | 1556 | 		memcpy(entry->last_pn, pn, CCMP_PN_LEN); | 
 | 1557 | 	} | 
 | 1558 |  | 
 | 1559 | 	skb_pull(rx->skb, ieee80211_hdrlen(fc)); | 
 | 1560 | 	__skb_queue_tail(&entry->skb_list, rx->skb); | 
 | 1561 | 	entry->last_frag = frag; | 
 | 1562 | 	entry->extra_len += rx->skb->len; | 
 | 1563 | 	if (ieee80211_has_morefrags(fc)) { | 
 | 1564 | 		rx->skb = NULL; | 
 | 1565 | 		return RX_QUEUED; | 
 | 1566 | 	} | 
 | 1567 |  | 
 | 1568 | 	rx->skb = __skb_dequeue(&entry->skb_list); | 
 | 1569 | 	if (skb_tailroom(rx->skb) < entry->extra_len) { | 
 | 1570 | 		I802_DEBUG_INC(rx->local->rx_expand_skb_head2); | 
 | 1571 | 		if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len, | 
 | 1572 | 					      GFP_ATOMIC))) { | 
 | 1573 | 			I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag); | 
 | 1574 | 			__skb_queue_purge(&entry->skb_list); | 
 | 1575 | 			return RX_DROP_UNUSABLE; | 
 | 1576 | 		} | 
 | 1577 | 	} | 
 | 1578 | 	while ((skb = __skb_dequeue(&entry->skb_list))) { | 
 | 1579 | 		memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len); | 
 | 1580 | 		dev_kfree_skb(skb); | 
 | 1581 | 	} | 
 | 1582 |  | 
 | 1583 | 	/* Complete frame has been reassembled - process it now */ | 
 | 1584 | 	status = IEEE80211_SKB_RXCB(rx->skb); | 
 | 1585 | 	status->rx_flags |= IEEE80211_RX_FRAGMENTED; | 
 | 1586 |  | 
 | 1587 |  out: | 
 | 1588 | 	ieee80211_led_rx(rx->local); | 
 | 1589 |  out_no_led: | 
 | 1590 | 	if (rx->sta) | 
 | 1591 | 		rx->sta->rx_packets++; | 
 | 1592 | 	return RX_CONTINUE; | 
 | 1593 | } | 
 | 1594 |  | 
 | 1595 | static int | 
 | 1596 | ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx) | 
 | 1597 | { | 
 | 1598 | 	if (unlikely(!rx->sta || | 
 | 1599 | 	    !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED))) | 
 | 1600 | 		return -EACCES; | 
 | 1601 |  | 
 | 1602 | 	return 0; | 
 | 1603 | } | 
 | 1604 |  | 
 | 1605 | static int | 
 | 1606 | ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc) | 
 | 1607 | { | 
 | 1608 | 	struct sk_buff *skb = rx->skb; | 
 | 1609 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); | 
 | 1610 |  | 
 | 1611 | 	/* | 
 | 1612 | 	 * Pass through unencrypted frames if the hardware has | 
 | 1613 | 	 * decrypted them already. | 
 | 1614 | 	 */ | 
 | 1615 | 	if (status->flag & RX_FLAG_DECRYPTED) | 
 | 1616 | 		return 0; | 
 | 1617 |  | 
 | 1618 | 	/* Drop unencrypted frames if key is set. */ | 
 | 1619 | 	if (unlikely(!ieee80211_has_protected(fc) && | 
 | 1620 | 		     !ieee80211_is_nullfunc(fc) && | 
 | 1621 | 		     ieee80211_is_data(fc) && | 
 | 1622 | 		     (rx->key || rx->sdata->drop_unencrypted))) | 
 | 1623 | 		return -EACCES; | 
 | 1624 |  | 
 | 1625 | 	return 0; | 
 | 1626 | } | 
 | 1627 |  | 
 | 1628 | static int | 
 | 1629 | ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx) | 
 | 1630 | { | 
 | 1631 | 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; | 
 | 1632 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); | 
 | 1633 | 	__le16 fc = hdr->frame_control; | 
 | 1634 |  | 
 | 1635 | 	/* | 
 | 1636 | 	 * Pass through unencrypted frames if the hardware has | 
 | 1637 | 	 * decrypted them already. | 
 | 1638 | 	 */ | 
 | 1639 | 	if (status->flag & RX_FLAG_DECRYPTED) | 
 | 1640 | 		return 0; | 
 | 1641 |  | 
 | 1642 | 	if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) { | 
 | 1643 | 		if (unlikely(!ieee80211_has_protected(fc) && | 
 | 1644 | 			     ieee80211_is_unicast_robust_mgmt_frame(rx->skb) && | 
 | 1645 | 			     rx->key)) { | 
 | 1646 | 			if (ieee80211_is_deauth(fc)) | 
 | 1647 | 				cfg80211_send_unprot_deauth(rx->sdata->dev, | 
 | 1648 | 							    rx->skb->data, | 
 | 1649 | 							    rx->skb->len); | 
 | 1650 | 			else if (ieee80211_is_disassoc(fc)) | 
 | 1651 | 				cfg80211_send_unprot_disassoc(rx->sdata->dev, | 
 | 1652 | 							      rx->skb->data, | 
 | 1653 | 							      rx->skb->len); | 
 | 1654 | 			return -EACCES; | 
 | 1655 | 		} | 
 | 1656 | 		/* BIP does not use Protected field, so need to check MMIE */ | 
 | 1657 | 		if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) && | 
 | 1658 | 			     ieee80211_get_mmie_keyidx(rx->skb) < 0)) { | 
 | 1659 | 			if (ieee80211_is_deauth(fc)) | 
 | 1660 | 				cfg80211_send_unprot_deauth(rx->sdata->dev, | 
 | 1661 | 							    rx->skb->data, | 
 | 1662 | 							    rx->skb->len); | 
 | 1663 | 			else if (ieee80211_is_disassoc(fc)) | 
 | 1664 | 				cfg80211_send_unprot_disassoc(rx->sdata->dev, | 
 | 1665 | 							      rx->skb->data, | 
 | 1666 | 							      rx->skb->len); | 
 | 1667 | 			return -EACCES; | 
 | 1668 | 		} | 
 | 1669 | 		/* | 
 | 1670 | 		 * When using MFP, Action frames are not allowed prior to | 
 | 1671 | 		 * having configured keys. | 
 | 1672 | 		 */ | 
 | 1673 | 		if (unlikely(ieee80211_is_action(fc) && !rx->key && | 
 | 1674 | 			     ieee80211_is_robust_mgmt_frame( | 
 | 1675 | 				     (struct ieee80211_hdr *) rx->skb->data))) | 
 | 1676 | 			return -EACCES; | 
 | 1677 | 	} | 
 | 1678 |  | 
 | 1679 | 	return 0; | 
 | 1680 | } | 
 | 1681 |  | 
 | 1682 | static int | 
 | 1683 | __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control) | 
 | 1684 | { | 
 | 1685 | 	struct ieee80211_sub_if_data *sdata = rx->sdata; | 
 | 1686 | 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; | 
 | 1687 | 	bool check_port_control = false; | 
 | 1688 | 	struct ethhdr *ehdr; | 
 | 1689 | 	int ret; | 
 | 1690 |  | 
 | 1691 | 	*port_control = false; | 
 | 1692 | 	if (ieee80211_has_a4(hdr->frame_control) && | 
 | 1693 | 	    sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta) | 
 | 1694 | 		return -1; | 
 | 1695 |  | 
 | 1696 | 	if (sdata->vif.type == NL80211_IFTYPE_STATION && | 
 | 1697 | 	    !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) { | 
 | 1698 |  | 
 | 1699 | 		if (!sdata->u.mgd.use_4addr) | 
 | 1700 | 			return -1; | 
 | 1701 | 		else | 
 | 1702 | 			check_port_control = true; | 
 | 1703 | 	} | 
 | 1704 |  | 
 | 1705 | 	if (is_multicast_ether_addr(hdr->addr1) && | 
 | 1706 | 	    sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta) | 
 | 1707 | 		return -1; | 
 | 1708 |  | 
 | 1709 | 	ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type); | 
 | 1710 | 	if (ret < 0) | 
 | 1711 | 		return ret; | 
 | 1712 |  | 
 | 1713 | 	ehdr = (struct ethhdr *) rx->skb->data; | 
 | 1714 | 	if (ehdr->h_proto == rx->sdata->control_port_protocol) | 
 | 1715 | 		*port_control = true; | 
 | 1716 | 	else if (check_port_control) | 
 | 1717 | 		return -1; | 
 | 1718 |  | 
 | 1719 | 	return 0; | 
 | 1720 | } | 
 | 1721 |  | 
 | 1722 | /* | 
 | 1723 |  * requires that rx->skb is a frame with ethernet header | 
 | 1724 |  */ | 
 | 1725 | static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc) | 
 | 1726 | { | 
 | 1727 | 	static const u8 pae_group_addr[ETH_ALEN] __aligned(2) | 
 | 1728 | 		= { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 }; | 
 | 1729 | 	struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data; | 
 | 1730 |  | 
 | 1731 | 	/* | 
 | 1732 | 	 * Allow EAPOL frames to us/the PAE group address regardless | 
 | 1733 | 	 * of whether the frame was encrypted or not. | 
 | 1734 | 	 */ | 
 | 1735 | 	if (ehdr->h_proto == rx->sdata->control_port_protocol && | 
 | 1736 | 	    (compare_ether_addr(ehdr->h_dest, rx->sdata->vif.addr) == 0 || | 
 | 1737 | 	     compare_ether_addr(ehdr->h_dest, pae_group_addr) == 0)) | 
 | 1738 | 		return true; | 
 | 1739 |  | 
 | 1740 | 	if (ieee80211_802_1x_port_control(rx) || | 
 | 1741 | 	    ieee80211_drop_unencrypted(rx, fc)) | 
 | 1742 | 		return false; | 
 | 1743 |  | 
 | 1744 | 	return true; | 
 | 1745 | } | 
 | 1746 |  | 
 | 1747 | /* | 
 | 1748 |  * requires that rx->skb is a frame with ethernet header | 
 | 1749 |  */ | 
 | 1750 | static void | 
 | 1751 | ieee80211_deliver_skb(struct ieee80211_rx_data *rx) | 
 | 1752 | { | 
 | 1753 | 	struct ieee80211_sub_if_data *sdata = rx->sdata; | 
 | 1754 | 	struct net_device *dev = sdata->dev; | 
 | 1755 | 	struct sk_buff *skb, *xmit_skb; | 
 | 1756 | 	struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data; | 
 | 1757 | 	struct sta_info *dsta; | 
 | 1758 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); | 
 | 1759 |  | 
 | 1760 | 	skb = rx->skb; | 
 | 1761 | 	xmit_skb = NULL; | 
 | 1762 |  | 
 | 1763 | 	if ((sdata->vif.type == NL80211_IFTYPE_AP || | 
 | 1764 | 	     sdata->vif.type == NL80211_IFTYPE_AP_VLAN) && | 
 | 1765 | 	    !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) && | 
 | 1766 | 	    (status->rx_flags & IEEE80211_RX_RA_MATCH) && | 
 | 1767 | 	    (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) { | 
 | 1768 | 		if (is_multicast_ether_addr(ehdr->h_dest)) { | 
 | 1769 | 			/* | 
 | 1770 | 			 * send multicast frames both to higher layers in | 
 | 1771 | 			 * local net stack and back to the wireless medium | 
 | 1772 | 			 */ | 
 | 1773 | 			xmit_skb = skb_copy(skb, GFP_ATOMIC); | 
 | 1774 | 			if (!xmit_skb && net_ratelimit()) | 
 | 1775 | 				printk(KERN_DEBUG "%s: failed to clone " | 
 | 1776 | 				       "multicast frame\n", dev->name); | 
 | 1777 | 		} else { | 
 | 1778 | 			dsta = sta_info_get(sdata, skb->data); | 
 | 1779 | 			if (dsta) { | 
 | 1780 | 				/* | 
 | 1781 | 				 * The destination station is associated to | 
 | 1782 | 				 * this AP (in this VLAN), so send the frame | 
 | 1783 | 				 * directly to it and do not pass it to local | 
 | 1784 | 				 * net stack. | 
 | 1785 | 				 */ | 
 | 1786 | 				xmit_skb = skb; | 
 | 1787 | 				skb = NULL; | 
 | 1788 | 			} | 
 | 1789 | 		} | 
 | 1790 | 	} | 
 | 1791 |  | 
 | 1792 | 	if (skb) { | 
 | 1793 | 		int align __maybe_unused; | 
 | 1794 |  | 
 | 1795 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS | 
 | 1796 | 		/* | 
 | 1797 | 		 * 'align' will only take the values 0 or 2 here | 
 | 1798 | 		 * since all frames are required to be aligned | 
 | 1799 | 		 * to 2-byte boundaries when being passed to | 
 | 1800 | 		 * mac80211. That also explains the __skb_push() | 
 | 1801 | 		 * below. | 
 | 1802 | 		 */ | 
 | 1803 | 		align = ((unsigned long)(skb->data + sizeof(struct ethhdr))) & 3; | 
 | 1804 | 		if (align) { | 
 | 1805 | 			if (WARN_ON(skb_headroom(skb) < 3)) { | 
 | 1806 | 				dev_kfree_skb(skb); | 
 | 1807 | 				skb = NULL; | 
 | 1808 | 			} else { | 
 | 1809 | 				u8 *data = skb->data; | 
 | 1810 | 				size_t len = skb_headlen(skb); | 
 | 1811 | 				skb->data -= align; | 
 | 1812 | 				memmove(skb->data, data, len); | 
 | 1813 | 				skb_set_tail_pointer(skb, len); | 
 | 1814 | 			} | 
 | 1815 | 		} | 
 | 1816 | #endif | 
 | 1817 |  | 
 | 1818 | 		if (skb) { | 
 | 1819 | 			/* deliver to local stack */ | 
 | 1820 | 			skb->protocol = eth_type_trans(skb, dev); | 
 | 1821 | 			memset(skb->cb, 0, sizeof(skb->cb)); | 
 | 1822 | #if 1 | 
 | 1823 | 		clean_cache(skb_mac_header(skb), skb->len + skb->data - skb_mac_header(skb)); | 
 | 1824 | 		int ret; | 
 | 1825 | 		extern int (*fast_from_driver)(struct sk_buff *skb, struct net_device *dev); | 
 | 1826 | 		if (fast_from_driver) { | 
 | 1827 | 			skb->data -= 14; | 
 | 1828 | 			skb->len += 14; | 
 | 1829 | 			if(((unsigned int)skb->data) % 4 == 0) | 
 | 1830 | 			{ | 
 | 1831 | 				memmove(skb->data - 2, skb->data, skb->len); | 
 | 1832 | 				skb->data = skb->data - 2; | 
 | 1833 | 			} | 
 | 1834 |  | 
 | 1835 | 			ret = fast_from_driver(skb,dev); | 
 | 1836 | 			if(!ret) | 
 | 1837 | 			{ | 
 | 1838 | 				skb->data += 14; | 
 | 1839 | 				skb->len -= 14; | 
 | 1840 | 				netif_receive_skb(skb); | 
 | 1841 | 			} | 
 | 1842 | 		} else { | 
 | 1843 | #endif | 
 | 1844 | 			netif_receive_skb(skb); | 
 | 1845 | 		} | 
 | 1846 | 		} | 
 | 1847 | 	} | 
 | 1848 |  | 
 | 1849 | 	if (xmit_skb) { | 
 | 1850 | 		/* | 
 | 1851 | 		 * Send to wireless media and increase priority by 256 to | 
 | 1852 | 		 * keep the received priority instead of reclassifying | 
 | 1853 | 		 * the frame (see cfg80211_classify8021d). | 
 | 1854 | 		 */ | 
 | 1855 | 		xmit_skb->priority += 256; | 
 | 1856 | 		xmit_skb->protocol = htons(ETH_P_802_3); | 
 | 1857 | 		skb_reset_network_header(xmit_skb); | 
 | 1858 | 		skb_reset_mac_header(xmit_skb); | 
 | 1859 | 		dev_queue_xmit(xmit_skb); | 
 | 1860 | 	} | 
 | 1861 | } | 
 | 1862 |  | 
 | 1863 | static ieee80211_rx_result debug_noinline | 
 | 1864 | ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx) | 
 | 1865 | { | 
 | 1866 | 	struct net_device *dev = rx->sdata->dev; | 
 | 1867 | 	struct sk_buff *skb = rx->skb; | 
 | 1868 | 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | 
 | 1869 | 	__le16 fc = hdr->frame_control; | 
 | 1870 | 	struct sk_buff_head frame_list; | 
 | 1871 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); | 
 | 1872 |  | 
 | 1873 | 	if (unlikely(!ieee80211_is_data(fc))) | 
 | 1874 | 		return RX_CONTINUE; | 
 | 1875 |  | 
 | 1876 | 	if (unlikely(!ieee80211_is_data_present(fc))) | 
 | 1877 | 		return RX_DROP_MONITOR; | 
 | 1878 |  | 
 | 1879 | 	if (!(status->rx_flags & IEEE80211_RX_AMSDU)) | 
 | 1880 | 		return RX_CONTINUE; | 
 | 1881 |  | 
 | 1882 | 	if (ieee80211_has_a4(hdr->frame_control) && | 
 | 1883 | 	    rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN && | 
 | 1884 | 	    !rx->sdata->u.vlan.sta) | 
 | 1885 | 		return RX_DROP_UNUSABLE; | 
 | 1886 |  | 
 | 1887 | 	if (is_multicast_ether_addr(hdr->addr1) && | 
 | 1888 | 	    ((rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN && | 
 | 1889 | 	      rx->sdata->u.vlan.sta) || | 
 | 1890 | 	     (rx->sdata->vif.type == NL80211_IFTYPE_STATION && | 
 | 1891 | 	      rx->sdata->u.mgd.use_4addr))) | 
 | 1892 | 		return RX_DROP_UNUSABLE; | 
 | 1893 |  | 
 | 1894 | 	skb->dev = dev; | 
 | 1895 | 	__skb_queue_head_init(&frame_list); | 
 | 1896 |  | 
 | 1897 | 	if (skb_linearize(skb)) | 
 | 1898 | 		return RX_DROP_UNUSABLE; | 
 | 1899 |  | 
 | 1900 | 	ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr, | 
 | 1901 | 				 rx->sdata->vif.type, | 
 | 1902 | 				 rx->local->hw.extra_tx_headroom, true); | 
 | 1903 |  | 
 | 1904 | 	while (!skb_queue_empty(&frame_list)) { | 
 | 1905 | 		rx->skb = __skb_dequeue(&frame_list); | 
 | 1906 |  | 
 | 1907 | 		if (!ieee80211_frame_allowed(rx, fc)) { | 
 | 1908 | 			dev_kfree_skb(rx->skb); | 
 | 1909 | 			continue; | 
 | 1910 | 		} | 
 | 1911 | 		dev->stats.rx_packets++; | 
 | 1912 | 		dev->stats.rx_bytes += rx->skb->len; | 
 | 1913 |  | 
 | 1914 | 		ieee80211_deliver_skb(rx); | 
 | 1915 | 	} | 
 | 1916 |  | 
 | 1917 | 	return RX_QUEUED; | 
 | 1918 | } | 
 | 1919 |  | 
 | 1920 | #ifdef CONFIG_MAC80211_MESH | 
 | 1921 | static ieee80211_rx_result | 
 | 1922 | ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx) | 
 | 1923 | { | 
 | 1924 | 	struct ieee80211_hdr *fwd_hdr, *hdr; | 
 | 1925 | 	struct ieee80211_tx_info *info; | 
 | 1926 | 	struct ieee80211s_hdr *mesh_hdr; | 
 | 1927 | 	struct sk_buff *skb = rx->skb, *fwd_skb; | 
 | 1928 | 	struct ieee80211_local *local = rx->local; | 
 | 1929 | 	struct ieee80211_sub_if_data *sdata = rx->sdata; | 
 | 1930 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); | 
 | 1931 | 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | 
 | 1932 | 	__le16 reason = cpu_to_le16(WLAN_REASON_MESH_PATH_NOFORWARD); | 
 | 1933 | 	u16 q, hdrlen; | 
 | 1934 |  | 
 | 1935 | 	hdr = (struct ieee80211_hdr *) skb->data; | 
 | 1936 | 	hdrlen = ieee80211_hdrlen(hdr->frame_control); | 
 | 1937 |  | 
 | 1938 | 	/* make sure fixed part of mesh header is there, also checks skb len */ | 
 | 1939 | 	if (!pskb_may_pull(rx->skb, hdrlen + 6)) | 
 | 1940 | 		return RX_DROP_MONITOR; | 
 | 1941 |  | 
 | 1942 | 	mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen); | 
 | 1943 |  | 
 | 1944 | 	/* make sure full mesh header is there, also checks skb len */ | 
 | 1945 | 	if (!pskb_may_pull(rx->skb, | 
 | 1946 | 			   hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr))) | 
 | 1947 | 		return RX_DROP_MONITOR; | 
 | 1948 |  | 
 | 1949 | 	/* reload pointers */ | 
 | 1950 | 	hdr = (struct ieee80211_hdr *) skb->data; | 
 | 1951 | 	mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen); | 
 | 1952 |  | 
 | 1953 | 	if (ieee80211_drop_unencrypted(rx, hdr->frame_control)) | 
 | 1954 | 		return RX_DROP_MONITOR; | 
 | 1955 |  | 
 | 1956 | 	/* frame is in RMC, don't forward */ | 
 | 1957 | 	if (ieee80211_is_data(hdr->frame_control) && | 
 | 1958 | 	    is_multicast_ether_addr(hdr->addr1) && | 
 | 1959 | 	    mesh_rmc_check(hdr->addr3, mesh_hdr, rx->sdata)) | 
 | 1960 | 		return RX_DROP_MONITOR; | 
 | 1961 |  | 
 | 1962 | 	if (!ieee80211_is_data(hdr->frame_control) || | 
 | 1963 | 	    !(status->rx_flags & IEEE80211_RX_RA_MATCH)) | 
 | 1964 | 		return RX_CONTINUE; | 
 | 1965 |  | 
 | 1966 | 	if (!mesh_hdr->ttl) | 
 | 1967 | 		return RX_DROP_MONITOR; | 
 | 1968 |  | 
 | 1969 | 	if (mesh_hdr->flags & MESH_FLAGS_AE) { | 
 | 1970 | 		struct mesh_path *mppath; | 
 | 1971 | 		char *proxied_addr; | 
 | 1972 | 		char *mpp_addr; | 
 | 1973 |  | 
 | 1974 | 		if (is_multicast_ether_addr(hdr->addr1)) { | 
 | 1975 | 			mpp_addr = hdr->addr3; | 
 | 1976 | 			proxied_addr = mesh_hdr->eaddr1; | 
 | 1977 | 		} else if (mesh_hdr->flags & MESH_FLAGS_AE_A5_A6) { | 
 | 1978 | 			/* has_a4 already checked in ieee80211_rx_mesh_check */ | 
 | 1979 | 			mpp_addr = hdr->addr4; | 
 | 1980 | 			proxied_addr = mesh_hdr->eaddr2; | 
 | 1981 | 		} else { | 
 | 1982 | 			return RX_DROP_MONITOR; | 
 | 1983 | 		} | 
 | 1984 |  | 
 | 1985 | 		rcu_read_lock(); | 
 | 1986 | 		mppath = mpp_path_lookup(proxied_addr, sdata); | 
 | 1987 | 		if (!mppath) { | 
 | 1988 | 			mpp_path_add(proxied_addr, mpp_addr, sdata); | 
 | 1989 | 		} else { | 
 | 1990 | 			spin_lock_bh(&mppath->state_lock); | 
 | 1991 | 			if (compare_ether_addr(mppath->mpp, mpp_addr) != 0) | 
 | 1992 | 				memcpy(mppath->mpp, mpp_addr, ETH_ALEN); | 
 | 1993 | 			spin_unlock_bh(&mppath->state_lock); | 
 | 1994 | 		} | 
 | 1995 | 		rcu_read_unlock(); | 
 | 1996 | 	} | 
 | 1997 |  | 
 | 1998 | 	/* Frame has reached destination.  Don't forward */ | 
 | 1999 | 	if (!is_multicast_ether_addr(hdr->addr1) && | 
 | 2000 | 	    compare_ether_addr(sdata->vif.addr, hdr->addr3) == 0) | 
 | 2001 | 		return RX_CONTINUE; | 
 | 2002 |  | 
 | 2003 | 	q = ieee80211_select_queue_80211(local, skb, hdr); | 
 | 2004 | 	if (ieee80211_queue_stopped(&local->hw, q)) { | 
 | 2005 | 		IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion); | 
 | 2006 | 		return RX_DROP_MONITOR; | 
 | 2007 | 	} | 
 | 2008 | 	skb_set_queue_mapping(skb, q); | 
 | 2009 |  | 
 | 2010 | 	if (!--mesh_hdr->ttl) { | 
 | 2011 | 		IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_ttl); | 
 | 2012 | 		return RX_DROP_MONITOR; | 
 | 2013 | 	} | 
 | 2014 |  | 
 | 2015 | 	if (!ifmsh->mshcfg.dot11MeshForwarding) | 
 | 2016 | 		goto out; | 
 | 2017 |  | 
 | 2018 | 	fwd_skb = skb_copy(skb, GFP_ATOMIC); | 
 | 2019 | 	if (!fwd_skb) { | 
 | 2020 | 		if (net_ratelimit()) | 
 | 2021 | 			printk(KERN_DEBUG "%s: failed to clone mesh frame\n", | 
 | 2022 | 					sdata->name); | 
 | 2023 | 		goto out; | 
 | 2024 | 	} | 
 | 2025 |  | 
 | 2026 | 	fwd_hdr =  (struct ieee80211_hdr *) fwd_skb->data; | 
 | 2027 | 	info = IEEE80211_SKB_CB(fwd_skb); | 
 | 2028 | 	memset(info, 0, sizeof(*info)); | 
 | 2029 | 	info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING; | 
 | 2030 | 	info->control.vif = &rx->sdata->vif; | 
 | 2031 | 	info->control.jiffies = jiffies; | 
 | 2032 | 	if (is_multicast_ether_addr(fwd_hdr->addr1)) { | 
 | 2033 | 		IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast); | 
 | 2034 | 		memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN); | 
 | 2035 | 	} else if (!mesh_nexthop_lookup(fwd_skb, sdata)) { | 
 | 2036 | 		IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast); | 
 | 2037 | 	} else { | 
 | 2038 | 		/* unable to resolve next hop */ | 
 | 2039 | 		mesh_path_error_tx(ifmsh->mshcfg.element_ttl, fwd_hdr->addr3, | 
 | 2040 | 				    0, reason, fwd_hdr->addr2, sdata); | 
 | 2041 | 		IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route); | 
 | 2042 | 		kfree_skb(fwd_skb); | 
 | 2043 | 		return RX_DROP_MONITOR; | 
 | 2044 | 	} | 
 | 2045 |  | 
 | 2046 | 	IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames); | 
 | 2047 | 	ieee80211_add_pending_skb(local, fwd_skb); | 
 | 2048 |  out: | 
 | 2049 | 	if (is_multicast_ether_addr(hdr->addr1) || | 
 | 2050 | 	    sdata->dev->flags & IFF_PROMISC) | 
 | 2051 | 		return RX_CONTINUE; | 
 | 2052 | 	else | 
 | 2053 | 		return RX_DROP_MONITOR; | 
 | 2054 | } | 
 | 2055 | #endif | 
 | 2056 |  | 
 | 2057 | static ieee80211_rx_result debug_noinline | 
 | 2058 | ieee80211_rx_h_data(struct ieee80211_rx_data *rx) | 
 | 2059 | { | 
 | 2060 | 	struct ieee80211_sub_if_data *sdata = rx->sdata; | 
 | 2061 | 	struct ieee80211_local *local = rx->local; | 
 | 2062 | 	struct net_device *dev = sdata->dev; | 
 | 2063 | 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; | 
 | 2064 | 	__le16 fc = hdr->frame_control; | 
 | 2065 | 	bool port_control; | 
 | 2066 | 	int err; | 
 | 2067 |  | 
 | 2068 | 	if (unlikely(!ieee80211_is_data(hdr->frame_control))) | 
 | 2069 | 		return RX_CONTINUE; | 
 | 2070 |  | 
 | 2071 | 	if (unlikely(!ieee80211_is_data_present(hdr->frame_control))) | 
 | 2072 | 		return RX_DROP_MONITOR; | 
 | 2073 |  | 
 | 2074 | 	/* | 
 | 2075 | 	 * Send unexpected-4addr-frame event to hostapd. For older versions, | 
 | 2076 | 	 * also drop the frame to cooked monitor interfaces. | 
 | 2077 | 	 */ | 
 | 2078 | 	if (ieee80211_has_a4(hdr->frame_control) && | 
 | 2079 | 	    sdata->vif.type == NL80211_IFTYPE_AP) { | 
 | 2080 | 		if (rx->sta && | 
 | 2081 | 		    !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT)) | 
 | 2082 | 			cfg80211_rx_unexpected_4addr_frame( | 
 | 2083 | 				rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC); | 
 | 2084 | 		return RX_DROP_MONITOR; | 
 | 2085 | 	} | 
 | 2086 |  | 
 | 2087 | 	err = __ieee80211_data_to_8023(rx, &port_control); | 
 | 2088 | 	if (unlikely(err)) | 
 | 2089 | 		return RX_DROP_UNUSABLE; | 
 | 2090 |  | 
 | 2091 | 	if (!ieee80211_frame_allowed(rx, fc)) | 
 | 2092 | 		return RX_DROP_MONITOR; | 
 | 2093 |  | 
 | 2094 | 	if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN && | 
 | 2095 | 	    unlikely(port_control) && sdata->bss) { | 
 | 2096 | 		sdata = container_of(sdata->bss, struct ieee80211_sub_if_data, | 
 | 2097 | 				     u.ap); | 
 | 2098 | 		dev = sdata->dev; | 
 | 2099 | 		rx->sdata = sdata; | 
 | 2100 | 	} | 
 | 2101 |  | 
 | 2102 | 	rx->skb->dev = dev; | 
 | 2103 |  | 
 | 2104 | 	dev->stats.rx_packets++; | 
 | 2105 | 	dev->stats.rx_bytes += rx->skb->len; | 
 | 2106 |  | 
 | 2107 | 	if (local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 && | 
 | 2108 | 	    !is_multicast_ether_addr( | 
 | 2109 | 		    ((struct ethhdr *)rx->skb->data)->h_dest) && | 
 | 2110 | 	    (!local->scanning && | 
 | 2111 | 	     !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))) { | 
 | 2112 | 			mod_timer(&local->dynamic_ps_timer, jiffies + | 
 | 2113 | 			 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout)); | 
 | 2114 | 	} | 
 | 2115 |  | 
 | 2116 | 	ieee80211_deliver_skb(rx); | 
 | 2117 |  | 
 | 2118 | 	return RX_QUEUED; | 
 | 2119 | } | 
 | 2120 |  | 
 | 2121 | static ieee80211_rx_result debug_noinline | 
 | 2122 | ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx) | 
 | 2123 | { | 
 | 2124 | 	struct ieee80211_local *local = rx->local; | 
 | 2125 | 	struct ieee80211_hw *hw = &local->hw; | 
 | 2126 | 	struct sk_buff *skb = rx->skb; | 
 | 2127 | 	struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data; | 
 | 2128 | 	struct tid_ampdu_rx *tid_agg_rx; | 
 | 2129 | 	u16 start_seq_num; | 
 | 2130 | 	u16 tid; | 
 | 2131 |  | 
 | 2132 | 	if (likely(!ieee80211_is_ctl(bar->frame_control))) | 
 | 2133 | 		return RX_CONTINUE; | 
 | 2134 |  | 
 | 2135 | 	if (ieee80211_is_back_req(bar->frame_control)) { | 
 | 2136 | 		struct { | 
 | 2137 | 			__le16 control, start_seq_num; | 
 | 2138 | 		} __packed bar_data; | 
 | 2139 |  | 
 | 2140 | 		if (!rx->sta) | 
 | 2141 | 			return RX_DROP_MONITOR; | 
 | 2142 |  | 
 | 2143 | 		if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control), | 
 | 2144 | 				  &bar_data, sizeof(bar_data))) | 
 | 2145 | 			return RX_DROP_MONITOR; | 
 | 2146 |  | 
 | 2147 | 		tid = le16_to_cpu(bar_data.control) >> 12; | 
 | 2148 |  | 
 | 2149 | 		tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]); | 
 | 2150 | 		if (!tid_agg_rx) | 
 | 2151 | 			return RX_DROP_MONITOR; | 
 | 2152 |  | 
 | 2153 | 		start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4; | 
 | 2154 |  | 
 | 2155 | 		/* reset session timer */ | 
 | 2156 | 		if (tid_agg_rx->timeout) | 
 | 2157 | 			mod_timer(&tid_agg_rx->session_timer, | 
 | 2158 | 				  TU_TO_EXP_TIME(tid_agg_rx->timeout)); | 
 | 2159 |  | 
 | 2160 | 		spin_lock(&tid_agg_rx->reorder_lock); | 
 | 2161 | 		/* release stored frames up to start of BAR */ | 
 | 2162 | 		ieee80211_release_reorder_frames(hw, tid_agg_rx, start_seq_num); | 
 | 2163 | 		spin_unlock(&tid_agg_rx->reorder_lock); | 
 | 2164 |  | 
 | 2165 | 		kfree_skb(skb); | 
 | 2166 | 		return RX_QUEUED; | 
 | 2167 | 	} | 
 | 2168 |  | 
 | 2169 | 	/* | 
 | 2170 | 	 * After this point, we only want management frames, | 
 | 2171 | 	 * so we can drop all remaining control frames to | 
 | 2172 | 	 * cooked monitor interfaces. | 
 | 2173 | 	 */ | 
 | 2174 | 	return RX_DROP_MONITOR; | 
 | 2175 | } | 
 | 2176 |  | 
 | 2177 | static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata, | 
 | 2178 | 					   struct ieee80211_mgmt *mgmt, | 
 | 2179 | 					   size_t len) | 
 | 2180 | { | 
 | 2181 | 	struct ieee80211_local *local = sdata->local; | 
 | 2182 | 	struct sk_buff *skb; | 
 | 2183 | 	struct ieee80211_mgmt *resp; | 
 | 2184 |  | 
 | 2185 | 	if (compare_ether_addr(mgmt->da, sdata->vif.addr) != 0) { | 
 | 2186 | 		/* Not to own unicast address */ | 
 | 2187 | 		return; | 
 | 2188 | 	} | 
 | 2189 |  | 
 | 2190 | 	if (compare_ether_addr(mgmt->sa, sdata->u.mgd.bssid) != 0 || | 
 | 2191 | 	    compare_ether_addr(mgmt->bssid, sdata->u.mgd.bssid) != 0) { | 
 | 2192 | 		/* Not from the current AP or not associated yet. */ | 
 | 2193 | 		return; | 
 | 2194 | 	} | 
 | 2195 |  | 
 | 2196 | 	if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) { | 
 | 2197 | 		/* Too short SA Query request frame */ | 
 | 2198 | 		return; | 
 | 2199 | 	} | 
 | 2200 |  | 
 | 2201 | 	skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom); | 
 | 2202 | 	if (skb == NULL) | 
 | 2203 | 		return; | 
 | 2204 |  | 
 | 2205 | 	skb_reserve(skb, local->hw.extra_tx_headroom); | 
 | 2206 | 	resp = (struct ieee80211_mgmt *) skb_put(skb, 24); | 
 | 2207 | 	memset(resp, 0, 24); | 
 | 2208 | 	memcpy(resp->da, mgmt->sa, ETH_ALEN); | 
 | 2209 | 	memcpy(resp->sa, sdata->vif.addr, ETH_ALEN); | 
 | 2210 | 	memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN); | 
 | 2211 | 	resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | 
 | 2212 | 					  IEEE80211_STYPE_ACTION); | 
 | 2213 | 	skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query)); | 
 | 2214 | 	resp->u.action.category = WLAN_CATEGORY_SA_QUERY; | 
 | 2215 | 	resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE; | 
 | 2216 | 	memcpy(resp->u.action.u.sa_query.trans_id, | 
 | 2217 | 	       mgmt->u.action.u.sa_query.trans_id, | 
 | 2218 | 	       WLAN_SA_QUERY_TR_ID_LEN); | 
 | 2219 |  | 
 | 2220 | 	ieee80211_tx_skb(sdata, skb); | 
 | 2221 | } | 
 | 2222 |  | 
 | 2223 | static ieee80211_rx_result debug_noinline | 
 | 2224 | ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx) | 
 | 2225 | { | 
 | 2226 | 	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data; | 
 | 2227 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); | 
 | 2228 |  | 
 | 2229 | 	/* | 
 | 2230 | 	 * From here on, look only at management frames. | 
 | 2231 | 	 * Data and control frames are already handled, | 
 | 2232 | 	 * and unknown (reserved) frames are useless. | 
 | 2233 | 	 */ | 
 | 2234 | 	if (rx->skb->len < 24) | 
 | 2235 | 		return RX_DROP_MONITOR; | 
 | 2236 |  | 
 | 2237 | 	if (!ieee80211_is_mgmt(mgmt->frame_control)) | 
 | 2238 | 		return RX_DROP_MONITOR; | 
 | 2239 |  | 
 | 2240 | 	if (rx->sdata->vif.type == NL80211_IFTYPE_AP && | 
 | 2241 | 	    ieee80211_is_beacon(mgmt->frame_control) && | 
 | 2242 | 	    !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) { | 
 | 2243 | 		int sig = 0; | 
 | 2244 |  | 
 | 2245 | 		if (rx->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) | 
 | 2246 | 			sig = status->signal; | 
 | 2247 |  | 
 | 2248 | 		cfg80211_report_obss_beacon(rx->local->hw.wiphy, | 
 | 2249 | 					    rx->skb->data, rx->skb->len, | 
 | 2250 | 					    status->freq, sig, GFP_ATOMIC); | 
 | 2251 | 		rx->flags |= IEEE80211_RX_BEACON_REPORTED; | 
 | 2252 | 	} | 
 | 2253 |  | 
 | 2254 | 	if (!(status->rx_flags & IEEE80211_RX_RA_MATCH)) | 
 | 2255 | 		return RX_DROP_MONITOR; | 
 | 2256 |  | 
 | 2257 | 	if (ieee80211_drop_unencrypted_mgmt(rx)) | 
 | 2258 | 		return RX_DROP_UNUSABLE; | 
 | 2259 |  | 
 | 2260 | 	return RX_CONTINUE; | 
 | 2261 | } | 
 | 2262 |  | 
 | 2263 | static ieee80211_rx_result debug_noinline | 
 | 2264 | ieee80211_rx_h_action(struct ieee80211_rx_data *rx) | 
 | 2265 | { | 
 | 2266 | 	struct ieee80211_local *local = rx->local; | 
 | 2267 | 	struct ieee80211_sub_if_data *sdata = rx->sdata; | 
 | 2268 | 	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data; | 
 | 2269 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); | 
 | 2270 | 	int len = rx->skb->len; | 
 | 2271 |  | 
 | 2272 | 	if (!ieee80211_is_action(mgmt->frame_control)) | 
 | 2273 | 		return RX_CONTINUE; | 
 | 2274 |  | 
 | 2275 | 	/* drop too small frames */ | 
 | 2276 | 	if (len < IEEE80211_MIN_ACTION_SIZE) | 
 | 2277 | 		return RX_DROP_UNUSABLE; | 
 | 2278 |  | 
 | 2279 | 	if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC) | 
 | 2280 | 		return RX_DROP_UNUSABLE; | 
 | 2281 |  | 
 | 2282 | 	if (!(status->rx_flags & IEEE80211_RX_RA_MATCH)) | 
 | 2283 | 		return RX_DROP_UNUSABLE; | 
 | 2284 |  | 
 | 2285 | 	switch (mgmt->u.action.category) { | 
 | 2286 | 	case WLAN_CATEGORY_HT: | 
 | 2287 | 		/* reject HT action frames from stations not supporting HT */ | 
 | 2288 | 		if (!rx->sta->sta.ht_cap.ht_supported) | 
 | 2289 | 			goto invalid; | 
 | 2290 |  | 
 | 2291 | 		if (sdata->vif.type != NL80211_IFTYPE_STATION && | 
 | 2292 | 		    sdata->vif.type != NL80211_IFTYPE_MESH_POINT && | 
 | 2293 | 		    sdata->vif.type != NL80211_IFTYPE_AP_VLAN && | 
 | 2294 | 		    sdata->vif.type != NL80211_IFTYPE_AP && | 
 | 2295 | 		    sdata->vif.type != NL80211_IFTYPE_ADHOC) | 
 | 2296 | 			break; | 
 | 2297 |  | 
 | 2298 | 		/* verify action & smps_control are present */ | 
 | 2299 | 		if (len < IEEE80211_MIN_ACTION_SIZE + 2) | 
 | 2300 | 			goto invalid; | 
 | 2301 |  | 
 | 2302 | 		switch (mgmt->u.action.u.ht_smps.action) { | 
 | 2303 | 		case WLAN_HT_ACTION_SMPS: { | 
 | 2304 | 			struct ieee80211_supported_band *sband; | 
 | 2305 | 			u8 smps; | 
 | 2306 |  | 
 | 2307 | 			/* convert to HT capability */ | 
 | 2308 | 			switch (mgmt->u.action.u.ht_smps.smps_control) { | 
 | 2309 | 			case WLAN_HT_SMPS_CONTROL_DISABLED: | 
 | 2310 | 				smps = WLAN_HT_CAP_SM_PS_DISABLED; | 
 | 2311 | 				break; | 
 | 2312 | 			case WLAN_HT_SMPS_CONTROL_STATIC: | 
 | 2313 | 				smps = WLAN_HT_CAP_SM_PS_STATIC; | 
 | 2314 | 				break; | 
 | 2315 | 			case WLAN_HT_SMPS_CONTROL_DYNAMIC: | 
 | 2316 | 				smps = WLAN_HT_CAP_SM_PS_DYNAMIC; | 
 | 2317 | 				break; | 
 | 2318 | 			default: | 
 | 2319 | 				goto invalid; | 
 | 2320 | 			} | 
 | 2321 | 			smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT; | 
 | 2322 |  | 
 | 2323 | 			/* if no change do nothing */ | 
 | 2324 | 			if ((rx->sta->sta.ht_cap.cap & | 
 | 2325 | 					IEEE80211_HT_CAP_SM_PS) == smps) | 
 | 2326 | 				goto handled; | 
 | 2327 |  | 
 | 2328 | 			rx->sta->sta.ht_cap.cap &= ~IEEE80211_HT_CAP_SM_PS; | 
 | 2329 | 			rx->sta->sta.ht_cap.cap |= smps; | 
 | 2330 |  | 
 | 2331 | 			sband = rx->local->hw.wiphy->bands[status->band]; | 
 | 2332 |  | 
 | 2333 | 			rate_control_rate_update( | 
 | 2334 | 				local, sband, rx->sta, | 
 | 2335 | 				IEEE80211_RC_SMPS_CHANGED, | 
 | 2336 | 				ieee80211_get_tx_channel_type( | 
 | 2337 | 					local, local->_oper_channel_type)); | 
 | 2338 | 			goto handled; | 
 | 2339 | 		} | 
 | 2340 | 		default: | 
 | 2341 | 			goto invalid; | 
 | 2342 | 		} | 
 | 2343 |  | 
 | 2344 | 		break; | 
 | 2345 | 	case WLAN_CATEGORY_BACK: | 
 | 2346 | 		if (sdata->vif.type != NL80211_IFTYPE_STATION && | 
 | 2347 | 		    sdata->vif.type != NL80211_IFTYPE_MESH_POINT && | 
 | 2348 | 		    sdata->vif.type != NL80211_IFTYPE_AP_VLAN && | 
 | 2349 | 		    sdata->vif.type != NL80211_IFTYPE_AP && | 
 | 2350 | 		    sdata->vif.type != NL80211_IFTYPE_ADHOC) | 
 | 2351 | 			break; | 
 | 2352 |  | 
 | 2353 | 		/* verify action_code is present */ | 
 | 2354 | 		if (len < IEEE80211_MIN_ACTION_SIZE + 1) | 
 | 2355 | 			break; | 
 | 2356 |  | 
 | 2357 | 		switch (mgmt->u.action.u.addba_req.action_code) { | 
 | 2358 | 		case WLAN_ACTION_ADDBA_REQ: | 
 | 2359 | 			if (len < (IEEE80211_MIN_ACTION_SIZE + | 
 | 2360 | 				   sizeof(mgmt->u.action.u.addba_req))) | 
 | 2361 | 				goto invalid; | 
 | 2362 | 			break; | 
 | 2363 | 		case WLAN_ACTION_ADDBA_RESP: | 
 | 2364 | 			if (len < (IEEE80211_MIN_ACTION_SIZE + | 
 | 2365 | 				   sizeof(mgmt->u.action.u.addba_resp))) | 
 | 2366 | 				goto invalid; | 
 | 2367 | 			break; | 
 | 2368 | 		case WLAN_ACTION_DELBA: | 
 | 2369 | 			if (len < (IEEE80211_MIN_ACTION_SIZE + | 
 | 2370 | 				   sizeof(mgmt->u.action.u.delba))) | 
 | 2371 | 				goto invalid; | 
 | 2372 | 			break; | 
 | 2373 | 		default: | 
 | 2374 | 			goto invalid; | 
 | 2375 | 		} | 
 | 2376 |  | 
 | 2377 | 		goto queue; | 
 | 2378 | 	case WLAN_CATEGORY_SPECTRUM_MGMT: | 
 | 2379 | 		if (local->hw.conf.channel->band != IEEE80211_BAND_5GHZ) | 
 | 2380 | 			break; | 
 | 2381 |  | 
 | 2382 | 		if (sdata->vif.type != NL80211_IFTYPE_STATION) | 
 | 2383 | 			break; | 
 | 2384 |  | 
 | 2385 | 		/* verify action_code is present */ | 
 | 2386 | 		if (len < IEEE80211_MIN_ACTION_SIZE + 1) | 
 | 2387 | 			break; | 
 | 2388 |  | 
 | 2389 | 		switch (mgmt->u.action.u.measurement.action_code) { | 
 | 2390 | 		case WLAN_ACTION_SPCT_MSR_REQ: | 
 | 2391 | 			if (len < (IEEE80211_MIN_ACTION_SIZE + | 
 | 2392 | 				   sizeof(mgmt->u.action.u.measurement))) | 
 | 2393 | 				break; | 
 | 2394 | 			ieee80211_process_measurement_req(sdata, mgmt, len); | 
 | 2395 | 			goto handled; | 
 | 2396 | 		case WLAN_ACTION_SPCT_CHL_SWITCH: | 
 | 2397 | 			if (len < (IEEE80211_MIN_ACTION_SIZE + | 
 | 2398 | 				   sizeof(mgmt->u.action.u.chan_switch))) | 
 | 2399 | 				break; | 
 | 2400 |  | 
 | 2401 | 			if (sdata->vif.type != NL80211_IFTYPE_STATION) | 
 | 2402 | 				break; | 
 | 2403 |  | 
 | 2404 | 			if (compare_ether_addr(mgmt->bssid, sdata->u.mgd.bssid)) | 
 | 2405 | 				break; | 
 | 2406 |  | 
 | 2407 | 			goto queue; | 
 | 2408 | 		} | 
 | 2409 | 		break; | 
 | 2410 | 	case WLAN_CATEGORY_SA_QUERY: | 
 | 2411 | 		if (len < (IEEE80211_MIN_ACTION_SIZE + | 
 | 2412 | 			   sizeof(mgmt->u.action.u.sa_query))) | 
 | 2413 | 			break; | 
 | 2414 |  | 
 | 2415 | 		switch (mgmt->u.action.u.sa_query.action) { | 
 | 2416 | 		case WLAN_ACTION_SA_QUERY_REQUEST: | 
 | 2417 | 			if (sdata->vif.type != NL80211_IFTYPE_STATION) | 
 | 2418 | 				break; | 
 | 2419 | 			ieee80211_process_sa_query_req(sdata, mgmt, len); | 
 | 2420 | 			goto handled; | 
 | 2421 | 		} | 
 | 2422 | 		break; | 
 | 2423 | 	case WLAN_CATEGORY_SELF_PROTECTED: | 
 | 2424 | 		if (len < (IEEE80211_MIN_ACTION_SIZE + | 
 | 2425 | 			   sizeof(mgmt->u.action.u.self_prot.action_code))) | 
 | 2426 | 			break; | 
 | 2427 |  | 
 | 2428 | 		switch (mgmt->u.action.u.self_prot.action_code) { | 
 | 2429 | 		case WLAN_SP_MESH_PEERING_OPEN: | 
 | 2430 | 		case WLAN_SP_MESH_PEERING_CLOSE: | 
 | 2431 | 		case WLAN_SP_MESH_PEERING_CONFIRM: | 
 | 2432 | 			if (!ieee80211_vif_is_mesh(&sdata->vif)) | 
 | 2433 | 				goto invalid; | 
 | 2434 | 			if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE) | 
 | 2435 | 				/* userspace handles this frame */ | 
 | 2436 | 				break; | 
 | 2437 | 			goto queue; | 
 | 2438 | 		case WLAN_SP_MGK_INFORM: | 
 | 2439 | 		case WLAN_SP_MGK_ACK: | 
 | 2440 | 			if (!ieee80211_vif_is_mesh(&sdata->vif)) | 
 | 2441 | 				goto invalid; | 
 | 2442 | 			break; | 
 | 2443 | 		} | 
 | 2444 | 		break; | 
 | 2445 | 	case WLAN_CATEGORY_MESH_ACTION: | 
 | 2446 | 		if (len < (IEEE80211_MIN_ACTION_SIZE + | 
 | 2447 | 			   sizeof(mgmt->u.action.u.mesh_action.action_code))) | 
 | 2448 | 			break; | 
 | 2449 |  | 
 | 2450 | 		if (!ieee80211_vif_is_mesh(&sdata->vif)) | 
 | 2451 | 			break; | 
 | 2452 | 		if (mesh_action_is_path_sel(mgmt) && | 
 | 2453 | 		  (!mesh_path_sel_is_hwmp(sdata))) | 
 | 2454 | 			break; | 
 | 2455 | 		goto queue; | 
 | 2456 | 	} | 
 | 2457 |  | 
 | 2458 | 	return RX_CONTINUE; | 
 | 2459 |  | 
 | 2460 |  invalid: | 
 | 2461 | 	status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM; | 
 | 2462 | 	/* will return in the next handlers */ | 
 | 2463 | 	return RX_CONTINUE; | 
 | 2464 |  | 
 | 2465 |  handled: | 
 | 2466 | 	if (rx->sta) | 
 | 2467 | 		rx->sta->rx_packets++; | 
 | 2468 | 	dev_kfree_skb(rx->skb); | 
 | 2469 | 	return RX_QUEUED; | 
 | 2470 |  | 
 | 2471 |  queue: | 
 | 2472 | 	rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME; | 
 | 2473 | 	skb_queue_tail(&sdata->skb_queue, rx->skb); | 
 | 2474 | 	ieee80211_queue_work(&local->hw, &sdata->work); | 
 | 2475 | 	if (rx->sta) | 
 | 2476 | 		rx->sta->rx_packets++; | 
 | 2477 | 	return RX_QUEUED; | 
 | 2478 | } | 
 | 2479 |  | 
 | 2480 | static ieee80211_rx_result debug_noinline | 
 | 2481 | ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx) | 
 | 2482 | { | 
 | 2483 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); | 
 | 2484 | 	int sig = 0; | 
 | 2485 |  | 
 | 2486 | 	/* skip known-bad action frames and return them in the next handler */ | 
 | 2487 | 	if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) | 
 | 2488 | 		return RX_CONTINUE; | 
 | 2489 |  | 
 | 2490 | 	/* | 
 | 2491 | 	 * Getting here means the kernel doesn't know how to handle | 
 | 2492 | 	 * it, but maybe userspace does ... include returned frames | 
 | 2493 | 	 * so userspace can register for those to know whether ones | 
 | 2494 | 	 * it transmitted were processed or returned. | 
 | 2495 | 	 */ | 
 | 2496 |  | 
 | 2497 | 	if (rx->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) | 
 | 2498 | 		sig = status->signal; | 
 | 2499 |  | 
 | 2500 | 	if (cfg80211_rx_mgmt(rx->sdata->dev, status->freq, sig, | 
 | 2501 | 			     rx->skb->data, rx->skb->len, | 
 | 2502 | 			     GFP_ATOMIC)) { | 
 | 2503 | 		if (rx->sta) | 
 | 2504 | 			rx->sta->rx_packets++; | 
 | 2505 | 		dev_kfree_skb(rx->skb); | 
 | 2506 | 		return RX_QUEUED; | 
 | 2507 | 	} | 
 | 2508 |  | 
 | 2509 |  | 
 | 2510 | 	return RX_CONTINUE; | 
 | 2511 | } | 
 | 2512 |  | 
 | 2513 | static ieee80211_rx_result debug_noinline | 
 | 2514 | ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx) | 
 | 2515 | { | 
 | 2516 | 	struct ieee80211_local *local = rx->local; | 
 | 2517 | 	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data; | 
 | 2518 | 	struct sk_buff *nskb; | 
 | 2519 | 	struct ieee80211_sub_if_data *sdata = rx->sdata; | 
 | 2520 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); | 
 | 2521 |  | 
 | 2522 | 	if (!ieee80211_is_action(mgmt->frame_control)) | 
 | 2523 | 		return RX_CONTINUE; | 
 | 2524 |  | 
 | 2525 | 	/* | 
 | 2526 | 	 * For AP mode, hostapd is responsible for handling any action | 
 | 2527 | 	 * frames that we didn't handle, including returning unknown | 
 | 2528 | 	 * ones. For all other modes we will return them to the sender, | 
 | 2529 | 	 * setting the 0x80 bit in the action category, as required by | 
 | 2530 | 	 * 802.11-2012 9.24.4. | 
 | 2531 | 	 * Newer versions of hostapd shall also use the management frame | 
 | 2532 | 	 * registration mechanisms, but older ones still use cooked | 
 | 2533 | 	 * monitor interfaces so push all frames there. | 
 | 2534 | 	 */ | 
 | 2535 | 	if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) && | 
 | 2536 | 	    (sdata->vif.type == NL80211_IFTYPE_AP || | 
 | 2537 | 	     sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) | 
 | 2538 | 		return RX_DROP_MONITOR; | 
 | 2539 |  | 
 | 2540 | 	if (is_multicast_ether_addr(mgmt->da)) | 
 | 2541 | 		return RX_DROP_MONITOR; | 
 | 2542 |  | 
 | 2543 | 	/* do not return rejected action frames */ | 
 | 2544 | 	if (mgmt->u.action.category & 0x80) | 
 | 2545 | 		return RX_DROP_UNUSABLE; | 
 | 2546 |  | 
 | 2547 | 	nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0, | 
 | 2548 | 			       GFP_ATOMIC); | 
 | 2549 | 	if (nskb) { | 
 | 2550 | 		struct ieee80211_mgmt *nmgmt = (void *)nskb->data; | 
 | 2551 |  | 
 | 2552 | 		nmgmt->u.action.category |= 0x80; | 
 | 2553 | 		memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN); | 
 | 2554 | 		memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN); | 
 | 2555 |  | 
 | 2556 | 		memset(nskb->cb, 0, sizeof(nskb->cb)); | 
 | 2557 |  | 
 | 2558 | 		ieee80211_tx_skb(rx->sdata, nskb); | 
 | 2559 | 	} | 
 | 2560 | 	dev_kfree_skb(rx->skb); | 
 | 2561 | 	return RX_QUEUED; | 
 | 2562 | } | 
 | 2563 |  | 
 | 2564 | static ieee80211_rx_result debug_noinline | 
 | 2565 | ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx) | 
 | 2566 | { | 
 | 2567 | 	struct ieee80211_sub_if_data *sdata = rx->sdata; | 
 | 2568 | 	struct ieee80211_mgmt *mgmt = (void *)rx->skb->data; | 
 | 2569 | 	__le16 stype; | 
 | 2570 |  | 
 | 2571 | 	stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE); | 
 | 2572 |  | 
 | 2573 | 	if (!ieee80211_vif_is_mesh(&sdata->vif) && | 
 | 2574 | 	    sdata->vif.type != NL80211_IFTYPE_ADHOC && | 
 | 2575 | 	    sdata->vif.type != NL80211_IFTYPE_STATION) | 
 | 2576 | 		return RX_DROP_MONITOR; | 
 | 2577 |  | 
 | 2578 | 	switch (stype) { | 
 | 2579 | 	case cpu_to_le16(IEEE80211_STYPE_AUTH): | 
 | 2580 | 	case cpu_to_le16(IEEE80211_STYPE_BEACON): | 
 | 2581 | 	case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP): | 
 | 2582 | 		/* process for all: mesh, mlme, ibss */ | 
 | 2583 | 		break; | 
 | 2584 | 	case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP): | 
 | 2585 | 	case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP): | 
 | 2586 | 	case cpu_to_le16(IEEE80211_STYPE_DEAUTH): | 
 | 2587 | 	case cpu_to_le16(IEEE80211_STYPE_DISASSOC): | 
 | 2588 | 		if (is_multicast_ether_addr(mgmt->da) && | 
 | 2589 | 		    !is_broadcast_ether_addr(mgmt->da)) | 
 | 2590 | 			return RX_DROP_MONITOR; | 
 | 2591 |  | 
 | 2592 | 		/* process only for station */ | 
 | 2593 | 		if (sdata->vif.type != NL80211_IFTYPE_STATION) | 
 | 2594 | 			return RX_DROP_MONITOR; | 
 | 2595 | 		break; | 
 | 2596 | 	case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ): | 
 | 2597 | 		/* process only for ibss */ | 
 | 2598 | 		if (sdata->vif.type != NL80211_IFTYPE_ADHOC) | 
 | 2599 | 			return RX_DROP_MONITOR; | 
 | 2600 | 		break; | 
 | 2601 | 	default: | 
 | 2602 | 		return RX_DROP_MONITOR; | 
 | 2603 | 	} | 
 | 2604 |  | 
 | 2605 | 	/* queue up frame and kick off work to process it */ | 
 | 2606 | 	rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME; | 
 | 2607 | 	skb_queue_tail(&sdata->skb_queue, rx->skb); | 
 | 2608 | 	ieee80211_queue_work(&rx->local->hw, &sdata->work); | 
 | 2609 | 	if (rx->sta) | 
 | 2610 | 		rx->sta->rx_packets++; | 
 | 2611 |  | 
 | 2612 | 	return RX_QUEUED; | 
 | 2613 | } | 
 | 2614 |  | 
 | 2615 | /* TODO: use IEEE80211_RX_FRAGMENTED */ | 
 | 2616 | static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx, | 
 | 2617 | 					struct ieee80211_rate *rate) | 
 | 2618 | { | 
 | 2619 | 	struct ieee80211_sub_if_data *sdata; | 
 | 2620 | 	struct ieee80211_local *local = rx->local; | 
 | 2621 | 	struct sk_buff *skb = rx->skb, *skb2; | 
 | 2622 | 	struct net_device *prev_dev = NULL; | 
 | 2623 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); | 
 | 2624 | 	int needed_headroom; | 
 | 2625 |  | 
 | 2626 | 	/* | 
 | 2627 | 	 * If cooked monitor has been processed already, then | 
 | 2628 | 	 * don't do it again. If not, set the flag. | 
 | 2629 | 	 */ | 
 | 2630 | 	if (rx->flags & IEEE80211_RX_CMNTR) | 
 | 2631 | 		goto out_free_skb; | 
 | 2632 | 	rx->flags |= IEEE80211_RX_CMNTR; | 
 | 2633 |  | 
 | 2634 | 	/* If there are no cooked monitor interfaces, just free the SKB */ | 
 | 2635 | 	if (!local->cooked_mntrs) | 
 | 2636 | 		goto out_free_skb; | 
 | 2637 |  | 
 | 2638 | 	/* room for the radiotap header based on driver features */ | 
 | 2639 | 	needed_headroom = ieee80211_rx_radiotap_len(local, status); | 
 | 2640 |  | 
 | 2641 | 	if (skb_headroom(skb) < needed_headroom && | 
 | 2642 | 	    pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) | 
 | 2643 | 		goto out_free_skb; | 
 | 2644 |  | 
 | 2645 | 	/* prepend radiotap information */ | 
 | 2646 | 	ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom, | 
 | 2647 | 					 false); | 
 | 2648 |  | 
 | 2649 | 	skb_set_mac_header(skb, 0); | 
 | 2650 | 	skb->ip_summed = CHECKSUM_UNNECESSARY; | 
 | 2651 | 	skb->pkt_type = PACKET_OTHERHOST; | 
 | 2652 | 	skb->protocol = htons(ETH_P_802_2); | 
 | 2653 |  | 
 | 2654 | 	list_for_each_entry_rcu(sdata, &local->interfaces, list) { | 
 | 2655 | 		if (!ieee80211_sdata_running(sdata)) | 
 | 2656 | 			continue; | 
 | 2657 |  | 
 | 2658 | 		if (sdata->vif.type != NL80211_IFTYPE_MONITOR || | 
 | 2659 | 		    !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)) | 
 | 2660 | 			continue; | 
 | 2661 |  | 
 | 2662 | 		if (prev_dev) { | 
 | 2663 | 			skb2 = skb_clone(skb, GFP_ATOMIC); | 
 | 2664 | 			if (skb2) { | 
 | 2665 | 				skb2->dev = prev_dev; | 
 | 2666 | 				netif_receive_skb(skb2); | 
 | 2667 | 			} | 
 | 2668 | 		} | 
 | 2669 |  | 
 | 2670 | 		prev_dev = sdata->dev; | 
 | 2671 | 		sdata->dev->stats.rx_packets++; | 
 | 2672 | 		sdata->dev->stats.rx_bytes += skb->len; | 
 | 2673 | 	} | 
 | 2674 |  | 
 | 2675 | 	if (prev_dev) { | 
 | 2676 | 		skb->dev = prev_dev; | 
 | 2677 | 		netif_receive_skb(skb); | 
 | 2678 | 		return; | 
 | 2679 | 	} | 
 | 2680 |  | 
 | 2681 |  out_free_skb: | 
 | 2682 | 	dev_kfree_skb(skb); | 
 | 2683 | } | 
 | 2684 |  | 
 | 2685 | static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx, | 
 | 2686 | 					 ieee80211_rx_result res) | 
 | 2687 | { | 
 | 2688 | 	switch (res) { | 
 | 2689 | 	case RX_DROP_MONITOR: | 
 | 2690 | 		I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop); | 
 | 2691 | 		if (rx->sta) | 
 | 2692 | 			rx->sta->rx_dropped++; | 
 | 2693 | 		/* fall through */ | 
 | 2694 | 	case RX_CONTINUE: { | 
 | 2695 | 		struct ieee80211_rate *rate = NULL; | 
 | 2696 | 		struct ieee80211_supported_band *sband; | 
 | 2697 | 		struct ieee80211_rx_status *status; | 
 | 2698 |  | 
 | 2699 | 		status = IEEE80211_SKB_RXCB((rx->skb)); | 
 | 2700 |  | 
 | 2701 | 		sband = rx->local->hw.wiphy->bands[status->band]; | 
 | 2702 | 		if (!(status->flag & RX_FLAG_HT)) | 
 | 2703 | 			rate = &sband->bitrates[status->rate_idx]; | 
 | 2704 |  | 
 | 2705 | 		ieee80211_rx_cooked_monitor(rx, rate); | 
 | 2706 | 		break; | 
 | 2707 | 		} | 
 | 2708 | 	case RX_DROP_UNUSABLE: | 
 | 2709 | 		I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop); | 
 | 2710 | 		if (rx->sta) | 
 | 2711 | 			rx->sta->rx_dropped++; | 
 | 2712 | 		dev_kfree_skb(rx->skb); | 
 | 2713 | 		break; | 
 | 2714 | 	case RX_QUEUED: | 
 | 2715 | 		I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued); | 
 | 2716 | 		break; | 
 | 2717 | 	} | 
 | 2718 | } | 
 | 2719 |  | 
 | 2720 | static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx) | 
 | 2721 | { | 
 | 2722 | 	ieee80211_rx_result res = RX_DROP_MONITOR; | 
 | 2723 | 	struct sk_buff *skb; | 
 | 2724 |  | 
 | 2725 | #define CALL_RXH(rxh)			\ | 
 | 2726 | 	do {				\ | 
 | 2727 | 		res = rxh(rx);		\ | 
 | 2728 | 		if (res != RX_CONTINUE)	\ | 
 | 2729 | 			goto rxh_next;  \ | 
 | 2730 | 	} while (0); | 
 | 2731 |  | 
 | 2732 | 	spin_lock(&rx->local->rx_skb_queue.lock); | 
 | 2733 | 	if (rx->local->running_rx_handler) | 
 | 2734 | 		goto unlock; | 
 | 2735 |  | 
 | 2736 | 	rx->local->running_rx_handler = true; | 
 | 2737 |  | 
 | 2738 | 	while ((skb = __skb_dequeue(&rx->local->rx_skb_queue))) { | 
 | 2739 | 		spin_unlock(&rx->local->rx_skb_queue.lock); | 
 | 2740 |  | 
 | 2741 | 		/* | 
 | 2742 | 		 * all the other fields are valid across frames | 
 | 2743 | 		 * that belong to an aMPDU since they are on the | 
 | 2744 | 		 * same TID from the same station | 
 | 2745 | 		 */ | 
 | 2746 | 		rx->skb = skb; | 
 | 2747 |  | 
 | 2748 | 		CALL_RXH(ieee80211_rx_h_decrypt) | 
 | 2749 | 		CALL_RXH(ieee80211_rx_h_check_more_data) | 
 | 2750 | 		CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll) | 
 | 2751 | 		CALL_RXH(ieee80211_rx_h_sta_process) | 
 | 2752 | 		CALL_RXH(ieee80211_rx_h_defragment) | 
 | 2753 | 		CALL_RXH(ieee80211_rx_h_michael_mic_verify) | 
 | 2754 | 		/* must be after MMIC verify so header is counted in MPDU mic */ | 
 | 2755 | #ifdef CONFIG_MAC80211_MESH | 
 | 2756 | 		if (ieee80211_vif_is_mesh(&rx->sdata->vif)) | 
 | 2757 | 			CALL_RXH(ieee80211_rx_h_mesh_fwding); | 
 | 2758 | #endif | 
 | 2759 | 		CALL_RXH(ieee80211_rx_h_amsdu) | 
 | 2760 | 		CALL_RXH(ieee80211_rx_h_data) | 
 | 2761 | 		CALL_RXH(ieee80211_rx_h_ctrl); | 
 | 2762 | 		CALL_RXH(ieee80211_rx_h_mgmt_check) | 
 | 2763 | 		CALL_RXH(ieee80211_rx_h_action) | 
 | 2764 | 		CALL_RXH(ieee80211_rx_h_userspace_mgmt) | 
 | 2765 | 		CALL_RXH(ieee80211_rx_h_action_return) | 
 | 2766 | 		CALL_RXH(ieee80211_rx_h_mgmt) | 
 | 2767 |  | 
 | 2768 |  rxh_next: | 
 | 2769 | 		ieee80211_rx_handlers_result(rx, res); | 
 | 2770 | 		spin_lock(&rx->local->rx_skb_queue.lock); | 
 | 2771 | #undef CALL_RXH | 
 | 2772 | 	} | 
 | 2773 |  | 
 | 2774 | 	rx->local->running_rx_handler = false; | 
 | 2775 |  | 
 | 2776 |  unlock: | 
 | 2777 | 	spin_unlock(&rx->local->rx_skb_queue.lock); | 
 | 2778 | } | 
 | 2779 |  | 
 | 2780 | static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx) | 
 | 2781 | { | 
 | 2782 | 	ieee80211_rx_result res = RX_DROP_MONITOR; | 
 | 2783 |  | 
 | 2784 | #define CALL_RXH(rxh)			\ | 
 | 2785 | 	do {				\ | 
 | 2786 | 		res = rxh(rx);		\ | 
 | 2787 | 		if (res != RX_CONTINUE)	\ | 
 | 2788 | 			goto rxh_next;  \ | 
 | 2789 | 	} while (0); | 
 | 2790 |  | 
 | 2791 | 	CALL_RXH(ieee80211_rx_h_passive_scan) | 
 | 2792 | 	CALL_RXH(ieee80211_rx_h_check) | 
 | 2793 |  | 
 | 2794 | 	ieee80211_rx_reorder_ampdu(rx); | 
 | 2795 |  | 
 | 2796 | 	ieee80211_rx_handlers(rx); | 
 | 2797 | 	return; | 
 | 2798 |  | 
 | 2799 |  rxh_next: | 
 | 2800 | 	ieee80211_rx_handlers_result(rx, res); | 
 | 2801 |  | 
 | 2802 | #undef CALL_RXH | 
 | 2803 | } | 
 | 2804 |  | 
 | 2805 | /* | 
 | 2806 |  * This function makes calls into the RX path, therefore | 
 | 2807 |  * it has to be invoked under RCU read lock. | 
 | 2808 |  */ | 
 | 2809 | void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid) | 
 | 2810 | { | 
 | 2811 | 	struct ieee80211_rx_data rx = { | 
 | 2812 | 		.sta = sta, | 
 | 2813 | 		.sdata = sta->sdata, | 
 | 2814 | 		.local = sta->local, | 
 | 2815 | 		/* This is OK -- must be QoS data frame */ | 
 | 2816 | 		.security_idx = tid, | 
 | 2817 | 		.seqno_idx = tid, | 
 | 2818 | 		.flags = 0, | 
 | 2819 | 	}; | 
 | 2820 | 	struct tid_ampdu_rx *tid_agg_rx; | 
 | 2821 |  | 
 | 2822 | 	tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]); | 
 | 2823 | 	if (!tid_agg_rx) | 
 | 2824 | 		return; | 
 | 2825 |  | 
 | 2826 | 	spin_lock(&tid_agg_rx->reorder_lock); | 
 | 2827 | 	ieee80211_sta_reorder_release(&sta->local->hw, tid_agg_rx); | 
 | 2828 | 	spin_unlock(&tid_agg_rx->reorder_lock); | 
 | 2829 |  | 
 | 2830 | 	ieee80211_rx_handlers(&rx); | 
 | 2831 | } | 
 | 2832 |  | 
 | 2833 | /* main receive path */ | 
 | 2834 |  | 
 | 2835 | static int prepare_for_handlers(struct ieee80211_rx_data *rx, | 
 | 2836 | 				struct ieee80211_hdr *hdr) | 
 | 2837 | { | 
 | 2838 | 	struct ieee80211_sub_if_data *sdata = rx->sdata; | 
 | 2839 | 	struct sk_buff *skb = rx->skb; | 
 | 2840 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); | 
 | 2841 | 	u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type); | 
 | 2842 | 	int multicast = is_multicast_ether_addr(hdr->addr1); | 
 | 2843 |  | 
 | 2844 | 	switch (sdata->vif.type) { | 
 | 2845 | 	case NL80211_IFTYPE_STATION: | 
 | 2846 | 		if (!bssid && !sdata->u.mgd.use_4addr) | 
 | 2847 | 			return 0; | 
 | 2848 | 		if (!multicast && | 
 | 2849 | 		    compare_ether_addr(sdata->vif.addr, hdr->addr1) != 0) { | 
 | 2850 | 			if (!(sdata->dev->flags & IFF_PROMISC) || | 
 | 2851 | 			    sdata->u.mgd.use_4addr) | 
 | 2852 | 				return 0; | 
 | 2853 | 			status->rx_flags &= ~IEEE80211_RX_RA_MATCH; | 
 | 2854 | 		} | 
 | 2855 | 		break; | 
 | 2856 | 	case NL80211_IFTYPE_ADHOC: | 
 | 2857 | 		if (!bssid) | 
 | 2858 | 			return 0; | 
 | 2859 | 		if (compare_ether_addr(sdata->vif.addr, hdr->addr2) == 0 || | 
 | 2860 | 		    compare_ether_addr(sdata->u.ibss.bssid, hdr->addr2) == 0) | 
 | 2861 | 			return 0; | 
 | 2862 | 		if (ieee80211_is_beacon(hdr->frame_control)) { | 
 | 2863 | 			return 1; | 
 | 2864 | 		} | 
 | 2865 | 		else if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid)) { | 
 | 2866 | 			if (!(status->rx_flags & IEEE80211_RX_IN_SCAN)) | 
 | 2867 | 				return 0; | 
 | 2868 | 			status->rx_flags &= ~IEEE80211_RX_RA_MATCH; | 
 | 2869 | 		} else if (!multicast && | 
 | 2870 | 			   compare_ether_addr(sdata->vif.addr, | 
 | 2871 | 					      hdr->addr1) != 0) { | 
 | 2872 | 			if (!(sdata->dev->flags & IFF_PROMISC)) | 
 | 2873 | 				return 0; | 
 | 2874 | 			status->rx_flags &= ~IEEE80211_RX_RA_MATCH; | 
 | 2875 | 		} else if (!rx->sta) { | 
 | 2876 | 			int rate_idx; | 
 | 2877 | 			if (status->flag & RX_FLAG_HT) | 
 | 2878 | 				rate_idx = 0; /* TODO: HT rates */ | 
 | 2879 | 			else | 
 | 2880 | 				rate_idx = status->rate_idx; | 
 | 2881 | 			ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2, | 
 | 2882 | 						 BIT(rate_idx)); | 
 | 2883 | 		} | 
 | 2884 | 		break; | 
 | 2885 | 	case NL80211_IFTYPE_MESH_POINT: | 
 | 2886 | 		if (!multicast && | 
 | 2887 | 		    compare_ether_addr(sdata->vif.addr, | 
 | 2888 | 				       hdr->addr1) != 0) { | 
 | 2889 | 			if (!(sdata->dev->flags & IFF_PROMISC)) | 
 | 2890 | 				return 0; | 
 | 2891 |  | 
 | 2892 | 			status->rx_flags &= ~IEEE80211_RX_RA_MATCH; | 
 | 2893 | 		} | 
 | 2894 | 		break; | 
 | 2895 | 	case NL80211_IFTYPE_AP_VLAN: | 
 | 2896 | 	case NL80211_IFTYPE_AP: | 
 | 2897 | 		if (!bssid) { | 
 | 2898 | 			if (compare_ether_addr(sdata->vif.addr, | 
 | 2899 | 					       hdr->addr1)) | 
 | 2900 | 				return 0; | 
 | 2901 | 		} else if (!ieee80211_bssid_match(bssid, | 
 | 2902 | 					sdata->vif.addr)) { | 
 | 2903 | 			/* | 
 | 2904 | 			 * Accept public action frames even when the | 
 | 2905 | 			 * BSSID doesn't match, this is used for P2P | 
 | 2906 | 			 * and location updates. Note that mac80211 | 
 | 2907 | 			 * itself never looks at these frames. | 
 | 2908 | 			 */ | 
 | 2909 | 			if (!(status->rx_flags & IEEE80211_RX_IN_SCAN) && | 
 | 2910 | 			    ieee80211_is_public_action(hdr, skb->len)) | 
 | 2911 | 				return 1; | 
 | 2912 | 			if (!(status->rx_flags & IEEE80211_RX_IN_SCAN) && | 
 | 2913 | 			    !ieee80211_is_beacon(hdr->frame_control)) | 
 | 2914 | 				return 0; | 
 | 2915 | 			status->rx_flags &= ~IEEE80211_RX_RA_MATCH; | 
 | 2916 | 		} | 
 | 2917 | 		break; | 
 | 2918 | 	case NL80211_IFTYPE_WDS: | 
 | 2919 | 		if (bssid || !ieee80211_is_data(hdr->frame_control)) | 
 | 2920 | 			return 0; | 
 | 2921 | 		if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2)) | 
 | 2922 | 			return 0; | 
 | 2923 | 		break; | 
 | 2924 | 	default: | 
 | 2925 | 		/* should never get here */ | 
 | 2926 | 		WARN_ON(1); | 
 | 2927 | 		break; | 
 | 2928 | 	} | 
 | 2929 |  | 
 | 2930 | 	return 1; | 
 | 2931 | } | 
 | 2932 |  | 
 | 2933 | /* | 
 | 2934 |  * This function returns whether or not the SKB | 
 | 2935 |  * was destined for RX processing or not, which, | 
 | 2936 |  * if consume is true, is equivalent to whether | 
 | 2937 |  * or not the skb was consumed. | 
 | 2938 |  */ | 
 | 2939 | static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx, | 
 | 2940 | 					    struct sk_buff *skb, bool consume) | 
 | 2941 | { | 
 | 2942 | 	struct ieee80211_local *local = rx->local; | 
 | 2943 | 	struct ieee80211_sub_if_data *sdata = rx->sdata; | 
 | 2944 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); | 
 | 2945 | 	struct ieee80211_hdr *hdr = (void *)skb->data; | 
 | 2946 | 	int prepares; | 
 | 2947 |  | 
 | 2948 | 	rx->skb = skb; | 
 | 2949 | 	status->rx_flags |= IEEE80211_RX_RA_MATCH; | 
 | 2950 | 	prepares = prepare_for_handlers(rx, hdr); | 
 | 2951 |  | 
 | 2952 | 	if (!prepares) | 
 | 2953 | 		return false; | 
 | 2954 |  | 
 | 2955 | 	if (!consume) { | 
 | 2956 | 		skb = skb_copy(skb, GFP_ATOMIC); | 
 | 2957 | 		if (!skb) { | 
 | 2958 | 			if (net_ratelimit()) | 
 | 2959 | 				wiphy_debug(local->hw.wiphy, | 
 | 2960 | 					"failed to copy skb for %s\n", | 
 | 2961 | 					sdata->name); | 
 | 2962 | 			return true; | 
 | 2963 | 		} | 
 | 2964 |  | 
 | 2965 | 		rx->skb = skb; | 
 | 2966 | 	} | 
 | 2967 |  | 
 | 2968 | 	ieee80211_invoke_rx_handlers(rx); | 
 | 2969 | 	return true; | 
 | 2970 | } | 
 | 2971 |  | 
 | 2972 | /* | 
 | 2973 |  * This is the actual Rx frames handler. as it blongs to Rx path it must | 
 | 2974 |  * be called with rcu_read_lock protection. | 
 | 2975 |  */ | 
 | 2976 | static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, | 
 | 2977 | 					 struct sk_buff *skb) | 
 | 2978 | { | 
 | 2979 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); | 
 | 2980 | 	struct ieee80211_local *local = hw_to_local(hw); | 
 | 2981 | 	struct ieee80211_sub_if_data *sdata; | 
 | 2982 | 	struct ieee80211_hdr *hdr; | 
 | 2983 | 	__le16 fc; | 
 | 2984 | 	struct ieee80211_rx_data rx; | 
 | 2985 | 	struct ieee80211_sub_if_data *prev; | 
 | 2986 | 	struct sta_info *sta, *tmp, *prev_sta; | 
 | 2987 | 	int err = 0; | 
 | 2988 |  | 
 | 2989 | 	fc = ((struct ieee80211_hdr *)skb->data)->frame_control; | 
 | 2990 | 	memset(&rx, 0, sizeof(rx)); | 
 | 2991 | 	rx.skb = skb; | 
 | 2992 | 	rx.local = local; | 
 | 2993 |  | 
 | 2994 | 	if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc)) | 
 | 2995 | 		local->dot11ReceivedFragmentCount++; | 
 | 2996 |  | 
 | 2997 | 	if (unlikely(test_bit(SCAN_HW_SCANNING, &local->scanning) || | 
 | 2998 | 		     test_bit(SCAN_SW_SCANNING, &local->scanning))) | 
 | 2999 | 		status->rx_flags |= IEEE80211_RX_IN_SCAN; | 
 | 3000 |  | 
 | 3001 | 	if (ieee80211_is_mgmt(fc)) { | 
 | 3002 | 		/* drop frame if too short for header */ | 
 | 3003 | 		if (skb->len < ieee80211_hdrlen(fc)) | 
 | 3004 | 			err = -ENOBUFS; | 
 | 3005 | 		else | 
 | 3006 | 			err = skb_linearize(skb); | 
 | 3007 | 	} else { | 
 | 3008 | 		err = !pskb_may_pull(skb, ieee80211_hdrlen(fc)); | 
 | 3009 | 	} | 
 | 3010 |  | 
 | 3011 | 	if (err) { | 
 | 3012 | 		dev_kfree_skb(skb); | 
 | 3013 | 		return; | 
 | 3014 | 	} | 
 | 3015 |  | 
 | 3016 | 	hdr = (struct ieee80211_hdr *)skb->data; | 
 | 3017 | 	ieee80211_parse_qos(&rx); | 
 | 3018 | 	ieee80211_verify_alignment(&rx); | 
 | 3019 |  | 
 | 3020 | 	if (ieee80211_is_data(fc)) { | 
 | 3021 | 		prev_sta = NULL; | 
 | 3022 |  | 
 | 3023 | 		for_each_sta_info(local, hdr->addr2, sta, tmp) { | 
 | 3024 | 			if (!prev_sta) { | 
 | 3025 | 				prev_sta = sta; | 
 | 3026 | 				continue; | 
 | 3027 | 			} | 
 | 3028 |  | 
 | 3029 | 			rx.sta = prev_sta; | 
 | 3030 | 			rx.sdata = prev_sta->sdata; | 
 | 3031 | 			ieee80211_prepare_and_rx_handle(&rx, skb, false); | 
 | 3032 |  | 
 | 3033 | 			prev_sta = sta; | 
 | 3034 | 		} | 
 | 3035 |  | 
 | 3036 | 		if (prev_sta) { | 
 | 3037 | 			rx.sta = prev_sta; | 
 | 3038 | 			rx.sdata = prev_sta->sdata; | 
 | 3039 |  | 
 | 3040 | 			if (ieee80211_prepare_and_rx_handle(&rx, skb, true)) | 
 | 3041 | 				return; | 
 | 3042 | 			goto out; | 
 | 3043 | 		} | 
 | 3044 | 	} | 
 | 3045 |  | 
 | 3046 | 	prev = NULL; | 
 | 3047 |  | 
 | 3048 | 	list_for_each_entry_rcu(sdata, &local->interfaces, list) { | 
 | 3049 | 		if (!ieee80211_sdata_running(sdata)) | 
 | 3050 | 			continue; | 
 | 3051 |  | 
 | 3052 | 		if (sdata->vif.type == NL80211_IFTYPE_MONITOR || | 
 | 3053 | 		    sdata->vif.type == NL80211_IFTYPE_AP_VLAN) | 
 | 3054 | 			continue; | 
 | 3055 |  | 
 | 3056 | 		/* | 
 | 3057 | 		 * frame is destined for this interface, but if it's | 
 | 3058 | 		 * not also for the previous one we handle that after | 
 | 3059 | 		 * the loop to avoid copying the SKB once too much | 
 | 3060 | 		 */ | 
 | 3061 |  | 
 | 3062 | 		if (!prev) { | 
 | 3063 | 			prev = sdata; | 
 | 3064 | 			continue; | 
 | 3065 | 		} | 
 | 3066 |  | 
 | 3067 | 		rx.sta = sta_info_get_bss(prev, hdr->addr2); | 
 | 3068 | 		rx.sdata = prev; | 
 | 3069 | 		ieee80211_prepare_and_rx_handle(&rx, skb, false); | 
 | 3070 |  | 
 | 3071 | 		prev = sdata; | 
 | 3072 | 	} | 
 | 3073 |  | 
 | 3074 | 	if (prev) { | 
 | 3075 | 		rx.sta = sta_info_get_bss(prev, hdr->addr2); | 
 | 3076 | 		rx.sdata = prev; | 
 | 3077 |  | 
 | 3078 | 		if (ieee80211_prepare_and_rx_handle(&rx, skb, true)) | 
 | 3079 | 			return; | 
 | 3080 | 	} | 
 | 3081 |  | 
 | 3082 |  out: | 
 | 3083 | 	dev_kfree_skb(skb); | 
 | 3084 | } | 
 | 3085 |  | 
 | 3086 | /* | 
 | 3087 |  * This is the receive path handler. It is called by a low level driver when an | 
 | 3088 |  * 802.11 MPDU is received from the hardware. | 
 | 3089 |  */ | 
 | 3090 | void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb) | 
 | 3091 | { | 
 | 3092 | 	struct ieee80211_local *local = hw_to_local(hw); | 
 | 3093 | 	struct ieee80211_rate *rate = NULL; | 
 | 3094 | 	struct ieee80211_supported_band *sband; | 
 | 3095 | 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); | 
 | 3096 |  | 
 | 3097 | 	WARN_ON_ONCE_NONRT(softirq_count() == 0); | 
 | 3098 |  | 
 | 3099 | 	if (WARN_ON(status->band < 0 || | 
 | 3100 | 		    status->band >= IEEE80211_NUM_BANDS)) | 
 | 3101 | 		goto drop; | 
 | 3102 |  | 
 | 3103 | 	sband = local->hw.wiphy->bands[status->band]; | 
 | 3104 | 	if (WARN_ON(!sband)) | 
 | 3105 | 		goto drop; | 
 | 3106 |  | 
 | 3107 | 	/* | 
 | 3108 | 	 * If we're suspending, it is possible although not too likely | 
 | 3109 | 	 * that we'd be receiving frames after having already partially | 
 | 3110 | 	 * quiesced the stack. We can't process such frames then since | 
 | 3111 | 	 * that might, for example, cause stations to be added or other | 
 | 3112 | 	 * driver callbacks be invoked. | 
 | 3113 | 	 */ | 
 | 3114 | 	if (unlikely(local->quiescing || local->suspended)) | 
 | 3115 | 		goto drop; | 
 | 3116 |  | 
 | 3117 | 	/* | 
 | 3118 | 	 * The same happens when we're not even started, | 
 | 3119 | 	 * but that's worth a warning. | 
 | 3120 | 	 */ | 
 | 3121 | 	if (WARN_ON(!local->started)) | 
 | 3122 | 		goto drop; | 
 | 3123 |  | 
 | 3124 | 	if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) { | 
 | 3125 | 		/* | 
 | 3126 | 		 * Validate the rate, unless a PLCP error means that | 
 | 3127 | 		 * we probably can't have a valid rate here anyway. | 
 | 3128 | 		 */ | 
 | 3129 |  | 
 | 3130 | 		if (status->flag & RX_FLAG_HT) { | 
 | 3131 | 			/* | 
 | 3132 | 			 * rate_idx is MCS index, which can be [0-76] | 
 | 3133 | 			 * as documented on: | 
 | 3134 | 			 * | 
 | 3135 | 			 * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n | 
 | 3136 | 			 * | 
 | 3137 | 			 * Anything else would be some sort of driver or | 
 | 3138 | 			 * hardware error. The driver should catch hardware | 
 | 3139 | 			 * errors. | 
 | 3140 | 			 */ | 
 | 3141 | 			if (WARN((status->rate_idx < 0 || | 
 | 3142 | 				 status->rate_idx > 76), | 
 | 3143 | 				 "Rate marked as an HT rate but passed " | 
 | 3144 | 				 "status->rate_idx is not " | 
 | 3145 | 				 "an MCS index [0-76]: %d (0x%02x)\n", | 
 | 3146 | 				 status->rate_idx, | 
 | 3147 | 				 status->rate_idx)) | 
 | 3148 | 				goto drop; | 
 | 3149 | 		} else { | 
 | 3150 | 			if (WARN_ON(status->rate_idx < 0 || | 
 | 3151 | 				    status->rate_idx >= sband->n_bitrates)) | 
 | 3152 | 				goto drop; | 
 | 3153 | 			rate = &sband->bitrates[status->rate_idx]; | 
 | 3154 | 		} | 
 | 3155 | 	} | 
 | 3156 |  | 
 | 3157 | 	status->rx_flags = 0; | 
 | 3158 |  | 
 | 3159 | 	/* | 
 | 3160 | 	 * key references and virtual interfaces are protected using RCU | 
 | 3161 | 	 * and this requires that we are in a read-side RCU section during | 
 | 3162 | 	 * receive processing | 
 | 3163 | 	 */ | 
 | 3164 | 	rcu_read_lock(); | 
 | 3165 |  | 
 | 3166 | 	/* | 
 | 3167 | 	 * Frames with failed FCS/PLCP checksum are not returned, | 
 | 3168 | 	 * all other frames are returned without radiotap header | 
 | 3169 | 	 * if it was previously present. | 
 | 3170 | 	 * Also, frames with less than 16 bytes are dropped. | 
 | 3171 | 	 */ | 
 | 3172 | 	skb = ieee80211_rx_monitor(local, skb, rate); | 
 | 3173 | 	if (!skb) { | 
 | 3174 | 		rcu_read_unlock(); | 
 | 3175 | 		return; | 
 | 3176 | 	} | 
 | 3177 |  | 
 | 3178 | 	ieee80211_tpt_led_trig_rx(local, | 
 | 3179 | 			((struct ieee80211_hdr *)skb->data)->frame_control, | 
 | 3180 | 			skb->len); | 
 | 3181 | 	__ieee80211_rx_handle_packet(hw, skb); | 
 | 3182 |  | 
 | 3183 | 	rcu_read_unlock(); | 
 | 3184 |  | 
 | 3185 | 	return; | 
 | 3186 |  drop: | 
 | 3187 | 	kfree_skb(skb); | 
 | 3188 | } | 
 | 3189 | EXPORT_SYMBOL(ieee80211_rx); | 
 | 3190 |  | 
 | 3191 | /* This is a version of the rx handler that can be called from hard irq | 
 | 3192 |  * context. Post the skb on the queue and schedule the tasklet */ | 
 | 3193 | void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb) | 
 | 3194 | { | 
 | 3195 | 	struct ieee80211_local *local = hw_to_local(hw); | 
 | 3196 |  | 
 | 3197 | 	BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb)); | 
 | 3198 |  | 
 | 3199 | 	skb->pkt_type = IEEE80211_RX_MSG; | 
 | 3200 | 	skb_queue_tail(&local->skb_queue, skb); | 
 | 3201 | 	tasklet_schedule(&local->tasklet); | 
 | 3202 | } | 
 | 3203 | EXPORT_SYMBOL(ieee80211_rx_irqsafe); |