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