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