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