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