mac80211: rx.c use new frame control helpers
[safe/jmp/linux-2.6] / net / mac80211 / rx.c
index 8e1e285..8962d13 100644 (file)
@@ -19,7 +19,7 @@
 #include <net/ieee80211_radiotap.h>
 
 #include "ieee80211_i.h"
-#include "ieee80211_led.h"
+#include "led.h"
 #include "mesh.h"
 #include "wep.h"
 #include "wpa.h"
@@ -61,22 +61,147 @@ static inline int should_drop_frame(struct ieee80211_rx_status *status,
                                    int present_fcs_len,
                                    int radiotap_len)
 {
-       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
+       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
 
        if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
                return 1;
        if (unlikely(skb->len < 16 + present_fcs_len + radiotap_len))
                return 1;
-       if (((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FTYPE)) ==
-                       cpu_to_le16(IEEE80211_FTYPE_CTL)) &&
-           ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE)) !=
-                       cpu_to_le16(IEEE80211_STYPE_PSPOLL)) &&
-           ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE)) !=
-                       cpu_to_le16(IEEE80211_STYPE_BACK_REQ)))
+       if (ieee80211_is_ctl(hdr->frame_control) &&
+           !ieee80211_is_pspoll(hdr->frame_control) &&
+           !ieee80211_is_back_req(hdr->frame_control))
                return 1;
        return 0;
 }
 
+static int
+ieee80211_rx_radiotap_len(struct ieee80211_local *local,
+                         struct ieee80211_rx_status *status)
+{
+       int len;
+
+       /* always present fields */
+       len = sizeof(struct ieee80211_radiotap_header) + 9;
+
+       if (status->flag & RX_FLAG_TSFT)
+               len += 8;
+       if (local->hw.flags & IEEE80211_HW_SIGNAL_DB ||
+           local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
+               len += 1;
+       if (local->hw.flags & IEEE80211_HW_NOISE_DBM)
+               len += 1;
+
+       if (len & 1) /* padding for RX_FLAGS if necessary */
+               len++;
+
+       /* make sure radiotap starts at a naturally aligned address */
+       if (len % 8)
+               len = roundup(len, 8);
+
+       return len;
+}
+
+/**
+ * ieee80211_add_rx_radiotap_header - add radiotap header
+ *
+ * add a radiotap header containing all the fields which the hardware provided.
+ */
+static void
+ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
+                                struct sk_buff *skb,
+                                struct ieee80211_rx_status *status,
+                                struct ieee80211_rate *rate,
+                                int rtap_len)
+{
+       struct ieee80211_radiotap_header *rthdr;
+       unsigned char *pos;
+
+       rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
+       memset(rthdr, 0, rtap_len);
+
+       /* radiotap header, set always present flags */
+       rthdr->it_present =
+               cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
+                           (1 << IEEE80211_RADIOTAP_RATE) |
+                           (1 << IEEE80211_RADIOTAP_CHANNEL) |
+                           (1 << IEEE80211_RADIOTAP_ANTENNA) |
+                           (1 << IEEE80211_RADIOTAP_RX_FLAGS));
+       rthdr->it_len = cpu_to_le16(rtap_len);
+
+       pos = (unsigned char *)(rthdr+1);
+
+       /* the order of the following fields is important */
+
+       /* IEEE80211_RADIOTAP_TSFT */
+       if (status->flag & RX_FLAG_TSFT) {
+               *(__le64 *)pos = cpu_to_le64(status->mactime);
+               rthdr->it_present |=
+                       cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
+               pos += 8;
+       }
+
+       /* IEEE80211_RADIOTAP_FLAGS */
+       if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
+               *pos |= IEEE80211_RADIOTAP_F_FCS;
+       pos++;
+
+       /* IEEE80211_RADIOTAP_RATE */
+       *pos = rate->bitrate / 5;
+       pos++;
+
+       /* IEEE80211_RADIOTAP_CHANNEL */
+       *(__le16 *)pos = cpu_to_le16(status->freq);
+       pos += 2;
+       if (status->band == IEEE80211_BAND_5GHZ)
+               *(__le16 *)pos = cpu_to_le16(IEEE80211_CHAN_OFDM |
+                                            IEEE80211_CHAN_5GHZ);
+       else
+               *(__le16 *)pos = cpu_to_le16(IEEE80211_CHAN_DYN |
+                                            IEEE80211_CHAN_2GHZ);
+       pos += 2;
+
+       /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
+       if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
+               *pos = status->signal;
+               rthdr->it_present |=
+                       cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
+               pos++;
+       }
+
+       /* IEEE80211_RADIOTAP_DBM_ANTNOISE */
+       if (local->hw.flags & IEEE80211_HW_NOISE_DBM) {
+               *pos = status->noise;
+               rthdr->it_present |=
+                       cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTNOISE);
+               pos++;
+       }
+
+       /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
+
+       /* IEEE80211_RADIOTAP_ANTENNA */
+       *pos = status->antenna;
+       pos++;
+
+       /* IEEE80211_RADIOTAP_DB_ANTSIGNAL */
+       if (local->hw.flags & IEEE80211_HW_SIGNAL_DB) {
+               *pos = status->signal;
+               rthdr->it_present |=
+                       cpu_to_le32(1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL);
+               pos++;
+       }
+
+       /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
+
+       /* IEEE80211_RADIOTAP_RX_FLAGS */
+       /* ensure 2 byte alignment for the 2 byte field as required */
+       if ((pos - (unsigned char *)rthdr) & 1)
+               pos++;
+       /* FIXME: when radiotap gets a 'bad PLCP' flag use it here */
+       if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
+               *(__le16 *)pos |= cpu_to_le16(IEEE80211_RADIOTAP_F_RX_BADFCS);
+       pos += 2;
+}
+
 /*
  * This function copies a received frame to all monitor interfaces and
  * returns a cleaned-up SKB that no longer includes the FCS nor the
@@ -89,17 +214,6 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
 {
        struct ieee80211_sub_if_data *sdata;
        int needed_headroom = 0;
-       struct ieee80211_radiotap_header *rthdr;
-       __le64 *rttsft = NULL;
-       struct ieee80211_rtap_fixed_data {
-               u8 flags;
-               u8 rate;
-               __le16 chan_freq;
-               __le16 chan_flags;
-               u8 antsignal;
-               u8 padding_for_rxflags;
-               __le16 rx_flags;
-       } __attribute__ ((packed)) *rtfixed;
        struct sk_buff *skb, *skb2;
        struct net_device *prev_dev = NULL;
        int present_fcs_len = 0;
@@ -116,8 +230,8 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
        if (status->flag & RX_FLAG_RADIOTAP)
                rtap_len = ieee80211_get_radiotap_len(origskb->data);
        else
-               /* room for radiotap header, always present fields and TSFT */
-               needed_headroom = sizeof(*rthdr) + sizeof(*rtfixed) + 8;
+               /* room for the radiotap header based on driver features */
+               needed_headroom = ieee80211_rx_radiotap_len(local, status);
 
        if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
                present_fcs_len = FCS_LEN;
@@ -163,55 +277,9 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
        }
 
        /* if necessary, prepend radiotap information */
-       if (!(status->flag & RX_FLAG_RADIOTAP)) {
-               rtfixed = (void *) skb_push(skb, sizeof(*rtfixed));
-               rtap_len = sizeof(*rthdr) + sizeof(*rtfixed);
-               if (status->flag & RX_FLAG_TSFT) {
-                       rttsft = (void *) skb_push(skb, sizeof(*rttsft));
-                       rtap_len += 8;
-               }
-               rthdr = (void *) skb_push(skb, sizeof(*rthdr));
-               memset(rthdr, 0, sizeof(*rthdr));
-               memset(rtfixed, 0, sizeof(*rtfixed));
-               rthdr->it_present =
-                       cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
-                                   (1 << IEEE80211_RADIOTAP_RATE) |
-                                   (1 << IEEE80211_RADIOTAP_CHANNEL) |
-                                   (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) |
-                                   (1 << IEEE80211_RADIOTAP_RX_FLAGS));
-               rtfixed->flags = 0;
-               if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
-                       rtfixed->flags |= IEEE80211_RADIOTAP_F_FCS;
-
-               if (rttsft) {
-                       *rttsft = cpu_to_le64(status->mactime);
-                       rthdr->it_present |=
-                               cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
-               }
-
-               /* FIXME: when radiotap gets a 'bad PLCP' flag use it here */
-               rtfixed->rx_flags = 0;
-               if (status->flag &
-                   (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
-                       rtfixed->rx_flags |=
-                               cpu_to_le16(IEEE80211_RADIOTAP_F_RX_BADFCS);
-
-               rtfixed->rate = rate->bitrate / 5;
-
-               rtfixed->chan_freq = cpu_to_le16(status->freq);
-
-               if (status->band == IEEE80211_BAND_5GHZ)
-                       rtfixed->chan_flags =
-                               cpu_to_le16(IEEE80211_CHAN_OFDM |
-                                           IEEE80211_CHAN_5GHZ);
-               else
-                       rtfixed->chan_flags =
-                               cpu_to_le16(IEEE80211_CHAN_DYN |
-                                           IEEE80211_CHAN_2GHZ);
-
-               rtfixed->antsignal = status->ssi;
-               rthdr->it_len = cpu_to_le16(rtap_len);
-       }
+       if (!(status->flag & RX_FLAG_RADIOTAP))
+               ieee80211_add_rx_radiotap_header(local, skb, status, rate,
+                                                needed_headroom);
 
        skb_reset_mac_header(skb);
        skb->ip_summed = CHECKSUM_UNNECESSARY;
@@ -275,11 +343,6 @@ static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
                }
        }
 
-       I802_DEBUG_INC(rx->local->wme_rx_queue[tid]);
-       /* only a debug counter, sta might not be assigned properly yet */
-       if (rx->sta)
-               I802_DEBUG_INC(rx->sta->wme_rx_queue[tid]);
-
        rx->queue = tid;
        /* Set skb->priority to 1d tag if highest order bit of TID is not set.
         * For now, set skb->priority to 0 for other cases. */
@@ -321,51 +384,9 @@ static void ieee80211_verify_ip_alignment(struct ieee80211_rx_data *rx)
 }
 
 
-static u32 ieee80211_rx_load_stats(struct ieee80211_local *local,
-                                  struct sk_buff *skb,
-                                  struct ieee80211_rx_status *status,
-                                  struct ieee80211_rate *rate)
-{
-       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
-       u32 load = 0, hdrtime;
-
-       /* Estimate total channel use caused by this frame */
-
-       /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
-        * 1 usec = 1/8 * (1080 / 10) = 13.5 */
-
-       if (status->band == IEEE80211_BAND_5GHZ ||
-           (status->band == IEEE80211_BAND_5GHZ &&
-            rate->flags & IEEE80211_RATE_ERP_G))
-               hdrtime = CHAN_UTIL_HDR_SHORT;
-       else
-               hdrtime = CHAN_UTIL_HDR_LONG;
-
-       load = hdrtime;
-       if (!is_multicast_ether_addr(hdr->addr1))
-               load += hdrtime;
-
-       /* TODO: optimise again */
-       load += skb->len * CHAN_UTIL_RATE_LCM / rate->bitrate;
-
-       /* Divide channel_use by 8 to avoid wrapping around the counter */
-       load >>= CHAN_UTIL_SHIFT;
-
-       return load;
-}
-
 /* rx handlers */
 
 static ieee80211_rx_result
-ieee80211_rx_h_if_stats(struct ieee80211_rx_data *rx)
-{
-       if (rx->sta)
-               rx->sta->channel_use_raw += rx->load;
-       rx->sdata->channel_use_raw += rx->load;
-       return RX_CONTINUE;
-}
-
-static ieee80211_rx_result
 ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx)
 {
        struct ieee80211_local *local = rx->local;
@@ -411,7 +432,7 @@ ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
         * establisment frame, beacon or probe, drop the frame.
         */
 
-       if (!rx->sta || sta_plink_state(rx->sta) != ESTAB) {
+       if (!rx->sta || sta_plink_state(rx->sta) != PLINK_ESTAB) {
                struct ieee80211_mgmt *mgmt;
 
                if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT)
@@ -433,7 +454,7 @@ ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
                }
 
         } else if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
-                   is_broadcast_ether_addr(hdr->addr1) &&
+                   is_multicast_ether_addr(hdr->addr1) &&
                    mesh_rmc_check(hdr->addr4, msh_h_get(hdr, hdrlen), rx->dev))
                return RX_DROP_MONITOR;
 #undef msh_h_get
@@ -484,7 +505,7 @@ ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
                      ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL &&
                       (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)) &&
                     rx->sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
-                    (!rx->sta || !(rx->sta->flags & WLAN_STA_ASSOC)))) {
+                    (!rx->sta || !test_sta_flags(rx->sta, WLAN_STA_ASSOC)))) {
                if ((!(rx->fc & IEEE80211_FCTL_FROMDS) &&
                     !(rx->fc & IEEE80211_FCTL_TODS) &&
                     (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
@@ -635,8 +656,7 @@ static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta)
 
        if (sdata->bss)
                atomic_inc(&sdata->bss->num_sta_ps);
-       sta->flags |= WLAN_STA_PS;
-       sta->flags &= ~WLAN_STA_PSPOLL;
+       set_and_clear_sta_flags(sta, WLAN_STA_PS, WLAN_STA_PSPOLL);
 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
        printk(KERN_DEBUG "%s: STA %s aid %d enters power save mode\n",
               dev->name, print_mac(mac, sta->addr), sta->aid);
@@ -649,7 +669,7 @@ static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
        struct sk_buff *skb;
        int sent = 0;
        struct ieee80211_sub_if_data *sdata;
-       struct ieee80211_tx_packet_data *pkt_data;
+       struct ieee80211_tx_info *info;
        DECLARE_MAC_BUF(mac);
 
        sdata = sta->sdata;
@@ -657,7 +677,7 @@ static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
        if (sdata->bss)
                atomic_dec(&sdata->bss->num_sta_ps);
 
-       sta->flags &= ~(WLAN_STA_PS | WLAN_STA_PSPOLL);
+       clear_sta_flags(sta, WLAN_STA_PS | WLAN_STA_PSPOLL);
 
        if (!skb_queue_empty(&sta->ps_tx_buf))
                sta_info_clear_tim_bit(sta);
@@ -669,13 +689,13 @@ static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
 
        /* Send all buffered frames to the station */
        while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
-               pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
+               info = IEEE80211_SKB_CB(skb);
                sent++;
-               pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
+               info->flags |= IEEE80211_TX_CTL_REQUEUE;
                dev_queue_xmit(skb);
        }
        while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
-               pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
+               info = IEEE80211_SKB_CB(skb);
                local->total_ps_buffered--;
                sent++;
 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
@@ -683,7 +703,7 @@ static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
                       "since STA not sleeping anymore\n", dev->name,
                       print_mac(mac, sta->addr), sta->aid);
 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
-               pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
+               info->flags |= IEEE80211_TX_CTL_REQUEUE;
                dev_queue_xmit(skb);
        }
 
@@ -725,16 +745,17 @@ ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
 
        sta->rx_fragments++;
        sta->rx_bytes += rx->skb->len;
-       sta->last_rssi = rx->status->ssi;
        sta->last_signal = rx->status->signal;
+       sta->last_qual = rx->status->qual;
        sta->last_noise = rx->status->noise;
 
        if (!(rx->fc & IEEE80211_FCTL_MOREFRAGS)) {
                /* Change STA power saving mode only in the end of a frame
                 * exchange sequence */
-               if ((sta->flags & WLAN_STA_PS) && !(rx->fc & IEEE80211_FCTL_PM))
+               if (test_sta_flags(sta, WLAN_STA_PS) &&
+                   !(rx->fc & IEEE80211_FCTL_PM))
                        rx->sent_ps_buffered += ap_sta_ps_end(dev, sta);
-               else if (!(sta->flags & WLAN_STA_PS) &&
+               else if (!test_sta_flags(sta, WLAN_STA_PS) &&
                         (rx->fc & IEEE80211_FCTL_PM))
                        ap_sta_ps_start(dev, sta);
        }
@@ -988,7 +1009,7 @@ ieee80211_rx_h_ps_poll(struct ieee80211_rx_data *rx)
                 * Tell TX path to send one frame even though the STA may
                 * still remain is PS mode after this frame exchange.
                 */
-               rx->sta->flags |= WLAN_STA_PSPOLL;
+               set_sta_flags(rx->sta, WLAN_STA_PSPOLL);
 
 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
                printk(KERN_DEBUG "STA %s aid %d: PS Poll (entries after %d)\n",
@@ -1051,7 +1072,8 @@ ieee80211_rx_h_remove_qos_control(struct ieee80211_rx_data *rx)
 static int
 ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
 {
-       if (unlikely(!rx->sta || !(rx->sta->flags & WLAN_STA_AUTHORIZED))) {
+       if (unlikely(!rx->sta ||
+           !test_sta_flags(rx->sta, WLAN_STA_AUTHORIZED))) {
 #ifdef CONFIG_MAC80211_DEBUG
                if (net_ratelimit())
                        printk(KERN_DEBUG "%s: dropped frame "
@@ -1077,12 +1099,9 @@ ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx)
        if (unlikely(!(rx->fc & IEEE80211_FCTL_PROTECTED) &&
                     (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
                     (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC &&
-                    (rx->key || rx->sdata->drop_unencrypted))) {
-               if (net_ratelimit())
-                       printk(KERN_DEBUG "%s: RX non-WEP frame, but expected "
-                              "encryption\n", rx->dev->name);
+                    (rx->key || rx->sdata->drop_unencrypted)))
                return -EACCES;
-       }
+
        return 0;
 }
 
@@ -1094,7 +1113,7 @@ ieee80211_data_to_8023(struct ieee80211_rx_data *rx)
        u16 fc, hdrlen, ethertype;
        u8 *payload;
        u8 dst[ETH_ALEN];
-       u8 src[ETH_ALEN];
+       u8 src[ETH_ALEN] __aligned(2);
        struct sk_buff *skb = rx->skb;
        struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
        DECLARE_MAC_BUF(mac);
@@ -1237,7 +1256,7 @@ ieee80211_data_to_8023(struct ieee80211_rx_data *rx)
  */
 static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx)
 {
-       static const u8 pae_group_addr[ETH_ALEN]
+       static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
                = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
        struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
 
@@ -1308,11 +1327,11 @@ ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
                if (is_multicast_ether_addr(skb->data)) {
                        if (*mesh_ttl > 0) {
                                xmit_skb = skb_copy(skb, GFP_ATOMIC);
-                               if (!xmit_skb && net_ratelimit())
+                               if (xmit_skb)
+                                       xmit_skb->pkt_type = PACKET_OTHERHOST;
+                               else if (net_ratelimit())
                                        printk(KERN_DEBUG "%s: failed to clone "
                                               "multicast frame\n", dev->name);
-                               else
-                                       xmit_skb->pkt_type = PACKET_OTHERHOST;
                        } else
                                IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.sta,
                                                             dropped_frames_ttl);
@@ -1398,7 +1417,7 @@ ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
                padding = ((4 - subframe_len) & 0x3);
                /* the last MSDU has no padding */
                if (subframe_len > remaining) {
-                       printk(KERN_DEBUG "%s: wrong buffer size", dev->name);
+                       printk(KERN_DEBUG "%s: wrong buffer size\n", dev->name);
                        return RX_DROP_UNUSABLE;
                }
 
@@ -1421,7 +1440,7 @@ ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
                        eth = (struct ethhdr *) skb_pull(skb, ntohs(len) +
                                                        padding);
                        if (!eth) {
-                               printk(KERN_DEBUG "%s: wrong buffer size ",
+                               printk(KERN_DEBUG "%s: wrong buffer size\n",
                                       dev->name);
                                dev_kfree_skb(frame);
                                return RX_DROP_UNUSABLE;
@@ -1514,9 +1533,10 @@ ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx)
                if (!rx->sta)
                        return RX_CONTINUE;
                tid = le16_to_cpu(bar->control) >> 12;
-               tid_agg_rx = &(rx->sta->ampdu_mlme.tid_rx[tid]);
-               if (tid_agg_rx->state != HT_AGG_STATE_OPERATIONAL)
+               if (rx->sta->ampdu_mlme.tid_state_rx[tid]
+                                       != HT_AGG_STATE_OPERATIONAL)
                        return RX_CONTINUE;
+               tid_agg_rx = rx->sta->ampdu_mlme.tid_rx[tid];
 
                start_seq_num = le16_to_cpu(bar->start_seq_num) >> 4;
 
@@ -1715,7 +1735,6 @@ static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx)
 typedef ieee80211_rx_result (*ieee80211_rx_handler)(struct ieee80211_rx_data *);
 static ieee80211_rx_handler ieee80211_rx_handlers[] =
 {
-       ieee80211_rx_h_if_stats,
        ieee80211_rx_h_passive_scan,
        ieee80211_rx_h_check,
        ieee80211_rx_h_decrypt,
@@ -1804,8 +1823,13 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
                if (!bssid)
                        return 0;
                if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT &&
-                   (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
+                   (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) {
+                       if (!rx->sta)
+                               rx->sta = ieee80211_ibss_add_sta(sdata->dev,
+                                               rx->skb, bssid, hdr->addr2,
+                                               BIT(rx->status->rate_idx));
                        return 1;
+               }
                else if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
                        if (!(rx->flags & IEEE80211_RX_IN_SCAN))
                                return 0;
@@ -1818,7 +1842,8 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
                        rx->flags &= ~IEEE80211_RX_RA_MATCH;
                } else if (!rx->sta)
                        rx->sta = ieee80211_ibss_add_sta(sdata->dev, rx->skb,
-                                                        bssid, hdr->addr2);
+                                               bssid, hdr->addr2,
+                                               BIT(rx->status->rate_idx));
                break;
        case IEEE80211_IF_TYPE_MESH_POINT:
                if (!multicast &&
@@ -1874,7 +1899,6 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
 static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
                                         struct sk_buff *skb,
                                         struct ieee80211_rx_status *status,
-                                        u32 load,
                                         struct ieee80211_rate *rate)
 {
        struct ieee80211_local *local = hw_to_local(hw);
@@ -1893,7 +1917,6 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
        rx.local = local;
 
        rx.status = status;
-       rx.load = load;
        rx.rate = rate;
        rx.fc = le16_to_cpu(hdr->frame_control);
        type = rx.fc & IEEE80211_FCTL_FTYPE;
@@ -1954,7 +1977,7 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
                if (!skb_new) {
                        if (net_ratelimit())
                                printk(KERN_DEBUG "%s: failed to copy "
-                                      "multicast frame for %s",
+                                      "multicast frame for %s\n",
                                       wiphy_name(local->hw.wiphy),
                                       prev->dev->name);
                        continue;
@@ -2002,7 +2025,6 @@ u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
        struct ieee80211_rx_status status;
        u16 head_seq_num, buf_size;
        int index;
-       u32 pkt_load;
        struct ieee80211_supported_band *sband;
        struct ieee80211_rate *rate;
 
@@ -2037,12 +2059,9 @@ u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
                                        sizeof(status));
                                sband = local->hw.wiphy->bands[status.band];
                                rate = &sband->bitrates[status.rate_idx];
-                               pkt_load = ieee80211_rx_load_stats(local,
-                                               tid_agg_rx->reorder_buf[index],
-                                               &status, rate);
                                __ieee80211_rx_handle_packet(hw,
                                        tid_agg_rx->reorder_buf[index],
-                                       &status, pkt_load, rate);
+                                       &status, rate);
                                tid_agg_rx->stored_mpdu_num--;
                                tid_agg_rx->reorder_buf[index] = NULL;
                        }
@@ -2084,11 +2103,8 @@ u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
                        sizeof(status));
                sband = local->hw.wiphy->bands[status.band];
                rate = &sband->bitrates[status.rate_idx];
-               pkt_load = ieee80211_rx_load_stats(local,
-                                       tid_agg_rx->reorder_buf[index],
-                                       &status, rate);
                __ieee80211_rx_handle_packet(hw, tid_agg_rx->reorder_buf[index],
-                                            &status, pkt_load, rate);
+                                            &status, rate);
                tid_agg_rx->stored_mpdu_num--;
                tid_agg_rx->reorder_buf[index] = NULL;
                tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
@@ -2105,31 +2121,29 @@ static u8 ieee80211_rx_reorder_ampdu(struct ieee80211_local *local,
        struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
        struct sta_info *sta;
        struct tid_ampdu_rx *tid_agg_rx;
-       u16 fc, sc;
+       u16 sc;
        u16 mpdu_seq_num;
-       u8 ret = 0, *qc;
+       u8 ret = 0;
        int tid;
 
        sta = sta_info_get(local, hdr->addr2);
        if (!sta)
                return ret;
 
-       fc = le16_to_cpu(hdr->frame_control);
-
        /* filter the QoS data rx stream according to
         * STA/TID and check if this STA/TID is on aggregation */
-       if (!WLAN_FC_IS_QOS_DATA(fc))
+       if (!ieee80211_is_data_qos(hdr->frame_control))
                goto end_reorder;
 
-       qc = skb->data + ieee80211_get_hdrlen(fc) - QOS_CONTROL_LEN;
-       tid = qc[0] & QOS_CONTROL_TID_MASK;
-       tid_agg_rx = &(sta->ampdu_mlme.tid_rx[tid]);
+       tid = *ieee80211_get_qos_ctl(hdr) & QOS_CONTROL_TID_MASK;
 
-       if (tid_agg_rx->state != HT_AGG_STATE_OPERATIONAL)
+       if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_OPERATIONAL)
                goto end_reorder;
 
+       tid_agg_rx = sta->ampdu_mlme.tid_rx[tid];
+
        /* null data frames are excluded */
-       if (unlikely(fc & IEEE80211_STYPE_NULLFUNC))
+       if (unlikely(ieee80211_is_nullfunc(hdr->frame_control)))
                goto end_reorder;
 
        /* new un-ordered ampdu frame - process it */
@@ -2166,12 +2180,11 @@ void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
                    struct ieee80211_rx_status *status)
 {
        struct ieee80211_local *local = hw_to_local(hw);
-       u32 pkt_load;
        struct ieee80211_rate *rate = NULL;
        struct ieee80211_supported_band *sband;
 
        if (status->band < 0 ||
-           status->band > IEEE80211_NUM_BANDS) {
+           status->band >= IEEE80211_NUM_BANDS) {
                WARN_ON(1);
                return;
        }
@@ -2206,11 +2219,8 @@ void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
                return;
        }
 
-       pkt_load = ieee80211_rx_load_stats(local, skb, status, rate);
-       local->channel_use_raw += pkt_load;
-
        if (!ieee80211_rx_reorder_ampdu(local, skb))
-               __ieee80211_rx_handle_packet(hw, skb, status, pkt_load, rate);
+               __ieee80211_rx_handle_packet(hw, skb, status, rate);
 
        rcu_read_unlock();
 }