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