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