Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [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> |
Johannes Berg | 8404080 | 2010-02-15 12:46:39 +0200 | [diff] [blame] | 5 | * Copyright 2007-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | d98ad83 | 2014-09-03 15:24:57 +0300 | [diff] [blame] | 6 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
Johannes Berg | fb4ea05 | 2016-01-28 16:19:24 +0200 | [diff] [blame] | 7 | * Copyright(c) 2015 - 2016 Intel Deutschland GmbH |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
S.Çağlar Onur | ab46623 | 2008-02-14 17:36:47 +0200 | [diff] [blame] | 14 | #include <linux/jiffies.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 16 | #include <linux/kernel.h> |
| 17 | #include <linux/skbuff.h> |
| 18 | #include <linux/netdevice.h> |
| 19 | #include <linux/etherdevice.h> |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 20 | #include <linux/rcupdate.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 21 | #include <linux/export.h> |
Sara Sharon | 06470f7 | 2016-01-28 16:19:25 +0200 | [diff] [blame] | 22 | #include <linux/bitops.h> |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 23 | #include <net/mac80211.h> |
| 24 | #include <net/ieee80211_radiotap.h> |
Johannes Berg | d26ad37 | 2012-02-20 11:38:41 +0100 | [diff] [blame] | 25 | #include <asm/unaligned.h> |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 26 | |
| 27 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 28 | #include "driver-ops.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 29 | #include "led.h" |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 30 | #include "mesh.h" |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 31 | #include "wep.h" |
| 32 | #include "wpa.h" |
| 33 | #include "tkip.h" |
| 34 | #include "wme.h" |
Johannes Berg | 1d8d3de | 2011-12-16 15:28:57 +0100 | [diff] [blame] | 35 | #include "rate.h" |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 36 | |
Johannes Berg | 5a49051 | 2015-04-22 17:10:38 +0200 | [diff] [blame] | 37 | static inline void ieee80211_rx_stats(struct net_device *dev, u32 len) |
| 38 | { |
| 39 | struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats); |
| 40 | |
| 41 | u64_stats_update_begin(&tstats->syncp); |
| 42 | tstats->rx_packets++; |
| 43 | tstats->rx_bytes += len; |
| 44 | u64_stats_update_end(&tstats->syncp); |
| 45 | } |
| 46 | |
Johannes Berg | a682849 | 2015-06-16 15:17:15 +0200 | [diff] [blame] | 47 | static u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len, |
| 48 | enum nl80211_iftype type) |
| 49 | { |
| 50 | __le16 fc = hdr->frame_control; |
| 51 | |
| 52 | if (ieee80211_is_data(fc)) { |
| 53 | if (len < 24) /* drop incorrect hdr len (data) */ |
| 54 | return NULL; |
| 55 | |
| 56 | if (ieee80211_has_a4(fc)) |
| 57 | return NULL; |
| 58 | if (ieee80211_has_tods(fc)) |
| 59 | return hdr->addr1; |
| 60 | if (ieee80211_has_fromds(fc)) |
| 61 | return hdr->addr2; |
| 62 | |
| 63 | return hdr->addr3; |
| 64 | } |
| 65 | |
| 66 | if (ieee80211_is_mgmt(fc)) { |
| 67 | if (len < 24) /* drop incorrect hdr len (mgmt) */ |
| 68 | return NULL; |
| 69 | return hdr->addr3; |
| 70 | } |
| 71 | |
| 72 | if (ieee80211_is_ctl(fc)) { |
| 73 | if (ieee80211_is_pspoll(fc)) |
| 74 | return hdr->addr1; |
| 75 | |
| 76 | if (ieee80211_is_back_req(fc)) { |
| 77 | switch (type) { |
| 78 | case NL80211_IFTYPE_STATION: |
| 79 | return hdr->addr2; |
| 80 | case NL80211_IFTYPE_AP: |
| 81 | case NL80211_IFTYPE_AP_VLAN: |
| 82 | return hdr->addr1; |
| 83 | default: |
| 84 | break; /* fall through to the return */ |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | return NULL; |
| 90 | } |
| 91 | |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 92 | /* |
| 93 | * monitor mode reception |
| 94 | * |
| 95 | * This function cleans up the SKB, i.e. it removes all the stuff |
| 96 | * only useful for monitoring. |
| 97 | */ |
| 98 | static struct sk_buff *remove_monitor_info(struct ieee80211_local *local, |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 99 | struct sk_buff *skb, |
| 100 | unsigned int rtap_vendor_space) |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 101 | { |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 102 | if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) { |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 103 | if (likely(skb->len > FCS_LEN)) |
Zhu Yi | e3cf8b3f | 2010-03-29 17:35:07 +0800 | [diff] [blame] | 104 | __pskb_trim(skb, skb->len - FCS_LEN); |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 105 | else { |
| 106 | /* driver bug */ |
| 107 | WARN_ON(1); |
| 108 | dev_kfree_skb(skb); |
Dan Carpenter | 0624760 | 2012-11-27 20:31:19 +0300 | [diff] [blame] | 109 | return NULL; |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 110 | } |
| 111 | } |
| 112 | |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 113 | __pskb_pull(skb, rtap_vendor_space); |
| 114 | |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 115 | return skb; |
| 116 | } |
| 117 | |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 118 | static inline bool should_drop_frame(struct sk_buff *skb, int present_fcs_len, |
| 119 | unsigned int rtap_vendor_space) |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 120 | { |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 121 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 122 | struct ieee80211_hdr *hdr; |
| 123 | |
| 124 | hdr = (void *)(skb->data + rtap_vendor_space); |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 125 | |
Johannes Berg | 4c29867 | 2012-07-05 11:34:31 +0200 | [diff] [blame] | 126 | if (status->flag & (RX_FLAG_FAILED_FCS_CRC | |
Grzegorz Bajorski | 1788304 | 2015-12-11 14:39:46 +0100 | [diff] [blame] | 127 | RX_FLAG_FAILED_PLCP_CRC | |
| 128 | RX_FLAG_ONLY_MONITOR)) |
Zhao, Gang | 6b59db7 | 2014-04-21 12:52:59 +0800 | [diff] [blame] | 129 | return true; |
| 130 | |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 131 | if (unlikely(skb->len < 16 + present_fcs_len + rtap_vendor_space)) |
Zhao, Gang | 6b59db7 | 2014-04-21 12:52:59 +0800 | [diff] [blame] | 132 | return true; |
| 133 | |
Harvey Harrison | 87228f5 | 2008-06-11 14:21:59 -0700 | [diff] [blame] | 134 | if (ieee80211_is_ctl(hdr->frame_control) && |
| 135 | !ieee80211_is_pspoll(hdr->frame_control) && |
| 136 | !ieee80211_is_back_req(hdr->frame_control)) |
Zhao, Gang | 6b59db7 | 2014-04-21 12:52:59 +0800 | [diff] [blame] | 137 | return true; |
| 138 | |
| 139 | return false; |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 140 | } |
| 141 | |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 142 | static int |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 143 | ieee80211_rx_radiotap_hdrlen(struct ieee80211_local *local, |
| 144 | struct ieee80211_rx_status *status, |
| 145 | struct sk_buff *skb) |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 146 | { |
| 147 | int len; |
| 148 | |
| 149 | /* always present fields */ |
Johannes Berg | a144f37 | 2013-07-03 13:34:02 +0200 | [diff] [blame] | 150 | len = sizeof(struct ieee80211_radiotap_header) + 8; |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 151 | |
Johannes Berg | a144f37 | 2013-07-03 13:34:02 +0200 | [diff] [blame] | 152 | /* allocate extra bitmaps */ |
Johannes Berg | a144f37 | 2013-07-03 13:34:02 +0200 | [diff] [blame] | 153 | if (status->chains) |
| 154 | len += 4 * hweight8(status->chains); |
Johannes Berg | 90b9e446 | 2012-11-16 10:09:08 +0100 | [diff] [blame] | 155 | |
| 156 | if (ieee80211_have_rx_timestamp(status)) { |
| 157 | len = ALIGN(len, 8); |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 158 | len += 8; |
Johannes Berg | 90b9e446 | 2012-11-16 10:09:08 +0100 | [diff] [blame] | 159 | } |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 160 | if (ieee80211_hw_check(&local->hw, SIGNAL_DBM)) |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 161 | len += 1; |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 162 | |
Johannes Berg | a144f37 | 2013-07-03 13:34:02 +0200 | [diff] [blame] | 163 | /* antenna field, if we don't have per-chain info */ |
| 164 | if (!status->chains) |
| 165 | len += 1; |
| 166 | |
Johannes Berg | 90b9e446 | 2012-11-16 10:09:08 +0100 | [diff] [blame] | 167 | /* padding for RX_FLAGS if necessary */ |
| 168 | len = ALIGN(len, 2); |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 169 | |
Johannes Berg | 6d744ba | 2011-01-27 14:13:17 +0100 | [diff] [blame] | 170 | if (status->flag & RX_FLAG_HT) /* HT info */ |
| 171 | len += 3; |
| 172 | |
Johannes Berg | 4c29867 | 2012-07-05 11:34:31 +0200 | [diff] [blame] | 173 | if (status->flag & RX_FLAG_AMPDU_DETAILS) { |
Johannes Berg | 90b9e446 | 2012-11-16 10:09:08 +0100 | [diff] [blame] | 174 | len = ALIGN(len, 4); |
Johannes Berg | 4c29867 | 2012-07-05 11:34:31 +0200 | [diff] [blame] | 175 | len += 8; |
| 176 | } |
| 177 | |
Johannes Berg | 5164892 | 2012-11-22 23:00:18 +0100 | [diff] [blame] | 178 | if (status->flag & RX_FLAG_VHT) { |
| 179 | len = ALIGN(len, 2); |
| 180 | len += 12; |
| 181 | } |
| 182 | |
Johannes Berg | a144f37 | 2013-07-03 13:34:02 +0200 | [diff] [blame] | 183 | if (status->chains) { |
| 184 | /* antenna and antenna signal fields */ |
| 185 | len += 2 * hweight8(status->chains); |
| 186 | } |
| 187 | |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 188 | if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) { |
| 189 | struct ieee80211_vendor_radiotap *rtap = (void *)skb->data; |
| 190 | |
| 191 | /* vendor presence bitmap */ |
| 192 | len += 4; |
| 193 | /* alignment for fixed 6-byte vendor data header */ |
| 194 | len = ALIGN(len, 2); |
| 195 | /* vendor data header */ |
| 196 | len += 6; |
| 197 | if (WARN_ON(rtap->align == 0)) |
| 198 | rtap->align = 1; |
| 199 | len = ALIGN(len, rtap->align); |
| 200 | len += rtap->len + rtap->pad; |
| 201 | } |
| 202 | |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 203 | return len; |
| 204 | } |
| 205 | |
Johannes Berg | 00ea6de | 2012-09-05 15:54:51 +0200 | [diff] [blame] | 206 | /* |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 207 | * ieee80211_add_rx_radiotap_header - add radiotap header |
| 208 | * |
| 209 | * add a radiotap header containing all the fields which the hardware provided. |
| 210 | */ |
| 211 | static void |
| 212 | ieee80211_add_rx_radiotap_header(struct ieee80211_local *local, |
| 213 | struct sk_buff *skb, |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 214 | struct ieee80211_rate *rate, |
Felix Fietkau | 973ef21 | 2012-04-16 14:56:48 +0200 | [diff] [blame] | 215 | int rtap_len, bool has_fcs) |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 216 | { |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 217 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 218 | struct ieee80211_radiotap_header *rthdr; |
| 219 | unsigned char *pos; |
Johannes Berg | a144f37 | 2013-07-03 13:34:02 +0200 | [diff] [blame] | 220 | __le32 *it_present; |
| 221 | u32 it_present_val; |
Johannes Berg | 6a86b9c | 2009-10-28 09:58:52 +0100 | [diff] [blame] | 222 | u16 rx_flags = 0; |
Simon Wunderlich | a5e7069 | 2013-07-08 16:55:52 +0200 | [diff] [blame] | 223 | u16 channel_flags = 0; |
Johannes Berg | a144f37 | 2013-07-03 13:34:02 +0200 | [diff] [blame] | 224 | int mpdulen, chain; |
| 225 | unsigned long chains = status->chains; |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 226 | struct ieee80211_vendor_radiotap rtap = {}; |
| 227 | |
| 228 | if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) { |
| 229 | rtap = *(struct ieee80211_vendor_radiotap *)skb->data; |
| 230 | /* rtap.len and rtap.pad are undone immediately */ |
| 231 | skb_pull(skb, sizeof(rtap) + rtap.len + rtap.pad); |
| 232 | } |
Thomas Pedersen | f4bda33 | 2012-11-13 10:46:27 -0800 | [diff] [blame] | 233 | |
| 234 | mpdulen = skb->len; |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 235 | if (!(has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))) |
Thomas Pedersen | f4bda33 | 2012-11-13 10:46:27 -0800 | [diff] [blame] | 236 | mpdulen += FCS_LEN; |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 237 | |
| 238 | rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len); |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 239 | memset(rthdr, 0, rtap_len - rtap.len - rtap.pad); |
Johannes Berg | a144f37 | 2013-07-03 13:34:02 +0200 | [diff] [blame] | 240 | it_present = &rthdr->it_present; |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 241 | |
| 242 | /* radiotap header, set always present flags */ |
Emmanuel Grumbach | 0059b2b | 2014-02-05 16:36:01 +0200 | [diff] [blame] | 243 | rthdr->it_len = cpu_to_le16(rtap_len); |
Johannes Berg | a144f37 | 2013-07-03 13:34:02 +0200 | [diff] [blame] | 244 | it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) | |
| 245 | BIT(IEEE80211_RADIOTAP_CHANNEL) | |
| 246 | BIT(IEEE80211_RADIOTAP_RX_FLAGS); |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 247 | |
Johannes Berg | a144f37 | 2013-07-03 13:34:02 +0200 | [diff] [blame] | 248 | if (!status->chains) |
| 249 | it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA); |
| 250 | |
| 251 | for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) { |
| 252 | it_present_val |= |
| 253 | BIT(IEEE80211_RADIOTAP_EXT) | |
| 254 | BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE); |
| 255 | put_unaligned_le32(it_present_val, it_present); |
| 256 | it_present++; |
| 257 | it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) | |
| 258 | BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL); |
| 259 | } |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 260 | |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 261 | if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) { |
| 262 | it_present_val |= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE) | |
| 263 | BIT(IEEE80211_RADIOTAP_EXT); |
| 264 | put_unaligned_le32(it_present_val, it_present); |
| 265 | it_present++; |
| 266 | it_present_val = rtap.present; |
| 267 | } |
| 268 | |
Johannes Berg | a144f37 | 2013-07-03 13:34:02 +0200 | [diff] [blame] | 269 | put_unaligned_le32(it_present_val, it_present); |
| 270 | |
| 271 | pos = (void *)(it_present + 1); |
| 272 | |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 273 | /* the order of the following fields is important */ |
| 274 | |
| 275 | /* IEEE80211_RADIOTAP_TSFT */ |
Thomas Pedersen | f4bda33 | 2012-11-13 10:46:27 -0800 | [diff] [blame] | 276 | if (ieee80211_have_rx_timestamp(status)) { |
Johannes Berg | 90b9e446 | 2012-11-16 10:09:08 +0100 | [diff] [blame] | 277 | /* padding */ |
| 278 | while ((pos - (u8 *)rthdr) & 7) |
| 279 | *pos++ = 0; |
Thomas Pedersen | f4bda33 | 2012-11-13 10:46:27 -0800 | [diff] [blame] | 280 | put_unaligned_le64( |
| 281 | ieee80211_calculate_rx_timestamp(local, status, |
| 282 | mpdulen, 0), |
| 283 | pos); |
Johannes Berg | 1df332e | 2012-10-26 00:09:11 +0200 | [diff] [blame] | 284 | rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT); |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 285 | pos += 8; |
| 286 | } |
| 287 | |
| 288 | /* IEEE80211_RADIOTAP_FLAGS */ |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 289 | if (has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 290 | *pos |= IEEE80211_RADIOTAP_F_FCS; |
Johannes Berg | aae8983 | 2009-03-13 12:52:10 +0100 | [diff] [blame] | 291 | if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC)) |
| 292 | *pos |= IEEE80211_RADIOTAP_F_BADFCS; |
Bruno Randolf | b4f28bb | 2008-07-30 17:19:55 +0200 | [diff] [blame] | 293 | if (status->flag & RX_FLAG_SHORTPRE) |
| 294 | *pos |= IEEE80211_RADIOTAP_F_SHORTPRE; |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 295 | pos++; |
| 296 | |
| 297 | /* IEEE80211_RADIOTAP_RATE */ |
Johannes Berg | 5614618 | 2012-11-09 15:07:02 +0100 | [diff] [blame] | 298 | if (!rate || status->flag & (RX_FLAG_HT | RX_FLAG_VHT)) { |
Jouni Malinen | 0fb8ca4 | 2008-12-12 14:38:33 +0200 | [diff] [blame] | 299 | /* |
Johannes Berg | f8d1ccf | 2011-11-08 12:28:33 +0100 | [diff] [blame] | 300 | * Without rate information don't add it. If we have, |
Mohammed Shafi Shajakhan | 38f37be | 2011-02-07 10:10:04 +0530 | [diff] [blame] | 301 | * MCS information is a separate field in radiotap, |
Johannes Berg | 73b4809 | 2011-04-18 17:05:21 +0200 | [diff] [blame] | 302 | * added below. The byte here is needed as padding |
| 303 | * for the channel though, so initialise it to 0. |
Jouni Malinen | 0fb8ca4 | 2008-12-12 14:38:33 +0200 | [diff] [blame] | 304 | */ |
| 305 | *pos = 0; |
Jouni Malinen | 8d6f658 | 2008-12-15 10:37:50 +0200 | [diff] [blame] | 306 | } else { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 307 | int shift = 0; |
Jouni Malinen | ebe6c7b | 2009-01-10 11:47:33 +0200 | [diff] [blame] | 308 | rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE); |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 309 | if (status->flag & RX_FLAG_10MHZ) |
| 310 | shift = 1; |
| 311 | else if (status->flag & RX_FLAG_5MHZ) |
| 312 | shift = 2; |
| 313 | *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift)); |
Jouni Malinen | 8d6f658 | 2008-12-15 10:37:50 +0200 | [diff] [blame] | 314 | } |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 315 | pos++; |
| 316 | |
| 317 | /* IEEE80211_RADIOTAP_CHANNEL */ |
Johannes Berg | 6a86b9c | 2009-10-28 09:58:52 +0100 | [diff] [blame] | 318 | put_unaligned_le16(status->freq, pos); |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 319 | pos += 2; |
Simon Wunderlich | a5e7069 | 2013-07-08 16:55:52 +0200 | [diff] [blame] | 320 | if (status->flag & RX_FLAG_10MHZ) |
| 321 | channel_flags |= IEEE80211_CHAN_HALF; |
| 322 | else if (status->flag & RX_FLAG_5MHZ) |
| 323 | channel_flags |= IEEE80211_CHAN_QUARTER; |
| 324 | |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 325 | if (status->band == IEEE80211_BAND_5GHZ) |
Simon Wunderlich | a5e7069 | 2013-07-08 16:55:52 +0200 | [diff] [blame] | 326 | channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ; |
Johannes Berg | 5614618 | 2012-11-09 15:07:02 +0100 | [diff] [blame] | 327 | else if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT)) |
Simon Wunderlich | a5e7069 | 2013-07-08 16:55:52 +0200 | [diff] [blame] | 328 | channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ; |
Johannes Berg | f8d1ccf | 2011-11-08 12:28:33 +0100 | [diff] [blame] | 329 | else if (rate && rate->flags & IEEE80211_RATE_ERP_G) |
Simon Wunderlich | a5e7069 | 2013-07-08 16:55:52 +0200 | [diff] [blame] | 330 | channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ; |
Johannes Berg | f8d1ccf | 2011-11-08 12:28:33 +0100 | [diff] [blame] | 331 | else if (rate) |
Mathy Vanhoef | 3a5c5e8 | 2015-01-20 15:05:08 +0100 | [diff] [blame] | 332 | channel_flags |= IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ; |
Johannes Berg | f8d1ccf | 2011-11-08 12:28:33 +0100 | [diff] [blame] | 333 | else |
Simon Wunderlich | a5e7069 | 2013-07-08 16:55:52 +0200 | [diff] [blame] | 334 | channel_flags |= IEEE80211_CHAN_2GHZ; |
| 335 | put_unaligned_le16(channel_flags, pos); |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 336 | pos += 2; |
| 337 | |
| 338 | /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */ |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 339 | if (ieee80211_hw_check(&local->hw, SIGNAL_DBM) && |
Felix Fietkau | fe8431f | 2012-03-01 18:00:07 +0100 | [diff] [blame] | 340 | !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) { |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 341 | *pos = status->signal; |
| 342 | rthdr->it_present |= |
| 343 | cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL); |
| 344 | pos++; |
| 345 | } |
| 346 | |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 347 | /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */ |
| 348 | |
Johannes Berg | a144f37 | 2013-07-03 13:34:02 +0200 | [diff] [blame] | 349 | if (!status->chains) { |
| 350 | /* IEEE80211_RADIOTAP_ANTENNA */ |
| 351 | *pos = status->antenna; |
| 352 | pos++; |
| 353 | } |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 354 | |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 355 | /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */ |
| 356 | |
| 357 | /* IEEE80211_RADIOTAP_RX_FLAGS */ |
| 358 | /* ensure 2 byte alignment for the 2 byte field as required */ |
Johannes Berg | 6a86b9c | 2009-10-28 09:58:52 +0100 | [diff] [blame] | 359 | if ((pos - (u8 *)rthdr) & 1) |
Johannes Berg | 90b9e446 | 2012-11-16 10:09:08 +0100 | [diff] [blame] | 360 | *pos++ = 0; |
Johannes Berg | aae8983 | 2009-03-13 12:52:10 +0100 | [diff] [blame] | 361 | if (status->flag & RX_FLAG_FAILED_PLCP_CRC) |
Johannes Berg | 6a86b9c | 2009-10-28 09:58:52 +0100 | [diff] [blame] | 362 | rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP; |
| 363 | put_unaligned_le16(rx_flags, pos); |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 364 | pos += 2; |
Johannes Berg | 6d744ba | 2011-01-27 14:13:17 +0100 | [diff] [blame] | 365 | |
| 366 | if (status->flag & RX_FLAG_HT) { |
Oleksij Rempel | 786677d | 2013-05-24 12:05:45 +0200 | [diff] [blame] | 367 | unsigned int stbc; |
| 368 | |
Johannes Berg | 6d744ba | 2011-01-27 14:13:17 +0100 | [diff] [blame] | 369 | rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS); |
Johannes Berg | ac55d2f | 2012-05-10 09:09:10 +0200 | [diff] [blame] | 370 | *pos++ = local->hw.radiotap_mcs_details; |
Johannes Berg | 6d744ba | 2011-01-27 14:13:17 +0100 | [diff] [blame] | 371 | *pos = 0; |
| 372 | if (status->flag & RX_FLAG_SHORT_GI) |
| 373 | *pos |= IEEE80211_RADIOTAP_MCS_SGI; |
| 374 | if (status->flag & RX_FLAG_40MHZ) |
| 375 | *pos |= IEEE80211_RADIOTAP_MCS_BW_40; |
Johannes Berg | ac55d2f | 2012-05-10 09:09:10 +0200 | [diff] [blame] | 376 | if (status->flag & RX_FLAG_HT_GF) |
| 377 | *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF; |
Emmanuel Grumbach | 63c361f | 2014-02-05 12:48:53 +0200 | [diff] [blame] | 378 | if (status->flag & RX_FLAG_LDPC) |
| 379 | *pos |= IEEE80211_RADIOTAP_MCS_FEC_LDPC; |
Oleksij Rempel | 786677d | 2013-05-24 12:05:45 +0200 | [diff] [blame] | 380 | stbc = (status->flag & RX_FLAG_STBC_MASK) >> RX_FLAG_STBC_SHIFT; |
| 381 | *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT; |
Johannes Berg | 6d744ba | 2011-01-27 14:13:17 +0100 | [diff] [blame] | 382 | pos++; |
| 383 | *pos++ = status->rate_idx; |
| 384 | } |
Johannes Berg | 4c29867 | 2012-07-05 11:34:31 +0200 | [diff] [blame] | 385 | |
| 386 | if (status->flag & RX_FLAG_AMPDU_DETAILS) { |
| 387 | u16 flags = 0; |
| 388 | |
| 389 | /* ensure 4 byte alignment */ |
| 390 | while ((pos - (u8 *)rthdr) & 3) |
| 391 | pos++; |
| 392 | rthdr->it_present |= |
| 393 | cpu_to_le32(1 << IEEE80211_RADIOTAP_AMPDU_STATUS); |
| 394 | put_unaligned_le32(status->ampdu_reference, pos); |
| 395 | pos += 4; |
Johannes Berg | 4c29867 | 2012-07-05 11:34:31 +0200 | [diff] [blame] | 396 | if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN) |
| 397 | flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN; |
| 398 | if (status->flag & RX_FLAG_AMPDU_IS_LAST) |
| 399 | flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST; |
| 400 | if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR) |
| 401 | flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR; |
| 402 | if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN) |
| 403 | flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN; |
| 404 | put_unaligned_le16(flags, pos); |
| 405 | pos += 2; |
| 406 | if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN) |
| 407 | *pos++ = status->ampdu_delimiter_crc; |
| 408 | else |
| 409 | *pos++ = 0; |
| 410 | *pos++ = 0; |
| 411 | } |
Johannes Berg | 90b9e446 | 2012-11-16 10:09:08 +0100 | [diff] [blame] | 412 | |
Johannes Berg | 5164892 | 2012-11-22 23:00:18 +0100 | [diff] [blame] | 413 | if (status->flag & RX_FLAG_VHT) { |
| 414 | u16 known = local->hw.radiotap_vht_details; |
| 415 | |
| 416 | rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_VHT); |
Johannes Berg | 5164892 | 2012-11-22 23:00:18 +0100 | [diff] [blame] | 417 | put_unaligned_le16(known, pos); |
| 418 | pos += 2; |
| 419 | /* flags */ |
| 420 | if (status->flag & RX_FLAG_SHORT_GI) |
| 421 | *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI; |
Emmanuel Grumbach | 63c361f | 2014-02-05 12:48:53 +0200 | [diff] [blame] | 422 | /* in VHT, STBC is binary */ |
| 423 | if (status->flag & RX_FLAG_STBC_MASK) |
| 424 | *pos |= IEEE80211_RADIOTAP_VHT_FLAG_STBC; |
Emmanuel Grumbach | fb378c2 | 2014-03-04 10:35:25 +0200 | [diff] [blame] | 425 | if (status->vht_flag & RX_VHT_FLAG_BF) |
| 426 | *pos |= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED; |
Johannes Berg | 5164892 | 2012-11-22 23:00:18 +0100 | [diff] [blame] | 427 | pos++; |
| 428 | /* bandwidth */ |
Emmanuel Grumbach | 1b8d242 | 2014-02-05 16:37:11 +0200 | [diff] [blame] | 429 | if (status->vht_flag & RX_VHT_FLAG_80MHZ) |
Johannes Berg | 5164892 | 2012-11-22 23:00:18 +0100 | [diff] [blame] | 430 | *pos++ = 4; |
Emmanuel Grumbach | 1b8d242 | 2014-02-05 16:37:11 +0200 | [diff] [blame] | 431 | else if (status->vht_flag & RX_VHT_FLAG_160MHZ) |
Johannes Berg | 5164892 | 2012-11-22 23:00:18 +0100 | [diff] [blame] | 432 | *pos++ = 11; |
| 433 | else if (status->flag & RX_FLAG_40MHZ) |
| 434 | *pos++ = 1; |
| 435 | else /* 20 MHz */ |
| 436 | *pos++ = 0; |
| 437 | /* MCS/NSS */ |
| 438 | *pos = (status->rate_idx << 4) | status->vht_nss; |
| 439 | pos += 4; |
| 440 | /* coding field */ |
Emmanuel Grumbach | 63c361f | 2014-02-05 12:48:53 +0200 | [diff] [blame] | 441 | if (status->flag & RX_FLAG_LDPC) |
| 442 | *pos |= IEEE80211_RADIOTAP_CODING_LDPC_USER0; |
Johannes Berg | 5164892 | 2012-11-22 23:00:18 +0100 | [diff] [blame] | 443 | pos++; |
| 444 | /* group ID */ |
| 445 | pos++; |
| 446 | /* partial_aid */ |
| 447 | pos += 2; |
| 448 | } |
| 449 | |
Johannes Berg | a144f37 | 2013-07-03 13:34:02 +0200 | [diff] [blame] | 450 | for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) { |
| 451 | *pos++ = status->chain_signal[chain]; |
| 452 | *pos++ = chain; |
| 453 | } |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 454 | |
| 455 | if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) { |
| 456 | /* ensure 2 byte alignment for the vendor field as required */ |
| 457 | if ((pos - (u8 *)rthdr) & 1) |
| 458 | *pos++ = 0; |
| 459 | *pos++ = rtap.oui[0]; |
| 460 | *pos++ = rtap.oui[1]; |
| 461 | *pos++ = rtap.oui[2]; |
| 462 | *pos++ = rtap.subns; |
| 463 | put_unaligned_le16(rtap.len, pos); |
| 464 | pos += 2; |
| 465 | /* align the actual payload as requested */ |
| 466 | while ((pos - (u8 *)rthdr) & (rtap.align - 1)) |
| 467 | *pos++ = 0; |
| 468 | /* data (and possible padding) already follows */ |
| 469 | } |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 470 | } |
| 471 | |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 472 | /* |
| 473 | * This function copies a received frame to all monitor interfaces and |
| 474 | * returns a cleaned-up SKB that no longer includes the FCS nor the |
| 475 | * radiotap header the driver might have added. |
| 476 | */ |
| 477 | static struct sk_buff * |
| 478 | ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 479 | struct ieee80211_rate *rate) |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 480 | { |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 481 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb); |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 482 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 483 | int rt_hdrlen, needed_headroom; |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 484 | struct sk_buff *skb, *skb2; |
| 485 | struct net_device *prev_dev = NULL; |
| 486 | int present_fcs_len = 0; |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 487 | unsigned int rtap_vendor_space = 0; |
| 488 | |
| 489 | if (unlikely(status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)) { |
| 490 | struct ieee80211_vendor_radiotap *rtap = (void *)origskb->data; |
| 491 | |
| 492 | rtap_vendor_space = sizeof(*rtap) + rtap->len + rtap->pad; |
| 493 | } |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 494 | |
| 495 | /* |
| 496 | * First, we may need to make a copy of the skb because |
| 497 | * (1) we need to modify it for radiotap (if not present), and |
| 498 | * (2) the other RX handlers will modify the skb we got. |
| 499 | * |
| 500 | * We don't need to, of course, if we aren't going to return |
| 501 | * the SKB because it has a bad FCS/PLCP checksum. |
| 502 | */ |
Johannes Berg | 0869aea0 | 2009-10-28 10:03:35 +0100 | [diff] [blame] | 503 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 504 | if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 505 | present_fcs_len = FCS_LEN; |
| 506 | |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 507 | /* ensure hdr->frame_control and vendor radiotap data are in skb head */ |
| 508 | if (!pskb_may_pull(origskb, 2 + rtap_vendor_space)) { |
Zhu Yi | e3cf8b3f | 2010-03-29 17:35:07 +0800 | [diff] [blame] | 509 | dev_kfree_skb(origskb); |
| 510 | return NULL; |
| 511 | } |
| 512 | |
Grzegorz Bajorski | 1788304 | 2015-12-11 14:39:46 +0100 | [diff] [blame] | 513 | if (!local->monitors || (status->flag & RX_FLAG_SKIP_MONITOR)) { |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 514 | if (should_drop_frame(origskb, present_fcs_len, |
| 515 | rtap_vendor_space)) { |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 516 | dev_kfree_skb(origskb); |
| 517 | return NULL; |
| 518 | } |
| 519 | |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 520 | return remove_monitor_info(local, origskb, rtap_vendor_space); |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 521 | } |
| 522 | |
Helmut Schaa | 751413e | 2012-12-05 14:36:12 +0100 | [diff] [blame] | 523 | /* room for the radiotap header based on driver features */ |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 524 | rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, origskb); |
| 525 | needed_headroom = rt_hdrlen - rtap_vendor_space; |
Helmut Schaa | 751413e | 2012-12-05 14:36:12 +0100 | [diff] [blame] | 526 | |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 527 | if (should_drop_frame(origskb, present_fcs_len, rtap_vendor_space)) { |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 528 | /* only need to expand headroom if necessary */ |
| 529 | skb = origskb; |
| 530 | origskb = NULL; |
| 531 | |
| 532 | /* |
| 533 | * This shouldn't trigger often because most devices have an |
| 534 | * RX header they pull before we get here, and that should |
| 535 | * be big enough for our radiotap information. We should |
| 536 | * probably export the length to drivers so that we can have |
| 537 | * them allocate enough headroom to start with. |
| 538 | */ |
| 539 | if (skb_headroom(skb) < needed_headroom && |
Johannes Berg | c49e5ea | 2007-12-11 21:33:42 +0100 | [diff] [blame] | 540 | pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) { |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 541 | dev_kfree_skb(skb); |
| 542 | return NULL; |
| 543 | } |
| 544 | } else { |
| 545 | /* |
| 546 | * Need to make a copy and possibly remove radiotap header |
| 547 | * and FCS from the original. |
| 548 | */ |
| 549 | skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC); |
| 550 | |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 551 | origskb = remove_monitor_info(local, origskb, |
| 552 | rtap_vendor_space); |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 553 | |
| 554 | if (!skb) |
| 555 | return origskb; |
| 556 | } |
| 557 | |
Johannes Berg | 0869aea0 | 2009-10-28 10:03:35 +0100 | [diff] [blame] | 558 | /* prepend radiotap information */ |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 559 | ieee80211_add_rx_radiotap_header(local, skb, rate, rt_hdrlen, true); |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 560 | |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 561 | skb_reset_mac_header(skb); |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 562 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 563 | skb->pkt_type = PACKET_OTHERHOST; |
| 564 | skb->protocol = htons(ETH_P_802_2); |
| 565 | |
| 566 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 567 | if (sdata->vif.type != NL80211_IFTYPE_MONITOR) |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 568 | continue; |
| 569 | |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 570 | if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) |
| 571 | continue; |
| 572 | |
Johannes Berg | 9607e6b66 | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 573 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 574 | continue; |
| 575 | |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 576 | if (prev_dev) { |
| 577 | skb2 = skb_clone(skb, GFP_ATOMIC); |
| 578 | if (skb2) { |
| 579 | skb2->dev = prev_dev; |
John W. Linville | 5548a8a | 2010-06-24 14:25:56 -0400 | [diff] [blame] | 580 | netif_receive_skb(skb2); |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 581 | } |
| 582 | } |
| 583 | |
| 584 | prev_dev = sdata->dev; |
Johannes Berg | 5a49051 | 2015-04-22 17:10:38 +0200 | [diff] [blame] | 585 | ieee80211_rx_stats(sdata->dev, skb->len); |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | if (prev_dev) { |
| 589 | skb->dev = prev_dev; |
John W. Linville | 5548a8a | 2010-06-24 14:25:56 -0400 | [diff] [blame] | 590 | netif_receive_skb(skb); |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 591 | } else |
| 592 | dev_kfree_skb(skb); |
| 593 | |
| 594 | return origskb; |
| 595 | } |
| 596 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 597 | static void ieee80211_parse_qos(struct ieee80211_rx_data *rx) |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 598 | { |
Harvey Harrison | 238f74a | 2008-07-02 11:05:34 -0700 | [diff] [blame] | 599 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; |
Johannes Berg | 554891e | 2010-09-24 12:38:25 +0200 | [diff] [blame] | 600 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); |
Johannes Berg | 9e26297 | 2011-07-07 18:45:03 +0200 | [diff] [blame] | 601 | int tid, seqno_idx, security_idx; |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 602 | |
| 603 | /* does the frame have a qos control field? */ |
Harvey Harrison | 238f74a | 2008-07-02 11:05:34 -0700 | [diff] [blame] | 604 | if (ieee80211_is_data_qos(hdr->frame_control)) { |
| 605 | u8 *qc = ieee80211_get_qos_ctl(hdr); |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 606 | /* frame has qos control */ |
Harvey Harrison | 238f74a | 2008-07-02 11:05:34 -0700 | [diff] [blame] | 607 | tid = *qc & IEEE80211_QOS_CTL_TID_MASK; |
Johannes Berg | 04b7dcf | 2011-06-22 10:06:59 +0200 | [diff] [blame] | 608 | if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT) |
Johannes Berg | 554891e | 2010-09-24 12:38:25 +0200 | [diff] [blame] | 609 | status->rx_flags |= IEEE80211_RX_AMSDU; |
Johannes Berg | 9e26297 | 2011-07-07 18:45:03 +0200 | [diff] [blame] | 610 | |
| 611 | seqno_idx = tid; |
| 612 | security_idx = tid; |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 613 | } else { |
Johannes Berg | 1411f9b | 2008-07-10 10:11:02 +0200 | [diff] [blame] | 614 | /* |
| 615 | * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"): |
| 616 | * |
| 617 | * Sequence numbers for management frames, QoS data |
| 618 | * frames with a broadcast/multicast address in the |
| 619 | * Address 1 field, and all non-QoS data frames sent |
| 620 | * by QoS STAs are assigned using an additional single |
| 621 | * modulo-4096 counter, [...] |
| 622 | * |
| 623 | * We also use that counter for non-QoS STAs. |
| 624 | */ |
Johannes Berg | 5a306f5 | 2012-11-14 23:22:21 +0100 | [diff] [blame] | 625 | seqno_idx = IEEE80211_NUM_TIDS; |
Johannes Berg | 9e26297 | 2011-07-07 18:45:03 +0200 | [diff] [blame] | 626 | security_idx = 0; |
| 627 | if (ieee80211_is_mgmt(hdr->frame_control)) |
Johannes Berg | 5a306f5 | 2012-11-14 23:22:21 +0100 | [diff] [blame] | 628 | security_idx = IEEE80211_NUM_TIDS; |
Johannes Berg | 9e26297 | 2011-07-07 18:45:03 +0200 | [diff] [blame] | 629 | tid = 0; |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 630 | } |
Johannes Berg | 52865dfd | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 631 | |
Johannes Berg | 9e26297 | 2011-07-07 18:45:03 +0200 | [diff] [blame] | 632 | rx->seqno_idx = seqno_idx; |
| 633 | rx->security_idx = security_idx; |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 634 | /* Set skb->priority to 1d tag if highest order bit of TID is not set. |
| 635 | * For now, set skb->priority to 0 for other cases. */ |
| 636 | rx->skb->priority = (tid > 7) ? 0 : tid; |
Johannes Berg | 38f3714 | 2008-01-29 17:07:43 +0100 | [diff] [blame] | 637 | } |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 638 | |
Johannes Berg | d1c3a37 | 2009-01-07 00:26:10 +0100 | [diff] [blame] | 639 | /** |
| 640 | * DOC: Packet alignment |
| 641 | * |
| 642 | * Drivers always need to pass packets that are aligned to two-byte boundaries |
| 643 | * to the stack. |
| 644 | * |
| 645 | * Additionally, should, if possible, align the payload data in a way that |
| 646 | * guarantees that the contained IP header is aligned to a four-byte |
| 647 | * boundary. In the case of regular frames, this simply means aligning the |
| 648 | * payload to a four-byte boundary (because either the IP header is directly |
| 649 | * contained, or IV/RFC1042 headers that have a length divisible by four are |
Kalle Valo | 59d9cb0 | 2009-12-17 13:54:57 +0100 | [diff] [blame] | 650 | * in front of it). If the payload data is not properly aligned and the |
| 651 | * architecture doesn't support efficient unaligned operations, mac80211 |
| 652 | * will align the data. |
Johannes Berg | d1c3a37 | 2009-01-07 00:26:10 +0100 | [diff] [blame] | 653 | * |
| 654 | * With A-MSDU frames, however, the payload data address must yield two modulo |
| 655 | * four because there are 14-byte 802.3 headers within the A-MSDU frames that |
| 656 | * push the IP header further back to a multiple of four again. Thankfully, the |
| 657 | * specs were sane enough this time around to require padding each A-MSDU |
| 658 | * subframe to a length that is a multiple of four. |
| 659 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 660 | * Padding like Atheros hardware adds which is between the 802.11 header and |
Johannes Berg | d1c3a37 | 2009-01-07 00:26:10 +0100 | [diff] [blame] | 661 | * the payload is not supported, the driver is required to move the 802.11 |
| 662 | * header to be directly in front of the payload in that case. |
| 663 | */ |
| 664 | static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx) |
Johannes Berg | 38f3714 | 2008-01-29 17:07:43 +0100 | [diff] [blame] | 665 | { |
Kalle Valo | 59d9cb0 | 2009-12-17 13:54:57 +0100 | [diff] [blame] | 666 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Johannes Berg | 441275e | 2015-11-06 12:34:24 +0100 | [diff] [blame] | 667 | WARN_ON_ONCE((unsigned long)rx->skb->data & 1); |
Johannes Berg | d1c3a37 | 2009-01-07 00:26:10 +0100 | [diff] [blame] | 668 | #endif |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 669 | } |
| 670 | |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 671 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 672 | /* rx handlers */ |
| 673 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 674 | static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb) |
| 675 | { |
| 676 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 677 | |
Johannes Berg | d8ca16d | 2014-01-23 16:20:29 +0100 | [diff] [blame] | 678 | if (is_multicast_ether_addr(hdr->addr1)) |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 679 | return 0; |
| 680 | |
Johannes Berg | d8ca16d | 2014-01-23 16:20:29 +0100 | [diff] [blame] | 681 | return ieee80211_is_robust_mgmt_frame(skb); |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | |
| 685 | static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb) |
| 686 | { |
| 687 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 688 | |
Johannes Berg | d8ca16d | 2014-01-23 16:20:29 +0100 | [diff] [blame] | 689 | if (!is_multicast_ether_addr(hdr->addr1)) |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 690 | return 0; |
| 691 | |
Johannes Berg | d8ca16d | 2014-01-23 16:20:29 +0100 | [diff] [blame] | 692 | return ieee80211_is_robust_mgmt_frame(skb); |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | |
| 696 | /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */ |
| 697 | static int ieee80211_get_mmie_keyidx(struct sk_buff *skb) |
| 698 | { |
| 699 | struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data; |
| 700 | struct ieee80211_mmie *mmie; |
Jouni Malinen | 56c52da | 2015-01-24 19:52:08 +0200 | [diff] [blame] | 701 | struct ieee80211_mmie_16 *mmie16; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 702 | |
Johannes Berg | 1df332e | 2012-10-26 00:09:11 +0200 | [diff] [blame] | 703 | if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da)) |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 704 | return -1; |
| 705 | |
Johannes Berg | d8ca16d | 2014-01-23 16:20:29 +0100 | [diff] [blame] | 706 | if (!ieee80211_is_robust_mgmt_frame(skb)) |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 707 | return -1; /* not a robust management frame */ |
| 708 | |
| 709 | mmie = (struct ieee80211_mmie *) |
| 710 | (skb->data + skb->len - sizeof(*mmie)); |
Jouni Malinen | 56c52da | 2015-01-24 19:52:08 +0200 | [diff] [blame] | 711 | if (mmie->element_id == WLAN_EID_MMIE && |
| 712 | mmie->length == sizeof(*mmie) - 2) |
| 713 | return le16_to_cpu(mmie->key_id); |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 714 | |
Jouni Malinen | 56c52da | 2015-01-24 19:52:08 +0200 | [diff] [blame] | 715 | mmie16 = (struct ieee80211_mmie_16 *) |
| 716 | (skb->data + skb->len - sizeof(*mmie16)); |
| 717 | if (skb->len >= 24 + sizeof(*mmie16) && |
| 718 | mmie16->element_id == WLAN_EID_MMIE && |
| 719 | mmie16->length == sizeof(*mmie16) - 2) |
| 720 | return le16_to_cpu(mmie16->key_id); |
| 721 | |
| 722 | return -1; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 723 | } |
| 724 | |
Johannes Berg | 2c61cf9 | 2016-03-17 15:02:55 +0200 | [diff] [blame] | 725 | static int ieee80211_get_cs_keyid(const struct ieee80211_cipher_scheme *cs, |
| 726 | struct sk_buff *skb) |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 727 | { |
| 728 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 729 | __le16 fc; |
| 730 | int hdrlen; |
| 731 | u8 keyid; |
| 732 | |
| 733 | fc = hdr->frame_control; |
| 734 | hdrlen = ieee80211_hdrlen(fc); |
| 735 | |
| 736 | if (skb->len < hdrlen + cs->hdr_len) |
| 737 | return -EINVAL; |
| 738 | |
| 739 | skb_copy_bits(skb, hdrlen + cs->key_idx_off, &keyid, 1); |
| 740 | keyid &= cs->key_idx_mask; |
| 741 | keyid >>= cs->key_idx_shift; |
| 742 | |
| 743 | return keyid; |
| 744 | } |
| 745 | |
Johannes Berg | 1df332e | 2012-10-26 00:09:11 +0200 | [diff] [blame] | 746 | static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx) |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 747 | { |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 748 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 749 | char *dev_addr = rx->sdata->vif.addr; |
Johannes Berg | d6d1a5a | 2008-02-25 16:24:38 +0100 | [diff] [blame] | 750 | |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 751 | if (ieee80211_is_data(hdr->frame_control)) { |
Javier Cardona | 3c5772a | 2009-08-10 12:15:48 -0700 | [diff] [blame] | 752 | if (is_multicast_ether_addr(hdr->addr1)) { |
| 753 | if (ieee80211_has_tods(hdr->frame_control) || |
Johannes Berg | 1df332e | 2012-10-26 00:09:11 +0200 | [diff] [blame] | 754 | !ieee80211_has_fromds(hdr->frame_control)) |
Javier Cardona | 3c5772a | 2009-08-10 12:15:48 -0700 | [diff] [blame] | 755 | return RX_DROP_MONITOR; |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 756 | if (ether_addr_equal(hdr->addr3, dev_addr)) |
Javier Cardona | 3c5772a | 2009-08-10 12:15:48 -0700 | [diff] [blame] | 757 | return RX_DROP_MONITOR; |
| 758 | } else { |
| 759 | if (!ieee80211_has_a4(hdr->frame_control)) |
| 760 | return RX_DROP_MONITOR; |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 761 | if (ether_addr_equal(hdr->addr4, dev_addr)) |
Javier Cardona | 3c5772a | 2009-08-10 12:15:48 -0700 | [diff] [blame] | 762 | return RX_DROP_MONITOR; |
| 763 | } |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | /* If there is not an established peer link and this is not a peer link |
| 767 | * establisment frame, beacon or probe, drop the frame. |
| 768 | */ |
| 769 | |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 770 | if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) { |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 771 | struct ieee80211_mgmt *mgmt; |
Johannes Berg | d6d1a5a | 2008-02-25 16:24:38 +0100 | [diff] [blame] | 772 | |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 773 | if (!ieee80211_is_mgmt(hdr->frame_control)) |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 774 | return RX_DROP_MONITOR; |
| 775 | |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 776 | if (ieee80211_is_action(hdr->frame_control)) { |
Javier Cardona | d3aaec8a | 2011-05-03 16:57:09 -0700 | [diff] [blame] | 777 | u8 category; |
Johannes Berg | 9b395bc | 2012-10-26 00:36:40 +0200 | [diff] [blame] | 778 | |
| 779 | /* make sure category field is present */ |
| 780 | if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE) |
| 781 | return RX_DROP_MONITOR; |
| 782 | |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 783 | mgmt = (struct ieee80211_mgmt *)hdr; |
Javier Cardona | d3aaec8a | 2011-05-03 16:57:09 -0700 | [diff] [blame] | 784 | category = mgmt->u.action.category; |
| 785 | if (category != WLAN_CATEGORY_MESH_ACTION && |
Johannes Berg | 1df332e | 2012-10-26 00:09:11 +0200 | [diff] [blame] | 786 | category != WLAN_CATEGORY_SELF_PROTECTED) |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 787 | return RX_DROP_MONITOR; |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 788 | return RX_CONTINUE; |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 789 | } |
| 790 | |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 791 | if (ieee80211_is_probe_req(hdr->frame_control) || |
| 792 | ieee80211_is_probe_resp(hdr->frame_control) || |
Javier Cardona | 7183912 | 2011-04-07 15:08:31 -0700 | [diff] [blame] | 793 | ieee80211_is_beacon(hdr->frame_control) || |
| 794 | ieee80211_is_auth(hdr->frame_control)) |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 795 | return RX_CONTINUE; |
| 796 | |
| 797 | return RX_DROP_MONITOR; |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 798 | } |
| 799 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 800 | return RX_CONTINUE; |
| 801 | } |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 802 | |
Johannes Berg | fb4ea05 | 2016-01-28 16:19:24 +0200 | [diff] [blame] | 803 | static inline bool ieee80211_rx_reorder_ready(struct tid_ampdu_rx *tid_agg_rx, |
| 804 | int index) |
| 805 | { |
| 806 | struct sk_buff_head *frames = &tid_agg_rx->reorder_buf[index]; |
| 807 | struct sk_buff *tail = skb_peek_tail(frames); |
| 808 | struct ieee80211_rx_status *status; |
| 809 | |
Sara Sharon | 06470f7 | 2016-01-28 16:19:25 +0200 | [diff] [blame] | 810 | if (tid_agg_rx->reorder_buf_filtered & BIT_ULL(index)) |
| 811 | return true; |
| 812 | |
Johannes Berg | fb4ea05 | 2016-01-28 16:19:24 +0200 | [diff] [blame] | 813 | if (!tail) |
| 814 | return false; |
| 815 | |
| 816 | status = IEEE80211_SKB_RXCB(tail); |
| 817 | if (status->flag & RX_FLAG_AMSDU_MORE) |
| 818 | return false; |
| 819 | |
| 820 | return true; |
| 821 | } |
| 822 | |
Johannes Berg | d3b2fb5 | 2012-06-22 12:48:38 +0200 | [diff] [blame] | 823 | static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 824 | struct tid_ampdu_rx *tid_agg_rx, |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 825 | int index, |
| 826 | struct sk_buff_head *frames) |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 827 | { |
Michal Kazior | 83eb935 | 2014-07-16 12:09:31 +0200 | [diff] [blame] | 828 | struct sk_buff_head *skb_list = &tid_agg_rx->reorder_buf[index]; |
| 829 | struct sk_buff *skb; |
Christian Lamparter | 4cfda47 | 2010-12-27 23:21:26 +0100 | [diff] [blame] | 830 | struct ieee80211_rx_status *status; |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 831 | |
Johannes Berg | dd31857 | 2010-11-29 11:09:16 +0100 | [diff] [blame] | 832 | lockdep_assert_held(&tid_agg_rx->reorder_lock); |
| 833 | |
Michal Kazior | 83eb935 | 2014-07-16 12:09:31 +0200 | [diff] [blame] | 834 | if (skb_queue_empty(skb_list)) |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 835 | goto no_frame; |
| 836 | |
Johannes Berg | fb4ea05 | 2016-01-28 16:19:24 +0200 | [diff] [blame] | 837 | if (!ieee80211_rx_reorder_ready(tid_agg_rx, index)) { |
Michal Kazior | 83eb935 | 2014-07-16 12:09:31 +0200 | [diff] [blame] | 838 | __skb_queue_purge(skb_list); |
| 839 | goto no_frame; |
| 840 | } |
| 841 | |
| 842 | /* release frames from the reorder ring buffer */ |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 843 | tid_agg_rx->stored_mpdu_num--; |
Michal Kazior | 83eb935 | 2014-07-16 12:09:31 +0200 | [diff] [blame] | 844 | while ((skb = __skb_dequeue(skb_list))) { |
| 845 | status = IEEE80211_SKB_RXCB(skb); |
| 846 | status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE; |
| 847 | __skb_queue_tail(frames, skb); |
| 848 | } |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 849 | |
| 850 | no_frame: |
Sara Sharon | 06470f7 | 2016-01-28 16:19:25 +0200 | [diff] [blame] | 851 | tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index); |
Johannes Berg | 9a88658 | 2013-02-15 19:25:00 +0100 | [diff] [blame] | 852 | tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num); |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 853 | } |
| 854 | |
Johannes Berg | d3b2fb5 | 2012-06-22 12:48:38 +0200 | [diff] [blame] | 855 | static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 856 | struct tid_ampdu_rx *tid_agg_rx, |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 857 | u16 head_seq_num, |
| 858 | struct sk_buff_head *frames) |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 859 | { |
| 860 | int index; |
| 861 | |
Johannes Berg | dd31857 | 2010-11-29 11:09:16 +0100 | [diff] [blame] | 862 | lockdep_assert_held(&tid_agg_rx->reorder_lock); |
| 863 | |
Johannes Berg | 9a88658 | 2013-02-15 19:25:00 +0100 | [diff] [blame] | 864 | while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) { |
Karl Beldan | 2e3049b | 2013-10-24 15:53:32 +0200 | [diff] [blame] | 865 | index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size; |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 866 | ieee80211_release_reorder_frame(sdata, tid_agg_rx, index, |
| 867 | frames); |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 868 | } |
| 869 | } |
| 870 | |
| 871 | /* |
| 872 | * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If |
| 873 | * the skb was added to the buffer longer than this time ago, the earlier |
| 874 | * frames that have not yet been received are assumed to be lost and the skb |
| 875 | * can be released for processing. This may also release other skb's from the |
| 876 | * reorder buffer if there are no additional gaps between the frames. |
Christian Lamparter | 2bff8ebf | 2010-08-05 01:36:41 +0200 | [diff] [blame] | 877 | * |
| 878 | * Callers must hold tid_agg_rx->reorder_lock. |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 879 | */ |
| 880 | #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10) |
| 881 | |
Johannes Berg | d3b2fb5 | 2012-06-22 12:48:38 +0200 | [diff] [blame] | 882 | static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata, |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 883 | struct tid_ampdu_rx *tid_agg_rx, |
| 884 | struct sk_buff_head *frames) |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 885 | { |
Michal Kazior | 83eb935 | 2014-07-16 12:09:31 +0200 | [diff] [blame] | 886 | int index, i, j; |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 887 | |
Johannes Berg | dd31857 | 2010-11-29 11:09:16 +0100 | [diff] [blame] | 888 | lockdep_assert_held(&tid_agg_rx->reorder_lock); |
| 889 | |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 890 | /* release the buffer until next missing frame */ |
Karl Beldan | 2e3049b | 2013-10-24 15:53:32 +0200 | [diff] [blame] | 891 | index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size; |
Johannes Berg | fb4ea05 | 2016-01-28 16:19:24 +0200 | [diff] [blame] | 892 | if (!ieee80211_rx_reorder_ready(tid_agg_rx, index) && |
Eliad Peller | 07ae2df | 2012-02-01 18:48:09 +0200 | [diff] [blame] | 893 | tid_agg_rx->stored_mpdu_num) { |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 894 | /* |
| 895 | * No buffers ready to be released, but check whether any |
| 896 | * frames in the reorder buffer have timed out. |
| 897 | */ |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 898 | int skipped = 1; |
| 899 | for (j = (index + 1) % tid_agg_rx->buf_size; j != index; |
| 900 | j = (j + 1) % tid_agg_rx->buf_size) { |
Johannes Berg | fb4ea05 | 2016-01-28 16:19:24 +0200 | [diff] [blame] | 901 | if (!ieee80211_rx_reorder_ready(tid_agg_rx, j)) { |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 902 | skipped++; |
| 903 | continue; |
| 904 | } |
Daniel Halperin | 499fe9a | 2011-03-24 16:01:48 -0700 | [diff] [blame] | 905 | if (skipped && |
| 906 | !time_after(jiffies, tid_agg_rx->reorder_time[j] + |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 907 | HT_RX_REORDER_BUF_TIMEOUT)) |
Christian Lamparter | 2bff8ebf | 2010-08-05 01:36:41 +0200 | [diff] [blame] | 908 | goto set_release_timer; |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 909 | |
Michal Kazior | 83eb935 | 2014-07-16 12:09:31 +0200 | [diff] [blame] | 910 | /* don't leave incomplete A-MSDUs around */ |
| 911 | for (i = (index + 1) % tid_agg_rx->buf_size; i != j; |
| 912 | i = (i + 1) % tid_agg_rx->buf_size) |
| 913 | __skb_queue_purge(&tid_agg_rx->reorder_buf[i]); |
| 914 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 915 | ht_dbg_ratelimited(sdata, |
| 916 | "release an RX reorder frame due to timeout on earlier frames\n"); |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 917 | ieee80211_release_reorder_frame(sdata, tid_agg_rx, j, |
| 918 | frames); |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 919 | |
| 920 | /* |
| 921 | * Increment the head seq# also for the skipped slots. |
| 922 | */ |
| 923 | tid_agg_rx->head_seq_num = |
Johannes Berg | 9a88658 | 2013-02-15 19:25:00 +0100 | [diff] [blame] | 924 | (tid_agg_rx->head_seq_num + |
| 925 | skipped) & IEEE80211_SN_MASK; |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 926 | skipped = 0; |
| 927 | } |
Johannes Berg | fb4ea05 | 2016-01-28 16:19:24 +0200 | [diff] [blame] | 928 | } else while (ieee80211_rx_reorder_ready(tid_agg_rx, index)) { |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 929 | ieee80211_release_reorder_frame(sdata, tid_agg_rx, index, |
| 930 | frames); |
Karl Beldan | 2e3049b | 2013-10-24 15:53:32 +0200 | [diff] [blame] | 931 | index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size; |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 932 | } |
Christian Lamparter | 2bff8ebf | 2010-08-05 01:36:41 +0200 | [diff] [blame] | 933 | |
| 934 | if (tid_agg_rx->stored_mpdu_num) { |
Karl Beldan | 2e3049b | 2013-10-24 15:53:32 +0200 | [diff] [blame] | 935 | j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size; |
Christian Lamparter | 2bff8ebf | 2010-08-05 01:36:41 +0200 | [diff] [blame] | 936 | |
| 937 | for (; j != (index - 1) % tid_agg_rx->buf_size; |
| 938 | j = (j + 1) % tid_agg_rx->buf_size) { |
Johannes Berg | fb4ea05 | 2016-01-28 16:19:24 +0200 | [diff] [blame] | 939 | if (ieee80211_rx_reorder_ready(tid_agg_rx, j)) |
Christian Lamparter | 2bff8ebf | 2010-08-05 01:36:41 +0200 | [diff] [blame] | 940 | break; |
| 941 | } |
| 942 | |
| 943 | set_release_timer: |
| 944 | |
Johannes Berg | 788211d | 2015-04-01 14:20:42 +0200 | [diff] [blame] | 945 | if (!tid_agg_rx->removed) |
| 946 | mod_timer(&tid_agg_rx->reorder_timer, |
| 947 | tid_agg_rx->reorder_time[j] + 1 + |
| 948 | HT_RX_REORDER_BUF_TIMEOUT); |
Christian Lamparter | 2bff8ebf | 2010-08-05 01:36:41 +0200 | [diff] [blame] | 949 | } else { |
| 950 | del_timer(&tid_agg_rx->reorder_timer); |
| 951 | } |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 952 | } |
| 953 | |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 954 | /* |
| 955 | * As this function belongs to the RX path it must be under |
| 956 | * rcu_read_lock protection. It returns false if the frame |
| 957 | * can be processed immediately, true if it was consumed. |
| 958 | */ |
Johannes Berg | d3b2fb5 | 2012-06-22 12:48:38 +0200 | [diff] [blame] | 959 | static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 960 | struct tid_ampdu_rx *tid_agg_rx, |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 961 | struct sk_buff *skb, |
| 962 | struct sk_buff_head *frames) |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 963 | { |
| 964 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
Michal Kazior | 83eb935 | 2014-07-16 12:09:31 +0200 | [diff] [blame] | 965 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 966 | u16 sc = le16_to_cpu(hdr->seq_ctrl); |
| 967 | u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 968 | u16 head_seq_num, buf_size; |
| 969 | int index; |
Christian Lamparter | 2bff8ebf | 2010-08-05 01:36:41 +0200 | [diff] [blame] | 970 | bool ret = true; |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 971 | |
Johannes Berg | dd31857 | 2010-11-29 11:09:16 +0100 | [diff] [blame] | 972 | spin_lock(&tid_agg_rx->reorder_lock); |
| 973 | |
Michal Kazior | 4549cf2 | 2014-09-02 14:05:10 +0200 | [diff] [blame] | 974 | /* |
| 975 | * Offloaded BA sessions have no known starting sequence number so pick |
| 976 | * one from first Rxed frame for this tid after BA was started. |
| 977 | */ |
| 978 | if (unlikely(tid_agg_rx->auto_seq)) { |
| 979 | tid_agg_rx->auto_seq = false; |
| 980 | tid_agg_rx->ssn = mpdu_seq_num; |
| 981 | tid_agg_rx->head_seq_num = mpdu_seq_num; |
| 982 | } |
| 983 | |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 984 | buf_size = tid_agg_rx->buf_size; |
| 985 | head_seq_num = tid_agg_rx->head_seq_num; |
| 986 | |
| 987 | /* frame with out of date sequence number */ |
Johannes Berg | 9a88658 | 2013-02-15 19:25:00 +0100 | [diff] [blame] | 988 | if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) { |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 989 | dev_kfree_skb(skb); |
Christian Lamparter | 2bff8ebf | 2010-08-05 01:36:41 +0200 | [diff] [blame] | 990 | goto out; |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | /* |
| 994 | * If frame the sequence number exceeds our buffering window |
| 995 | * size release some previous frames to make room for this one. |
| 996 | */ |
Johannes Berg | 9a88658 | 2013-02-15 19:25:00 +0100 | [diff] [blame] | 997 | if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) { |
| 998 | head_seq_num = ieee80211_sn_inc( |
| 999 | ieee80211_sn_sub(mpdu_seq_num, buf_size)); |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1000 | /* release stored frames up to new head to stack */ |
Johannes Berg | d3b2fb5 | 2012-06-22 12:48:38 +0200 | [diff] [blame] | 1001 | ieee80211_release_reorder_frames(sdata, tid_agg_rx, |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 1002 | head_seq_num, frames); |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | /* Now the new frame is always in the range of the reordering buffer */ |
| 1006 | |
Karl Beldan | 2e3049b | 2013-10-24 15:53:32 +0200 | [diff] [blame] | 1007 | index = mpdu_seq_num % tid_agg_rx->buf_size; |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1008 | |
| 1009 | /* check if we already stored this frame */ |
Johannes Berg | fb4ea05 | 2016-01-28 16:19:24 +0200 | [diff] [blame] | 1010 | if (ieee80211_rx_reorder_ready(tid_agg_rx, index)) { |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1011 | dev_kfree_skb(skb); |
Christian Lamparter | 2bff8ebf | 2010-08-05 01:36:41 +0200 | [diff] [blame] | 1012 | goto out; |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | /* |
| 1016 | * If the current MPDU is in the right order and nothing else |
| 1017 | * is stored we can process it directly, no need to buffer it. |
Johannes Berg | c835b21 | 2011-03-15 23:17:01 +0100 | [diff] [blame] | 1018 | * If it is first but there's something stored, we may be able |
| 1019 | * to release frames after this one. |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1020 | */ |
| 1021 | if (mpdu_seq_num == tid_agg_rx->head_seq_num && |
| 1022 | tid_agg_rx->stored_mpdu_num == 0) { |
Michal Kazior | 83eb935 | 2014-07-16 12:09:31 +0200 | [diff] [blame] | 1023 | if (!(status->flag & RX_FLAG_AMSDU_MORE)) |
| 1024 | tid_agg_rx->head_seq_num = |
| 1025 | ieee80211_sn_inc(tid_agg_rx->head_seq_num); |
Christian Lamparter | 2bff8ebf | 2010-08-05 01:36:41 +0200 | [diff] [blame] | 1026 | ret = false; |
| 1027 | goto out; |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | /* put the frame in the reordering buffer */ |
Michal Kazior | 83eb935 | 2014-07-16 12:09:31 +0200 | [diff] [blame] | 1031 | __skb_queue_tail(&tid_agg_rx->reorder_buf[index], skb); |
| 1032 | if (!(status->flag & RX_FLAG_AMSDU_MORE)) { |
| 1033 | tid_agg_rx->reorder_time[index] = jiffies; |
| 1034 | tid_agg_rx->stored_mpdu_num++; |
| 1035 | ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames); |
| 1036 | } |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1037 | |
Christian Lamparter | 2bff8ebf | 2010-08-05 01:36:41 +0200 | [diff] [blame] | 1038 | out: |
| 1039 | spin_unlock(&tid_agg_rx->reorder_lock); |
| 1040 | return ret; |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | /* |
| 1044 | * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns |
| 1045 | * true if the MPDU was buffered, false if it should be processed. |
| 1046 | */ |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 1047 | static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx, |
| 1048 | struct sk_buff_head *frames) |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1049 | { |
Johannes Berg | 2569a82 | 2009-11-25 17:46:17 +0100 | [diff] [blame] | 1050 | struct sk_buff *skb = rx->skb; |
| 1051 | struct ieee80211_local *local = rx->local; |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1052 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
Johannes Berg | 2569a82 | 2009-11-25 17:46:17 +0100 | [diff] [blame] | 1053 | struct sta_info *sta = rx->sta; |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1054 | struct tid_ampdu_rx *tid_agg_rx; |
| 1055 | u16 sc; |
Thomas Pedersen | 6cc00d5 | 2011-11-03 21:11:11 -0700 | [diff] [blame] | 1056 | u8 tid, ack_policy; |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1057 | |
Johannes Berg | 051a41fa | 2013-11-20 11:28:27 +0100 | [diff] [blame] | 1058 | if (!ieee80211_is_data_qos(hdr->frame_control) || |
| 1059 | is_multicast_ether_addr(hdr->addr1)) |
Johannes Berg | 2569a82 | 2009-11-25 17:46:17 +0100 | [diff] [blame] | 1060 | goto dont_reorder; |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1061 | |
| 1062 | /* |
| 1063 | * filter the QoS data rx stream according to |
| 1064 | * STA/TID and check if this STA/TID is on aggregation |
| 1065 | */ |
| 1066 | |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1067 | if (!sta) |
Johannes Berg | 2569a82 | 2009-11-25 17:46:17 +0100 | [diff] [blame] | 1068 | goto dont_reorder; |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1069 | |
Thomas Pedersen | 6cc00d5 | 2011-11-03 21:11:11 -0700 | [diff] [blame] | 1070 | ack_policy = *ieee80211_get_qos_ctl(hdr) & |
| 1071 | IEEE80211_QOS_CTL_ACK_POLICY_MASK; |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1072 | tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK; |
| 1073 | |
Johannes Berg | a87f736 | 2010-06-10 10:21:38 +0200 | [diff] [blame] | 1074 | tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]); |
| 1075 | if (!tid_agg_rx) |
| 1076 | goto dont_reorder; |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1077 | |
| 1078 | /* qos null data frames are excluded */ |
| 1079 | if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC))) |
Johannes Berg | a87f736 | 2010-06-10 10:21:38 +0200 | [diff] [blame] | 1080 | goto dont_reorder; |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1081 | |
Thomas Pedersen | 6cc00d5 | 2011-11-03 21:11:11 -0700 | [diff] [blame] | 1082 | /* not part of a BA session */ |
| 1083 | if (ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK && |
| 1084 | ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_NORMAL) |
| 1085 | goto dont_reorder; |
| 1086 | |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1087 | /* new, potentially un-ordered, ampdu frame - process it */ |
| 1088 | |
| 1089 | /* reset session timer */ |
| 1090 | if (tid_agg_rx->timeout) |
Felix Fietkau | 12d3952f | 2012-03-18 22:58:06 +0100 | [diff] [blame] | 1091 | tid_agg_rx->last_rx = jiffies; |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1092 | |
| 1093 | /* if this mpdu is fragmented - terminate rx aggregation session */ |
| 1094 | sc = le16_to_cpu(hdr->seq_ctrl); |
| 1095 | if (sc & IEEE80211_SCTL_FRAG) { |
Johannes Berg | c1475ca | 2010-06-10 10:21:37 +0200 | [diff] [blame] | 1096 | skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME; |
Johannes Berg | 344eec6 | 2010-06-10 10:21:36 +0200 | [diff] [blame] | 1097 | skb_queue_tail(&rx->sdata->skb_queue, skb); |
| 1098 | ieee80211_queue_work(&local->hw, &rx->sdata->work); |
Johannes Berg | 2569a82 | 2009-11-25 17:46:17 +0100 | [diff] [blame] | 1099 | return; |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1100 | } |
| 1101 | |
Johannes Berg | a87f736 | 2010-06-10 10:21:38 +0200 | [diff] [blame] | 1102 | /* |
| 1103 | * No locking needed -- we will only ever process one |
| 1104 | * RX packet at a time, and thus own tid_agg_rx. All |
| 1105 | * other code manipulating it needs to (and does) make |
| 1106 | * sure that we cannot get to it any more before doing |
| 1107 | * anything with it. |
| 1108 | */ |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 1109 | if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb, |
| 1110 | frames)) |
Johannes Berg | 2569a82 | 2009-11-25 17:46:17 +0100 | [diff] [blame] | 1111 | return; |
| 1112 | |
| 1113 | dont_reorder: |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 1114 | __skb_queue_tail(frames, skb); |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame] | 1115 | } |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 1116 | |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 1117 | static ieee80211_rx_result debug_noinline |
Johannes Berg | 0395442 | 2014-11-11 16:49:25 +0100 | [diff] [blame] | 1118 | ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1119 | { |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 1120 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; |
Johannes Berg | 554891e | 2010-09-24 12:38:25 +0200 | [diff] [blame] | 1121 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1122 | |
Sara Sharon | f9cfa5f | 2015-12-08 16:04:33 +0200 | [diff] [blame] | 1123 | if (status->flag & RX_FLAG_DUP_VALIDATED) |
| 1124 | return RX_CONTINUE; |
| 1125 | |
Johannes Berg | 6b0f327 | 2013-07-11 22:33:26 +0200 | [diff] [blame] | 1126 | /* |
| 1127 | * Drop duplicate 802.11 retransmissions |
| 1128 | * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery") |
| 1129 | */ |
Johannes Berg | 0395442 | 2014-11-11 16:49:25 +0100 | [diff] [blame] | 1130 | |
| 1131 | if (rx->skb->len < 24) |
| 1132 | return RX_CONTINUE; |
| 1133 | |
| 1134 | if (ieee80211_is_ctl(hdr->frame_control) || |
| 1135 | ieee80211_is_qos_nullfunc(hdr->frame_control) || |
| 1136 | is_multicast_ether_addr(hdr->addr1)) |
| 1137 | return RX_CONTINUE; |
| 1138 | |
Johannes Berg | a732fa7 | 2015-10-14 18:27:07 +0200 | [diff] [blame] | 1139 | if (!rx->sta) |
| 1140 | return RX_CONTINUE; |
| 1141 | |
| 1142 | if (unlikely(ieee80211_has_retry(hdr->frame_control) && |
| 1143 | rx->sta->last_seq_ctrl[rx->seqno_idx] == hdr->seq_ctrl)) { |
| 1144 | I802_DEBUG_INC(rx->local->dot11FrameDuplicateCount); |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 1145 | rx->sta->rx_stats.num_duplicates++; |
Johannes Berg | a732fa7 | 2015-10-14 18:27:07 +0200 | [diff] [blame] | 1146 | return RX_DROP_UNUSABLE; |
| 1147 | } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) { |
| 1148 | rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1149 | } |
| 1150 | |
Johannes Berg | 0395442 | 2014-11-11 16:49:25 +0100 | [diff] [blame] | 1151 | return RX_CONTINUE; |
| 1152 | } |
| 1153 | |
| 1154 | static ieee80211_rx_result debug_noinline |
| 1155 | ieee80211_rx_h_check(struct ieee80211_rx_data *rx) |
| 1156 | { |
| 1157 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; |
| 1158 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1159 | /* Drop disallowed frame classes based on STA auth/assoc state; |
| 1160 | * IEEE 802.11, Chap 5.5. |
| 1161 | * |
Johannes Berg | ccd7b36 | 2008-09-11 00:01:56 +0200 | [diff] [blame] | 1162 | * mac80211 filters only based on association state, i.e. it drops |
| 1163 | * Class 3 frames from not associated stations. hostapd sends |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1164 | * deauth/disassoc frames when needed. In addition, hostapd is |
| 1165 | * responsible for filtering on both auth and assoc states. |
| 1166 | */ |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 1167 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 1168 | if (ieee80211_vif_is_mesh(&rx->sdata->vif)) |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 1169 | return ieee80211_rx_mesh_check(rx); |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 1170 | |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 1171 | if (unlikely((ieee80211_is_data(hdr->frame_control) || |
| 1172 | ieee80211_is_pspoll(hdr->frame_control)) && |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1173 | rx->sdata->vif.type != NL80211_IFTYPE_ADHOC && |
Bill Jordan | 1be7fe8 | 2010-10-01 11:20:41 -0400 | [diff] [blame] | 1174 | rx->sdata->vif.type != NL80211_IFTYPE_WDS && |
Rostislav Lisovy | 239281f | 2014-11-03 10:33:19 +0100 | [diff] [blame] | 1175 | rx->sdata->vif.type != NL80211_IFTYPE_OCB && |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1176 | (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) { |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 1177 | /* |
| 1178 | * accept port control frames from the AP even when it's not |
| 1179 | * yet marked ASSOC to prevent a race where we don't set the |
| 1180 | * assoc bit quickly enough before it sends the first frame |
| 1181 | */ |
| 1182 | if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION && |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 1183 | ieee80211_is_data_present(hdr->frame_control)) { |
Johannes Berg | 6dbda2d | 2012-10-26 00:41:23 +0200 | [diff] [blame] | 1184 | unsigned int hdrlen; |
| 1185 | __be16 ethertype; |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 1186 | |
Johannes Berg | 6dbda2d | 2012-10-26 00:41:23 +0200 | [diff] [blame] | 1187 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
| 1188 | |
| 1189 | if (rx->skb->len < hdrlen + 8) |
| 1190 | return RX_DROP_MONITOR; |
| 1191 | |
| 1192 | skb_copy_bits(rx->skb, hdrlen + 6, ðertype, 2); |
| 1193 | if (ethertype == rx->sdata->control_port_protocol) |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 1194 | return RX_CONTINUE; |
| 1195 | } |
Johannes Berg | 21fc756 | 2011-11-04 11:18:13 +0100 | [diff] [blame] | 1196 | |
| 1197 | if (rx->sdata->vif.type == NL80211_IFTYPE_AP && |
| 1198 | cfg80211_rx_spurious_frame(rx->sdata->dev, |
| 1199 | hdr->addr2, |
| 1200 | GFP_ATOMIC)) |
| 1201 | return RX_DROP_UNUSABLE; |
| 1202 | |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1203 | return RX_DROP_MONITOR; |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 1204 | } |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1205 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1206 | return RX_CONTINUE; |
Johannes Berg | 570bd53 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 1210 | static ieee80211_rx_result debug_noinline |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1211 | ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx) |
| 1212 | { |
| 1213 | struct ieee80211_local *local; |
| 1214 | struct ieee80211_hdr *hdr; |
| 1215 | struct sk_buff *skb; |
| 1216 | |
| 1217 | local = rx->local; |
| 1218 | skb = rx->skb; |
| 1219 | hdr = (struct ieee80211_hdr *) skb->data; |
| 1220 | |
| 1221 | if (!local->pspolling) |
| 1222 | return RX_CONTINUE; |
| 1223 | |
| 1224 | if (!ieee80211_has_fromds(hdr->frame_control)) |
| 1225 | /* this is not from AP */ |
| 1226 | return RX_CONTINUE; |
| 1227 | |
| 1228 | if (!ieee80211_is_data(hdr->frame_control)) |
| 1229 | return RX_CONTINUE; |
| 1230 | |
| 1231 | if (!ieee80211_has_moredata(hdr->frame_control)) { |
| 1232 | /* AP has no more frames buffered for us */ |
| 1233 | local->pspolling = false; |
| 1234 | return RX_CONTINUE; |
| 1235 | } |
| 1236 | |
| 1237 | /* more data bit is set, let's request a new frame from the AP */ |
| 1238 | ieee80211_send_pspoll(local, rx->sdata); |
| 1239 | |
| 1240 | return RX_CONTINUE; |
| 1241 | } |
| 1242 | |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 1243 | static void sta_ps_start(struct sta_info *sta) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1244 | { |
Johannes Berg | 133b822 | 2008-09-16 14:18:59 +0200 | [diff] [blame] | 1245 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Christian Lamparter | 4571d3b | 2008-11-30 00:48:41 +0100 | [diff] [blame] | 1246 | struct ieee80211_local *local = sdata->local; |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 1247 | struct ps_data *ps; |
Felix Fietkau | ba8c3d6 | 2015-03-27 21:30:37 +0100 | [diff] [blame] | 1248 | int tid; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1249 | |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 1250 | if (sta->sdata->vif.type == NL80211_IFTYPE_AP || |
| 1251 | sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
| 1252 | ps = &sdata->bss->ps; |
| 1253 | else |
| 1254 | return; |
| 1255 | |
| 1256 | atomic_inc(&ps->num_sta_ps); |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1257 | set_sta_flag(sta, WLAN_STA_PS_STA); |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1258 | if (!ieee80211_hw_check(&local->hw, AP_LINK_PS)) |
Arik Nemtsov | d057e5a | 2011-01-31 22:29:13 +0200 | [diff] [blame] | 1259 | drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta); |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 1260 | ps_dbg(sdata, "STA %pM aid %d enters power save mode\n", |
| 1261 | sta->sta.addr, sta->sta.aid); |
Felix Fietkau | ba8c3d6 | 2015-03-27 21:30:37 +0100 | [diff] [blame] | 1262 | |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 1263 | ieee80211_clear_fast_xmit(sta); |
| 1264 | |
Felix Fietkau | ba8c3d6 | 2015-03-27 21:30:37 +0100 | [diff] [blame] | 1265 | if (!sta->sta.txq[0]) |
| 1266 | return; |
| 1267 | |
| 1268 | for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) { |
| 1269 | struct txq_info *txqi = to_txq_info(sta->sta.txq[tid]); |
| 1270 | |
| 1271 | if (!skb_queue_len(&txqi->queue)) |
| 1272 | set_bit(tid, &sta->txq_buffered_tids); |
| 1273 | else |
| 1274 | clear_bit(tid, &sta->txq_buffered_tids); |
| 1275 | } |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1276 | } |
| 1277 | |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 1278 | static void sta_ps_end(struct sta_info *sta) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1279 | { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 1280 | ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n", |
| 1281 | sta->sta.addr, sta->sta.aid); |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 1282 | |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1283 | if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) { |
Johannes Berg | e3685e0 | 2014-02-20 11:19:58 +0100 | [diff] [blame] | 1284 | /* |
| 1285 | * Clear the flag only if the other one is still set |
| 1286 | * so that the TX path won't start TX'ing new frames |
| 1287 | * directly ... In the case that the driver flag isn't |
| 1288 | * set ieee80211_sta_ps_deliver_wakeup() will clear it. |
| 1289 | */ |
| 1290 | clear_sta_flag(sta, WLAN_STA_PS_STA); |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 1291 | ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n", |
| 1292 | sta->sta.addr, sta->sta.aid); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1293 | return; |
| 1294 | } |
| 1295 | |
Johannes Berg | 5ac2e35 | 2014-05-27 16:32:27 +0200 | [diff] [blame] | 1296 | set_sta_flag(sta, WLAN_STA_PS_DELIVER); |
| 1297 | clear_sta_flag(sta, WLAN_STA_PS_STA); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1298 | ieee80211_sta_ps_deliver_wakeup(sta); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1299 | } |
| 1300 | |
Johannes Berg | cf47161 | 2015-06-16 16:16:38 +0200 | [diff] [blame] | 1301 | int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start) |
Arik Nemtsov | d057e5a | 2011-01-31 22:29:13 +0200 | [diff] [blame] | 1302 | { |
Johannes Berg | cf47161 | 2015-06-16 16:16:38 +0200 | [diff] [blame] | 1303 | struct sta_info *sta = container_of(pubsta, struct sta_info, sta); |
Arik Nemtsov | d057e5a | 2011-01-31 22:29:13 +0200 | [diff] [blame] | 1304 | bool in_ps; |
| 1305 | |
Johannes Berg | cf47161 | 2015-06-16 16:16:38 +0200 | [diff] [blame] | 1306 | WARN_ON(!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS)); |
Arik Nemtsov | d057e5a | 2011-01-31 22:29:13 +0200 | [diff] [blame] | 1307 | |
| 1308 | /* Don't let the same PS state be set twice */ |
Johannes Berg | cf47161 | 2015-06-16 16:16:38 +0200 | [diff] [blame] | 1309 | in_ps = test_sta_flag(sta, WLAN_STA_PS_STA); |
Arik Nemtsov | d057e5a | 2011-01-31 22:29:13 +0200 | [diff] [blame] | 1310 | if ((start && in_ps) || (!start && !in_ps)) |
| 1311 | return -EINVAL; |
| 1312 | |
| 1313 | if (start) |
Johannes Berg | cf47161 | 2015-06-16 16:16:38 +0200 | [diff] [blame] | 1314 | sta_ps_start(sta); |
Arik Nemtsov | d057e5a | 2011-01-31 22:29:13 +0200 | [diff] [blame] | 1315 | else |
Johannes Berg | cf47161 | 2015-06-16 16:16:38 +0200 | [diff] [blame] | 1316 | sta_ps_end(sta); |
Arik Nemtsov | d057e5a | 2011-01-31 22:29:13 +0200 | [diff] [blame] | 1317 | |
| 1318 | return 0; |
| 1319 | } |
| 1320 | EXPORT_SYMBOL(ieee80211_sta_ps_transition); |
| 1321 | |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 1322 | static ieee80211_rx_result debug_noinline |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1323 | ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx) |
| 1324 | { |
| 1325 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
| 1326 | struct ieee80211_hdr *hdr = (void *)rx->skb->data; |
| 1327 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); |
| 1328 | int tid, ac; |
| 1329 | |
Johannes Berg | 5c90067 | 2015-04-22 14:48:34 +0200 | [diff] [blame] | 1330 | if (!rx->sta) |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1331 | return RX_CONTINUE; |
| 1332 | |
| 1333 | if (sdata->vif.type != NL80211_IFTYPE_AP && |
| 1334 | sdata->vif.type != NL80211_IFTYPE_AP_VLAN) |
| 1335 | return RX_CONTINUE; |
| 1336 | |
| 1337 | /* |
| 1338 | * The device handles station powersave, so don't do anything about |
| 1339 | * uAPSD and PS-Poll frames (the latter shouldn't even come up from |
| 1340 | * it to mac80211 since they're handled.) |
| 1341 | */ |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1342 | if (ieee80211_hw_check(&sdata->local->hw, AP_LINK_PS)) |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1343 | return RX_CONTINUE; |
| 1344 | |
| 1345 | /* |
| 1346 | * Don't do anything if the station isn't already asleep. In |
| 1347 | * the uAPSD case, the station will probably be marked asleep, |
| 1348 | * in the PS-Poll case the station must be confused ... |
| 1349 | */ |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1350 | if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA)) |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1351 | return RX_CONTINUE; |
| 1352 | |
| 1353 | if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) { |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1354 | if (!test_sta_flag(rx->sta, WLAN_STA_SP)) { |
| 1355 | if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER)) |
Johannes Berg | deeaee19 | 2011-09-29 16:04:35 +0200 | [diff] [blame] | 1356 | ieee80211_sta_ps_deliver_poll_response(rx->sta); |
| 1357 | else |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1358 | set_sta_flag(rx->sta, WLAN_STA_PSPOLL); |
Johannes Berg | deeaee19 | 2011-09-29 16:04:35 +0200 | [diff] [blame] | 1359 | } |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1360 | |
| 1361 | /* Free PS Poll skb here instead of returning RX_DROP that would |
| 1362 | * count as an dropped frame. */ |
| 1363 | dev_kfree_skb(rx->skb); |
| 1364 | |
| 1365 | return RX_QUEUED; |
| 1366 | } else if (!ieee80211_has_morefrags(hdr->frame_control) && |
| 1367 | !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) && |
| 1368 | ieee80211_has_pm(hdr->frame_control) && |
| 1369 | (ieee80211_is_data_qos(hdr->frame_control) || |
| 1370 | ieee80211_is_qos_nullfunc(hdr->frame_control))) { |
| 1371 | tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK; |
| 1372 | ac = ieee802_1d_to_ac[tid & 7]; |
| 1373 | |
| 1374 | /* |
| 1375 | * If this AC is not trigger-enabled do nothing. |
| 1376 | * |
| 1377 | * NB: This could/should check a separate bitmap of trigger- |
| 1378 | * enabled queues, but for now we only implement uAPSD w/o |
| 1379 | * TSPEC changes to the ACs, so they're always the same. |
| 1380 | */ |
| 1381 | if (!(rx->sta->sta.uapsd_queues & BIT(ac))) |
| 1382 | return RX_CONTINUE; |
| 1383 | |
| 1384 | /* if we are in a service period, do nothing */ |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1385 | if (test_sta_flag(rx->sta, WLAN_STA_SP)) |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1386 | return RX_CONTINUE; |
| 1387 | |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1388 | if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER)) |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1389 | ieee80211_sta_ps_deliver_uapsd(rx->sta); |
| 1390 | else |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1391 | set_sta_flag(rx->sta, WLAN_STA_UAPSD); |
Johannes Berg | 47086fc | 2011-09-29 16:04:33 +0200 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | return RX_CONTINUE; |
| 1395 | } |
| 1396 | |
| 1397 | static ieee80211_rx_result debug_noinline |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1398 | ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1399 | { |
| 1400 | struct sta_info *sta = rx->sta; |
Johannes Berg | eb9fb5b8 | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 1401 | struct sk_buff *skb = rx->skb; |
| 1402 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
| 1403 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Felix Fietkau | ef0621e | 2013-04-22 16:29:31 +0200 | [diff] [blame] | 1404 | int i; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1405 | |
| 1406 | if (!sta) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1407 | return RX_CONTINUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1408 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1409 | /* |
| 1410 | * Update last_rx only for IBSS packets which are for the current |
Antonio Quartulli | e584da5e | 2012-11-25 23:13:42 +0100 | [diff] [blame] | 1411 | * BSSID and for station already AUTHORIZED to avoid keeping the |
| 1412 | * current IBSS network alive in cases where other STAs start |
| 1413 | * using different BSSID. This will also give the station another |
| 1414 | * chance to restart the authentication/authorization in case |
| 1415 | * something went wrong the first time. |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1416 | */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1417 | if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) { |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 1418 | u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len, |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1419 | NL80211_IFTYPE_ADHOC); |
Antonio Quartulli | e584da5e | 2012-11-25 23:13:42 +0100 | [diff] [blame] | 1420 | if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) && |
| 1421 | test_sta_flag(sta, WLAN_STA_AUTHORIZED)) { |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 1422 | sta->rx_stats.last_rx = jiffies; |
Henning Rogge | f4ebddf | 2014-05-01 10:03:46 +0200 | [diff] [blame] | 1423 | if (ieee80211_is_data(hdr->frame_control) && |
Johannes Berg | 4f6b1b3 | 2016-03-31 20:02:08 +0300 | [diff] [blame] | 1424 | !is_multicast_ether_addr(hdr->addr1)) |
| 1425 | sta->rx_stats.last_rate = |
| 1426 | sta_stats_encode_rate(status); |
Felix Fietkau | 3af6334 | 2011-02-27 22:08:01 +0100 | [diff] [blame] | 1427 | } |
Rostislav Lisovy | 239281f | 2014-11-03 10:33:19 +0100 | [diff] [blame] | 1428 | } else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) { |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 1429 | sta->rx_stats.last_rx = jiffies; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1430 | } else if (!is_multicast_ether_addr(hdr->addr1)) { |
| 1431 | /* |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 1432 | * Mesh beacons will update last_rx when if they are found to |
| 1433 | * match the current local configuration when processed. |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1434 | */ |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 1435 | sta->rx_stats.last_rx = jiffies; |
Johannes Berg | 4f6b1b3 | 2016-03-31 20:02:08 +0300 | [diff] [blame] | 1436 | if (ieee80211_is_data(hdr->frame_control)) |
| 1437 | sta->rx_stats.last_rate = sta_stats_encode_rate(status); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1438 | } |
| 1439 | |
Kalle Valo | 3cf335d5 | 2009-03-22 21:57:06 +0200 | [diff] [blame] | 1440 | if (rx->sdata->vif.type == NL80211_IFTYPE_STATION) |
| 1441 | ieee80211_sta_rx_notify(rx->sdata, hdr); |
| 1442 | |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 1443 | sta->rx_stats.fragments++; |
Johannes Berg | 0f9c5a6 | 2016-03-31 20:02:09 +0300 | [diff] [blame] | 1444 | |
| 1445 | u64_stats_update_begin(&rx->sta->rx_stats.syncp); |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 1446 | sta->rx_stats.bytes += rx->skb->len; |
Johannes Berg | 0f9c5a6 | 2016-03-31 20:02:09 +0300 | [diff] [blame] | 1447 | u64_stats_update_end(&rx->sta->rx_stats.syncp); |
| 1448 | |
Felix Fietkau | fe8431f | 2012-03-01 18:00:07 +0100 | [diff] [blame] | 1449 | if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) { |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 1450 | sta->rx_stats.last_signal = status->signal; |
Johannes Berg | 0be6ed1 | 2016-03-31 20:02:05 +0300 | [diff] [blame] | 1451 | ewma_signal_add(&sta->rx_stats_avg.signal, -status->signal); |
Felix Fietkau | fe8431f | 2012-03-01 18:00:07 +0100 | [diff] [blame] | 1452 | } |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1453 | |
Felix Fietkau | ef0621e | 2013-04-22 16:29:31 +0200 | [diff] [blame] | 1454 | if (status->chains) { |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 1455 | sta->rx_stats.chains = status->chains; |
Felix Fietkau | ef0621e | 2013-04-22 16:29:31 +0200 | [diff] [blame] | 1456 | for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) { |
| 1457 | int signal = status->chain_signal[i]; |
| 1458 | |
| 1459 | if (!(status->chains & BIT(i))) |
| 1460 | continue; |
| 1461 | |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 1462 | sta->rx_stats.chain_signal_last[i] = signal; |
Johannes Berg | 0be6ed1 | 2016-03-31 20:02:05 +0300 | [diff] [blame] | 1463 | ewma_signal_add(&sta->rx_stats_avg.chain_signal[i], |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 1464 | -signal); |
Felix Fietkau | ef0621e | 2013-04-22 16:29:31 +0200 | [diff] [blame] | 1465 | } |
| 1466 | } |
| 1467 | |
Johannes Berg | 72eaa43 | 2008-11-26 15:02:58 +0100 | [diff] [blame] | 1468 | /* |
| 1469 | * Change STA power saving mode only at the end of a frame |
| 1470 | * exchange sequence. |
| 1471 | */ |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1472 | if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) && |
Arik Nemtsov | d057e5a | 2011-01-31 22:29:13 +0200 | [diff] [blame] | 1473 | !ieee80211_has_morefrags(hdr->frame_control) && |
Christian Lamparter | 4cfda47 | 2010-12-27 23:21:26 +0100 | [diff] [blame] | 1474 | !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) && |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1475 | (rx->sdata->vif.type == NL80211_IFTYPE_AP || |
Johannes Berg | b4ba544 | 2014-01-24 14:41:44 +0100 | [diff] [blame] | 1476 | rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) && |
| 1477 | /* PM bit is only checked in frames where it isn't reserved, |
| 1478 | * in AP mode it's reserved in non-bufferable management frames |
| 1479 | * (cf. IEEE 802.11-2012 8.2.4.1.7 Power Management field) |
| 1480 | */ |
| 1481 | (!ieee80211_is_mgmt(hdr->frame_control) || |
| 1482 | ieee80211_is_bufferable_mmpdu(hdr->frame_control))) { |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1483 | if (test_sta_flag(sta, WLAN_STA_PS_STA)) { |
Johannes Berg | b4ba544 | 2014-01-24 14:41:44 +0100 | [diff] [blame] | 1484 | if (!ieee80211_has_pm(hdr->frame_control)) |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 1485 | sta_ps_end(sta); |
Johannes Berg | 72eaa43 | 2008-11-26 15:02:58 +0100 | [diff] [blame] | 1486 | } else { |
| 1487 | if (ieee80211_has_pm(hdr->frame_control)) |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 1488 | sta_ps_start(sta); |
Johannes Berg | 72eaa43 | 2008-11-26 15:02:58 +0100 | [diff] [blame] | 1489 | } |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1490 | } |
| 1491 | |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 1492 | /* mesh power save support */ |
| 1493 | if (ieee80211_vif_is_mesh(&rx->sdata->vif)) |
| 1494 | ieee80211_mps_rx_h_sta_process(sta, hdr); |
| 1495 | |
Johannes Berg | 22403de | 2009-10-30 12:55:03 +0100 | [diff] [blame] | 1496 | /* |
| 1497 | * Drop (qos-)data::nullfunc frames silently, since they |
| 1498 | * are used only to control station power saving mode. |
| 1499 | */ |
| 1500 | if (ieee80211_is_nullfunc(hdr->frame_control) || |
| 1501 | ieee80211_is_qos_nullfunc(hdr->frame_control)) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1502 | I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc); |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 1503 | |
| 1504 | /* |
| 1505 | * If we receive a 4-addr nullfunc frame from a STA |
Johannes Berg | e7f4a94 | 2011-11-04 11:18:20 +0100 | [diff] [blame] | 1506 | * that was not moved to a 4-addr STA vlan yet send |
| 1507 | * the event to userspace and for older hostapd drop |
| 1508 | * the frame to the monitor interface. |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 1509 | */ |
| 1510 | if (ieee80211_has_a4(hdr->frame_control) && |
| 1511 | (rx->sdata->vif.type == NL80211_IFTYPE_AP || |
| 1512 | (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | e7f4a94 | 2011-11-04 11:18:20 +0100 | [diff] [blame] | 1513 | !rx->sdata->u.vlan.sta))) { |
| 1514 | if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT)) |
| 1515 | cfg80211_rx_unexpected_4addr_frame( |
| 1516 | rx->sdata->dev, sta->sta.addr, |
| 1517 | GFP_ATOMIC); |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 1518 | return RX_DROP_MONITOR; |
Johannes Berg | e7f4a94 | 2011-11-04 11:18:20 +0100 | [diff] [blame] | 1519 | } |
Johannes Berg | 22403de | 2009-10-30 12:55:03 +0100 | [diff] [blame] | 1520 | /* |
| 1521 | * Update counter and free packet here to avoid |
| 1522 | * counting this as a dropped packed. |
| 1523 | */ |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 1524 | sta->rx_stats.packets++; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1525 | dev_kfree_skb(rx->skb); |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1526 | return RX_QUEUED; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1527 | } |
| 1528 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1529 | return RX_CONTINUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1530 | } /* ieee80211_rx_h_sta_process */ |
| 1531 | |
Johan Almbladh | 86c228a | 2013-08-14 15:29:46 +0200 | [diff] [blame] | 1532 | static ieee80211_rx_result debug_noinline |
| 1533 | ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx) |
| 1534 | { |
| 1535 | struct sk_buff *skb = rx->skb; |
| 1536 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
| 1537 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 1538 | int keyidx; |
| 1539 | int hdrlen; |
| 1540 | ieee80211_rx_result result = RX_DROP_UNUSABLE; |
| 1541 | struct ieee80211_key *sta_ptk = NULL; |
| 1542 | int mmie_keyidx = -1; |
| 1543 | __le16 fc; |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 1544 | const struct ieee80211_cipher_scheme *cs = NULL; |
Johan Almbladh | 86c228a | 2013-08-14 15:29:46 +0200 | [diff] [blame] | 1545 | |
| 1546 | /* |
| 1547 | * Key selection 101 |
| 1548 | * |
| 1549 | * There are four types of keys: |
| 1550 | * - GTK (group keys) |
| 1551 | * - IGTK (group keys for management frames) |
| 1552 | * - PTK (pairwise keys) |
| 1553 | * - STK (station-to-station pairwise keys) |
| 1554 | * |
| 1555 | * When selecting a key, we have to distinguish between multicast |
| 1556 | * (including broadcast) and unicast frames, the latter can only |
| 1557 | * use PTKs and STKs while the former always use GTKs and IGTKs. |
| 1558 | * Unless, of course, actual WEP keys ("pre-RSNA") are used, then |
| 1559 | * unicast frames can also use key indices like GTKs. Hence, if we |
| 1560 | * don't have a PTK/STK we check the key index for a WEP key. |
| 1561 | * |
| 1562 | * Note that in a regular BSS, multicast frames are sent by the |
| 1563 | * AP only, associated stations unicast the frame to the AP first |
| 1564 | * which then multicasts it on their behalf. |
| 1565 | * |
| 1566 | * There is also a slight problem in IBSS mode: GTKs are negotiated |
| 1567 | * with each station, that is something we don't currently handle. |
| 1568 | * The spec seems to expect that one negotiates the same key with |
| 1569 | * every station but there's no such requirement; VLANs could be |
| 1570 | * possible. |
| 1571 | */ |
| 1572 | |
Johan Almbladh | 86c228a | 2013-08-14 15:29:46 +0200 | [diff] [blame] | 1573 | /* start without a key */ |
| 1574 | rx->key = NULL; |
Johan Almbladh | 86c228a | 2013-08-14 15:29:46 +0200 | [diff] [blame] | 1575 | fc = hdr->frame_control; |
| 1576 | |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 1577 | if (rx->sta) { |
| 1578 | int keyid = rx->sta->ptk_idx; |
| 1579 | |
| 1580 | if (ieee80211_has_protected(fc) && rx->sta->cipher_scheme) { |
| 1581 | cs = rx->sta->cipher_scheme; |
Johannes Berg | 2c61cf9 | 2016-03-17 15:02:55 +0200 | [diff] [blame] | 1582 | keyid = ieee80211_get_cs_keyid(cs, rx->skb); |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 1583 | if (unlikely(keyid < 0)) |
| 1584 | return RX_DROP_UNUSABLE; |
| 1585 | } |
| 1586 | sta_ptk = rcu_dereference(rx->sta->ptk[keyid]); |
| 1587 | } |
| 1588 | |
Johan Almbladh | 86c228a | 2013-08-14 15:29:46 +0200 | [diff] [blame] | 1589 | if (!ieee80211_has_protected(fc)) |
| 1590 | mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb); |
| 1591 | |
| 1592 | if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) { |
| 1593 | rx->key = sta_ptk; |
| 1594 | if ((status->flag & RX_FLAG_DECRYPTED) && |
| 1595 | (status->flag & RX_FLAG_IV_STRIPPED)) |
| 1596 | return RX_CONTINUE; |
| 1597 | /* Skip decryption if the frame is not protected. */ |
| 1598 | if (!ieee80211_has_protected(fc)) |
| 1599 | return RX_CONTINUE; |
| 1600 | } else if (mmie_keyidx >= 0) { |
| 1601 | /* Broadcast/multicast robust management frame / BIP */ |
| 1602 | if ((status->flag & RX_FLAG_DECRYPTED) && |
| 1603 | (status->flag & RX_FLAG_IV_STRIPPED)) |
| 1604 | return RX_CONTINUE; |
| 1605 | |
| 1606 | if (mmie_keyidx < NUM_DEFAULT_KEYS || |
| 1607 | mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) |
| 1608 | return RX_DROP_MONITOR; /* unexpected BIP keyidx */ |
| 1609 | if (rx->sta) |
| 1610 | rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]); |
| 1611 | if (!rx->key) |
| 1612 | rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]); |
| 1613 | } else if (!ieee80211_has_protected(fc)) { |
| 1614 | /* |
| 1615 | * The frame was not protected, so skip decryption. However, we |
| 1616 | * need to set rx->key if there is a key that could have been |
| 1617 | * used so that the frame may be dropped if encryption would |
| 1618 | * have been expected. |
| 1619 | */ |
| 1620 | struct ieee80211_key *key = NULL; |
| 1621 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
| 1622 | int i; |
| 1623 | |
| 1624 | if (ieee80211_is_mgmt(fc) && |
| 1625 | is_multicast_ether_addr(hdr->addr1) && |
| 1626 | (key = rcu_dereference(rx->sdata->default_mgmt_key))) |
| 1627 | rx->key = key; |
| 1628 | else { |
| 1629 | if (rx->sta) { |
| 1630 | for (i = 0; i < NUM_DEFAULT_KEYS; i++) { |
| 1631 | key = rcu_dereference(rx->sta->gtk[i]); |
| 1632 | if (key) |
| 1633 | break; |
| 1634 | } |
| 1635 | } |
| 1636 | if (!key) { |
| 1637 | for (i = 0; i < NUM_DEFAULT_KEYS; i++) { |
| 1638 | key = rcu_dereference(sdata->keys[i]); |
| 1639 | if (key) |
| 1640 | break; |
| 1641 | } |
| 1642 | } |
| 1643 | if (key) |
| 1644 | rx->key = key; |
| 1645 | } |
| 1646 | return RX_CONTINUE; |
| 1647 | } else { |
| 1648 | u8 keyid; |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 1649 | |
Johan Almbladh | 86c228a | 2013-08-14 15:29:46 +0200 | [diff] [blame] | 1650 | /* |
| 1651 | * The device doesn't give us the IV so we won't be |
| 1652 | * able to look up the key. That's ok though, we |
| 1653 | * don't need to decrypt the frame, we just won't |
| 1654 | * be able to keep statistics accurate. |
| 1655 | * Except for key threshold notifications, should |
| 1656 | * we somehow allow the driver to tell us which key |
| 1657 | * the hardware used if this flag is set? |
| 1658 | */ |
| 1659 | if ((status->flag & RX_FLAG_DECRYPTED) && |
| 1660 | (status->flag & RX_FLAG_IV_STRIPPED)) |
| 1661 | return RX_CONTINUE; |
| 1662 | |
| 1663 | hdrlen = ieee80211_hdrlen(fc); |
| 1664 | |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 1665 | if (cs) { |
Johannes Berg | 2c61cf9 | 2016-03-17 15:02:55 +0200 | [diff] [blame] | 1666 | keyidx = ieee80211_get_cs_keyid(cs, rx->skb); |
Johan Almbladh | 86c228a | 2013-08-14 15:29:46 +0200 | [diff] [blame] | 1667 | |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 1668 | if (unlikely(keyidx < 0)) |
| 1669 | return RX_DROP_UNUSABLE; |
| 1670 | } else { |
| 1671 | if (rx->skb->len < 8 + hdrlen) |
| 1672 | return RX_DROP_UNUSABLE; /* TODO: count this? */ |
| 1673 | /* |
| 1674 | * no need to call ieee80211_wep_get_keyidx, |
| 1675 | * it verifies a bunch of things we've done already |
| 1676 | */ |
| 1677 | skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1); |
| 1678 | keyidx = keyid >> 6; |
| 1679 | } |
Johan Almbladh | 86c228a | 2013-08-14 15:29:46 +0200 | [diff] [blame] | 1680 | |
| 1681 | /* check per-station GTK first, if multicast packet */ |
| 1682 | if (is_multicast_ether_addr(hdr->addr1) && rx->sta) |
| 1683 | rx->key = rcu_dereference(rx->sta->gtk[keyidx]); |
| 1684 | |
| 1685 | /* if not found, try default key */ |
| 1686 | if (!rx->key) { |
| 1687 | rx->key = rcu_dereference(rx->sdata->keys[keyidx]); |
| 1688 | |
| 1689 | /* |
| 1690 | * RSNA-protected unicast frames should always be |
| 1691 | * sent with pairwise or station-to-station keys, |
| 1692 | * but for WEP we allow using a key index as well. |
| 1693 | */ |
| 1694 | if (rx->key && |
| 1695 | rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 && |
| 1696 | rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 && |
| 1697 | !is_multicast_ether_addr(hdr->addr1)) |
| 1698 | rx->key = NULL; |
| 1699 | } |
| 1700 | } |
| 1701 | |
| 1702 | if (rx->key) { |
| 1703 | if (unlikely(rx->key->flags & KEY_FLAG_TAINTED)) |
| 1704 | return RX_DROP_MONITOR; |
| 1705 | |
Johan Almbladh | 86c228a | 2013-08-14 15:29:46 +0200 | [diff] [blame] | 1706 | /* TODO: add threshold stuff again */ |
| 1707 | } else { |
| 1708 | return RX_DROP_MONITOR; |
| 1709 | } |
| 1710 | |
| 1711 | switch (rx->key->conf.cipher) { |
| 1712 | case WLAN_CIPHER_SUITE_WEP40: |
| 1713 | case WLAN_CIPHER_SUITE_WEP104: |
| 1714 | result = ieee80211_crypto_wep_decrypt(rx); |
| 1715 | break; |
| 1716 | case WLAN_CIPHER_SUITE_TKIP: |
| 1717 | result = ieee80211_crypto_tkip_decrypt(rx); |
| 1718 | break; |
| 1719 | case WLAN_CIPHER_SUITE_CCMP: |
Jouni Malinen | 2b2ba0d | 2015-01-24 19:52:07 +0200 | [diff] [blame] | 1720 | result = ieee80211_crypto_ccmp_decrypt( |
| 1721 | rx, IEEE80211_CCMP_MIC_LEN); |
| 1722 | break; |
| 1723 | case WLAN_CIPHER_SUITE_CCMP_256: |
| 1724 | result = ieee80211_crypto_ccmp_decrypt( |
| 1725 | rx, IEEE80211_CCMP_256_MIC_LEN); |
Johan Almbladh | 86c228a | 2013-08-14 15:29:46 +0200 | [diff] [blame] | 1726 | break; |
| 1727 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 1728 | result = ieee80211_crypto_aes_cmac_decrypt(rx); |
| 1729 | break; |
Jouni Malinen | 56c52da | 2015-01-24 19:52:08 +0200 | [diff] [blame] | 1730 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
| 1731 | result = ieee80211_crypto_aes_cmac_256_decrypt(rx); |
| 1732 | break; |
Jouni Malinen | 8ade538 | 2015-01-24 19:52:09 +0200 | [diff] [blame] | 1733 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 1734 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
| 1735 | result = ieee80211_crypto_aes_gmac_decrypt(rx); |
| 1736 | break; |
Jouni Malinen | 00b9cfa | 2015-01-24 19:52:06 +0200 | [diff] [blame] | 1737 | case WLAN_CIPHER_SUITE_GCMP: |
| 1738 | case WLAN_CIPHER_SUITE_GCMP_256: |
| 1739 | result = ieee80211_crypto_gcmp_decrypt(rx); |
| 1740 | break; |
Johan Almbladh | 86c228a | 2013-08-14 15:29:46 +0200 | [diff] [blame] | 1741 | default: |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 1742 | result = ieee80211_crypto_hw_decrypt(rx); |
Johan Almbladh | 86c228a | 2013-08-14 15:29:46 +0200 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | /* the hdr variable is invalid after the decrypt handlers */ |
| 1746 | |
| 1747 | /* either the frame has been decrypted or will be dropped */ |
| 1748 | status->flag |= RX_FLAG_DECRYPTED; |
| 1749 | |
| 1750 | return result; |
| 1751 | } |
| 1752 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1753 | static inline struct ieee80211_fragment_entry * |
| 1754 | ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata, |
| 1755 | unsigned int frag, unsigned int seq, int rx_queue, |
| 1756 | struct sk_buff **skb) |
| 1757 | { |
| 1758 | struct ieee80211_fragment_entry *entry; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1759 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1760 | entry = &sdata->fragments[sdata->fragment_next++]; |
| 1761 | if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX) |
| 1762 | sdata->fragment_next = 0; |
| 1763 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 1764 | if (!skb_queue_empty(&entry->skb_list)) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1765 | __skb_queue_purge(&entry->skb_list); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1766 | |
| 1767 | __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */ |
| 1768 | *skb = NULL; |
| 1769 | entry->first_frag_time = jiffies; |
| 1770 | entry->seq = seq; |
| 1771 | entry->rx_queue = rx_queue; |
| 1772 | entry->last_frag = frag; |
Johannes Berg | 9acc54b | 2016-02-26 22:13:40 +0100 | [diff] [blame] | 1773 | entry->check_sequential_pn = false; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1774 | entry->extra_len = 0; |
| 1775 | |
| 1776 | return entry; |
| 1777 | } |
| 1778 | |
| 1779 | static inline struct ieee80211_fragment_entry * |
| 1780 | ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata, |
Harvey Harrison | b73d70a | 2008-07-15 18:44:12 -0700 | [diff] [blame] | 1781 | unsigned int frag, unsigned int seq, |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1782 | int rx_queue, struct ieee80211_hdr *hdr) |
| 1783 | { |
| 1784 | struct ieee80211_fragment_entry *entry; |
| 1785 | int i, idx; |
| 1786 | |
| 1787 | idx = sdata->fragment_next; |
| 1788 | for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) { |
| 1789 | struct ieee80211_hdr *f_hdr; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1790 | |
| 1791 | idx--; |
| 1792 | if (idx < 0) |
| 1793 | idx = IEEE80211_FRAGMENT_MAX - 1; |
| 1794 | |
| 1795 | entry = &sdata->fragments[idx]; |
| 1796 | if (skb_queue_empty(&entry->skb_list) || entry->seq != seq || |
| 1797 | entry->rx_queue != rx_queue || |
| 1798 | entry->last_frag + 1 != frag) |
| 1799 | continue; |
| 1800 | |
Harvey Harrison | b73d70a | 2008-07-15 18:44:12 -0700 | [diff] [blame] | 1801 | f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1802 | |
Harvey Harrison | b73d70a | 2008-07-15 18:44:12 -0700 | [diff] [blame] | 1803 | /* |
| 1804 | * Check ftype and addresses are equal, else check next fragment |
| 1805 | */ |
| 1806 | if (((hdr->frame_control ^ f_hdr->frame_control) & |
| 1807 | cpu_to_le16(IEEE80211_FCTL_FTYPE)) || |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 1808 | !ether_addr_equal(hdr->addr1, f_hdr->addr1) || |
| 1809 | !ether_addr_equal(hdr->addr2, f_hdr->addr2)) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1810 | continue; |
| 1811 | |
S.Çağlar Onur | ab46623 | 2008-02-14 17:36:47 +0200 | [diff] [blame] | 1812 | if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1813 | __skb_queue_purge(&entry->skb_list); |
| 1814 | continue; |
| 1815 | } |
| 1816 | return entry; |
| 1817 | } |
| 1818 | |
| 1819 | return NULL; |
| 1820 | } |
| 1821 | |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 1822 | static ieee80211_rx_result debug_noinline |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1823 | ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1824 | { |
| 1825 | struct ieee80211_hdr *hdr; |
| 1826 | u16 sc; |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1827 | __le16 fc; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1828 | unsigned int frag, seq; |
| 1829 | struct ieee80211_fragment_entry *entry; |
| 1830 | struct sk_buff *skb; |
Johannes Berg | 554891e | 2010-09-24 12:38:25 +0200 | [diff] [blame] | 1831 | struct ieee80211_rx_status *status; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1832 | |
Harvey Harrison | b73d70a | 2008-07-15 18:44:12 -0700 | [diff] [blame] | 1833 | hdr = (struct ieee80211_hdr *)rx->skb->data; |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1834 | fc = hdr->frame_control; |
Javier Cardona | f7fbf70 | 2012-10-25 11:10:18 -0700 | [diff] [blame] | 1835 | |
| 1836 | if (ieee80211_is_ctl(fc)) |
| 1837 | return RX_CONTINUE; |
| 1838 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1839 | sc = le16_to_cpu(hdr->seq_ctrl); |
| 1840 | frag = sc & IEEE80211_SCTL_FRAG; |
| 1841 | |
Johannes Berg | b8fff40 | 2014-11-03 13:57:46 +0100 | [diff] [blame] | 1842 | if (is_multicast_ether_addr(hdr->addr1)) { |
Johannes Berg | c206ca6 | 2015-04-22 20:47:28 +0200 | [diff] [blame] | 1843 | I802_DEBUG_INC(rx->local->dot11MulticastReceivedFrameCount); |
Andreas Müller | d025933 | 2014-12-12 12:11:11 +0100 | [diff] [blame] | 1844 | goto out_no_led; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1845 | } |
Johannes Berg | b8fff40 | 2014-11-03 13:57:46 +0100 | [diff] [blame] | 1846 | |
Andreas Müller | d025933 | 2014-12-12 12:11:11 +0100 | [diff] [blame] | 1847 | if (likely(!ieee80211_has_morefrags(fc) && frag == 0)) |
| 1848 | goto out; |
| 1849 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1850 | I802_DEBUG_INC(rx->local->rx_handlers_fragments); |
| 1851 | |
Zhu Yi | e3cf8b3f | 2010-03-29 17:35:07 +0800 | [diff] [blame] | 1852 | if (skb_linearize(rx->skb)) |
| 1853 | return RX_DROP_UNUSABLE; |
| 1854 | |
Abhijeet Kolekar | 058897a | 2010-05-11 11:22:11 -0700 | [diff] [blame] | 1855 | /* |
| 1856 | * skb_linearize() might change the skb->data and |
| 1857 | * previously cached variables (in this case, hdr) need to |
| 1858 | * be refreshed with the new data. |
| 1859 | */ |
| 1860 | hdr = (struct ieee80211_hdr *)rx->skb->data; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1861 | seq = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 1862 | |
| 1863 | if (frag == 0) { |
| 1864 | /* This is the first fragment of a new frame. */ |
| 1865 | entry = ieee80211_reassemble_add(rx->sdata, frag, seq, |
Johannes Berg | 9e26297 | 2011-07-07 18:45:03 +0200 | [diff] [blame] | 1866 | rx->seqno_idx, &(rx->skb)); |
Jouni Malinen | 2b2ba0d | 2015-01-24 19:52:07 +0200 | [diff] [blame] | 1867 | if (rx->key && |
| 1868 | (rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP || |
Johannes Berg | 9acc54b | 2016-02-26 22:13:40 +0100 | [diff] [blame] | 1869 | rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP_256 || |
| 1870 | rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP || |
| 1871 | rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP_256) && |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1872 | ieee80211_has_protected(fc)) { |
Johannes Berg | 9e26297 | 2011-07-07 18:45:03 +0200 | [diff] [blame] | 1873 | int queue = rx->security_idx; |
Johannes Berg | 9acc54b | 2016-02-26 22:13:40 +0100 | [diff] [blame] | 1874 | |
| 1875 | /* Store CCMP/GCMP PN so that we can verify that the |
| 1876 | * next fragment has a sequential PN value. |
| 1877 | */ |
| 1878 | entry->check_sequential_pn = true; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1879 | memcpy(entry->last_pn, |
Jouni Malinen | 9190252 | 2010-06-11 10:27:33 -0700 | [diff] [blame] | 1880 | rx->key->u.ccmp.rx_pn[queue], |
Johannes Berg | 4325f6c | 2013-05-08 13:09:08 +0200 | [diff] [blame] | 1881 | IEEE80211_CCMP_PN_LEN); |
Johannes Berg | 9acc54b | 2016-02-26 22:13:40 +0100 | [diff] [blame] | 1882 | BUILD_BUG_ON(offsetof(struct ieee80211_key, |
| 1883 | u.ccmp.rx_pn) != |
| 1884 | offsetof(struct ieee80211_key, |
| 1885 | u.gcmp.rx_pn)); |
| 1886 | BUILD_BUG_ON(sizeof(rx->key->u.ccmp.rx_pn[queue]) != |
| 1887 | sizeof(rx->key->u.gcmp.rx_pn[queue])); |
| 1888 | BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN != |
| 1889 | IEEE80211_GCMP_PN_LEN); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1890 | } |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1891 | return RX_QUEUED; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1892 | } |
| 1893 | |
| 1894 | /* This is a fragment for a frame that should already be pending in |
| 1895 | * fragment cache. Add this fragment to the end of the pending entry. |
| 1896 | */ |
Johannes Berg | 9e26297 | 2011-07-07 18:45:03 +0200 | [diff] [blame] | 1897 | entry = ieee80211_reassemble_find(rx->sdata, frag, seq, |
| 1898 | rx->seqno_idx, hdr); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1899 | if (!entry) { |
| 1900 | I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag); |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1901 | return RX_DROP_MONITOR; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1902 | } |
| 1903 | |
Johannes Berg | 9acc54b | 2016-02-26 22:13:40 +0100 | [diff] [blame] | 1904 | /* "The receiver shall discard MSDUs and MMPDUs whose constituent |
| 1905 | * MPDU PN values are not incrementing in steps of 1." |
| 1906 | * see IEEE P802.11-REVmc/D5.0, 12.5.3.4.4, item d (for CCMP) |
| 1907 | * and IEEE P802.11-REVmc/D5.0, 12.5.5.4.4, item d (for GCMP) |
| 1908 | */ |
| 1909 | if (entry->check_sequential_pn) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1910 | int i; |
Johannes Berg | 4325f6c | 2013-05-08 13:09:08 +0200 | [diff] [blame] | 1911 | u8 pn[IEEE80211_CCMP_PN_LEN], *rpn; |
Jouni Malinen | 9190252 | 2010-06-11 10:27:33 -0700 | [diff] [blame] | 1912 | int queue; |
Johannes Berg | 9acc54b | 2016-02-26 22:13:40 +0100 | [diff] [blame] | 1913 | |
Jouni Malinen | 2b2ba0d | 2015-01-24 19:52:07 +0200 | [diff] [blame] | 1914 | if (!rx->key || |
| 1915 | (rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP && |
Johannes Berg | 9acc54b | 2016-02-26 22:13:40 +0100 | [diff] [blame] | 1916 | rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP_256 && |
| 1917 | rx->key->conf.cipher != WLAN_CIPHER_SUITE_GCMP && |
| 1918 | rx->key->conf.cipher != WLAN_CIPHER_SUITE_GCMP_256)) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1919 | return RX_DROP_UNUSABLE; |
Johannes Berg | 4325f6c | 2013-05-08 13:09:08 +0200 | [diff] [blame] | 1920 | memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN); |
| 1921 | for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1922 | pn[i]++; |
| 1923 | if (pn[i]) |
| 1924 | break; |
| 1925 | } |
Johannes Berg | 9e26297 | 2011-07-07 18:45:03 +0200 | [diff] [blame] | 1926 | queue = rx->security_idx; |
Jouni Malinen | 9190252 | 2010-06-11 10:27:33 -0700 | [diff] [blame] | 1927 | rpn = rx->key->u.ccmp.rx_pn[queue]; |
Johannes Berg | 4325f6c | 2013-05-08 13:09:08 +0200 | [diff] [blame] | 1928 | if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN)) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1929 | return RX_DROP_UNUSABLE; |
Johannes Berg | 4325f6c | 2013-05-08 13:09:08 +0200 | [diff] [blame] | 1930 | memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1931 | } |
| 1932 | |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1933 | skb_pull(rx->skb, ieee80211_hdrlen(fc)); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1934 | __skb_queue_tail(&entry->skb_list, rx->skb); |
| 1935 | entry->last_frag = frag; |
| 1936 | entry->extra_len += rx->skb->len; |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1937 | if (ieee80211_has_morefrags(fc)) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1938 | rx->skb = NULL; |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1939 | return RX_QUEUED; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | rx->skb = __skb_dequeue(&entry->skb_list); |
| 1943 | if (skb_tailroom(rx->skb) < entry->extra_len) { |
Johannes Berg | f116043 | 2015-04-22 20:25:20 +0200 | [diff] [blame] | 1944 | I802_DEBUG_INC(rx->local->rx_expand_skb_head_defrag); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1945 | if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len, |
| 1946 | GFP_ATOMIC))) { |
| 1947 | I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag); |
| 1948 | __skb_queue_purge(&entry->skb_list); |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1949 | return RX_DROP_UNUSABLE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1950 | } |
| 1951 | } |
| 1952 | while ((skb = __skb_dequeue(&entry->skb_list))) { |
| 1953 | memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len); |
| 1954 | dev_kfree_skb(skb); |
| 1955 | } |
| 1956 | |
| 1957 | /* Complete frame has been reassembled - process it now */ |
Johannes Berg | 554891e | 2010-09-24 12:38:25 +0200 | [diff] [blame] | 1958 | status = IEEE80211_SKB_RXCB(rx->skb); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1959 | |
| 1960 | out: |
Andreas Müller | d025933 | 2014-12-12 12:11:11 +0100 | [diff] [blame] | 1961 | ieee80211_led_rx(rx->local); |
| 1962 | out_no_led: |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1963 | if (rx->sta) |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 1964 | rx->sta->rx_stats.packets++; |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1965 | return RX_CONTINUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1966 | } |
| 1967 | |
Johannes Berg | 1df332e | 2012-10-26 00:09:11 +0200 | [diff] [blame] | 1968 | static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1969 | { |
Johannes Berg | 1df332e | 2012-10-26 00:09:11 +0200 | [diff] [blame] | 1970 | if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED))) |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1971 | return -EACCES; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1972 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1973 | return 0; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1974 | } |
| 1975 | |
Johannes Berg | 1df332e | 2012-10-26 00:09:11 +0200 | [diff] [blame] | 1976 | static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1977 | { |
Johannes Berg | eb9fb5b8 | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 1978 | struct sk_buff *skb = rx->skb; |
| 1979 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
| 1980 | |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 1981 | /* |
Johannes Berg | 7848ba7 | 2007-09-14 11:10:25 -0400 | [diff] [blame] | 1982 | * Pass through unencrypted frames if the hardware has |
| 1983 | * decrypted them already. |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 1984 | */ |
Johannes Berg | eb9fb5b8 | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 1985 | if (status->flag & RX_FLAG_DECRYPTED) |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1986 | return 0; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1987 | |
| 1988 | /* Drop unencrypted frames if key is set. */ |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1989 | if (unlikely(!ieee80211_has_protected(fc) && |
| 1990 | !ieee80211_is_nullfunc(fc) && |
Johannes Berg | e8f4fb7 | 2015-03-20 11:37:36 +0100 | [diff] [blame] | 1991 | ieee80211_is_data(fc) && rx->key)) |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1992 | return -EACCES; |
Johannes Berg | bef5d1c | 2010-02-16 11:05:00 +0100 | [diff] [blame] | 1993 | |
| 1994 | return 0; |
| 1995 | } |
| 1996 | |
Johannes Berg | 1df332e | 2012-10-26 00:09:11 +0200 | [diff] [blame] | 1997 | static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx) |
Johannes Berg | bef5d1c | 2010-02-16 11:05:00 +0100 | [diff] [blame] | 1998 | { |
| 1999 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; |
Jouni Malinen | e3efca0 | 2010-03-28 22:31:15 -0700 | [diff] [blame] | 2000 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); |
Johannes Berg | bef5d1c | 2010-02-16 11:05:00 +0100 | [diff] [blame] | 2001 | __le16 fc = hdr->frame_control; |
Johannes Berg | bef5d1c | 2010-02-16 11:05:00 +0100 | [diff] [blame] | 2002 | |
Jouni Malinen | e3efca0 | 2010-03-28 22:31:15 -0700 | [diff] [blame] | 2003 | /* |
| 2004 | * Pass through unencrypted frames if the hardware has |
| 2005 | * decrypted them already. |
| 2006 | */ |
| 2007 | if (status->flag & RX_FLAG_DECRYPTED) |
| 2008 | return 0; |
Johannes Berg | bef5d1c | 2010-02-16 11:05:00 +0100 | [diff] [blame] | 2009 | |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 2010 | if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) { |
Jouni Malinen | d211e90 | 2010-03-28 22:29:52 -0700 | [diff] [blame] | 2011 | if (unlikely(!ieee80211_has_protected(fc) && |
| 2012 | ieee80211_is_unicast_robust_mgmt_frame(rx->skb) && |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 2013 | rx->key)) { |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 2014 | if (ieee80211_is_deauth(fc) || |
| 2015 | ieee80211_is_disassoc(fc)) |
| 2016 | cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev, |
| 2017 | rx->skb->data, |
| 2018 | rx->skb->len); |
Jouni Malinen | f2ca3ea | 2009-05-08 12:36:03 +0300 | [diff] [blame] | 2019 | return -EACCES; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 2020 | } |
Jouni Malinen | f2ca3ea | 2009-05-08 12:36:03 +0300 | [diff] [blame] | 2021 | /* BIP does not use Protected field, so need to check MMIE */ |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 2022 | if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) && |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 2023 | ieee80211_get_mmie_keyidx(rx->skb) < 0)) { |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 2024 | if (ieee80211_is_deauth(fc) || |
| 2025 | ieee80211_is_disassoc(fc)) |
| 2026 | cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev, |
| 2027 | rx->skb->data, |
| 2028 | rx->skb->len); |
Jouni Malinen | f2ca3ea | 2009-05-08 12:36:03 +0300 | [diff] [blame] | 2029 | return -EACCES; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 2030 | } |
Jouni Malinen | f2ca3ea | 2009-05-08 12:36:03 +0300 | [diff] [blame] | 2031 | /* |
| 2032 | * When using MFP, Action frames are not allowed prior to |
| 2033 | * having configured keys. |
| 2034 | */ |
| 2035 | if (unlikely(ieee80211_is_action(fc) && !rx->key && |
Johannes Berg | d8ca16d | 2014-01-23 16:20:29 +0100 | [diff] [blame] | 2036 | ieee80211_is_robust_mgmt_frame(rx->skb))) |
Jouni Malinen | f2ca3ea | 2009-05-08 12:36:03 +0300 | [diff] [blame] | 2037 | return -EACCES; |
| 2038 | } |
Johannes Berg | b3fc9c6 | 2008-04-13 10:12:47 +0200 | [diff] [blame] | 2039 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 2040 | return 0; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2041 | } |
| 2042 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 2043 | static int |
Felix Fietkau | 4114fa2 | 2011-04-12 19:15:22 +0200 | [diff] [blame] | 2044 | __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2045 | { |
Johannes Berg | eb9fb5b8 | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 2046 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
Felix Fietkau | f14543ee | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 2047 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; |
Felix Fietkau | fbb327c | 2011-01-18 15:48:48 +0100 | [diff] [blame] | 2048 | bool check_port_control = false; |
| 2049 | struct ethhdr *ehdr; |
| 2050 | int ret; |
Felix Fietkau | f14543ee | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 2051 | |
Felix Fietkau | 4114fa2 | 2011-04-12 19:15:22 +0200 | [diff] [blame] | 2052 | *port_control = false; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2053 | if (ieee80211_has_a4(hdr->frame_control) && |
| 2054 | sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta) |
Felix Fietkau | f14543ee | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 2055 | return -1; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2056 | |
Felix Fietkau | fbb327c | 2011-01-18 15:48:48 +0100 | [diff] [blame] | 2057 | if (sdata->vif.type == NL80211_IFTYPE_STATION && |
| 2058 | !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) { |
| 2059 | |
| 2060 | if (!sdata->u.mgd.use_4addr) |
| 2061 | return -1; |
| 2062 | else |
| 2063 | check_port_control = true; |
| 2064 | } |
| 2065 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2066 | if (is_multicast_ether_addr(hdr->addr1) && |
Felix Fietkau | fbb327c | 2011-01-18 15:48:48 +0100 | [diff] [blame] | 2067 | sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta) |
Felix Fietkau | f14543ee | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 2068 | return -1; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2069 | |
Felix Fietkau | fbb327c | 2011-01-18 15:48:48 +0100 | [diff] [blame] | 2070 | ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type); |
Felix Fietkau | 4114fa2 | 2011-04-12 19:15:22 +0200 | [diff] [blame] | 2071 | if (ret < 0) |
Felix Fietkau | fbb327c | 2011-01-18 15:48:48 +0100 | [diff] [blame] | 2072 | return ret; |
| 2073 | |
| 2074 | ehdr = (struct ethhdr *) rx->skb->data; |
Felix Fietkau | 4114fa2 | 2011-04-12 19:15:22 +0200 | [diff] [blame] | 2075 | if (ehdr->h_proto == rx->sdata->control_port_protocol) |
| 2076 | *port_control = true; |
| 2077 | else if (check_port_control) |
Felix Fietkau | fbb327c | 2011-01-18 15:48:48 +0100 | [diff] [blame] | 2078 | return -1; |
| 2079 | |
| 2080 | return 0; |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 2081 | } |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2082 | |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 2083 | /* |
| 2084 | * requires that rx->skb is a frame with ethernet header |
| 2085 | */ |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 2086 | static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc) |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 2087 | { |
Senthil Balasubramanian | c97c23e | 2008-05-28 23:15:32 +0530 | [diff] [blame] | 2088 | static const u8 pae_group_addr[ETH_ALEN] __aligned(2) |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 2089 | = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 }; |
| 2090 | struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data; |
| 2091 | |
| 2092 | /* |
| 2093 | * Allow EAPOL frames to us/the PAE group address regardless |
| 2094 | * of whether the frame was encrypted or not. |
| 2095 | */ |
Johannes Berg | a621fa4 | 2010-08-27 14:26:54 +0300 | [diff] [blame] | 2096 | if (ehdr->h_proto == rx->sdata->control_port_protocol && |
Joe Perches | 3bc7945 | 2012-05-08 18:56:53 +0000 | [diff] [blame] | 2097 | (ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) || |
| 2098 | ether_addr_equal(ehdr->h_dest, pae_group_addr))) |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 2099 | return true; |
| 2100 | |
| 2101 | if (ieee80211_802_1x_port_control(rx) || |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 2102 | ieee80211_drop_unencrypted(rx, fc)) |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 2103 | return false; |
| 2104 | |
| 2105 | return true; |
| 2106 | } |
| 2107 | |
| 2108 | /* |
| 2109 | * requires that rx->skb is a frame with ethernet header |
| 2110 | */ |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 2111 | static void |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 2112 | ieee80211_deliver_skb(struct ieee80211_rx_data *rx) |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 2113 | { |
Johannes Berg | eb9fb5b8 | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 2114 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
| 2115 | struct net_device *dev = sdata->dev; |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 2116 | struct sk_buff *skb, *xmit_skb; |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 2117 | struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data; |
| 2118 | struct sta_info *dsta; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2119 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 2120 | skb = rx->skb; |
| 2121 | xmit_skb = NULL; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2122 | |
Johannes Berg | 5a49051 | 2015-04-22 17:10:38 +0200 | [diff] [blame] | 2123 | ieee80211_rx_stats(dev, skb->len); |
| 2124 | |
Johannes Berg | de8f18d | 2016-03-31 20:02:03 +0300 | [diff] [blame] | 2125 | if (rx->sta) { |
| 2126 | /* The seqno index has the same property as needed |
| 2127 | * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS |
| 2128 | * for non-QoS-data frames. Here we know it's a data |
| 2129 | * frame, so count MSDUs. |
| 2130 | */ |
Johannes Berg | 0f9c5a6 | 2016-03-31 20:02:09 +0300 | [diff] [blame] | 2131 | u64_stats_update_begin(&rx->sta->rx_stats.syncp); |
Johannes Berg | de8f18d | 2016-03-31 20:02:03 +0300 | [diff] [blame] | 2132 | rx->sta->rx_stats.msdu[rx->seqno_idx]++; |
Johannes Berg | 0f9c5a6 | 2016-03-31 20:02:09 +0300 | [diff] [blame] | 2133 | u64_stats_update_end(&rx->sta->rx_stats.syncp); |
Johannes Berg | de8f18d | 2016-03-31 20:02:03 +0300 | [diff] [blame] | 2134 | } |
| 2135 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2136 | if ((sdata->vif.type == NL80211_IFTYPE_AP || |
| 2137 | sdata->vif.type == NL80211_IFTYPE_AP_VLAN) && |
Johannes Berg | 213cd11 | 2008-09-11 00:01:54 +0200 | [diff] [blame] | 2138 | !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) && |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2139 | (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) { |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 2140 | if (is_multicast_ether_addr(ehdr->h_dest)) { |
| 2141 | /* |
| 2142 | * send multicast frames both to higher layers in |
| 2143 | * local net stack and back to the wireless medium |
| 2144 | */ |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 2145 | xmit_skb = skb_copy(skb, GFP_ATOMIC); |
Joe Perches | e87cc47 | 2012-05-13 21:56:26 +0000 | [diff] [blame] | 2146 | if (!xmit_skb) |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2147 | net_info_ratelimited("%s: failed to clone multicast frame\n", |
Joe Perches | e87cc47 | 2012-05-13 21:56:26 +0000 | [diff] [blame] | 2148 | dev->name); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2149 | } else { |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 2150 | dsta = sta_info_get(sdata, skb->data); |
| 2151 | if (dsta) { |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 2152 | /* |
| 2153 | * The destination station is associated to |
| 2154 | * this AP (in this VLAN), so send the frame |
| 2155 | * directly to it and do not pass it to local |
| 2156 | * net stack. |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2157 | */ |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 2158 | xmit_skb = skb; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2159 | skb = NULL; |
| 2160 | } |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2161 | } |
| 2162 | } |
| 2163 | |
Kalle Valo | 59d9cb0 | 2009-12-17 13:54:57 +0100 | [diff] [blame] | 2164 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
Johannes Berg | 9e890a1f | 2013-12-04 09:16:31 +0100 | [diff] [blame] | 2165 | if (skb) { |
| 2166 | /* 'align' will only take the values 0 or 2 here since all |
| 2167 | * frames are required to be aligned to 2-byte boundaries |
| 2168 | * when being passed to mac80211; the code here works just |
| 2169 | * as well if that isn't true, but mac80211 assumes it can |
| 2170 | * access fields as 2-byte aligned (e.g. for ether_addr_equal) |
Johannes Berg | d1c3a37 | 2009-01-07 00:26:10 +0100 | [diff] [blame] | 2171 | */ |
Johannes Berg | 9e890a1f | 2013-12-04 09:16:31 +0100 | [diff] [blame] | 2172 | int align; |
| 2173 | |
| 2174 | align = (unsigned long)(skb->data + sizeof(struct ethhdr)) & 3; |
Johannes Berg | d1c3a37 | 2009-01-07 00:26:10 +0100 | [diff] [blame] | 2175 | if (align) { |
| 2176 | if (WARN_ON(skb_headroom(skb) < 3)) { |
| 2177 | dev_kfree_skb(skb); |
| 2178 | skb = NULL; |
| 2179 | } else { |
| 2180 | u8 *data = skb->data; |
Zhu Yi | 8ce0b58 | 2009-10-28 13:13:52 -0700 | [diff] [blame] | 2181 | size_t len = skb_headlen(skb); |
| 2182 | skb->data -= align; |
| 2183 | memmove(skb->data, data, len); |
| 2184 | skb_set_tail_pointer(skb, len); |
Johannes Berg | d1c3a37 | 2009-01-07 00:26:10 +0100 | [diff] [blame] | 2185 | } |
| 2186 | } |
Johannes Berg | 9e890a1f | 2013-12-04 09:16:31 +0100 | [diff] [blame] | 2187 | } |
Johannes Berg | d1c3a37 | 2009-01-07 00:26:10 +0100 | [diff] [blame] | 2188 | #endif |
| 2189 | |
Johannes Berg | 9e890a1f | 2013-12-04 09:16:31 +0100 | [diff] [blame] | 2190 | if (skb) { |
| 2191 | /* deliver to local stack */ |
| 2192 | skb->protocol = eth_type_trans(skb, dev); |
| 2193 | memset(skb->cb, 0, sizeof(skb->cb)); |
Johannes Berg | af9f9b2 | 2015-06-11 16:02:32 +0200 | [diff] [blame] | 2194 | if (rx->napi) |
| 2195 | napi_gro_receive(rx->napi, skb); |
Johannes Berg | 06d181a | 2014-02-04 20:51:09 +0100 | [diff] [blame] | 2196 | else |
| 2197 | netif_receive_skb(skb); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2198 | } |
| 2199 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 2200 | if (xmit_skb) { |
Helmut Schaa | aef6c92 | 2011-12-21 09:11:35 +0100 | [diff] [blame] | 2201 | /* |
| 2202 | * Send to wireless media and increase priority by 256 to |
| 2203 | * keep the received priority instead of reclassifying |
| 2204 | * the frame (see cfg80211_classify8021d). |
| 2205 | */ |
| 2206 | xmit_skb->priority += 256; |
YOSHIFUJI Hideaki | f831e90 | 2007-12-12 03:54:23 +0900 | [diff] [blame] | 2207 | xmit_skb->protocol = htons(ETH_P_802_3); |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 2208 | skb_reset_network_header(xmit_skb); |
| 2209 | skb_reset_mac_header(xmit_skb); |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 2210 | dev_queue_xmit(xmit_skb); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2211 | } |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 2212 | } |
| 2213 | |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 2214 | static ieee80211_rx_result debug_noinline |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 2215 | ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx) |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 2216 | { |
Johannes Berg | eb9fb5b8 | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 2217 | struct net_device *dev = rx->sdata->dev; |
Zhu Yi | eaf85ca | 2009-12-01 10:18:37 +0800 | [diff] [blame] | 2218 | struct sk_buff *skb = rx->skb; |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 2219 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 2220 | __le16 fc = hdr->frame_control; |
Zhu Yi | eaf85ca | 2009-12-01 10:18:37 +0800 | [diff] [blame] | 2221 | struct sk_buff_head frame_list; |
Johannes Berg | 554891e | 2010-09-24 12:38:25 +0200 | [diff] [blame] | 2222 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 2223 | |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 2224 | if (unlikely(!ieee80211_is_data(fc))) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 2225 | return RX_CONTINUE; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 2226 | |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 2227 | if (unlikely(!ieee80211_is_data_present(fc))) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 2228 | return RX_DROP_MONITOR; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 2229 | |
Johannes Berg | 554891e | 2010-09-24 12:38:25 +0200 | [diff] [blame] | 2230 | if (!(status->rx_flags & IEEE80211_RX_AMSDU)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 2231 | return RX_CONTINUE; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 2232 | |
Zhu Yi | eaf85ca | 2009-12-01 10:18:37 +0800 | [diff] [blame] | 2233 | if (ieee80211_has_a4(hdr->frame_control) && |
| 2234 | rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN && |
| 2235 | !rx->sdata->u.vlan.sta) |
| 2236 | return RX_DROP_UNUSABLE; |
| 2237 | |
| 2238 | if (is_multicast_ether_addr(hdr->addr1) && |
| 2239 | ((rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN && |
| 2240 | rx->sdata->u.vlan.sta) || |
| 2241 | (rx->sdata->vif.type == NL80211_IFTYPE_STATION && |
| 2242 | rx->sdata->u.mgd.use_4addr))) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 2243 | return RX_DROP_UNUSABLE; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 2244 | |
| 2245 | skb->dev = dev; |
Zhu Yi | eaf85ca | 2009-12-01 10:18:37 +0800 | [diff] [blame] | 2246 | __skb_queue_head_init(&frame_list); |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 2247 | |
Zhu Yi | eaf85ca | 2009-12-01 10:18:37 +0800 | [diff] [blame] | 2248 | ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr, |
| 2249 | rx->sdata->vif.type, |
Yogesh Ashok Powar | 8b3beca | 2011-05-13 11:22:31 -0700 | [diff] [blame] | 2250 | rx->local->hw.extra_tx_headroom, true); |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 2251 | |
Zhu Yi | eaf85ca | 2009-12-01 10:18:37 +0800 | [diff] [blame] | 2252 | while (!skb_queue_empty(&frame_list)) { |
| 2253 | rx->skb = __skb_dequeue(&frame_list); |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 2254 | |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 2255 | if (!ieee80211_frame_allowed(rx, fc)) { |
Zhu Yi | eaf85ca | 2009-12-01 10:18:37 +0800 | [diff] [blame] | 2256 | dev_kfree_skb(rx->skb); |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 2257 | continue; |
| 2258 | } |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 2259 | |
| 2260 | ieee80211_deliver_skb(rx); |
| 2261 | } |
| 2262 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 2263 | return RX_QUEUED; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 2264 | } |
| 2265 | |
Ingo Molnar | bf94e17 | 2008-10-12 23:51:38 -0700 | [diff] [blame] | 2266 | #ifdef CONFIG_MAC80211_MESH |
Davide Pesavento | b0dee57 | 2008-09-27 17:29:12 +0200 | [diff] [blame] | 2267 | static ieee80211_rx_result |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 2268 | ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx) |
| 2269 | { |
Thomas Pedersen | 30789eb | 2011-11-24 17:15:26 -0800 | [diff] [blame] | 2270 | struct ieee80211_hdr *fwd_hdr, *hdr; |
| 2271 | struct ieee80211_tx_info *info; |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 2272 | struct ieee80211s_hdr *mesh_hdr; |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 2273 | struct sk_buff *skb = rx->skb, *fwd_skb; |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 2274 | struct ieee80211_local *local = rx->local; |
Johannes Berg | eb9fb5b8 | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 2275 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
Thomas Pedersen | 30789eb | 2011-11-24 17:15:26 -0800 | [diff] [blame] | 2276 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
Michal Kazior | cf44012 | 2016-01-25 14:43:24 +0100 | [diff] [blame] | 2277 | u16 ac, q, hdrlen; |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 2278 | |
| 2279 | hdr = (struct ieee80211_hdr *) skb->data; |
| 2280 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
Johannes Berg | 9b395bc | 2012-10-26 00:36:40 +0200 | [diff] [blame] | 2281 | |
| 2282 | /* make sure fixed part of mesh header is there, also checks skb len */ |
| 2283 | if (!pskb_may_pull(rx->skb, hdrlen + 6)) |
| 2284 | return RX_DROP_MONITOR; |
| 2285 | |
| 2286 | mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen); |
| 2287 | |
| 2288 | /* make sure full mesh header is there, also checks skb len */ |
| 2289 | if (!pskb_may_pull(rx->skb, |
| 2290 | hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr))) |
| 2291 | return RX_DROP_MONITOR; |
| 2292 | |
| 2293 | /* reload pointers */ |
| 2294 | hdr = (struct ieee80211_hdr *) skb->data; |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 2295 | mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen); |
| 2296 | |
Bob Copeland | d0c2211 | 2015-03-02 14:28:52 -0500 | [diff] [blame] | 2297 | if (ieee80211_drop_unencrypted(rx, hdr->frame_control)) |
| 2298 | return RX_DROP_MONITOR; |
| 2299 | |
Thomas Pedersen | 2157fdd | 2011-09-01 12:32:14 -0700 | [diff] [blame] | 2300 | /* frame is in RMC, don't forward */ |
| 2301 | if (ieee80211_is_data(hdr->frame_control) && |
| 2302 | is_multicast_ether_addr(hdr->addr1) && |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 2303 | mesh_rmc_check(rx->sdata, hdr->addr3, mesh_hdr)) |
Thomas Pedersen | 2157fdd | 2011-09-01 12:32:14 -0700 | [diff] [blame] | 2304 | return RX_DROP_MONITOR; |
| 2305 | |
Johannes Berg | 5c90067 | 2015-04-22 14:48:34 +0200 | [diff] [blame] | 2306 | if (!ieee80211_is_data(hdr->frame_control)) |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 2307 | return RX_CONTINUE; |
| 2308 | |
| 2309 | if (!mesh_hdr->ttl) |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 2310 | return RX_DROP_MONITOR; |
| 2311 | |
Javier Cardona | 43b7b31 | 2009-10-15 18:10:51 -0700 | [diff] [blame] | 2312 | if (mesh_hdr->flags & MESH_FLAGS_AE) { |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 2313 | struct mesh_path *mppath; |
Javier Cardona | 43b7b31 | 2009-10-15 18:10:51 -0700 | [diff] [blame] | 2314 | char *proxied_addr; |
| 2315 | char *mpp_addr; |
| 2316 | |
| 2317 | if (is_multicast_ether_addr(hdr->addr1)) { |
| 2318 | mpp_addr = hdr->addr3; |
| 2319 | proxied_addr = mesh_hdr->eaddr1; |
Johannes Berg | 9b395bc | 2012-10-26 00:36:40 +0200 | [diff] [blame] | 2320 | } else if (mesh_hdr->flags & MESH_FLAGS_AE_A5_A6) { |
| 2321 | /* has_a4 already checked in ieee80211_rx_mesh_check */ |
Javier Cardona | 43b7b31 | 2009-10-15 18:10:51 -0700 | [diff] [blame] | 2322 | mpp_addr = hdr->addr4; |
| 2323 | proxied_addr = mesh_hdr->eaddr2; |
Johannes Berg | 9b395bc | 2012-10-26 00:36:40 +0200 | [diff] [blame] | 2324 | } else { |
| 2325 | return RX_DROP_MONITOR; |
Javier Cardona | 43b7b31 | 2009-10-15 18:10:51 -0700 | [diff] [blame] | 2326 | } |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 2327 | |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 2328 | rcu_read_lock(); |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 2329 | mppath = mpp_path_lookup(sdata, proxied_addr); |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 2330 | if (!mppath) { |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 2331 | mpp_path_add(sdata, proxied_addr, mpp_addr); |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 2332 | } else { |
| 2333 | spin_lock_bh(&mppath->state_lock); |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2334 | if (!ether_addr_equal(mppath->mpp, mpp_addr)) |
Javier Cardona | 43b7b31 | 2009-10-15 18:10:51 -0700 | [diff] [blame] | 2335 | memcpy(mppath->mpp, mpp_addr, ETH_ALEN); |
Henning Rogge | ab1c790 | 2016-02-03 13:58:37 +0100 | [diff] [blame] | 2336 | mppath->exp_time = jiffies; |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 2337 | spin_unlock_bh(&mppath->state_lock); |
| 2338 | } |
| 2339 | rcu_read_unlock(); |
| 2340 | } |
| 2341 | |
Javier Cardona | 3c5772a | 2009-08-10 12:15:48 -0700 | [diff] [blame] | 2342 | /* Frame has reached destination. Don't forward */ |
| 2343 | if (!is_multicast_ether_addr(hdr->addr1) && |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2344 | ether_addr_equal(sdata->vif.addr, hdr->addr3)) |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 2345 | return RX_CONTINUE; |
| 2346 | |
Michal Kazior | cf44012 | 2016-01-25 14:43:24 +0100 | [diff] [blame] | 2347 | ac = ieee80211_select_queue_80211(sdata, skb, hdr); |
| 2348 | q = sdata->vif.hw_queue[ac]; |
Thomas Pedersen | d3c1597 | 2011-11-24 17:15:23 -0800 | [diff] [blame] | 2349 | if (ieee80211_queue_stopped(&local->hw, q)) { |
Thomas Pedersen | 30789eb | 2011-11-24 17:15:26 -0800 | [diff] [blame] | 2350 | IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion); |
Thomas Pedersen | d3c1597 | 2011-11-24 17:15:23 -0800 | [diff] [blame] | 2351 | return RX_DROP_MONITOR; |
| 2352 | } |
| 2353 | skb_set_queue_mapping(skb, q); |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 2354 | |
Thomas Pedersen | 30789eb | 2011-11-24 17:15:26 -0800 | [diff] [blame] | 2355 | if (!--mesh_hdr->ttl) { |
| 2356 | IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_ttl); |
Javier Cardona | 2ac64cd | 2012-10-24 12:43:31 -0700 | [diff] [blame] | 2357 | goto out; |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 2358 | } |
| 2359 | |
Chun-Yeow Yeoh | d665508 | 2012-03-02 02:03:19 +0800 | [diff] [blame] | 2360 | if (!ifmsh->mshcfg.dot11MeshForwarding) |
| 2361 | goto out; |
| 2362 | |
Thomas Pedersen | 30789eb | 2011-11-24 17:15:26 -0800 | [diff] [blame] | 2363 | fwd_skb = skb_copy(skb, GFP_ATOMIC); |
| 2364 | if (!fwd_skb) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2365 | net_info_ratelimited("%s: failed to clone mesh frame\n", |
Joe Perches | e87cc47 | 2012-05-13 21:56:26 +0000 | [diff] [blame] | 2366 | sdata->name); |
Thomas Pedersen | 30789eb | 2011-11-24 17:15:26 -0800 | [diff] [blame] | 2367 | goto out; |
| 2368 | } |
| 2369 | |
| 2370 | fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data; |
Thomas Pedersen | 9d6d6f4 | 2013-04-08 11:06:12 -0700 | [diff] [blame] | 2371 | fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY); |
Thomas Pedersen | 30789eb | 2011-11-24 17:15:26 -0800 | [diff] [blame] | 2372 | info = IEEE80211_SKB_CB(fwd_skb); |
| 2373 | memset(info, 0, sizeof(*info)); |
| 2374 | info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING; |
| 2375 | info->control.vif = &rx->sdata->vif; |
| 2376 | info->control.jiffies = jiffies; |
| 2377 | if (is_multicast_ether_addr(fwd_hdr->addr1)) { |
| 2378 | IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast); |
| 2379 | memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN); |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 2380 | /* update power mode indication when forwarding */ |
| 2381 | ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr); |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 2382 | } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) { |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 2383 | /* mesh power mode flags updated in mesh_nexthop_lookup */ |
Thomas Pedersen | 30789eb | 2011-11-24 17:15:26 -0800 | [diff] [blame] | 2384 | IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast); |
| 2385 | } else { |
| 2386 | /* unable to resolve next hop */ |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 2387 | mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl, |
Chun-Yeow Yeoh | f63f842 | 2013-11-13 15:39:12 +0800 | [diff] [blame] | 2388 | fwd_hdr->addr3, 0, |
| 2389 | WLAN_REASON_MESH_PATH_NOFORWARD, |
| 2390 | fwd_hdr->addr2); |
Thomas Pedersen | 30789eb | 2011-11-24 17:15:26 -0800 | [diff] [blame] | 2391 | IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route); |
Jesper Juhl | 74b8cc3 | 2012-01-14 21:52:17 +0100 | [diff] [blame] | 2392 | kfree_skb(fwd_skb); |
Thomas Pedersen | 30789eb | 2011-11-24 17:15:26 -0800 | [diff] [blame] | 2393 | return RX_DROP_MONITOR; |
| 2394 | } |
| 2395 | |
| 2396 | IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames); |
| 2397 | ieee80211_add_pending_skb(local, fwd_skb); |
Johannes Berg | b51aff0 | 2010-12-22 10:15:07 +0100 | [diff] [blame] | 2398 | out: |
Johannes Berg | df14046 | 2015-04-22 14:40:58 +0200 | [diff] [blame] | 2399 | if (is_multicast_ether_addr(hdr->addr1)) |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 2400 | return RX_CONTINUE; |
Johannes Berg | df14046 | 2015-04-22 14:40:58 +0200 | [diff] [blame] | 2401 | return RX_DROP_MONITOR; |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 2402 | } |
Ingo Molnar | bf94e17 | 2008-10-12 23:51:38 -0700 | [diff] [blame] | 2403 | #endif |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 2404 | |
| 2405 | static ieee80211_rx_result debug_noinline |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 2406 | ieee80211_rx_h_data(struct ieee80211_rx_data *rx) |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 2407 | { |
Johannes Berg | eb9fb5b8 | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 2408 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
Vivek Natarajan | e15276a | 2010-02-08 17:47:01 +0530 | [diff] [blame] | 2409 | struct ieee80211_local *local = rx->local; |
Johannes Berg | eb9fb5b8 | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 2410 | struct net_device *dev = sdata->dev; |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 2411 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; |
| 2412 | __le16 fc = hdr->frame_control; |
Felix Fietkau | 4114fa2 | 2011-04-12 19:15:22 +0200 | [diff] [blame] | 2413 | bool port_control; |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 2414 | int err; |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 2415 | |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 2416 | if (unlikely(!ieee80211_is_data(hdr->frame_control))) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 2417 | return RX_CONTINUE; |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 2418 | |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 2419 | if (unlikely(!ieee80211_is_data_present(hdr->frame_control))) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 2420 | return RX_DROP_MONITOR; |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 2421 | |
Felix Fietkau | f14543ee | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 2422 | /* |
Johannes Berg | e7f4a94 | 2011-11-04 11:18:20 +0100 | [diff] [blame] | 2423 | * Send unexpected-4addr-frame event to hostapd. For older versions, |
| 2424 | * also drop the frame to cooked monitor interfaces. |
Felix Fietkau | f14543ee | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 2425 | */ |
| 2426 | if (ieee80211_has_a4(hdr->frame_control) && |
Johannes Berg | e7f4a94 | 2011-11-04 11:18:20 +0100 | [diff] [blame] | 2427 | sdata->vif.type == NL80211_IFTYPE_AP) { |
| 2428 | if (rx->sta && |
| 2429 | !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT)) |
| 2430 | cfg80211_rx_unexpected_4addr_frame( |
| 2431 | rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC); |
Felix Fietkau | f14543ee | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 2432 | return RX_DROP_MONITOR; |
Johannes Berg | e7f4a94 | 2011-11-04 11:18:20 +0100 | [diff] [blame] | 2433 | } |
Felix Fietkau | f14543ee | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 2434 | |
Felix Fietkau | 4114fa2 | 2011-04-12 19:15:22 +0200 | [diff] [blame] | 2435 | err = __ieee80211_data_to_8023(rx, &port_control); |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 2436 | if (unlikely(err)) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 2437 | return RX_DROP_UNUSABLE; |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 2438 | |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 2439 | if (!ieee80211_frame_allowed(rx, fc)) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 2440 | return RX_DROP_MONITOR; |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 2441 | |
Arik Nemtsov | 8a4d32f | 2014-11-09 18:50:20 +0200 | [diff] [blame] | 2442 | /* directly handle TDLS channel switch requests/responses */ |
| 2443 | if (unlikely(((struct ethhdr *)rx->skb->data)->h_proto == |
| 2444 | cpu_to_be16(ETH_P_TDLS))) { |
| 2445 | struct ieee80211_tdls_data *tf = (void *)rx->skb->data; |
| 2446 | |
| 2447 | if (pskb_may_pull(rx->skb, |
| 2448 | offsetof(struct ieee80211_tdls_data, u)) && |
| 2449 | tf->payload_type == WLAN_TDLS_SNAP_RFTYPE && |
| 2450 | tf->category == WLAN_CATEGORY_TDLS && |
| 2451 | (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST || |
| 2452 | tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) { |
Arik Nemtsov | c8ff71e | 2015-07-08 15:41:45 +0300 | [diff] [blame] | 2453 | skb_queue_tail(&local->skb_queue_tdls_chsw, rx->skb); |
| 2454 | schedule_work(&local->tdls_chsw_work); |
Arik Nemtsov | 8a4d32f | 2014-11-09 18:50:20 +0200 | [diff] [blame] | 2455 | if (rx->sta) |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 2456 | rx->sta->rx_stats.packets++; |
Arik Nemtsov | 8a4d32f | 2014-11-09 18:50:20 +0200 | [diff] [blame] | 2457 | |
| 2458 | return RX_QUEUED; |
| 2459 | } |
| 2460 | } |
| 2461 | |
Felix Fietkau | 4114fa2 | 2011-04-12 19:15:22 +0200 | [diff] [blame] | 2462 | if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN && |
| 2463 | unlikely(port_control) && sdata->bss) { |
| 2464 | sdata = container_of(sdata->bss, struct ieee80211_sub_if_data, |
| 2465 | u.ap); |
| 2466 | dev = sdata->dev; |
| 2467 | rx->sdata = sdata; |
| 2468 | } |
| 2469 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 2470 | rx->skb->dev = dev; |
| 2471 | |
Johannes Berg | 602fae4 | 2016-03-17 15:02:52 +0200 | [diff] [blame] | 2472 | if (!ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) && |
| 2473 | local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 && |
Rajkumar Manoharan | 8c99f69 | 2011-02-02 22:57:53 +0530 | [diff] [blame] | 2474 | !is_multicast_ether_addr( |
| 2475 | ((struct ethhdr *)rx->skb->data)->h_dest) && |
| 2476 | (!local->scanning && |
Johannes Berg | 602fae4 | 2016-03-17 15:02:52 +0200 | [diff] [blame] | 2477 | !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))) |
| 2478 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 2479 | msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout)); |
Vivek Natarajan | e15276a | 2010-02-08 17:47:01 +0530 | [diff] [blame] | 2480 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 2481 | ieee80211_deliver_skb(rx); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2482 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 2483 | return RX_QUEUED; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2484 | } |
| 2485 | |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 2486 | static ieee80211_rx_result debug_noinline |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 2487 | ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames) |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 2488 | { |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 2489 | struct sk_buff *skb = rx->skb; |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 2490 | struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data; |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 2491 | struct tid_ampdu_rx *tid_agg_rx; |
| 2492 | u16 start_seq_num; |
| 2493 | u16 tid; |
| 2494 | |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 2495 | if (likely(!ieee80211_is_ctl(bar->frame_control))) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 2496 | return RX_CONTINUE; |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 2497 | |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 2498 | if (ieee80211_is_back_req(bar->frame_control)) { |
Johannes Berg | 8ae5977 | 2010-05-30 14:52:58 +0200 | [diff] [blame] | 2499 | struct { |
| 2500 | __le16 control, start_seq_num; |
| 2501 | } __packed bar_data; |
Emmanuel Grumbach | 6382246 | 2015-04-20 22:53:37 +0300 | [diff] [blame] | 2502 | struct ieee80211_event event = { |
| 2503 | .type = BAR_RX_EVENT, |
| 2504 | }; |
Johannes Berg | 8ae5977 | 2010-05-30 14:52:58 +0200 | [diff] [blame] | 2505 | |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 2506 | if (!rx->sta) |
Johannes Berg | a02ae75 | 2009-11-16 12:00:40 +0100 | [diff] [blame] | 2507 | return RX_DROP_MONITOR; |
Johannes Berg | 8ae5977 | 2010-05-30 14:52:58 +0200 | [diff] [blame] | 2508 | |
| 2509 | if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control), |
| 2510 | &bar_data, sizeof(bar_data))) |
| 2511 | return RX_DROP_MONITOR; |
| 2512 | |
Johannes Berg | 8ae5977 | 2010-05-30 14:52:58 +0200 | [diff] [blame] | 2513 | tid = le16_to_cpu(bar_data.control) >> 12; |
Johannes Berg | a87f736 | 2010-06-10 10:21:38 +0200 | [diff] [blame] | 2514 | |
| 2515 | tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]); |
| 2516 | if (!tid_agg_rx) |
Johannes Berg | a02ae75 | 2009-11-16 12:00:40 +0100 | [diff] [blame] | 2517 | return RX_DROP_MONITOR; |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 2518 | |
Johannes Berg | 8ae5977 | 2010-05-30 14:52:58 +0200 | [diff] [blame] | 2519 | start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4; |
Emmanuel Grumbach | 6382246 | 2015-04-20 22:53:37 +0300 | [diff] [blame] | 2520 | event.u.ba.tid = tid; |
| 2521 | event.u.ba.ssn = start_seq_num; |
| 2522 | event.u.ba.sta = &rx->sta->sta; |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 2523 | |
| 2524 | /* reset session timer */ |
Johannes Berg | 20ad19d | 2009-02-10 21:25:45 +0100 | [diff] [blame] | 2525 | if (tid_agg_rx->timeout) |
| 2526 | mod_timer(&tid_agg_rx->session_timer, |
| 2527 | TU_TO_EXP_TIME(tid_agg_rx->timeout)); |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 2528 | |
Johannes Berg | dd31857 | 2010-11-29 11:09:16 +0100 | [diff] [blame] | 2529 | spin_lock(&tid_agg_rx->reorder_lock); |
Johannes Berg | a02ae75 | 2009-11-16 12:00:40 +0100 | [diff] [blame] | 2530 | /* release stored frames up to start of BAR */ |
Johannes Berg | d3b2fb5 | 2012-06-22 12:48:38 +0200 | [diff] [blame] | 2531 | ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx, |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 2532 | start_seq_num, frames); |
Johannes Berg | dd31857 | 2010-11-29 11:09:16 +0100 | [diff] [blame] | 2533 | spin_unlock(&tid_agg_rx->reorder_lock); |
| 2534 | |
Emmanuel Grumbach | 6382246 | 2015-04-20 22:53:37 +0300 | [diff] [blame] | 2535 | drv_event_callback(rx->local, rx->sdata, &event); |
| 2536 | |
Johannes Berg | a02ae75 | 2009-11-16 12:00:40 +0100 | [diff] [blame] | 2537 | kfree_skb(skb); |
| 2538 | return RX_QUEUED; |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 2539 | } |
| 2540 | |
Johannes Berg | 08daeca | 2010-05-30 14:53:43 +0200 | [diff] [blame] | 2541 | /* |
| 2542 | * After this point, we only want management frames, |
| 2543 | * so we can drop all remaining control frames to |
| 2544 | * cooked monitor interfaces. |
| 2545 | */ |
| 2546 | return RX_DROP_MONITOR; |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 2547 | } |
| 2548 | |
Jouni Malinen | f4f727a | 2009-01-10 11:46:53 +0200 | [diff] [blame] | 2549 | static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata, |
| 2550 | struct ieee80211_mgmt *mgmt, |
| 2551 | size_t len) |
Jouni Malinen | fea1473 | 2009-01-08 13:32:06 +0200 | [diff] [blame] | 2552 | { |
| 2553 | struct ieee80211_local *local = sdata->local; |
| 2554 | struct sk_buff *skb; |
| 2555 | struct ieee80211_mgmt *resp; |
| 2556 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2557 | if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) { |
Jouni Malinen | fea1473 | 2009-01-08 13:32:06 +0200 | [diff] [blame] | 2558 | /* Not to own unicast address */ |
| 2559 | return; |
| 2560 | } |
| 2561 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2562 | if (!ether_addr_equal(mgmt->sa, sdata->u.mgd.bssid) || |
| 2563 | !ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) { |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2564 | /* Not from the current AP or not associated yet. */ |
Jouni Malinen | fea1473 | 2009-01-08 13:32:06 +0200 | [diff] [blame] | 2565 | return; |
| 2566 | } |
| 2567 | |
| 2568 | if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) { |
| 2569 | /* Too short SA Query request frame */ |
| 2570 | return; |
| 2571 | } |
| 2572 | |
| 2573 | skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom); |
| 2574 | if (skb == NULL) |
| 2575 | return; |
| 2576 | |
| 2577 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 2578 | resp = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 2579 | memset(resp, 0, 24); |
| 2580 | memcpy(resp->da, mgmt->sa, ETH_ALEN); |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 2581 | memcpy(resp->sa, sdata->vif.addr, ETH_ALEN); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2582 | memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN); |
Jouni Malinen | fea1473 | 2009-01-08 13:32:06 +0200 | [diff] [blame] | 2583 | resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 2584 | IEEE80211_STYPE_ACTION); |
| 2585 | skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query)); |
| 2586 | resp->u.action.category = WLAN_CATEGORY_SA_QUERY; |
| 2587 | resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE; |
| 2588 | memcpy(resp->u.action.u.sa_query.trans_id, |
| 2589 | mgmt->u.action.u.sa_query.trans_id, |
| 2590 | WLAN_SA_QUERY_TR_ID_LEN); |
| 2591 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 2592 | ieee80211_tx_skb(sdata, skb); |
Jouni Malinen | fea1473 | 2009-01-08 13:32:06 +0200 | [diff] [blame] | 2593 | } |
| 2594 | |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 2595 | static ieee80211_rx_result debug_noinline |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2596 | ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx) |
| 2597 | { |
| 2598 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data; |
Johannes Berg | 554891e | 2010-09-24 12:38:25 +0200 | [diff] [blame] | 2599 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2600 | |
| 2601 | /* |
| 2602 | * From here on, look only at management frames. |
| 2603 | * Data and control frames are already handled, |
| 2604 | * and unknown (reserved) frames are useless. |
| 2605 | */ |
| 2606 | if (rx->skb->len < 24) |
| 2607 | return RX_DROP_MONITOR; |
| 2608 | |
| 2609 | if (!ieee80211_is_mgmt(mgmt->frame_control)) |
| 2610 | return RX_DROP_MONITOR; |
| 2611 | |
Johannes Berg | ee97192 | 2011-11-04 11:18:18 +0100 | [diff] [blame] | 2612 | if (rx->sdata->vif.type == NL80211_IFTYPE_AP && |
| 2613 | ieee80211_is_beacon(mgmt->frame_control) && |
| 2614 | !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) { |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 2615 | int sig = 0; |
| 2616 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2617 | if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM)) |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 2618 | sig = status->signal; |
| 2619 | |
Johannes Berg | ee97192 | 2011-11-04 11:18:18 +0100 | [diff] [blame] | 2620 | cfg80211_report_obss_beacon(rx->local->hw.wiphy, |
| 2621 | rx->skb->data, rx->skb->len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 2622 | status->freq, sig); |
Johannes Berg | ee97192 | 2011-11-04 11:18:18 +0100 | [diff] [blame] | 2623 | rx->flags |= IEEE80211_RX_BEACON_REPORTED; |
| 2624 | } |
| 2625 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2626 | if (ieee80211_drop_unencrypted_mgmt(rx)) |
| 2627 | return RX_DROP_UNUSABLE; |
| 2628 | |
| 2629 | return RX_CONTINUE; |
| 2630 | } |
| 2631 | |
| 2632 | static ieee80211_rx_result debug_noinline |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 2633 | ieee80211_rx_h_action(struct ieee80211_rx_data *rx) |
| 2634 | { |
| 2635 | struct ieee80211_local *local = rx->local; |
Johannes Berg | eb9fb5b8 | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 2636 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 2637 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data; |
Johannes Berg | 554891e | 2010-09-24 12:38:25 +0200 | [diff] [blame] | 2638 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 2639 | int len = rx->skb->len; |
| 2640 | |
| 2641 | if (!ieee80211_is_action(mgmt->frame_control)) |
| 2642 | return RX_CONTINUE; |
| 2643 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 2644 | /* drop too small frames */ |
| 2645 | if (len < IEEE80211_MIN_ACTION_SIZE) |
| 2646 | return RX_DROP_UNUSABLE; |
| 2647 | |
Marco Porsch | 815b809 | 2012-12-05 15:04:26 -0800 | [diff] [blame] | 2648 | if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC && |
Simon Wunderlich | cd7760e | 2013-08-28 13:41:31 +0200 | [diff] [blame] | 2649 | mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED && |
| 2650 | mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT) |
Johannes Berg | 8404080 | 2010-02-15 12:46:39 +0200 | [diff] [blame] | 2651 | return RX_DROP_UNUSABLE; |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 2652 | |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 2653 | switch (mgmt->u.action.category) { |
Johannes Berg | 1d8d3de | 2011-12-16 15:28:57 +0100 | [diff] [blame] | 2654 | case WLAN_CATEGORY_HT: |
| 2655 | /* reject HT action frames from stations not supporting HT */ |
| 2656 | if (!rx->sta->sta.ht_cap.ht_supported) |
| 2657 | goto invalid; |
| 2658 | |
| 2659 | if (sdata->vif.type != NL80211_IFTYPE_STATION && |
| 2660 | sdata->vif.type != NL80211_IFTYPE_MESH_POINT && |
| 2661 | sdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
| 2662 | sdata->vif.type != NL80211_IFTYPE_AP && |
| 2663 | sdata->vif.type != NL80211_IFTYPE_ADHOC) |
| 2664 | break; |
| 2665 | |
Johannes Berg | ec61cd6 | 2012-12-28 12:12:10 +0100 | [diff] [blame] | 2666 | /* verify action & smps_control/chanwidth are present */ |
Johannes Berg | 1d8d3de | 2011-12-16 15:28:57 +0100 | [diff] [blame] | 2667 | if (len < IEEE80211_MIN_ACTION_SIZE + 2) |
| 2668 | goto invalid; |
| 2669 | |
| 2670 | switch (mgmt->u.action.u.ht_smps.action) { |
| 2671 | case WLAN_HT_ACTION_SMPS: { |
| 2672 | struct ieee80211_supported_band *sband; |
Johannes Berg | af0ed69 | 2013-02-12 14:21:00 +0100 | [diff] [blame] | 2673 | enum ieee80211_smps_mode smps_mode; |
Johannes Berg | 1d8d3de | 2011-12-16 15:28:57 +0100 | [diff] [blame] | 2674 | |
| 2675 | /* convert to HT capability */ |
| 2676 | switch (mgmt->u.action.u.ht_smps.smps_control) { |
| 2677 | case WLAN_HT_SMPS_CONTROL_DISABLED: |
Johannes Berg | af0ed69 | 2013-02-12 14:21:00 +0100 | [diff] [blame] | 2678 | smps_mode = IEEE80211_SMPS_OFF; |
Johannes Berg | 1d8d3de | 2011-12-16 15:28:57 +0100 | [diff] [blame] | 2679 | break; |
| 2680 | case WLAN_HT_SMPS_CONTROL_STATIC: |
Johannes Berg | af0ed69 | 2013-02-12 14:21:00 +0100 | [diff] [blame] | 2681 | smps_mode = IEEE80211_SMPS_STATIC; |
Johannes Berg | 1d8d3de | 2011-12-16 15:28:57 +0100 | [diff] [blame] | 2682 | break; |
| 2683 | case WLAN_HT_SMPS_CONTROL_DYNAMIC: |
Johannes Berg | af0ed69 | 2013-02-12 14:21:00 +0100 | [diff] [blame] | 2684 | smps_mode = IEEE80211_SMPS_DYNAMIC; |
Johannes Berg | 1d8d3de | 2011-12-16 15:28:57 +0100 | [diff] [blame] | 2685 | break; |
| 2686 | default: |
| 2687 | goto invalid; |
| 2688 | } |
Johannes Berg | 1d8d3de | 2011-12-16 15:28:57 +0100 | [diff] [blame] | 2689 | |
| 2690 | /* if no change do nothing */ |
Johannes Berg | af0ed69 | 2013-02-12 14:21:00 +0100 | [diff] [blame] | 2691 | if (rx->sta->sta.smps_mode == smps_mode) |
Johannes Berg | 1d8d3de | 2011-12-16 15:28:57 +0100 | [diff] [blame] | 2692 | goto handled; |
Johannes Berg | af0ed69 | 2013-02-12 14:21:00 +0100 | [diff] [blame] | 2693 | rx->sta->sta.smps_mode = smps_mode; |
Johannes Berg | 1d8d3de | 2011-12-16 15:28:57 +0100 | [diff] [blame] | 2694 | |
| 2695 | sband = rx->local->hw.wiphy->bands[status->band]; |
| 2696 | |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 2697 | rate_control_rate_update(local, sband, rx->sta, |
| 2698 | IEEE80211_RC_SMPS_CHANGED); |
Johannes Berg | 1d8d3de | 2011-12-16 15:28:57 +0100 | [diff] [blame] | 2699 | goto handled; |
| 2700 | } |
Johannes Berg | ec61cd6 | 2012-12-28 12:12:10 +0100 | [diff] [blame] | 2701 | case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: { |
| 2702 | struct ieee80211_supported_band *sband; |
| 2703 | u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth; |
Eliad Peller | 1c45c5c | 2014-12-14 11:05:51 +0200 | [diff] [blame] | 2704 | enum ieee80211_sta_rx_bandwidth max_bw, new_bw; |
Johannes Berg | ec61cd6 | 2012-12-28 12:12:10 +0100 | [diff] [blame] | 2705 | |
| 2706 | /* If it doesn't support 40 MHz it can't change ... */ |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 2707 | if (!(rx->sta->sta.ht_cap.cap & |
| 2708 | IEEE80211_HT_CAP_SUP_WIDTH_20_40)) |
Johannes Berg | ec61cd6 | 2012-12-28 12:12:10 +0100 | [diff] [blame] | 2709 | goto handled; |
| 2710 | |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 2711 | if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ) |
Eliad Peller | 1c45c5c | 2014-12-14 11:05:51 +0200 | [diff] [blame] | 2712 | max_bw = IEEE80211_STA_RX_BW_20; |
Johannes Berg | ec61cd6 | 2012-12-28 12:12:10 +0100 | [diff] [blame] | 2713 | else |
Eliad Peller | 1c45c5c | 2014-12-14 11:05:51 +0200 | [diff] [blame] | 2714 | max_bw = ieee80211_sta_cap_rx_bw(rx->sta); |
| 2715 | |
| 2716 | /* set cur_max_bandwidth and recalc sta bw */ |
| 2717 | rx->sta->cur_max_bandwidth = max_bw; |
| 2718 | new_bw = ieee80211_sta_cur_vht_bw(rx->sta); |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 2719 | |
| 2720 | if (rx->sta->sta.bandwidth == new_bw) |
| 2721 | goto handled; |
Johannes Berg | ec61cd6 | 2012-12-28 12:12:10 +0100 | [diff] [blame] | 2722 | |
Eliad Peller | 1c45c5c | 2014-12-14 11:05:51 +0200 | [diff] [blame] | 2723 | rx->sta->sta.bandwidth = new_bw; |
Johannes Berg | ec61cd6 | 2012-12-28 12:12:10 +0100 | [diff] [blame] | 2724 | sband = rx->local->hw.wiphy->bands[status->band]; |
| 2725 | |
| 2726 | rate_control_rate_update(local, sband, rx->sta, |
| 2727 | IEEE80211_RC_BW_CHANGED); |
| 2728 | goto handled; |
| 2729 | } |
Johannes Berg | 1d8d3de | 2011-12-16 15:28:57 +0100 | [diff] [blame] | 2730 | default: |
| 2731 | goto invalid; |
| 2732 | } |
| 2733 | |
| 2734 | break; |
Johannes Berg | 1b3a2e4 | 2013-03-26 15:17:18 +0100 | [diff] [blame] | 2735 | case WLAN_CATEGORY_PUBLIC: |
| 2736 | if (len < IEEE80211_MIN_ACTION_SIZE + 1) |
| 2737 | goto invalid; |
| 2738 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 2739 | break; |
| 2740 | if (!rx->sta) |
| 2741 | break; |
| 2742 | if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) |
| 2743 | break; |
| 2744 | if (mgmt->u.action.u.ext_chan_switch.action_code != |
| 2745 | WLAN_PUB_ACTION_EXT_CHANSW_ANN) |
| 2746 | break; |
| 2747 | if (len < offsetof(struct ieee80211_mgmt, |
| 2748 | u.action.u.ext_chan_switch.variable)) |
| 2749 | goto invalid; |
| 2750 | goto queue; |
Johannes Berg | 0af83d3 | 2012-12-27 18:55:36 +0100 | [diff] [blame] | 2751 | case WLAN_CATEGORY_VHT: |
| 2752 | if (sdata->vif.type != NL80211_IFTYPE_STATION && |
| 2753 | sdata->vif.type != NL80211_IFTYPE_MESH_POINT && |
| 2754 | sdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
| 2755 | sdata->vif.type != NL80211_IFTYPE_AP && |
| 2756 | sdata->vif.type != NL80211_IFTYPE_ADHOC) |
| 2757 | break; |
| 2758 | |
| 2759 | /* verify action code is present */ |
| 2760 | if (len < IEEE80211_MIN_ACTION_SIZE + 1) |
| 2761 | goto invalid; |
| 2762 | |
| 2763 | switch (mgmt->u.action.u.vht_opmode_notif.action_code) { |
| 2764 | case WLAN_VHT_ACTION_OPMODE_NOTIF: { |
| 2765 | u8 opmode; |
| 2766 | |
| 2767 | /* verify opmode is present */ |
| 2768 | if (len < IEEE80211_MIN_ACTION_SIZE + 2) |
| 2769 | goto invalid; |
| 2770 | |
| 2771 | opmode = mgmt->u.action.u.vht_opmode_notif.operating_mode; |
| 2772 | |
| 2773 | ieee80211_vht_handle_opmode(rx->sdata, rx->sta, |
Eyal Shapira | cf1e05c | 2015-12-08 16:04:36 +0200 | [diff] [blame] | 2774 | opmode, status->band); |
Johannes Berg | 0af83d3 | 2012-12-27 18:55:36 +0100 | [diff] [blame] | 2775 | goto handled; |
| 2776 | } |
Sara Sharon | 23a1f8d | 2015-12-08 16:04:31 +0200 | [diff] [blame] | 2777 | case WLAN_VHT_ACTION_GROUPID_MGMT: { |
| 2778 | if (len < IEEE80211_MIN_ACTION_SIZE + 25) |
| 2779 | goto invalid; |
| 2780 | goto queue; |
| 2781 | } |
Johannes Berg | 0af83d3 | 2012-12-27 18:55:36 +0100 | [diff] [blame] | 2782 | default: |
| 2783 | break; |
| 2784 | } |
| 2785 | break; |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 2786 | case WLAN_CATEGORY_BACK: |
Johannes Berg | 8abd3f9 | 2009-02-10 21:25:47 +0100 | [diff] [blame] | 2787 | if (sdata->vif.type != NL80211_IFTYPE_STATION && |
Thomas Pedersen | ae2772b | 2011-10-26 14:47:29 -0700 | [diff] [blame] | 2788 | sdata->vif.type != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 8abd3f9 | 2009-02-10 21:25:47 +0100 | [diff] [blame] | 2789 | sdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
Alexander Simon | 13c40c5 | 2011-11-30 16:56:34 +0100 | [diff] [blame] | 2790 | sdata->vif.type != NL80211_IFTYPE_AP && |
| 2791 | sdata->vif.type != NL80211_IFTYPE_ADHOC) |
Johannes Berg | 8404080 | 2010-02-15 12:46:39 +0200 | [diff] [blame] | 2792 | break; |
Johannes Berg | 8abd3f9 | 2009-02-10 21:25:47 +0100 | [diff] [blame] | 2793 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 2794 | /* verify action_code is present */ |
| 2795 | if (len < IEEE80211_MIN_ACTION_SIZE + 1) |
| 2796 | break; |
| 2797 | |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 2798 | switch (mgmt->u.action.u.addba_req.action_code) { |
| 2799 | case WLAN_ACTION_ADDBA_REQ: |
| 2800 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
| 2801 | sizeof(mgmt->u.action.u.addba_req))) |
Johannes Berg | bed7ee6e | 2010-06-10 10:21:35 +0200 | [diff] [blame] | 2802 | goto invalid; |
| 2803 | break; |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 2804 | case WLAN_ACTION_ADDBA_RESP: |
| 2805 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
| 2806 | sizeof(mgmt->u.action.u.addba_resp))) |
Johannes Berg | bed7ee6e | 2010-06-10 10:21:35 +0200 | [diff] [blame] | 2807 | goto invalid; |
| 2808 | break; |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 2809 | case WLAN_ACTION_DELBA: |
| 2810 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
| 2811 | sizeof(mgmt->u.action.u.delba))) |
Johannes Berg | bed7ee6e | 2010-06-10 10:21:35 +0200 | [diff] [blame] | 2812 | goto invalid; |
| 2813 | break; |
| 2814 | default: |
| 2815 | goto invalid; |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 2816 | } |
Johannes Berg | bed7ee6e | 2010-06-10 10:21:35 +0200 | [diff] [blame] | 2817 | |
Johannes Berg | 8b58ff8 | 2010-06-10 10:21:51 +0200 | [diff] [blame] | 2818 | goto queue; |
Johannes Berg | 39192c0 | 2008-09-09 14:49:03 +0200 | [diff] [blame] | 2819 | case WLAN_CATEGORY_SPECTRUM_MGMT: |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 2820 | /* verify action_code is present */ |
| 2821 | if (len < IEEE80211_MIN_ACTION_SIZE + 1) |
| 2822 | break; |
| 2823 | |
Johannes Berg | 39192c0 | 2008-09-09 14:49:03 +0200 | [diff] [blame] | 2824 | switch (mgmt->u.action.u.measurement.action_code) { |
| 2825 | case WLAN_ACTION_SPCT_MSR_REQ: |
Simon Wunderlich | cd7760e | 2013-08-28 13:41:31 +0200 | [diff] [blame] | 2826 | if (status->band != IEEE80211_BAND_5GHZ) |
| 2827 | break; |
| 2828 | |
Johannes Berg | 39192c0 | 2008-09-09 14:49:03 +0200 | [diff] [blame] | 2829 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
| 2830 | sizeof(mgmt->u.action.u.measurement))) |
Johannes Berg | 8404080 | 2010-02-15 12:46:39 +0200 | [diff] [blame] | 2831 | break; |
Simon Wunderlich | cd7760e | 2013-08-28 13:41:31 +0200 | [diff] [blame] | 2832 | |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 2833 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
Johannes Berg | 8404080 | 2010-02-15 12:46:39 +0200 | [diff] [blame] | 2834 | break; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 2835 | |
Simon Wunderlich | cd7760e | 2013-08-28 13:41:31 +0200 | [diff] [blame] | 2836 | ieee80211_process_measurement_req(sdata, mgmt, len); |
| 2837 | goto handled; |
| 2838 | case WLAN_ACTION_SPCT_CHL_SWITCH: { |
| 2839 | u8 *bssid; |
| 2840 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
| 2841 | sizeof(mgmt->u.action.u.chan_switch))) |
| 2842 | break; |
| 2843 | |
| 2844 | if (sdata->vif.type != NL80211_IFTYPE_STATION && |
Chun-Yeow Yeoh | b8456a1 | 2013-10-17 15:55:02 -0700 | [diff] [blame] | 2845 | sdata->vif.type != NL80211_IFTYPE_ADHOC && |
| 2846 | sdata->vif.type != NL80211_IFTYPE_MESH_POINT) |
Simon Wunderlich | cd7760e | 2013-08-28 13:41:31 +0200 | [diff] [blame] | 2847 | break; |
| 2848 | |
| 2849 | if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 2850 | bssid = sdata->u.mgd.bssid; |
| 2851 | else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 2852 | bssid = sdata->u.ibss.bssid; |
Chun-Yeow Yeoh | b8456a1 | 2013-10-17 15:55:02 -0700 | [diff] [blame] | 2853 | else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT) |
| 2854 | bssid = mgmt->sa; |
Simon Wunderlich | cd7760e | 2013-08-28 13:41:31 +0200 | [diff] [blame] | 2855 | else |
| 2856 | break; |
| 2857 | |
| 2858 | if (!ether_addr_equal(mgmt->bssid, bssid)) |
Johannes Berg | 8404080 | 2010-02-15 12:46:39 +0200 | [diff] [blame] | 2859 | break; |
Sujith | c481ec9 | 2009-01-06 09:28:37 +0530 | [diff] [blame] | 2860 | |
Johannes Berg | 8b58ff8 | 2010-06-10 10:21:51 +0200 | [diff] [blame] | 2861 | goto queue; |
Simon Wunderlich | cd7760e | 2013-08-28 13:41:31 +0200 | [diff] [blame] | 2862 | } |
Johannes Berg | 39192c0 | 2008-09-09 14:49:03 +0200 | [diff] [blame] | 2863 | } |
| 2864 | break; |
Jouni Malinen | fea1473 | 2009-01-08 13:32:06 +0200 | [diff] [blame] | 2865 | case WLAN_CATEGORY_SA_QUERY: |
| 2866 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
| 2867 | sizeof(mgmt->u.action.u.sa_query))) |
Johannes Berg | 8404080 | 2010-02-15 12:46:39 +0200 | [diff] [blame] | 2868 | break; |
| 2869 | |
Jouni Malinen | fea1473 | 2009-01-08 13:32:06 +0200 | [diff] [blame] | 2870 | switch (mgmt->u.action.u.sa_query.action) { |
| 2871 | case WLAN_ACTION_SA_QUERY_REQUEST: |
| 2872 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
Johannes Berg | 8404080 | 2010-02-15 12:46:39 +0200 | [diff] [blame] | 2873 | break; |
Jouni Malinen | fea1473 | 2009-01-08 13:32:06 +0200 | [diff] [blame] | 2874 | ieee80211_process_sa_query_req(sdata, mgmt, len); |
Johannes Berg | 8404080 | 2010-02-15 12:46:39 +0200 | [diff] [blame] | 2875 | goto handled; |
Jouni Malinen | fea1473 | 2009-01-08 13:32:06 +0200 | [diff] [blame] | 2876 | } |
| 2877 | break; |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 2878 | case WLAN_CATEGORY_SELF_PROTECTED: |
Johannes Berg | 9b395bc | 2012-10-26 00:36:40 +0200 | [diff] [blame] | 2879 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
| 2880 | sizeof(mgmt->u.action.u.self_prot.action_code))) |
| 2881 | break; |
| 2882 | |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 2883 | switch (mgmt->u.action.u.self_prot.action_code) { |
| 2884 | case WLAN_SP_MESH_PEERING_OPEN: |
| 2885 | case WLAN_SP_MESH_PEERING_CLOSE: |
| 2886 | case WLAN_SP_MESH_PEERING_CONFIRM: |
| 2887 | if (!ieee80211_vif_is_mesh(&sdata->vif)) |
| 2888 | goto invalid; |
Thomas Pedersen | a6dad6a | 2013-03-04 13:06:12 -0800 | [diff] [blame] | 2889 | if (sdata->u.mesh.user_mpm) |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 2890 | /* userspace handles this frame */ |
| 2891 | break; |
| 2892 | goto queue; |
| 2893 | case WLAN_SP_MGK_INFORM: |
| 2894 | case WLAN_SP_MGK_ACK: |
| 2895 | if (!ieee80211_vif_is_mesh(&sdata->vif)) |
| 2896 | goto invalid; |
| 2897 | break; |
| 2898 | } |
| 2899 | break; |
Javier Cardona | d3aaec8a | 2011-05-03 16:57:09 -0700 | [diff] [blame] | 2900 | case WLAN_CATEGORY_MESH_ACTION: |
Johannes Berg | 9b395bc | 2012-10-26 00:36:40 +0200 | [diff] [blame] | 2901 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
| 2902 | sizeof(mgmt->u.action.u.mesh_action.action_code))) |
| 2903 | break; |
| 2904 | |
Johannes Berg | 77a121c | 2010-06-10 10:21:34 +0200 | [diff] [blame] | 2905 | if (!ieee80211_vif_is_mesh(&sdata->vif)) |
| 2906 | break; |
Thomas Pedersen | 25d49e4 | 2011-08-11 19:35:15 -0700 | [diff] [blame] | 2907 | if (mesh_action_is_path_sel(mgmt) && |
Johannes Berg | 1df332e | 2012-10-26 00:09:11 +0200 | [diff] [blame] | 2908 | !mesh_path_sel_is_hwmp(sdata)) |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 2909 | break; |
| 2910 | goto queue; |
Johannes Berg | 8404080 | 2010-02-15 12:46:39 +0200 | [diff] [blame] | 2911 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 2912 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2913 | return RX_CONTINUE; |
| 2914 | |
Johannes Berg | bed7ee6e | 2010-06-10 10:21:35 +0200 | [diff] [blame] | 2915 | invalid: |
Johannes Berg | 554891e | 2010-09-24 12:38:25 +0200 | [diff] [blame] | 2916 | status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2917 | /* will return in the next handlers */ |
| 2918 | return RX_CONTINUE; |
| 2919 | |
| 2920 | handled: |
| 2921 | if (rx->sta) |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 2922 | rx->sta->rx_stats.packets++; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2923 | dev_kfree_skb(rx->skb); |
| 2924 | return RX_QUEUED; |
| 2925 | |
| 2926 | queue: |
| 2927 | rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME; |
| 2928 | skb_queue_tail(&sdata->skb_queue, rx->skb); |
| 2929 | ieee80211_queue_work(&local->hw, &sdata->work); |
| 2930 | if (rx->sta) |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 2931 | rx->sta->rx_stats.packets++; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2932 | return RX_QUEUED; |
| 2933 | } |
| 2934 | |
| 2935 | static ieee80211_rx_result debug_noinline |
| 2936 | ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx) |
| 2937 | { |
Johannes Berg | 554891e | 2010-09-24 12:38:25 +0200 | [diff] [blame] | 2938 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 2939 | int sig = 0; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2940 | |
| 2941 | /* skip known-bad action frames and return them in the next handler */ |
Johannes Berg | 554891e | 2010-09-24 12:38:25 +0200 | [diff] [blame] | 2942 | if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2943 | return RX_CONTINUE; |
Felix Fietkau | d790744 | 2010-01-07 20:23:53 +0100 | [diff] [blame] | 2944 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 2945 | /* |
| 2946 | * Getting here means the kernel doesn't know how to handle |
| 2947 | * it, but maybe userspace does ... include returned frames |
| 2948 | * so userspace can register for those to know whether ones |
| 2949 | * it transmitted were processed or returned. |
| 2950 | */ |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 2951 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2952 | if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM)) |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 2953 | sig = status->signal; |
| 2954 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2955 | if (cfg80211_rx_mgmt(&rx->sdata->wdev, status->freq, sig, |
Vladimir Kondratiev | 970fdfa | 2014-08-11 03:29:57 -0700 | [diff] [blame] | 2956 | rx->skb->data, rx->skb->len, 0)) { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2957 | if (rx->sta) |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 2958 | rx->sta->rx_stats.packets++; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2959 | dev_kfree_skb(rx->skb); |
| 2960 | return RX_QUEUED; |
| 2961 | } |
| 2962 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2963 | return RX_CONTINUE; |
| 2964 | } |
| 2965 | |
| 2966 | static ieee80211_rx_result debug_noinline |
| 2967 | ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx) |
| 2968 | { |
| 2969 | struct ieee80211_local *local = rx->local; |
| 2970 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data; |
| 2971 | struct sk_buff *nskb; |
| 2972 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
Johannes Berg | 554891e | 2010-09-24 12:38:25 +0200 | [diff] [blame] | 2973 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2974 | |
| 2975 | if (!ieee80211_is_action(mgmt->frame_control)) |
| 2976 | return RX_CONTINUE; |
| 2977 | |
| 2978 | /* |
| 2979 | * For AP mode, hostapd is responsible for handling any action |
| 2980 | * frames that we didn't handle, including returning unknown |
| 2981 | * ones. For all other modes we will return them to the sender, |
| 2982 | * setting the 0x80 bit in the action category, as required by |
Johannes Berg | 4b5ebcc | 2012-06-27 15:38:56 +0200 | [diff] [blame] | 2983 | * 802.11-2012 9.24.4. |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2984 | * Newer versions of hostapd shall also use the management frame |
| 2985 | * registration mechanisms, but older ones still use cooked |
| 2986 | * monitor interfaces so push all frames there. |
| 2987 | */ |
Johannes Berg | 554891e | 2010-09-24 12:38:25 +0200 | [diff] [blame] | 2988 | if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) && |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2989 | (sdata->vif.type == NL80211_IFTYPE_AP || |
| 2990 | sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) |
| 2991 | return RX_DROP_MONITOR; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 2992 | |
Johannes Berg | 4b5ebcc | 2012-06-27 15:38:56 +0200 | [diff] [blame] | 2993 | if (is_multicast_ether_addr(mgmt->da)) |
| 2994 | return RX_DROP_MONITOR; |
| 2995 | |
Johannes Berg | 8404080 | 2010-02-15 12:46:39 +0200 | [diff] [blame] | 2996 | /* do not return rejected action frames */ |
| 2997 | if (mgmt->u.action.category & 0x80) |
| 2998 | return RX_DROP_UNUSABLE; |
| 2999 | |
| 3000 | nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0, |
| 3001 | GFP_ATOMIC); |
| 3002 | if (nskb) { |
John W. Linville | 292b4df | 2010-06-24 11:13:56 -0400 | [diff] [blame] | 3003 | struct ieee80211_mgmt *nmgmt = (void *)nskb->data; |
Johannes Berg | 8404080 | 2010-02-15 12:46:39 +0200 | [diff] [blame] | 3004 | |
John W. Linville | 292b4df | 2010-06-24 11:13:56 -0400 | [diff] [blame] | 3005 | nmgmt->u.action.category |= 0x80; |
| 3006 | memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN); |
| 3007 | memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN); |
Johannes Berg | 8404080 | 2010-02-15 12:46:39 +0200 | [diff] [blame] | 3008 | |
| 3009 | memset(nskb->cb, 0, sizeof(nskb->cb)); |
| 3010 | |
Johannes Berg | 07e5a5f | 2013-03-07 13:22:05 +0100 | [diff] [blame] | 3011 | if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) { |
| 3012 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb); |
| 3013 | |
| 3014 | info->flags = IEEE80211_TX_CTL_TX_OFFCHAN | |
| 3015 | IEEE80211_TX_INTFL_OFFCHAN_TX_OK | |
| 3016 | IEEE80211_TX_CTL_NO_CCK_RATE; |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 3017 | if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) |
Johannes Berg | 07e5a5f | 2013-03-07 13:22:05 +0100 | [diff] [blame] | 3018 | info->hw_queue = |
| 3019 | local->hw.offchannel_tx_hw_queue; |
| 3020 | } |
| 3021 | |
| 3022 | __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7, |
| 3023 | status->band); |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 3024 | } |
Johannes Berg | 39192c0 | 2008-09-09 14:49:03 +0200 | [diff] [blame] | 3025 | dev_kfree_skb(rx->skb); |
| 3026 | return RX_QUEUED; |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 3027 | } |
| 3028 | |
| 3029 | static ieee80211_rx_result debug_noinline |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 3030 | ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 3031 | { |
Johannes Berg | eb9fb5b8 | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 3032 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
Johannes Berg | 77a121c | 2010-06-10 10:21:34 +0200 | [diff] [blame] | 3033 | struct ieee80211_mgmt *mgmt = (void *)rx->skb->data; |
| 3034 | __le16 stype; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 3035 | |
Johannes Berg | 77a121c | 2010-06-10 10:21:34 +0200 | [diff] [blame] | 3036 | stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE); |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 3037 | |
Johannes Berg | 77a121c | 2010-06-10 10:21:34 +0200 | [diff] [blame] | 3038 | if (!ieee80211_vif_is_mesh(&sdata->vif) && |
| 3039 | sdata->vif.type != NL80211_IFTYPE_ADHOC && |
Rostislav Lisovy | 239281f | 2014-11-03 10:33:19 +0100 | [diff] [blame] | 3040 | sdata->vif.type != NL80211_IFTYPE_OCB && |
Johannes Berg | 77a121c | 2010-06-10 10:21:34 +0200 | [diff] [blame] | 3041 | sdata->vif.type != NL80211_IFTYPE_STATION) |
| 3042 | return RX_DROP_MONITOR; |
Johannes Berg | f9d540e | 2007-09-28 14:02:09 +0200 | [diff] [blame] | 3043 | |
Johannes Berg | 77a121c | 2010-06-10 10:21:34 +0200 | [diff] [blame] | 3044 | switch (stype) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3045 | case cpu_to_le16(IEEE80211_STYPE_AUTH): |
Johannes Berg | 77a121c | 2010-06-10 10:21:34 +0200 | [diff] [blame] | 3046 | case cpu_to_le16(IEEE80211_STYPE_BEACON): |
| 3047 | case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP): |
| 3048 | /* process for all: mesh, mlme, ibss */ |
| 3049 | break; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3050 | case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP): |
| 3051 | case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP): |
Johannes Berg | 77a121c | 2010-06-10 10:21:34 +0200 | [diff] [blame] | 3052 | case cpu_to_le16(IEEE80211_STYPE_DEAUTH): |
| 3053 | case cpu_to_le16(IEEE80211_STYPE_DISASSOC): |
Christian Lamparter | 2c31333a | 2010-11-29 20:53:23 +0100 | [diff] [blame] | 3054 | if (is_multicast_ether_addr(mgmt->da) && |
| 3055 | !is_broadcast_ether_addr(mgmt->da)) |
| 3056 | return RX_DROP_MONITOR; |
| 3057 | |
Johannes Berg | 77a121c | 2010-06-10 10:21:34 +0200 | [diff] [blame] | 3058 | /* process only for station */ |
| 3059 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 3060 | return RX_DROP_MONITOR; |
| 3061 | break; |
| 3062 | case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ): |
Thomas Pedersen | 9fb04b5 | 2013-02-14 11:20:14 -0800 | [diff] [blame] | 3063 | /* process only for ibss and mesh */ |
| 3064 | if (sdata->vif.type != NL80211_IFTYPE_ADHOC && |
| 3065 | sdata->vif.type != NL80211_IFTYPE_MESH_POINT) |
Johannes Berg | 77a121c | 2010-06-10 10:21:34 +0200 | [diff] [blame] | 3066 | return RX_DROP_MONITOR; |
| 3067 | break; |
| 3068 | default: |
| 3069 | return RX_DROP_MONITOR; |
| 3070 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3071 | |
Johannes Berg | 77a121c | 2010-06-10 10:21:34 +0200 | [diff] [blame] | 3072 | /* queue up frame and kick off work to process it */ |
Johannes Berg | c1475ca | 2010-06-10 10:21:37 +0200 | [diff] [blame] | 3073 | rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME; |
Johannes Berg | 77a121c | 2010-06-10 10:21:34 +0200 | [diff] [blame] | 3074 | skb_queue_tail(&sdata->skb_queue, rx->skb); |
| 3075 | ieee80211_queue_work(&rx->local->hw, &sdata->work); |
Johannes Berg | 8b58ff8 | 2010-06-10 10:21:51 +0200 | [diff] [blame] | 3076 | if (rx->sta) |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 3077 | rx->sta->rx_stats.packets++; |
Johannes Berg | 77a121c | 2010-06-10 10:21:34 +0200 | [diff] [blame] | 3078 | |
| 3079 | return RX_QUEUED; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 3080 | } |
| 3081 | |
Johannes Berg | 5f0b7de | 2009-11-16 13:58:21 +0100 | [diff] [blame] | 3082 | static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx, |
| 3083 | struct ieee80211_rate *rate) |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 3084 | { |
| 3085 | struct ieee80211_sub_if_data *sdata; |
| 3086 | struct ieee80211_local *local = rx->local; |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 3087 | struct sk_buff *skb = rx->skb, *skb2; |
| 3088 | struct net_device *prev_dev = NULL; |
Johannes Berg | eb9fb5b8 | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 3089 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
Johannes Berg | 293702a | 2012-03-02 13:18:19 +0100 | [diff] [blame] | 3090 | int needed_headroom; |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 3091 | |
Johannes Berg | 554891e | 2010-09-24 12:38:25 +0200 | [diff] [blame] | 3092 | /* |
| 3093 | * If cooked monitor has been processed already, then |
| 3094 | * don't do it again. If not, set the flag. |
| 3095 | */ |
| 3096 | if (rx->flags & IEEE80211_RX_CMNTR) |
John W. Linville | 7c1e183 | 2010-09-24 15:52:49 -0400 | [diff] [blame] | 3097 | goto out_free_skb; |
Johannes Berg | 554891e | 2010-09-24 12:38:25 +0200 | [diff] [blame] | 3098 | rx->flags |= IEEE80211_RX_CMNTR; |
John W. Linville | 7c1e183 | 2010-09-24 15:52:49 -0400 | [diff] [blame] | 3099 | |
Johannes Berg | 152c477 | 2011-10-21 10:22:22 +0200 | [diff] [blame] | 3100 | /* If there are no cooked monitor interfaces, just free the SKB */ |
| 3101 | if (!local->cooked_mntrs) |
| 3102 | goto out_free_skb; |
| 3103 | |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 3104 | /* vendor data is long removed here */ |
| 3105 | status->flag &= ~RX_FLAG_RADIOTAP_VENDOR_DATA; |
Johannes Berg | 293702a | 2012-03-02 13:18:19 +0100 | [diff] [blame] | 3106 | /* room for the radiotap header based on driver features */ |
Johannes Berg | 1f7bba7 | 2014-11-06 22:56:36 +0100 | [diff] [blame] | 3107 | needed_headroom = ieee80211_rx_radiotap_hdrlen(local, status, skb); |
Johannes Berg | 293702a | 2012-03-02 13:18:19 +0100 | [diff] [blame] | 3108 | |
| 3109 | if (skb_headroom(skb) < needed_headroom && |
| 3110 | pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 3111 | goto out_free_skb; |
| 3112 | |
Johannes Berg | 293702a | 2012-03-02 13:18:19 +0100 | [diff] [blame] | 3113 | /* prepend radiotap information */ |
Felix Fietkau | 973ef21 | 2012-04-16 14:56:48 +0200 | [diff] [blame] | 3114 | ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom, |
| 3115 | false); |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 3116 | |
Zhang Shengju | d57a544 | 2016-03-03 01:16:56 +0000 | [diff] [blame] | 3117 | skb_reset_mac_header(skb); |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 3118 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 3119 | skb->pkt_type = PACKET_OTHERHOST; |
| 3120 | skb->protocol = htons(ETH_P_802_2); |
| 3121 | |
| 3122 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
Johannes Berg | 9607e6b66 | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 3123 | if (!ieee80211_sdata_running(sdata)) |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 3124 | continue; |
| 3125 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 3126 | if (sdata->vif.type != NL80211_IFTYPE_MONITOR || |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 3127 | !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)) |
| 3128 | continue; |
| 3129 | |
| 3130 | if (prev_dev) { |
| 3131 | skb2 = skb_clone(skb, GFP_ATOMIC); |
| 3132 | if (skb2) { |
| 3133 | skb2->dev = prev_dev; |
John W. Linville | 5548a8a | 2010-06-24 14:25:56 -0400 | [diff] [blame] | 3134 | netif_receive_skb(skb2); |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 3135 | } |
| 3136 | } |
| 3137 | |
| 3138 | prev_dev = sdata->dev; |
Johannes Berg | 5a49051 | 2015-04-22 17:10:38 +0200 | [diff] [blame] | 3139 | ieee80211_rx_stats(sdata->dev, skb->len); |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 3140 | } |
| 3141 | |
| 3142 | if (prev_dev) { |
| 3143 | skb->dev = prev_dev; |
John W. Linville | 5548a8a | 2010-06-24 14:25:56 -0400 | [diff] [blame] | 3144 | netif_receive_skb(skb); |
Johannes Berg | 554891e | 2010-09-24 12:38:25 +0200 | [diff] [blame] | 3145 | return; |
| 3146 | } |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 3147 | |
| 3148 | out_free_skb: |
| 3149 | dev_kfree_skb(skb); |
| 3150 | } |
| 3151 | |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 3152 | static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx, |
| 3153 | ieee80211_rx_result res) |
| 3154 | { |
| 3155 | switch (res) { |
| 3156 | case RX_DROP_MONITOR: |
| 3157 | I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop); |
| 3158 | if (rx->sta) |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 3159 | rx->sta->rx_stats.dropped++; |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 3160 | /* fall through */ |
| 3161 | case RX_CONTINUE: { |
| 3162 | struct ieee80211_rate *rate = NULL; |
| 3163 | struct ieee80211_supported_band *sband; |
| 3164 | struct ieee80211_rx_status *status; |
| 3165 | |
| 3166 | status = IEEE80211_SKB_RXCB((rx->skb)); |
| 3167 | |
| 3168 | sband = rx->local->hw.wiphy->bands[status->band]; |
Johannes Berg | 5614618 | 2012-11-09 15:07:02 +0100 | [diff] [blame] | 3169 | if (!(status->flag & RX_FLAG_HT) && |
| 3170 | !(status->flag & RX_FLAG_VHT)) |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 3171 | rate = &sband->bitrates[status->rate_idx]; |
| 3172 | |
| 3173 | ieee80211_rx_cooked_monitor(rx, rate); |
| 3174 | break; |
| 3175 | } |
| 3176 | case RX_DROP_UNUSABLE: |
| 3177 | I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop); |
| 3178 | if (rx->sta) |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 3179 | rx->sta->rx_stats.dropped++; |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 3180 | dev_kfree_skb(rx->skb); |
| 3181 | break; |
| 3182 | case RX_QUEUED: |
| 3183 | I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued); |
| 3184 | break; |
| 3185 | } |
| 3186 | } |
| 3187 | |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 3188 | static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx, |
| 3189 | struct sk_buff_head *frames) |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 3190 | { |
| 3191 | ieee80211_rx_result res = RX_DROP_MONITOR; |
| 3192 | struct sk_buff *skb; |
| 3193 | |
| 3194 | #define CALL_RXH(rxh) \ |
| 3195 | do { \ |
| 3196 | res = rxh(rx); \ |
| 3197 | if (res != RX_CONTINUE) \ |
| 3198 | goto rxh_next; \ |
Johannes Berg | 8ebaa5b | 2016-03-31 20:02:04 +0300 | [diff] [blame] | 3199 | } while (0) |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 3200 | |
Johannes Berg | 45ceeee | 2015-03-16 09:08:20 +0100 | [diff] [blame] | 3201 | /* Lock here to avoid hitting all of the data used in the RX |
| 3202 | * path (e.g. key data, station data, ...) concurrently when |
| 3203 | * a frame is released from the reorder buffer due to timeout |
| 3204 | * from the timer, potentially concurrently with RX from the |
| 3205 | * driver. |
| 3206 | */ |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 3207 | spin_lock_bh(&rx->local->rx_path_lock); |
Christian Lamparter | 24a8fda | 2010-12-30 17:25:29 +0100 | [diff] [blame] | 3208 | |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 3209 | while ((skb = __skb_dequeue(frames))) { |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 3210 | /* |
| 3211 | * all the other fields are valid across frames |
| 3212 | * that belong to an aMPDU since they are on the |
| 3213 | * same TID from the same station |
| 3214 | */ |
| 3215 | rx->skb = skb; |
| 3216 | |
Johannes Berg | 8ebaa5b | 2016-03-31 20:02:04 +0300 | [diff] [blame] | 3217 | CALL_RXH(ieee80211_rx_h_check_more_data); |
| 3218 | CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll); |
| 3219 | CALL_RXH(ieee80211_rx_h_sta_process); |
| 3220 | CALL_RXH(ieee80211_rx_h_decrypt); |
| 3221 | CALL_RXH(ieee80211_rx_h_defragment); |
| 3222 | CALL_RXH(ieee80211_rx_h_michael_mic_verify); |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 3223 | /* must be after MMIC verify so header is counted in MPDU mic */ |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 3224 | #ifdef CONFIG_MAC80211_MESH |
| 3225 | if (ieee80211_vif_is_mesh(&rx->sdata->vif)) |
| 3226 | CALL_RXH(ieee80211_rx_h_mesh_fwding); |
| 3227 | #endif |
Johannes Berg | 8ebaa5b | 2016-03-31 20:02:04 +0300 | [diff] [blame] | 3228 | CALL_RXH(ieee80211_rx_h_amsdu); |
| 3229 | CALL_RXH(ieee80211_rx_h_data); |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 3230 | |
| 3231 | /* special treatment -- needs the queue */ |
| 3232 | res = ieee80211_rx_h_ctrl(rx, frames); |
| 3233 | if (res != RX_CONTINUE) |
| 3234 | goto rxh_next; |
| 3235 | |
Johannes Berg | 8ebaa5b | 2016-03-31 20:02:04 +0300 | [diff] [blame] | 3236 | CALL_RXH(ieee80211_rx_h_mgmt_check); |
| 3237 | CALL_RXH(ieee80211_rx_h_action); |
| 3238 | CALL_RXH(ieee80211_rx_h_userspace_mgmt); |
| 3239 | CALL_RXH(ieee80211_rx_h_action_return); |
| 3240 | CALL_RXH(ieee80211_rx_h_mgmt); |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 3241 | |
| 3242 | rxh_next: |
| 3243 | ieee80211_rx_handlers_result(rx, res); |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 3244 | |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 3245 | #undef CALL_RXH |
| 3246 | } |
Christian Lamparter | 24a8fda | 2010-12-30 17:25:29 +0100 | [diff] [blame] | 3247 | |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 3248 | spin_unlock_bh(&rx->local->rx_path_lock); |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 3249 | } |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 3250 | |
Johannes Berg | 4406c37 | 2010-09-24 11:21:06 +0200 | [diff] [blame] | 3251 | static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx) |
Johannes Berg | 5890529 | 2008-01-31 19:48:25 +0100 | [diff] [blame] | 3252 | { |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 3253 | struct sk_buff_head reorder_release; |
Johannes Berg | 5890529 | 2008-01-31 19:48:25 +0100 | [diff] [blame] | 3254 | ieee80211_rx_result res = RX_DROP_MONITOR; |
| 3255 | |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 3256 | __skb_queue_head_init(&reorder_release); |
| 3257 | |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 3258 | #define CALL_RXH(rxh) \ |
| 3259 | do { \ |
| 3260 | res = rxh(rx); \ |
| 3261 | if (res != RX_CONTINUE) \ |
Johannes Berg | 2569a82 | 2009-11-25 17:46:17 +0100 | [diff] [blame] | 3262 | goto rxh_next; \ |
Johannes Berg | 8ebaa5b | 2016-03-31 20:02:04 +0300 | [diff] [blame] | 3263 | } while (0) |
Johannes Berg | 5890529 | 2008-01-31 19:48:25 +0100 | [diff] [blame] | 3264 | |
Johannes Berg | 8ebaa5b | 2016-03-31 20:02:04 +0300 | [diff] [blame] | 3265 | CALL_RXH(ieee80211_rx_h_check_dup); |
| 3266 | CALL_RXH(ieee80211_rx_h_check); |
Johannes Berg | 2569a82 | 2009-11-25 17:46:17 +0100 | [diff] [blame] | 3267 | |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 3268 | ieee80211_rx_reorder_ampdu(rx, &reorder_release); |
Johannes Berg | 2569a82 | 2009-11-25 17:46:17 +0100 | [diff] [blame] | 3269 | |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 3270 | ieee80211_rx_handlers(rx, &reorder_release); |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 3271 | return; |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 3272 | |
Johannes Berg | 2569a82 | 2009-11-25 17:46:17 +0100 | [diff] [blame] | 3273 | rxh_next: |
Christian Lamparter | aa0c863 | 2010-08-05 01:36:04 +0200 | [diff] [blame] | 3274 | ieee80211_rx_handlers_result(rx, res); |
| 3275 | |
| 3276 | #undef CALL_RXH |
Johannes Berg | 5890529 | 2008-01-31 19:48:25 +0100 | [diff] [blame] | 3277 | } |
| 3278 | |
Christian Lamparter | 2bff8ebf | 2010-08-05 01:36:41 +0200 | [diff] [blame] | 3279 | /* |
Johannes Berg | dd31857 | 2010-11-29 11:09:16 +0100 | [diff] [blame] | 3280 | * This function makes calls into the RX path, therefore |
| 3281 | * it has to be invoked under RCU read lock. |
Christian Lamparter | 2bff8ebf | 2010-08-05 01:36:41 +0200 | [diff] [blame] | 3282 | */ |
| 3283 | void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid) |
| 3284 | { |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 3285 | struct sk_buff_head frames; |
Johannes Berg | 554891e | 2010-09-24 12:38:25 +0200 | [diff] [blame] | 3286 | struct ieee80211_rx_data rx = { |
| 3287 | .sta = sta, |
| 3288 | .sdata = sta->sdata, |
| 3289 | .local = sta->local, |
Johannes Berg | 9e26297 | 2011-07-07 18:45:03 +0200 | [diff] [blame] | 3290 | /* This is OK -- must be QoS data frame */ |
| 3291 | .security_idx = tid, |
| 3292 | .seqno_idx = tid, |
Johannes Berg | af9f9b2 | 2015-06-11 16:02:32 +0200 | [diff] [blame] | 3293 | .napi = NULL, /* must be NULL to not have races */ |
Johannes Berg | 554891e | 2010-09-24 12:38:25 +0200 | [diff] [blame] | 3294 | }; |
Christian Lamparter | 2c15a0c | 2010-08-24 19:22:42 +0200 | [diff] [blame] | 3295 | struct tid_ampdu_rx *tid_agg_rx; |
| 3296 | |
| 3297 | tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]); |
| 3298 | if (!tid_agg_rx) |
| 3299 | return; |
Christian Lamparter | 2bff8ebf | 2010-08-05 01:36:41 +0200 | [diff] [blame] | 3300 | |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 3301 | __skb_queue_head_init(&frames); |
| 3302 | |
Christian Lamparter | 2c15a0c | 2010-08-24 19:22:42 +0200 | [diff] [blame] | 3303 | spin_lock(&tid_agg_rx->reorder_lock); |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 3304 | ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames); |
Christian Lamparter | 2c15a0c | 2010-08-24 19:22:42 +0200 | [diff] [blame] | 3305 | spin_unlock(&tid_agg_rx->reorder_lock); |
Christian Lamparter | 2bff8ebf | 2010-08-05 01:36:41 +0200 | [diff] [blame] | 3306 | |
Emmanuel Grumbach | b497de6 | 2015-04-20 22:53:38 +0300 | [diff] [blame] | 3307 | if (!skb_queue_empty(&frames)) { |
| 3308 | struct ieee80211_event event = { |
| 3309 | .type = BA_FRAME_TIMEOUT, |
| 3310 | .u.ba.tid = tid, |
| 3311 | .u.ba.sta = &sta->sta, |
| 3312 | }; |
| 3313 | drv_event_callback(rx.local, rx.sdata, &event); |
| 3314 | } |
| 3315 | |
Christian Lamparter | f9e124f | 2013-02-04 17:44:44 +0000 | [diff] [blame] | 3316 | ieee80211_rx_handlers(&rx, &frames); |
Christian Lamparter | 2bff8ebf | 2010-08-05 01:36:41 +0200 | [diff] [blame] | 3317 | } |
| 3318 | |
Sara Sharon | 06470f7 | 2016-01-28 16:19:25 +0200 | [diff] [blame] | 3319 | void ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta *pubsta, u8 tid, |
| 3320 | u16 ssn, u64 filtered, |
| 3321 | u16 received_mpdus) |
| 3322 | { |
| 3323 | struct sta_info *sta; |
| 3324 | struct tid_ampdu_rx *tid_agg_rx; |
| 3325 | struct sk_buff_head frames; |
| 3326 | struct ieee80211_rx_data rx = { |
| 3327 | /* This is OK -- must be QoS data frame */ |
| 3328 | .security_idx = tid, |
| 3329 | .seqno_idx = tid, |
| 3330 | }; |
| 3331 | int i, diff; |
| 3332 | |
| 3333 | if (WARN_ON(!pubsta || tid >= IEEE80211_NUM_TIDS)) |
| 3334 | return; |
| 3335 | |
| 3336 | __skb_queue_head_init(&frames); |
| 3337 | |
| 3338 | sta = container_of(pubsta, struct sta_info, sta); |
| 3339 | |
| 3340 | rx.sta = sta; |
| 3341 | rx.sdata = sta->sdata; |
| 3342 | rx.local = sta->local; |
| 3343 | |
| 3344 | rcu_read_lock(); |
| 3345 | tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]); |
| 3346 | if (!tid_agg_rx) |
| 3347 | goto out; |
| 3348 | |
| 3349 | spin_lock_bh(&tid_agg_rx->reorder_lock); |
| 3350 | |
| 3351 | if (received_mpdus >= IEEE80211_SN_MODULO >> 1) { |
| 3352 | int release; |
| 3353 | |
| 3354 | /* release all frames in the reorder buffer */ |
| 3355 | release = (tid_agg_rx->head_seq_num + tid_agg_rx->buf_size) % |
| 3356 | IEEE80211_SN_MODULO; |
| 3357 | ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx, |
| 3358 | release, &frames); |
| 3359 | /* update ssn to match received ssn */ |
| 3360 | tid_agg_rx->head_seq_num = ssn; |
| 3361 | } else { |
| 3362 | ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx, ssn, |
| 3363 | &frames); |
| 3364 | } |
| 3365 | |
| 3366 | /* handle the case that received ssn is behind the mac ssn. |
| 3367 | * it can be tid_agg_rx->buf_size behind and still be valid */ |
| 3368 | diff = (tid_agg_rx->head_seq_num - ssn) & IEEE80211_SN_MASK; |
| 3369 | if (diff >= tid_agg_rx->buf_size) { |
| 3370 | tid_agg_rx->reorder_buf_filtered = 0; |
| 3371 | goto release; |
| 3372 | } |
| 3373 | filtered = filtered >> diff; |
| 3374 | ssn += diff; |
| 3375 | |
| 3376 | /* update bitmap */ |
| 3377 | for (i = 0; i < tid_agg_rx->buf_size; i++) { |
| 3378 | int index = (ssn + i) % tid_agg_rx->buf_size; |
| 3379 | |
| 3380 | tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index); |
| 3381 | if (filtered & BIT_ULL(i)) |
| 3382 | tid_agg_rx->reorder_buf_filtered |= BIT_ULL(index); |
| 3383 | } |
| 3384 | |
| 3385 | /* now process also frames that the filter marking released */ |
| 3386 | ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames); |
| 3387 | |
| 3388 | release: |
| 3389 | spin_unlock_bh(&tid_agg_rx->reorder_lock); |
| 3390 | |
| 3391 | ieee80211_rx_handlers(&rx, &frames); |
| 3392 | |
| 3393 | out: |
| 3394 | rcu_read_unlock(); |
| 3395 | } |
| 3396 | EXPORT_SYMBOL(ieee80211_mark_rx_ba_filtered_frames); |
| 3397 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 3398 | /* main receive path */ |
| 3399 | |
Johannes Berg | a58fbe1 | 2015-04-22 15:08:39 +0200 | [diff] [blame] | 3400 | static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx) |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 3401 | { |
Johannes Berg | 20b01f8 | 2010-09-24 11:21:05 +0200 | [diff] [blame] | 3402 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
Johannes Berg | eb9fb5b8 | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 3403 | struct sk_buff *skb = rx->skb; |
Johannes Berg | a58fbe1 | 2015-04-22 15:08:39 +0200 | [diff] [blame] | 3404 | struct ieee80211_hdr *hdr = (void *)skb->data; |
Johannes Berg | eb9fb5b8 | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 3405 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
| 3406 | u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type); |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 3407 | int multicast = is_multicast_ether_addr(hdr->addr1); |
| 3408 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 3409 | switch (sdata->vif.type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 3410 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3411 | if (!bssid && !sdata->u.mgd.use_4addr) |
Johannes Berg | 3c2723f5 | 2014-01-07 16:23:24 +0100 | [diff] [blame] | 3412 | return false; |
Johannes Berg | a58fbe1 | 2015-04-22 15:08:39 +0200 | [diff] [blame] | 3413 | if (multicast) |
| 3414 | return true; |
| 3415 | return ether_addr_equal(sdata->vif.addr, hdr->addr1); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 3416 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 3417 | if (!bssid) |
Johannes Berg | 3c2723f5 | 2014-01-07 16:23:24 +0100 | [diff] [blame] | 3418 | return false; |
Felix Fietkau | 6329b8d | 2013-09-17 11:15:43 +0200 | [diff] [blame] | 3419 | if (ether_addr_equal(sdata->vif.addr, hdr->addr2) || |
| 3420 | ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2)) |
Johannes Berg | 3c2723f5 | 2014-01-07 16:23:24 +0100 | [diff] [blame] | 3421 | return false; |
Johannes Berg | a58fbe1 | 2015-04-22 15:08:39 +0200 | [diff] [blame] | 3422 | if (ieee80211_is_beacon(hdr->frame_control)) |
Johannes Berg | 3c2723f5 | 2014-01-07 16:23:24 +0100 | [diff] [blame] | 3423 | return true; |
Johannes Berg | a58fbe1 | 2015-04-22 15:08:39 +0200 | [diff] [blame] | 3424 | if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid)) |
Johannes Berg | 3c2723f5 | 2014-01-07 16:23:24 +0100 | [diff] [blame] | 3425 | return false; |
Johannes Berg | a58fbe1 | 2015-04-22 15:08:39 +0200 | [diff] [blame] | 3426 | if (!multicast && |
| 3427 | !ether_addr_equal(sdata->vif.addr, hdr->addr1)) |
Johannes Berg | df14046 | 2015-04-22 14:40:58 +0200 | [diff] [blame] | 3428 | return false; |
Johannes Berg | a58fbe1 | 2015-04-22 15:08:39 +0200 | [diff] [blame] | 3429 | if (!rx->sta) { |
Jouni Malinen | 0fb8ca4 | 2008-12-12 14:38:33 +0200 | [diff] [blame] | 3430 | int rate_idx; |
Johannes Berg | 5614618 | 2012-11-09 15:07:02 +0100 | [diff] [blame] | 3431 | if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT)) |
| 3432 | rate_idx = 0; /* TODO: HT/VHT rates */ |
Jouni Malinen | 0fb8ca4 | 2008-12-12 14:38:33 +0200 | [diff] [blame] | 3433 | else |
Johannes Berg | eb9fb5b8 | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 3434 | rate_idx = status->rate_idx; |
Johannes Berg | 8bf11d8 | 2011-12-15 11:17:37 +0100 | [diff] [blame] | 3435 | ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2, |
| 3436 | BIT(rate_idx)); |
Jouni Malinen | 0fb8ca4 | 2008-12-12 14:38:33 +0200 | [diff] [blame] | 3437 | } |
Johannes Berg | a58fbe1 | 2015-04-22 15:08:39 +0200 | [diff] [blame] | 3438 | return true; |
Rostislav Lisovy | 239281f | 2014-11-03 10:33:19 +0100 | [diff] [blame] | 3439 | case NL80211_IFTYPE_OCB: |
| 3440 | if (!bssid) |
| 3441 | return false; |
Bertold Van den Bergh | cc11729 | 2015-08-05 16:02:42 +0200 | [diff] [blame] | 3442 | if (!ieee80211_is_data_present(hdr->frame_control)) |
Rostislav Lisovy | 239281f | 2014-11-03 10:33:19 +0100 | [diff] [blame] | 3443 | return false; |
Johannes Berg | a58fbe1 | 2015-04-22 15:08:39 +0200 | [diff] [blame] | 3444 | if (!is_broadcast_ether_addr(bssid)) |
Rostislav Lisovy | 239281f | 2014-11-03 10:33:19 +0100 | [diff] [blame] | 3445 | return false; |
Johannes Berg | a58fbe1 | 2015-04-22 15:08:39 +0200 | [diff] [blame] | 3446 | if (!multicast && |
| 3447 | !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1)) |
Johannes Berg | df14046 | 2015-04-22 14:40:58 +0200 | [diff] [blame] | 3448 | return false; |
Johannes Berg | a58fbe1 | 2015-04-22 15:08:39 +0200 | [diff] [blame] | 3449 | if (!rx->sta) { |
Rostislav Lisovy | 239281f | 2014-11-03 10:33:19 +0100 | [diff] [blame] | 3450 | int rate_idx; |
| 3451 | if (status->flag & RX_FLAG_HT) |
| 3452 | rate_idx = 0; /* TODO: HT rates */ |
| 3453 | else |
| 3454 | rate_idx = status->rate_idx; |
| 3455 | ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2, |
| 3456 | BIT(rate_idx)); |
| 3457 | } |
Johannes Berg | a58fbe1 | 2015-04-22 15:08:39 +0200 | [diff] [blame] | 3458 | return true; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 3459 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a58fbe1 | 2015-04-22 15:08:39 +0200 | [diff] [blame] | 3460 | if (multicast) |
| 3461 | return true; |
| 3462 | return ether_addr_equal(sdata->vif.addr, hdr->addr1); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 3463 | case NL80211_IFTYPE_AP_VLAN: |
| 3464 | case NL80211_IFTYPE_AP: |
Johannes Berg | a58fbe1 | 2015-04-22 15:08:39 +0200 | [diff] [blame] | 3465 | if (!bssid) |
| 3466 | return ether_addr_equal(sdata->vif.addr, hdr->addr1); |
| 3467 | |
| 3468 | if (!ieee80211_bssid_match(bssid, sdata->vif.addr)) { |
Johannes Berg | 3df6eae | 2011-12-06 10:39:40 +0100 | [diff] [blame] | 3469 | /* |
| 3470 | * Accept public action frames even when the |
| 3471 | * BSSID doesn't match, this is used for P2P |
| 3472 | * and location updates. Note that mac80211 |
| 3473 | * itself never looks at these frames. |
| 3474 | */ |
Johannes Berg | 2b9ccd4 | 2013-05-13 16:42:40 +0200 | [diff] [blame] | 3475 | if (!multicast && |
| 3476 | !ether_addr_equal(sdata->vif.addr, hdr->addr1)) |
Johannes Berg | 3c2723f5 | 2014-01-07 16:23:24 +0100 | [diff] [blame] | 3477 | return false; |
Johannes Berg | d48b296 | 2012-07-06 22:19:27 +0200 | [diff] [blame] | 3478 | if (ieee80211_is_public_action(hdr, skb->len)) |
Johannes Berg | 3c2723f5 | 2014-01-07 16:23:24 +0100 | [diff] [blame] | 3479 | return true; |
Johannes Berg | 5c90067 | 2015-04-22 14:48:34 +0200 | [diff] [blame] | 3480 | return ieee80211_is_beacon(hdr->frame_control); |
Johannes Berg | a58fbe1 | 2015-04-22 15:08:39 +0200 | [diff] [blame] | 3481 | } |
| 3482 | |
| 3483 | if (!ieee80211_has_tods(hdr->frame_control)) { |
Arik Nemtsov | db8e173 | 2014-07-17 17:14:30 +0300 | [diff] [blame] | 3484 | /* ignore data frames to TDLS-peers */ |
| 3485 | if (ieee80211_is_data(hdr->frame_control)) |
| 3486 | return false; |
| 3487 | /* ignore action frames to TDLS-peers */ |
| 3488 | if (ieee80211_is_action(hdr->frame_control) && |
Jouni Malinen | 1ec7bae | 2016-03-01 00:29:00 +0200 | [diff] [blame] | 3489 | !is_broadcast_ether_addr(bssid) && |
Arik Nemtsov | db8e173 | 2014-07-17 17:14:30 +0300 | [diff] [blame] | 3490 | !ether_addr_equal(bssid, hdr->addr1)) |
| 3491 | return false; |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 3492 | } |
Johannes Berg | a58fbe1 | 2015-04-22 15:08:39 +0200 | [diff] [blame] | 3493 | return true; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 3494 | case NL80211_IFTYPE_WDS: |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 3495 | if (bssid || !ieee80211_is_data(hdr->frame_control)) |
Johannes Berg | 3c2723f5 | 2014-01-07 16:23:24 +0100 | [diff] [blame] | 3496 | return false; |
Johannes Berg | a58fbe1 | 2015-04-22 15:08:39 +0200 | [diff] [blame] | 3497 | return ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2); |
Johannes Berg | f142c6b | 2012-06-18 20:07:15 +0200 | [diff] [blame] | 3498 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | a58fbe1 | 2015-04-22 15:08:39 +0200 | [diff] [blame] | 3499 | return ieee80211_is_public_action(hdr, skb->len) || |
| 3500 | ieee80211_is_probe_req(hdr->frame_control) || |
| 3501 | ieee80211_is_probe_resp(hdr->frame_control) || |
| 3502 | ieee80211_is_beacon(hdr->frame_control); |
Johannes Berg | 2ca27bc | 2010-09-16 14:58:23 +0200 | [diff] [blame] | 3503 | default: |
Johannes Berg | fb1c1cd | 2007-09-26 15:19:43 +0200 | [diff] [blame] | 3504 | break; |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 3505 | } |
| 3506 | |
Johannes Berg | a58fbe1 | 2015-04-22 15:08:39 +0200 | [diff] [blame] | 3507 | WARN_ON_ONCE(1); |
| 3508 | return false; |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 3509 | } |
| 3510 | |
Johannes Berg | 49ddf8e | 2016-03-31 20:02:10 +0300 | [diff] [blame^] | 3511 | void ieee80211_check_fast_rx(struct sta_info *sta) |
| 3512 | { |
| 3513 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 3514 | struct ieee80211_local *local = sdata->local; |
| 3515 | struct ieee80211_key *key; |
| 3516 | struct ieee80211_fast_rx fastrx = { |
| 3517 | .dev = sdata->dev, |
| 3518 | .vif_type = sdata->vif.type, |
| 3519 | .control_port_protocol = sdata->control_port_protocol, |
| 3520 | }, *old, *new = NULL; |
| 3521 | bool assign = false; |
| 3522 | |
| 3523 | /* use sparse to check that we don't return without updating */ |
| 3524 | __acquire(check_fast_rx); |
| 3525 | |
| 3526 | BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != sizeof(rfc1042_header)); |
| 3527 | BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != ETH_ALEN); |
| 3528 | ether_addr_copy(fastrx.rfc1042_hdr, rfc1042_header); |
| 3529 | ether_addr_copy(fastrx.vif_addr, sdata->vif.addr); |
| 3530 | |
| 3531 | /* fast-rx doesn't do reordering */ |
| 3532 | if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) && |
| 3533 | !ieee80211_hw_check(&local->hw, SUPPORTS_REORDERING_BUFFER)) |
| 3534 | goto clear; |
| 3535 | |
| 3536 | switch (sdata->vif.type) { |
| 3537 | case NL80211_IFTYPE_STATION: |
| 3538 | /* 4-addr is harder to deal with, later maybe */ |
| 3539 | if (sdata->u.mgd.use_4addr) |
| 3540 | goto clear; |
| 3541 | /* software powersave is a huge mess, avoid all of it */ |
| 3542 | if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) |
| 3543 | goto clear; |
| 3544 | if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) && |
| 3545 | !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) |
| 3546 | goto clear; |
| 3547 | if (sta->sta.tdls) { |
| 3548 | fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1); |
| 3549 | fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2); |
| 3550 | fastrx.expected_ds_bits = 0; |
| 3551 | } else { |
| 3552 | fastrx.sta_notify = sdata->u.mgd.probe_send_count > 0; |
| 3553 | fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1); |
| 3554 | fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr3); |
| 3555 | fastrx.expected_ds_bits = |
| 3556 | cpu_to_le16(IEEE80211_FCTL_FROMDS); |
| 3557 | } |
| 3558 | break; |
| 3559 | case NL80211_IFTYPE_AP_VLAN: |
| 3560 | case NL80211_IFTYPE_AP: |
| 3561 | /* parallel-rx requires this, at least with calls to |
| 3562 | * ieee80211_sta_ps_transition() |
| 3563 | */ |
| 3564 | if (!ieee80211_hw_check(&local->hw, AP_LINK_PS)) |
| 3565 | goto clear; |
| 3566 | fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3); |
| 3567 | fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2); |
| 3568 | fastrx.expected_ds_bits = cpu_to_le16(IEEE80211_FCTL_TODS); |
| 3569 | |
| 3570 | fastrx.internal_forward = |
| 3571 | !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) && |
| 3572 | (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || |
| 3573 | !sdata->u.vlan.sta); |
| 3574 | break; |
| 3575 | default: |
| 3576 | goto clear; |
| 3577 | } |
| 3578 | |
| 3579 | if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED)) |
| 3580 | goto clear; |
| 3581 | |
| 3582 | rcu_read_lock(); |
| 3583 | key = rcu_dereference(sta->ptk[sta->ptk_idx]); |
| 3584 | if (key) { |
| 3585 | switch (key->conf.cipher) { |
| 3586 | case WLAN_CIPHER_SUITE_TKIP: |
| 3587 | /* we don't want to deal with MMIC in fast-rx */ |
| 3588 | goto clear_rcu; |
| 3589 | case WLAN_CIPHER_SUITE_CCMP: |
| 3590 | case WLAN_CIPHER_SUITE_CCMP_256: |
| 3591 | case WLAN_CIPHER_SUITE_GCMP: |
| 3592 | case WLAN_CIPHER_SUITE_GCMP_256: |
| 3593 | break; |
| 3594 | default: |
| 3595 | /* we also don't want to deal with WEP or cipher scheme |
| 3596 | * since those require looking up the key idx in the |
| 3597 | * frame, rather than assuming the PTK is used |
| 3598 | * (we need to revisit this once we implement the real |
| 3599 | * PTK index, which is now valid in the spec, but we |
| 3600 | * haven't implemented that part yet) |
| 3601 | */ |
| 3602 | goto clear_rcu; |
| 3603 | } |
| 3604 | |
| 3605 | fastrx.key = true; |
| 3606 | fastrx.icv_len = key->conf.icv_len; |
| 3607 | } |
| 3608 | |
| 3609 | assign = true; |
| 3610 | clear_rcu: |
| 3611 | rcu_read_unlock(); |
| 3612 | clear: |
| 3613 | __release(check_fast_rx); |
| 3614 | |
| 3615 | if (assign) |
| 3616 | new = kmemdup(&fastrx, sizeof(fastrx), GFP_KERNEL); |
| 3617 | |
| 3618 | spin_lock_bh(&sta->lock); |
| 3619 | old = rcu_dereference_protected(sta->fast_rx, true); |
| 3620 | rcu_assign_pointer(sta->fast_rx, new); |
| 3621 | spin_unlock_bh(&sta->lock); |
| 3622 | |
| 3623 | if (old) |
| 3624 | kfree_rcu(old, rcu_head); |
| 3625 | } |
| 3626 | |
| 3627 | void ieee80211_clear_fast_rx(struct sta_info *sta) |
| 3628 | { |
| 3629 | struct ieee80211_fast_rx *old; |
| 3630 | |
| 3631 | spin_lock_bh(&sta->lock); |
| 3632 | old = rcu_dereference_protected(sta->fast_rx, true); |
| 3633 | RCU_INIT_POINTER(sta->fast_rx, NULL); |
| 3634 | spin_unlock_bh(&sta->lock); |
| 3635 | |
| 3636 | if (old) |
| 3637 | kfree_rcu(old, rcu_head); |
| 3638 | } |
| 3639 | |
| 3640 | void __ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata) |
| 3641 | { |
| 3642 | struct ieee80211_local *local = sdata->local; |
| 3643 | struct sta_info *sta; |
| 3644 | |
| 3645 | lockdep_assert_held(&local->sta_mtx); |
| 3646 | |
| 3647 | list_for_each_entry_rcu(sta, &local->sta_list, list) { |
| 3648 | if (sdata != sta->sdata && |
| 3649 | (!sta->sdata->bss || sta->sdata->bss != sdata->bss)) |
| 3650 | continue; |
| 3651 | ieee80211_check_fast_rx(sta); |
| 3652 | } |
| 3653 | } |
| 3654 | |
| 3655 | void ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata) |
| 3656 | { |
| 3657 | struct ieee80211_local *local = sdata->local; |
| 3658 | |
| 3659 | mutex_lock(&local->sta_mtx); |
| 3660 | __ieee80211_check_fast_rx_iface(sdata); |
| 3661 | mutex_unlock(&local->sta_mtx); |
| 3662 | } |
| 3663 | |
| 3664 | static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx, |
| 3665 | struct ieee80211_fast_rx *fast_rx) |
| 3666 | { |
| 3667 | struct sk_buff *skb = rx->skb; |
| 3668 | struct ieee80211_hdr *hdr = (void *)skb->data; |
| 3669 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
| 3670 | struct sta_info *sta = rx->sta; |
| 3671 | int orig_len = skb->len; |
| 3672 | int snap_offs = ieee80211_hdrlen(hdr->frame_control); |
| 3673 | struct { |
| 3674 | u8 snap[sizeof(rfc1042_header)]; |
| 3675 | __be16 proto; |
| 3676 | } *payload __aligned(2); |
| 3677 | struct { |
| 3678 | u8 da[ETH_ALEN]; |
| 3679 | u8 sa[ETH_ALEN]; |
| 3680 | } addrs __aligned(2); |
| 3681 | |
| 3682 | /* for parallel-rx, we need to have DUP_VALIDATED, otherwise we write |
| 3683 | * to a common data structure; drivers can implement that per queue |
| 3684 | * but we don't have that information in mac80211 |
| 3685 | */ |
| 3686 | if (!(status->flag & RX_FLAG_DUP_VALIDATED)) |
| 3687 | return false; |
| 3688 | |
| 3689 | #define FAST_RX_CRYPT_FLAGS (RX_FLAG_PN_VALIDATED | RX_FLAG_DECRYPTED) |
| 3690 | |
| 3691 | /* If using encryption, we also need to have: |
| 3692 | * - PN_VALIDATED: similar, but the implementation is tricky |
| 3693 | * - DECRYPTED: necessary for PN_VALIDATED |
| 3694 | */ |
| 3695 | if (fast_rx->key && |
| 3696 | (status->flag & FAST_RX_CRYPT_FLAGS) != FAST_RX_CRYPT_FLAGS) |
| 3697 | return false; |
| 3698 | |
| 3699 | /* we don't deal with A-MSDU deaggregation here */ |
| 3700 | if (status->rx_flags & IEEE80211_RX_AMSDU) |
| 3701 | return false; |
| 3702 | |
| 3703 | if (unlikely(!ieee80211_is_data_present(hdr->frame_control))) |
| 3704 | return false; |
| 3705 | |
| 3706 | if (unlikely(ieee80211_is_frag(hdr))) |
| 3707 | return false; |
| 3708 | |
| 3709 | /* Since our interface address cannot be multicast, this |
| 3710 | * implicitly also rejects multicast frames without the |
| 3711 | * explicit check. |
| 3712 | * |
| 3713 | * We shouldn't get any *data* frames not addressed to us |
| 3714 | * (AP mode will accept multicast *management* frames), but |
| 3715 | * punting here will make it go through the full checks in |
| 3716 | * ieee80211_accept_frame(). |
| 3717 | */ |
| 3718 | if (!ether_addr_equal(fast_rx->vif_addr, hdr->addr1)) |
| 3719 | return false; |
| 3720 | |
| 3721 | if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FROMDS | |
| 3722 | IEEE80211_FCTL_TODS)) != |
| 3723 | fast_rx->expected_ds_bits) |
| 3724 | goto drop; |
| 3725 | |
| 3726 | /* assign the key to drop unencrypted frames (later) |
| 3727 | * and strip the IV/MIC if necessary |
| 3728 | */ |
| 3729 | if (fast_rx->key && !(status->flag & RX_FLAG_IV_STRIPPED)) { |
| 3730 | /* GCMP header length is the same */ |
| 3731 | snap_offs += IEEE80211_CCMP_HDR_LEN; |
| 3732 | } |
| 3733 | |
| 3734 | if (!pskb_may_pull(skb, snap_offs + sizeof(*payload))) |
| 3735 | goto drop; |
| 3736 | payload = (void *)(skb->data + snap_offs); |
| 3737 | |
| 3738 | if (!ether_addr_equal(payload->snap, fast_rx->rfc1042_hdr)) |
| 3739 | return false; |
| 3740 | |
| 3741 | /* Don't handle these here since they require special code. |
| 3742 | * Accept AARP and IPX even though they should come with a |
| 3743 | * bridge-tunnel header - but if we get them this way then |
| 3744 | * there's little point in discarding them. |
| 3745 | */ |
| 3746 | if (unlikely(payload->proto == cpu_to_be16(ETH_P_TDLS) || |
| 3747 | payload->proto == fast_rx->control_port_protocol)) |
| 3748 | return false; |
| 3749 | |
| 3750 | /* after this point, don't punt to the slowpath! */ |
| 3751 | |
| 3752 | if (rx->key && !(status->flag & RX_FLAG_MIC_STRIPPED) && |
| 3753 | pskb_trim(skb, skb->len - fast_rx->icv_len)) |
| 3754 | goto drop; |
| 3755 | |
| 3756 | if (unlikely(fast_rx->sta_notify)) { |
| 3757 | ieee80211_sta_rx_notify(rx->sdata, hdr); |
| 3758 | fast_rx->sta_notify = false; |
| 3759 | } |
| 3760 | |
| 3761 | /* statistics part of ieee80211_rx_h_sta_process() */ |
| 3762 | sta->rx_stats.last_rx = jiffies; |
| 3763 | sta->rx_stats.last_rate = sta_stats_encode_rate(status); |
| 3764 | |
| 3765 | sta->rx_stats.fragments++; |
| 3766 | |
| 3767 | if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) { |
| 3768 | sta->rx_stats.last_signal = status->signal; |
| 3769 | ewma_signal_add(&sta->rx_stats_avg.signal, -status->signal); |
| 3770 | } |
| 3771 | |
| 3772 | if (status->chains) { |
| 3773 | int i; |
| 3774 | |
| 3775 | sta->rx_stats.chains = status->chains; |
| 3776 | for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) { |
| 3777 | int signal = status->chain_signal[i]; |
| 3778 | |
| 3779 | if (!(status->chains & BIT(i))) |
| 3780 | continue; |
| 3781 | |
| 3782 | sta->rx_stats.chain_signal_last[i] = signal; |
| 3783 | ewma_signal_add(&sta->rx_stats_avg.chain_signal[i], |
| 3784 | -signal); |
| 3785 | } |
| 3786 | } |
| 3787 | /* end of statistics */ |
| 3788 | |
| 3789 | if (rx->key && !ieee80211_has_protected(hdr->frame_control)) |
| 3790 | goto drop; |
| 3791 | |
| 3792 | /* do the header conversion - first grab the addresses */ |
| 3793 | ether_addr_copy(addrs.da, skb->data + fast_rx->da_offs); |
| 3794 | ether_addr_copy(addrs.sa, skb->data + fast_rx->sa_offs); |
| 3795 | /* remove the SNAP but leave the ethertype */ |
| 3796 | skb_pull(skb, snap_offs + sizeof(rfc1042_header)); |
| 3797 | /* push the addresses in front */ |
| 3798 | memcpy(skb_push(skb, sizeof(addrs)), &addrs, sizeof(addrs)); |
| 3799 | |
| 3800 | skb->dev = fast_rx->dev; |
| 3801 | |
| 3802 | ieee80211_rx_stats(fast_rx->dev, skb->len); |
| 3803 | |
| 3804 | /* The seqno index has the same property as needed |
| 3805 | * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS |
| 3806 | * for non-QoS-data frames. Here we know it's a data |
| 3807 | * frame, so count MSDUs. |
| 3808 | */ |
| 3809 | u64_stats_update_begin(&sta->rx_stats.syncp); |
| 3810 | sta->rx_stats.msdu[rx->seqno_idx]++; |
| 3811 | sta->rx_stats.bytes += orig_len; |
| 3812 | u64_stats_update_end(&sta->rx_stats.syncp); |
| 3813 | |
| 3814 | if (fast_rx->internal_forward) { |
| 3815 | struct sta_info *dsta = sta_info_get(rx->sdata, skb->data); |
| 3816 | |
| 3817 | if (dsta) { |
| 3818 | /* |
| 3819 | * Send to wireless media and increase priority by 256 |
| 3820 | * to keep the received priority instead of |
| 3821 | * reclassifying the frame (see cfg80211_classify8021d). |
| 3822 | */ |
| 3823 | skb->priority += 256; |
| 3824 | skb->protocol = htons(ETH_P_802_3); |
| 3825 | skb_reset_network_header(skb); |
| 3826 | skb_reset_mac_header(skb); |
| 3827 | dev_queue_xmit(skb); |
| 3828 | return true; |
| 3829 | } |
| 3830 | } |
| 3831 | |
| 3832 | /* deliver to local stack */ |
| 3833 | skb->protocol = eth_type_trans(skb, fast_rx->dev); |
| 3834 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 3835 | if (rx->napi) |
| 3836 | napi_gro_receive(rx->napi, skb); |
| 3837 | else |
| 3838 | netif_receive_skb(skb); |
| 3839 | |
| 3840 | return true; |
| 3841 | drop: |
| 3842 | dev_kfree_skb(skb); |
| 3843 | sta->rx_stats.dropped++; |
| 3844 | return true; |
| 3845 | } |
| 3846 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 3847 | /* |
Johannes Berg | 4406c37 | 2010-09-24 11:21:06 +0200 | [diff] [blame] | 3848 | * This function returns whether or not the SKB |
| 3849 | * was destined for RX processing or not, which, |
| 3850 | * if consume is true, is equivalent to whether |
| 3851 | * or not the skb was consumed. |
| 3852 | */ |
| 3853 | static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx, |
| 3854 | struct sk_buff *skb, bool consume) |
| 3855 | { |
| 3856 | struct ieee80211_local *local = rx->local; |
| 3857 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
Johannes Berg | 4406c37 | 2010-09-24 11:21:06 +0200 | [diff] [blame] | 3858 | |
| 3859 | rx->skb = skb; |
Johannes Berg | 4406c37 | 2010-09-24 11:21:06 +0200 | [diff] [blame] | 3860 | |
Johannes Berg | 49ddf8e | 2016-03-31 20:02:10 +0300 | [diff] [blame^] | 3861 | /* See if we can do fast-rx; if we have to copy we already lost, |
| 3862 | * so punt in that case. We should never have to deliver a data |
| 3863 | * frame to multiple interfaces anyway. |
| 3864 | * |
| 3865 | * We skip the ieee80211_accept_frame() call and do the necessary |
| 3866 | * checking inside ieee80211_invoke_fast_rx(). |
| 3867 | */ |
| 3868 | if (consume && rx->sta) { |
| 3869 | struct ieee80211_fast_rx *fast_rx; |
| 3870 | |
| 3871 | fast_rx = rcu_dereference(rx->sta->fast_rx); |
| 3872 | if (fast_rx && ieee80211_invoke_fast_rx(rx, fast_rx)) |
| 3873 | return true; |
| 3874 | } |
| 3875 | |
Johannes Berg | a58fbe1 | 2015-04-22 15:08:39 +0200 | [diff] [blame] | 3876 | if (!ieee80211_accept_frame(rx)) |
Johannes Berg | 4406c37 | 2010-09-24 11:21:06 +0200 | [diff] [blame] | 3877 | return false; |
| 3878 | |
Johannes Berg | 4406c37 | 2010-09-24 11:21:06 +0200 | [diff] [blame] | 3879 | if (!consume) { |
| 3880 | skb = skb_copy(skb, GFP_ATOMIC); |
| 3881 | if (!skb) { |
| 3882 | if (net_ratelimit()) |
| 3883 | wiphy_debug(local->hw.wiphy, |
Ben Greear | b305dae | 2011-01-08 10:30:54 -0800 | [diff] [blame] | 3884 | "failed to copy skb for %s\n", |
Johannes Berg | 4406c37 | 2010-09-24 11:21:06 +0200 | [diff] [blame] | 3885 | sdata->name); |
| 3886 | return true; |
| 3887 | } |
| 3888 | |
| 3889 | rx->skb = skb; |
| 3890 | } |
| 3891 | |
| 3892 | ieee80211_invoke_rx_handlers(rx); |
| 3893 | return true; |
| 3894 | } |
| 3895 | |
| 3896 | /* |
Zhao, Gang | 6b59db7 | 2014-04-21 12:52:59 +0800 | [diff] [blame] | 3897 | * This is the actual Rx frames handler. as it belongs to Rx path it must |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 3898 | * be called with rcu_read_lock protection. |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 3899 | */ |
Ron Rindjunsky | 71ebb4a | 2008-01-21 12:39:12 +0200 | [diff] [blame] | 3900 | static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, |
Johannes Berg | d63b548 | 2016-03-31 20:02:02 +0300 | [diff] [blame] | 3901 | struct ieee80211_sta *pubsta, |
Johannes Berg | af9f9b2 | 2015-06-11 16:02:32 +0200 | [diff] [blame] | 3902 | struct sk_buff *skb, |
| 3903 | struct napi_struct *napi) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 3904 | { |
| 3905 | struct ieee80211_local *local = hw_to_local(hw); |
| 3906 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 3907 | struct ieee80211_hdr *hdr; |
Zhu Yi | e3cf8b3f | 2010-03-29 17:35:07 +0800 | [diff] [blame] | 3908 | __le16 fc; |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 3909 | struct ieee80211_rx_data rx; |
Johannes Berg | 4406c37 | 2010-09-24 11:21:06 +0200 | [diff] [blame] | 3910 | struct ieee80211_sub_if_data *prev; |
Johannes Berg | 7bedd0c | 2015-02-13 21:55:15 +0100 | [diff] [blame] | 3911 | struct rhash_head *tmp; |
Zhu Yi | e3cf8b3f | 2010-03-29 17:35:07 +0800 | [diff] [blame] | 3912 | int err = 0; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 3913 | |
Zhu Yi | e3cf8b3f | 2010-03-29 17:35:07 +0800 | [diff] [blame] | 3914 | fc = ((struct ieee80211_hdr *)skb->data)->frame_control; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 3915 | memset(&rx, 0, sizeof(rx)); |
| 3916 | rx.skb = skb; |
| 3917 | rx.local = local; |
Johannes Berg | af9f9b2 | 2015-06-11 16:02:32 +0200 | [diff] [blame] | 3918 | rx.napi = napi; |
Johannes Berg | 72abd81 | 2007-09-17 01:29:22 -0400 | [diff] [blame] | 3919 | |
Zhu Yi | e3cf8b3f | 2010-03-29 17:35:07 +0800 | [diff] [blame] | 3920 | if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc)) |
Johannes Berg | c206ca6 | 2015-04-22 20:47:28 +0200 | [diff] [blame] | 3921 | I802_DEBUG_INC(local->dot11ReceivedFragmentCount); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 3922 | |
Johannes Berg | 4a4f1a5 | 2012-10-26 00:33:36 +0200 | [diff] [blame] | 3923 | if (ieee80211_is_mgmt(fc)) { |
| 3924 | /* drop frame if too short for header */ |
| 3925 | if (skb->len < ieee80211_hdrlen(fc)) |
| 3926 | err = -ENOBUFS; |
| 3927 | else |
| 3928 | err = skb_linearize(skb); |
| 3929 | } else { |
Zhu Yi | e3cf8b3f | 2010-03-29 17:35:07 +0800 | [diff] [blame] | 3930 | err = !pskb_may_pull(skb, ieee80211_hdrlen(fc)); |
Johannes Berg | 4a4f1a5 | 2012-10-26 00:33:36 +0200 | [diff] [blame] | 3931 | } |
Zhu Yi | e3cf8b3f | 2010-03-29 17:35:07 +0800 | [diff] [blame] | 3932 | |
| 3933 | if (err) { |
| 3934 | dev_kfree_skb(skb); |
| 3935 | return; |
| 3936 | } |
| 3937 | |
| 3938 | hdr = (struct ieee80211_hdr *)skb->data; |
Johannes Berg | 38f3714 | 2008-01-29 17:07:43 +0100 | [diff] [blame] | 3939 | ieee80211_parse_qos(&rx); |
Johannes Berg | d1c3a37 | 2009-01-07 00:26:10 +0100 | [diff] [blame] | 3940 | ieee80211_verify_alignment(&rx); |
Johannes Berg | 38f3714 | 2008-01-29 17:07:43 +0100 | [diff] [blame] | 3941 | |
Johannes Berg | d48b296 | 2012-07-06 22:19:27 +0200 | [diff] [blame] | 3942 | if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) || |
| 3943 | ieee80211_is_beacon(hdr->frame_control))) |
| 3944 | ieee80211_scan_rx(local, skb); |
| 3945 | |
Johannes Berg | d63b548 | 2016-03-31 20:02:02 +0300 | [diff] [blame] | 3946 | if (pubsta) { |
| 3947 | rx.sta = container_of(pubsta, struct sta_info, sta); |
| 3948 | rx.sdata = rx.sta->sdata; |
| 3949 | if (ieee80211_prepare_and_rx_handle(&rx, skb, true)) |
| 3950 | return; |
| 3951 | goto out; |
| 3952 | } else if (ieee80211_is_data(fc)) { |
| 3953 | struct sta_info *sta, *prev_sta; |
Johannes Berg | 7bedd0c | 2015-02-13 21:55:15 +0100 | [diff] [blame] | 3954 | const struct bucket_table *tbl; |
| 3955 | |
Ben Greear | 56af326 | 2010-09-23 10:22:24 -0700 | [diff] [blame] | 3956 | prev_sta = NULL; |
Johannes Berg | 4406c37 | 2010-09-24 11:21:06 +0200 | [diff] [blame] | 3957 | |
Johannes Berg | 7bedd0c | 2015-02-13 21:55:15 +0100 | [diff] [blame] | 3958 | tbl = rht_dereference_rcu(local->sta_hash.tbl, &local->sta_hash); |
| 3959 | |
| 3960 | for_each_sta_info(local, tbl, hdr->addr2, sta, tmp) { |
Ben Greear | 56af326 | 2010-09-23 10:22:24 -0700 | [diff] [blame] | 3961 | if (!prev_sta) { |
| 3962 | prev_sta = sta; |
| 3963 | continue; |
| 3964 | } |
| 3965 | |
| 3966 | rx.sta = prev_sta; |
| 3967 | rx.sdata = prev_sta->sdata; |
Johannes Berg | 4406c37 | 2010-09-24 11:21:06 +0200 | [diff] [blame] | 3968 | ieee80211_prepare_and_rx_handle(&rx, skb, false); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 3969 | |
Ben Greear | 56af326 | 2010-09-23 10:22:24 -0700 | [diff] [blame] | 3970 | prev_sta = sta; |
Johannes Berg | 4406c37 | 2010-09-24 11:21:06 +0200 | [diff] [blame] | 3971 | } |
Ben Greear | 56af326 | 2010-09-23 10:22:24 -0700 | [diff] [blame] | 3972 | |
| 3973 | if (prev_sta) { |
| 3974 | rx.sta = prev_sta; |
| 3975 | rx.sdata = prev_sta->sdata; |
| 3976 | |
Johannes Berg | 4406c37 | 2010-09-24 11:21:06 +0200 | [diff] [blame] | 3977 | if (ieee80211_prepare_and_rx_handle(&rx, skb, true)) |
Ben Greear | 56af326 | 2010-09-23 10:22:24 -0700 | [diff] [blame] | 3978 | return; |
Senthil Balasubramanian | 8e26d5a | 2010-11-30 20:15:38 +0530 | [diff] [blame] | 3979 | goto out; |
Ben Greear | 56af326 | 2010-09-23 10:22:24 -0700 | [diff] [blame] | 3980 | } |
Johannes Berg | 4406c37 | 2010-09-24 11:21:06 +0200 | [diff] [blame] | 3981 | } |
| 3982 | |
Johannes Berg | 4b0dd98 | 2010-09-24 11:21:07 +0200 | [diff] [blame] | 3983 | prev = NULL; |
Johannes Berg | 4406c37 | 2010-09-24 11:21:06 +0200 | [diff] [blame] | 3984 | |
Johannes Berg | 4b0dd98 | 2010-09-24 11:21:07 +0200 | [diff] [blame] | 3985 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
| 3986 | if (!ieee80211_sdata_running(sdata)) |
| 3987 | continue; |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 3988 | |
Johannes Berg | 4b0dd98 | 2010-09-24 11:21:07 +0200 | [diff] [blame] | 3989 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR || |
| 3990 | sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
| 3991 | continue; |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 3992 | |
Johannes Berg | 4b0dd98 | 2010-09-24 11:21:07 +0200 | [diff] [blame] | 3993 | /* |
| 3994 | * frame is destined for this interface, but if it's |
| 3995 | * not also for the previous one we handle that after |
| 3996 | * the loop to avoid copying the SKB once too much |
| 3997 | */ |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 3998 | |
Johannes Berg | 4b0dd98 | 2010-09-24 11:21:07 +0200 | [diff] [blame] | 3999 | if (!prev) { |
Johannes Berg | 340e11f | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4000 | prev = sdata; |
Johannes Berg | 4b0dd98 | 2010-09-24 11:21:07 +0200 | [diff] [blame] | 4001 | continue; |
Johannes Berg | 8e6f0032 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4002 | } |
Felix Fietkau | 4bb29f8 | 2010-01-22 00:36:39 +0100 | [diff] [blame] | 4003 | |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 4004 | rx.sta = sta_info_get_bss(prev, hdr->addr2); |
Johannes Berg | 4b0dd98 | 2010-09-24 11:21:07 +0200 | [diff] [blame] | 4005 | rx.sdata = prev; |
| 4006 | ieee80211_prepare_and_rx_handle(&rx, skb, false); |
Felix Fietkau | 4bb29f8 | 2010-01-22 00:36:39 +0100 | [diff] [blame] | 4007 | |
Johannes Berg | 4b0dd98 | 2010-09-24 11:21:07 +0200 | [diff] [blame] | 4008 | prev = sdata; |
| 4009 | } |
Johannes Berg | 4406c37 | 2010-09-24 11:21:06 +0200 | [diff] [blame] | 4010 | |
Johannes Berg | 4b0dd98 | 2010-09-24 11:21:07 +0200 | [diff] [blame] | 4011 | if (prev) { |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 4012 | rx.sta = sta_info_get_bss(prev, hdr->addr2); |
Johannes Berg | 4b0dd98 | 2010-09-24 11:21:07 +0200 | [diff] [blame] | 4013 | rx.sdata = prev; |
| 4014 | |
| 4015 | if (ieee80211_prepare_and_rx_handle(&rx, skb, true)) |
| 4016 | return; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4017 | } |
Johannes Berg | 4406c37 | 2010-09-24 11:21:06 +0200 | [diff] [blame] | 4018 | |
Senthil Balasubramanian | 8e26d5a | 2010-11-30 20:15:38 +0530 | [diff] [blame] | 4019 | out: |
Johannes Berg | 4406c37 | 2010-09-24 11:21:06 +0200 | [diff] [blame] | 4020 | dev_kfree_skb(skb); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4021 | } |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 4022 | |
| 4023 | /* |
| 4024 | * This is the receive path handler. It is called by a low level driver when an |
| 4025 | * 802.11 MPDU is received from the hardware. |
| 4026 | */ |
Johannes Berg | d63b548 | 2016-03-31 20:02:02 +0300 | [diff] [blame] | 4027 | void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta, |
| 4028 | struct sk_buff *skb, struct napi_struct *napi) |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 4029 | { |
| 4030 | struct ieee80211_local *local = hw_to_local(hw); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4031 | struct ieee80211_rate *rate = NULL; |
| 4032 | struct ieee80211_supported_band *sband; |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 4033 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4034 | |
Johannes Berg | d20ef63 | 2009-10-11 15:10:40 +0200 | [diff] [blame] | 4035 | WARN_ON_ONCE(softirq_count() == 0); |
| 4036 | |
Johannes Berg | 444e380 | 2012-09-30 17:08:35 +0200 | [diff] [blame] | 4037 | if (WARN_ON(status->band >= IEEE80211_NUM_BANDS)) |
Johannes Berg | 77a980d | 2009-08-24 11:46:30 +0200 | [diff] [blame] | 4038 | goto drop; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4039 | |
| 4040 | sband = local->hw.wiphy->bands[status->band]; |
Johannes Berg | 77a980d | 2009-08-24 11:46:30 +0200 | [diff] [blame] | 4041 | if (WARN_ON(!sband)) |
| 4042 | goto drop; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4043 | |
Johannes Berg | 89c3a8a | 2009-07-28 18:10:17 +0200 | [diff] [blame] | 4044 | /* |
| 4045 | * If we're suspending, it is possible although not too likely |
| 4046 | * that we'd be receiving frames after having already partially |
| 4047 | * quiesced the stack. We can't process such frames then since |
| 4048 | * that might, for example, cause stations to be added or other |
| 4049 | * driver callbacks be invoked. |
| 4050 | */ |
Johannes Berg | 77a980d | 2009-08-24 11:46:30 +0200 | [diff] [blame] | 4051 | if (unlikely(local->quiescing || local->suspended)) |
| 4052 | goto drop; |
Johannes Berg | 89c3a8a | 2009-07-28 18:10:17 +0200 | [diff] [blame] | 4053 | |
Arik Nemtsov | 04800ad | 2012-06-06 11:25:02 +0300 | [diff] [blame] | 4054 | /* We might be during a HW reconfig, prevent Rx for the same reason */ |
| 4055 | if (unlikely(local->in_reconfig)) |
| 4056 | goto drop; |
| 4057 | |
Johannes Berg | ea77f12 | 2009-08-21 14:44:45 +0200 | [diff] [blame] | 4058 | /* |
| 4059 | * The same happens when we're not even started, |
| 4060 | * but that's worth a warning. |
| 4061 | */ |
Johannes Berg | 77a980d | 2009-08-24 11:46:30 +0200 | [diff] [blame] | 4062 | if (WARN_ON(!local->started)) |
| 4063 | goto drop; |
Johannes Berg | ea77f12 | 2009-08-21 14:44:45 +0200 | [diff] [blame] | 4064 | |
Johannes Berg | fc88518 | 2010-07-30 13:23:12 +0200 | [diff] [blame] | 4065 | if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) { |
Luis R. Rodriguez | e5d6eb8 | 2009-11-09 16:03:22 -0500 | [diff] [blame] | 4066 | /* |
Johannes Berg | fc88518 | 2010-07-30 13:23:12 +0200 | [diff] [blame] | 4067 | * Validate the rate, unless a PLCP error means that |
| 4068 | * we probably can't have a valid rate here anyway. |
Luis R. Rodriguez | e5d6eb8 | 2009-11-09 16:03:22 -0500 | [diff] [blame] | 4069 | */ |
Johannes Berg | fc88518 | 2010-07-30 13:23:12 +0200 | [diff] [blame] | 4070 | |
| 4071 | if (status->flag & RX_FLAG_HT) { |
| 4072 | /* |
| 4073 | * rate_idx is MCS index, which can be [0-76] |
| 4074 | * as documented on: |
| 4075 | * |
| 4076 | * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n |
| 4077 | * |
| 4078 | * Anything else would be some sort of driver or |
| 4079 | * hardware error. The driver should catch hardware |
| 4080 | * errors. |
| 4081 | */ |
Johannes Berg | 444e380 | 2012-09-30 17:08:35 +0200 | [diff] [blame] | 4082 | if (WARN(status->rate_idx > 76, |
Johannes Berg | fc88518 | 2010-07-30 13:23:12 +0200 | [diff] [blame] | 4083 | "Rate marked as an HT rate but passed " |
| 4084 | "status->rate_idx is not " |
| 4085 | "an MCS index [0-76]: %d (0x%02x)\n", |
| 4086 | status->rate_idx, |
| 4087 | status->rate_idx)) |
| 4088 | goto drop; |
Johannes Berg | 5614618 | 2012-11-09 15:07:02 +0100 | [diff] [blame] | 4089 | } else if (status->flag & RX_FLAG_VHT) { |
| 4090 | if (WARN_ONCE(status->rate_idx > 9 || |
| 4091 | !status->vht_nss || |
| 4092 | status->vht_nss > 8, |
| 4093 | "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n", |
| 4094 | status->rate_idx, status->vht_nss)) |
| 4095 | goto drop; |
Johannes Berg | fc88518 | 2010-07-30 13:23:12 +0200 | [diff] [blame] | 4096 | } else { |
Johannes Berg | 444e380 | 2012-09-30 17:08:35 +0200 | [diff] [blame] | 4097 | if (WARN_ON(status->rate_idx >= sband->n_bitrates)) |
Johannes Berg | fc88518 | 2010-07-30 13:23:12 +0200 | [diff] [blame] | 4098 | goto drop; |
| 4099 | rate = &sband->bitrates[status->rate_idx]; |
| 4100 | } |
Jouni Malinen | 0fb8ca4 | 2008-12-12 14:38:33 +0200 | [diff] [blame] | 4101 | } |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 4102 | |
Johannes Berg | 554891e | 2010-09-24 12:38:25 +0200 | [diff] [blame] | 4103 | status->rx_flags = 0; |
| 4104 | |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 4105 | /* |
| 4106 | * key references and virtual interfaces are protected using RCU |
| 4107 | * and this requires that we are in a read-side RCU section during |
| 4108 | * receive processing |
| 4109 | */ |
| 4110 | rcu_read_lock(); |
| 4111 | |
| 4112 | /* |
| 4113 | * Frames with failed FCS/PLCP checksum are not returned, |
| 4114 | * all other frames are returned without radiotap header |
| 4115 | * if it was previously present. |
| 4116 | * Also, frames with less than 16 bytes are dropped. |
| 4117 | */ |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 4118 | skb = ieee80211_rx_monitor(local, skb, rate); |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 4119 | if (!skb) { |
| 4120 | rcu_read_unlock(); |
| 4121 | return; |
| 4122 | } |
| 4123 | |
Johannes Berg | e1e5406 | 2010-11-30 08:58:45 +0100 | [diff] [blame] | 4124 | ieee80211_tpt_led_trig_rx(local, |
| 4125 | ((struct ieee80211_hdr *)skb->data)->frame_control, |
| 4126 | skb->len); |
Johannes Berg | d63b548 | 2016-03-31 20:02:02 +0300 | [diff] [blame] | 4127 | |
| 4128 | __ieee80211_rx_handle_packet(hw, pubsta, skb, napi); |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 4129 | |
| 4130 | rcu_read_unlock(); |
Johannes Berg | 77a980d | 2009-08-24 11:46:30 +0200 | [diff] [blame] | 4131 | |
| 4132 | return; |
| 4133 | drop: |
| 4134 | kfree_skb(skb); |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 4135 | } |
Johannes Berg | af9f9b2 | 2015-06-11 16:02:32 +0200 | [diff] [blame] | 4136 | EXPORT_SYMBOL(ieee80211_rx_napi); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4137 | |
| 4138 | /* This is a version of the rx handler that can be called from hard irq |
| 4139 | * context. Post the skb on the queue and schedule the tasklet */ |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 4140 | void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4141 | { |
| 4142 | struct ieee80211_local *local = hw_to_local(hw); |
| 4143 | |
| 4144 | BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb)); |
| 4145 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4146 | skb->pkt_type = IEEE80211_RX_MSG; |
| 4147 | skb_queue_tail(&local->skb_queue, skb); |
| 4148 | tasklet_schedule(&local->tasklet); |
| 4149 | } |
| 4150 | EXPORT_SYMBOL(ieee80211_rx_irqsafe); |