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 | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 22 | #include "led.h" |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 23 | #include "mesh.h" |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 24 | #include "wep.h" |
| 25 | #include "wpa.h" |
| 26 | #include "tkip.h" |
| 27 | #include "wme.h" |
| 28 | |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 29 | u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw, |
| 30 | struct tid_ampdu_rx *tid_agg_rx, |
| 31 | struct sk_buff *skb, u16 mpdu_seq_num, |
| 32 | int bar_req); |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 33 | /* |
| 34 | * monitor mode reception |
| 35 | * |
| 36 | * This function cleans up the SKB, i.e. it removes all the stuff |
| 37 | * only useful for monitoring. |
| 38 | */ |
| 39 | static struct sk_buff *remove_monitor_info(struct ieee80211_local *local, |
| 40 | struct sk_buff *skb, |
| 41 | int rtap_len) |
| 42 | { |
| 43 | skb_pull(skb, rtap_len); |
| 44 | |
| 45 | if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) { |
| 46 | if (likely(skb->len > FCS_LEN)) |
| 47 | skb_trim(skb, skb->len - FCS_LEN); |
| 48 | else { |
| 49 | /* driver bug */ |
| 50 | WARN_ON(1); |
| 51 | dev_kfree_skb(skb); |
| 52 | skb = NULL; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | return skb; |
| 57 | } |
| 58 | |
| 59 | static inline int should_drop_frame(struct ieee80211_rx_status *status, |
| 60 | struct sk_buff *skb, |
| 61 | int present_fcs_len, |
| 62 | int radiotap_len) |
| 63 | { |
| 64 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 65 | |
| 66 | if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC)) |
| 67 | return 1; |
| 68 | if (unlikely(skb->len < 16 + present_fcs_len + radiotap_len)) |
| 69 | return 1; |
Ron Rindjunsky | 98f0b0a | 2007-12-18 17:23:53 +0200 | [diff] [blame] | 70 | if (((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FTYPE)) == |
| 71 | cpu_to_le16(IEEE80211_FTYPE_CTL)) && |
| 72 | ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE)) != |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 73 | cpu_to_le16(IEEE80211_STYPE_PSPOLL)) && |
| 74 | ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE)) != |
| 75 | cpu_to_le16(IEEE80211_STYPE_BACK_REQ))) |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 76 | return 1; |
| 77 | return 0; |
| 78 | } |
| 79 | |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 80 | static int |
| 81 | ieee80211_rx_radiotap_len(struct ieee80211_local *local, |
| 82 | struct ieee80211_rx_status *status) |
| 83 | { |
| 84 | int len; |
| 85 | |
| 86 | /* always present fields */ |
| 87 | len = sizeof(struct ieee80211_radiotap_header) + 9; |
| 88 | |
| 89 | if (status->flag & RX_FLAG_TSFT) |
| 90 | len += 8; |
| 91 | if (local->hw.flags & IEEE80211_HW_SIGNAL_DB || |
| 92 | local->hw.flags & IEEE80211_HW_SIGNAL_DBM) |
| 93 | len += 1; |
| 94 | if (local->hw.flags & IEEE80211_HW_NOISE_DBM) |
| 95 | len += 1; |
| 96 | |
| 97 | if (len & 1) /* padding for RX_FLAGS if necessary */ |
| 98 | len++; |
| 99 | |
| 100 | /* make sure radiotap starts at a naturally aligned address */ |
| 101 | if (len % 8) |
| 102 | len = roundup(len, 8); |
| 103 | |
| 104 | return len; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * ieee80211_add_rx_radiotap_header - add radiotap header |
| 109 | * |
| 110 | * add a radiotap header containing all the fields which the hardware provided. |
| 111 | */ |
| 112 | static void |
| 113 | ieee80211_add_rx_radiotap_header(struct ieee80211_local *local, |
| 114 | struct sk_buff *skb, |
| 115 | struct ieee80211_rx_status *status, |
| 116 | struct ieee80211_rate *rate, |
| 117 | int rtap_len) |
| 118 | { |
| 119 | struct ieee80211_radiotap_header *rthdr; |
| 120 | unsigned char *pos; |
| 121 | |
| 122 | rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len); |
| 123 | memset(rthdr, 0, rtap_len); |
| 124 | |
| 125 | /* radiotap header, set always present flags */ |
| 126 | rthdr->it_present = |
| 127 | cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) | |
| 128 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 129 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 130 | (1 << IEEE80211_RADIOTAP_ANTENNA) | |
| 131 | (1 << IEEE80211_RADIOTAP_RX_FLAGS)); |
| 132 | rthdr->it_len = cpu_to_le16(rtap_len); |
| 133 | |
| 134 | pos = (unsigned char *)(rthdr+1); |
| 135 | |
| 136 | /* the order of the following fields is important */ |
| 137 | |
| 138 | /* IEEE80211_RADIOTAP_TSFT */ |
| 139 | if (status->flag & RX_FLAG_TSFT) { |
| 140 | *(__le64 *)pos = cpu_to_le64(status->mactime); |
| 141 | rthdr->it_present |= |
| 142 | cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT); |
| 143 | pos += 8; |
| 144 | } |
| 145 | |
| 146 | /* IEEE80211_RADIOTAP_FLAGS */ |
| 147 | if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) |
| 148 | *pos |= IEEE80211_RADIOTAP_F_FCS; |
| 149 | pos++; |
| 150 | |
| 151 | /* IEEE80211_RADIOTAP_RATE */ |
| 152 | *pos = rate->bitrate / 5; |
| 153 | pos++; |
| 154 | |
| 155 | /* IEEE80211_RADIOTAP_CHANNEL */ |
| 156 | *(__le16 *)pos = cpu_to_le16(status->freq); |
| 157 | pos += 2; |
| 158 | if (status->band == IEEE80211_BAND_5GHZ) |
| 159 | *(__le16 *)pos = cpu_to_le16(IEEE80211_CHAN_OFDM | |
| 160 | IEEE80211_CHAN_5GHZ); |
| 161 | else |
| 162 | *(__le16 *)pos = cpu_to_le16(IEEE80211_CHAN_DYN | |
| 163 | IEEE80211_CHAN_2GHZ); |
| 164 | pos += 2; |
| 165 | |
| 166 | /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */ |
| 167 | if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) { |
| 168 | *pos = status->signal; |
| 169 | rthdr->it_present |= |
| 170 | cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL); |
| 171 | pos++; |
| 172 | } |
| 173 | |
| 174 | /* IEEE80211_RADIOTAP_DBM_ANTNOISE */ |
| 175 | if (local->hw.flags & IEEE80211_HW_NOISE_DBM) { |
| 176 | *pos = status->noise; |
| 177 | rthdr->it_present |= |
| 178 | cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTNOISE); |
| 179 | pos++; |
| 180 | } |
| 181 | |
| 182 | /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */ |
| 183 | |
| 184 | /* IEEE80211_RADIOTAP_ANTENNA */ |
| 185 | *pos = status->antenna; |
| 186 | pos++; |
| 187 | |
| 188 | /* IEEE80211_RADIOTAP_DB_ANTSIGNAL */ |
| 189 | if (local->hw.flags & IEEE80211_HW_SIGNAL_DB) { |
| 190 | *pos = status->signal; |
| 191 | rthdr->it_present |= |
| 192 | cpu_to_le32(1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL); |
| 193 | pos++; |
| 194 | } |
| 195 | |
| 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 */ |
| 200 | if ((pos - (unsigned char *)rthdr) & 1) |
| 201 | pos++; |
| 202 | /* FIXME: when radiotap gets a 'bad PLCP' flag use it here */ |
| 203 | if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC)) |
| 204 | *(__le16 *)pos |= cpu_to_le16(IEEE80211_RADIOTAP_F_RX_BADFCS); |
| 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_rx_status *status, |
| 216 | struct ieee80211_rate *rate) |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 217 | { |
| 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; |
| 223 | int rtap_len = 0; |
| 224 | |
| 225 | /* |
| 226 | * First, we may need to make a copy of the skb because |
| 227 | * (1) we need to modify it for radiotap (if not present), and |
| 228 | * (2) the other RX handlers will modify the skb we got. |
| 229 | * |
| 230 | * We don't need to, of course, if we aren't going to return |
| 231 | * the SKB because it has a bad FCS/PLCP checksum. |
| 232 | */ |
| 233 | if (status->flag & RX_FLAG_RADIOTAP) |
| 234 | rtap_len = ieee80211_get_radiotap_len(origskb->data); |
| 235 | else |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 236 | /* room for the radiotap header based on driver features */ |
| 237 | needed_headroom = ieee80211_rx_radiotap_len(local, status); |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 238 | |
| 239 | if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) |
| 240 | present_fcs_len = FCS_LEN; |
| 241 | |
| 242 | if (!local->monitors) { |
| 243 | if (should_drop_frame(status, origskb, present_fcs_len, |
| 244 | rtap_len)) { |
| 245 | dev_kfree_skb(origskb); |
| 246 | return NULL; |
| 247 | } |
| 248 | |
| 249 | return remove_monitor_info(local, origskb, rtap_len); |
| 250 | } |
| 251 | |
| 252 | if (should_drop_frame(status, origskb, present_fcs_len, rtap_len)) { |
| 253 | /* only need to expand headroom if necessary */ |
| 254 | skb = origskb; |
| 255 | origskb = NULL; |
| 256 | |
| 257 | /* |
| 258 | * This shouldn't trigger often because most devices have an |
| 259 | * RX header they pull before we get here, and that should |
| 260 | * be big enough for our radiotap information. We should |
| 261 | * probably export the length to drivers so that we can have |
| 262 | * them allocate enough headroom to start with. |
| 263 | */ |
| 264 | if (skb_headroom(skb) < needed_headroom && |
Johannes Berg | c49e5ea | 2007-12-11 21:33:42 +0100 | [diff] [blame] | 265 | pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) { |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 266 | dev_kfree_skb(skb); |
| 267 | return NULL; |
| 268 | } |
| 269 | } else { |
| 270 | /* |
| 271 | * Need to make a copy and possibly remove radiotap header |
| 272 | * and FCS from the original. |
| 273 | */ |
| 274 | skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC); |
| 275 | |
| 276 | origskb = remove_monitor_info(local, origskb, rtap_len); |
| 277 | |
| 278 | if (!skb) |
| 279 | return origskb; |
| 280 | } |
| 281 | |
| 282 | /* if necessary, prepend radiotap information */ |
Bruno Randolf | 601ae7f | 2008-05-08 19:22:43 +0200 | [diff] [blame] | 283 | if (!(status->flag & RX_FLAG_RADIOTAP)) |
| 284 | ieee80211_add_rx_radiotap_header(local, skb, status, rate, |
| 285 | needed_headroom); |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 286 | |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 287 | skb_reset_mac_header(skb); |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 288 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 289 | skb->pkt_type = PACKET_OTHERHOST; |
| 290 | skb->protocol = htons(ETH_P_802_2); |
| 291 | |
| 292 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
| 293 | if (!netif_running(sdata->dev)) |
| 294 | continue; |
| 295 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 296 | if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR) |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 297 | continue; |
| 298 | |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 299 | if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) |
| 300 | continue; |
| 301 | |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 302 | if (prev_dev) { |
| 303 | skb2 = skb_clone(skb, GFP_ATOMIC); |
| 304 | if (skb2) { |
| 305 | skb2->dev = prev_dev; |
| 306 | netif_rx(skb2); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | prev_dev = sdata->dev; |
| 311 | sdata->dev->stats.rx_packets++; |
| 312 | sdata->dev->stats.rx_bytes += skb->len; |
| 313 | } |
| 314 | |
| 315 | if (prev_dev) { |
| 316 | skb->dev = prev_dev; |
| 317 | netif_rx(skb); |
| 318 | } else |
| 319 | dev_kfree_skb(skb); |
| 320 | |
| 321 | return origskb; |
| 322 | } |
| 323 | |
| 324 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 325 | static void ieee80211_parse_qos(struct ieee80211_rx_data *rx) |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 326 | { |
| 327 | u8 *data = rx->skb->data; |
| 328 | int tid; |
| 329 | |
| 330 | /* does the frame have a qos control field? */ |
| 331 | if (WLAN_FC_IS_QOS_DATA(rx->fc)) { |
| 332 | u8 *qc = data + ieee80211_get_hdrlen(rx->fc) - QOS_CONTROL_LEN; |
| 333 | /* frame has qos control */ |
| 334 | tid = qc[0] & QOS_CONTROL_TID_MASK; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 335 | if (qc[0] & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT) |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 336 | rx->flags |= IEEE80211_RX_AMSDU; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 337 | else |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 338 | rx->flags &= ~IEEE80211_RX_AMSDU; |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 339 | } else { |
| 340 | if (unlikely((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)) { |
| 341 | /* Separate TID for management frames */ |
| 342 | tid = NUM_RX_DATA_QUEUES - 1; |
| 343 | } else { |
| 344 | /* no qos control present */ |
| 345 | tid = 0; /* 802.1d - Best Effort */ |
| 346 | } |
| 347 | } |
Johannes Berg | 52865df | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 348 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 349 | rx->queue = tid; |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 350 | /* Set skb->priority to 1d tag if highest order bit of TID is not set. |
| 351 | * For now, set skb->priority to 0 for other cases. */ |
| 352 | rx->skb->priority = (tid > 7) ? 0 : tid; |
Johannes Berg | 38f3714 | 2008-01-29 17:07:43 +0100 | [diff] [blame] | 353 | } |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 354 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 355 | static void ieee80211_verify_ip_alignment(struct ieee80211_rx_data *rx) |
Johannes Berg | 38f3714 | 2008-01-29 17:07:43 +0100 | [diff] [blame] | 356 | { |
| 357 | #ifdef CONFIG_MAC80211_DEBUG_PACKET_ALIGNMENT |
| 358 | int hdrlen; |
| 359 | |
| 360 | if (!WLAN_FC_DATA_PRESENT(rx->fc)) |
| 361 | return; |
| 362 | |
| 363 | /* |
| 364 | * Drivers are required to align the payload data in a way that |
| 365 | * guarantees that the contained IP header is aligned to a four- |
| 366 | * byte boundary. In the case of regular frames, this simply means |
| 367 | * aligning the payload to a four-byte boundary (because either |
| 368 | * the IP header is directly contained, or IV/RFC1042 headers that |
| 369 | * have a length divisible by four are in front of it. |
| 370 | * |
| 371 | * With A-MSDU frames, however, the payload data address must |
| 372 | * yield two modulo four because there are 14-byte 802.3 headers |
| 373 | * within the A-MSDU frames that push the IP header further back |
| 374 | * to a multiple of four again. Thankfully, the specs were sane |
| 375 | * enough this time around to require padding each A-MSDU subframe |
| 376 | * to a length that is a multiple of four. |
| 377 | * |
| 378 | * Padding like atheros hardware adds which is inbetween the 802.11 |
| 379 | * header and the payload is not supported, the driver is required |
| 380 | * to move the 802.11 header further back in that case. |
| 381 | */ |
| 382 | hdrlen = ieee80211_get_hdrlen(rx->fc); |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 383 | if (rx->flags & IEEE80211_RX_AMSDU) |
Johannes Berg | 38f3714 | 2008-01-29 17:07:43 +0100 | [diff] [blame] | 384 | hdrlen += ETH_HLEN; |
| 385 | WARN_ON_ONCE(((unsigned long)(rx->skb->data + hdrlen)) & 3); |
| 386 | #endif |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 387 | } |
| 388 | |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 389 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 390 | /* rx handlers */ |
| 391 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 392 | static ieee80211_rx_result |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 393 | ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 394 | { |
| 395 | struct ieee80211_local *local = rx->local; |
| 396 | struct sk_buff *skb = rx->skb; |
| 397 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 398 | if (unlikely(local->sta_hw_scanning)) |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 399 | return ieee80211_sta_rx_scan(rx->dev, skb, rx->status); |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 400 | |
| 401 | if (unlikely(local->sta_sw_scanning)) { |
| 402 | /* drop all the other packets during a software scan anyway */ |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 403 | if (ieee80211_sta_rx_scan(rx->dev, skb, rx->status) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 404 | != RX_QUEUED) |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 405 | dev_kfree_skb(skb); |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 406 | return RX_QUEUED; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 407 | } |
| 408 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 409 | if (unlikely(rx->flags & IEEE80211_RX_IN_SCAN)) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 410 | /* scanning finished during invoking of handlers */ |
| 411 | I802_DEBUG_INC(local->rx_handlers_drop_passive_scan); |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 412 | return RX_DROP_UNUSABLE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 413 | } |
| 414 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 415 | return RX_CONTINUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 416 | } |
| 417 | |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 418 | static ieee80211_rx_result |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 419 | ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx) |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 420 | { |
| 421 | int hdrlen = ieee80211_get_hdrlen(rx->fc); |
| 422 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; |
Johannes Berg | d6d1a5a | 2008-02-25 16:24:38 +0100 | [diff] [blame] | 423 | |
| 424 | #define msh_h_get(h, l) ((struct ieee80211s_hdr *) ((u8 *)h + l)) |
| 425 | |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 426 | if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) { |
| 427 | if (!((rx->fc & IEEE80211_FCTL_FROMDS) && |
| 428 | (rx->fc & IEEE80211_FCTL_TODS))) |
| 429 | return RX_DROP_MONITOR; |
| 430 | if (memcmp(hdr->addr4, rx->dev->dev_addr, ETH_ALEN) == 0) |
| 431 | return RX_DROP_MONITOR; |
| 432 | } |
| 433 | |
| 434 | /* If there is not an established peer link and this is not a peer link |
| 435 | * establisment frame, beacon or probe, drop the frame. |
| 436 | */ |
| 437 | |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 438 | if (!rx->sta || sta_plink_state(rx->sta) != PLINK_ESTAB) { |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 439 | struct ieee80211_mgmt *mgmt; |
Johannes Berg | d6d1a5a | 2008-02-25 16:24:38 +0100 | [diff] [blame] | 440 | |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 441 | if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT) |
| 442 | return RX_DROP_MONITOR; |
| 443 | |
| 444 | switch (rx->fc & IEEE80211_FCTL_STYPE) { |
| 445 | case IEEE80211_STYPE_ACTION: |
| 446 | mgmt = (struct ieee80211_mgmt *)hdr; |
| 447 | if (mgmt->u.action.category != PLINK_CATEGORY) |
| 448 | return RX_DROP_MONITOR; |
| 449 | /* fall through on else */ |
| 450 | case IEEE80211_STYPE_PROBE_REQ: |
| 451 | case IEEE80211_STYPE_PROBE_RESP: |
| 452 | case IEEE80211_STYPE_BEACON: |
| 453 | return RX_CONTINUE; |
| 454 | break; |
| 455 | default: |
| 456 | return RX_DROP_MONITOR; |
| 457 | } |
| 458 | |
| 459 | } else if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA && |
Luis Carlos Cobo | 966a542 | 2008-03-31 15:33:39 -0700 | [diff] [blame] | 460 | is_multicast_ether_addr(hdr->addr1) && |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 461 | mesh_rmc_check(hdr->addr4, msh_h_get(hdr, hdrlen), rx->dev)) |
| 462 | return RX_DROP_MONITOR; |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 463 | #undef msh_h_get |
Johannes Berg | d6d1a5a | 2008-02-25 16:24:38 +0100 | [diff] [blame] | 464 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 465 | return RX_CONTINUE; |
| 466 | } |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 467 | |
| 468 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 469 | static ieee80211_rx_result |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 470 | ieee80211_rx_h_check(struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 471 | { |
| 472 | struct ieee80211_hdr *hdr; |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 473 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 474 | hdr = (struct ieee80211_hdr *) rx->skb->data; |
| 475 | |
| 476 | /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */ |
| 477 | if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) { |
| 478 | if (unlikely(rx->fc & IEEE80211_FCTL_RETRY && |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 479 | rx->sta->last_seq_ctrl[rx->queue] == |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 480 | hdr->seq_ctrl)) { |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 481 | if (rx->flags & IEEE80211_RX_RA_MATCH) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 482 | rx->local->dot11FrameDuplicateCount++; |
| 483 | rx->sta->num_duplicates++; |
| 484 | } |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 485 | return RX_DROP_MONITOR; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 486 | } else |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 487 | rx->sta->last_seq_ctrl[rx->queue] = hdr->seq_ctrl; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 488 | } |
| 489 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 490 | if (unlikely(rx->skb->len < 16)) { |
| 491 | I802_DEBUG_INC(rx->local->rx_handlers_drop_short); |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 492 | return RX_DROP_MONITOR; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 493 | } |
| 494 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 495 | /* Drop disallowed frame classes based on STA auth/assoc state; |
| 496 | * IEEE 802.11, Chap 5.5. |
| 497 | * |
| 498 | * 80211.o does filtering only based on association state, i.e., it |
| 499 | * drops Class 3 frames from not associated stations. hostapd sends |
| 500 | * deauth/disassoc frames when needed. In addition, hostapd is |
| 501 | * responsible for filtering on both auth and assoc states. |
| 502 | */ |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 503 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 504 | if (ieee80211_vif_is_mesh(&rx->sdata->vif)) |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 505 | return ieee80211_rx_mesh_check(rx); |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 506 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 507 | if (unlikely(((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA || |
| 508 | ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL && |
| 509 | (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)) && |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 510 | rx->sdata->vif.type != IEEE80211_IF_TYPE_IBSS && |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 511 | (!rx->sta || !test_sta_flags(rx->sta, WLAN_STA_ASSOC)))) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 512 | if ((!(rx->fc & IEEE80211_FCTL_FROMDS) && |
| 513 | !(rx->fc & IEEE80211_FCTL_TODS) && |
| 514 | (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 515 | || !(rx->flags & IEEE80211_RX_RA_MATCH)) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 516 | /* Drop IBSS frames and frames for other hosts |
| 517 | * silently. */ |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 518 | return RX_DROP_MONITOR; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 519 | } |
| 520 | |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 521 | return RX_DROP_MONITOR; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 522 | } |
| 523 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 524 | return RX_CONTINUE; |
Johannes Berg | 570bd53 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 528 | static ieee80211_rx_result |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 529 | ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx) |
Johannes Berg | 570bd53 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 530 | { |
| 531 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 532 | int keyidx; |
| 533 | int hdrlen; |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 534 | ieee80211_rx_result result = RX_DROP_UNUSABLE; |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 535 | struct ieee80211_key *stakey = NULL; |
Johannes Berg | 570bd53 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 536 | |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 537 | /* |
| 538 | * Key selection 101 |
| 539 | * |
| 540 | * There are three types of keys: |
| 541 | * - GTK (group keys) |
| 542 | * - PTK (pairwise keys) |
| 543 | * - STK (station-to-station pairwise keys) |
| 544 | * |
| 545 | * When selecting a key, we have to distinguish between multicast |
| 546 | * (including broadcast) and unicast frames, the latter can only |
| 547 | * use PTKs and STKs while the former always use GTKs. Unless, of |
| 548 | * course, actual WEP keys ("pre-RSNA") are used, then unicast |
| 549 | * frames can also use key indizes like GTKs. Hence, if we don't |
| 550 | * have a PTK/STK we check the key index for a WEP key. |
| 551 | * |
Johannes Berg | 8dc06a1 | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 552 | * Note that in a regular BSS, multicast frames are sent by the |
| 553 | * AP only, associated stations unicast the frame to the AP first |
| 554 | * which then multicasts it on their behalf. |
| 555 | * |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 556 | * There is also a slight problem in IBSS mode: GTKs are negotiated |
| 557 | * with each station, that is something we don't currently handle. |
Johannes Berg | 8dc06a1 | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 558 | * The spec seems to expect that one negotiates the same key with |
| 559 | * every station but there's no such requirement; VLANs could be |
| 560 | * possible. |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 561 | */ |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 562 | |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 563 | if (!(rx->fc & IEEE80211_FCTL_PROTECTED)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 564 | return RX_CONTINUE; |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 565 | |
| 566 | /* |
Johannes Berg | 1990af8 | 2007-09-26 17:53:15 +0200 | [diff] [blame] | 567 | * 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] | 568 | * addressed to us nor a multicast frame. |
| 569 | */ |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 570 | if (!(rx->flags & IEEE80211_RX_RA_MATCH)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 571 | return RX_CONTINUE; |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 572 | |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 573 | if (rx->sta) |
| 574 | stakey = rcu_dereference(rx->sta->key); |
| 575 | |
| 576 | if (!is_multicast_ether_addr(hdr->addr1) && stakey) { |
| 577 | rx->key = stakey; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 578 | } else { |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 579 | /* |
| 580 | * The device doesn't give us the IV so we won't be |
| 581 | * able to look up the key. That's ok though, we |
| 582 | * don't need to decrypt the frame, we just won't |
| 583 | * be able to keep statistics accurate. |
| 584 | * Except for key threshold notifications, should |
| 585 | * we somehow allow the driver to tell us which key |
| 586 | * the hardware used if this flag is set? |
| 587 | */ |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 588 | if ((rx->status->flag & RX_FLAG_DECRYPTED) && |
| 589 | (rx->status->flag & RX_FLAG_IV_STRIPPED)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 590 | return RX_CONTINUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 591 | |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 592 | hdrlen = ieee80211_get_hdrlen(rx->fc); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 593 | |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 594 | if (rx->skb->len < 8 + hdrlen) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 595 | return RX_DROP_UNUSABLE; /* TODO: count this? */ |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 596 | |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 597 | /* |
| 598 | * no need to call ieee80211_wep_get_keyidx, |
| 599 | * it verifies a bunch of things we've done already |
| 600 | */ |
| 601 | keyidx = rx->skb->data[hdrlen + 3] >> 6; |
| 602 | |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 603 | rx->key = rcu_dereference(rx->sdata->keys[keyidx]); |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 604 | |
| 605 | /* |
| 606 | * RSNA-protected unicast frames should always be sent with |
| 607 | * pairwise or station-to-station keys, but for WEP we allow |
| 608 | * using a key index as well. |
| 609 | */ |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 610 | if (rx->key && rx->key->conf.alg != ALG_WEP && |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 611 | !is_multicast_ether_addr(hdr->addr1)) |
| 612 | rx->key = NULL; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 613 | } |
| 614 | |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 615 | if (rx->key) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 616 | rx->key->tx_rx_count++; |
Johannes Berg | 011bfcc | 2007-09-17 01:29:25 -0400 | [diff] [blame] | 617 | /* TODO: add threshold stuff again */ |
Johannes Berg | 1990af8 | 2007-09-26 17:53:15 +0200 | [diff] [blame] | 618 | } else { |
John W. Linville | 7f3ad89 | 2007-11-06 17:12:31 -0500 | [diff] [blame] | 619 | #ifdef CONFIG_MAC80211_DEBUG |
Johannes Berg | 70f0876 | 2007-09-26 17:53:14 +0200 | [diff] [blame] | 620 | if (net_ratelimit()) |
| 621 | printk(KERN_DEBUG "%s: RX protected frame," |
| 622 | " but have no key\n", rx->dev->name); |
John W. Linville | 7f3ad89 | 2007-11-06 17:12:31 -0500 | [diff] [blame] | 623 | #endif /* CONFIG_MAC80211_DEBUG */ |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 624 | return RX_DROP_MONITOR; |
Johannes Berg | 70f0876 | 2007-09-26 17:53:14 +0200 | [diff] [blame] | 625 | } |
| 626 | |
Johannes Berg | 1990af8 | 2007-09-26 17:53:15 +0200 | [diff] [blame] | 627 | /* Check for weak IVs if possible */ |
| 628 | if (rx->sta && rx->key->conf.alg == ALG_WEP && |
| 629 | ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) && |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 630 | (!(rx->status->flag & RX_FLAG_IV_STRIPPED) || |
| 631 | !(rx->status->flag & RX_FLAG_DECRYPTED)) && |
Johannes Berg | 1990af8 | 2007-09-26 17:53:15 +0200 | [diff] [blame] | 632 | ieee80211_wep_is_weak_iv(rx->skb, rx->key)) |
| 633 | rx->sta->wep_weak_iv_count++; |
| 634 | |
Johannes Berg | 70f0876 | 2007-09-26 17:53:14 +0200 | [diff] [blame] | 635 | switch (rx->key->conf.alg) { |
| 636 | case ALG_WEP: |
Mattias Nissler | e2f036d | 2007-10-07 16:35:31 +0200 | [diff] [blame] | 637 | result = ieee80211_crypto_wep_decrypt(rx); |
| 638 | break; |
Johannes Berg | 70f0876 | 2007-09-26 17:53:14 +0200 | [diff] [blame] | 639 | case ALG_TKIP: |
Mattias Nissler | e2f036d | 2007-10-07 16:35:31 +0200 | [diff] [blame] | 640 | result = ieee80211_crypto_tkip_decrypt(rx); |
| 641 | break; |
Johannes Berg | 70f0876 | 2007-09-26 17:53:14 +0200 | [diff] [blame] | 642 | case ALG_CCMP: |
Mattias Nissler | e2f036d | 2007-10-07 16:35:31 +0200 | [diff] [blame] | 643 | result = ieee80211_crypto_ccmp_decrypt(rx); |
| 644 | break; |
Johannes Berg | 70f0876 | 2007-09-26 17:53:14 +0200 | [diff] [blame] | 645 | } |
| 646 | |
Mattias Nissler | e2f036d | 2007-10-07 16:35:31 +0200 | [diff] [blame] | 647 | /* either the frame has been decrypted or will be dropped */ |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 648 | rx->status->flag |= RX_FLAG_DECRYPTED; |
Mattias Nissler | e2f036d | 2007-10-07 16:35:31 +0200 | [diff] [blame] | 649 | |
| 650 | return result; |
Johannes Berg | 70f0876 | 2007-09-26 17:53:14 +0200 | [diff] [blame] | 651 | } |
| 652 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 653 | static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta) |
| 654 | { |
| 655 | struct ieee80211_sub_if_data *sdata; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 656 | DECLARE_MAC_BUF(mac); |
| 657 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 658 | sdata = sta->sdata; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 659 | |
| 660 | if (sdata->bss) |
| 661 | atomic_inc(&sdata->bss->num_sta_ps); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 662 | set_and_clear_sta_flags(sta, WLAN_STA_PS, WLAN_STA_PSPOLL); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 663 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 664 | printk(KERN_DEBUG "%s: STA %s aid %d enters power save mode\n", |
| 665 | dev->name, print_mac(mac, sta->addr), sta->aid); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 666 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
| 667 | } |
| 668 | |
| 669 | static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta) |
| 670 | { |
| 671 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 672 | struct sk_buff *skb; |
| 673 | int sent = 0; |
| 674 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 675 | struct ieee80211_tx_info *info; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 676 | DECLARE_MAC_BUF(mac); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 677 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 678 | sdata = sta->sdata; |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 679 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 680 | if (sdata->bss) |
| 681 | atomic_dec(&sdata->bss->num_sta_ps); |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 682 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 683 | clear_sta_flags(sta, WLAN_STA_PS | WLAN_STA_PSPOLL); |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 684 | |
| 685 | if (!skb_queue_empty(&sta->ps_tx_buf)) |
| 686 | sta_info_clear_tim_bit(sta); |
| 687 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 688 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 689 | printk(KERN_DEBUG "%s: STA %s aid %d exits power save mode\n", |
| 690 | dev->name, print_mac(mac, sta->addr), sta->aid); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 691 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 692 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 693 | /* Send all buffered frames to the station */ |
| 694 | while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 695 | info = IEEE80211_SKB_CB(skb); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 696 | sent++; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 697 | info->flags |= IEEE80211_TX_CTL_REQUEUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 698 | dev_queue_xmit(skb); |
| 699 | } |
| 700 | while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 701 | info = IEEE80211_SKB_CB(skb); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 702 | local->total_ps_buffered--; |
| 703 | sent++; |
| 704 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 705 | printk(KERN_DEBUG "%s: STA %s aid %d send PS frame " |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 706 | "since STA not sleeping anymore\n", dev->name, |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 707 | print_mac(mac, sta->addr), sta->aid); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 708 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 709 | info->flags |= IEEE80211_TX_CTL_REQUEUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 710 | dev_queue_xmit(skb); |
| 711 | } |
| 712 | |
| 713 | return sent; |
| 714 | } |
| 715 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 716 | static ieee80211_rx_result |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 717 | ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 718 | { |
| 719 | struct sta_info *sta = rx->sta; |
| 720 | struct net_device *dev = rx->dev; |
| 721 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; |
| 722 | |
| 723 | if (!sta) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 724 | return RX_CONTINUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 725 | |
| 726 | /* Update last_rx only for IBSS packets which are for the current |
| 727 | * BSSID to avoid keeping the current IBSS network alive in cases where |
| 728 | * other STAs are using different BSSID. */ |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 729 | if (rx->sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 730 | u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len, |
| 731 | IEEE80211_IF_TYPE_IBSS); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 732 | if (compare_ether_addr(bssid, rx->sdata->u.sta.bssid) == 0) |
| 733 | sta->last_rx = jiffies; |
| 734 | } else |
| 735 | if (!is_multicast_ether_addr(hdr->addr1) || |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 736 | rx->sdata->vif.type == IEEE80211_IF_TYPE_STA) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 737 | /* Update last_rx only for unicast frames in order to prevent |
| 738 | * the Probe Request frames (the only broadcast frames from a |
| 739 | * STA in infrastructure mode) from keeping a connection alive. |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 740 | * Mesh beacons will update last_rx when if they are found to |
| 741 | * match the current local configuration when processed. |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 742 | */ |
| 743 | sta->last_rx = jiffies; |
| 744 | } |
| 745 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 746 | if (!(rx->flags & IEEE80211_RX_RA_MATCH)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 747 | return RX_CONTINUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 748 | |
| 749 | sta->rx_fragments++; |
| 750 | sta->rx_bytes += rx->skb->len; |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 751 | sta->last_signal = rx->status->signal; |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 752 | sta->last_qual = rx->status->qual; |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 753 | sta->last_noise = rx->status->noise; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 754 | |
| 755 | if (!(rx->fc & IEEE80211_FCTL_MOREFRAGS)) { |
| 756 | /* Change STA power saving mode only in the end of a frame |
| 757 | * exchange sequence */ |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 758 | if (test_sta_flags(sta, WLAN_STA_PS) && |
| 759 | !(rx->fc & IEEE80211_FCTL_PM)) |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 760 | rx->sent_ps_buffered += ap_sta_ps_end(dev, sta); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 761 | else if (!test_sta_flags(sta, WLAN_STA_PS) && |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 762 | (rx->fc & IEEE80211_FCTL_PM)) |
| 763 | ap_sta_ps_start(dev, sta); |
| 764 | } |
| 765 | |
| 766 | /* Drop data::nullfunc frames silently, since they are used only to |
| 767 | * control station power saving mode. */ |
| 768 | if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA && |
| 769 | (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_NULLFUNC) { |
| 770 | I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc); |
| 771 | /* Update counter and free packet here to avoid counting this |
| 772 | * as a dropped packed. */ |
| 773 | sta->rx_packets++; |
| 774 | dev_kfree_skb(rx->skb); |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 775 | return RX_QUEUED; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 776 | } |
| 777 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 778 | return RX_CONTINUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 779 | } /* ieee80211_rx_h_sta_process */ |
| 780 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 781 | static inline struct ieee80211_fragment_entry * |
| 782 | ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata, |
| 783 | unsigned int frag, unsigned int seq, int rx_queue, |
| 784 | struct sk_buff **skb) |
| 785 | { |
| 786 | struct ieee80211_fragment_entry *entry; |
| 787 | int idx; |
| 788 | |
| 789 | idx = sdata->fragment_next; |
| 790 | entry = &sdata->fragments[sdata->fragment_next++]; |
| 791 | if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX) |
| 792 | sdata->fragment_next = 0; |
| 793 | |
| 794 | if (!skb_queue_empty(&entry->skb_list)) { |
| 795 | #ifdef CONFIG_MAC80211_DEBUG |
| 796 | struct ieee80211_hdr *hdr = |
| 797 | (struct ieee80211_hdr *) entry->skb_list.next->data; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 798 | DECLARE_MAC_BUF(mac); |
| 799 | DECLARE_MAC_BUF(mac2); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 800 | printk(KERN_DEBUG "%s: RX reassembly removed oldest " |
| 801 | "fragment entry (idx=%d age=%lu seq=%d last_frag=%d " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 802 | "addr1=%s addr2=%s\n", |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 803 | sdata->dev->name, idx, |
| 804 | jiffies - entry->first_frag_time, entry->seq, |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 805 | entry->last_frag, print_mac(mac, hdr->addr1), |
| 806 | print_mac(mac2, hdr->addr2)); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 807 | #endif /* CONFIG_MAC80211_DEBUG */ |
| 808 | __skb_queue_purge(&entry->skb_list); |
| 809 | } |
| 810 | |
| 811 | __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */ |
| 812 | *skb = NULL; |
| 813 | entry->first_frag_time = jiffies; |
| 814 | entry->seq = seq; |
| 815 | entry->rx_queue = rx_queue; |
| 816 | entry->last_frag = frag; |
| 817 | entry->ccmp = 0; |
| 818 | entry->extra_len = 0; |
| 819 | |
| 820 | return entry; |
| 821 | } |
| 822 | |
| 823 | static inline struct ieee80211_fragment_entry * |
| 824 | ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata, |
| 825 | u16 fc, unsigned int frag, unsigned int seq, |
| 826 | int rx_queue, struct ieee80211_hdr *hdr) |
| 827 | { |
| 828 | struct ieee80211_fragment_entry *entry; |
| 829 | int i, idx; |
| 830 | |
| 831 | idx = sdata->fragment_next; |
| 832 | for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) { |
| 833 | struct ieee80211_hdr *f_hdr; |
| 834 | u16 f_fc; |
| 835 | |
| 836 | idx--; |
| 837 | if (idx < 0) |
| 838 | idx = IEEE80211_FRAGMENT_MAX - 1; |
| 839 | |
| 840 | entry = &sdata->fragments[idx]; |
| 841 | if (skb_queue_empty(&entry->skb_list) || entry->seq != seq || |
| 842 | entry->rx_queue != rx_queue || |
| 843 | entry->last_frag + 1 != frag) |
| 844 | continue; |
| 845 | |
| 846 | f_hdr = (struct ieee80211_hdr *) entry->skb_list.next->data; |
| 847 | f_fc = le16_to_cpu(f_hdr->frame_control); |
| 848 | |
| 849 | if ((fc & IEEE80211_FCTL_FTYPE) != (f_fc & IEEE80211_FCTL_FTYPE) || |
| 850 | compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 || |
| 851 | compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0) |
| 852 | continue; |
| 853 | |
S.Çağlar Onur | ab46623 | 2008-02-14 17:36:47 +0200 | [diff] [blame] | 854 | if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 855 | __skb_queue_purge(&entry->skb_list); |
| 856 | continue; |
| 857 | } |
| 858 | return entry; |
| 859 | } |
| 860 | |
| 861 | return NULL; |
| 862 | } |
| 863 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 864 | static ieee80211_rx_result |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 865 | ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 866 | { |
| 867 | struct ieee80211_hdr *hdr; |
| 868 | u16 sc; |
| 869 | unsigned int frag, seq; |
| 870 | struct ieee80211_fragment_entry *entry; |
| 871 | struct sk_buff *skb; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 872 | DECLARE_MAC_BUF(mac); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 873 | |
| 874 | hdr = (struct ieee80211_hdr *) rx->skb->data; |
| 875 | sc = le16_to_cpu(hdr->seq_ctrl); |
| 876 | frag = sc & IEEE80211_SCTL_FRAG; |
| 877 | |
| 878 | if (likely((!(rx->fc & IEEE80211_FCTL_MOREFRAGS) && frag == 0) || |
| 879 | (rx->skb)->len < 24 || |
| 880 | is_multicast_ether_addr(hdr->addr1))) { |
| 881 | /* not fragmented */ |
| 882 | goto out; |
| 883 | } |
| 884 | I802_DEBUG_INC(rx->local->rx_handlers_fragments); |
| 885 | |
| 886 | seq = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 887 | |
| 888 | if (frag == 0) { |
| 889 | /* This is the first fragment of a new frame. */ |
| 890 | entry = ieee80211_reassemble_add(rx->sdata, frag, seq, |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 891 | rx->queue, &(rx->skb)); |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 892 | if (rx->key && rx->key->conf.alg == ALG_CCMP && |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 893 | (rx->fc & IEEE80211_FCTL_PROTECTED)) { |
| 894 | /* Store CCMP PN so that we can verify that the next |
| 895 | * fragment has a sequential PN value. */ |
| 896 | entry->ccmp = 1; |
| 897 | memcpy(entry->last_pn, |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 898 | rx->key->u.ccmp.rx_pn[rx->queue], |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 899 | CCMP_PN_LEN); |
| 900 | } |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 901 | return RX_QUEUED; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | /* This is a fragment for a frame that should already be pending in |
| 905 | * fragment cache. Add this fragment to the end of the pending entry. |
| 906 | */ |
| 907 | entry = ieee80211_reassemble_find(rx->sdata, rx->fc, frag, seq, |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 908 | rx->queue, hdr); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 909 | if (!entry) { |
| 910 | I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag); |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 911 | return RX_DROP_MONITOR; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | /* Verify that MPDUs within one MSDU have sequential PN values. |
| 915 | * (IEEE 802.11i, 8.3.3.4.5) */ |
| 916 | if (entry->ccmp) { |
| 917 | int i; |
| 918 | u8 pn[CCMP_PN_LEN], *rpn; |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 919 | if (!rx->key || rx->key->conf.alg != ALG_CCMP) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 920 | return RX_DROP_UNUSABLE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 921 | memcpy(pn, entry->last_pn, CCMP_PN_LEN); |
| 922 | for (i = CCMP_PN_LEN - 1; i >= 0; i--) { |
| 923 | pn[i]++; |
| 924 | if (pn[i]) |
| 925 | break; |
| 926 | } |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 927 | rpn = rx->key->u.ccmp.rx_pn[rx->queue]; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 928 | if (memcmp(pn, rpn, CCMP_PN_LEN) != 0) { |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 929 | if (net_ratelimit()) |
| 930 | printk(KERN_DEBUG "%s: defrag: CCMP PN not " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 931 | "sequential A2=%s" |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 932 | " PN=%02x%02x%02x%02x%02x%02x " |
| 933 | "(expected %02x%02x%02x%02x%02x%02x)\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 934 | rx->dev->name, print_mac(mac, hdr->addr2), |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 935 | rpn[0], rpn[1], rpn[2], rpn[3], rpn[4], |
| 936 | rpn[5], pn[0], pn[1], pn[2], pn[3], |
| 937 | pn[4], pn[5]); |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 938 | return RX_DROP_UNUSABLE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 939 | } |
| 940 | memcpy(entry->last_pn, pn, CCMP_PN_LEN); |
| 941 | } |
| 942 | |
| 943 | skb_pull(rx->skb, ieee80211_get_hdrlen(rx->fc)); |
| 944 | __skb_queue_tail(&entry->skb_list, rx->skb); |
| 945 | entry->last_frag = frag; |
| 946 | entry->extra_len += rx->skb->len; |
| 947 | if (rx->fc & IEEE80211_FCTL_MOREFRAGS) { |
| 948 | rx->skb = NULL; |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 949 | return RX_QUEUED; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | rx->skb = __skb_dequeue(&entry->skb_list); |
| 953 | if (skb_tailroom(rx->skb) < entry->extra_len) { |
| 954 | I802_DEBUG_INC(rx->local->rx_expand_skb_head2); |
| 955 | if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len, |
| 956 | GFP_ATOMIC))) { |
| 957 | I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag); |
| 958 | __skb_queue_purge(&entry->skb_list); |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 959 | return RX_DROP_UNUSABLE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 960 | } |
| 961 | } |
| 962 | while ((skb = __skb_dequeue(&entry->skb_list))) { |
| 963 | memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len); |
| 964 | dev_kfree_skb(skb); |
| 965 | } |
| 966 | |
| 967 | /* Complete frame has been reassembled - process it now */ |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 968 | rx->flags |= IEEE80211_RX_FRAGMENTED; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 969 | |
| 970 | out: |
| 971 | if (rx->sta) |
| 972 | rx->sta->rx_packets++; |
| 973 | if (is_multicast_ether_addr(hdr->addr1)) |
| 974 | rx->local->dot11MulticastReceivedFrameCount++; |
| 975 | else |
| 976 | ieee80211_led_rx(rx->local); |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 977 | return RX_CONTINUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 978 | } |
| 979 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 980 | static ieee80211_rx_result |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 981 | ieee80211_rx_h_ps_poll(struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 982 | { |
Ron Rindjunsky | 98f0b0a | 2007-12-18 17:23:53 +0200 | [diff] [blame] | 983 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 984 | struct sk_buff *skb; |
| 985 | int no_pending_pkts; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 986 | DECLARE_MAC_BUF(mac); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 987 | |
| 988 | if (likely(!rx->sta || |
| 989 | (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL || |
| 990 | (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PSPOLL || |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 991 | !(rx->flags & IEEE80211_RX_RA_MATCH))) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 992 | return RX_CONTINUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 993 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 994 | if ((sdata->vif.type != IEEE80211_IF_TYPE_AP) && |
| 995 | (sdata->vif.type != IEEE80211_IF_TYPE_VLAN)) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 996 | return RX_DROP_UNUSABLE; |
Ron Rindjunsky | 98f0b0a | 2007-12-18 17:23:53 +0200 | [diff] [blame] | 997 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 998 | skb = skb_dequeue(&rx->sta->tx_filtered); |
| 999 | if (!skb) { |
| 1000 | skb = skb_dequeue(&rx->sta->ps_tx_buf); |
| 1001 | if (skb) |
| 1002 | rx->local->total_ps_buffered--; |
| 1003 | } |
| 1004 | no_pending_pkts = skb_queue_empty(&rx->sta->tx_filtered) && |
| 1005 | skb_queue_empty(&rx->sta->ps_tx_buf); |
| 1006 | |
| 1007 | if (skb) { |
| 1008 | struct ieee80211_hdr *hdr = |
| 1009 | (struct ieee80211_hdr *) skb->data; |
| 1010 | |
Johannes Berg | 4a9a66e | 2008-02-19 11:31:14 +0100 | [diff] [blame] | 1011 | /* |
| 1012 | * Tell TX path to send one frame even though the STA may |
| 1013 | * still remain is PS mode after this frame exchange. |
| 1014 | */ |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1015 | set_sta_flags(rx->sta, WLAN_STA_PSPOLL); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1016 | |
| 1017 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1018 | printk(KERN_DEBUG "STA %s aid %d: PS Poll (entries after %d)\n", |
| 1019 | print_mac(mac, rx->sta->addr), rx->sta->aid, |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1020 | skb_queue_len(&rx->sta->ps_tx_buf)); |
| 1021 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
| 1022 | |
| 1023 | /* Use MoreData flag to indicate whether there are more |
| 1024 | * buffered frames for this STA */ |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 1025 | if (no_pending_pkts) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1026 | hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA); |
Johannes Berg | 836341a | 2008-02-20 02:07:21 +0100 | [diff] [blame] | 1027 | else |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1028 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA); |
| 1029 | |
| 1030 | dev_queue_xmit(skb); |
| 1031 | |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 1032 | if (no_pending_pkts) |
| 1033 | sta_info_clear_tim_bit(rx->sta); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1034 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1035 | } else if (!rx->sent_ps_buffered) { |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 1036 | /* |
| 1037 | * FIXME: This can be the result of a race condition between |
| 1038 | * us expiring a frame and the station polling for it. |
| 1039 | * Should we send it a null-func frame indicating we |
| 1040 | * have nothing buffered for it? |
| 1041 | */ |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1042 | printk(KERN_DEBUG "%s: STA %s sent PS Poll even " |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1043 | "though there is no buffered frames for it\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1044 | rx->dev->name, print_mac(mac, rx->sta->addr)); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1045 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1046 | } |
| 1047 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1048 | /* Free PS Poll skb here instead of returning RX_DROP that would |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1049 | * count as an dropped frame. */ |
| 1050 | dev_kfree_skb(rx->skb); |
| 1051 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1052 | return RX_QUEUED; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1053 | } |
| 1054 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1055 | static ieee80211_rx_result |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1056 | ieee80211_rx_h_remove_qos_control(struct ieee80211_rx_data *rx) |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1057 | { |
| 1058 | u16 fc = rx->fc; |
| 1059 | u8 *data = rx->skb->data; |
| 1060 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data; |
| 1061 | |
| 1062 | if (!WLAN_FC_IS_QOS_DATA(fc)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1063 | return RX_CONTINUE; |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1064 | |
| 1065 | /* remove the qos control field, update frame type and meta-data */ |
| 1066 | memmove(data + 2, data, ieee80211_get_hdrlen(fc) - 2); |
| 1067 | hdr = (struct ieee80211_hdr *) skb_pull(rx->skb, 2); |
| 1068 | /* change frame type to non QOS */ |
| 1069 | rx->fc = fc &= ~IEEE80211_STYPE_QOS_DATA; |
| 1070 | hdr->frame_control = cpu_to_le16(fc); |
| 1071 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1072 | return RX_CONTINUE; |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1073 | } |
| 1074 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1075 | static int |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1076 | ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1077 | { |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1078 | if (unlikely(!rx->sta || |
| 1079 | !test_sta_flags(rx->sta, WLAN_STA_AUTHORIZED))) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1080 | #ifdef CONFIG_MAC80211_DEBUG |
Johannes Berg | 238814f | 2008-01-28 17:19:37 +0100 | [diff] [blame] | 1081 | if (net_ratelimit()) |
| 1082 | printk(KERN_DEBUG "%s: dropped frame " |
| 1083 | "(unauthorized port)\n", rx->dev->name); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1084 | #endif /* CONFIG_MAC80211_DEBUG */ |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1085 | return -EACCES; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1086 | } |
| 1087 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1088 | return 0; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1089 | } |
| 1090 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1091 | static int |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1092 | ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1093 | { |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 1094 | /* |
Johannes Berg | 7848ba7 | 2007-09-14 11:10:25 -0400 | [diff] [blame] | 1095 | * Pass through unencrypted frames if the hardware has |
| 1096 | * decrypted them already. |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 1097 | */ |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1098 | if (rx->status->flag & RX_FLAG_DECRYPTED) |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1099 | return 0; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1100 | |
| 1101 | /* Drop unencrypted frames if key is set. */ |
| 1102 | if (unlikely(!(rx->fc & IEEE80211_FCTL_PROTECTED) && |
| 1103 | (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA && |
| 1104 | (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC && |
Johannes Berg | b3fc9c6 | 2008-04-13 10:12:47 +0200 | [diff] [blame] | 1105 | (rx->key || rx->sdata->drop_unencrypted))) |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1106 | return -EACCES; |
Johannes Berg | b3fc9c6 | 2008-04-13 10:12:47 +0200 | [diff] [blame] | 1107 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1108 | return 0; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1109 | } |
| 1110 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1111 | static int |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1112 | ieee80211_data_to_8023(struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1113 | { |
| 1114 | struct net_device *dev = rx->dev; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1115 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; |
| 1116 | u16 fc, hdrlen, ethertype; |
| 1117 | u8 *payload; |
| 1118 | u8 dst[ETH_ALEN]; |
| 1119 | u8 src[ETH_ALEN]; |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1120 | struct sk_buff *skb = rx->skb; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1121 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1122 | DECLARE_MAC_BUF(mac); |
| 1123 | DECLARE_MAC_BUF(mac2); |
| 1124 | DECLARE_MAC_BUF(mac3); |
| 1125 | DECLARE_MAC_BUF(mac4); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1126 | |
| 1127 | fc = rx->fc; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1128 | |
| 1129 | if (unlikely(!WLAN_FC_DATA_PRESENT(fc))) |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1130 | return -1; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1131 | |
| 1132 | hdrlen = ieee80211_get_hdrlen(fc); |
| 1133 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 1134 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 1135 | int meshhdrlen = ieee80211_get_mesh_hdrlen( |
| 1136 | (struct ieee80211s_hdr *) (skb->data + hdrlen)); |
| 1137 | /* Copy on cb: |
| 1138 | * - mesh header: to be used for mesh forwarding |
| 1139 | * decision. It will also be used as mesh header template at |
| 1140 | * tx.c:ieee80211_subif_start_xmit() if interface |
| 1141 | * type is mesh and skb->pkt_type == PACKET_OTHERHOST |
| 1142 | * - ta: to be used if a RERR needs to be sent. |
| 1143 | */ |
| 1144 | memcpy(skb->cb, skb->data + hdrlen, meshhdrlen); |
| 1145 | memcpy(MESH_PREQ(skb), hdr->addr2, ETH_ALEN); |
| 1146 | hdrlen += meshhdrlen; |
| 1147 | } |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 1148 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1149 | /* convert IEEE 802.11 header + possible LLC headers into Ethernet |
| 1150 | * header |
| 1151 | * IEEE 802.11 address fields: |
| 1152 | * ToDS FromDS Addr1 Addr2 Addr3 Addr4 |
| 1153 | * 0 0 DA SA BSSID n/a |
| 1154 | * 0 1 DA BSSID SA n/a |
| 1155 | * 1 0 BSSID SA DA n/a |
| 1156 | * 1 1 RA TA DA SA |
| 1157 | */ |
| 1158 | |
| 1159 | switch (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) { |
| 1160 | case IEEE80211_FCTL_TODS: |
| 1161 | /* BSSID SA DA */ |
| 1162 | memcpy(dst, hdr->addr3, ETH_ALEN); |
| 1163 | memcpy(src, hdr->addr2, ETH_ALEN); |
| 1164 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1165 | if (unlikely(sdata->vif.type != IEEE80211_IF_TYPE_AP && |
| 1166 | sdata->vif.type != IEEE80211_IF_TYPE_VLAN)) { |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 1167 | if (net_ratelimit()) |
| 1168 | printk(KERN_DEBUG "%s: dropped ToDS frame " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1169 | "(BSSID=%s SA=%s DA=%s)\n", |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 1170 | dev->name, |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1171 | print_mac(mac, hdr->addr1), |
| 1172 | print_mac(mac2, hdr->addr2), |
| 1173 | print_mac(mac3, hdr->addr3)); |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1174 | return -1; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1175 | } |
| 1176 | break; |
| 1177 | case (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS): |
| 1178 | /* RA TA DA SA */ |
| 1179 | memcpy(dst, hdr->addr3, ETH_ALEN); |
| 1180 | memcpy(src, hdr->addr4, ETH_ALEN); |
| 1181 | |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 1182 | if (unlikely(sdata->vif.type != IEEE80211_IF_TYPE_WDS && |
| 1183 | sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)) { |
| 1184 | if (net_ratelimit()) |
| 1185 | printk(KERN_DEBUG "%s: dropped FromDS&ToDS " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1186 | "frame (RA=%s TA=%s DA=%s SA=%s)\n", |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 1187 | rx->dev->name, |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1188 | print_mac(mac, hdr->addr1), |
| 1189 | print_mac(mac2, hdr->addr2), |
| 1190 | print_mac(mac3, hdr->addr3), |
| 1191 | print_mac(mac4, hdr->addr4)); |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1192 | return -1; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1193 | } |
| 1194 | break; |
| 1195 | case IEEE80211_FCTL_FROMDS: |
| 1196 | /* DA BSSID SA */ |
| 1197 | memcpy(dst, hdr->addr1, ETH_ALEN); |
| 1198 | memcpy(src, hdr->addr3, ETH_ALEN); |
| 1199 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1200 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA || |
John W. Linville | b331615 | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 1201 | (is_multicast_ether_addr(dst) && |
| 1202 | !compare_ether_addr(src, dev->dev_addr))) |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1203 | return -1; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1204 | break; |
| 1205 | case 0: |
| 1206 | /* DA SA BSSID */ |
| 1207 | memcpy(dst, hdr->addr1, ETH_ALEN); |
| 1208 | memcpy(src, hdr->addr2, ETH_ALEN); |
| 1209 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1210 | if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1211 | if (net_ratelimit()) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1212 | printk(KERN_DEBUG "%s: dropped IBSS frame " |
| 1213 | "(DA=%s SA=%s BSSID=%s)\n", |
| 1214 | dev->name, |
| 1215 | print_mac(mac, hdr->addr1), |
| 1216 | print_mac(mac2, hdr->addr2), |
| 1217 | print_mac(mac3, hdr->addr3)); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1218 | } |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1219 | return -1; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1220 | } |
| 1221 | break; |
| 1222 | } |
| 1223 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1224 | if (unlikely(skb->len - hdrlen < 8)) { |
| 1225 | if (net_ratelimit()) { |
| 1226 | printk(KERN_DEBUG "%s: RX too short data frame " |
| 1227 | "payload\n", dev->name); |
| 1228 | } |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1229 | return -1; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1230 | } |
| 1231 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1232 | payload = skb->data + hdrlen; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1233 | ethertype = (payload[6] << 8) | payload[7]; |
| 1234 | |
| 1235 | if (likely((compare_ether_addr(payload, rfc1042_header) == 0 && |
| 1236 | ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) || |
| 1237 | compare_ether_addr(payload, bridge_tunnel_header) == 0)) { |
| 1238 | /* remove RFC1042 or Bridge-Tunnel encapsulation and |
| 1239 | * replace EtherType */ |
| 1240 | skb_pull(skb, hdrlen + 6); |
| 1241 | memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN); |
| 1242 | memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN); |
| 1243 | } else { |
| 1244 | struct ethhdr *ehdr; |
| 1245 | __be16 len; |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1246 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1247 | skb_pull(skb, hdrlen); |
| 1248 | len = htons(skb->len); |
| 1249 | ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr)); |
| 1250 | memcpy(ehdr->h_dest, dst, ETH_ALEN); |
| 1251 | memcpy(ehdr->h_source, src, ETH_ALEN); |
| 1252 | ehdr->h_proto = len; |
| 1253 | } |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1254 | return 0; |
| 1255 | } |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1256 | |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1257 | /* |
| 1258 | * requires that rx->skb is a frame with ethernet header |
| 1259 | */ |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1260 | static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx) |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1261 | { |
| 1262 | static const u8 pae_group_addr[ETH_ALEN] |
| 1263 | = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 }; |
| 1264 | struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data; |
| 1265 | |
| 1266 | /* |
| 1267 | * Allow EAPOL frames to us/the PAE group address regardless |
| 1268 | * of whether the frame was encrypted or not. |
| 1269 | */ |
| 1270 | if (ehdr->h_proto == htons(ETH_P_PAE) && |
| 1271 | (compare_ether_addr(ehdr->h_dest, rx->dev->dev_addr) == 0 || |
| 1272 | compare_ether_addr(ehdr->h_dest, pae_group_addr) == 0)) |
| 1273 | return true; |
| 1274 | |
| 1275 | if (ieee80211_802_1x_port_control(rx) || |
| 1276 | ieee80211_drop_unencrypted(rx)) |
| 1277 | return false; |
| 1278 | |
| 1279 | return true; |
| 1280 | } |
| 1281 | |
| 1282 | /* |
| 1283 | * requires that rx->skb is a frame with ethernet header |
| 1284 | */ |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1285 | static void |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1286 | ieee80211_deliver_skb(struct ieee80211_rx_data *rx) |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1287 | { |
| 1288 | struct net_device *dev = rx->dev; |
| 1289 | struct ieee80211_local *local = rx->local; |
| 1290 | struct sk_buff *skb, *xmit_skb; |
| 1291 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1292 | struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data; |
| 1293 | struct sta_info *dsta; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1294 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1295 | skb = rx->skb; |
| 1296 | xmit_skb = NULL; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1297 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1298 | if (local->bridge_packets && (sdata->vif.type == IEEE80211_IF_TYPE_AP || |
| 1299 | sdata->vif.type == IEEE80211_IF_TYPE_VLAN) && |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1300 | (rx->flags & IEEE80211_RX_RA_MATCH)) { |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1301 | if (is_multicast_ether_addr(ehdr->h_dest)) { |
| 1302 | /* |
| 1303 | * send multicast frames both to higher layers in |
| 1304 | * local net stack and back to the wireless medium |
| 1305 | */ |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1306 | xmit_skb = skb_copy(skb, GFP_ATOMIC); |
| 1307 | if (!xmit_skb && net_ratelimit()) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1308 | printk(KERN_DEBUG "%s: failed to clone " |
| 1309 | "multicast frame\n", dev->name); |
| 1310 | } else { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1311 | dsta = sta_info_get(local, skb->data); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1312 | if (dsta && dsta->sdata->dev == dev) { |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1313 | /* |
| 1314 | * The destination station is associated to |
| 1315 | * this AP (in this VLAN), so send the frame |
| 1316 | * directly to it and do not pass it to local |
| 1317 | * net stack. |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1318 | */ |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1319 | xmit_skb = skb; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1320 | skb = NULL; |
| 1321 | } |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1322 | } |
| 1323 | } |
| 1324 | |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 1325 | /* Mesh forwarding */ |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 1326 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 1327 | u8 *mesh_ttl = &((struct ieee80211s_hdr *)skb->cb)->ttl; |
| 1328 | (*mesh_ttl)--; |
| 1329 | |
| 1330 | if (is_multicast_ether_addr(skb->data)) { |
| 1331 | if (*mesh_ttl > 0) { |
| 1332 | xmit_skb = skb_copy(skb, GFP_ATOMIC); |
Luis Carlos Cobo | 69687a0 | 2008-05-05 12:29:42 -0700 | [diff] [blame] | 1333 | if (xmit_skb) |
| 1334 | xmit_skb->pkt_type = PACKET_OTHERHOST; |
| 1335 | else if (net_ratelimit()) |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 1336 | printk(KERN_DEBUG "%s: failed to clone " |
| 1337 | "multicast frame\n", dev->name); |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 1338 | } else |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 1339 | IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.sta, |
| 1340 | dropped_frames_ttl); |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 1341 | } else if (skb->pkt_type != PACKET_OTHERHOST && |
| 1342 | compare_ether_addr(dev->dev_addr, skb->data) != 0) { |
| 1343 | if (*mesh_ttl == 0) { |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 1344 | IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.sta, |
| 1345 | dropped_frames_ttl); |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 1346 | dev_kfree_skb(skb); |
| 1347 | skb = NULL; |
| 1348 | } else { |
| 1349 | xmit_skb = skb; |
| 1350 | xmit_skb->pkt_type = PACKET_OTHERHOST; |
| 1351 | if (!(dev->flags & IFF_PROMISC)) |
| 1352 | skb = NULL; |
| 1353 | } |
| 1354 | } |
| 1355 | } |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 1356 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1357 | if (skb) { |
| 1358 | /* deliver to local stack */ |
| 1359 | skb->protocol = eth_type_trans(skb, dev); |
| 1360 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 1361 | netif_rx(skb); |
| 1362 | } |
| 1363 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1364 | if (xmit_skb) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1365 | /* send to wireless media */ |
YOSHIFUJI Hideaki | f831e90 | 2007-12-12 03:54:23 +0900 | [diff] [blame] | 1366 | xmit_skb->protocol = htons(ETH_P_802_3); |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1367 | skb_reset_network_header(xmit_skb); |
| 1368 | skb_reset_mac_header(xmit_skb); |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1369 | dev_queue_xmit(xmit_skb); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1370 | } |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1371 | } |
| 1372 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1373 | static ieee80211_rx_result |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1374 | ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx) |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1375 | { |
| 1376 | struct net_device *dev = rx->dev; |
| 1377 | struct ieee80211_local *local = rx->local; |
| 1378 | u16 fc, ethertype; |
| 1379 | u8 *payload; |
| 1380 | struct sk_buff *skb = rx->skb, *frame = NULL; |
| 1381 | const struct ethhdr *eth; |
| 1382 | int remaining, err; |
| 1383 | u8 dst[ETH_ALEN]; |
| 1384 | u8 src[ETH_ALEN]; |
| 1385 | DECLARE_MAC_BUF(mac); |
| 1386 | |
| 1387 | fc = rx->fc; |
| 1388 | if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1389 | return RX_CONTINUE; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1390 | |
| 1391 | if (unlikely(!WLAN_FC_DATA_PRESENT(fc))) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1392 | return RX_DROP_MONITOR; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1393 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1394 | if (!(rx->flags & IEEE80211_RX_AMSDU)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1395 | return RX_CONTINUE; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1396 | |
| 1397 | err = ieee80211_data_to_8023(rx); |
| 1398 | if (unlikely(err)) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1399 | return RX_DROP_UNUSABLE; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1400 | |
| 1401 | skb->dev = dev; |
| 1402 | |
| 1403 | dev->stats.rx_packets++; |
| 1404 | dev->stats.rx_bytes += skb->len; |
| 1405 | |
| 1406 | /* skip the wrapping header */ |
| 1407 | eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr)); |
| 1408 | if (!eth) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1409 | return RX_DROP_UNUSABLE; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1410 | |
| 1411 | while (skb != frame) { |
| 1412 | u8 padding; |
| 1413 | __be16 len = eth->h_proto; |
| 1414 | unsigned int subframe_len = sizeof(struct ethhdr) + ntohs(len); |
| 1415 | |
| 1416 | remaining = skb->len; |
| 1417 | memcpy(dst, eth->h_dest, ETH_ALEN); |
| 1418 | memcpy(src, eth->h_source, ETH_ALEN); |
| 1419 | |
| 1420 | padding = ((4 - subframe_len) & 0x3); |
| 1421 | /* the last MSDU has no padding */ |
| 1422 | if (subframe_len > remaining) { |
Pavel Roskin | a4278e1 | 2008-05-12 09:02:24 -0400 | [diff] [blame] | 1423 | printk(KERN_DEBUG "%s: wrong buffer size\n", dev->name); |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1424 | return RX_DROP_UNUSABLE; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | skb_pull(skb, sizeof(struct ethhdr)); |
| 1428 | /* if last subframe reuse skb */ |
| 1429 | if (remaining <= subframe_len + padding) |
| 1430 | frame = skb; |
| 1431 | else { |
| 1432 | frame = dev_alloc_skb(local->hw.extra_tx_headroom + |
| 1433 | subframe_len); |
| 1434 | |
| 1435 | if (frame == NULL) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1436 | return RX_DROP_UNUSABLE; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1437 | |
| 1438 | skb_reserve(frame, local->hw.extra_tx_headroom + |
| 1439 | sizeof(struct ethhdr)); |
| 1440 | memcpy(skb_put(frame, ntohs(len)), skb->data, |
| 1441 | ntohs(len)); |
| 1442 | |
| 1443 | eth = (struct ethhdr *) skb_pull(skb, ntohs(len) + |
| 1444 | padding); |
| 1445 | if (!eth) { |
Pavel Roskin | a4278e1 | 2008-05-12 09:02:24 -0400 | [diff] [blame] | 1446 | printk(KERN_DEBUG "%s: wrong buffer size\n", |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1447 | dev->name); |
| 1448 | dev_kfree_skb(frame); |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1449 | return RX_DROP_UNUSABLE; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1450 | } |
| 1451 | } |
| 1452 | |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1453 | skb_reset_network_header(frame); |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1454 | frame->dev = dev; |
| 1455 | frame->priority = skb->priority; |
| 1456 | rx->skb = frame; |
| 1457 | |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1458 | payload = frame->data; |
| 1459 | ethertype = (payload[6] << 8) | payload[7]; |
| 1460 | |
| 1461 | if (likely((compare_ether_addr(payload, rfc1042_header) == 0 && |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1462 | ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) || |
| 1463 | compare_ether_addr(payload, |
| 1464 | bridge_tunnel_header) == 0)) { |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1465 | /* remove RFC1042 or Bridge-Tunnel |
| 1466 | * encapsulation and replace EtherType */ |
| 1467 | skb_pull(frame, 6); |
| 1468 | memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN); |
| 1469 | memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN); |
| 1470 | } else { |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1471 | memcpy(skb_push(frame, sizeof(__be16)), |
| 1472 | &len, sizeof(__be16)); |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1473 | memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN); |
| 1474 | memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN); |
| 1475 | } |
| 1476 | |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1477 | if (!ieee80211_frame_allowed(rx)) { |
| 1478 | if (skb == frame) /* last frame */ |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1479 | return RX_DROP_UNUSABLE; |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1480 | dev_kfree_skb(frame); |
| 1481 | continue; |
| 1482 | } |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1483 | |
| 1484 | ieee80211_deliver_skb(rx); |
| 1485 | } |
| 1486 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1487 | return RX_QUEUED; |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1488 | } |
| 1489 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1490 | static ieee80211_rx_result |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1491 | ieee80211_rx_h_data(struct ieee80211_rx_data *rx) |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1492 | { |
| 1493 | struct net_device *dev = rx->dev; |
| 1494 | u16 fc; |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1495 | int err; |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1496 | |
| 1497 | fc = rx->fc; |
| 1498 | if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1499 | return RX_CONTINUE; |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1500 | |
| 1501 | if (unlikely(!WLAN_FC_DATA_PRESENT(fc))) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1502 | return RX_DROP_MONITOR; |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1503 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1504 | err = ieee80211_data_to_8023(rx); |
| 1505 | if (unlikely(err)) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1506 | return RX_DROP_UNUSABLE; |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1507 | |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1508 | if (!ieee80211_frame_allowed(rx)) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1509 | return RX_DROP_MONITOR; |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 1510 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame] | 1511 | rx->skb->dev = dev; |
| 1512 | |
| 1513 | dev->stats.rx_packets++; |
| 1514 | dev->stats.rx_bytes += rx->skb->len; |
| 1515 | |
| 1516 | ieee80211_deliver_skb(rx); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1517 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1518 | return RX_QUEUED; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1519 | } |
| 1520 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1521 | static ieee80211_rx_result |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1522 | ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx) |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 1523 | { |
| 1524 | struct ieee80211_local *local = rx->local; |
| 1525 | struct ieee80211_hw *hw = &local->hw; |
| 1526 | struct sk_buff *skb = rx->skb; |
| 1527 | struct ieee80211_bar *bar = (struct ieee80211_bar *) skb->data; |
| 1528 | struct tid_ampdu_rx *tid_agg_rx; |
| 1529 | u16 start_seq_num; |
| 1530 | u16 tid; |
| 1531 | |
| 1532 | if (likely((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1533 | return RX_CONTINUE; |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 1534 | |
| 1535 | if ((rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BACK_REQ) { |
| 1536 | if (!rx->sta) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1537 | return RX_CONTINUE; |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 1538 | tid = le16_to_cpu(bar->control) >> 12; |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1539 | if (rx->sta->ampdu_mlme.tid_state_rx[tid] |
| 1540 | != HT_AGG_STATE_OPERATIONAL) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1541 | return RX_CONTINUE; |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1542 | tid_agg_rx = rx->sta->ampdu_mlme.tid_rx[tid]; |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 1543 | |
| 1544 | start_seq_num = le16_to_cpu(bar->start_seq_num) >> 4; |
| 1545 | |
| 1546 | /* reset session timer */ |
| 1547 | if (tid_agg_rx->timeout) { |
| 1548 | unsigned long expires = |
| 1549 | jiffies + (tid_agg_rx->timeout / 1000) * HZ; |
| 1550 | mod_timer(&tid_agg_rx->session_timer, expires); |
| 1551 | } |
| 1552 | |
| 1553 | /* manage reordering buffer according to requested */ |
| 1554 | /* sequence number */ |
| 1555 | rcu_read_lock(); |
| 1556 | ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, NULL, |
| 1557 | start_seq_num, 1); |
| 1558 | rcu_read_unlock(); |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1559 | return RX_DROP_UNUSABLE; |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 1560 | } |
| 1561 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1562 | return RX_CONTINUE; |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 1563 | } |
| 1564 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1565 | static ieee80211_rx_result |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1566 | ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1567 | { |
| 1568 | struct ieee80211_sub_if_data *sdata; |
| 1569 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1570 | if (!(rx->flags & IEEE80211_RX_RA_MATCH)) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1571 | return RX_DROP_MONITOR; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1572 | |
| 1573 | sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev); |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1574 | if ((sdata->vif.type == IEEE80211_IF_TYPE_STA || |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 1575 | sdata->vif.type == IEEE80211_IF_TYPE_IBSS || |
| 1576 | sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT) && |
Johannes Berg | ddd3d2b | 2007-09-26 17:53:20 +0200 | [diff] [blame] | 1577 | !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)) |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1578 | ieee80211_sta_rx_mgmt(rx->dev, rx->skb, rx->status); |
Johannes Berg | f9d540e | 2007-09-28 14:02:09 +0200 | [diff] [blame] | 1579 | else |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 1580 | return RX_DROP_MONITOR; |
Johannes Berg | f9d540e | 2007-09-28 14:02:09 +0200 | [diff] [blame] | 1581 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1582 | return RX_QUEUED; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1583 | } |
| 1584 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1585 | static void ieee80211_rx_michael_mic_report(struct net_device *dev, |
| 1586 | struct ieee80211_hdr *hdr, |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1587 | struct ieee80211_rx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1588 | { |
| 1589 | int keyidx, hdrlen; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1590 | DECLARE_MAC_BUF(mac); |
| 1591 | DECLARE_MAC_BUF(mac2); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1592 | |
| 1593 | hdrlen = ieee80211_get_hdrlen_from_skb(rx->skb); |
| 1594 | if (rx->skb->len >= hdrlen + 4) |
| 1595 | keyidx = rx->skb->data[hdrlen + 3] >> 6; |
| 1596 | else |
| 1597 | keyidx = -1; |
| 1598 | |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 1599 | if (net_ratelimit()) |
| 1600 | printk(KERN_DEBUG "%s: TKIP hwaccel reported Michael MIC " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1601 | "failure from %s to %s keyidx=%d\n", |
| 1602 | dev->name, print_mac(mac, hdr->addr2), |
| 1603 | print_mac(mac2, hdr->addr1), keyidx); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1604 | |
Johannes Berg | 8944b79 | 2008-01-31 19:48:26 +0100 | [diff] [blame] | 1605 | if (!rx->sta) { |
Johannes Berg | aa0daf0 | 2007-09-10 14:15:25 +0200 | [diff] [blame] | 1606 | /* |
| 1607 | * Some hardware seem to generate incorrect Michael MIC |
| 1608 | * reports; ignore them to avoid triggering countermeasures. |
| 1609 | */ |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 1610 | if (net_ratelimit()) |
| 1611 | printk(KERN_DEBUG "%s: ignored spurious Michael MIC " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1612 | "error for unknown address %s\n", |
| 1613 | dev->name, print_mac(mac, hdr->addr2)); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1614 | goto ignore; |
| 1615 | } |
| 1616 | |
| 1617 | if (!(rx->fc & IEEE80211_FCTL_PROTECTED)) { |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 1618 | if (net_ratelimit()) |
| 1619 | printk(KERN_DEBUG "%s: ignored spurious Michael MIC " |
Johannes Berg | aa0daf0 | 2007-09-10 14:15:25 +0200 | [diff] [blame] | 1620 | "error for a frame with no PROTECTED flag (src " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1621 | "%s)\n", dev->name, print_mac(mac, hdr->addr2)); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1622 | goto ignore; |
| 1623 | } |
| 1624 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1625 | if (rx->sdata->vif.type == IEEE80211_IF_TYPE_AP && keyidx) { |
Johannes Berg | aa0daf0 | 2007-09-10 14:15:25 +0200 | [diff] [blame] | 1626 | /* |
| 1627 | * APs with pairwise keys should never receive Michael MIC |
| 1628 | * errors for non-zero keyidx because these are reserved for |
| 1629 | * group keys and only the AP is sending real multicast |
| 1630 | * frames in the BSS. |
| 1631 | */ |
Johannes Berg | eb063c1 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 1632 | if (net_ratelimit()) |
| 1633 | printk(KERN_DEBUG "%s: ignored Michael MIC error for " |
| 1634 | "a frame with non-zero keyidx (%d)" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1635 | " (src %s)\n", dev->name, keyidx, |
| 1636 | print_mac(mac, hdr->addr2)); |
Johannes Berg | eb063c1 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 1637 | goto ignore; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA && |
| 1641 | ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT || |
| 1642 | (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)) { |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 1643 | if (net_ratelimit()) |
| 1644 | printk(KERN_DEBUG "%s: ignored spurious Michael MIC " |
| 1645 | "error for a frame that cannot be encrypted " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1646 | "(fc=0x%04x) (src %s)\n", |
| 1647 | dev->name, rx->fc, print_mac(mac, hdr->addr2)); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1648 | goto ignore; |
| 1649 | } |
| 1650 | |
Johannes Berg | eb063c1 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 1651 | mac80211_ev_michael_mic_failure(rx->dev, keyidx, hdr); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1652 | ignore: |
| 1653 | dev_kfree_skb(rx->skb); |
| 1654 | rx->skb = NULL; |
| 1655 | } |
| 1656 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1657 | /* TODO: use IEEE80211_RX_FRAGMENTED */ |
| 1658 | static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx) |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 1659 | { |
| 1660 | struct ieee80211_sub_if_data *sdata; |
| 1661 | struct ieee80211_local *local = rx->local; |
| 1662 | struct ieee80211_rtap_hdr { |
| 1663 | struct ieee80211_radiotap_header hdr; |
| 1664 | u8 flags; |
| 1665 | u8 rate; |
| 1666 | __le16 chan_freq; |
| 1667 | __le16 chan_flags; |
| 1668 | } __attribute__ ((packed)) *rthdr; |
| 1669 | struct sk_buff *skb = rx->skb, *skb2; |
| 1670 | struct net_device *prev_dev = NULL; |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1671 | struct ieee80211_rx_status *status = rx->status; |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 1672 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1673 | if (rx->flags & IEEE80211_RX_CMNTR_REPORTED) |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 1674 | goto out_free_skb; |
| 1675 | |
| 1676 | if (skb_headroom(skb) < sizeof(*rthdr) && |
| 1677 | pskb_expand_head(skb, sizeof(*rthdr), 0, GFP_ATOMIC)) |
| 1678 | goto out_free_skb; |
| 1679 | |
| 1680 | rthdr = (void *)skb_push(skb, sizeof(*rthdr)); |
| 1681 | memset(rthdr, 0, sizeof(*rthdr)); |
| 1682 | rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr)); |
| 1683 | rthdr->hdr.it_present = |
| 1684 | cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) | |
| 1685 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 1686 | (1 << IEEE80211_RADIOTAP_CHANNEL)); |
| 1687 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1688 | rthdr->rate = rx->rate->bitrate / 5; |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 1689 | rthdr->chan_freq = cpu_to_le16(status->freq); |
| 1690 | |
| 1691 | if (status->band == IEEE80211_BAND_5GHZ) |
| 1692 | rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_OFDM | |
| 1693 | IEEE80211_CHAN_5GHZ); |
| 1694 | else |
| 1695 | rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_DYN | |
| 1696 | IEEE80211_CHAN_2GHZ); |
| 1697 | |
| 1698 | skb_set_mac_header(skb, 0); |
| 1699 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1700 | skb->pkt_type = PACKET_OTHERHOST; |
| 1701 | skb->protocol = htons(ETH_P_802_2); |
| 1702 | |
| 1703 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
| 1704 | if (!netif_running(sdata->dev)) |
| 1705 | continue; |
| 1706 | |
| 1707 | if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR || |
| 1708 | !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)) |
| 1709 | continue; |
| 1710 | |
| 1711 | if (prev_dev) { |
| 1712 | skb2 = skb_clone(skb, GFP_ATOMIC); |
| 1713 | if (skb2) { |
| 1714 | skb2->dev = prev_dev; |
| 1715 | netif_rx(skb2); |
| 1716 | } |
| 1717 | } |
| 1718 | |
| 1719 | prev_dev = sdata->dev; |
| 1720 | sdata->dev->stats.rx_packets++; |
| 1721 | sdata->dev->stats.rx_bytes += skb->len; |
| 1722 | } |
| 1723 | |
| 1724 | if (prev_dev) { |
| 1725 | skb->dev = prev_dev; |
| 1726 | netif_rx(skb); |
| 1727 | skb = NULL; |
| 1728 | } else |
| 1729 | goto out_free_skb; |
| 1730 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1731 | rx->flags |= IEEE80211_RX_CMNTR_REPORTED; |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 1732 | return; |
| 1733 | |
| 1734 | out_free_skb: |
| 1735 | dev_kfree_skb(skb); |
| 1736 | } |
| 1737 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1738 | typedef ieee80211_rx_result (*ieee80211_rx_handler)(struct ieee80211_rx_data *); |
Johannes Berg | 5890529 | 2008-01-31 19:48:25 +0100 | [diff] [blame] | 1739 | static ieee80211_rx_handler ieee80211_rx_handlers[] = |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1740 | { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1741 | ieee80211_rx_h_passive_scan, |
| 1742 | ieee80211_rx_h_check, |
Johannes Berg | 4f0d18e | 2007-09-26 15:19:40 +0200 | [diff] [blame] | 1743 | ieee80211_rx_h_decrypt, |
Johannes Berg | 70f0876 | 2007-09-26 17:53:14 +0200 | [diff] [blame] | 1744 | ieee80211_rx_h_sta_process, |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1745 | ieee80211_rx_h_defragment, |
| 1746 | ieee80211_rx_h_ps_poll, |
| 1747 | ieee80211_rx_h_michael_mic_verify, |
| 1748 | /* this must be after decryption - so header is counted in MPDU mic |
| 1749 | * must be before pae and data, so QOS_DATA format frames |
| 1750 | * are not passed to user space by these functions |
| 1751 | */ |
| 1752 | ieee80211_rx_h_remove_qos_control, |
Ron Rindjunsky | fd4c7f2 | 2007-11-26 16:14:33 +0200 | [diff] [blame] | 1753 | ieee80211_rx_h_amsdu, |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1754 | ieee80211_rx_h_data, |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 1755 | ieee80211_rx_h_ctrl, |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1756 | ieee80211_rx_h_mgmt, |
| 1757 | NULL |
| 1758 | }; |
| 1759 | |
Johannes Berg | 8944b79 | 2008-01-31 19:48:26 +0100 | [diff] [blame] | 1760 | static void ieee80211_invoke_rx_handlers(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1761 | struct ieee80211_rx_data *rx, |
Johannes Berg | 8944b79 | 2008-01-31 19:48:26 +0100 | [diff] [blame] | 1762 | struct sk_buff *skb) |
Johannes Berg | 5890529 | 2008-01-31 19:48:25 +0100 | [diff] [blame] | 1763 | { |
| 1764 | ieee80211_rx_handler *handler; |
| 1765 | ieee80211_rx_result res = RX_DROP_MONITOR; |
| 1766 | |
Johannes Berg | 8944b79 | 2008-01-31 19:48:26 +0100 | [diff] [blame] | 1767 | rx->skb = skb; |
| 1768 | rx->sdata = sdata; |
| 1769 | rx->dev = sdata->dev; |
| 1770 | |
Johannes Berg | 5890529 | 2008-01-31 19:48:25 +0100 | [diff] [blame] | 1771 | for (handler = ieee80211_rx_handlers; *handler != NULL; handler++) { |
| 1772 | res = (*handler)(rx); |
| 1773 | |
| 1774 | switch (res) { |
| 1775 | case RX_CONTINUE: |
| 1776 | continue; |
| 1777 | case RX_DROP_UNUSABLE: |
| 1778 | case RX_DROP_MONITOR: |
Johannes Berg | 8944b79 | 2008-01-31 19:48:26 +0100 | [diff] [blame] | 1779 | I802_DEBUG_INC(sdata->local->rx_handlers_drop); |
| 1780 | if (rx->sta) |
| 1781 | rx->sta->rx_dropped++; |
Johannes Berg | 5890529 | 2008-01-31 19:48:25 +0100 | [diff] [blame] | 1782 | break; |
| 1783 | case RX_QUEUED: |
Johannes Berg | 8944b79 | 2008-01-31 19:48:26 +0100 | [diff] [blame] | 1784 | I802_DEBUG_INC(sdata->local->rx_handlers_queued); |
Johannes Berg | 5890529 | 2008-01-31 19:48:25 +0100 | [diff] [blame] | 1785 | break; |
| 1786 | } |
| 1787 | break; |
| 1788 | } |
| 1789 | |
| 1790 | switch (res) { |
Johannes Berg | 5890529 | 2008-01-31 19:48:25 +0100 | [diff] [blame] | 1791 | case RX_CONTINUE: |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 1792 | case RX_DROP_MONITOR: |
| 1793 | ieee80211_rx_cooked_monitor(rx); |
| 1794 | break; |
| 1795 | case RX_DROP_UNUSABLE: |
Johannes Berg | 5890529 | 2008-01-31 19:48:25 +0100 | [diff] [blame] | 1796 | dev_kfree_skb(rx->skb); |
| 1797 | break; |
| 1798 | } |
| 1799 | } |
| 1800 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1801 | /* main receive path */ |
| 1802 | |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1803 | static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1804 | u8 *bssid, struct ieee80211_rx_data *rx, |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1805 | struct ieee80211_hdr *hdr) |
| 1806 | { |
| 1807 | int multicast = is_multicast_ether_addr(hdr->addr1); |
| 1808 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1809 | switch (sdata->vif.type) { |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1810 | case IEEE80211_IF_TYPE_STA: |
| 1811 | if (!bssid) |
| 1812 | return 0; |
| 1813 | if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) { |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1814 | if (!(rx->flags & IEEE80211_RX_IN_SCAN)) |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1815 | return 0; |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1816 | rx->flags &= ~IEEE80211_RX_RA_MATCH; |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1817 | } else if (!multicast && |
| 1818 | compare_ether_addr(sdata->dev->dev_addr, |
| 1819 | hdr->addr1) != 0) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1820 | if (!(sdata->dev->flags & IFF_PROMISC)) |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1821 | return 0; |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1822 | rx->flags &= ~IEEE80211_RX_RA_MATCH; |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1823 | } |
| 1824 | break; |
| 1825 | case IEEE80211_IF_TYPE_IBSS: |
| 1826 | if (!bssid) |
| 1827 | return 0; |
Bruno Randolf | 9d9bf77 | 2008-02-18 11:21:36 +0900 | [diff] [blame] | 1828 | if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && |
| 1829 | (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) |
| 1830 | return 1; |
| 1831 | else if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) { |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1832 | if (!(rx->flags & IEEE80211_RX_IN_SCAN)) |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1833 | return 0; |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1834 | rx->flags &= ~IEEE80211_RX_RA_MATCH; |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1835 | } else if (!multicast && |
| 1836 | compare_ether_addr(sdata->dev->dev_addr, |
| 1837 | hdr->addr1) != 0) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1838 | if (!(sdata->dev->flags & IFF_PROMISC)) |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1839 | return 0; |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1840 | rx->flags &= ~IEEE80211_RX_RA_MATCH; |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1841 | } else if (!rx->sta) |
| 1842 | rx->sta = ieee80211_ibss_add_sta(sdata->dev, rx->skb, |
| 1843 | bssid, hdr->addr2); |
| 1844 | break; |
Johannes Berg | 6032f93 | 2008-02-23 15:17:07 +0100 | [diff] [blame] | 1845 | case IEEE80211_IF_TYPE_MESH_POINT: |
| 1846 | if (!multicast && |
| 1847 | compare_ether_addr(sdata->dev->dev_addr, |
| 1848 | hdr->addr1) != 0) { |
| 1849 | if (!(sdata->dev->flags & IFF_PROMISC)) |
| 1850 | return 0; |
| 1851 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1852 | rx->flags &= ~IEEE80211_RX_RA_MATCH; |
Johannes Berg | 6032f93 | 2008-02-23 15:17:07 +0100 | [diff] [blame] | 1853 | } |
| 1854 | break; |
Johannes Berg | fb1c1cd | 2007-09-26 15:19:43 +0200 | [diff] [blame] | 1855 | case IEEE80211_IF_TYPE_VLAN: |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1856 | case IEEE80211_IF_TYPE_AP: |
| 1857 | if (!bssid) { |
| 1858 | if (compare_ether_addr(sdata->dev->dev_addr, |
| 1859 | hdr->addr1)) |
| 1860 | return 0; |
| 1861 | } else if (!ieee80211_bssid_match(bssid, |
| 1862 | sdata->dev->dev_addr)) { |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1863 | if (!(rx->flags & IEEE80211_RX_IN_SCAN)) |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1864 | return 0; |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1865 | rx->flags &= ~IEEE80211_RX_RA_MATCH; |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1866 | } |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1867 | if (sdata->dev == sdata->local->mdev && |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1868 | !(rx->flags & IEEE80211_RX_IN_SCAN)) |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1869 | /* do not receive anything via |
| 1870 | * master device when not scanning */ |
| 1871 | return 0; |
| 1872 | break; |
| 1873 | case IEEE80211_IF_TYPE_WDS: |
| 1874 | if (bssid || |
| 1875 | (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) |
| 1876 | return 0; |
| 1877 | if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2)) |
| 1878 | return 0; |
| 1879 | break; |
Johannes Berg | fb1c1cd | 2007-09-26 15:19:43 +0200 | [diff] [blame] | 1880 | case IEEE80211_IF_TYPE_MNTR: |
| 1881 | /* take everything */ |
| 1882 | break; |
Johannes Berg | a289755 | 2007-09-28 14:01:25 +0200 | [diff] [blame] | 1883 | case IEEE80211_IF_TYPE_INVALID: |
Johannes Berg | fb1c1cd | 2007-09-26 15:19:43 +0200 | [diff] [blame] | 1884 | /* should never get here */ |
| 1885 | WARN_ON(1); |
| 1886 | break; |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | return 1; |
| 1890 | } |
| 1891 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1892 | /* |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 1893 | * This is the actual Rx frames handler. as it blongs to Rx path it must |
| 1894 | * be called with rcu_read_lock protection. |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1895 | */ |
Ron Rindjunsky | 71ebb4a | 2008-01-21 12:39:12 +0200 | [diff] [blame] | 1896 | static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, |
| 1897 | struct sk_buff *skb, |
| 1898 | struct ieee80211_rx_status *status, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1899 | struct ieee80211_rate *rate) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1900 | { |
| 1901 | struct ieee80211_local *local = hw_to_local(hw); |
| 1902 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1903 | struct ieee80211_hdr *hdr; |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1904 | struct ieee80211_rx_data rx; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1905 | u16 type; |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 1906 | int prepares; |
Johannes Berg | 8e6f003 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1907 | struct ieee80211_sub_if_data *prev = NULL; |
| 1908 | struct sk_buff *skb_new; |
| 1909 | u8 *bssid; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1910 | |
| 1911 | hdr = (struct ieee80211_hdr *) skb->data; |
| 1912 | memset(&rx, 0, sizeof(rx)); |
| 1913 | rx.skb = skb; |
| 1914 | rx.local = local; |
| 1915 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1916 | rx.status = status; |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1917 | rx.rate = rate; |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 1918 | rx.fc = le16_to_cpu(hdr->frame_control); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1919 | type = rx.fc & IEEE80211_FCTL_FTYPE; |
Johannes Berg | 72abd81 | 2007-09-17 01:29:22 -0400 | [diff] [blame] | 1920 | |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 1921 | if (type == IEEE80211_FTYPE_DATA || type == IEEE80211_FTYPE_MGMT) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1922 | local->dot11ReceivedFragmentCount++; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1923 | |
Johannes Berg | 8944b79 | 2008-01-31 19:48:26 +0100 | [diff] [blame] | 1924 | rx.sta = sta_info_get(local, hdr->addr2); |
| 1925 | if (rx.sta) { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1926 | rx.sdata = rx.sta->sdata; |
| 1927 | rx.dev = rx.sta->sdata->dev; |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 1928 | } |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1929 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1930 | if ((status->flag & RX_FLAG_MMIC_ERROR)) { |
Johannes Berg | 8944b79 | 2008-01-31 19:48:26 +0100 | [diff] [blame] | 1931 | ieee80211_rx_michael_mic_report(local->mdev, hdr, &rx); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1932 | return; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1933 | } |
| 1934 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 1935 | if (unlikely(local->sta_sw_scanning || local->sta_hw_scanning)) |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1936 | rx.flags |= IEEE80211_RX_IN_SCAN; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1937 | |
Johannes Berg | 38f3714 | 2008-01-29 17:07:43 +0100 | [diff] [blame] | 1938 | ieee80211_parse_qos(&rx); |
| 1939 | ieee80211_verify_ip_alignment(&rx); |
| 1940 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1941 | skb = rx.skb; |
| 1942 | |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 1943 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
Johannes Berg | 2a8a9a8 | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 1944 | if (!netif_running(sdata->dev)) |
| 1945 | continue; |
| 1946 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1947 | if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR) |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 1948 | continue; |
| 1949 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1950 | bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type); |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1951 | rx.flags |= IEEE80211_RX_RA_MATCH; |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 1952 | prepares = prepare_for_handlers(sdata, bssid, &rx, hdr); |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1953 | |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 1954 | if (!prepares) |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1955 | continue; |
Johannes Berg | 8e6f003 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1956 | |
Johannes Berg | 340e11f | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1957 | /* |
| 1958 | * frame is destined for this interface, but if it's not |
| 1959 | * also for the previous one we handle that after the |
| 1960 | * loop to avoid copying the SKB once too much |
| 1961 | */ |
| 1962 | |
| 1963 | if (!prev) { |
| 1964 | prev = sdata; |
| 1965 | continue; |
Johannes Berg | 8e6f003 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1966 | } |
Johannes Berg | 340e11f | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1967 | |
| 1968 | /* |
| 1969 | * frame was destined for the previous interface |
| 1970 | * so invoke RX handlers for it |
| 1971 | */ |
| 1972 | |
| 1973 | skb_new = skb_copy(skb, GFP_ATOMIC); |
| 1974 | if (!skb_new) { |
| 1975 | if (net_ratelimit()) |
| 1976 | printk(KERN_DEBUG "%s: failed to copy " |
Pavel Roskin | a4278e1 | 2008-05-12 09:02:24 -0400 | [diff] [blame] | 1977 | "multicast frame for %s\n", |
Johannes Berg | dd1cd4c | 2007-09-18 17:29:20 -0400 | [diff] [blame] | 1978 | wiphy_name(local->hw.wiphy), |
| 1979 | prev->dev->name); |
Johannes Berg | 340e11f | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1980 | continue; |
| 1981 | } |
Helmut Schaa | 69f817b | 2007-12-21 15:16:35 +0100 | [diff] [blame] | 1982 | rx.fc = le16_to_cpu(hdr->frame_control); |
Johannes Berg | 8944b79 | 2008-01-31 19:48:26 +0100 | [diff] [blame] | 1983 | ieee80211_invoke_rx_handlers(prev, &rx, skb_new); |
Johannes Berg | 8e6f003 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1984 | prev = sdata; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1985 | } |
Johannes Berg | 8e6f003 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1986 | if (prev) { |
Helmut Schaa | 69f817b | 2007-12-21 15:16:35 +0100 | [diff] [blame] | 1987 | rx.fc = le16_to_cpu(hdr->frame_control); |
Johannes Berg | 8944b79 | 2008-01-31 19:48:26 +0100 | [diff] [blame] | 1988 | ieee80211_invoke_rx_handlers(prev, &rx, skb); |
Johannes Berg | 8e6f003 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1989 | } else |
| 1990 | dev_kfree_skb(skb); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1991 | } |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 1992 | |
Ron Rindjunsky | b580781 | 2007-12-25 17:00:35 +0200 | [diff] [blame] | 1993 | #define SEQ_MODULO 0x1000 |
| 1994 | #define SEQ_MASK 0xfff |
| 1995 | |
| 1996 | static inline int seq_less(u16 sq1, u16 sq2) |
| 1997 | { |
| 1998 | return (((sq1 - sq2) & SEQ_MASK) > (SEQ_MODULO >> 1)); |
| 1999 | } |
| 2000 | |
| 2001 | static inline u16 seq_inc(u16 sq) |
| 2002 | { |
| 2003 | return ((sq + 1) & SEQ_MASK); |
| 2004 | } |
| 2005 | |
| 2006 | static inline u16 seq_sub(u16 sq1, u16 sq2) |
| 2007 | { |
| 2008 | return ((sq1 - sq2) & SEQ_MASK); |
| 2009 | } |
| 2010 | |
| 2011 | |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 2012 | /* |
| 2013 | * As it function blongs to Rx path it must be called with |
| 2014 | * the proper rcu_read_lock protection for its flow. |
| 2015 | */ |
Ron Rindjunsky | b580781 | 2007-12-25 17:00:35 +0200 | [diff] [blame] | 2016 | u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw, |
| 2017 | struct tid_ampdu_rx *tid_agg_rx, |
| 2018 | struct sk_buff *skb, u16 mpdu_seq_num, |
| 2019 | int bar_req) |
| 2020 | { |
| 2021 | struct ieee80211_local *local = hw_to_local(hw); |
| 2022 | struct ieee80211_rx_status status; |
| 2023 | u16 head_seq_num, buf_size; |
| 2024 | int index; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2025 | struct ieee80211_supported_band *sband; |
| 2026 | struct ieee80211_rate *rate; |
Ron Rindjunsky | b580781 | 2007-12-25 17:00:35 +0200 | [diff] [blame] | 2027 | |
| 2028 | buf_size = tid_agg_rx->buf_size; |
| 2029 | head_seq_num = tid_agg_rx->head_seq_num; |
| 2030 | |
| 2031 | /* frame with out of date sequence number */ |
| 2032 | if (seq_less(mpdu_seq_num, head_seq_num)) { |
| 2033 | dev_kfree_skb(skb); |
| 2034 | return 1; |
| 2035 | } |
| 2036 | |
| 2037 | /* if frame sequence number exceeds our buffering window size or |
| 2038 | * block Ack Request arrived - release stored frames */ |
| 2039 | if ((!seq_less(mpdu_seq_num, head_seq_num + buf_size)) || (bar_req)) { |
| 2040 | /* new head to the ordering buffer */ |
| 2041 | if (bar_req) |
| 2042 | head_seq_num = mpdu_seq_num; |
| 2043 | else |
| 2044 | head_seq_num = |
| 2045 | seq_inc(seq_sub(mpdu_seq_num, buf_size)); |
| 2046 | /* release stored frames up to new head to stack */ |
| 2047 | while (seq_less(tid_agg_rx->head_seq_num, head_seq_num)) { |
| 2048 | index = seq_sub(tid_agg_rx->head_seq_num, |
| 2049 | tid_agg_rx->ssn) |
| 2050 | % tid_agg_rx->buf_size; |
| 2051 | |
| 2052 | if (tid_agg_rx->reorder_buf[index]) { |
| 2053 | /* release the reordered frames to stack */ |
| 2054 | memcpy(&status, |
| 2055 | tid_agg_rx->reorder_buf[index]->cb, |
| 2056 | sizeof(status)); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2057 | sband = local->hw.wiphy->bands[status.band]; |
| 2058 | rate = &sband->bitrates[status.rate_idx]; |
Ron Rindjunsky | b580781 | 2007-12-25 17:00:35 +0200 | [diff] [blame] | 2059 | __ieee80211_rx_handle_packet(hw, |
| 2060 | tid_agg_rx->reorder_buf[index], |
Johannes Berg | 9e72ebd | 2008-05-21 17:33:42 +0200 | [diff] [blame^] | 2061 | &status, rate); |
Ron Rindjunsky | b580781 | 2007-12-25 17:00:35 +0200 | [diff] [blame] | 2062 | tid_agg_rx->stored_mpdu_num--; |
| 2063 | tid_agg_rx->reorder_buf[index] = NULL; |
| 2064 | } |
| 2065 | tid_agg_rx->head_seq_num = |
| 2066 | seq_inc(tid_agg_rx->head_seq_num); |
| 2067 | } |
| 2068 | if (bar_req) |
| 2069 | return 1; |
| 2070 | } |
| 2071 | |
| 2072 | /* now the new frame is always in the range of the reordering */ |
| 2073 | /* buffer window */ |
| 2074 | index = seq_sub(mpdu_seq_num, tid_agg_rx->ssn) |
| 2075 | % tid_agg_rx->buf_size; |
| 2076 | /* check if we already stored this frame */ |
| 2077 | if (tid_agg_rx->reorder_buf[index]) { |
| 2078 | dev_kfree_skb(skb); |
| 2079 | return 1; |
| 2080 | } |
| 2081 | |
| 2082 | /* if arrived mpdu is in the right order and nothing else stored */ |
| 2083 | /* release it immediately */ |
| 2084 | if (mpdu_seq_num == tid_agg_rx->head_seq_num && |
| 2085 | tid_agg_rx->stored_mpdu_num == 0) { |
| 2086 | tid_agg_rx->head_seq_num = |
| 2087 | seq_inc(tid_agg_rx->head_seq_num); |
| 2088 | return 0; |
| 2089 | } |
| 2090 | |
| 2091 | /* put the frame in the reordering buffer */ |
| 2092 | tid_agg_rx->reorder_buf[index] = skb; |
| 2093 | tid_agg_rx->stored_mpdu_num++; |
| 2094 | /* release the buffer until next missing frame */ |
| 2095 | index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) |
| 2096 | % tid_agg_rx->buf_size; |
| 2097 | while (tid_agg_rx->reorder_buf[index]) { |
| 2098 | /* release the reordered frame back to stack */ |
| 2099 | memcpy(&status, tid_agg_rx->reorder_buf[index]->cb, |
| 2100 | sizeof(status)); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2101 | sband = local->hw.wiphy->bands[status.band]; |
| 2102 | rate = &sband->bitrates[status.rate_idx]; |
Ron Rindjunsky | b580781 | 2007-12-25 17:00:35 +0200 | [diff] [blame] | 2103 | __ieee80211_rx_handle_packet(hw, tid_agg_rx->reorder_buf[index], |
Johannes Berg | 9e72ebd | 2008-05-21 17:33:42 +0200 | [diff] [blame^] | 2104 | &status, rate); |
Ron Rindjunsky | b580781 | 2007-12-25 17:00:35 +0200 | [diff] [blame] | 2105 | tid_agg_rx->stored_mpdu_num--; |
| 2106 | tid_agg_rx->reorder_buf[index] = NULL; |
| 2107 | tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num); |
| 2108 | index = seq_sub(tid_agg_rx->head_seq_num, |
| 2109 | tid_agg_rx->ssn) % tid_agg_rx->buf_size; |
| 2110 | } |
| 2111 | return 1; |
| 2112 | } |
| 2113 | |
Ron Rindjunsky | 71ebb4a | 2008-01-21 12:39:12 +0200 | [diff] [blame] | 2114 | static u8 ieee80211_rx_reorder_ampdu(struct ieee80211_local *local, |
| 2115 | struct sk_buff *skb) |
Ron Rindjunsky | b580781 | 2007-12-25 17:00:35 +0200 | [diff] [blame] | 2116 | { |
| 2117 | struct ieee80211_hw *hw = &local->hw; |
| 2118 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 2119 | struct sta_info *sta; |
| 2120 | struct tid_ampdu_rx *tid_agg_rx; |
| 2121 | u16 fc, sc; |
| 2122 | u16 mpdu_seq_num; |
| 2123 | u8 ret = 0, *qc; |
| 2124 | int tid; |
| 2125 | |
| 2126 | sta = sta_info_get(local, hdr->addr2); |
| 2127 | if (!sta) |
| 2128 | return ret; |
| 2129 | |
| 2130 | fc = le16_to_cpu(hdr->frame_control); |
| 2131 | |
| 2132 | /* filter the QoS data rx stream according to |
| 2133 | * STA/TID and check if this STA/TID is on aggregation */ |
| 2134 | if (!WLAN_FC_IS_QOS_DATA(fc)) |
| 2135 | goto end_reorder; |
| 2136 | |
| 2137 | qc = skb->data + ieee80211_get_hdrlen(fc) - QOS_CONTROL_LEN; |
| 2138 | tid = qc[0] & QOS_CONTROL_TID_MASK; |
Ron Rindjunsky | b580781 | 2007-12-25 17:00:35 +0200 | [diff] [blame] | 2139 | |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 2140 | if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_OPERATIONAL) |
Ron Rindjunsky | b580781 | 2007-12-25 17:00:35 +0200 | [diff] [blame] | 2141 | goto end_reorder; |
| 2142 | |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 2143 | tid_agg_rx = sta->ampdu_mlme.tid_rx[tid]; |
| 2144 | |
Ron Rindjunsky | b580781 | 2007-12-25 17:00:35 +0200 | [diff] [blame] | 2145 | /* null data frames are excluded */ |
Ron Rindjunsky | 8b6bbe7 | 2008-01-23 18:17:13 +0200 | [diff] [blame] | 2146 | if (unlikely(fc & IEEE80211_STYPE_NULLFUNC)) |
Ron Rindjunsky | b580781 | 2007-12-25 17:00:35 +0200 | [diff] [blame] | 2147 | goto end_reorder; |
| 2148 | |
| 2149 | /* new un-ordered ampdu frame - process it */ |
| 2150 | |
| 2151 | /* reset session timer */ |
| 2152 | if (tid_agg_rx->timeout) { |
| 2153 | unsigned long expires = |
| 2154 | jiffies + (tid_agg_rx->timeout / 1000) * HZ; |
| 2155 | mod_timer(&tid_agg_rx->session_timer, expires); |
| 2156 | } |
| 2157 | |
| 2158 | /* if this mpdu is fragmented - terminate rx aggregation session */ |
| 2159 | sc = le16_to_cpu(hdr->seq_ctrl); |
| 2160 | if (sc & IEEE80211_SCTL_FRAG) { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 2161 | ieee80211_sta_stop_rx_ba_session(sta->sdata->dev, sta->addr, |
Ron Rindjunsky | b580781 | 2007-12-25 17:00:35 +0200 | [diff] [blame] | 2162 | tid, 0, WLAN_REASON_QSTA_REQUIRE_SETUP); |
| 2163 | ret = 1; |
| 2164 | goto end_reorder; |
| 2165 | } |
| 2166 | |
| 2167 | /* according to mpdu sequence number deal with reordering buffer */ |
| 2168 | mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 2169 | ret = ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb, |
| 2170 | mpdu_seq_num, 0); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 2171 | end_reorder: |
Ron Rindjunsky | b580781 | 2007-12-25 17:00:35 +0200 | [diff] [blame] | 2172 | return ret; |
| 2173 | } |
| 2174 | |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 2175 | /* |
| 2176 | * This is the receive path handler. It is called by a low level driver when an |
| 2177 | * 802.11 MPDU is received from the hardware. |
| 2178 | */ |
| 2179 | void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb, |
| 2180 | struct ieee80211_rx_status *status) |
| 2181 | { |
| 2182 | struct ieee80211_local *local = hw_to_local(hw); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2183 | struct ieee80211_rate *rate = NULL; |
| 2184 | struct ieee80211_supported_band *sband; |
| 2185 | |
| 2186 | if (status->band < 0 || |
Adrian Bunk | 13d8fd2 | 2008-04-23 12:51:28 +0300 | [diff] [blame] | 2187 | status->band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2188 | WARN_ON(1); |
| 2189 | return; |
| 2190 | } |
| 2191 | |
| 2192 | sband = local->hw.wiphy->bands[status->band]; |
| 2193 | |
| 2194 | if (!sband || |
| 2195 | status->rate_idx < 0 || |
| 2196 | status->rate_idx >= sband->n_bitrates) { |
| 2197 | WARN_ON(1); |
| 2198 | return; |
| 2199 | } |
| 2200 | |
| 2201 | rate = &sband->bitrates[status->rate_idx]; |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 2202 | |
| 2203 | /* |
| 2204 | * key references and virtual interfaces are protected using RCU |
| 2205 | * and this requires that we are in a read-side RCU section during |
| 2206 | * receive processing |
| 2207 | */ |
| 2208 | rcu_read_lock(); |
| 2209 | |
| 2210 | /* |
| 2211 | * Frames with failed FCS/PLCP checksum are not returned, |
| 2212 | * all other frames are returned without radiotap header |
| 2213 | * if it was previously present. |
| 2214 | * Also, frames with less than 16 bytes are dropped. |
| 2215 | */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2216 | skb = ieee80211_rx_monitor(local, skb, status, rate); |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 2217 | if (!skb) { |
| 2218 | rcu_read_unlock(); |
| 2219 | return; |
| 2220 | } |
| 2221 | |
Ron Rindjunsky | b580781 | 2007-12-25 17:00:35 +0200 | [diff] [blame] | 2222 | if (!ieee80211_rx_reorder_ampdu(local, skb)) |
Johannes Berg | 9e72ebd | 2008-05-21 17:33:42 +0200 | [diff] [blame^] | 2223 | __ieee80211_rx_handle_packet(hw, skb, status, rate); |
Ron Rindjunsky | 6368e4b | 2007-12-24 13:36:39 +0200 | [diff] [blame] | 2224 | |
| 2225 | rcu_read_unlock(); |
| 2226 | } |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2227 | EXPORT_SYMBOL(__ieee80211_rx); |
| 2228 | |
| 2229 | /* This is a version of the rx handler that can be called from hard irq |
| 2230 | * context. Post the skb on the queue and schedule the tasklet */ |
| 2231 | void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb, |
| 2232 | struct ieee80211_rx_status *status) |
| 2233 | { |
| 2234 | struct ieee80211_local *local = hw_to_local(hw); |
| 2235 | |
| 2236 | BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb)); |
| 2237 | |
| 2238 | skb->dev = local->mdev; |
| 2239 | /* copy status into skb->cb for use by tasklet */ |
| 2240 | memcpy(skb->cb, status, sizeof(*status)); |
| 2241 | skb->pkt_type = IEEE80211_RX_MSG; |
| 2242 | skb_queue_tail(&local->skb_queue, skb); |
| 2243 | tasklet_schedule(&local->tasklet); |
| 2244 | } |
| 2245 | EXPORT_SYMBOL(ieee80211_rx_irqsafe); |