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 | |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/skbuff.h> |
| 14 | #include <linux/netdevice.h> |
| 15 | #include <linux/etherdevice.h> |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 16 | #include <linux/rcupdate.h> |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 17 | #include <net/mac80211.h> |
| 18 | #include <net/ieee80211_radiotap.h> |
| 19 | |
| 20 | #include "ieee80211_i.h" |
| 21 | #include "ieee80211_led.h" |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 22 | #include "wep.h" |
| 23 | #include "wpa.h" |
| 24 | #include "tkip.h" |
| 25 | #include "wme.h" |
| 26 | |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 27 | /* |
| 28 | * monitor mode reception |
| 29 | * |
| 30 | * This function cleans up the SKB, i.e. it removes all the stuff |
| 31 | * only useful for monitoring. |
| 32 | */ |
| 33 | static struct sk_buff *remove_monitor_info(struct ieee80211_local *local, |
| 34 | struct sk_buff *skb, |
| 35 | int rtap_len) |
| 36 | { |
| 37 | skb_pull(skb, rtap_len); |
| 38 | |
| 39 | if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) { |
| 40 | if (likely(skb->len > FCS_LEN)) |
| 41 | skb_trim(skb, skb->len - FCS_LEN); |
| 42 | else { |
| 43 | /* driver bug */ |
| 44 | WARN_ON(1); |
| 45 | dev_kfree_skb(skb); |
| 46 | skb = NULL; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | return skb; |
| 51 | } |
| 52 | |
| 53 | static inline int should_drop_frame(struct ieee80211_rx_status *status, |
| 54 | struct sk_buff *skb, |
| 55 | int present_fcs_len, |
| 56 | int radiotap_len) |
| 57 | { |
| 58 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 59 | |
| 60 | if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC)) |
| 61 | return 1; |
| 62 | if (unlikely(skb->len < 16 + present_fcs_len + radiotap_len)) |
| 63 | return 1; |
| 64 | if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FTYPE)) == |
| 65 | cpu_to_le16(IEEE80211_FTYPE_CTL)) |
| 66 | return 1; |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | /* |
| 71 | * This function copies a received frame to all monitor interfaces and |
| 72 | * returns a cleaned-up SKB that no longer includes the FCS nor the |
| 73 | * radiotap header the driver might have added. |
| 74 | */ |
| 75 | static struct sk_buff * |
| 76 | ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb, |
| 77 | struct ieee80211_rx_status *status) |
| 78 | { |
| 79 | struct ieee80211_sub_if_data *sdata; |
| 80 | struct ieee80211_rate *rate; |
| 81 | int needed_headroom = 0; |
| 82 | struct ieee80211_rtap_hdr { |
| 83 | struct ieee80211_radiotap_header hdr; |
| 84 | u8 flags; |
| 85 | u8 rate; |
| 86 | __le16 chan_freq; |
| 87 | __le16 chan_flags; |
| 88 | u8 antsignal; |
| 89 | u8 padding_for_rxflags; |
| 90 | __le16 rx_flags; |
| 91 | } __attribute__ ((packed)) *rthdr; |
| 92 | struct sk_buff *skb, *skb2; |
| 93 | struct net_device *prev_dev = NULL; |
| 94 | int present_fcs_len = 0; |
| 95 | int rtap_len = 0; |
| 96 | |
| 97 | /* |
| 98 | * First, we may need to make a copy of the skb because |
| 99 | * (1) we need to modify it for radiotap (if not present), and |
| 100 | * (2) the other RX handlers will modify the skb we got. |
| 101 | * |
| 102 | * We don't need to, of course, if we aren't going to return |
| 103 | * the SKB because it has a bad FCS/PLCP checksum. |
| 104 | */ |
| 105 | if (status->flag & RX_FLAG_RADIOTAP) |
| 106 | rtap_len = ieee80211_get_radiotap_len(origskb->data); |
| 107 | else |
| 108 | needed_headroom = sizeof(*rthdr); |
| 109 | |
| 110 | if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) |
| 111 | present_fcs_len = FCS_LEN; |
| 112 | |
| 113 | if (!local->monitors) { |
| 114 | if (should_drop_frame(status, origskb, present_fcs_len, |
| 115 | rtap_len)) { |
| 116 | dev_kfree_skb(origskb); |
| 117 | return NULL; |
| 118 | } |
| 119 | |
| 120 | return remove_monitor_info(local, origskb, rtap_len); |
| 121 | } |
| 122 | |
| 123 | if (should_drop_frame(status, origskb, present_fcs_len, rtap_len)) { |
| 124 | /* only need to expand headroom if necessary */ |
| 125 | skb = origskb; |
| 126 | origskb = NULL; |
| 127 | |
| 128 | /* |
| 129 | * This shouldn't trigger often because most devices have an |
| 130 | * RX header they pull before we get here, and that should |
| 131 | * be big enough for our radiotap information. We should |
| 132 | * probably export the length to drivers so that we can have |
| 133 | * them allocate enough headroom to start with. |
| 134 | */ |
| 135 | if (skb_headroom(skb) < needed_headroom && |
| 136 | pskb_expand_head(skb, sizeof(*rthdr), 0, GFP_ATOMIC)) { |
| 137 | dev_kfree_skb(skb); |
| 138 | return NULL; |
| 139 | } |
| 140 | } else { |
| 141 | /* |
| 142 | * Need to make a copy and possibly remove radiotap header |
| 143 | * and FCS from the original. |
| 144 | */ |
| 145 | skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC); |
| 146 | |
| 147 | origskb = remove_monitor_info(local, origskb, rtap_len); |
| 148 | |
| 149 | if (!skb) |
| 150 | return origskb; |
| 151 | } |
| 152 | |
| 153 | /* if necessary, prepend radiotap information */ |
| 154 | if (!(status->flag & RX_FLAG_RADIOTAP)) { |
| 155 | rthdr = (void *) skb_push(skb, sizeof(*rthdr)); |
| 156 | memset(rthdr, 0, sizeof(*rthdr)); |
| 157 | rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr)); |
| 158 | rthdr->hdr.it_present = |
| 159 | cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) | |
| 160 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 161 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 162 | (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) | |
| 163 | (1 << IEEE80211_RADIOTAP_RX_FLAGS)); |
| 164 | rthdr->flags = local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS ? |
| 165 | IEEE80211_RADIOTAP_F_FCS : 0; |
| 166 | |
| 167 | /* FIXME: when radiotap gets a 'bad PLCP' flag use it here */ |
| 168 | rthdr->rx_flags = 0; |
| 169 | if (status->flag & |
| 170 | (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC)) |
| 171 | rthdr->rx_flags |= |
| 172 | cpu_to_le16(IEEE80211_RADIOTAP_F_RX_BADFCS); |
| 173 | |
| 174 | rate = ieee80211_get_rate(local, status->phymode, |
| 175 | status->rate); |
| 176 | if (rate) |
| 177 | rthdr->rate = rate->rate / 5; |
| 178 | |
| 179 | rthdr->chan_freq = cpu_to_le16(status->freq); |
| 180 | |
| 181 | if (status->phymode == MODE_IEEE80211A) |
| 182 | rthdr->chan_flags = |
| 183 | cpu_to_le16(IEEE80211_CHAN_OFDM | |
| 184 | IEEE80211_CHAN_5GHZ); |
| 185 | else |
| 186 | rthdr->chan_flags = |
| 187 | cpu_to_le16(IEEE80211_CHAN_DYN | |
| 188 | IEEE80211_CHAN_2GHZ); |
| 189 | |
| 190 | rthdr->antsignal = status->ssi; |
| 191 | } |
| 192 | |
| 193 | skb_set_mac_header(skb, 0); |
| 194 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 195 | skb->pkt_type = PACKET_OTHERHOST; |
| 196 | skb->protocol = htons(ETH_P_802_2); |
| 197 | |
| 198 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
| 199 | if (!netif_running(sdata->dev)) |
| 200 | continue; |
| 201 | |
| 202 | if (sdata->type != IEEE80211_IF_TYPE_MNTR) |
| 203 | continue; |
| 204 | |
| 205 | if (prev_dev) { |
| 206 | skb2 = skb_clone(skb, GFP_ATOMIC); |
| 207 | if (skb2) { |
| 208 | skb2->dev = prev_dev; |
| 209 | netif_rx(skb2); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | prev_dev = sdata->dev; |
| 214 | sdata->dev->stats.rx_packets++; |
| 215 | sdata->dev->stats.rx_bytes += skb->len; |
| 216 | } |
| 217 | |
| 218 | if (prev_dev) { |
| 219 | skb->dev = prev_dev; |
| 220 | netif_rx(skb); |
| 221 | } else |
| 222 | dev_kfree_skb(skb); |
| 223 | |
| 224 | return origskb; |
| 225 | } |
| 226 | |
| 227 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 228 | /* pre-rx handlers |
| 229 | * |
| 230 | * these don't have dev/sdata fields in the rx data |
Johannes Berg | 52865df | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 231 | * The sta value should also not be used because it may |
| 232 | * be NULL even though a STA (in IBSS mode) will be added. |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 233 | */ |
| 234 | |
| 235 | static ieee80211_txrx_result |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 236 | ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx) |
| 237 | { |
| 238 | u8 *data = rx->skb->data; |
| 239 | int tid; |
| 240 | |
| 241 | /* does the frame have a qos control field? */ |
| 242 | if (WLAN_FC_IS_QOS_DATA(rx->fc)) { |
| 243 | u8 *qc = data + ieee80211_get_hdrlen(rx->fc) - QOS_CONTROL_LEN; |
| 244 | /* frame has qos control */ |
| 245 | tid = qc[0] & QOS_CONTROL_TID_MASK; |
| 246 | } else { |
| 247 | if (unlikely((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)) { |
| 248 | /* Separate TID for management frames */ |
| 249 | tid = NUM_RX_DATA_QUEUES - 1; |
| 250 | } else { |
| 251 | /* no qos control present */ |
| 252 | tid = 0; /* 802.1d - Best Effort */ |
| 253 | } |
| 254 | } |
Johannes Berg | 52865df | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 255 | |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 256 | I802_DEBUG_INC(rx->local->wme_rx_queue[tid]); |
Johannes Berg | 52865df | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 257 | /* only a debug counter, sta might not be assigned properly yet */ |
| 258 | if (rx->sta) |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 259 | I802_DEBUG_INC(rx->sta->wme_rx_queue[tid]); |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 260 | |
| 261 | rx->u.rx.queue = tid; |
| 262 | /* Set skb->priority to 1d tag if highest order bit of TID is not set. |
| 263 | * For now, set skb->priority to 0 for other cases. */ |
| 264 | rx->skb->priority = (tid > 7) ? 0 : tid; |
| 265 | |
| 266 | return TXRX_CONTINUE; |
| 267 | } |
| 268 | |
| 269 | static ieee80211_txrx_result |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 270 | ieee80211_rx_h_load_stats(struct ieee80211_txrx_data *rx) |
| 271 | { |
| 272 | struct ieee80211_local *local = rx->local; |
| 273 | struct sk_buff *skb = rx->skb; |
| 274 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 275 | u32 load = 0, hdrtime; |
| 276 | struct ieee80211_rate *rate; |
| 277 | struct ieee80211_hw_mode *mode = local->hw.conf.mode; |
| 278 | int i; |
| 279 | |
| 280 | /* Estimate total channel use caused by this frame */ |
| 281 | |
| 282 | if (unlikely(mode->num_rates < 0)) |
| 283 | return TXRX_CONTINUE; |
| 284 | |
| 285 | rate = &mode->rates[0]; |
| 286 | for (i = 0; i < mode->num_rates; i++) { |
| 287 | if (mode->rates[i].val == rx->u.rx.status->rate) { |
| 288 | rate = &mode->rates[i]; |
| 289 | break; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values, |
| 294 | * 1 usec = 1/8 * (1080 / 10) = 13.5 */ |
| 295 | |
| 296 | if (mode->mode == MODE_IEEE80211A || |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 297 | (mode->mode == MODE_IEEE80211G && |
| 298 | rate->flags & IEEE80211_RATE_ERP)) |
| 299 | hdrtime = CHAN_UTIL_HDR_SHORT; |
| 300 | else |
| 301 | hdrtime = CHAN_UTIL_HDR_LONG; |
| 302 | |
| 303 | load = hdrtime; |
| 304 | if (!is_multicast_ether_addr(hdr->addr1)) |
| 305 | load += hdrtime; |
| 306 | |
| 307 | load += skb->len * rate->rate_inv; |
| 308 | |
| 309 | /* Divide channel_use by 8 to avoid wrapping around the counter */ |
| 310 | load >>= CHAN_UTIL_SHIFT; |
| 311 | local->channel_use_raw += load; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 312 | rx->u.rx.load = load; |
| 313 | |
| 314 | return TXRX_CONTINUE; |
| 315 | } |
| 316 | |
| 317 | ieee80211_rx_handler ieee80211_rx_pre_handlers[] = |
| 318 | { |
| 319 | ieee80211_rx_h_parse_qos, |
| 320 | ieee80211_rx_h_load_stats, |
| 321 | NULL |
| 322 | }; |
| 323 | |
| 324 | /* rx handlers */ |
| 325 | |
| 326 | static ieee80211_txrx_result |
| 327 | ieee80211_rx_h_if_stats(struct ieee80211_txrx_data *rx) |
| 328 | { |
Johannes Berg | 52865df | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 329 | if (rx->sta) |
| 330 | rx->sta->channel_use_raw += rx->u.rx.load; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 331 | rx->sdata->channel_use_raw += rx->u.rx.load; |
| 332 | return TXRX_CONTINUE; |
| 333 | } |
| 334 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 335 | static ieee80211_txrx_result |
| 336 | ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data *rx) |
| 337 | { |
| 338 | struct ieee80211_local *local = rx->local; |
| 339 | struct sk_buff *skb = rx->skb; |
| 340 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 341 | if (unlikely(local->sta_hw_scanning)) |
| 342 | return ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status); |
| 343 | |
| 344 | if (unlikely(local->sta_sw_scanning)) { |
| 345 | /* drop all the other packets during a software scan anyway */ |
| 346 | if (ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status) |
| 347 | != TXRX_QUEUED) |
| 348 | dev_kfree_skb(skb); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 349 | return TXRX_QUEUED; |
| 350 | } |
| 351 | |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 352 | if (unlikely(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 353 | /* scanning finished during invoking of handlers */ |
| 354 | I802_DEBUG_INC(local->rx_handlers_drop_passive_scan); |
| 355 | return TXRX_DROP; |
| 356 | } |
| 357 | |
| 358 | return TXRX_CONTINUE; |
| 359 | } |
| 360 | |
| 361 | static ieee80211_txrx_result |
| 362 | ieee80211_rx_h_check(struct ieee80211_txrx_data *rx) |
| 363 | { |
| 364 | struct ieee80211_hdr *hdr; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 365 | hdr = (struct ieee80211_hdr *) rx->skb->data; |
| 366 | |
| 367 | /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */ |
| 368 | if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) { |
| 369 | if (unlikely(rx->fc & IEEE80211_FCTL_RETRY && |
| 370 | rx->sta->last_seq_ctrl[rx->u.rx.queue] == |
| 371 | hdr->seq_ctrl)) { |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 372 | if (rx->flags & IEEE80211_TXRXD_RXRA_MATCH) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 373 | rx->local->dot11FrameDuplicateCount++; |
| 374 | rx->sta->num_duplicates++; |
| 375 | } |
| 376 | return TXRX_DROP; |
| 377 | } else |
| 378 | rx->sta->last_seq_ctrl[rx->u.rx.queue] = hdr->seq_ctrl; |
| 379 | } |
| 380 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 381 | if (unlikely(rx->skb->len < 16)) { |
| 382 | I802_DEBUG_INC(rx->local->rx_handlers_drop_short); |
| 383 | return TXRX_DROP; |
| 384 | } |
| 385 | |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 386 | if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 387 | rx->skb->pkt_type = PACKET_OTHERHOST; |
| 388 | else if (compare_ether_addr(rx->dev->dev_addr, hdr->addr1) == 0) |
| 389 | rx->skb->pkt_type = PACKET_HOST; |
| 390 | else if (is_multicast_ether_addr(hdr->addr1)) { |
| 391 | if (is_broadcast_ether_addr(hdr->addr1)) |
| 392 | rx->skb->pkt_type = PACKET_BROADCAST; |
| 393 | else |
| 394 | rx->skb->pkt_type = PACKET_MULTICAST; |
| 395 | } else |
| 396 | rx->skb->pkt_type = PACKET_OTHERHOST; |
| 397 | |
| 398 | /* Drop disallowed frame classes based on STA auth/assoc state; |
| 399 | * IEEE 802.11, Chap 5.5. |
| 400 | * |
| 401 | * 80211.o does filtering only based on association state, i.e., it |
| 402 | * drops Class 3 frames from not associated stations. hostapd sends |
| 403 | * deauth/disassoc frames when needed. In addition, hostapd is |
| 404 | * responsible for filtering on both auth and assoc states. |
| 405 | */ |
| 406 | if (unlikely(((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA || |
| 407 | ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL && |
| 408 | (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)) && |
| 409 | rx->sdata->type != IEEE80211_IF_TYPE_IBSS && |
| 410 | (!rx->sta || !(rx->sta->flags & WLAN_STA_ASSOC)))) { |
| 411 | if ((!(rx->fc & IEEE80211_FCTL_FROMDS) && |
| 412 | !(rx->fc & IEEE80211_FCTL_TODS) && |
| 413 | (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 414 | || !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 415 | /* Drop IBSS frames and frames for other hosts |
| 416 | * silently. */ |
| 417 | return TXRX_DROP; |
| 418 | } |
| 419 | |
Johannes Berg | f9d540e | 2007-09-28 14:02:09 +0200 | [diff] [blame] | 420 | return TXRX_DROP; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 421 | } |
| 422 | |
Johannes Berg | 570bd53 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 423 | return TXRX_CONTINUE; |
| 424 | } |
| 425 | |
| 426 | |
| 427 | static ieee80211_txrx_result |
Johannes Berg | 1990af8 | 2007-09-26 17:53:15 +0200 | [diff] [blame] | 428 | ieee80211_rx_h_decrypt(struct ieee80211_txrx_data *rx) |
Johannes Berg | 570bd53 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 429 | { |
| 430 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 431 | int keyidx; |
| 432 | int hdrlen; |
Mattias Nissler | e2f036d | 2007-10-07 16:35:31 +0200 | [diff] [blame] | 433 | ieee80211_txrx_result result = TXRX_DROP; |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 434 | struct ieee80211_key *stakey = NULL; |
Johannes Berg | 570bd53 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 435 | |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 436 | /* |
| 437 | * Key selection 101 |
| 438 | * |
| 439 | * There are three types of keys: |
| 440 | * - GTK (group keys) |
| 441 | * - PTK (pairwise keys) |
| 442 | * - STK (station-to-station pairwise keys) |
| 443 | * |
| 444 | * When selecting a key, we have to distinguish between multicast |
| 445 | * (including broadcast) and unicast frames, the latter can only |
| 446 | * use PTKs and STKs while the former always use GTKs. Unless, of |
| 447 | * course, actual WEP keys ("pre-RSNA") are used, then unicast |
| 448 | * frames can also use key indizes like GTKs. Hence, if we don't |
| 449 | * have a PTK/STK we check the key index for a WEP key. |
| 450 | * |
Johannes Berg | 8dc06a1 | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 451 | * Note that in a regular BSS, multicast frames are sent by the |
| 452 | * AP only, associated stations unicast the frame to the AP first |
| 453 | * which then multicasts it on their behalf. |
| 454 | * |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 455 | * There is also a slight problem in IBSS mode: GTKs are negotiated |
| 456 | * with each station, that is something we don't currently handle. |
Johannes Berg | 8dc06a1 | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 457 | * The spec seems to expect that one negotiates the same key with |
| 458 | * every station but there's no such requirement; VLANs could be |
| 459 | * possible. |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 460 | */ |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 461 | |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 462 | if (!(rx->fc & IEEE80211_FCTL_PROTECTED)) |
| 463 | return TXRX_CONTINUE; |
| 464 | |
| 465 | /* |
Johannes Berg | 1990af8 | 2007-09-26 17:53:15 +0200 | [diff] [blame] | 466 | * 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] | 467 | * addressed to us nor a multicast frame. |
| 468 | */ |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 469 | if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 470 | return TXRX_CONTINUE; |
| 471 | |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 472 | if (rx->sta) |
| 473 | stakey = rcu_dereference(rx->sta->key); |
| 474 | |
| 475 | if (!is_multicast_ether_addr(hdr->addr1) && stakey) { |
| 476 | rx->key = stakey; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 477 | } else { |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 478 | /* |
| 479 | * The device doesn't give us the IV so we won't be |
| 480 | * able to look up the key. That's ok though, we |
| 481 | * don't need to decrypt the frame, we just won't |
| 482 | * be able to keep statistics accurate. |
| 483 | * Except for key threshold notifications, should |
| 484 | * we somehow allow the driver to tell us which key |
| 485 | * the hardware used if this flag is set? |
| 486 | */ |
Johannes Berg | 7848ba7 | 2007-09-14 11:10:25 -0400 | [diff] [blame] | 487 | if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) && |
| 488 | (rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED)) |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 489 | return TXRX_CONTINUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 490 | |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 491 | hdrlen = ieee80211_get_hdrlen(rx->fc); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 492 | |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 493 | if (rx->skb->len < 8 + hdrlen) |
| 494 | return TXRX_DROP; /* TODO: count this? */ |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 495 | |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 496 | /* |
| 497 | * no need to call ieee80211_wep_get_keyidx, |
| 498 | * it verifies a bunch of things we've done already |
| 499 | */ |
| 500 | keyidx = rx->skb->data[hdrlen + 3] >> 6; |
| 501 | |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 502 | rx->key = rcu_dereference(rx->sdata->keys[keyidx]); |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 503 | |
| 504 | /* |
| 505 | * RSNA-protected unicast frames should always be sent with |
| 506 | * pairwise or station-to-station keys, but for WEP we allow |
| 507 | * using a key index as well. |
| 508 | */ |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 509 | if (rx->key && rx->key->conf.alg != ALG_WEP && |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 510 | !is_multicast_ether_addr(hdr->addr1)) |
| 511 | rx->key = NULL; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 512 | } |
| 513 | |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 514 | if (rx->key) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 515 | rx->key->tx_rx_count++; |
Johannes Berg | 011bfcc | 2007-09-17 01:29:25 -0400 | [diff] [blame] | 516 | /* TODO: add threshold stuff again */ |
Johannes Berg | 1990af8 | 2007-09-26 17:53:15 +0200 | [diff] [blame] | 517 | } else { |
John W. Linville | 7f3ad89 | 2007-11-06 17:12:31 -0500 | [diff] [blame] | 518 | #ifdef CONFIG_MAC80211_DEBUG |
Johannes Berg | 70f0876 | 2007-09-26 17:53:14 +0200 | [diff] [blame] | 519 | if (net_ratelimit()) |
| 520 | printk(KERN_DEBUG "%s: RX protected frame," |
| 521 | " but have no key\n", rx->dev->name); |
John W. Linville | 7f3ad89 | 2007-11-06 17:12:31 -0500 | [diff] [blame] | 522 | #endif /* CONFIG_MAC80211_DEBUG */ |
Johannes Berg | 70f0876 | 2007-09-26 17:53:14 +0200 | [diff] [blame] | 523 | return TXRX_DROP; |
| 524 | } |
| 525 | |
Johannes Berg | 1990af8 | 2007-09-26 17:53:15 +0200 | [diff] [blame] | 526 | /* Check for weak IVs if possible */ |
| 527 | if (rx->sta && rx->key->conf.alg == ALG_WEP && |
| 528 | ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) && |
| 529 | (!(rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED) || |
| 530 | !(rx->u.rx.status->flag & RX_FLAG_DECRYPTED)) && |
| 531 | ieee80211_wep_is_weak_iv(rx->skb, rx->key)) |
| 532 | rx->sta->wep_weak_iv_count++; |
| 533 | |
Johannes Berg | 70f0876 | 2007-09-26 17:53:14 +0200 | [diff] [blame] | 534 | switch (rx->key->conf.alg) { |
| 535 | case ALG_WEP: |
Mattias Nissler | e2f036d | 2007-10-07 16:35:31 +0200 | [diff] [blame] | 536 | result = ieee80211_crypto_wep_decrypt(rx); |
| 537 | break; |
Johannes Berg | 70f0876 | 2007-09-26 17:53:14 +0200 | [diff] [blame] | 538 | case ALG_TKIP: |
Mattias Nissler | e2f036d | 2007-10-07 16:35:31 +0200 | [diff] [blame] | 539 | result = ieee80211_crypto_tkip_decrypt(rx); |
| 540 | break; |
Johannes Berg | 70f0876 | 2007-09-26 17:53:14 +0200 | [diff] [blame] | 541 | case ALG_CCMP: |
Mattias Nissler | e2f036d | 2007-10-07 16:35:31 +0200 | [diff] [blame] | 542 | result = ieee80211_crypto_ccmp_decrypt(rx); |
| 543 | break; |
Johannes Berg | 70f0876 | 2007-09-26 17:53:14 +0200 | [diff] [blame] | 544 | } |
| 545 | |
Mattias Nissler | e2f036d | 2007-10-07 16:35:31 +0200 | [diff] [blame] | 546 | /* either the frame has been decrypted or will be dropped */ |
| 547 | rx->u.rx.status->flag |= RX_FLAG_DECRYPTED; |
| 548 | |
| 549 | return result; |
Johannes Berg | 70f0876 | 2007-09-26 17:53:14 +0200 | [diff] [blame] | 550 | } |
| 551 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 552 | static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta) |
| 553 | { |
| 554 | struct ieee80211_sub_if_data *sdata; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 555 | DECLARE_MAC_BUF(mac); |
| 556 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 557 | sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev); |
| 558 | |
| 559 | if (sdata->bss) |
| 560 | atomic_inc(&sdata->bss->num_sta_ps); |
| 561 | sta->flags |= WLAN_STA_PS; |
| 562 | sta->pspoll = 0; |
| 563 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 564 | printk(KERN_DEBUG "%s: STA %s aid %d enters power save mode\n", |
| 565 | dev->name, print_mac(mac, sta->addr), sta->aid); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 566 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
| 567 | } |
| 568 | |
| 569 | static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta) |
| 570 | { |
| 571 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 572 | struct sk_buff *skb; |
| 573 | int sent = 0; |
| 574 | struct ieee80211_sub_if_data *sdata; |
| 575 | struct ieee80211_tx_packet_data *pkt_data; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 576 | DECLARE_MAC_BUF(mac); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 577 | |
| 578 | sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev); |
| 579 | if (sdata->bss) |
| 580 | atomic_dec(&sdata->bss->num_sta_ps); |
| 581 | sta->flags &= ~(WLAN_STA_PS | WLAN_STA_TIM); |
| 582 | sta->pspoll = 0; |
| 583 | if (!skb_queue_empty(&sta->ps_tx_buf)) { |
| 584 | if (local->ops->set_tim) |
| 585 | local->ops->set_tim(local_to_hw(local), sta->aid, 0); |
| 586 | if (sdata->bss) |
| 587 | bss_tim_clear(local, sdata->bss, sta->aid); |
| 588 | } |
| 589 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 590 | printk(KERN_DEBUG "%s: STA %s aid %d exits power save mode\n", |
| 591 | dev->name, print_mac(mac, sta->addr), sta->aid); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 592 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
| 593 | /* Send all buffered frames to the station */ |
| 594 | while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) { |
| 595 | pkt_data = (struct ieee80211_tx_packet_data *) skb->cb; |
| 596 | sent++; |
Jiri Slaby | e8bf964 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 597 | pkt_data->flags |= IEEE80211_TXPD_REQUEUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 598 | dev_queue_xmit(skb); |
| 599 | } |
| 600 | while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) { |
| 601 | pkt_data = (struct ieee80211_tx_packet_data *) skb->cb; |
| 602 | local->total_ps_buffered--; |
| 603 | sent++; |
| 604 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 605 | printk(KERN_DEBUG "%s: STA %s aid %d send PS frame " |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 606 | "since STA not sleeping anymore\n", dev->name, |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 607 | print_mac(mac, sta->addr), sta->aid); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 608 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
Jiri Slaby | e8bf964 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 609 | pkt_data->flags |= IEEE80211_TXPD_REQUEUE; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 610 | dev_queue_xmit(skb); |
| 611 | } |
| 612 | |
| 613 | return sent; |
| 614 | } |
| 615 | |
| 616 | static ieee80211_txrx_result |
| 617 | ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx) |
| 618 | { |
| 619 | struct sta_info *sta = rx->sta; |
| 620 | struct net_device *dev = rx->dev; |
| 621 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; |
| 622 | |
| 623 | if (!sta) |
| 624 | return TXRX_CONTINUE; |
| 625 | |
| 626 | /* Update last_rx only for IBSS packets which are for the current |
| 627 | * BSSID to avoid keeping the current IBSS network alive in cases where |
| 628 | * other STAs are using different BSSID. */ |
| 629 | if (rx->sdata->type == IEEE80211_IF_TYPE_IBSS) { |
| 630 | u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len); |
| 631 | if (compare_ether_addr(bssid, rx->sdata->u.sta.bssid) == 0) |
| 632 | sta->last_rx = jiffies; |
| 633 | } else |
| 634 | if (!is_multicast_ether_addr(hdr->addr1) || |
| 635 | rx->sdata->type == IEEE80211_IF_TYPE_STA) { |
| 636 | /* Update last_rx only for unicast frames in order to prevent |
| 637 | * the Probe Request frames (the only broadcast frames from a |
| 638 | * STA in infrastructure mode) from keeping a connection alive. |
| 639 | */ |
| 640 | sta->last_rx = jiffies; |
| 641 | } |
| 642 | |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 643 | if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 644 | return TXRX_CONTINUE; |
| 645 | |
| 646 | sta->rx_fragments++; |
| 647 | sta->rx_bytes += rx->skb->len; |
Larry Finger | 6c55aa9 | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 648 | sta->last_rssi = rx->u.rx.status->ssi; |
| 649 | sta->last_signal = rx->u.rx.status->signal; |
| 650 | sta->last_noise = rx->u.rx.status->noise; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 651 | |
| 652 | if (!(rx->fc & IEEE80211_FCTL_MOREFRAGS)) { |
| 653 | /* Change STA power saving mode only in the end of a frame |
| 654 | * exchange sequence */ |
| 655 | if ((sta->flags & WLAN_STA_PS) && !(rx->fc & IEEE80211_FCTL_PM)) |
| 656 | rx->u.rx.sent_ps_buffered += ap_sta_ps_end(dev, sta); |
| 657 | else if (!(sta->flags & WLAN_STA_PS) && |
| 658 | (rx->fc & IEEE80211_FCTL_PM)) |
| 659 | ap_sta_ps_start(dev, sta); |
| 660 | } |
| 661 | |
| 662 | /* Drop data::nullfunc frames silently, since they are used only to |
| 663 | * control station power saving mode. */ |
| 664 | if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA && |
| 665 | (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_NULLFUNC) { |
| 666 | I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc); |
| 667 | /* Update counter and free packet here to avoid counting this |
| 668 | * as a dropped packed. */ |
| 669 | sta->rx_packets++; |
| 670 | dev_kfree_skb(rx->skb); |
| 671 | return TXRX_QUEUED; |
| 672 | } |
| 673 | |
| 674 | return TXRX_CONTINUE; |
| 675 | } /* ieee80211_rx_h_sta_process */ |
| 676 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 677 | static inline struct ieee80211_fragment_entry * |
| 678 | ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata, |
| 679 | unsigned int frag, unsigned int seq, int rx_queue, |
| 680 | struct sk_buff **skb) |
| 681 | { |
| 682 | struct ieee80211_fragment_entry *entry; |
| 683 | int idx; |
| 684 | |
| 685 | idx = sdata->fragment_next; |
| 686 | entry = &sdata->fragments[sdata->fragment_next++]; |
| 687 | if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX) |
| 688 | sdata->fragment_next = 0; |
| 689 | |
| 690 | if (!skb_queue_empty(&entry->skb_list)) { |
| 691 | #ifdef CONFIG_MAC80211_DEBUG |
| 692 | struct ieee80211_hdr *hdr = |
| 693 | (struct ieee80211_hdr *) entry->skb_list.next->data; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 694 | DECLARE_MAC_BUF(mac); |
| 695 | DECLARE_MAC_BUF(mac2); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 696 | printk(KERN_DEBUG "%s: RX reassembly removed oldest " |
| 697 | "fragment entry (idx=%d age=%lu seq=%d last_frag=%d " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 698 | "addr1=%s addr2=%s\n", |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 699 | sdata->dev->name, idx, |
| 700 | jiffies - entry->first_frag_time, entry->seq, |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 701 | entry->last_frag, print_mac(mac, hdr->addr1), |
| 702 | print_mac(mac2, hdr->addr2)); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 703 | #endif /* CONFIG_MAC80211_DEBUG */ |
| 704 | __skb_queue_purge(&entry->skb_list); |
| 705 | } |
| 706 | |
| 707 | __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */ |
| 708 | *skb = NULL; |
| 709 | entry->first_frag_time = jiffies; |
| 710 | entry->seq = seq; |
| 711 | entry->rx_queue = rx_queue; |
| 712 | entry->last_frag = frag; |
| 713 | entry->ccmp = 0; |
| 714 | entry->extra_len = 0; |
| 715 | |
| 716 | return entry; |
| 717 | } |
| 718 | |
| 719 | static inline struct ieee80211_fragment_entry * |
| 720 | ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata, |
| 721 | u16 fc, unsigned int frag, unsigned int seq, |
| 722 | int rx_queue, struct ieee80211_hdr *hdr) |
| 723 | { |
| 724 | struct ieee80211_fragment_entry *entry; |
| 725 | int i, idx; |
| 726 | |
| 727 | idx = sdata->fragment_next; |
| 728 | for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) { |
| 729 | struct ieee80211_hdr *f_hdr; |
| 730 | u16 f_fc; |
| 731 | |
| 732 | idx--; |
| 733 | if (idx < 0) |
| 734 | idx = IEEE80211_FRAGMENT_MAX - 1; |
| 735 | |
| 736 | entry = &sdata->fragments[idx]; |
| 737 | if (skb_queue_empty(&entry->skb_list) || entry->seq != seq || |
| 738 | entry->rx_queue != rx_queue || |
| 739 | entry->last_frag + 1 != frag) |
| 740 | continue; |
| 741 | |
| 742 | f_hdr = (struct ieee80211_hdr *) entry->skb_list.next->data; |
| 743 | f_fc = le16_to_cpu(f_hdr->frame_control); |
| 744 | |
| 745 | if ((fc & IEEE80211_FCTL_FTYPE) != (f_fc & IEEE80211_FCTL_FTYPE) || |
| 746 | compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 || |
| 747 | compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0) |
| 748 | continue; |
| 749 | |
| 750 | if (entry->first_frag_time + 2 * HZ < jiffies) { |
| 751 | __skb_queue_purge(&entry->skb_list); |
| 752 | continue; |
| 753 | } |
| 754 | return entry; |
| 755 | } |
| 756 | |
| 757 | return NULL; |
| 758 | } |
| 759 | |
| 760 | static ieee80211_txrx_result |
| 761 | ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx) |
| 762 | { |
| 763 | struct ieee80211_hdr *hdr; |
| 764 | u16 sc; |
| 765 | unsigned int frag, seq; |
| 766 | struct ieee80211_fragment_entry *entry; |
| 767 | struct sk_buff *skb; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 768 | DECLARE_MAC_BUF(mac); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 769 | |
| 770 | hdr = (struct ieee80211_hdr *) rx->skb->data; |
| 771 | sc = le16_to_cpu(hdr->seq_ctrl); |
| 772 | frag = sc & IEEE80211_SCTL_FRAG; |
| 773 | |
| 774 | if (likely((!(rx->fc & IEEE80211_FCTL_MOREFRAGS) && frag == 0) || |
| 775 | (rx->skb)->len < 24 || |
| 776 | is_multicast_ether_addr(hdr->addr1))) { |
| 777 | /* not fragmented */ |
| 778 | goto out; |
| 779 | } |
| 780 | I802_DEBUG_INC(rx->local->rx_handlers_fragments); |
| 781 | |
| 782 | seq = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 783 | |
| 784 | if (frag == 0) { |
| 785 | /* This is the first fragment of a new frame. */ |
| 786 | entry = ieee80211_reassemble_add(rx->sdata, frag, seq, |
| 787 | rx->u.rx.queue, &(rx->skb)); |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 788 | if (rx->key && rx->key->conf.alg == ALG_CCMP && |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 789 | (rx->fc & IEEE80211_FCTL_PROTECTED)) { |
| 790 | /* Store CCMP PN so that we can verify that the next |
| 791 | * fragment has a sequential PN value. */ |
| 792 | entry->ccmp = 1; |
| 793 | memcpy(entry->last_pn, |
| 794 | rx->key->u.ccmp.rx_pn[rx->u.rx.queue], |
| 795 | CCMP_PN_LEN); |
| 796 | } |
| 797 | return TXRX_QUEUED; |
| 798 | } |
| 799 | |
| 800 | /* This is a fragment for a frame that should already be pending in |
| 801 | * fragment cache. Add this fragment to the end of the pending entry. |
| 802 | */ |
| 803 | entry = ieee80211_reassemble_find(rx->sdata, rx->fc, frag, seq, |
| 804 | rx->u.rx.queue, hdr); |
| 805 | if (!entry) { |
| 806 | I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag); |
| 807 | return TXRX_DROP; |
| 808 | } |
| 809 | |
| 810 | /* Verify that MPDUs within one MSDU have sequential PN values. |
| 811 | * (IEEE 802.11i, 8.3.3.4.5) */ |
| 812 | if (entry->ccmp) { |
| 813 | int i; |
| 814 | u8 pn[CCMP_PN_LEN], *rpn; |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 815 | if (!rx->key || rx->key->conf.alg != ALG_CCMP) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 816 | return TXRX_DROP; |
| 817 | memcpy(pn, entry->last_pn, CCMP_PN_LEN); |
| 818 | for (i = CCMP_PN_LEN - 1; i >= 0; i--) { |
| 819 | pn[i]++; |
| 820 | if (pn[i]) |
| 821 | break; |
| 822 | } |
| 823 | rpn = rx->key->u.ccmp.rx_pn[rx->u.rx.queue]; |
| 824 | if (memcmp(pn, rpn, CCMP_PN_LEN) != 0) { |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 825 | if (net_ratelimit()) |
| 826 | printk(KERN_DEBUG "%s: defrag: CCMP PN not " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 827 | "sequential A2=%s" |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 828 | " PN=%02x%02x%02x%02x%02x%02x " |
| 829 | "(expected %02x%02x%02x%02x%02x%02x)\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 830 | rx->dev->name, print_mac(mac, hdr->addr2), |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 831 | rpn[0], rpn[1], rpn[2], rpn[3], rpn[4], |
| 832 | rpn[5], pn[0], pn[1], pn[2], pn[3], |
| 833 | pn[4], pn[5]); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 834 | return TXRX_DROP; |
| 835 | } |
| 836 | memcpy(entry->last_pn, pn, CCMP_PN_LEN); |
| 837 | } |
| 838 | |
| 839 | skb_pull(rx->skb, ieee80211_get_hdrlen(rx->fc)); |
| 840 | __skb_queue_tail(&entry->skb_list, rx->skb); |
| 841 | entry->last_frag = frag; |
| 842 | entry->extra_len += rx->skb->len; |
| 843 | if (rx->fc & IEEE80211_FCTL_MOREFRAGS) { |
| 844 | rx->skb = NULL; |
| 845 | return TXRX_QUEUED; |
| 846 | } |
| 847 | |
| 848 | rx->skb = __skb_dequeue(&entry->skb_list); |
| 849 | if (skb_tailroom(rx->skb) < entry->extra_len) { |
| 850 | I802_DEBUG_INC(rx->local->rx_expand_skb_head2); |
| 851 | if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len, |
| 852 | GFP_ATOMIC))) { |
| 853 | I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag); |
| 854 | __skb_queue_purge(&entry->skb_list); |
| 855 | return TXRX_DROP; |
| 856 | } |
| 857 | } |
| 858 | while ((skb = __skb_dequeue(&entry->skb_list))) { |
| 859 | memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len); |
| 860 | dev_kfree_skb(skb); |
| 861 | } |
| 862 | |
| 863 | /* Complete frame has been reassembled - process it now */ |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 864 | rx->flags |= IEEE80211_TXRXD_FRAGMENTED; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 865 | |
| 866 | out: |
| 867 | if (rx->sta) |
| 868 | rx->sta->rx_packets++; |
| 869 | if (is_multicast_ether_addr(hdr->addr1)) |
| 870 | rx->local->dot11MulticastReceivedFrameCount++; |
| 871 | else |
| 872 | ieee80211_led_rx(rx->local); |
| 873 | return TXRX_CONTINUE; |
| 874 | } |
| 875 | |
| 876 | static ieee80211_txrx_result |
| 877 | ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx) |
| 878 | { |
| 879 | struct sk_buff *skb; |
| 880 | int no_pending_pkts; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 881 | DECLARE_MAC_BUF(mac); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 882 | |
| 883 | if (likely(!rx->sta || |
| 884 | (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL || |
| 885 | (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PSPOLL || |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 886 | !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 887 | return TXRX_CONTINUE; |
| 888 | |
| 889 | skb = skb_dequeue(&rx->sta->tx_filtered); |
| 890 | if (!skb) { |
| 891 | skb = skb_dequeue(&rx->sta->ps_tx_buf); |
| 892 | if (skb) |
| 893 | rx->local->total_ps_buffered--; |
| 894 | } |
| 895 | no_pending_pkts = skb_queue_empty(&rx->sta->tx_filtered) && |
| 896 | skb_queue_empty(&rx->sta->ps_tx_buf); |
| 897 | |
| 898 | if (skb) { |
| 899 | struct ieee80211_hdr *hdr = |
| 900 | (struct ieee80211_hdr *) skb->data; |
| 901 | |
| 902 | /* tell TX path to send one frame even though the STA may |
| 903 | * still remain is PS mode after this frame exchange */ |
| 904 | rx->sta->pspoll = 1; |
| 905 | |
| 906 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 907 | printk(KERN_DEBUG "STA %s aid %d: PS Poll (entries after %d)\n", |
| 908 | print_mac(mac, rx->sta->addr), rx->sta->aid, |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 909 | skb_queue_len(&rx->sta->ps_tx_buf)); |
| 910 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
| 911 | |
| 912 | /* Use MoreData flag to indicate whether there are more |
| 913 | * buffered frames for this STA */ |
| 914 | if (no_pending_pkts) { |
| 915 | hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA); |
| 916 | rx->sta->flags &= ~WLAN_STA_TIM; |
| 917 | } else |
| 918 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA); |
| 919 | |
| 920 | dev_queue_xmit(skb); |
| 921 | |
| 922 | if (no_pending_pkts) { |
| 923 | if (rx->local->ops->set_tim) |
| 924 | rx->local->ops->set_tim(local_to_hw(rx->local), |
| 925 | rx->sta->aid, 0); |
| 926 | if (rx->sdata->bss) |
| 927 | bss_tim_clear(rx->local, rx->sdata->bss, rx->sta->aid); |
| 928 | } |
| 929 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
| 930 | } else if (!rx->u.rx.sent_ps_buffered) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 931 | printk(KERN_DEBUG "%s: STA %s sent PS Poll even " |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 932 | "though there is no buffered frames for it\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 933 | rx->dev->name, print_mac(mac, rx->sta->addr)); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 934 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
| 935 | |
| 936 | } |
| 937 | |
| 938 | /* Free PS Poll skb here instead of returning TXRX_DROP that would |
| 939 | * count as an dropped frame. */ |
| 940 | dev_kfree_skb(rx->skb); |
| 941 | |
| 942 | return TXRX_QUEUED; |
| 943 | } |
| 944 | |
| 945 | static ieee80211_txrx_result |
Johannes Berg | 6e0d114 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 946 | ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx) |
| 947 | { |
| 948 | u16 fc = rx->fc; |
| 949 | u8 *data = rx->skb->data; |
| 950 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data; |
| 951 | |
| 952 | if (!WLAN_FC_IS_QOS_DATA(fc)) |
| 953 | return TXRX_CONTINUE; |
| 954 | |
| 955 | /* remove the qos control field, update frame type and meta-data */ |
| 956 | memmove(data + 2, data, ieee80211_get_hdrlen(fc) - 2); |
| 957 | hdr = (struct ieee80211_hdr *) skb_pull(rx->skb, 2); |
| 958 | /* change frame type to non QOS */ |
| 959 | rx->fc = fc &= ~IEEE80211_STYPE_QOS_DATA; |
| 960 | hdr->frame_control = cpu_to_le16(fc); |
| 961 | |
| 962 | return TXRX_CONTINUE; |
| 963 | } |
| 964 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 965 | static int |
| 966 | ieee80211_drop_802_1x_pae(struct ieee80211_txrx_data *rx, int hdrlen) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 967 | { |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 968 | if (rx->sdata->eapol && ieee80211_is_eapol(rx->skb, hdrlen) && |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 969 | rx->sdata->type != IEEE80211_IF_TYPE_STA && |
Johannes Berg | f9d540e | 2007-09-28 14:02:09 +0200 | [diff] [blame] | 970 | (rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 971 | return 0; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 972 | |
| 973 | if (unlikely(rx->sdata->ieee802_1x && |
| 974 | (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA && |
| 975 | (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC && |
| 976 | (!rx->sta || !(rx->sta->flags & WLAN_STA_AUTHORIZED)) && |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 977 | !ieee80211_is_eapol(rx->skb, hdrlen))) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 978 | #ifdef CONFIG_MAC80211_DEBUG |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 979 | printk(KERN_DEBUG "%s: dropped frame " |
| 980 | "(unauthorized port)\n", rx->dev->name); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 981 | #endif /* CONFIG_MAC80211_DEBUG */ |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 982 | return -EACCES; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 983 | } |
| 984 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 985 | return 0; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 986 | } |
| 987 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 988 | static int |
| 989 | ieee80211_drop_unencrypted(struct ieee80211_txrx_data *rx, int hdrlen) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 990 | { |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 991 | /* |
Johannes Berg | 7848ba7 | 2007-09-14 11:10:25 -0400 | [diff] [blame] | 992 | * Pass through unencrypted frames if the hardware has |
| 993 | * decrypted them already. |
Johannes Berg | 3017b80 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 994 | */ |
Johannes Berg | 7848ba7 | 2007-09-14 11:10:25 -0400 | [diff] [blame] | 995 | if (rx->u.rx.status->flag & RX_FLAG_DECRYPTED) |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 996 | return 0; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 997 | |
| 998 | /* Drop unencrypted frames if key is set. */ |
| 999 | if (unlikely(!(rx->fc & IEEE80211_FCTL_PROTECTED) && |
| 1000 | (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA && |
| 1001 | (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC && |
Johannes Berg | 8312512 | 2007-11-28 11:07:57 +0100 | [diff] [blame] | 1002 | (rx->key || rx->sdata->drop_unencrypted) && |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 1003 | (rx->sdata->eapol == 0 || |
| 1004 | !ieee80211_is_eapol(rx->skb, hdrlen)))) { |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 1005 | if (net_ratelimit()) |
| 1006 | printk(KERN_DEBUG "%s: RX non-WEP frame, but expected " |
| 1007 | "encryption\n", rx->dev->name); |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 1008 | return -EACCES; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1009 | } |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 1010 | return 0; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1011 | } |
| 1012 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 1013 | static int |
| 1014 | ieee80211_data_to_8023(struct ieee80211_txrx_data *rx) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1015 | { |
| 1016 | struct net_device *dev = rx->dev; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1017 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; |
| 1018 | u16 fc, hdrlen, ethertype; |
| 1019 | u8 *payload; |
| 1020 | u8 dst[ETH_ALEN]; |
| 1021 | u8 src[ETH_ALEN]; |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 1022 | struct sk_buff *skb = rx->skb; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1023 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1024 | DECLARE_MAC_BUF(mac); |
| 1025 | DECLARE_MAC_BUF(mac2); |
| 1026 | DECLARE_MAC_BUF(mac3); |
| 1027 | DECLARE_MAC_BUF(mac4); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1028 | |
| 1029 | fc = rx->fc; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1030 | |
| 1031 | if (unlikely(!WLAN_FC_DATA_PRESENT(fc))) |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 1032 | return -1; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1033 | |
| 1034 | hdrlen = ieee80211_get_hdrlen(fc); |
| 1035 | |
| 1036 | /* convert IEEE 802.11 header + possible LLC headers into Ethernet |
| 1037 | * header |
| 1038 | * IEEE 802.11 address fields: |
| 1039 | * ToDS FromDS Addr1 Addr2 Addr3 Addr4 |
| 1040 | * 0 0 DA SA BSSID n/a |
| 1041 | * 0 1 DA BSSID SA n/a |
| 1042 | * 1 0 BSSID SA DA n/a |
| 1043 | * 1 1 RA TA DA SA |
| 1044 | */ |
| 1045 | |
| 1046 | switch (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) { |
| 1047 | case IEEE80211_FCTL_TODS: |
| 1048 | /* BSSID SA DA */ |
| 1049 | memcpy(dst, hdr->addr3, ETH_ALEN); |
| 1050 | memcpy(src, hdr->addr2, ETH_ALEN); |
| 1051 | |
| 1052 | if (unlikely(sdata->type != IEEE80211_IF_TYPE_AP && |
| 1053 | sdata->type != IEEE80211_IF_TYPE_VLAN)) { |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 1054 | if (net_ratelimit()) |
| 1055 | printk(KERN_DEBUG "%s: dropped ToDS frame " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1056 | "(BSSID=%s SA=%s DA=%s)\n", |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 1057 | dev->name, |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1058 | print_mac(mac, hdr->addr1), |
| 1059 | print_mac(mac2, hdr->addr2), |
| 1060 | print_mac(mac3, hdr->addr3)); |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 1061 | return -1; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1062 | } |
| 1063 | break; |
| 1064 | case (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS): |
| 1065 | /* RA TA DA SA */ |
| 1066 | memcpy(dst, hdr->addr3, ETH_ALEN); |
| 1067 | memcpy(src, hdr->addr4, ETH_ALEN); |
| 1068 | |
| 1069 | if (unlikely(sdata->type != IEEE80211_IF_TYPE_WDS)) { |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 1070 | if (net_ratelimit()) |
| 1071 | printk(KERN_DEBUG "%s: dropped FromDS&ToDS " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1072 | "frame (RA=%s TA=%s DA=%s SA=%s)\n", |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 1073 | rx->dev->name, |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1074 | print_mac(mac, hdr->addr1), |
| 1075 | print_mac(mac2, hdr->addr2), |
| 1076 | print_mac(mac3, hdr->addr3), |
| 1077 | print_mac(mac4, hdr->addr4)); |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 1078 | return -1; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1079 | } |
| 1080 | break; |
| 1081 | case IEEE80211_FCTL_FROMDS: |
| 1082 | /* DA BSSID SA */ |
| 1083 | memcpy(dst, hdr->addr1, ETH_ALEN); |
| 1084 | memcpy(src, hdr->addr3, ETH_ALEN); |
| 1085 | |
John W. Linville | b331615 | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 1086 | if (sdata->type != IEEE80211_IF_TYPE_STA || |
| 1087 | (is_multicast_ether_addr(dst) && |
| 1088 | !compare_ether_addr(src, dev->dev_addr))) |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 1089 | return -1; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1090 | break; |
| 1091 | case 0: |
| 1092 | /* DA SA BSSID */ |
| 1093 | memcpy(dst, hdr->addr1, ETH_ALEN); |
| 1094 | memcpy(src, hdr->addr2, ETH_ALEN); |
| 1095 | |
| 1096 | if (sdata->type != IEEE80211_IF_TYPE_IBSS) { |
| 1097 | if (net_ratelimit()) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1098 | printk(KERN_DEBUG "%s: dropped IBSS frame " |
| 1099 | "(DA=%s SA=%s BSSID=%s)\n", |
| 1100 | dev->name, |
| 1101 | print_mac(mac, hdr->addr1), |
| 1102 | print_mac(mac2, hdr->addr2), |
| 1103 | print_mac(mac3, hdr->addr3)); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1104 | } |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 1105 | return -1; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1106 | } |
| 1107 | break; |
| 1108 | } |
| 1109 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1110 | if (unlikely(skb->len - hdrlen < 8)) { |
| 1111 | if (net_ratelimit()) { |
| 1112 | printk(KERN_DEBUG "%s: RX too short data frame " |
| 1113 | "payload\n", dev->name); |
| 1114 | } |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 1115 | return -1; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1116 | } |
| 1117 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 1118 | payload = skb->data + hdrlen; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1119 | ethertype = (payload[6] << 8) | payload[7]; |
| 1120 | |
| 1121 | if (likely((compare_ether_addr(payload, rfc1042_header) == 0 && |
| 1122 | ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) || |
| 1123 | compare_ether_addr(payload, bridge_tunnel_header) == 0)) { |
| 1124 | /* remove RFC1042 or Bridge-Tunnel encapsulation and |
| 1125 | * replace EtherType */ |
| 1126 | skb_pull(skb, hdrlen + 6); |
| 1127 | memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN); |
| 1128 | memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN); |
| 1129 | } else { |
| 1130 | struct ethhdr *ehdr; |
| 1131 | __be16 len; |
| 1132 | skb_pull(skb, hdrlen); |
| 1133 | len = htons(skb->len); |
| 1134 | ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr)); |
| 1135 | memcpy(ehdr->h_dest, dst, ETH_ALEN); |
| 1136 | memcpy(ehdr->h_source, src, ETH_ALEN); |
| 1137 | ehdr->h_proto = len; |
| 1138 | } |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 1139 | return 0; |
| 1140 | } |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1141 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 1142 | static void |
| 1143 | ieee80211_deliver_skb(struct ieee80211_txrx_data *rx) |
| 1144 | { |
| 1145 | struct net_device *dev = rx->dev; |
| 1146 | struct ieee80211_local *local = rx->local; |
| 1147 | struct sk_buff *skb, *xmit_skb; |
| 1148 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1149 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 1150 | skb = rx->skb; |
| 1151 | xmit_skb = NULL; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1152 | |
| 1153 | if (local->bridge_packets && (sdata->type == IEEE80211_IF_TYPE_AP |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1154 | || sdata->type == IEEE80211_IF_TYPE_VLAN) && |
| 1155 | (rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1156 | if (is_multicast_ether_addr(skb->data)) { |
| 1157 | /* send multicast frames both to higher layers in |
| 1158 | * local net stack and back to the wireless media */ |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 1159 | xmit_skb = skb_copy(skb, GFP_ATOMIC); |
| 1160 | if (!xmit_skb && net_ratelimit()) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1161 | printk(KERN_DEBUG "%s: failed to clone " |
| 1162 | "multicast frame\n", dev->name); |
| 1163 | } else { |
| 1164 | struct sta_info *dsta; |
| 1165 | dsta = sta_info_get(local, skb->data); |
| 1166 | if (dsta && !dsta->dev) { |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 1167 | if (net_ratelimit()) |
| 1168 | printk(KERN_DEBUG "Station with null " |
| 1169 | "dev structure!\n"); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1170 | } else if (dsta && dsta->dev == dev) { |
| 1171 | /* Destination station is associated to this |
| 1172 | * AP, so send the frame directly to it and |
| 1173 | * do not pass the frame to local net stack. |
| 1174 | */ |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 1175 | xmit_skb = skb; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1176 | skb = NULL; |
| 1177 | } |
| 1178 | if (dsta) |
| 1179 | sta_info_put(dsta); |
| 1180 | } |
| 1181 | } |
| 1182 | |
| 1183 | if (skb) { |
| 1184 | /* deliver to local stack */ |
| 1185 | skb->protocol = eth_type_trans(skb, dev); |
| 1186 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 1187 | netif_rx(skb); |
| 1188 | } |
| 1189 | |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 1190 | if (xmit_skb) { |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1191 | /* send to wireless media */ |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 1192 | xmit_skb->protocol = __constant_htons(ETH_P_802_3); |
| 1193 | skb_set_network_header(xmit_skb, 0); |
| 1194 | skb_set_mac_header(xmit_skb, 0); |
| 1195 | dev_queue_xmit(xmit_skb); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1196 | } |
Ron Rindjunsky | 76ee65b | 2007-11-22 19:49:12 +0200 | [diff] [blame^] | 1197 | } |
| 1198 | |
| 1199 | static ieee80211_txrx_result |
| 1200 | ieee80211_rx_h_data(struct ieee80211_txrx_data *rx) |
| 1201 | { |
| 1202 | struct net_device *dev = rx->dev; |
| 1203 | u16 fc; |
| 1204 | int err, hdrlen; |
| 1205 | |
| 1206 | fc = rx->fc; |
| 1207 | if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)) |
| 1208 | return TXRX_CONTINUE; |
| 1209 | |
| 1210 | if (unlikely(!WLAN_FC_DATA_PRESENT(fc))) |
| 1211 | return TXRX_DROP; |
| 1212 | |
| 1213 | hdrlen = ieee80211_get_hdrlen(fc); |
| 1214 | |
| 1215 | if ((ieee80211_drop_802_1x_pae(rx, hdrlen)) || |
| 1216 | (ieee80211_drop_unencrypted(rx, hdrlen))) |
| 1217 | return TXRX_DROP; |
| 1218 | |
| 1219 | err = ieee80211_data_to_8023(rx); |
| 1220 | if (unlikely(err)) |
| 1221 | return TXRX_DROP; |
| 1222 | |
| 1223 | rx->skb->dev = dev; |
| 1224 | |
| 1225 | dev->stats.rx_packets++; |
| 1226 | dev->stats.rx_bytes += rx->skb->len; |
| 1227 | |
| 1228 | ieee80211_deliver_skb(rx); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1229 | |
| 1230 | return TXRX_QUEUED; |
| 1231 | } |
| 1232 | |
| 1233 | static ieee80211_txrx_result |
| 1234 | ieee80211_rx_h_mgmt(struct ieee80211_txrx_data *rx) |
| 1235 | { |
| 1236 | struct ieee80211_sub_if_data *sdata; |
| 1237 | |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1238 | if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1239 | return TXRX_DROP; |
| 1240 | |
| 1241 | sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev); |
| 1242 | if ((sdata->type == IEEE80211_IF_TYPE_STA || |
| 1243 | sdata->type == IEEE80211_IF_TYPE_IBSS) && |
Johannes Berg | ddd3d2b | 2007-09-26 17:53:20 +0200 | [diff] [blame] | 1244 | !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1245 | ieee80211_sta_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status); |
Johannes Berg | f9d540e | 2007-09-28 14:02:09 +0200 | [diff] [blame] | 1246 | else |
| 1247 | return TXRX_DROP; |
| 1248 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1249 | return TXRX_QUEUED; |
| 1250 | } |
| 1251 | |
| 1252 | static inline ieee80211_txrx_result __ieee80211_invoke_rx_handlers( |
| 1253 | struct ieee80211_local *local, |
| 1254 | ieee80211_rx_handler *handlers, |
| 1255 | struct ieee80211_txrx_data *rx, |
| 1256 | struct sta_info *sta) |
| 1257 | { |
| 1258 | ieee80211_rx_handler *handler; |
| 1259 | ieee80211_txrx_result res = TXRX_DROP; |
| 1260 | |
| 1261 | for (handler = handlers; *handler != NULL; handler++) { |
| 1262 | res = (*handler)(rx); |
Johannes Berg | 8e6f003 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1263 | |
| 1264 | switch (res) { |
| 1265 | case TXRX_CONTINUE: |
| 1266 | continue; |
| 1267 | case TXRX_DROP: |
| 1268 | I802_DEBUG_INC(local->rx_handlers_drop); |
| 1269 | if (sta) |
| 1270 | sta->rx_dropped++; |
| 1271 | break; |
| 1272 | case TXRX_QUEUED: |
| 1273 | I802_DEBUG_INC(local->rx_handlers_queued); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1274 | break; |
| 1275 | } |
Johannes Berg | 8e6f003 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1276 | break; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1277 | } |
| 1278 | |
Johannes Berg | 8e6f003 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1279 | if (res == TXRX_DROP) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1280 | dev_kfree_skb(rx->skb); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1281 | return res; |
| 1282 | } |
| 1283 | |
| 1284 | static inline void ieee80211_invoke_rx_handlers(struct ieee80211_local *local, |
| 1285 | ieee80211_rx_handler *handlers, |
| 1286 | struct ieee80211_txrx_data *rx, |
| 1287 | struct sta_info *sta) |
| 1288 | { |
| 1289 | if (__ieee80211_invoke_rx_handlers(local, handlers, rx, sta) == |
| 1290 | TXRX_CONTINUE) |
| 1291 | dev_kfree_skb(rx->skb); |
| 1292 | } |
| 1293 | |
| 1294 | static void ieee80211_rx_michael_mic_report(struct net_device *dev, |
| 1295 | struct ieee80211_hdr *hdr, |
| 1296 | struct sta_info *sta, |
| 1297 | struct ieee80211_txrx_data *rx) |
| 1298 | { |
| 1299 | int keyidx, hdrlen; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1300 | DECLARE_MAC_BUF(mac); |
| 1301 | DECLARE_MAC_BUF(mac2); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1302 | |
| 1303 | hdrlen = ieee80211_get_hdrlen_from_skb(rx->skb); |
| 1304 | if (rx->skb->len >= hdrlen + 4) |
| 1305 | keyidx = rx->skb->data[hdrlen + 3] >> 6; |
| 1306 | else |
| 1307 | keyidx = -1; |
| 1308 | |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 1309 | if (net_ratelimit()) |
| 1310 | printk(KERN_DEBUG "%s: TKIP hwaccel reported Michael MIC " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1311 | "failure from %s to %s keyidx=%d\n", |
| 1312 | dev->name, print_mac(mac, hdr->addr2), |
| 1313 | print_mac(mac2, hdr->addr1), keyidx); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1314 | |
| 1315 | if (!sta) { |
Johannes Berg | aa0daf0 | 2007-09-10 14:15:25 +0200 | [diff] [blame] | 1316 | /* |
| 1317 | * Some hardware seem to generate incorrect Michael MIC |
| 1318 | * reports; ignore them to avoid triggering countermeasures. |
| 1319 | */ |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 1320 | if (net_ratelimit()) |
| 1321 | printk(KERN_DEBUG "%s: ignored spurious Michael MIC " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1322 | "error for unknown address %s\n", |
| 1323 | dev->name, print_mac(mac, hdr->addr2)); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1324 | goto ignore; |
| 1325 | } |
| 1326 | |
| 1327 | if (!(rx->fc & IEEE80211_FCTL_PROTECTED)) { |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 1328 | if (net_ratelimit()) |
| 1329 | printk(KERN_DEBUG "%s: ignored spurious Michael MIC " |
Johannes Berg | aa0daf0 | 2007-09-10 14:15:25 +0200 | [diff] [blame] | 1330 | "error for a frame with no PROTECTED flag (src " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1331 | "%s)\n", dev->name, print_mac(mac, hdr->addr2)); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1332 | goto ignore; |
| 1333 | } |
| 1334 | |
Johannes Berg | 7848ba7 | 2007-09-14 11:10:25 -0400 | [diff] [blame] | 1335 | if (rx->sdata->type == IEEE80211_IF_TYPE_AP && keyidx) { |
Johannes Berg | aa0daf0 | 2007-09-10 14:15:25 +0200 | [diff] [blame] | 1336 | /* |
| 1337 | * APs with pairwise keys should never receive Michael MIC |
| 1338 | * errors for non-zero keyidx because these are reserved for |
| 1339 | * group keys and only the AP is sending real multicast |
| 1340 | * frames in the BSS. |
| 1341 | */ |
Johannes Berg | eb063c1 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 1342 | if (net_ratelimit()) |
| 1343 | printk(KERN_DEBUG "%s: ignored Michael MIC error for " |
| 1344 | "a frame with non-zero keyidx (%d)" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1345 | " (src %s)\n", dev->name, keyidx, |
| 1346 | print_mac(mac, hdr->addr2)); |
Johannes Berg | eb063c1 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 1347 | goto ignore; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA && |
| 1351 | ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT || |
| 1352 | (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)) { |
Johannes Berg | 1a84f3f | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 1353 | if (net_ratelimit()) |
| 1354 | printk(KERN_DEBUG "%s: ignored spurious Michael MIC " |
| 1355 | "error for a frame that cannot be encrypted " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1356 | "(fc=0x%04x) (src %s)\n", |
| 1357 | dev->name, rx->fc, print_mac(mac, hdr->addr2)); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1358 | goto ignore; |
| 1359 | } |
| 1360 | |
Johannes Berg | eb063c1 | 2007-08-28 17:01:53 -0400 | [diff] [blame] | 1361 | mac80211_ev_michael_mic_failure(rx->dev, keyidx, hdr); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1362 | ignore: |
| 1363 | dev_kfree_skb(rx->skb); |
| 1364 | rx->skb = NULL; |
| 1365 | } |
| 1366 | |
| 1367 | ieee80211_rx_handler ieee80211_rx_handlers[] = |
| 1368 | { |
| 1369 | ieee80211_rx_h_if_stats, |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1370 | ieee80211_rx_h_passive_scan, |
| 1371 | ieee80211_rx_h_check, |
Johannes Berg | 4f0d18e | 2007-09-26 15:19:40 +0200 | [diff] [blame] | 1372 | ieee80211_rx_h_decrypt, |
Johannes Berg | 70f0876 | 2007-09-26 17:53:14 +0200 | [diff] [blame] | 1373 | ieee80211_rx_h_sta_process, |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1374 | ieee80211_rx_h_defragment, |
| 1375 | ieee80211_rx_h_ps_poll, |
| 1376 | ieee80211_rx_h_michael_mic_verify, |
| 1377 | /* this must be after decryption - so header is counted in MPDU mic |
| 1378 | * must be before pae and data, so QOS_DATA format frames |
| 1379 | * are not passed to user space by these functions |
| 1380 | */ |
| 1381 | ieee80211_rx_h_remove_qos_control, |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1382 | ieee80211_rx_h_data, |
| 1383 | ieee80211_rx_h_mgmt, |
| 1384 | NULL |
| 1385 | }; |
| 1386 | |
| 1387 | /* main receive path */ |
| 1388 | |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1389 | static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata, |
| 1390 | u8 *bssid, struct ieee80211_txrx_data *rx, |
| 1391 | struct ieee80211_hdr *hdr) |
| 1392 | { |
| 1393 | int multicast = is_multicast_ether_addr(hdr->addr1); |
| 1394 | |
| 1395 | switch (sdata->type) { |
| 1396 | case IEEE80211_IF_TYPE_STA: |
| 1397 | if (!bssid) |
| 1398 | return 0; |
| 1399 | if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) { |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1400 | if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1401 | return 0; |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1402 | rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH; |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1403 | } else if (!multicast && |
| 1404 | compare_ether_addr(sdata->dev->dev_addr, |
| 1405 | hdr->addr1) != 0) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1406 | if (!(sdata->dev->flags & IFF_PROMISC)) |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1407 | return 0; |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1408 | rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH; |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1409 | } |
| 1410 | break; |
| 1411 | case IEEE80211_IF_TYPE_IBSS: |
| 1412 | if (!bssid) |
| 1413 | return 0; |
| 1414 | if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) { |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1415 | if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1416 | return 0; |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1417 | rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH; |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1418 | } else if (!multicast && |
| 1419 | compare_ether_addr(sdata->dev->dev_addr, |
| 1420 | hdr->addr1) != 0) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1421 | if (!(sdata->dev->flags & IFF_PROMISC)) |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1422 | return 0; |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1423 | rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH; |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1424 | } else if (!rx->sta) |
| 1425 | rx->sta = ieee80211_ibss_add_sta(sdata->dev, rx->skb, |
| 1426 | bssid, hdr->addr2); |
| 1427 | break; |
Johannes Berg | fb1c1cd | 2007-09-26 15:19:43 +0200 | [diff] [blame] | 1428 | case IEEE80211_IF_TYPE_VLAN: |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1429 | case IEEE80211_IF_TYPE_AP: |
| 1430 | if (!bssid) { |
| 1431 | if (compare_ether_addr(sdata->dev->dev_addr, |
| 1432 | hdr->addr1)) |
| 1433 | return 0; |
| 1434 | } else if (!ieee80211_bssid_match(bssid, |
| 1435 | sdata->dev->dev_addr)) { |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1436 | if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1437 | return 0; |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1438 | rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH; |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1439 | } |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1440 | if (sdata->dev == sdata->local->mdev && |
| 1441 | !(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1442 | /* do not receive anything via |
| 1443 | * master device when not scanning */ |
| 1444 | return 0; |
| 1445 | break; |
| 1446 | case IEEE80211_IF_TYPE_WDS: |
| 1447 | if (bssid || |
| 1448 | (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) |
| 1449 | return 0; |
| 1450 | if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2)) |
| 1451 | return 0; |
| 1452 | break; |
Johannes Berg | fb1c1cd | 2007-09-26 15:19:43 +0200 | [diff] [blame] | 1453 | case IEEE80211_IF_TYPE_MNTR: |
| 1454 | /* take everything */ |
| 1455 | break; |
Johannes Berg | a289755 | 2007-09-28 14:01:25 +0200 | [diff] [blame] | 1456 | case IEEE80211_IF_TYPE_INVALID: |
Johannes Berg | fb1c1cd | 2007-09-26 15:19:43 +0200 | [diff] [blame] | 1457 | /* should never get here */ |
| 1458 | WARN_ON(1); |
| 1459 | break; |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | return 1; |
| 1463 | } |
| 1464 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1465 | /* |
| 1466 | * This is the receive path handler. It is called by a low level driver when an |
| 1467 | * 802.11 MPDU is received from the hardware. |
| 1468 | */ |
| 1469 | void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb, |
| 1470 | struct ieee80211_rx_status *status) |
| 1471 | { |
| 1472 | struct ieee80211_local *local = hw_to_local(hw); |
| 1473 | struct ieee80211_sub_if_data *sdata; |
| 1474 | struct sta_info *sta; |
| 1475 | struct ieee80211_hdr *hdr; |
| 1476 | struct ieee80211_txrx_data rx; |
| 1477 | u16 type; |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 1478 | int prepres; |
Johannes Berg | 8e6f003 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1479 | struct ieee80211_sub_if_data *prev = NULL; |
| 1480 | struct sk_buff *skb_new; |
| 1481 | u8 *bssid; |
David S. Miller | d10f215 | 2008-01-24 16:57:39 -0800 | [diff] [blame] | 1482 | int hdrlen; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1483 | |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 1484 | /* |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 1485 | * key references and virtual interfaces are protected using RCU |
| 1486 | * and this requires that we are in a read-side RCU section during |
| 1487 | * receive processing |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 1488 | */ |
| 1489 | rcu_read_lock(); |
| 1490 | |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 1491 | /* |
| 1492 | * Frames with failed FCS/PLCP checksum are not returned, |
| 1493 | * all other frames are returned without radiotap header |
| 1494 | * if it was previously present. |
| 1495 | * Also, frames with less than 16 bytes are dropped. |
| 1496 | */ |
| 1497 | skb = ieee80211_rx_monitor(local, skb, status); |
| 1498 | if (!skb) { |
| 1499 | rcu_read_unlock(); |
| 1500 | return; |
| 1501 | } |
| 1502 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1503 | hdr = (struct ieee80211_hdr *) skb->data; |
| 1504 | memset(&rx, 0, sizeof(rx)); |
| 1505 | rx.skb = skb; |
| 1506 | rx.local = local; |
| 1507 | |
| 1508 | rx.u.rx.status = status; |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 1509 | rx.fc = le16_to_cpu(hdr->frame_control); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1510 | type = rx.fc & IEEE80211_FCTL_FTYPE; |
Johannes Berg | 72abd81 | 2007-09-17 01:29:22 -0400 | [diff] [blame] | 1511 | |
David S. Miller | d10f215 | 2008-01-24 16:57:39 -0800 | [diff] [blame] | 1512 | /* |
| 1513 | * Drivers are required to align the payload data to a four-byte |
| 1514 | * boundary, so the last two bits of the address where it starts |
| 1515 | * may not be set. The header is required to be directly before |
| 1516 | * the payload data, padding like atheros hardware adds which is |
| 1517 | * inbetween the 802.11 header and the payload is not supported, |
| 1518 | * the driver is required to move the 802.11 header further back |
| 1519 | * in that case. |
| 1520 | */ |
| 1521 | hdrlen = ieee80211_get_hdrlen(rx.fc); |
| 1522 | WARN_ON_ONCE(((unsigned long)(skb->data + hdrlen)) & 3); |
| 1523 | |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 1524 | if (type == IEEE80211_FTYPE_DATA || type == IEEE80211_FTYPE_MGMT) |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1525 | local->dot11ReceivedFragmentCount++; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1526 | |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 1527 | sta = rx.sta = sta_info_get(local, hdr->addr2); |
| 1528 | if (sta) { |
| 1529 | rx.dev = rx.sta->dev; |
| 1530 | rx.sdata = IEEE80211_DEV_TO_SUB_IF(rx.dev); |
| 1531 | } |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1532 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1533 | if ((status->flag & RX_FLAG_MMIC_ERROR)) { |
| 1534 | ieee80211_rx_michael_mic_report(local->mdev, hdr, sta, &rx); |
| 1535 | goto end; |
| 1536 | } |
| 1537 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 1538 | if (unlikely(local->sta_sw_scanning || local->sta_hw_scanning)) |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1539 | rx.flags |= IEEE80211_TXRXD_RXIN_SCAN; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1540 | |
| 1541 | if (__ieee80211_invoke_rx_handlers(local, local->rx_pre_handlers, &rx, |
| 1542 | sta) != TXRX_CONTINUE) |
| 1543 | goto end; |
| 1544 | skb = rx.skb; |
| 1545 | |
Johannes Berg | c9ee23d | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 1546 | if (sta && !(sta->flags & (WLAN_STA_WDS | WLAN_STA_ASSOC_AP)) && |
Johannes Berg | 5391899 | 2007-09-26 15:19:47 +0200 | [diff] [blame] | 1547 | !atomic_read(&local->iff_promiscs) && |
| 1548 | !is_multicast_ether_addr(hdr->addr1)) { |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1549 | rx.flags |= IEEE80211_TXRXD_RXRA_MATCH; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1550 | ieee80211_invoke_rx_handlers(local, local->rx_handlers, &rx, |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1551 | rx.sta); |
Johannes Berg | 8e6f003 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1552 | sta_info_put(sta); |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 1553 | rcu_read_unlock(); |
Johannes Berg | 8e6f003 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1554 | return; |
| 1555 | } |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1556 | |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 1557 | bssid = ieee80211_get_bssid(hdr, skb->len); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1558 | |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 1559 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
Johannes Berg | 2a8a9a8 | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 1560 | if (!netif_running(sdata->dev)) |
| 1561 | continue; |
| 1562 | |
Johannes Berg | b2e7771 | 2007-09-26 15:19:39 +0200 | [diff] [blame] | 1563 | if (sdata->type == IEEE80211_IF_TYPE_MNTR) |
| 1564 | continue; |
| 1565 | |
| 1566 | rx.flags |= IEEE80211_TXRXD_RXRA_MATCH; |
Johannes Berg | 23a24de | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1567 | prepres = prepare_for_handlers(sdata, bssid, &rx, hdr); |
| 1568 | /* prepare_for_handlers can change sta */ |
| 1569 | sta = rx.sta; |
| 1570 | |
| 1571 | if (!prepres) |
| 1572 | continue; |
Johannes Berg | 8e6f003 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1573 | |
Johannes Berg | 340e11f | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1574 | /* |
| 1575 | * frame is destined for this interface, but if it's not |
| 1576 | * also for the previous one we handle that after the |
| 1577 | * loop to avoid copying the SKB once too much |
| 1578 | */ |
| 1579 | |
| 1580 | if (!prev) { |
| 1581 | prev = sdata; |
| 1582 | continue; |
Johannes Berg | 8e6f003 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1583 | } |
Johannes Berg | 340e11f | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1584 | |
| 1585 | /* |
| 1586 | * frame was destined for the previous interface |
| 1587 | * so invoke RX handlers for it |
| 1588 | */ |
| 1589 | |
| 1590 | skb_new = skb_copy(skb, GFP_ATOMIC); |
| 1591 | if (!skb_new) { |
| 1592 | if (net_ratelimit()) |
| 1593 | printk(KERN_DEBUG "%s: failed to copy " |
| 1594 | "multicast frame for %s", |
Johannes Berg | dd1cd4c | 2007-09-18 17:29:20 -0400 | [diff] [blame] | 1595 | wiphy_name(local->hw.wiphy), |
| 1596 | prev->dev->name); |
Johannes Berg | 340e11f | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1597 | continue; |
| 1598 | } |
| 1599 | rx.skb = skb_new; |
| 1600 | rx.dev = prev->dev; |
| 1601 | rx.sdata = prev; |
| 1602 | ieee80211_invoke_rx_handlers(local, local->rx_handlers, |
| 1603 | &rx, sta); |
Johannes Berg | 8e6f003 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1604 | prev = sdata; |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1605 | } |
Johannes Berg | 8e6f003 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1606 | if (prev) { |
| 1607 | rx.skb = skb; |
| 1608 | rx.dev = prev->dev; |
| 1609 | rx.sdata = prev; |
| 1610 | ieee80211_invoke_rx_handlers(local, local->rx_handlers, |
| 1611 | &rx, sta); |
| 1612 | } else |
| 1613 | dev_kfree_skb(skb); |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1614 | |
Johannes Berg | 8e6f003 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1615 | end: |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 1616 | rcu_read_unlock(); |
| 1617 | |
Johannes Berg | 571ecf6 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1618 | if (sta) |
| 1619 | sta_info_put(sta); |
| 1620 | } |
| 1621 | EXPORT_SYMBOL(__ieee80211_rx); |
| 1622 | |
| 1623 | /* This is a version of the rx handler that can be called from hard irq |
| 1624 | * context. Post the skb on the queue and schedule the tasklet */ |
| 1625 | void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb, |
| 1626 | struct ieee80211_rx_status *status) |
| 1627 | { |
| 1628 | struct ieee80211_local *local = hw_to_local(hw); |
| 1629 | |
| 1630 | BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb)); |
| 1631 | |
| 1632 | skb->dev = local->mdev; |
| 1633 | /* copy status into skb->cb for use by tasklet */ |
| 1634 | memcpy(skb->cb, status, sizeof(*status)); |
| 1635 | skb->pkt_type = IEEE80211_RX_MSG; |
| 1636 | skb_queue_tail(&local->skb_queue, skb); |
| 1637 | tasklet_schedule(&local->tasklet); |
| 1638 | } |
| 1639 | EXPORT_SYMBOL(ieee80211_rx_irqsafe); |