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