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