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> |
| 5 | * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | |
S.Çağlar Onur | ab46623 | 2008-02-14 17:36:47 +0200 | [diff] [blame] | 12 | #include <linux/jiffies.h> |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 13 | #include <linux/kernel.h> |
| 14 | #include <linux/skbuff.h> |
| 15 | #include <linux/netdevice.h> |
| 16 | #include <linux/etherdevice.h> |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 17 | #include <linux/rcupdate.h> |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 18 | #include <net/mac80211.h> |
| 19 | #include <net/ieee80211_radiotap.h> |
| 20 | |
| 21 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 22 | #include "driver-ops.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 23 | #include "led.h" |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 24 | #include "mesh.h" |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 25 | #include "wep.h" |
| 26 | #include "wpa.h" |
| 27 | #include "tkip.h" |
| 28 | #include "wme.h" |
| 29 | |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame^] | 30 | static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, |
| 31 | struct sk_buff *skb, |
| 32 | struct ieee80211_rate *rate); |
Johannes Berg | a02ae75 | 2009-11-16 12:00:40 +0100 | [diff] [blame] | 33 | |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 34 | /* |
| 35 | * monitor mode reception |
| 36 | * |
| 37 | * This function cleans up the SKB, i.e. it removes all the stuff |
| 38 | * only useful for monitoring. |
| 39 | */ |
| 40 | static struct sk_buff *remove_monitor_info(struct ieee80211_local *local, |
Johannes Berg | 0869aea | 2009-10-28 10:03:35 +0100 | [diff] [blame] | 41 | struct sk_buff *skb) |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 42 | { |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 43 | if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) { |
| 44 | if (likely(skb->len > FCS_LEN)) |
| 45 | skb_trim(skb, skb->len - FCS_LEN); |
| 46 | else { |
| 47 | /* driver bug */ |
| 48 | WARN_ON(1); |
| 49 | dev_kfree_skb(skb); |
| 50 | skb = NULL; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | return skb; |
| 55 | } |
| 56 | |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 57 | static inline int should_drop_frame(struct sk_buff *skb, |
Johannes Berg | 0869aea | 2009-10-28 10:03:35 +0100 | [diff] [blame] | 58 | int present_fcs_len) |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 59 | { |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 60 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
Harvey Harrison | 182503a | 2008-06-22 16:45:29 -0700 | [diff] [blame] | 61 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 62 | |
| 63 | if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC)) |
| 64 | return 1; |
Johannes Berg | 0869aea | 2009-10-28 10:03:35 +0100 | [diff] [blame] | 65 | if (unlikely(skb->len < 16 + present_fcs_len)) |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 66 | return 1; |
Harvey Harrison | 87228f5 | 2008-06-11 14:21:59 -0700 | [diff] [blame] | 67 | if (ieee80211_is_ctl(hdr->frame_control) && |
| 68 | !ieee80211_is_pspoll(hdr->frame_control) && |
| 69 | !ieee80211_is_back_req(hdr->frame_control)) |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 70 | return 1; |
| 71 | return 0; |
| 72 | } |
| 73 | |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 74 | static int |
| 75 | ieee80211_rx_radiotap_len(struct ieee80211_local *local, |
| 76 | struct ieee80211_rx_status *status) |
| 77 | { |
| 78 | int len; |
| 79 | |
| 80 | /* always present fields */ |
| 81 | len = sizeof(struct ieee80211_radiotap_header) + 9; |
| 82 | |
| 83 | if (status->flag & RX_FLAG_TSFT) |
| 84 | len += 8; |
Johannes Berg | 7fee537 | 2009-01-30 11:13:06 +0100 | [diff] [blame] | 85 | if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 86 | len += 1; |
| 87 | if (local->hw.flags & IEEE80211_HW_NOISE_DBM) |
| 88 | len += 1; |
| 89 | |
| 90 | if (len & 1) /* padding for RX_FLAGS if necessary */ |
| 91 | len++; |
| 92 | |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 93 | return len; |
| 94 | } |
| 95 | |
Johannes Berg | d1c3a37 | 2009-01-07 00:26:10 +0100 | [diff] [blame] | 96 | /* |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 97 | * ieee80211_add_rx_radiotap_header - add radiotap header |
| 98 | * |
| 99 | * add a radiotap header containing all the fields which the hardware provided. |
| 100 | */ |
| 101 | static void |
| 102 | ieee80211_add_rx_radiotap_header(struct ieee80211_local *local, |
| 103 | struct sk_buff *skb, |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 104 | struct ieee80211_rate *rate, |
| 105 | int rtap_len) |
| 106 | { |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 107 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 108 | struct ieee80211_radiotap_header *rthdr; |
| 109 | unsigned char *pos; |
Johannes Berg | 6a86b9c | 2009-10-28 09:58:52 +0100 | [diff] [blame] | 110 | u16 rx_flags = 0; |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 111 | |
| 112 | rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len); |
| 113 | memset(rthdr, 0, rtap_len); |
| 114 | |
| 115 | /* radiotap header, set always present flags */ |
| 116 | rthdr->it_present = |
| 117 | cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) | |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 118 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 119 | (1 << IEEE80211_RADIOTAP_ANTENNA) | |
| 120 | (1 << IEEE80211_RADIOTAP_RX_FLAGS)); |
| 121 | rthdr->it_len = cpu_to_le16(rtap_len); |
| 122 | |
| 123 | pos = (unsigned char *)(rthdr+1); |
| 124 | |
| 125 | /* the order of the following fields is important */ |
| 126 | |
| 127 | /* IEEE80211_RADIOTAP_TSFT */ |
| 128 | if (status->flag & RX_FLAG_TSFT) { |
Johannes Berg | 6a86b9c | 2009-10-28 09:58:52 +0100 | [diff] [blame] | 129 | put_unaligned_le64(status->mactime, pos); |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 130 | rthdr->it_present |= |
| 131 | cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT); |
| 132 | pos += 8; |
| 133 | } |
| 134 | |
| 135 | /* IEEE80211_RADIOTAP_FLAGS */ |
| 136 | if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) |
| 137 | *pos |= IEEE80211_RADIOTAP_F_FCS; |
Johannes Berg | aae8983 | 2009-03-13 12:52:10 +0100 | [diff] [blame] | 138 | if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC)) |
| 139 | *pos |= IEEE80211_RADIOTAP_F_BADFCS; |
Bruno Randolf | b4f28bb | 2008-07-30 17:19:55 +0200 | [diff] [blame] | 140 | if (status->flag & RX_FLAG_SHORTPRE) |
| 141 | *pos |= IEEE80211_RADIOTAP_F_SHORTPRE; |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 142 | pos++; |
| 143 | |
| 144 | /* IEEE80211_RADIOTAP_RATE */ |
Jouni Malinen | 0fb8ca4 | 2008-12-12 14:38:33 +0200 | [diff] [blame] | 145 | if (status->flag & RX_FLAG_HT) { |
| 146 | /* |
| 147 | * TODO: add following information into radiotap header once |
| 148 | * suitable fields are defined for it: |
| 149 | * - MCS index (status->rate_idx) |
| 150 | * - HT40 (status->flag & RX_FLAG_40MHZ) |
| 151 | * - short-GI (status->flag & RX_FLAG_SHORT_GI) |
| 152 | */ |
| 153 | *pos = 0; |
Jouni Malinen | 8d6f658 | 2008-12-15 10:37:50 +0200 | [diff] [blame] | 154 | } else { |
Jouni Malinen | ebe6c7b | 2009-01-10 11:47:33 +0200 | [diff] [blame] | 155 | rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE); |
Jouni Malinen | 0fb8ca4 | 2008-12-12 14:38:33 +0200 | [diff] [blame] | 156 | *pos = rate->bitrate / 5; |
Jouni Malinen | 8d6f658 | 2008-12-15 10:37:50 +0200 | [diff] [blame] | 157 | } |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 158 | pos++; |
| 159 | |
| 160 | /* IEEE80211_RADIOTAP_CHANNEL */ |
Johannes Berg | 6a86b9c | 2009-10-28 09:58:52 +0100 | [diff] [blame] | 161 | put_unaligned_le16(status->freq, pos); |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 162 | pos += 2; |
| 163 | if (status->band == IEEE80211_BAND_5GHZ) |
Johannes Berg | 6a86b9c | 2009-10-28 09:58:52 +0100 | [diff] [blame] | 164 | put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ, |
| 165 | pos); |
Johannes Berg | 5f0b7de | 2009-11-16 13:58:21 +0100 | [diff] [blame] | 166 | else if (status->flag & RX_FLAG_HT) |
| 167 | put_unaligned_le16(IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ, |
| 168 | pos); |
Bruno Randolf | 9deb1ae | 2008-07-30 17:20:06 +0200 | [diff] [blame] | 169 | else if (rate->flags & IEEE80211_RATE_ERP_G) |
Johannes Berg | 6a86b9c | 2009-10-28 09:58:52 +0100 | [diff] [blame] | 170 | put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ, |
| 171 | pos); |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 172 | else |
Johannes Berg | 6a86b9c | 2009-10-28 09:58:52 +0100 | [diff] [blame] | 173 | put_unaligned_le16(IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ, |
| 174 | pos); |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 175 | pos += 2; |
| 176 | |
| 177 | /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */ |
| 178 | if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) { |
| 179 | *pos = status->signal; |
| 180 | rthdr->it_present |= |
| 181 | cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL); |
| 182 | pos++; |
| 183 | } |
| 184 | |
| 185 | /* IEEE80211_RADIOTAP_DBM_ANTNOISE */ |
| 186 | if (local->hw.flags & IEEE80211_HW_NOISE_DBM) { |
| 187 | *pos = status->noise; |
| 188 | rthdr->it_present |= |
| 189 | cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTNOISE); |
| 190 | pos++; |
| 191 | } |
| 192 | |
| 193 | /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */ |
| 194 | |
| 195 | /* IEEE80211_RADIOTAP_ANTENNA */ |
| 196 | *pos = status->antenna; |
| 197 | pos++; |
| 198 | |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 199 | /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */ |
| 200 | |
| 201 | /* IEEE80211_RADIOTAP_RX_FLAGS */ |
| 202 | /* ensure 2 byte alignment for the 2 byte field as required */ |
Johannes Berg | 6a86b9c | 2009-10-28 09:58:52 +0100 | [diff] [blame] | 203 | if ((pos - (u8 *)rthdr) & 1) |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 204 | pos++; |
Johannes Berg | aae8983 | 2009-03-13 12:52:10 +0100 | [diff] [blame] | 205 | if (status->flag & RX_FLAG_FAILED_PLCP_CRC) |
Johannes Berg | 6a86b9c | 2009-10-28 09:58:52 +0100 | [diff] [blame] | 206 | rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP; |
| 207 | put_unaligned_le16(rx_flags, pos); |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 208 | pos += 2; |
| 209 | } |
| 210 | |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 211 | /* |
| 212 | * This function copies a received frame to all monitor interfaces and |
| 213 | * returns a cleaned-up SKB that no longer includes the FCS nor the |
| 214 | * radiotap header the driver might have added. |
| 215 | */ |
| 216 | static struct sk_buff * |
| 217 | ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 218 | struct ieee80211_rate *rate) |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 219 | { |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 220 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb); |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 221 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 222 | int needed_headroom = 0; |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 223 | struct sk_buff *skb, *skb2; |
| 224 | struct net_device *prev_dev = NULL; |
| 225 | int present_fcs_len = 0; |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 226 | |
| 227 | /* |
| 228 | * First, we may need to make a copy of the skb because |
| 229 | * (1) we need to modify it for radiotap (if not present), and |
| 230 | * (2) the other RX handlers will modify the skb we got. |
| 231 | * |
| 232 | * We don't need to, of course, if we aren't going to return |
| 233 | * the SKB because it has a bad FCS/PLCP checksum. |
| 234 | */ |
Johannes Berg | 0869aea | 2009-10-28 10:03:35 +0100 | [diff] [blame] | 235 | |
| 236 | /* room for the radiotap header based on driver features */ |
| 237 | needed_headroom = ieee80211_rx_radiotap_len(local, status); |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 238 | |
| 239 | if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) |
| 240 | present_fcs_len = FCS_LEN; |
| 241 | |
| 242 | if (!local->monitors) { |
Johannes Berg | 0869aea | 2009-10-28 10:03:35 +0100 | [diff] [blame] | 243 | if (should_drop_frame(origskb, present_fcs_len)) { |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 244 | dev_kfree_skb(origskb); |
| 245 | return NULL; |
| 246 | } |
| 247 | |
Johannes Berg | 0869aea | 2009-10-28 10:03:35 +0100 | [diff] [blame] | 248 | return remove_monitor_info(local, origskb); |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 249 | } |
| 250 | |
Johannes Berg | 0869aea | 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 | /* only need to expand headroom if necessary */ |
| 253 | skb = origskb; |
| 254 | origskb = NULL; |
| 255 | |
| 256 | /* |
| 257 | * This shouldn't trigger often because most devices have an |
| 258 | * RX header they pull before we get here, and that should |
| 259 | * be big enough for our radiotap information. We should |
| 260 | * probably export the length to drivers so that we can have |
| 261 | * them allocate enough headroom to start with. |
| 262 | */ |
| 263 | if (skb_headroom(skb) < needed_headroom && |
Johannes Berg | c49e5ea | 2007-12-11 21:33:42 +0100 | [diff] [blame] | 264 | pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) { |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 265 | dev_kfree_skb(skb); |
| 266 | return NULL; |
| 267 | } |
| 268 | } else { |
| 269 | /* |
| 270 | * Need to make a copy and possibly remove radiotap header |
| 271 | * and FCS from the original. |
| 272 | */ |
| 273 | skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC); |
| 274 | |
Johannes Berg | 0869aea | 2009-10-28 10:03:35 +0100 | [diff] [blame] | 275 | origskb = remove_monitor_info(local, origskb); |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 276 | |
| 277 | if (!skb) |
| 278 | return origskb; |
| 279 | } |
| 280 | |
Johannes Berg | 0869aea | 2009-10-28 10:03:35 +0100 | [diff] [blame] | 281 | /* prepend radiotap information */ |
| 282 | ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom); |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 283 | |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 284 | skb_reset_mac_header(skb); |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 285 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 286 | skb->pkt_type = PACKET_OTHERHOST; |
| 287 | skb->protocol = htons(ETH_P_802_2); |
| 288 | |
| 289 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
| 290 | if (!netif_running(sdata->dev)) |
| 291 | continue; |
| 292 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 293 | if (sdata->vif.type != NL80211_IFTYPE_MONITOR) |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 294 | continue; |
| 295 | |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 296 | if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) |
| 297 | continue; |
| 298 | |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 299 | if (prev_dev) { |
| 300 | skb2 = skb_clone(skb, GFP_ATOMIC); |
| 301 | if (skb2) { |
| 302 | skb2->dev = prev_dev; |
| 303 | netif_rx(skb2); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | prev_dev = sdata->dev; |
| 308 | sdata->dev->stats.rx_packets++; |
| 309 | sdata->dev->stats.rx_bytes += skb->len; |
| 310 | } |
| 311 | |
| 312 | if (prev_dev) { |
| 313 | skb->dev = prev_dev; |
| 314 | netif_rx(skb); |
| 315 | } else |
| 316 | dev_kfree_skb(skb); |
| 317 | |
| 318 | return origskb; |
| 319 | } |
| 320 | |
| 321 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 322 | static void ieee80211_parse_qos(struct ieee80211_rx_data *rx) |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 323 | { |
Harvey Harrison | 238f74a | 2008-07-02 11:05:34 -0700 | [diff] [blame] | 324 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 325 | int tid; |
| 326 | |
| 327 | /* does the frame have a qos control field? */ |
Harvey Harrison | 238f74a | 2008-07-02 11:05:34 -0700 | [diff] [blame] | 328 | if (ieee80211_is_data_qos(hdr->frame_control)) { |
| 329 | u8 *qc = ieee80211_get_qos_ctl(hdr); |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 330 | /* frame has qos control */ |
Harvey Harrison | 238f74a | 2008-07-02 11:05:34 -0700 | [diff] [blame] | 331 | tid = *qc & IEEE80211_QOS_CTL_TID_MASK; |
| 332 | if (*qc & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT) |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 333 | rx->flags |= IEEE80211_RX_AMSDU; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 334 | else |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 335 | rx->flags &= ~IEEE80211_RX_AMSDU; |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 336 | } else { |
Johannes Berg | 1411f9b | 2008-07-10 10:11:02 +0200 | [diff] [blame] | 337 | /* |
| 338 | * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"): |
| 339 | * |
| 340 | * Sequence numbers for management frames, QoS data |
| 341 | * frames with a broadcast/multicast address in the |
| 342 | * Address 1 field, and all non-QoS data frames sent |
| 343 | * by QoS STAs are assigned using an additional single |
| 344 | * modulo-4096 counter, [...] |
| 345 | * |
| 346 | * We also use that counter for non-QoS STAs. |
| 347 | */ |
| 348 | tid = NUM_RX_DATA_QUEUES - 1; |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 349 | } |
Johannes Berg | 52865df | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 350 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 351 | rx->queue = tid; |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 352 | /* Set skb->priority to 1d tag if highest order bit of TID is not set. |
| 353 | * For now, set skb->priority to 0 for other cases. */ |
| 354 | rx->skb->priority = (tid > 7) ? 0 : tid; |
Johannes Berg | 38f3714 | 2008-01-29 17:07:43 +0100 | [diff] [blame] | 355 | } |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 356 | |
Johannes Berg | d1c3a37 | 2009-01-07 00:26:10 +0100 | [diff] [blame] | 357 | /** |
| 358 | * DOC: Packet alignment |
| 359 | * |
| 360 | * Drivers always need to pass packets that are aligned to two-byte boundaries |
| 361 | * to the stack. |
| 362 | * |
| 363 | * Additionally, should, if possible, align the payload data in a way that |
| 364 | * guarantees that the contained IP header is aligned to a four-byte |
| 365 | * boundary. In the case of regular frames, this simply means aligning the |
| 366 | * payload to a four-byte boundary (because either the IP header is directly |
| 367 | * contained, or IV/RFC1042 headers that have a length divisible by four are |
| 368 | * in front of it). |
| 369 | * |
| 370 | * With A-MSDU frames, however, the payload data address must yield two modulo |
| 371 | * four because there are 14-byte 802.3 headers within the A-MSDU frames that |
| 372 | * push the IP header further back to a multiple of four again. Thankfully, the |
| 373 | * specs were sane enough this time around to require padding each A-MSDU |
| 374 | * subframe to a length that is a multiple of four. |
| 375 | * |
| 376 | * Padding like Atheros hardware adds which is inbetween the 802.11 header and |
| 377 | * the payload is not supported, the driver is required to move the 802.11 |
| 378 | * header to be directly in front of the payload in that case. |
| 379 | */ |
| 380 | static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx) |
Johannes Berg | 38f3714 | 2008-01-29 17:07:43 +0100 | [diff] [blame] | 381 | { |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 382 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; |
Johannes Berg | 38f3714 | 2008-01-29 17:07:43 +0100 | [diff] [blame] | 383 | int hdrlen; |
| 384 | |
Johannes Berg | d1c3a37 | 2009-01-07 00:26:10 +0100 | [diff] [blame] | 385 | #ifndef CONFIG_MAC80211_DEBUG_PACKET_ALIGNMENT |
| 386 | return; |
| 387 | #endif |
| 388 | |
| 389 | if (WARN_ONCE((unsigned long)rx->skb->data & 1, |
| 390 | "unaligned packet at 0x%p\n", rx->skb->data)) |
| 391 | return; |
| 392 | |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 393 | if (!ieee80211_is_data_present(hdr->frame_control)) |
Johannes Berg | 38f3714 | 2008-01-29 17:07:43 +0100 | [diff] [blame] | 394 | return; |
| 395 | |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 396 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 397 | if (rx->flags & IEEE80211_RX_AMSDU) |
Johannes Berg | 38f3714 | 2008-01-29 17:07:43 +0100 | [diff] [blame] | 398 | hdrlen += ETH_HLEN; |
Johannes Berg | d1c3a37 | 2009-01-07 00:26:10 +0100 | [diff] [blame] | 399 | WARN_ONCE(((unsigned long)(rx->skb->data + hdrlen)) & 3, |
| 400 | "unaligned IP payload at 0x%p\n", rx->skb->data + hdrlen); |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 401 | } |
| 402 | |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 403 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 404 | /* rx handlers */ |
| 405 | |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 406 | static ieee80211_rx_result debug_noinline |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 407 | ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 408 | { |
| 409 | struct ieee80211_local *local = rx->local; |
| 410 | struct sk_buff *skb = rx->skb; |
| 411 | |
Helmut Schaa | fbe9c42 | 2009-07-23 12:14:04 +0200 | [diff] [blame] | 412 | if (unlikely(test_bit(SCAN_HW_SCANNING, &local->scanning))) |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 413 | return ieee80211_scan_rx(rx->sdata, skb); |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 414 | |
Helmut Schaa | 142b9f5 | 2009-07-23 13:18:01 +0200 | [diff] [blame] | 415 | if (unlikely(test_bit(SCAN_SW_SCANNING, &local->scanning) && |
| 416 | (rx->flags & IEEE80211_RX_IN_SCAN))) { |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 417 | /* drop all the other packets during a software scan anyway */ |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 418 | if (ieee80211_scan_rx(rx->sdata, skb) != RX_QUEUED) |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 419 | dev_kfree_skb(skb); |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 420 | return RX_QUEUED; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 421 | } |
| 422 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 423 | if (unlikely(rx->flags & IEEE80211_RX_IN_SCAN)) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 424 | /* scanning finished during invoking of handlers */ |
| 425 | I802_DEBUG_INC(local->rx_handlers_drop_passive_scan); |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 426 | return RX_DROP_UNUSABLE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 427 | } |
| 428 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 429 | return RX_CONTINUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 430 | } |
| 431 | |
Jouni Malinen | 3cfcf6a | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 432 | |
| 433 | static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb) |
| 434 | { |
| 435 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 436 | |
| 437 | if (skb->len < 24 || is_multicast_ether_addr(hdr->addr1)) |
| 438 | return 0; |
| 439 | |
| 440 | return ieee80211_is_robust_mgmt_frame(hdr); |
| 441 | } |
| 442 | |
| 443 | |
| 444 | static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb) |
| 445 | { |
| 446 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 447 | |
| 448 | if (skb->len < 24 || !is_multicast_ether_addr(hdr->addr1)) |
| 449 | return 0; |
| 450 | |
| 451 | return ieee80211_is_robust_mgmt_frame(hdr); |
| 452 | } |
| 453 | |
| 454 | |
| 455 | /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */ |
| 456 | static int ieee80211_get_mmie_keyidx(struct sk_buff *skb) |
| 457 | { |
| 458 | struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data; |
| 459 | struct ieee80211_mmie *mmie; |
| 460 | |
| 461 | if (skb->len < 24 + sizeof(*mmie) || |
| 462 | !is_multicast_ether_addr(hdr->da)) |
| 463 | return -1; |
| 464 | |
| 465 | if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *) hdr)) |
| 466 | return -1; /* not a robust management frame */ |
| 467 | |
| 468 | mmie = (struct ieee80211_mmie *) |
| 469 | (skb->data + skb->len - sizeof(*mmie)); |
| 470 | if (mmie->element_id != WLAN_EID_MMIE || |
| 471 | mmie->length != sizeof(*mmie) - 2) |
| 472 | return -1; |
| 473 | |
| 474 | return le16_to_cpu(mmie->key_id); |
| 475 | } |
| 476 | |
| 477 | |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 478 | static ieee80211_rx_result |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 479 | ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx) |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 480 | { |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 481 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; |
| 482 | unsigned int hdrlen = ieee80211_hdrlen(hdr->frame_control); |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 483 | char *dev_addr = rx->sdata->dev->dev_addr; |
Johannes Berg | d6d1a5a | 2008-02-25 16:24:38 +0100 | [diff] [blame] | 484 | |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 485 | if (ieee80211_is_data(hdr->frame_control)) { |
Javier Cardona | 3c5772a | 2009-08-10 12:15:48 -0700 | [diff] [blame] | 486 | if (is_multicast_ether_addr(hdr->addr1)) { |
| 487 | if (ieee80211_has_tods(hdr->frame_control) || |
| 488 | !ieee80211_has_fromds(hdr->frame_control)) |
| 489 | return RX_DROP_MONITOR; |
| 490 | if (memcmp(hdr->addr3, dev_addr, ETH_ALEN) == 0) |
| 491 | return RX_DROP_MONITOR; |
| 492 | } else { |
| 493 | if (!ieee80211_has_a4(hdr->frame_control)) |
| 494 | return RX_DROP_MONITOR; |
| 495 | if (memcmp(hdr->addr4, dev_addr, ETH_ALEN) == 0) |
| 496 | return RX_DROP_MONITOR; |
| 497 | } |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | /* If there is not an established peer link and this is not a peer link |
| 501 | * establisment frame, beacon or probe, drop the frame. |
| 502 | */ |
| 503 | |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 504 | if (!rx->sta || sta_plink_state(rx->sta) != PLINK_ESTAB) { |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 505 | struct ieee80211_mgmt *mgmt; |
Johannes Berg | d6d1a5a | 2008-02-25 16:24:38 +0100 | [diff] [blame] | 506 | |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 507 | if (!ieee80211_is_mgmt(hdr->frame_control)) |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 508 | return RX_DROP_MONITOR; |
| 509 | |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 510 | if (ieee80211_is_action(hdr->frame_control)) { |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 511 | mgmt = (struct ieee80211_mgmt *)hdr; |
Rui Paulo | 0938393 | 2009-11-09 23:46:43 +0000 | [diff] [blame] | 512 | if (mgmt->u.action.category != MESH_PLINK_CATEGORY) |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 513 | return RX_DROP_MONITOR; |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 514 | return RX_CONTINUE; |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 515 | } |
| 516 | |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 517 | if (ieee80211_is_probe_req(hdr->frame_control) || |
| 518 | ieee80211_is_probe_resp(hdr->frame_control) || |
| 519 | ieee80211_is_beacon(hdr->frame_control)) |
| 520 | return RX_CONTINUE; |
| 521 | |
| 522 | return RX_DROP_MONITOR; |
| 523 | |
| 524 | } |
| 525 | |
| 526 | #define msh_h_get(h, l) ((struct ieee80211s_hdr *) ((u8 *)h + l)) |
| 527 | |
| 528 | if (ieee80211_is_data(hdr->frame_control) && |
| 529 | is_multicast_ether_addr(hdr->addr1) && |
Javier Cardona | 3c5772a | 2009-08-10 12:15:48 -0700 | [diff] [blame] | 530 | mesh_rmc_check(hdr->addr3, msh_h_get(hdr, hdrlen), rx->sdata)) |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 531 | return RX_DROP_MONITOR; |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 532 | #undef msh_h_get |
Johannes Berg | d6d1a5a | 2008-02-25 16:24:38 +0100 | [diff] [blame] | 533 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 534 | return RX_CONTINUE; |
| 535 | } |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 536 | |
Johannes Berg | 1edfb1a | 2009-11-25 17:46:16 +0100 | [diff] [blame^] | 537 | #define SEQ_MODULO 0x1000 |
| 538 | #define SEQ_MASK 0xfff |
| 539 | |
| 540 | static inline int seq_less(u16 sq1, u16 sq2) |
| 541 | { |
| 542 | return ((sq1 - sq2) & SEQ_MASK) > (SEQ_MODULO >> 1); |
| 543 | } |
| 544 | |
| 545 | static inline u16 seq_inc(u16 sq) |
| 546 | { |
| 547 | return (sq + 1) & SEQ_MASK; |
| 548 | } |
| 549 | |
| 550 | static inline u16 seq_sub(u16 sq1, u16 sq2) |
| 551 | { |
| 552 | return (sq1 - sq2) & SEQ_MASK; |
| 553 | } |
| 554 | |
| 555 | |
| 556 | static void ieee80211_release_reorder_frame(struct ieee80211_hw *hw, |
| 557 | struct tid_ampdu_rx *tid_agg_rx, |
| 558 | int index) |
| 559 | { |
| 560 | struct ieee80211_supported_band *sband; |
| 561 | struct ieee80211_rate *rate = NULL; |
| 562 | struct sk_buff *skb = tid_agg_rx->reorder_buf[index]; |
| 563 | struct ieee80211_rx_status *status; |
| 564 | |
| 565 | if (!skb) |
| 566 | goto no_frame; |
| 567 | |
| 568 | status = IEEE80211_SKB_RXCB(skb); |
| 569 | |
| 570 | /* release the reordered frames to stack */ |
| 571 | sband = hw->wiphy->bands[status->band]; |
| 572 | if (!(status->flag & RX_FLAG_HT)) |
| 573 | rate = &sband->bitrates[status->rate_idx]; |
| 574 | __ieee80211_rx_handle_packet(hw, skb, rate); |
| 575 | tid_agg_rx->stored_mpdu_num--; |
| 576 | tid_agg_rx->reorder_buf[index] = NULL; |
| 577 | |
| 578 | no_frame: |
| 579 | tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num); |
| 580 | } |
| 581 | |
| 582 | static void ieee80211_release_reorder_frames(struct ieee80211_hw *hw, |
| 583 | struct tid_ampdu_rx *tid_agg_rx, |
| 584 | u16 head_seq_num) |
| 585 | { |
| 586 | int index; |
| 587 | |
| 588 | while (seq_less(tid_agg_rx->head_seq_num, head_seq_num)) { |
| 589 | index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) % |
| 590 | tid_agg_rx->buf_size; |
| 591 | ieee80211_release_reorder_frame(hw, tid_agg_rx, index); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | /* |
| 596 | * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If |
| 597 | * the skb was added to the buffer longer than this time ago, the earlier |
| 598 | * frames that have not yet been received are assumed to be lost and the skb |
| 599 | * can be released for processing. This may also release other skb's from the |
| 600 | * reorder buffer if there are no additional gaps between the frames. |
| 601 | */ |
| 602 | #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10) |
| 603 | |
| 604 | /* |
| 605 | * As this function belongs to the RX path it must be under |
| 606 | * rcu_read_lock protection. It returns false if the frame |
| 607 | * can be processed immediately, true if it was consumed. |
| 608 | */ |
| 609 | static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw, |
| 610 | struct tid_ampdu_rx *tid_agg_rx, |
| 611 | struct sk_buff *skb) |
| 612 | { |
| 613 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 614 | u16 sc = le16_to_cpu(hdr->seq_ctrl); |
| 615 | u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 616 | u16 head_seq_num, buf_size; |
| 617 | int index; |
| 618 | |
| 619 | buf_size = tid_agg_rx->buf_size; |
| 620 | head_seq_num = tid_agg_rx->head_seq_num; |
| 621 | |
| 622 | /* frame with out of date sequence number */ |
| 623 | if (seq_less(mpdu_seq_num, head_seq_num)) { |
| 624 | dev_kfree_skb(skb); |
| 625 | return true; |
| 626 | } |
| 627 | |
| 628 | /* |
| 629 | * If frame the sequence number exceeds our buffering window |
| 630 | * size release some previous frames to make room for this one. |
| 631 | */ |
| 632 | if (!seq_less(mpdu_seq_num, head_seq_num + buf_size)) { |
| 633 | head_seq_num = seq_inc(seq_sub(mpdu_seq_num, buf_size)); |
| 634 | /* release stored frames up to new head to stack */ |
| 635 | ieee80211_release_reorder_frames(hw, tid_agg_rx, head_seq_num); |
| 636 | } |
| 637 | |
| 638 | /* Now the new frame is always in the range of the reordering buffer */ |
| 639 | |
| 640 | index = seq_sub(mpdu_seq_num, tid_agg_rx->ssn) % tid_agg_rx->buf_size; |
| 641 | |
| 642 | /* check if we already stored this frame */ |
| 643 | if (tid_agg_rx->reorder_buf[index]) { |
| 644 | dev_kfree_skb(skb); |
| 645 | return true; |
| 646 | } |
| 647 | |
| 648 | /* |
| 649 | * If the current MPDU is in the right order and nothing else |
| 650 | * is stored we can process it directly, no need to buffer it. |
| 651 | */ |
| 652 | if (mpdu_seq_num == tid_agg_rx->head_seq_num && |
| 653 | tid_agg_rx->stored_mpdu_num == 0) { |
| 654 | tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num); |
| 655 | return false; |
| 656 | } |
| 657 | |
| 658 | /* put the frame in the reordering buffer */ |
| 659 | tid_agg_rx->reorder_buf[index] = skb; |
| 660 | tid_agg_rx->reorder_time[index] = jiffies; |
| 661 | tid_agg_rx->stored_mpdu_num++; |
| 662 | /* release the buffer until next missing frame */ |
| 663 | index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) % |
| 664 | tid_agg_rx->buf_size; |
| 665 | if (!tid_agg_rx->reorder_buf[index] && |
| 666 | tid_agg_rx->stored_mpdu_num > 1) { |
| 667 | /* |
| 668 | * No buffers ready to be released, but check whether any |
| 669 | * frames in the reorder buffer have timed out. |
| 670 | */ |
| 671 | int j; |
| 672 | int skipped = 1; |
| 673 | for (j = (index + 1) % tid_agg_rx->buf_size; j != index; |
| 674 | j = (j + 1) % tid_agg_rx->buf_size) { |
| 675 | if (!tid_agg_rx->reorder_buf[j]) { |
| 676 | skipped++; |
| 677 | continue; |
| 678 | } |
| 679 | if (!time_after(jiffies, tid_agg_rx->reorder_time[j] + |
| 680 | HT_RX_REORDER_BUF_TIMEOUT)) |
| 681 | break; |
| 682 | |
| 683 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 684 | if (net_ratelimit()) |
| 685 | printk(KERN_DEBUG "%s: release an RX reorder " |
| 686 | "frame due to timeout on earlier " |
| 687 | "frames\n", |
| 688 | wiphy_name(hw->wiphy)); |
| 689 | #endif |
| 690 | ieee80211_release_reorder_frame(hw, tid_agg_rx, j); |
| 691 | |
| 692 | /* |
| 693 | * Increment the head seq# also for the skipped slots. |
| 694 | */ |
| 695 | tid_agg_rx->head_seq_num = |
| 696 | (tid_agg_rx->head_seq_num + skipped) & SEQ_MASK; |
| 697 | skipped = 0; |
| 698 | } |
| 699 | } else while (tid_agg_rx->reorder_buf[index]) { |
| 700 | ieee80211_release_reorder_frame(hw, tid_agg_rx, index); |
| 701 | index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) % |
| 702 | tid_agg_rx->buf_size; |
| 703 | } |
| 704 | |
| 705 | return true; |
| 706 | } |
| 707 | |
| 708 | /* |
| 709 | * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns |
| 710 | * true if the MPDU was buffered, false if it should be processed. |
| 711 | */ |
| 712 | static bool ieee80211_rx_reorder_ampdu(struct ieee80211_local *local, |
| 713 | struct sk_buff *skb) |
| 714 | { |
| 715 | struct ieee80211_hw *hw = &local->hw; |
| 716 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 717 | struct sta_info *sta; |
| 718 | struct tid_ampdu_rx *tid_agg_rx; |
| 719 | u16 sc; |
| 720 | int tid; |
| 721 | |
| 722 | if (!ieee80211_is_data_qos(hdr->frame_control)) |
| 723 | return false; |
| 724 | |
| 725 | /* |
| 726 | * filter the QoS data rx stream according to |
| 727 | * STA/TID and check if this STA/TID is on aggregation |
| 728 | */ |
| 729 | |
| 730 | sta = sta_info_get(local, hdr->addr2); |
| 731 | if (!sta) |
| 732 | return false; |
| 733 | |
| 734 | tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK; |
| 735 | |
| 736 | if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_OPERATIONAL) |
| 737 | return false; |
| 738 | |
| 739 | tid_agg_rx = sta->ampdu_mlme.tid_rx[tid]; |
| 740 | |
| 741 | /* qos null data frames are excluded */ |
| 742 | if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC))) |
| 743 | return false; |
| 744 | |
| 745 | /* new, potentially un-ordered, ampdu frame - process it */ |
| 746 | |
| 747 | /* reset session timer */ |
| 748 | if (tid_agg_rx->timeout) |
| 749 | mod_timer(&tid_agg_rx->session_timer, |
| 750 | TU_TO_EXP_TIME(tid_agg_rx->timeout)); |
| 751 | |
| 752 | /* if this mpdu is fragmented - terminate rx aggregation session */ |
| 753 | sc = le16_to_cpu(hdr->seq_ctrl); |
| 754 | if (sc & IEEE80211_SCTL_FRAG) { |
| 755 | ieee80211_sta_stop_rx_ba_session(sta->sdata, sta->sta.addr, |
| 756 | tid, 0, WLAN_REASON_QSTA_REQUIRE_SETUP); |
| 757 | dev_kfree_skb(skb); |
| 758 | return true; |
| 759 | } |
| 760 | |
| 761 | return ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb); |
| 762 | } |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 763 | |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 764 | static ieee80211_rx_result debug_noinline |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 765 | ieee80211_rx_h_check(struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 766 | { |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 767 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 768 | |
| 769 | /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */ |
| 770 | if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) { |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 771 | if (unlikely(ieee80211_has_retry(hdr->frame_control) && |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 772 | rx->sta->last_seq_ctrl[rx->queue] == |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 773 | hdr->seq_ctrl)) { |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 774 | if (rx->flags & IEEE80211_RX_RA_MATCH) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 775 | rx->local->dot11FrameDuplicateCount++; |
| 776 | rx->sta->num_duplicates++; |
| 777 | } |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 778 | return RX_DROP_MONITOR; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 779 | } else |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 780 | rx->sta->last_seq_ctrl[rx->queue] = hdr->seq_ctrl; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 781 | } |
| 782 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 783 | if (unlikely(rx->skb->len < 16)) { |
| 784 | I802_DEBUG_INC(rx->local->rx_handlers_drop_short); |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 785 | return RX_DROP_MONITOR; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 786 | } |
| 787 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 788 | /* Drop disallowed frame classes based on STA auth/assoc state; |
| 789 | * IEEE 802.11, Chap 5.5. |
| 790 | * |
Johannes Berg | ccd7b36 | 2008-09-11 00:01:56 +0200 | [diff] [blame] | 791 | * mac80211 filters only based on association state, i.e. it drops |
| 792 | * Class 3 frames from not associated stations. hostapd sends |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 793 | * deauth/disassoc frames when needed. In addition, hostapd is |
| 794 | * responsible for filtering on both auth and assoc states. |
| 795 | */ |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 796 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 797 | if (ieee80211_vif_is_mesh(&rx->sdata->vif)) |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 798 | return ieee80211_rx_mesh_check(rx); |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 799 | |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 800 | if (unlikely((ieee80211_is_data(hdr->frame_control) || |
| 801 | ieee80211_is_pspoll(hdr->frame_control)) && |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 802 | rx->sdata->vif.type != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 803 | (!rx->sta || !test_sta_flags(rx->sta, WLAN_STA_ASSOC)))) { |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 804 | if ((!ieee80211_has_fromds(hdr->frame_control) && |
| 805 | !ieee80211_has_tods(hdr->frame_control) && |
| 806 | ieee80211_is_data(hdr->frame_control)) || |
| 807 | !(rx->flags & IEEE80211_RX_RA_MATCH)) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 808 | /* Drop IBSS frames and frames for other hosts |
| 809 | * silently. */ |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 810 | return RX_DROP_MONITOR; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 811 | } |
| 812 | |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 813 | return RX_DROP_MONITOR; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 814 | } |
| 815 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 816 | return RX_CONTINUE; |
Johannes Berg | 570bd53 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 820 | static ieee80211_rx_result debug_noinline |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 821 | ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx) |
Johannes Berg | 570bd53 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 822 | { |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 823 | struct sk_buff *skb = rx->skb; |
| 824 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
| 825 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 826 | int keyidx; |
| 827 | int hdrlen; |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 828 | ieee80211_rx_result result = RX_DROP_UNUSABLE; |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 829 | struct ieee80211_key *stakey = NULL; |
Jouni Malinen | 3cfcf6a | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 830 | int mmie_keyidx = -1; |
Johannes Berg | 570bd53 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 831 | |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 832 | /* |
| 833 | * Key selection 101 |
| 834 | * |
Jouni Malinen | 3cfcf6a | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 835 | * There are four types of keys: |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 836 | * - GTK (group keys) |
Jouni Malinen | 3cfcf6a | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 837 | * - IGTK (group keys for management frames) |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 838 | * - PTK (pairwise keys) |
| 839 | * - STK (station-to-station pairwise keys) |
| 840 | * |
| 841 | * When selecting a key, we have to distinguish between multicast |
| 842 | * (including broadcast) and unicast frames, the latter can only |
Jouni Malinen | 3cfcf6a | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 843 | * use PTKs and STKs while the former always use GTKs and IGTKs. |
| 844 | * Unless, of course, actual WEP keys ("pre-RSNA") are used, then |
| 845 | * unicast frames can also use key indices like GTKs. Hence, if we |
| 846 | * 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] | 847 | * |
Johannes Berg | 8dc06a1 | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 848 | * Note that in a regular BSS, multicast frames are sent by the |
| 849 | * AP only, associated stations unicast the frame to the AP first |
| 850 | * which then multicasts it on their behalf. |
| 851 | * |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 852 | * There is also a slight problem in IBSS mode: GTKs are negotiated |
| 853 | * with each station, that is something we don't currently handle. |
Johannes Berg | 8dc06a1 | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 854 | * The spec seems to expect that one negotiates the same key with |
| 855 | * every station but there's no such requirement; VLANs could be |
| 856 | * possible. |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 857 | */ |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 858 | |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 859 | /* |
Johannes Berg | 1990af8 | 2007-09-26 17:53:15 +0200 | [diff] [blame] | 860 | * 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] | 861 | * addressed to us nor a multicast frame. |
| 862 | */ |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 863 | if (!(rx->flags & IEEE80211_RX_RA_MATCH)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 864 | return RX_CONTINUE; |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 865 | |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 866 | if (rx->sta) |
| 867 | stakey = rcu_dereference(rx->sta->key); |
| 868 | |
Jouni Malinen | 0c7c10c | 2009-05-08 12:34:10 +0300 | [diff] [blame] | 869 | if (!ieee80211_has_protected(hdr->frame_control)) |
| 870 | mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb); |
| 871 | |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 872 | if (!is_multicast_ether_addr(hdr->addr1) && stakey) { |
| 873 | rx->key = stakey; |
Jouni Malinen | 0c7c10c | 2009-05-08 12:34:10 +0300 | [diff] [blame] | 874 | /* Skip decryption if the frame is not protected. */ |
| 875 | if (!ieee80211_has_protected(hdr->frame_control)) |
| 876 | return RX_CONTINUE; |
Jouni Malinen | 3cfcf6a | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 877 | } else if (mmie_keyidx >= 0) { |
| 878 | /* Broadcast/multicast robust management frame / BIP */ |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 879 | if ((status->flag & RX_FLAG_DECRYPTED) && |
| 880 | (status->flag & RX_FLAG_IV_STRIPPED)) |
Jouni Malinen | 3cfcf6a | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 881 | return RX_CONTINUE; |
| 882 | |
| 883 | if (mmie_keyidx < NUM_DEFAULT_KEYS || |
| 884 | mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) |
| 885 | return RX_DROP_MONITOR; /* unexpected BIP keyidx */ |
| 886 | rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]); |
Jouni Malinen | 0c7c10c | 2009-05-08 12:34:10 +0300 | [diff] [blame] | 887 | } else if (!ieee80211_has_protected(hdr->frame_control)) { |
| 888 | /* |
| 889 | * The frame was not protected, so skip decryption. However, we |
| 890 | * need to set rx->key if there is a key that could have been |
| 891 | * used so that the frame may be dropped if encryption would |
| 892 | * have been expected. |
| 893 | */ |
| 894 | struct ieee80211_key *key = NULL; |
| 895 | if (ieee80211_is_mgmt(hdr->frame_control) && |
| 896 | is_multicast_ether_addr(hdr->addr1) && |
| 897 | (key = rcu_dereference(rx->sdata->default_mgmt_key))) |
| 898 | rx->key = key; |
| 899 | else if ((key = rcu_dereference(rx->sdata->default_key))) |
| 900 | rx->key = key; |
| 901 | return RX_CONTINUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 902 | } else { |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 903 | /* |
| 904 | * The device doesn't give us the IV so we won't be |
| 905 | * able to look up the key. That's ok though, we |
| 906 | * don't need to decrypt the frame, we just won't |
| 907 | * be able to keep statistics accurate. |
| 908 | * Except for key threshold notifications, should |
| 909 | * we somehow allow the driver to tell us which key |
| 910 | * the hardware used if this flag is set? |
| 911 | */ |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 912 | if ((status->flag & RX_FLAG_DECRYPTED) && |
| 913 | (status->flag & RX_FLAG_IV_STRIPPED)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 914 | return RX_CONTINUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 915 | |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 916 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 917 | |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 918 | if (rx->skb->len < 8 + hdrlen) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 919 | return RX_DROP_UNUSABLE; /* TODO: count this? */ |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 920 | |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 921 | /* |
| 922 | * no need to call ieee80211_wep_get_keyidx, |
| 923 | * it verifies a bunch of things we've done already |
| 924 | */ |
| 925 | keyidx = rx->skb->data[hdrlen + 3] >> 6; |
| 926 | |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 927 | rx->key = rcu_dereference(rx->sdata->keys[keyidx]); |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 928 | |
| 929 | /* |
| 930 | * RSNA-protected unicast frames should always be sent with |
| 931 | * pairwise or station-to-station keys, but for WEP we allow |
| 932 | * using a key index as well. |
| 933 | */ |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 934 | if (rx->key && rx->key->conf.alg != ALG_WEP && |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 935 | !is_multicast_ether_addr(hdr->addr1)) |
| 936 | rx->key = NULL; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 937 | } |
| 938 | |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 939 | if (rx->key) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 940 | rx->key->tx_rx_count++; |
Johannes Berg | 011bfcc | 2007-09-17 01:29:25 -0400 | [diff] [blame] | 941 | /* TODO: add threshold stuff again */ |
Johannes Berg | 1990af8 | 2007-09-26 17:53:15 +0200 | [diff] [blame] | 942 | } else { |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 943 | return RX_DROP_MONITOR; |
Johannes Berg | 70f0876 | 2007-09-26 17:53:14 +0200 | [diff] [blame] | 944 | } |
| 945 | |
Johannes Berg | 1990af8 | 2007-09-26 17:53:15 +0200 | [diff] [blame] | 946 | /* Check for weak IVs if possible */ |
| 947 | if (rx->sta && rx->key->conf.alg == ALG_WEP && |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 948 | ieee80211_is_data(hdr->frame_control) && |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 949 | (!(status->flag & RX_FLAG_IV_STRIPPED) || |
| 950 | !(status->flag & RX_FLAG_DECRYPTED)) && |
Johannes Berg | 1990af8 | 2007-09-26 17:53:15 +0200 | [diff] [blame] | 951 | ieee80211_wep_is_weak_iv(rx->skb, rx->key)) |
| 952 | rx->sta->wep_weak_iv_count++; |
| 953 | |
Johannes Berg | 70f0876 | 2007-09-26 17:53:14 +0200 | [diff] [blame] | 954 | switch (rx->key->conf.alg) { |
| 955 | case ALG_WEP: |
Mattias Nissler | e2f036d | 2007-10-07 16:35:31 +0200 | [diff] [blame] | 956 | result = ieee80211_crypto_wep_decrypt(rx); |
| 957 | break; |
Johannes Berg | 70f0876 | 2007-09-26 17:53:14 +0200 | [diff] [blame] | 958 | case ALG_TKIP: |
Mattias Nissler | e2f036d | 2007-10-07 16:35:31 +0200 | [diff] [blame] | 959 | result = ieee80211_crypto_tkip_decrypt(rx); |
| 960 | break; |
Johannes Berg | 70f0876 | 2007-09-26 17:53:14 +0200 | [diff] [blame] | 961 | case ALG_CCMP: |
Mattias Nissler | e2f036d | 2007-10-07 16:35:31 +0200 | [diff] [blame] | 962 | result = ieee80211_crypto_ccmp_decrypt(rx); |
| 963 | break; |
Jouni Malinen | 3cfcf6a | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 964 | case ALG_AES_CMAC: |
| 965 | result = ieee80211_crypto_aes_cmac_decrypt(rx); |
| 966 | break; |
Johannes Berg | 70f0876 | 2007-09-26 17:53:14 +0200 | [diff] [blame] | 967 | } |
| 968 | |
Mattias Nissler | e2f036d | 2007-10-07 16:35:31 +0200 | [diff] [blame] | 969 | /* either the frame has been decrypted or will be dropped */ |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 970 | status->flag |= RX_FLAG_DECRYPTED; |
Mattias Nissler | e2f036d | 2007-10-07 16:35:31 +0200 | [diff] [blame] | 971 | |
| 972 | return result; |
Johannes Berg | 70f0876 | 2007-09-26 17:53:14 +0200 | [diff] [blame] | 973 | } |
| 974 | |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 975 | static ieee80211_rx_result debug_noinline |
| 976 | ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx) |
| 977 | { |
| 978 | struct ieee80211_local *local; |
| 979 | struct ieee80211_hdr *hdr; |
| 980 | struct sk_buff *skb; |
| 981 | |
| 982 | local = rx->local; |
| 983 | skb = rx->skb; |
| 984 | hdr = (struct ieee80211_hdr *) skb->data; |
| 985 | |
| 986 | if (!local->pspolling) |
| 987 | return RX_CONTINUE; |
| 988 | |
| 989 | if (!ieee80211_has_fromds(hdr->frame_control)) |
| 990 | /* this is not from AP */ |
| 991 | return RX_CONTINUE; |
| 992 | |
| 993 | if (!ieee80211_is_data(hdr->frame_control)) |
| 994 | return RX_CONTINUE; |
| 995 | |
| 996 | if (!ieee80211_has_moredata(hdr->frame_control)) { |
| 997 | /* AP has no more frames buffered for us */ |
| 998 | local->pspolling = false; |
| 999 | return RX_CONTINUE; |
| 1000 | } |
| 1001 | |
| 1002 | /* more data bit is set, let's request a new frame from the AP */ |
| 1003 | ieee80211_send_pspoll(local, rx->sdata); |
| 1004 | |
| 1005 | return RX_CONTINUE; |
| 1006 | } |
| 1007 | |
Johannes Berg | 133b822 | 2008-09-16 14:18:59 +0200 | [diff] [blame] | 1008 | static void ap_sta_ps_start(struct sta_info *sta) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1009 | { |
Johannes Berg | 133b822 | 2008-09-16 14:18:59 +0200 | [diff] [blame] | 1010 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Christian Lamparter | 4571d3b | 2008-11-30 00:48:41 +0100 | [diff] [blame] | 1011 | struct ieee80211_local *local = sdata->local; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1012 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 1013 | atomic_inc(&sdata->bss->num_sta_ps); |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1014 | set_sta_flags(sta, WLAN_STA_PS_STA); |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 1015 | drv_sta_notify(local, &sdata->vif, STA_NOTIFY_SLEEP, &sta->sta); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1016 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 1017 | printk(KERN_DEBUG "%s: STA %pM aid %d enters power save mode\n", |
| 1018 | sdata->dev->name, sta->sta.addr, sta->sta.aid); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1019 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
| 1020 | } |
| 1021 | |
Johannes Berg | ff9458d | 2009-10-30 12:56:02 +0100 | [diff] [blame] | 1022 | static void ap_sta_ps_end(struct sta_info *sta) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1023 | { |
Johannes Berg | 133b822 | 2008-09-16 14:18:59 +0200 | [diff] [blame] | 1024 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1025 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 1026 | atomic_dec(&sdata->bss->num_sta_ps); |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 1027 | |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1028 | clear_sta_flags(sta, WLAN_STA_PS_STA); |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 1029 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1030 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 1031 | printk(KERN_DEBUG "%s: STA %pM aid %d exits power save mode\n", |
| 1032 | sdata->dev->name, sta->sta.addr, sta->sta.aid); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1033 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 1034 | |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1035 | if (test_sta_flags(sta, WLAN_STA_PS_DRIVER)) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1036 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1037 | printk(KERN_DEBUG "%s: STA %pM aid %d driver-ps-blocked\n", |
| 1038 | sdata->dev->name, sta->sta.addr, sta->sta.aid); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1039 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1040 | return; |
| 1041 | } |
| 1042 | |
| 1043 | ieee80211_sta_ps_deliver_wakeup(sta); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1044 | } |
| 1045 | |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 1046 | static ieee80211_rx_result debug_noinline |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1047 | ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1048 | { |
| 1049 | struct sta_info *sta = rx->sta; |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 1050 | struct sk_buff *skb = rx->skb; |
| 1051 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
| 1052 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1053 | |
| 1054 | if (!sta) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1055 | return RX_CONTINUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1056 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1057 | /* |
| 1058 | * Update last_rx only for IBSS packets which are for the current |
| 1059 | * BSSID to avoid keeping the current IBSS network alive in cases |
| 1060 | * where other STAs start using different BSSID. |
| 1061 | */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1062 | if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) { |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 1063 | u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len, |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1064 | NL80211_IFTYPE_ADHOC); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1065 | if (compare_ether_addr(bssid, rx->sdata->u.ibss.bssid) == 0) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1066 | sta->last_rx = jiffies; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1067 | } else if (!is_multicast_ether_addr(hdr->addr1)) { |
| 1068 | /* |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 1069 | * Mesh beacons will update last_rx when if they are found to |
| 1070 | * match the current local configuration when processed. |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1071 | */ |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1072 | sta->last_rx = jiffies; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1073 | } |
| 1074 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1075 | if (!(rx->flags & IEEE80211_RX_RA_MATCH)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1076 | return RX_CONTINUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1077 | |
Kalle Valo | 3cf335d | 2009-03-22 21:57:06 +0200 | [diff] [blame] | 1078 | if (rx->sdata->vif.type == NL80211_IFTYPE_STATION) |
| 1079 | ieee80211_sta_rx_notify(rx->sdata, hdr); |
| 1080 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1081 | sta->rx_fragments++; |
| 1082 | sta->rx_bytes += rx->skb->len; |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 1083 | sta->last_signal = status->signal; |
| 1084 | sta->last_noise = status->noise; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1085 | |
Johannes Berg | 72eaa43 | 2008-11-26 15:02:58 +0100 | [diff] [blame] | 1086 | /* |
| 1087 | * Change STA power saving mode only at the end of a frame |
| 1088 | * exchange sequence. |
| 1089 | */ |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 1090 | if (!ieee80211_has_morefrags(hdr->frame_control) && |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1091 | (rx->sdata->vif.type == NL80211_IFTYPE_AP || |
| 1092 | rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) { |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1093 | if (test_sta_flags(sta, WLAN_STA_PS_STA)) { |
Johannes Berg | 72eaa43 | 2008-11-26 15:02:58 +0100 | [diff] [blame] | 1094 | /* |
| 1095 | * Ignore doze->wake transitions that are |
| 1096 | * indicated by non-data frames, the standard |
| 1097 | * is unclear here, but for example going to |
| 1098 | * PS mode and then scanning would cause a |
| 1099 | * doze->wake transition for the probe request, |
| 1100 | * and that is clearly undesirable. |
| 1101 | */ |
| 1102 | if (ieee80211_is_data(hdr->frame_control) && |
| 1103 | !ieee80211_has_pm(hdr->frame_control)) |
Johannes Berg | ff9458d | 2009-10-30 12:56:02 +0100 | [diff] [blame] | 1104 | ap_sta_ps_end(sta); |
Johannes Berg | 72eaa43 | 2008-11-26 15:02:58 +0100 | [diff] [blame] | 1105 | } else { |
| 1106 | if (ieee80211_has_pm(hdr->frame_control)) |
| 1107 | ap_sta_ps_start(sta); |
| 1108 | } |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1109 | } |
| 1110 | |
Johannes Berg | 22403de | 2009-10-30 12:55:03 +0100 | [diff] [blame] | 1111 | /* |
| 1112 | * Drop (qos-)data::nullfunc frames silently, since they |
| 1113 | * are used only to control station power saving mode. |
| 1114 | */ |
| 1115 | if (ieee80211_is_nullfunc(hdr->frame_control) || |
| 1116 | ieee80211_is_qos_nullfunc(hdr->frame_control)) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1117 | I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc); |
Johannes Berg | 22403de | 2009-10-30 12:55:03 +0100 | [diff] [blame] | 1118 | /* |
| 1119 | * Update counter and free packet here to avoid |
| 1120 | * counting this as a dropped packed. |
| 1121 | */ |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1122 | sta->rx_packets++; |
| 1123 | dev_kfree_skb(rx->skb); |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1124 | return RX_QUEUED; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1125 | } |
| 1126 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1127 | return RX_CONTINUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1128 | } /* ieee80211_rx_h_sta_process */ |
| 1129 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1130 | static inline struct ieee80211_fragment_entry * |
| 1131 | ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata, |
| 1132 | unsigned int frag, unsigned int seq, int rx_queue, |
| 1133 | struct sk_buff **skb) |
| 1134 | { |
| 1135 | struct ieee80211_fragment_entry *entry; |
| 1136 | int idx; |
| 1137 | |
| 1138 | idx = sdata->fragment_next; |
| 1139 | entry = &sdata->fragments[sdata->fragment_next++]; |
| 1140 | if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX) |
| 1141 | sdata->fragment_next = 0; |
| 1142 | |
| 1143 | if (!skb_queue_empty(&entry->skb_list)) { |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1144 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1145 | struct ieee80211_hdr *hdr = |
| 1146 | (struct ieee80211_hdr *) entry->skb_list.next->data; |
| 1147 | printk(KERN_DEBUG "%s: RX reassembly removed oldest " |
| 1148 | "fragment entry (idx=%d age=%lu seq=%d last_frag=%d " |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 1149 | "addr1=%pM addr2=%pM\n", |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1150 | sdata->dev->name, idx, |
| 1151 | jiffies - entry->first_frag_time, entry->seq, |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 1152 | entry->last_frag, hdr->addr1, hdr->addr2); |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1153 | #endif |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1154 | __skb_queue_purge(&entry->skb_list); |
| 1155 | } |
| 1156 | |
| 1157 | __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */ |
| 1158 | *skb = NULL; |
| 1159 | entry->first_frag_time = jiffies; |
| 1160 | entry->seq = seq; |
| 1161 | entry->rx_queue = rx_queue; |
| 1162 | entry->last_frag = frag; |
| 1163 | entry->ccmp = 0; |
| 1164 | entry->extra_len = 0; |
| 1165 | |
| 1166 | return entry; |
| 1167 | } |
| 1168 | |
| 1169 | static inline struct ieee80211_fragment_entry * |
| 1170 | ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata, |
Harvey Harrison | b73d70a | 2008-07-15 18:44:12 -0700 | [diff] [blame] | 1171 | unsigned int frag, unsigned int seq, |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1172 | int rx_queue, struct ieee80211_hdr *hdr) |
| 1173 | { |
| 1174 | struct ieee80211_fragment_entry *entry; |
| 1175 | int i, idx; |
| 1176 | |
| 1177 | idx = sdata->fragment_next; |
| 1178 | for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) { |
| 1179 | struct ieee80211_hdr *f_hdr; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1180 | |
| 1181 | idx--; |
| 1182 | if (idx < 0) |
| 1183 | idx = IEEE80211_FRAGMENT_MAX - 1; |
| 1184 | |
| 1185 | entry = &sdata->fragments[idx]; |
| 1186 | if (skb_queue_empty(&entry->skb_list) || entry->seq != seq || |
| 1187 | entry->rx_queue != rx_queue || |
| 1188 | entry->last_frag + 1 != frag) |
| 1189 | continue; |
| 1190 | |
Harvey Harrison | b73d70a | 2008-07-15 18:44:12 -0700 | [diff] [blame] | 1191 | f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1192 | |
Harvey Harrison | b73d70a | 2008-07-15 18:44:12 -0700 | [diff] [blame] | 1193 | /* |
| 1194 | * Check ftype and addresses are equal, else check next fragment |
| 1195 | */ |
| 1196 | if (((hdr->frame_control ^ f_hdr->frame_control) & |
| 1197 | cpu_to_le16(IEEE80211_FCTL_FTYPE)) || |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1198 | compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 || |
| 1199 | compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0) |
| 1200 | continue; |
| 1201 | |
S.Çağlar Onur | ab46623 | 2008-02-14 17:36:47 +0200 | [diff] [blame] | 1202 | if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1203 | __skb_queue_purge(&entry->skb_list); |
| 1204 | continue; |
| 1205 | } |
| 1206 | return entry; |
| 1207 | } |
| 1208 | |
| 1209 | return NULL; |
| 1210 | } |
| 1211 | |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 1212 | static ieee80211_rx_result debug_noinline |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1213 | ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1214 | { |
| 1215 | struct ieee80211_hdr *hdr; |
| 1216 | u16 sc; |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1217 | __le16 fc; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1218 | unsigned int frag, seq; |
| 1219 | struct ieee80211_fragment_entry *entry; |
| 1220 | struct sk_buff *skb; |
| 1221 | |
Harvey Harrison | b73d70a | 2008-07-15 18:44:12 -0700 | [diff] [blame] | 1222 | hdr = (struct ieee80211_hdr *)rx->skb->data; |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1223 | fc = hdr->frame_control; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1224 | sc = le16_to_cpu(hdr->seq_ctrl); |
| 1225 | frag = sc & IEEE80211_SCTL_FRAG; |
| 1226 | |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1227 | if (likely((!ieee80211_has_morefrags(fc) && frag == 0) || |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1228 | (rx->skb)->len < 24 || |
| 1229 | is_multicast_ether_addr(hdr->addr1))) { |
| 1230 | /* not fragmented */ |
| 1231 | goto out; |
| 1232 | } |
| 1233 | I802_DEBUG_INC(rx->local->rx_handlers_fragments); |
| 1234 | |
| 1235 | seq = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 1236 | |
| 1237 | if (frag == 0) { |
| 1238 | /* This is the first fragment of a new frame. */ |
| 1239 | entry = ieee80211_reassemble_add(rx->sdata, frag, seq, |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1240 | rx->queue, &(rx->skb)); |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1241 | if (rx->key && rx->key->conf.alg == ALG_CCMP && |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1242 | ieee80211_has_protected(fc)) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1243 | /* Store CCMP PN so that we can verify that the next |
| 1244 | * fragment has a sequential PN value. */ |
| 1245 | entry->ccmp = 1; |
| 1246 | memcpy(entry->last_pn, |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1247 | rx->key->u.ccmp.rx_pn[rx->queue], |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1248 | CCMP_PN_LEN); |
| 1249 | } |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1250 | return RX_QUEUED; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | /* This is a fragment for a frame that should already be pending in |
| 1254 | * fragment cache. Add this fragment to the end of the pending entry. |
| 1255 | */ |
Harvey Harrison | b73d70a | 2008-07-15 18:44:12 -0700 | [diff] [blame] | 1256 | entry = ieee80211_reassemble_find(rx->sdata, frag, seq, rx->queue, hdr); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1257 | if (!entry) { |
| 1258 | I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag); |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1259 | return RX_DROP_MONITOR; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | /* Verify that MPDUs within one MSDU have sequential PN values. |
| 1263 | * (IEEE 802.11i, 8.3.3.4.5) */ |
| 1264 | if (entry->ccmp) { |
| 1265 | int i; |
| 1266 | u8 pn[CCMP_PN_LEN], *rpn; |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1267 | if (!rx->key || rx->key->conf.alg != ALG_CCMP) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1268 | return RX_DROP_UNUSABLE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1269 | memcpy(pn, entry->last_pn, CCMP_PN_LEN); |
| 1270 | for (i = CCMP_PN_LEN - 1; i >= 0; i--) { |
| 1271 | pn[i]++; |
| 1272 | if (pn[i]) |
| 1273 | break; |
| 1274 | } |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1275 | rpn = rx->key->u.ccmp.rx_pn[rx->queue]; |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1276 | if (memcmp(pn, rpn, CCMP_PN_LEN)) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1277 | return RX_DROP_UNUSABLE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1278 | memcpy(entry->last_pn, pn, CCMP_PN_LEN); |
| 1279 | } |
| 1280 | |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1281 | skb_pull(rx->skb, ieee80211_hdrlen(fc)); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1282 | __skb_queue_tail(&entry->skb_list, rx->skb); |
| 1283 | entry->last_frag = frag; |
| 1284 | entry->extra_len += rx->skb->len; |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1285 | if (ieee80211_has_morefrags(fc)) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1286 | rx->skb = NULL; |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1287 | return RX_QUEUED; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | rx->skb = __skb_dequeue(&entry->skb_list); |
| 1291 | if (skb_tailroom(rx->skb) < entry->extra_len) { |
| 1292 | I802_DEBUG_INC(rx->local->rx_expand_skb_head2); |
| 1293 | if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len, |
| 1294 | GFP_ATOMIC))) { |
| 1295 | I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag); |
| 1296 | __skb_queue_purge(&entry->skb_list); |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1297 | return RX_DROP_UNUSABLE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1298 | } |
| 1299 | } |
| 1300 | while ((skb = __skb_dequeue(&entry->skb_list))) { |
| 1301 | memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len); |
| 1302 | dev_kfree_skb(skb); |
| 1303 | } |
| 1304 | |
| 1305 | /* Complete frame has been reassembled - process it now */ |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1306 | rx->flags |= IEEE80211_RX_FRAGMENTED; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1307 | |
| 1308 | out: |
| 1309 | if (rx->sta) |
| 1310 | rx->sta->rx_packets++; |
| 1311 | if (is_multicast_ether_addr(hdr->addr1)) |
| 1312 | rx->local->dot11MulticastReceivedFrameCount++; |
| 1313 | else |
| 1314 | ieee80211_led_rx(rx->local); |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1315 | return RX_CONTINUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1316 | } |
| 1317 | |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 1318 | static ieee80211_rx_result debug_noinline |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1319 | ieee80211_rx_h_ps_poll(struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1320 | { |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1321 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1322 | __le16 fc = ((struct ieee80211_hdr *)rx->skb->data)->frame_control; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1323 | |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1324 | if (likely(!rx->sta || !ieee80211_is_pspoll(fc) || |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1325 | !(rx->flags & IEEE80211_RX_RA_MATCH))) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1326 | return RX_CONTINUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1327 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1328 | if ((sdata->vif.type != NL80211_IFTYPE_AP) && |
| 1329 | (sdata->vif.type != NL80211_IFTYPE_AP_VLAN)) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1330 | return RX_DROP_UNUSABLE; |
Ron Rindjunsky | 98f0b0a | 2007-12-18 17:23:53 +0200 | [diff] [blame] | 1331 | |
Johannes Berg | af81858 | 2009-11-06 11:35:50 +0100 | [diff] [blame] | 1332 | if (!test_sta_flags(rx->sta, WLAN_STA_PS_DRIVER)) |
| 1333 | ieee80211_sta_ps_deliver_poll_response(rx->sta); |
| 1334 | else |
| 1335 | set_sta_flags(rx->sta, WLAN_STA_PSPOLL); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1336 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1337 | /* Free PS Poll skb here instead of returning RX_DROP that would |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1338 | * count as an dropped frame. */ |
| 1339 | dev_kfree_skb(rx->skb); |
| 1340 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1341 | return RX_QUEUED; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1342 | } |
| 1343 | |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 1344 | static ieee80211_rx_result debug_noinline |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1345 | ieee80211_rx_h_remove_qos_control(struct ieee80211_rx_data *rx) |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1346 | { |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1347 | u8 *data = rx->skb->data; |
Harvey Harrison | 238f74a | 2008-07-02 11:05:34 -0700 | [diff] [blame] | 1348 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)data; |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1349 | |
Harvey Harrison | 238f74a | 2008-07-02 11:05:34 -0700 | [diff] [blame] | 1350 | if (!ieee80211_is_data_qos(hdr->frame_control)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1351 | return RX_CONTINUE; |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1352 | |
| 1353 | /* remove the qos control field, update frame type and meta-data */ |
Harvey Harrison | 238f74a | 2008-07-02 11:05:34 -0700 | [diff] [blame] | 1354 | memmove(data + IEEE80211_QOS_CTL_LEN, data, |
| 1355 | ieee80211_hdrlen(hdr->frame_control) - IEEE80211_QOS_CTL_LEN); |
| 1356 | hdr = (struct ieee80211_hdr *)skb_pull(rx->skb, IEEE80211_QOS_CTL_LEN); |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1357 | /* change frame type to non QOS */ |
Harvey Harrison | 238f74a | 2008-07-02 11:05:34 -0700 | [diff] [blame] | 1358 | hdr->frame_control &= ~cpu_to_le16(IEEE80211_STYPE_QOS_DATA); |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1359 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1360 | return RX_CONTINUE; |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1361 | } |
| 1362 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1363 | static int |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1364 | ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1365 | { |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1366 | if (unlikely(!rx->sta || |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1367 | !test_sta_flags(rx->sta, WLAN_STA_AUTHORIZED))) |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1368 | return -EACCES; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1369 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1370 | return 0; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1371 | } |
| 1372 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1373 | static int |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1374 | ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1375 | { |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 1376 | struct sk_buff *skb = rx->skb; |
| 1377 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
| 1378 | |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 1379 | /* |
Johannes Berg | 7848ba7 | 2007-09-14 11:10:25 -0400 | [diff] [blame] | 1380 | * Pass through unencrypted frames if the hardware has |
| 1381 | * decrypted them already. |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 1382 | */ |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 1383 | if (status->flag & RX_FLAG_DECRYPTED) |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1384 | return 0; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1385 | |
| 1386 | /* Drop unencrypted frames if key is set. */ |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1387 | if (unlikely(!ieee80211_has_protected(fc) && |
| 1388 | !ieee80211_is_nullfunc(fc) && |
Jouni Malinen | f2ca3ea4 | 2009-05-08 12:36:03 +0300 | [diff] [blame] | 1389 | ieee80211_is_data(fc) && |
Jouni Malinen | 3cfcf6a | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1390 | (rx->key || rx->sdata->drop_unencrypted))) |
| 1391 | return -EACCES; |
Jouni Malinen | f2ca3ea4 | 2009-05-08 12:36:03 +0300 | [diff] [blame] | 1392 | if (rx->sta && test_sta_flags(rx->sta, WLAN_STA_MFP)) { |
| 1393 | if (unlikely(ieee80211_is_unicast_robust_mgmt_frame(rx->skb) && |
| 1394 | rx->key)) |
| 1395 | return -EACCES; |
| 1396 | /* BIP does not use Protected field, so need to check MMIE */ |
| 1397 | if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) |
| 1398 | && ieee80211_get_mmie_keyidx(rx->skb) < 0 && |
| 1399 | rx->key)) |
| 1400 | return -EACCES; |
| 1401 | /* |
| 1402 | * When using MFP, Action frames are not allowed prior to |
| 1403 | * having configured keys. |
| 1404 | */ |
| 1405 | if (unlikely(ieee80211_is_action(fc) && !rx->key && |
| 1406 | ieee80211_is_robust_mgmt_frame( |
| 1407 | (struct ieee80211_hdr *) rx->skb->data))) |
| 1408 | return -EACCES; |
| 1409 | } |
Johannes Berg | b3fc9c6 | 2008-04-13 10:12:47 +0200 | [diff] [blame] | 1410 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1411 | return 0; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1412 | } |
| 1413 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1414 | static int |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 1415 | __ieee80211_data_to_8023(struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1416 | { |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 1417 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
| 1418 | struct net_device *dev = sdata->dev; |
Felix Fietkau | f14543e | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 1419 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; |
| 1420 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1421 | if (ieee80211_has_a4(hdr->frame_control) && |
| 1422 | sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta) |
Felix Fietkau | f14543e | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 1423 | return -1; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1424 | |
| 1425 | if (is_multicast_ether_addr(hdr->addr1) && |
| 1426 | ((sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta) || |
| 1427 | (sdata->vif.type == NL80211_IFTYPE_STATION && sdata->u.mgd.use_4addr))) |
Felix Fietkau | f14543e | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 1428 | return -1; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1429 | |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 1430 | return ieee80211_data_to_8023(rx->skb, dev->dev_addr, sdata->vif.type); |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1431 | } |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1432 | |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1433 | /* |
| 1434 | * requires that rx->skb is a frame with ethernet header |
| 1435 | */ |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1436 | static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc) |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1437 | { |
Senthil Balasubramanian | c97c23e | 2008-05-28 23:15:32 +0530 | [diff] [blame] | 1438 | static const u8 pae_group_addr[ETH_ALEN] __aligned(2) |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1439 | = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 }; |
| 1440 | struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data; |
| 1441 | |
| 1442 | /* |
| 1443 | * Allow EAPOL frames to us/the PAE group address regardless |
| 1444 | * of whether the frame was encrypted or not. |
| 1445 | */ |
| 1446 | if (ehdr->h_proto == htons(ETH_P_PAE) && |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 1447 | (compare_ether_addr(ehdr->h_dest, rx->sdata->dev->dev_addr) == 0 || |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1448 | compare_ether_addr(ehdr->h_dest, pae_group_addr) == 0)) |
| 1449 | return true; |
| 1450 | |
| 1451 | if (ieee80211_802_1x_port_control(rx) || |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1452 | ieee80211_drop_unencrypted(rx, fc)) |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1453 | return false; |
| 1454 | |
| 1455 | return true; |
| 1456 | } |
| 1457 | |
| 1458 | /* |
| 1459 | * requires that rx->skb is a frame with ethernet header |
| 1460 | */ |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1461 | static void |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1462 | ieee80211_deliver_skb(struct ieee80211_rx_data *rx) |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1463 | { |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 1464 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
| 1465 | struct net_device *dev = sdata->dev; |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1466 | struct ieee80211_local *local = rx->local; |
| 1467 | struct sk_buff *skb, *xmit_skb; |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1468 | struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data; |
| 1469 | struct sta_info *dsta; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1470 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1471 | skb = rx->skb; |
| 1472 | xmit_skb = NULL; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1473 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1474 | if ((sdata->vif.type == NL80211_IFTYPE_AP || |
| 1475 | sdata->vif.type == NL80211_IFTYPE_AP_VLAN) && |
Johannes Berg | 213cd11 | 2008-09-11 00:01:54 +0200 | [diff] [blame] | 1476 | !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) && |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1477 | (rx->flags & IEEE80211_RX_RA_MATCH) && |
| 1478 | (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) { |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1479 | if (is_multicast_ether_addr(ehdr->h_dest)) { |
| 1480 | /* |
| 1481 | * send multicast frames both to higher layers in |
| 1482 | * local net stack and back to the wireless medium |
| 1483 | */ |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1484 | xmit_skb = skb_copy(skb, GFP_ATOMIC); |
| 1485 | if (!xmit_skb && net_ratelimit()) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1486 | printk(KERN_DEBUG "%s: failed to clone " |
| 1487 | "multicast frame\n", dev->name); |
| 1488 | } else { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1489 | dsta = sta_info_get(local, skb->data); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1490 | if (dsta && dsta->sdata->dev == dev) { |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1491 | /* |
| 1492 | * The destination station is associated to |
| 1493 | * this AP (in this VLAN), so send the frame |
| 1494 | * directly to it and do not pass it to local |
| 1495 | * net stack. |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1496 | */ |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1497 | xmit_skb = skb; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1498 | skb = NULL; |
| 1499 | } |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1500 | } |
| 1501 | } |
| 1502 | |
| 1503 | if (skb) { |
Johannes Berg | d1c3a37 | 2009-01-07 00:26:10 +0100 | [diff] [blame] | 1504 | int align __maybe_unused; |
| 1505 | |
| 1506 | #if defined(CONFIG_MAC80211_DEBUG_PACKET_ALIGNMENT) || !defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) |
| 1507 | /* |
| 1508 | * 'align' will only take the values 0 or 2 here |
| 1509 | * since all frames are required to be aligned |
| 1510 | * to 2-byte boundaries when being passed to |
| 1511 | * mac80211. That also explains the __skb_push() |
| 1512 | * below. |
| 1513 | */ |
matthieu castet | dacb6f1 | 2009-06-04 22:16:18 +0200 | [diff] [blame] | 1514 | align = ((unsigned long)(skb->data + sizeof(struct ethhdr))) & 3; |
Johannes Berg | d1c3a37 | 2009-01-07 00:26:10 +0100 | [diff] [blame] | 1515 | if (align) { |
| 1516 | if (WARN_ON(skb_headroom(skb) < 3)) { |
| 1517 | dev_kfree_skb(skb); |
| 1518 | skb = NULL; |
| 1519 | } else { |
| 1520 | u8 *data = skb->data; |
Zhu Yi | 8ce0b58 | 2009-10-28 13:13:52 -0700 | [diff] [blame] | 1521 | size_t len = skb_headlen(skb); |
| 1522 | skb->data -= align; |
| 1523 | memmove(skb->data, data, len); |
| 1524 | skb_set_tail_pointer(skb, len); |
Johannes Berg | d1c3a37 | 2009-01-07 00:26:10 +0100 | [diff] [blame] | 1525 | } |
| 1526 | } |
| 1527 | #endif |
| 1528 | |
| 1529 | if (skb) { |
| 1530 | /* deliver to local stack */ |
| 1531 | skb->protocol = eth_type_trans(skb, dev); |
| 1532 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 1533 | netif_rx(skb); |
| 1534 | } |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1535 | } |
| 1536 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1537 | if (xmit_skb) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1538 | /* send to wireless media */ |
YOSHIFUJI Hideaki | f831e90 | 2007-12-12 03:54:23 +0900 | [diff] [blame] | 1539 | xmit_skb->protocol = htons(ETH_P_802_3); |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1540 | skb_reset_network_header(xmit_skb); |
| 1541 | skb_reset_mac_header(xmit_skb); |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1542 | dev_queue_xmit(xmit_skb); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1543 | } |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1544 | } |
| 1545 | |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 1546 | static ieee80211_rx_result debug_noinline |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1547 | ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx) |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1548 | { |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 1549 | struct net_device *dev = rx->sdata->dev; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1550 | struct ieee80211_local *local = rx->local; |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1551 | u16 ethertype; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1552 | u8 *payload; |
| 1553 | struct sk_buff *skb = rx->skb, *frame = NULL; |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1554 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 1555 | __le16 fc = hdr->frame_control; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1556 | const struct ethhdr *eth; |
| 1557 | int remaining, err; |
| 1558 | u8 dst[ETH_ALEN]; |
| 1559 | u8 src[ETH_ALEN]; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1560 | |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1561 | if (unlikely(!ieee80211_is_data(fc))) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1562 | return RX_CONTINUE; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1563 | |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1564 | if (unlikely(!ieee80211_is_data_present(fc))) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1565 | return RX_DROP_MONITOR; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1566 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1567 | if (!(rx->flags & IEEE80211_RX_AMSDU)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1568 | return RX_CONTINUE; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1569 | |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 1570 | err = __ieee80211_data_to_8023(rx); |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1571 | if (unlikely(err)) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1572 | return RX_DROP_UNUSABLE; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1573 | |
| 1574 | skb->dev = dev; |
| 1575 | |
| 1576 | dev->stats.rx_packets++; |
| 1577 | dev->stats.rx_bytes += skb->len; |
| 1578 | |
| 1579 | /* skip the wrapping header */ |
| 1580 | eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr)); |
| 1581 | if (!eth) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1582 | return RX_DROP_UNUSABLE; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1583 | |
| 1584 | while (skb != frame) { |
| 1585 | u8 padding; |
| 1586 | __be16 len = eth->h_proto; |
| 1587 | unsigned int subframe_len = sizeof(struct ethhdr) + ntohs(len); |
| 1588 | |
| 1589 | remaining = skb->len; |
| 1590 | memcpy(dst, eth->h_dest, ETH_ALEN); |
| 1591 | memcpy(src, eth->h_source, ETH_ALEN); |
| 1592 | |
| 1593 | padding = ((4 - subframe_len) & 0x3); |
| 1594 | /* the last MSDU has no padding */ |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1595 | if (subframe_len > remaining) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1596 | return RX_DROP_UNUSABLE; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1597 | |
| 1598 | skb_pull(skb, sizeof(struct ethhdr)); |
| 1599 | /* if last subframe reuse skb */ |
| 1600 | if (remaining <= subframe_len + padding) |
| 1601 | frame = skb; |
| 1602 | else { |
Johannes Berg | d1c3a37 | 2009-01-07 00:26:10 +0100 | [diff] [blame] | 1603 | /* |
| 1604 | * Allocate and reserve two bytes more for payload |
| 1605 | * alignment since sizeof(struct ethhdr) is 14. |
| 1606 | */ |
| 1607 | frame = dev_alloc_skb( |
| 1608 | ALIGN(local->hw.extra_tx_headroom, 4) + |
| 1609 | subframe_len + 2); |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1610 | |
| 1611 | if (frame == NULL) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1612 | return RX_DROP_UNUSABLE; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1613 | |
Johannes Berg | d1c3a37 | 2009-01-07 00:26:10 +0100 | [diff] [blame] | 1614 | skb_reserve(frame, |
| 1615 | ALIGN(local->hw.extra_tx_headroom, 4) + |
| 1616 | sizeof(struct ethhdr) + 2); |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1617 | memcpy(skb_put(frame, ntohs(len)), skb->data, |
| 1618 | ntohs(len)); |
| 1619 | |
| 1620 | eth = (struct ethhdr *) skb_pull(skb, ntohs(len) + |
| 1621 | padding); |
| 1622 | if (!eth) { |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1623 | dev_kfree_skb(frame); |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1624 | return RX_DROP_UNUSABLE; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1625 | } |
| 1626 | } |
| 1627 | |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1628 | skb_reset_network_header(frame); |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1629 | frame->dev = dev; |
| 1630 | frame->priority = skb->priority; |
| 1631 | rx->skb = frame; |
| 1632 | |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1633 | payload = frame->data; |
| 1634 | ethertype = (payload[6] << 8) | payload[7]; |
| 1635 | |
| 1636 | if (likely((compare_ether_addr(payload, rfc1042_header) == 0 && |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1637 | ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) || |
| 1638 | compare_ether_addr(payload, |
| 1639 | bridge_tunnel_header) == 0)) { |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1640 | /* remove RFC1042 or Bridge-Tunnel |
| 1641 | * encapsulation and replace EtherType */ |
| 1642 | skb_pull(frame, 6); |
| 1643 | memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN); |
| 1644 | memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN); |
| 1645 | } else { |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1646 | memcpy(skb_push(frame, sizeof(__be16)), |
| 1647 | &len, sizeof(__be16)); |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1648 | memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN); |
| 1649 | memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN); |
| 1650 | } |
| 1651 | |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1652 | if (!ieee80211_frame_allowed(rx, fc)) { |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1653 | if (skb == frame) /* last frame */ |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1654 | return RX_DROP_UNUSABLE; |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1655 | dev_kfree_skb(frame); |
| 1656 | continue; |
| 1657 | } |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1658 | |
| 1659 | ieee80211_deliver_skb(rx); |
| 1660 | } |
| 1661 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1662 | return RX_QUEUED; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1663 | } |
| 1664 | |
Ingo Molnar | bf94e17 | 2008-10-12 23:51:38 -0700 | [diff] [blame] | 1665 | #ifdef CONFIG_MAC80211_MESH |
Davide Pesavento | b0dee57 | 2008-09-27 17:29:12 +0200 | [diff] [blame] | 1666 | static ieee80211_rx_result |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 1667 | ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx) |
| 1668 | { |
| 1669 | struct ieee80211_hdr *hdr; |
| 1670 | struct ieee80211s_hdr *mesh_hdr; |
| 1671 | unsigned int hdrlen; |
| 1672 | struct sk_buff *skb = rx->skb, *fwd_skb; |
Johannes Berg | 3b8d81e | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 1673 | struct ieee80211_local *local = rx->local; |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 1674 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 1675 | |
| 1676 | hdr = (struct ieee80211_hdr *) skb->data; |
| 1677 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
| 1678 | mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen); |
| 1679 | |
| 1680 | if (!ieee80211_is_data(hdr->frame_control)) |
| 1681 | return RX_CONTINUE; |
| 1682 | |
| 1683 | if (!mesh_hdr->ttl) |
| 1684 | /* illegal frame */ |
| 1685 | return RX_DROP_MONITOR; |
| 1686 | |
Javier Cardona | 43b7b31 | 2009-10-15 18:10:51 -0700 | [diff] [blame] | 1687 | if (mesh_hdr->flags & MESH_FLAGS_AE) { |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 1688 | struct mesh_path *mppath; |
Javier Cardona | 43b7b31 | 2009-10-15 18:10:51 -0700 | [diff] [blame] | 1689 | char *proxied_addr; |
| 1690 | char *mpp_addr; |
| 1691 | |
| 1692 | if (is_multicast_ether_addr(hdr->addr1)) { |
| 1693 | mpp_addr = hdr->addr3; |
| 1694 | proxied_addr = mesh_hdr->eaddr1; |
| 1695 | } else { |
| 1696 | mpp_addr = hdr->addr4; |
| 1697 | proxied_addr = mesh_hdr->eaddr2; |
| 1698 | } |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 1699 | |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 1700 | rcu_read_lock(); |
Javier Cardona | 43b7b31 | 2009-10-15 18:10:51 -0700 | [diff] [blame] | 1701 | mppath = mpp_path_lookup(proxied_addr, sdata); |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 1702 | if (!mppath) { |
Javier Cardona | 43b7b31 | 2009-10-15 18:10:51 -0700 | [diff] [blame] | 1703 | mpp_path_add(proxied_addr, mpp_addr, sdata); |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 1704 | } else { |
| 1705 | spin_lock_bh(&mppath->state_lock); |
| 1706 | mppath->exp_time = jiffies; |
Javier Cardona | 43b7b31 | 2009-10-15 18:10:51 -0700 | [diff] [blame] | 1707 | if (compare_ether_addr(mppath->mpp, mpp_addr) != 0) |
| 1708 | memcpy(mppath->mpp, mpp_addr, ETH_ALEN); |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 1709 | spin_unlock_bh(&mppath->state_lock); |
| 1710 | } |
| 1711 | rcu_read_unlock(); |
| 1712 | } |
| 1713 | |
Javier Cardona | 3c5772a | 2009-08-10 12:15:48 -0700 | [diff] [blame] | 1714 | /* Frame has reached destination. Don't forward */ |
| 1715 | if (!is_multicast_ether_addr(hdr->addr1) && |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 1716 | compare_ether_addr(sdata->dev->dev_addr, hdr->addr3) == 0) |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 1717 | return RX_CONTINUE; |
| 1718 | |
| 1719 | mesh_hdr->ttl--; |
| 1720 | |
| 1721 | if (rx->flags & IEEE80211_RX_RA_MATCH) { |
| 1722 | if (!mesh_hdr->ttl) |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 1723 | IEEE80211_IFSTA_MESH_CTR_INC(&rx->sdata->u.mesh, |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 1724 | dropped_frames_ttl); |
| 1725 | else { |
| 1726 | struct ieee80211_hdr *fwd_hdr; |
Johannes Berg | 3b8d81e | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 1727 | struct ieee80211_tx_info *info; |
| 1728 | |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 1729 | fwd_skb = skb_copy(skb, GFP_ATOMIC); |
| 1730 | |
| 1731 | if (!fwd_skb && net_ratelimit()) |
| 1732 | printk(KERN_DEBUG "%s: failed to clone mesh frame\n", |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 1733 | sdata->dev->name); |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 1734 | |
| 1735 | fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data; |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 1736 | memcpy(fwd_hdr->addr2, sdata->dev->dev_addr, ETH_ALEN); |
Johannes Berg | 3b8d81e | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 1737 | info = IEEE80211_SKB_CB(fwd_skb); |
| 1738 | memset(info, 0, sizeof(*info)); |
| 1739 | info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING; |
Johannes Berg | 5061b0c | 2009-07-14 00:33:34 +0200 | [diff] [blame] | 1740 | info->control.vif = &rx->sdata->vif; |
Johannes Berg | 3b8d81e | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 1741 | ieee80211_select_queue(local, fwd_skb); |
Daniel Walker | c8a61a7 | 2009-08-18 10:59:00 -0700 | [diff] [blame] | 1742 | if (is_multicast_ether_addr(fwd_hdr->addr1)) |
| 1743 | IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh, |
| 1744 | fwded_mcast); |
| 1745 | else { |
Javier Cardona | 3c5772a | 2009-08-10 12:15:48 -0700 | [diff] [blame] | 1746 | int err; |
| 1747 | /* |
| 1748 | * Save TA to addr1 to send TA a path error if a |
| 1749 | * suitable next hop is not found |
| 1750 | */ |
| 1751 | memcpy(fwd_hdr->addr1, fwd_hdr->addr2, |
Javier Cardona | 249b405 | 2009-07-07 10:55:03 -0700 | [diff] [blame] | 1752 | ETH_ALEN); |
Javier Cardona | 3c5772a | 2009-08-10 12:15:48 -0700 | [diff] [blame] | 1753 | err = mesh_nexthop_lookup(fwd_skb, sdata); |
Javier Cardona | 249b405 | 2009-07-07 10:55:03 -0700 | [diff] [blame] | 1754 | /* Failed to immediately resolve next hop: |
| 1755 | * fwded frame was dropped or will be added |
| 1756 | * later to the pending skb queue. */ |
| 1757 | if (err) |
| 1758 | return RX_DROP_MONITOR; |
Daniel Walker | c8a61a7 | 2009-08-18 10:59:00 -0700 | [diff] [blame] | 1759 | |
| 1760 | IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh, |
| 1761 | fwded_unicast); |
Javier Cardona | 249b405 | 2009-07-07 10:55:03 -0700 | [diff] [blame] | 1762 | } |
| 1763 | IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh, |
| 1764 | fwded_frames); |
Johannes Berg | 3b8d81e | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 1765 | ieee80211_add_pending_skb(local, fwd_skb); |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 1766 | } |
| 1767 | } |
| 1768 | |
Javier Cardona | 3c5772a | 2009-08-10 12:15:48 -0700 | [diff] [blame] | 1769 | if (is_multicast_ether_addr(hdr->addr1) || |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 1770 | sdata->dev->flags & IFF_PROMISC) |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 1771 | return RX_CONTINUE; |
| 1772 | else |
| 1773 | return RX_DROP_MONITOR; |
| 1774 | } |
Ingo Molnar | bf94e17 | 2008-10-12 23:51:38 -0700 | [diff] [blame] | 1775 | #endif |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 1776 | |
| 1777 | static ieee80211_rx_result debug_noinline |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1778 | ieee80211_rx_h_data(struct ieee80211_rx_data *rx) |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1779 | { |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 1780 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
| 1781 | struct net_device *dev = sdata->dev; |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1782 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; |
| 1783 | __le16 fc = hdr->frame_control; |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1784 | int err; |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1785 | |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1786 | if (unlikely(!ieee80211_is_data(hdr->frame_control))) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1787 | return RX_CONTINUE; |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1788 | |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1789 | if (unlikely(!ieee80211_is_data_present(hdr->frame_control))) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1790 | return RX_DROP_MONITOR; |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1791 | |
Felix Fietkau | f14543e | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 1792 | /* |
| 1793 | * Allow the cooked monitor interface of an AP to see 4-addr frames so |
| 1794 | * that a 4-addr station can be detected and moved into a separate VLAN |
| 1795 | */ |
| 1796 | if (ieee80211_has_a4(hdr->frame_control) && |
| 1797 | sdata->vif.type == NL80211_IFTYPE_AP) |
| 1798 | return RX_DROP_MONITOR; |
| 1799 | |
Zhu Yi | e31a16d | 2009-05-21 21:47:03 +0800 | [diff] [blame] | 1800 | err = __ieee80211_data_to_8023(rx); |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1801 | if (unlikely(err)) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1802 | return RX_DROP_UNUSABLE; |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1803 | |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1804 | if (!ieee80211_frame_allowed(rx, fc)) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1805 | return RX_DROP_MONITOR; |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1806 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1807 | rx->skb->dev = dev; |
| 1808 | |
| 1809 | dev->stats.rx_packets++; |
| 1810 | dev->stats.rx_bytes += rx->skb->len; |
| 1811 | |
| 1812 | ieee80211_deliver_skb(rx); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1813 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1814 | return RX_QUEUED; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1815 | } |
| 1816 | |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 1817 | static ieee80211_rx_result debug_noinline |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1818 | ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx) |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 1819 | { |
| 1820 | struct ieee80211_local *local = rx->local; |
| 1821 | struct ieee80211_hw *hw = &local->hw; |
| 1822 | struct sk_buff *skb = rx->skb; |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 1823 | struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data; |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 1824 | struct tid_ampdu_rx *tid_agg_rx; |
| 1825 | u16 start_seq_num; |
| 1826 | u16 tid; |
| 1827 | |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 1828 | if (likely(!ieee80211_is_ctl(bar->frame_control))) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1829 | return RX_CONTINUE; |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 1830 | |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 1831 | if (ieee80211_is_back_req(bar->frame_control)) { |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 1832 | if (!rx->sta) |
Johannes Berg | a02ae75 | 2009-11-16 12:00:40 +0100 | [diff] [blame] | 1833 | return RX_DROP_MONITOR; |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 1834 | tid = le16_to_cpu(bar->control) >> 12; |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1835 | if (rx->sta->ampdu_mlme.tid_state_rx[tid] |
| 1836 | != HT_AGG_STATE_OPERATIONAL) |
Johannes Berg | a02ae75 | 2009-11-16 12:00:40 +0100 | [diff] [blame] | 1837 | return RX_DROP_MONITOR; |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1838 | tid_agg_rx = rx->sta->ampdu_mlme.tid_rx[tid]; |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 1839 | |
| 1840 | start_seq_num = le16_to_cpu(bar->start_seq_num) >> 4; |
| 1841 | |
| 1842 | /* reset session timer */ |
Johannes Berg | 20ad19d | 2009-02-10 21:25:45 +0100 | [diff] [blame] | 1843 | if (tid_agg_rx->timeout) |
| 1844 | mod_timer(&tid_agg_rx->session_timer, |
| 1845 | TU_TO_EXP_TIME(tid_agg_rx->timeout)); |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 1846 | |
Johannes Berg | a02ae75 | 2009-11-16 12:00:40 +0100 | [diff] [blame] | 1847 | /* release stored frames up to start of BAR */ |
| 1848 | ieee80211_release_reorder_frames(hw, tid_agg_rx, start_seq_num); |
| 1849 | kfree_skb(skb); |
| 1850 | return RX_QUEUED; |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 1851 | } |
| 1852 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1853 | return RX_CONTINUE; |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 1854 | } |
| 1855 | |
Jouni Malinen | f4f727a | 2009-01-10 11:46:53 +0200 | [diff] [blame] | 1856 | static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata, |
| 1857 | struct ieee80211_mgmt *mgmt, |
| 1858 | size_t len) |
Jouni Malinen | fea1473 | 2009-01-08 13:32:06 +0200 | [diff] [blame] | 1859 | { |
| 1860 | struct ieee80211_local *local = sdata->local; |
| 1861 | struct sk_buff *skb; |
| 1862 | struct ieee80211_mgmt *resp; |
| 1863 | |
| 1864 | if (compare_ether_addr(mgmt->da, sdata->dev->dev_addr) != 0) { |
| 1865 | /* Not to own unicast address */ |
| 1866 | return; |
| 1867 | } |
| 1868 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1869 | if (compare_ether_addr(mgmt->sa, sdata->u.mgd.bssid) != 0 || |
| 1870 | compare_ether_addr(mgmt->bssid, sdata->u.mgd.bssid) != 0) { |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1871 | /* Not from the current AP or not associated yet. */ |
Jouni Malinen | fea1473 | 2009-01-08 13:32:06 +0200 | [diff] [blame] | 1872 | return; |
| 1873 | } |
| 1874 | |
| 1875 | if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) { |
| 1876 | /* Too short SA Query request frame */ |
| 1877 | return; |
| 1878 | } |
| 1879 | |
| 1880 | skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom); |
| 1881 | if (skb == NULL) |
| 1882 | return; |
| 1883 | |
| 1884 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 1885 | resp = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 1886 | memset(resp, 0, 24); |
| 1887 | memcpy(resp->da, mgmt->sa, ETH_ALEN); |
| 1888 | memcpy(resp->sa, sdata->dev->dev_addr, ETH_ALEN); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1889 | memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN); |
Jouni Malinen | fea1473 | 2009-01-08 13:32:06 +0200 | [diff] [blame] | 1890 | resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 1891 | IEEE80211_STYPE_ACTION); |
| 1892 | skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query)); |
| 1893 | resp->u.action.category = WLAN_CATEGORY_SA_QUERY; |
| 1894 | resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE; |
| 1895 | memcpy(resp->u.action.u.sa_query.trans_id, |
| 1896 | mgmt->u.action.u.sa_query.trans_id, |
| 1897 | WLAN_SA_QUERY_TR_ID_LEN); |
| 1898 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 1899 | ieee80211_tx_skb(sdata, skb); |
Jouni Malinen | fea1473 | 2009-01-08 13:32:06 +0200 | [diff] [blame] | 1900 | } |
| 1901 | |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 1902 | static ieee80211_rx_result debug_noinline |
Johannes Berg | de1ede7a | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 1903 | ieee80211_rx_h_action(struct ieee80211_rx_data *rx) |
| 1904 | { |
| 1905 | struct ieee80211_local *local = rx->local; |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 1906 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
Johannes Berg | de1ede7a | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 1907 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data; |
| 1908 | int len = rx->skb->len; |
| 1909 | |
| 1910 | if (!ieee80211_is_action(mgmt->frame_control)) |
| 1911 | return RX_CONTINUE; |
| 1912 | |
| 1913 | if (!rx->sta) |
| 1914 | return RX_DROP_MONITOR; |
| 1915 | |
| 1916 | if (!(rx->flags & IEEE80211_RX_RA_MATCH)) |
| 1917 | return RX_DROP_MONITOR; |
| 1918 | |
Jouni Malinen | 97ebe12 | 2009-01-08 13:32:08 +0200 | [diff] [blame] | 1919 | if (ieee80211_drop_unencrypted(rx, mgmt->frame_control)) |
| 1920 | return RX_DROP_MONITOR; |
| 1921 | |
Johannes Berg | de1ede7a | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 1922 | /* all categories we currently handle have action_code */ |
| 1923 | if (len < IEEE80211_MIN_ACTION_SIZE + 1) |
| 1924 | return RX_DROP_MONITOR; |
| 1925 | |
Johannes Berg | de1ede7a | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 1926 | switch (mgmt->u.action.category) { |
| 1927 | case WLAN_CATEGORY_BACK: |
Johannes Berg | 8abd3f9 | 2009-02-10 21:25:47 +0100 | [diff] [blame] | 1928 | /* |
| 1929 | * The aggregation code is not prepared to handle |
| 1930 | * anything but STA/AP due to the BSSID handling; |
| 1931 | * IBSS could work in the code but isn't supported |
| 1932 | * by drivers or the standard. |
| 1933 | */ |
| 1934 | if (sdata->vif.type != NL80211_IFTYPE_STATION && |
| 1935 | sdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
| 1936 | sdata->vif.type != NL80211_IFTYPE_AP) |
| 1937 | return RX_DROP_MONITOR; |
| 1938 | |
Johannes Berg | de1ede7a | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 1939 | switch (mgmt->u.action.u.addba_req.action_code) { |
| 1940 | case WLAN_ACTION_ADDBA_REQ: |
| 1941 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
| 1942 | sizeof(mgmt->u.action.u.addba_req))) |
| 1943 | return RX_DROP_MONITOR; |
| 1944 | ieee80211_process_addba_request(local, rx->sta, mgmt, len); |
| 1945 | break; |
| 1946 | case WLAN_ACTION_ADDBA_RESP: |
| 1947 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
| 1948 | sizeof(mgmt->u.action.u.addba_resp))) |
| 1949 | return RX_DROP_MONITOR; |
| 1950 | ieee80211_process_addba_resp(local, rx->sta, mgmt, len); |
| 1951 | break; |
| 1952 | case WLAN_ACTION_DELBA: |
| 1953 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
| 1954 | sizeof(mgmt->u.action.u.delba))) |
| 1955 | return RX_DROP_MONITOR; |
| 1956 | ieee80211_process_delba(sdata, rx->sta, mgmt, len); |
| 1957 | break; |
| 1958 | } |
Johannes Berg | 39192c0 | 2008-09-09 14:49:03 +0200 | [diff] [blame] | 1959 | break; |
| 1960 | case WLAN_CATEGORY_SPECTRUM_MGMT: |
| 1961 | if (local->hw.conf.channel->band != IEEE80211_BAND_5GHZ) |
| 1962 | return RX_DROP_MONITOR; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1963 | |
| 1964 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 1965 | return RX_DROP_MONITOR; |
| 1966 | |
Johannes Berg | 39192c0 | 2008-09-09 14:49:03 +0200 | [diff] [blame] | 1967 | switch (mgmt->u.action.u.measurement.action_code) { |
| 1968 | case WLAN_ACTION_SPCT_MSR_REQ: |
| 1969 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
| 1970 | sizeof(mgmt->u.action.u.measurement))) |
| 1971 | return RX_DROP_MONITOR; |
| 1972 | ieee80211_process_measurement_req(sdata, mgmt, len); |
| 1973 | break; |
Sujith | c481ec9 | 2009-01-06 09:28:37 +0530 | [diff] [blame] | 1974 | case WLAN_ACTION_SPCT_CHL_SWITCH: |
| 1975 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
| 1976 | sizeof(mgmt->u.action.u.chan_switch))) |
| 1977 | return RX_DROP_MONITOR; |
| 1978 | |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 1979 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 1980 | return RX_DROP_MONITOR; |
| 1981 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1982 | if (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN)) |
Sujith | c481ec9 | 2009-01-06 09:28:37 +0530 | [diff] [blame] | 1983 | return RX_DROP_MONITOR; |
| 1984 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1985 | return ieee80211_sta_rx_mgmt(sdata, rx->skb); |
Johannes Berg | 39192c0 | 2008-09-09 14:49:03 +0200 | [diff] [blame] | 1986 | } |
| 1987 | break; |
Jouni Malinen | fea1473 | 2009-01-08 13:32:06 +0200 | [diff] [blame] | 1988 | case WLAN_CATEGORY_SA_QUERY: |
| 1989 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
| 1990 | sizeof(mgmt->u.action.u.sa_query))) |
| 1991 | return RX_DROP_MONITOR; |
| 1992 | switch (mgmt->u.action.u.sa_query.action) { |
| 1993 | case WLAN_ACTION_SA_QUERY_REQUEST: |
| 1994 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 1995 | return RX_DROP_MONITOR; |
| 1996 | ieee80211_process_sa_query_req(sdata, mgmt, len); |
| 1997 | break; |
| 1998 | case WLAN_ACTION_SA_QUERY_RESPONSE: |
| 1999 | /* |
| 2000 | * SA Query response is currently only used in AP mode |
| 2001 | * and it is processed in user space. |
| 2002 | */ |
| 2003 | return RX_CONTINUE; |
| 2004 | } |
| 2005 | break; |
Johannes Berg | 39192c0 | 2008-09-09 14:49:03 +0200 | [diff] [blame] | 2006 | default: |
| 2007 | return RX_CONTINUE; |
Johannes Berg | de1ede7a | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 2008 | } |
| 2009 | |
Johannes Berg | 39192c0 | 2008-09-09 14:49:03 +0200 | [diff] [blame] | 2010 | rx->sta->rx_packets++; |
| 2011 | dev_kfree_skb(rx->skb); |
| 2012 | return RX_QUEUED; |
Johannes Berg | de1ede7a | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | static ieee80211_rx_result debug_noinline |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 2016 | ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2017 | { |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 2018 | struct ieee80211_sub_if_data *sdata = rx->sdata; |
Jouni Malinen | 97ebe12 | 2009-01-08 13:32:08 +0200 | [diff] [blame] | 2019 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2020 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 2021 | if (!(rx->flags & IEEE80211_RX_RA_MATCH)) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 2022 | return RX_DROP_MONITOR; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2023 | |
Jouni Malinen | 97ebe12 | 2009-01-08 13:32:08 +0200 | [diff] [blame] | 2024 | if (ieee80211_drop_unencrypted(rx, mgmt->frame_control)) |
| 2025 | return RX_DROP_MONITOR; |
| 2026 | |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 2027 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 2028 | return ieee80211_mesh_rx_mgmt(sdata, rx->skb); |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 2029 | |
Johannes Berg | 3832c28 | 2009-03-24 08:46:57 +0100 | [diff] [blame] | 2030 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 2031 | return ieee80211_ibss_rx_mgmt(sdata, rx->skb); |
Johannes Berg | f9d540e | 2007-09-28 14:02:09 +0200 | [diff] [blame] | 2032 | |
Johannes Berg | 7986cf9 | 2009-03-21 17:08:43 +0100 | [diff] [blame] | 2033 | if (sdata->vif.type == NL80211_IFTYPE_STATION) |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 2034 | return ieee80211_sta_rx_mgmt(sdata, rx->skb); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2035 | |
Johannes Berg | 7986cf9 | 2009-03-21 17:08:43 +0100 | [diff] [blame] | 2036 | return RX_DROP_MONITOR; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2037 | } |
| 2038 | |
Johannes Berg | 3b8d81e | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 2039 | static void ieee80211_rx_michael_mic_report(struct ieee80211_hdr *hdr, |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 2040 | struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2041 | { |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 2042 | int keyidx; |
| 2043 | unsigned int hdrlen; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2044 | |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 2045 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2046 | if (rx->skb->len >= hdrlen + 4) |
| 2047 | keyidx = rx->skb->data[hdrlen + 3] >> 6; |
| 2048 | else |
| 2049 | keyidx = -1; |
| 2050 | |
Johannes Berg | 8944b79 | 2008-01-31 19:48:26 +0100 | [diff] [blame] | 2051 | if (!rx->sta) { |
Johannes Berg | aa0daf0 | 2007-09-10 14:15:25 +0200 | [diff] [blame] | 2052 | /* |
| 2053 | * Some hardware seem to generate incorrect Michael MIC |
| 2054 | * reports; ignore them to avoid triggering countermeasures. |
| 2055 | */ |
Johannes Berg | af2ced6 | 2009-11-16 12:00:39 +0100 | [diff] [blame] | 2056 | return; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2057 | } |
| 2058 | |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 2059 | if (!ieee80211_has_protected(hdr->frame_control)) |
Johannes Berg | af2ced6 | 2009-11-16 12:00:39 +0100 | [diff] [blame] | 2060 | return; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2061 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2062 | if (rx->sdata->vif.type == NL80211_IFTYPE_AP && keyidx) { |
Johannes Berg | aa0daf0 | 2007-09-10 14:15:25 +0200 | [diff] [blame] | 2063 | /* |
| 2064 | * APs with pairwise keys should never receive Michael MIC |
| 2065 | * errors for non-zero keyidx because these are reserved for |
| 2066 | * group keys and only the AP is sending real multicast |
| 2067 | * frames in the BSS. |
| 2068 | */ |
Johannes Berg | af2ced6 | 2009-11-16 12:00:39 +0100 | [diff] [blame] | 2069 | return; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2070 | } |
| 2071 | |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 2072 | if (!ieee80211_is_data(hdr->frame_control) && |
| 2073 | !ieee80211_is_auth(hdr->frame_control)) |
Johannes Berg | af2ced6 | 2009-11-16 12:00:39 +0100 | [diff] [blame] | 2074 | return; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2075 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 2076 | mac80211_ev_michael_mic_failure(rx->sdata, keyidx, hdr, NULL, |
| 2077 | GFP_ATOMIC); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2078 | } |
| 2079 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 2080 | /* TODO: use IEEE80211_RX_FRAGMENTED */ |
Johannes Berg | 5f0b7de | 2009-11-16 13:58:21 +0100 | [diff] [blame] | 2081 | static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx, |
| 2082 | struct ieee80211_rate *rate) |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 2083 | { |
| 2084 | struct ieee80211_sub_if_data *sdata; |
| 2085 | struct ieee80211_local *local = rx->local; |
| 2086 | struct ieee80211_rtap_hdr { |
| 2087 | struct ieee80211_radiotap_header hdr; |
| 2088 | u8 flags; |
Johannes Berg | 5f0b7de | 2009-11-16 13:58:21 +0100 | [diff] [blame] | 2089 | u8 rate_or_pad; |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 2090 | __le16 chan_freq; |
| 2091 | __le16 chan_flags; |
| 2092 | } __attribute__ ((packed)) *rthdr; |
| 2093 | struct sk_buff *skb = rx->skb, *skb2; |
| 2094 | struct net_device *prev_dev = NULL; |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 2095 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 2096 | |
Johannes Berg | 8c0c709 | 2009-11-25 17:46:15 +0100 | [diff] [blame] | 2097 | if (status->flag & RX_FLAG_INTERNAL_CMTR) |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 2098 | goto out_free_skb; |
| 2099 | |
| 2100 | if (skb_headroom(skb) < sizeof(*rthdr) && |
| 2101 | pskb_expand_head(skb, sizeof(*rthdr), 0, GFP_ATOMIC)) |
| 2102 | goto out_free_skb; |
| 2103 | |
| 2104 | rthdr = (void *)skb_push(skb, sizeof(*rthdr)); |
| 2105 | memset(rthdr, 0, sizeof(*rthdr)); |
| 2106 | rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr)); |
| 2107 | rthdr->hdr.it_present = |
| 2108 | cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) | |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 2109 | (1 << IEEE80211_RADIOTAP_CHANNEL)); |
| 2110 | |
Johannes Berg | 5f0b7de | 2009-11-16 13:58:21 +0100 | [diff] [blame] | 2111 | if (rate) { |
| 2112 | rthdr->rate_or_pad = rate->bitrate / 5; |
| 2113 | rthdr->hdr.it_present |= |
| 2114 | cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE); |
| 2115 | } |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 2116 | rthdr->chan_freq = cpu_to_le16(status->freq); |
| 2117 | |
| 2118 | if (status->band == IEEE80211_BAND_5GHZ) |
| 2119 | rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_OFDM | |
| 2120 | IEEE80211_CHAN_5GHZ); |
| 2121 | else |
| 2122 | rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_DYN | |
| 2123 | IEEE80211_CHAN_2GHZ); |
| 2124 | |
| 2125 | skb_set_mac_header(skb, 0); |
| 2126 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 2127 | skb->pkt_type = PACKET_OTHERHOST; |
| 2128 | skb->protocol = htons(ETH_P_802_2); |
| 2129 | |
| 2130 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
| 2131 | if (!netif_running(sdata->dev)) |
| 2132 | continue; |
| 2133 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2134 | if (sdata->vif.type != NL80211_IFTYPE_MONITOR || |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 2135 | !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)) |
| 2136 | continue; |
| 2137 | |
| 2138 | if (prev_dev) { |
| 2139 | skb2 = skb_clone(skb, GFP_ATOMIC); |
| 2140 | if (skb2) { |
| 2141 | skb2->dev = prev_dev; |
| 2142 | netif_rx(skb2); |
| 2143 | } |
| 2144 | } |
| 2145 | |
| 2146 | prev_dev = sdata->dev; |
| 2147 | sdata->dev->stats.rx_packets++; |
| 2148 | sdata->dev->stats.rx_bytes += skb->len; |
| 2149 | } |
| 2150 | |
| 2151 | if (prev_dev) { |
| 2152 | skb->dev = prev_dev; |
| 2153 | netif_rx(skb); |
| 2154 | skb = NULL; |
| 2155 | } else |
| 2156 | goto out_free_skb; |
| 2157 | |
Johannes Berg | 8c0c709 | 2009-11-25 17:46:15 +0100 | [diff] [blame] | 2158 | status->flag |= RX_FLAG_INTERNAL_CMTR; |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 2159 | return; |
| 2160 | |
| 2161 | out_free_skb: |
| 2162 | dev_kfree_skb(skb); |
| 2163 | } |
| 2164 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2165 | |
Johannes Berg | 8944b79 | 2008-01-31 19:48:26 +0100 | [diff] [blame] | 2166 | static void ieee80211_invoke_rx_handlers(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 2167 | struct ieee80211_rx_data *rx, |
Johannes Berg | 5f0b7de | 2009-11-16 13:58:21 +0100 | [diff] [blame] | 2168 | struct sk_buff *skb, |
| 2169 | struct ieee80211_rate *rate) |
Johannes Berg | 5890529 | 2008-01-31 19:48:25 +0100 | [diff] [blame] | 2170 | { |
Johannes Berg | 5890529 | 2008-01-31 19:48:25 +0100 | [diff] [blame] | 2171 | ieee80211_rx_result res = RX_DROP_MONITOR; |
| 2172 | |
Johannes Berg | 8944b79 | 2008-01-31 19:48:26 +0100 | [diff] [blame] | 2173 | rx->skb = skb; |
| 2174 | rx->sdata = sdata; |
Johannes Berg | 8944b79 | 2008-01-31 19:48:26 +0100 | [diff] [blame] | 2175 | |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 2176 | #define CALL_RXH(rxh) \ |
| 2177 | do { \ |
| 2178 | res = rxh(rx); \ |
| 2179 | if (res != RX_CONTINUE) \ |
| 2180 | goto rxh_done; \ |
| 2181 | } while (0); |
Johannes Berg | 5890529 | 2008-01-31 19:48:25 +0100 | [diff] [blame] | 2182 | |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 2183 | CALL_RXH(ieee80211_rx_h_passive_scan) |
| 2184 | CALL_RXH(ieee80211_rx_h_check) |
| 2185 | CALL_RXH(ieee80211_rx_h_decrypt) |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 2186 | CALL_RXH(ieee80211_rx_h_check_more_data) |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 2187 | CALL_RXH(ieee80211_rx_h_sta_process) |
| 2188 | CALL_RXH(ieee80211_rx_h_defragment) |
| 2189 | CALL_RXH(ieee80211_rx_h_ps_poll) |
| 2190 | CALL_RXH(ieee80211_rx_h_michael_mic_verify) |
| 2191 | /* must be after MMIC verify so header is counted in MPDU mic */ |
| 2192 | CALL_RXH(ieee80211_rx_h_remove_qos_control) |
| 2193 | CALL_RXH(ieee80211_rx_h_amsdu) |
Ingo Molnar | bf94e17 | 2008-10-12 23:51:38 -0700 | [diff] [blame] | 2194 | #ifdef CONFIG_MAC80211_MESH |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 2195 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
| 2196 | CALL_RXH(ieee80211_rx_h_mesh_fwding); |
Ingo Molnar | bf94e17 | 2008-10-12 23:51:38 -0700 | [diff] [blame] | 2197 | #endif |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 2198 | CALL_RXH(ieee80211_rx_h_data) |
| 2199 | CALL_RXH(ieee80211_rx_h_ctrl) |
Johannes Berg | de1ede7a | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 2200 | CALL_RXH(ieee80211_rx_h_action) |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 2201 | CALL_RXH(ieee80211_rx_h_mgmt) |
Johannes Berg | 5890529 | 2008-01-31 19:48:25 +0100 | [diff] [blame] | 2202 | |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 2203 | #undef CALL_RXH |
| 2204 | |
| 2205 | rxh_done: |
Johannes Berg | 5890529 | 2008-01-31 19:48:25 +0100 | [diff] [blame] | 2206 | switch (res) { |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 2207 | case RX_DROP_MONITOR: |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 2208 | I802_DEBUG_INC(sdata->local->rx_handlers_drop); |
| 2209 | if (rx->sta) |
| 2210 | rx->sta->rx_dropped++; |
| 2211 | /* fall through */ |
| 2212 | case RX_CONTINUE: |
Johannes Berg | 5f0b7de | 2009-11-16 13:58:21 +0100 | [diff] [blame] | 2213 | ieee80211_rx_cooked_monitor(rx, rate); |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 2214 | break; |
| 2215 | case RX_DROP_UNUSABLE: |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 2216 | I802_DEBUG_INC(sdata->local->rx_handlers_drop); |
| 2217 | if (rx->sta) |
| 2218 | rx->sta->rx_dropped++; |
Johannes Berg | 5890529 | 2008-01-31 19:48:25 +0100 | [diff] [blame] | 2219 | dev_kfree_skb(rx->skb); |
| 2220 | break; |
Johannes Berg | 4946162 | 2008-06-30 15:10:45 +0200 | [diff] [blame] | 2221 | case RX_QUEUED: |
| 2222 | I802_DEBUG_INC(sdata->local->rx_handlers_queued); |
| 2223 | break; |
Johannes Berg | 5890529 | 2008-01-31 19:48:25 +0100 | [diff] [blame] | 2224 | } |
| 2225 | } |
| 2226 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2227 | /* main receive path */ |
| 2228 | |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2229 | static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 7ab17c4 | 2009-02-10 21:25:43 +0100 | [diff] [blame] | 2230 | struct ieee80211_rx_data *rx, |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2231 | struct ieee80211_hdr *hdr) |
| 2232 | { |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 2233 | struct sk_buff *skb = rx->skb; |
| 2234 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
| 2235 | u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type); |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2236 | int multicast = is_multicast_ether_addr(hdr->addr1); |
| 2237 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 2238 | switch (sdata->vif.type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2239 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2240 | if (!bssid && !sdata->u.mgd.use_4addr) |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2241 | return 0; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2242 | if (!multicast && |
| 2243 | compare_ether_addr(sdata->dev->dev_addr, hdr->addr1) != 0) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 2244 | if (!(sdata->dev->flags & IFF_PROMISC)) |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2245 | return 0; |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 2246 | rx->flags &= ~IEEE80211_RX_RA_MATCH; |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2247 | } |
| 2248 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2249 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2250 | if (!bssid) |
| 2251 | return 0; |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 2252 | if (ieee80211_is_beacon(hdr->frame_control)) { |
Bruno Randolf | 9d9bf77 | 2008-02-18 11:21:36 +0900 | [diff] [blame] | 2253 | return 1; |
Vladimir Koutny | 87291c0 | 2008-06-13 16:50:44 +0200 | [diff] [blame] | 2254 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2255 | else if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid)) { |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 2256 | if (!(rx->flags & IEEE80211_RX_IN_SCAN)) |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2257 | return 0; |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 2258 | rx->flags &= ~IEEE80211_RX_RA_MATCH; |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2259 | } else if (!multicast && |
| 2260 | compare_ether_addr(sdata->dev->dev_addr, |
| 2261 | hdr->addr1) != 0) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 2262 | if (!(sdata->dev->flags & IFF_PROMISC)) |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2263 | return 0; |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 2264 | rx->flags &= ~IEEE80211_RX_RA_MATCH; |
Jouni Malinen | 0fb8ca4 | 2008-12-12 14:38:33 +0200 | [diff] [blame] | 2265 | } else if (!rx->sta) { |
| 2266 | int rate_idx; |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 2267 | if (status->flag & RX_FLAG_HT) |
Jouni Malinen | 0fb8ca4 | 2008-12-12 14:38:33 +0200 | [diff] [blame] | 2268 | rate_idx = 0; /* TODO: HT rates */ |
| 2269 | else |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 2270 | rate_idx = status->rate_idx; |
Rami Rosen | ab1f5c0 | 2008-12-11 14:00:25 +0200 | [diff] [blame] | 2271 | rx->sta = ieee80211_ibss_add_sta(sdata, bssid, hdr->addr2, |
Jouni Malinen | 0fb8ca4 | 2008-12-12 14:38:33 +0200 | [diff] [blame] | 2272 | BIT(rate_idx)); |
| 2273 | } |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2274 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2275 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 6032f93 | 2008-02-23 15:17:07 +0100 | [diff] [blame] | 2276 | if (!multicast && |
| 2277 | compare_ether_addr(sdata->dev->dev_addr, |
| 2278 | hdr->addr1) != 0) { |
| 2279 | if (!(sdata->dev->flags & IFF_PROMISC)) |
| 2280 | return 0; |
| 2281 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 2282 | rx->flags &= ~IEEE80211_RX_RA_MATCH; |
Johannes Berg | 6032f93 | 2008-02-23 15:17:07 +0100 | [diff] [blame] | 2283 | } |
| 2284 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2285 | case NL80211_IFTYPE_AP_VLAN: |
| 2286 | case NL80211_IFTYPE_AP: |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2287 | if (!bssid) { |
| 2288 | if (compare_ether_addr(sdata->dev->dev_addr, |
| 2289 | hdr->addr1)) |
| 2290 | return 0; |
| 2291 | } else if (!ieee80211_bssid_match(bssid, |
| 2292 | sdata->dev->dev_addr)) { |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 2293 | if (!(rx->flags & IEEE80211_RX_IN_SCAN)) |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2294 | return 0; |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 2295 | rx->flags &= ~IEEE80211_RX_RA_MATCH; |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2296 | } |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2297 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2298 | case NL80211_IFTYPE_WDS: |
Harvey Harrison | a7767f9 | 2008-07-02 16:30:51 -0700 | [diff] [blame] | 2299 | if (bssid || !ieee80211_is_data(hdr->frame_control)) |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2300 | return 0; |
| 2301 | if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2)) |
| 2302 | return 0; |
| 2303 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2304 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2305 | case NL80211_IFTYPE_UNSPECIFIED: |
| 2306 | case __NL80211_IFTYPE_AFTER_LAST: |
Johannes Berg | fb1c1cd | 2007-09-26 15:19:43 +0200 | [diff] [blame] | 2307 | /* should never get here */ |
| 2308 | WARN_ON(1); |
| 2309 | break; |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2310 | } |
| 2311 | |
| 2312 | return 1; |
| 2313 | } |
| 2314 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2315 | /* |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 2316 | * This is the actual Rx frames handler. as it blongs to Rx path it must |
| 2317 | * be called with rcu_read_lock protection. |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2318 | */ |
Ron Rindjunsky | 71ebb4a | 2008-01-21 12:39:12 +0200 | [diff] [blame] | 2319 | static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, |
| 2320 | struct sk_buff *skb, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2321 | struct ieee80211_rate *rate) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2322 | { |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 2323 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2324 | struct ieee80211_local *local = hw_to_local(hw); |
| 2325 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2326 | struct ieee80211_hdr *hdr; |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 2327 | struct ieee80211_rx_data rx; |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 2328 | int prepares; |
Johannes Berg | 8e6f003 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2329 | struct ieee80211_sub_if_data *prev = NULL; |
| 2330 | struct sk_buff *skb_new; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2331 | |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 2332 | hdr = (struct ieee80211_hdr *)skb->data; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2333 | memset(&rx, 0, sizeof(rx)); |
| 2334 | rx.skb = skb; |
| 2335 | rx.local = local; |
Johannes Berg | 72abd81 | 2007-09-17 01:29:22 -0400 | [diff] [blame] | 2336 | |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 2337 | if (ieee80211_is_data(hdr->frame_control) || ieee80211_is_mgmt(hdr->frame_control)) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2338 | local->dot11ReceivedFragmentCount++; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2339 | |
Helmut Schaa | 142b9f5 | 2009-07-23 13:18:01 +0200 | [diff] [blame] | 2340 | if (unlikely(test_bit(SCAN_HW_SCANNING, &local->scanning) || |
| 2341 | test_bit(SCAN_OFF_CHANNEL, &local->scanning))) |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 2342 | rx.flags |= IEEE80211_RX_IN_SCAN; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2343 | |
Johannes Berg | 38f3714 | 2008-01-29 17:07:43 +0100 | [diff] [blame] | 2344 | ieee80211_parse_qos(&rx); |
Johannes Berg | d1c3a37 | 2009-01-07 00:26:10 +0100 | [diff] [blame] | 2345 | ieee80211_verify_alignment(&rx); |
Johannes Berg | 38f3714 | 2008-01-29 17:07:43 +0100 | [diff] [blame] | 2346 | |
Johannes Berg | af2ced6 | 2009-11-16 12:00:39 +0100 | [diff] [blame] | 2347 | rx.sta = sta_info_get(local, hdr->addr2); |
Johannes Berg | eb9fb5b | 2009-11-16 13:58:20 +0100 | [diff] [blame] | 2348 | if (rx.sta) |
Johannes Berg | af2ced6 | 2009-11-16 12:00:39 +0100 | [diff] [blame] | 2349 | rx.sdata = rx.sta->sdata; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2350 | |
Johannes Berg | fbc44bf | 2009-10-01 22:06:29 +0200 | [diff] [blame] | 2351 | if (rx.sdata && ieee80211_is_data(hdr->frame_control)) { |
| 2352 | rx.flags |= IEEE80211_RX_RA_MATCH; |
| 2353 | prepares = prepare_for_handlers(rx.sdata, &rx, hdr); |
Johannes Berg | af2ced6 | 2009-11-16 12:00:39 +0100 | [diff] [blame] | 2354 | if (prepares) { |
| 2355 | if (status->flag & RX_FLAG_MMIC_ERROR) { |
| 2356 | if (rx.flags & IEEE80211_RX_RA_MATCH) |
| 2357 | ieee80211_rx_michael_mic_report(hdr, &rx); |
| 2358 | } else |
| 2359 | prev = rx.sdata; |
| 2360 | } |
Johannes Berg | fbc44bf | 2009-10-01 22:06:29 +0200 | [diff] [blame] | 2361 | } else list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
Johannes Berg | 2a8a9a8 | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 2362 | if (!netif_running(sdata->dev)) |
| 2363 | continue; |
| 2364 | |
Johannes Berg | fbc44bf | 2009-10-01 22:06:29 +0200 | [diff] [blame] | 2365 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR || |
| 2366 | sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 2367 | continue; |
| 2368 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 2369 | rx.flags |= IEEE80211_RX_RA_MATCH; |
Johannes Berg | 7ab17c4 | 2009-02-10 21:25:43 +0100 | [diff] [blame] | 2370 | prepares = prepare_for_handlers(sdata, &rx, hdr); |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2371 | |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 2372 | if (!prepares) |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2373 | continue; |
Johannes Berg | 8e6f003 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2374 | |
Johannes Berg | af2ced6 | 2009-11-16 12:00:39 +0100 | [diff] [blame] | 2375 | if (status->flag & RX_FLAG_MMIC_ERROR) { |
| 2376 | rx.sdata = sdata; |
| 2377 | if (rx.flags & IEEE80211_RX_RA_MATCH) |
| 2378 | ieee80211_rx_michael_mic_report(hdr, &rx); |
| 2379 | continue; |
| 2380 | } |
| 2381 | |
Johannes Berg | 340e11f | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2382 | /* |
| 2383 | * frame is destined for this interface, but if it's not |
| 2384 | * also for the previous one we handle that after the |
| 2385 | * loop to avoid copying the SKB once too much |
| 2386 | */ |
| 2387 | |
| 2388 | if (!prev) { |
| 2389 | prev = sdata; |
| 2390 | continue; |
Johannes Berg | 8e6f003 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2391 | } |
Johannes Berg | 340e11f | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2392 | |
| 2393 | /* |
| 2394 | * frame was destined for the previous interface |
| 2395 | * so invoke RX handlers for it |
| 2396 | */ |
| 2397 | |
| 2398 | skb_new = skb_copy(skb, GFP_ATOMIC); |
| 2399 | if (!skb_new) { |
| 2400 | if (net_ratelimit()) |
| 2401 | printk(KERN_DEBUG "%s: failed to copy " |
Pavel Roskin | a4278e1 | 2008-05-12 09:02:24 -0400 | [diff] [blame] | 2402 | "multicast frame for %s\n", |
Johannes Berg | dd1cd4c | 2007-09-18 17:29:20 -0400 | [diff] [blame] | 2403 | wiphy_name(local->hw.wiphy), |
| 2404 | prev->dev->name); |
Johannes Berg | 340e11f | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2405 | continue; |
| 2406 | } |
Johannes Berg | 5f0b7de | 2009-11-16 13:58:21 +0100 | [diff] [blame] | 2407 | ieee80211_invoke_rx_handlers(prev, &rx, skb_new, rate); |
Johannes Berg | 8e6f003 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2408 | prev = sdata; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2409 | } |
Harvey Harrison | a4b7d7b | 2008-07-15 18:44:14 -0700 | [diff] [blame] | 2410 | if (prev) |
Johannes Berg | 5f0b7de | 2009-11-16 13:58:21 +0100 | [diff] [blame] | 2411 | ieee80211_invoke_rx_handlers(prev, &rx, skb, rate); |
Harvey Harrison | a4b7d7b | 2008-07-15 18:44:14 -0700 | [diff] [blame] | 2412 | else |
Johannes Berg | 8e6f003 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2413 | dev_kfree_skb(skb); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2414 | } |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 2415 | |
| 2416 | /* |
| 2417 | * This is the receive path handler. It is called by a low level driver when an |
| 2418 | * 802.11 MPDU is received from the hardware. |
| 2419 | */ |
John W. Linville | 103bf9f | 2009-08-20 16:34:15 -0400 | [diff] [blame] | 2420 | void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb) |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 2421 | { |
| 2422 | struct ieee80211_local *local = hw_to_local(hw); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2423 | struct ieee80211_rate *rate = NULL; |
| 2424 | struct ieee80211_supported_band *sband; |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 2425 | struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2426 | |
Johannes Berg | d20ef63 | 2009-10-11 15:10:40 +0200 | [diff] [blame] | 2427 | WARN_ON_ONCE(softirq_count() == 0); |
| 2428 | |
Johannes Berg | 77a980d | 2009-08-24 11:46:30 +0200 | [diff] [blame] | 2429 | if (WARN_ON(status->band < 0 || |
| 2430 | status->band >= IEEE80211_NUM_BANDS)) |
| 2431 | goto drop; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2432 | |
| 2433 | sband = local->hw.wiphy->bands[status->band]; |
Johannes Berg | 77a980d | 2009-08-24 11:46:30 +0200 | [diff] [blame] | 2434 | if (WARN_ON(!sband)) |
| 2435 | goto drop; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2436 | |
Johannes Berg | 89c3a8a | 2009-07-28 18:10:17 +0200 | [diff] [blame] | 2437 | /* |
| 2438 | * If we're suspending, it is possible although not too likely |
| 2439 | * that we'd be receiving frames after having already partially |
| 2440 | * quiesced the stack. We can't process such frames then since |
| 2441 | * that might, for example, cause stations to be added or other |
| 2442 | * driver callbacks be invoked. |
| 2443 | */ |
Johannes Berg | 77a980d | 2009-08-24 11:46:30 +0200 | [diff] [blame] | 2444 | if (unlikely(local->quiescing || local->suspended)) |
| 2445 | goto drop; |
Johannes Berg | 89c3a8a | 2009-07-28 18:10:17 +0200 | [diff] [blame] | 2446 | |
Johannes Berg | ea77f12 | 2009-08-21 14:44:45 +0200 | [diff] [blame] | 2447 | /* |
| 2448 | * The same happens when we're not even started, |
| 2449 | * but that's worth a warning. |
| 2450 | */ |
Johannes Berg | 77a980d | 2009-08-24 11:46:30 +0200 | [diff] [blame] | 2451 | if (WARN_ON(!local->started)) |
| 2452 | goto drop; |
Johannes Berg | ea77f12 | 2009-08-21 14:44:45 +0200 | [diff] [blame] | 2453 | |
Jouni Malinen | 0fb8ca4 | 2008-12-12 14:38:33 +0200 | [diff] [blame] | 2454 | if (status->flag & RX_FLAG_HT) { |
Luis R. Rodriguez | e5d6eb8 | 2009-11-09 16:03:22 -0500 | [diff] [blame] | 2455 | /* |
| 2456 | * rate_idx is MCS index, which can be [0-76] as documented on: |
| 2457 | * |
| 2458 | * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n |
| 2459 | * |
| 2460 | * Anything else would be some sort of driver or hardware error. |
| 2461 | * The driver should catch hardware errors. |
| 2462 | */ |
| 2463 | if (WARN((status->rate_idx < 0 || |
| 2464 | status->rate_idx > 76), |
| 2465 | "Rate marked as an HT rate but passed " |
| 2466 | "status->rate_idx is not " |
| 2467 | "an MCS index [0-76]: %d (0x%02x)\n", |
| 2468 | status->rate_idx, |
| 2469 | status->rate_idx)) |
Johannes Berg | 77a980d | 2009-08-24 11:46:30 +0200 | [diff] [blame] | 2470 | goto drop; |
Jouni Malinen | 0fb8ca4 | 2008-12-12 14:38:33 +0200 | [diff] [blame] | 2471 | } else { |
| 2472 | if (WARN_ON(status->rate_idx < 0 || |
| 2473 | status->rate_idx >= sband->n_bitrates)) |
Johannes Berg | 77a980d | 2009-08-24 11:46:30 +0200 | [diff] [blame] | 2474 | goto drop; |
Jouni Malinen | 0fb8ca4 | 2008-12-12 14:38:33 +0200 | [diff] [blame] | 2475 | rate = &sband->bitrates[status->rate_idx]; |
| 2476 | } |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 2477 | |
| 2478 | /* |
| 2479 | * key references and virtual interfaces are protected using RCU |
| 2480 | * and this requires that we are in a read-side RCU section during |
| 2481 | * receive processing |
| 2482 | */ |
| 2483 | rcu_read_lock(); |
| 2484 | |
| 2485 | /* |
| 2486 | * Frames with failed FCS/PLCP checksum are not returned, |
| 2487 | * all other frames are returned without radiotap header |
| 2488 | * if it was previously present. |
| 2489 | * Also, frames with less than 16 bytes are dropped. |
| 2490 | */ |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 2491 | skb = ieee80211_rx_monitor(local, skb, rate); |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 2492 | if (!skb) { |
| 2493 | rcu_read_unlock(); |
| 2494 | return; |
| 2495 | } |
| 2496 | |
Jouni Malinen | aec6795 | 2009-05-05 20:35:15 +0300 | [diff] [blame] | 2497 | /* |
| 2498 | * In theory, the block ack reordering should happen after duplicate |
| 2499 | * removal (ieee80211_rx_h_check(), which is an RX handler). As such, |
| 2500 | * the call to ieee80211_rx_reorder_ampdu() should really be moved to |
| 2501 | * happen as a new RX handler between ieee80211_rx_h_check and |
| 2502 | * ieee80211_rx_h_decrypt. This cleanup may eventually happen, but for |
| 2503 | * the time being, the call can be here since RX reorder buf processing |
| 2504 | * will implicitly skip duplicates. We could, in theory at least, |
| 2505 | * process frames that ieee80211_rx_h_passive_scan would drop (e.g., |
| 2506 | * frames from other than operational channel), but that should not |
| 2507 | * happen in normal networks. |
| 2508 | */ |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 2509 | if (!ieee80211_rx_reorder_ampdu(local, skb)) |
| 2510 | __ieee80211_rx_handle_packet(hw, skb, rate); |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 2511 | |
| 2512 | rcu_read_unlock(); |
Johannes Berg | 77a980d | 2009-08-24 11:46:30 +0200 | [diff] [blame] | 2513 | |
| 2514 | return; |
| 2515 | drop: |
| 2516 | kfree_skb(skb); |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 2517 | } |
John W. Linville | 103bf9f | 2009-08-20 16:34:15 -0400 | [diff] [blame] | 2518 | EXPORT_SYMBOL(ieee80211_rx); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2519 | |
| 2520 | /* This is a version of the rx handler that can be called from hard irq |
| 2521 | * context. Post the skb on the queue and schedule the tasklet */ |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 2522 | void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2523 | { |
| 2524 | struct ieee80211_local *local = hw_to_local(hw); |
| 2525 | |
| 2526 | BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb)); |
| 2527 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2528 | skb->pkt_type = IEEE80211_RX_MSG; |
| 2529 | skb_queue_tail(&local->skb_queue, skb); |
| 2530 | tasklet_schedule(&local->tasklet); |
| 2531 | } |
| 2532 | EXPORT_SYMBOL(ieee80211_rx_irqsafe); |