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