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