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