mac80211: Fix radiotap header it_present on big endian CPUs
[safe/jmp/linux-2.6] / net / mac80211 / tx.c
index 1bed3be..ad53ea9 100644 (file)
 
 /* misc utils */
 
-#ifdef CONFIG_MAC80211_LOWTX_FRAME_DUMP
-static void ieee80211_dump_frame(const char *ifname, const char *title,
-                                const struct sk_buff *skb)
-{
-       const struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
-       unsigned int hdrlen;
-       DECLARE_MAC_BUF(mac);
-
-       printk(KERN_DEBUG "%s: %s (len=%d)", ifname, title, skb->len);
-       if (skb->len < 4) {
-               printk("\n");
-               return;
-       }
-
-       hdrlen = ieee80211_hdrlen(hdr->frame_control);
-       if (hdrlen > skb->len)
-               hdrlen = skb->len;
-       if (hdrlen >= 4)
-               printk(" FC=0x%04x DUR=0x%04x",
-                   le16_to_cpu(hdr->frame_control), le16_to_cpu(hdr->duration_id));
-       if (hdrlen >= 10)
-               printk(" A1=%s", print_mac(mac, hdr->addr1));
-       if (hdrlen >= 16)
-               printk(" A2=%s", print_mac(mac, hdr->addr2));
-       if (hdrlen >= 24)
-               printk(" A3=%s", print_mac(mac, hdr->addr3));
-       if (hdrlen >= 30)
-               printk(" A4=%s", print_mac(mac, hdr->addr4));
-       printk("\n");
-}
-#else /* CONFIG_MAC80211_LOWTX_FRAME_DUMP */
-static inline void ieee80211_dump_frame(const char *ifname, const char *title,
-                                       struct sk_buff *skb)
-{
-}
-#endif /* CONFIG_MAC80211_LOWTX_FRAME_DUMP */
-
 static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
                                 int next_frag_len)
 {
@@ -83,13 +46,20 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
        struct ieee80211_local *local = tx->local;
        struct ieee80211_supported_band *sband;
        struct ieee80211_hdr *hdr;
+       struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
+
+       /* assume HW handles this */
+       if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
+               return 0;
+
+       /* uh huh? */
+       if (WARN_ON_ONCE(info->control.rates[0].idx < 0))
+               return 0;
 
        sband = local->hw.wiphy->bands[tx->channel->band];
-       txrate = &sband->bitrates[tx->rate_idx];
+       txrate = &sband->bitrates[info->control.rates[0].idx];
 
-       erp = 0;
-       if (tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
-               erp = txrate->flags & IEEE80211_RATE_ERP_G;
+       erp = txrate->flags & IEEE80211_RATE_ERP_G;
 
        /*
         * data and mgmt (except PS Poll):
@@ -153,7 +123,7 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
                if (r->bitrate > txrate->bitrate)
                        break;
 
-               if (tx->sdata->basic_rates & BIT(i))
+               if (tx->sdata->vif.bss_conf.basic_rates & BIT(i))
                        rate = r->bitrate;
 
                switch (sband->band) {
@@ -187,7 +157,7 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
         * to closest integer */
 
        dur = ieee80211_frame_duration(local, 10, rate, erp,
-                               tx->sdata->bss_conf.use_short_preamble);
+                               tx->sdata->vif.bss_conf.use_short_preamble);
 
        if (next_frag_len) {
                /* Frame is fragmented: duration increases with time needed to
@@ -196,17 +166,16 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
                /* next fragment */
                dur += ieee80211_frame_duration(local, next_frag_len,
                                txrate->bitrate, erp,
-                               tx->sdata->bss_conf.use_short_preamble);
+                               tx->sdata->vif.bss_conf.use_short_preamble);
        }
 
        return cpu_to_le16(dur);
 }
 
-static int inline is_ieee80211_device(struct net_device *dev,
-                                     struct net_device *master)
+static int inline is_ieee80211_device(struct ieee80211_local *local,
+                                     struct net_device *dev)
 {
-       return (wdev_priv(dev->ieee80211_ptr) ==
-               wdev_priv(master->ieee80211_ptr));
+       return local == wdev_priv(dev->ieee80211_ptr);
 }
 
 /* tx handlers */
@@ -226,7 +195,7 @@ ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
            !ieee80211_is_probe_req(hdr->frame_control))
                return TX_DROP;
 
-       if (tx->sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT)
+       if (tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
                return TX_CONTINUE;
 
        if (tx->flags & IEEE80211_TX_PS_BUFFERED)
@@ -236,13 +205,12 @@ ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
 
        if (likely(tx->flags & IEEE80211_TX_UNICAST)) {
                if (unlikely(!(sta_flags & WLAN_STA_ASSOC) &&
-                            tx->sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
+                            tx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
                             ieee80211_is_data(hdr->frame_control))) {
 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
-                       DECLARE_MAC_BUF(mac);
                        printk(KERN_DEBUG "%s: dropped data frame to not "
-                              "associated station %s\n",
-                              tx->dev->name, print_mac(mac, hdr->addr1));
+                              "associated station %pM\n",
+                              tx->dev->name, hdr->addr1);
 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
                        I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
                        return TX_DROP;
@@ -250,7 +218,7 @@ ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
        } else {
                if (unlikely(ieee80211_is_data(hdr->frame_control) &&
                             tx->local->num_sta == 0 &&
-                            tx->sdata->vif.type != IEEE80211_IF_TYPE_IBSS)) {
+                            tx->sdata->vif.type != NL80211_IFTYPE_ADHOC)) {
                        /*
                         * No associated STAs - no need to send multicast
                         * frames.
@@ -281,7 +249,7 @@ static void purge_old_ps_buffers(struct ieee80211_local *local)
 
        list_for_each_entry_rcu(sdata, &local->interfaces, list) {
                struct ieee80211_if_ap *ap;
-               if (sdata->vif.type != IEEE80211_IF_TYPE_AP)
+               if (sdata->vif.type != NL80211_IFTYPE_AP)
                        continue;
                ap = &sdata->u.ap;
                skb = skb_dequeue(&ap->ps_bc_buf);
@@ -362,6 +330,22 @@ ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx)
        return TX_CONTINUE;
 }
 
+static int ieee80211_use_mfp(__le16 fc, struct sta_info *sta,
+                            struct sk_buff *skb)
+{
+       if (!ieee80211_is_mgmt(fc))
+               return 0;
+
+       if (sta == NULL || !test_sta_flags(sta, WLAN_STA_MFP))
+               return 0;
+
+       if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *)
+                                           skb->data))
+               return 0;
+
+       return 1;
+}
+
 static ieee80211_tx_result
 ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
 {
@@ -369,7 +353,6 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
        struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
        struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
        u32 staflags;
-       DECLARE_MAC_BUF(mac);
 
        if (unlikely(!sta || ieee80211_is_probe_resp(hdr->frame_control)))
                return TX_CONTINUE;
@@ -379,9 +362,9 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
        if (unlikely((staflags & WLAN_STA_PS) &&
                     !(staflags & WLAN_STA_PSPOLL))) {
 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
-               printk(KERN_DEBUG "STA %s aid %d: PS buffer (entries "
+               printk(KERN_DEBUG "STA %pM aid %d: PS buffer (entries "
                       "before %d)\n",
-                      print_mac(mac, sta->addr), sta->aid,
+                      sta->sta.addr, sta->sta.aid,
                       skb_queue_len(&sta->ps_tx_buf));
 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
                if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
@@ -390,9 +373,9 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
                        struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf);
 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
                        if (net_ratelimit()) {
-                               printk(KERN_DEBUG "%s: STA %s TX "
+                               printk(KERN_DEBUG "%s: STA %pM TX "
                                       "buffer full - dropping oldest frame\n",
-                                      tx->dev->name, print_mac(mac, sta->addr));
+                                      tx->dev->name, sta->sta.addr);
                        }
 #endif
                        dev_kfree_skb(old);
@@ -409,9 +392,9 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
        }
 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
        else if (unlikely(test_sta_flags(sta, WLAN_STA_PS))) {
-               printk(KERN_DEBUG "%s: STA %s in PS mode, but pspoll "
+               printk(KERN_DEBUG "%s: STA %pM in PS mode, but pspoll "
                       "set -> send frame\n", tx->dev->name,
-                      print_mac(mac, sta->addr));
+                      sta->sta.addr);
        }
 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
        clear_sta_flags(sta, WLAN_STA_PSPOLL);
@@ -442,6 +425,9 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
                tx->key = NULL;
        else if (tx->sta && (key = rcu_dereference(tx->sta->key)))
                tx->key = key;
+       else if (ieee80211_is_mgmt(hdr->frame_control) &&
+                (key = rcu_dereference(tx->sdata->default_mgmt_key)))
+               tx->key = key;
        else if ((key = rcu_dereference(tx->sdata->default_key)))
                tx->key = key;
        else if (tx->sdata->drop_unencrypted &&
@@ -461,10 +447,19 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
                        if (ieee80211_is_auth(hdr->frame_control))
                                break;
                case ALG_TKIP:
-               case ALG_CCMP:
                        if (!ieee80211_is_data_present(hdr->frame_control))
                                tx->key = NULL;
                        break;
+               case ALG_CCMP:
+                       if (!ieee80211_is_data_present(hdr->frame_control) &&
+                           !ieee80211_use_mfp(hdr->frame_control, tx->sta,
+                                              tx->skb))
+                               tx->key = NULL;
+                       break;
+               case ALG_AES_CMAC:
+                       if (!ieee80211_is_mgmt(hdr->frame_control))
+                               tx->key = NULL;
+                       break;
                }
        }
 
@@ -477,138 +472,156 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
 static ieee80211_tx_result debug_noinline
 ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
 {
-       struct rate_selection rsel;
-       struct ieee80211_supported_band *sband;
        struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
+       struct ieee80211_hdr *hdr = (void *)tx->skb->data;
+       struct ieee80211_supported_band *sband;
+       struct ieee80211_rate *rate;
+       int i, len;
+       bool inval = false, rts = false, short_preamble = false;
+       struct ieee80211_tx_rate_control txrc;
+
+       memset(&txrc, 0, sizeof(txrc));
 
        sband = tx->local->hw.wiphy->bands[tx->channel->band];
 
-       if (likely(tx->rate_idx < 0)) {
-               rate_control_get_rate(tx->dev, sband, tx->skb, &rsel);
-               tx->rate_idx = rsel.rate_idx;
-               if (unlikely(rsel.probe_idx >= 0)) {
-                       info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
-                       tx->flags |= IEEE80211_TX_PROBE_LAST_FRAG;
-                       info->control.alt_retry_rate_idx = tx->rate_idx;
-                       tx->rate_idx = rsel.probe_idx;
-               } else
-                       info->control.alt_retry_rate_idx = -1;
+       len = min_t(int, tx->skb->len + FCS_LEN,
+                        tx->local->fragmentation_threshold);
+
+       /* set up the tx rate control struct we give the RC algo */
+       txrc.hw = local_to_hw(tx->local);
+       txrc.sband = sband;
+       txrc.bss_conf = &tx->sdata->vif.bss_conf;
+       txrc.skb = tx->skb;
+       txrc.reported_rate.idx = -1;
+       txrc.max_rate_idx = tx->sdata->max_ratectrl_rateidx;
+
+       /* set up RTS protection if desired */
+       if (tx->local->rts_threshold < IEEE80211_MAX_RTS_THRESHOLD &&
+           len > tx->local->rts_threshold) {
+               txrc.rts = rts = true;
+       }
 
-               if (unlikely(tx->rate_idx < 0))
-                       return TX_DROP;
-       } else
-               info->control.alt_retry_rate_idx = -1;
+       /*
+        * Use short preamble if the BSS can handle it, but not for
+        * management frames unless we know the receiver can handle
+        * that -- the management frame might be to a station that
+        * just wants a probe response.
+        */
+       if (tx->sdata->vif.bss_conf.use_short_preamble &&
+           (ieee80211_is_data(hdr->frame_control) ||
+            (tx->sta && test_sta_flags(tx->sta, WLAN_STA_SHORT_PREAMBLE))))
+               txrc.short_preamble = short_preamble = true;
 
-       if (tx->sdata->bss_conf.use_cts_prot &&
-           (tx->flags & IEEE80211_TX_FRAGMENTED) && (rsel.nonerp_idx >= 0)) {
-               tx->last_frag_rate_idx = tx->rate_idx;
-               if (rsel.probe_idx >= 0)
-                       tx->flags &= ~IEEE80211_TX_PROBE_LAST_FRAG;
-               else
-                       tx->flags |= IEEE80211_TX_PROBE_LAST_FRAG;
-               tx->rate_idx = rsel.nonerp_idx;
-               info->tx_rate_idx = rsel.nonerp_idx;
-               info->flags &= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE;
-       } else {
-               tx->last_frag_rate_idx = tx->rate_idx;
-               info->tx_rate_idx = tx->rate_idx;
-       }
-       info->tx_rate_idx = tx->rate_idx;
 
-       return TX_CONTINUE;
-}
+       rate_control_get_rate(tx->sdata, tx->sta, &txrc);
 
-static ieee80211_tx_result debug_noinline
-ieee80211_tx_h_misc(struct ieee80211_tx_data *tx)
-{
-       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
-       struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
-       struct ieee80211_supported_band *sband;
+       if (unlikely(info->control.rates[0].idx < 0))
+               return TX_DROP;
 
-       sband = tx->local->hw.wiphy->bands[tx->channel->band];
+       if (txrc.reported_rate.idx < 0)
+               txrc.reported_rate = info->control.rates[0];
 
        if (tx->sta)
-               info->control.aid = tx->sta->aid;
-
-       if (!info->control.retry_limit) {
-               if (!is_multicast_ether_addr(hdr->addr1)) {
-                       int len = min_t(int, tx->skb->len + FCS_LEN,
-                                       tx->local->fragmentation_threshold);
-                       if (len > tx->local->rts_threshold
-                           && tx->local->rts_threshold <
-                                               IEEE80211_MAX_RTS_THRESHOLD) {
-                               info->flags |= IEEE80211_TX_CTL_USE_RTS_CTS;
-                               info->flags |=
-                                       IEEE80211_TX_CTL_LONG_RETRY_LIMIT;
-                               info->control.retry_limit =
-                                       tx->local->long_retry_limit;
-                       } else {
-                               info->control.retry_limit =
-                                       tx->local->short_retry_limit;
-                       }
-               } else {
-                       info->control.retry_limit = 1;
-               }
-       }
+               tx->sta->last_tx_rate = txrc.reported_rate;
 
-       if (tx->flags & IEEE80211_TX_FRAGMENTED) {
-               /* Do not use multiple retry rates when sending fragmented
-                * frames.
-                * TODO: The last fragment could still use multiple retry
-                * rates. */
-               info->control.alt_retry_rate_idx = -1;
+       if (unlikely(!info->control.rates[0].count))
+               info->control.rates[0].count = 1;
+
+       if (is_multicast_ether_addr(hdr->addr1)) {
+               /*
+                * XXX: verify the rate is in the basic rateset
+                */
+               return TX_CONTINUE;
        }
 
-       /* Use CTS protection for unicast frames sent using extended rates if
-        * there are associated non-ERP stations and RTS/CTS is not configured
-        * for the frame. */
-       if ((tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) &&
-           (sband->bitrates[tx->rate_idx].flags & IEEE80211_RATE_ERP_G) &&
-           (tx->flags & IEEE80211_TX_UNICAST) &&
-           tx->sdata->bss_conf.use_cts_prot &&
-           !(info->flags & IEEE80211_TX_CTL_USE_RTS_CTS))
-               info->flags |= IEEE80211_TX_CTL_USE_CTS_PROTECT;
-
-       /* Transmit data frames using short preambles if the driver supports
-        * short preambles at the selected rate and short preambles are
-        * available on the network at the current point in time. */
-       if (ieee80211_is_data(hdr->frame_control) &&
-           (sband->bitrates[tx->rate_idx].flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
-           tx->sdata->bss_conf.use_short_preamble &&
-           (!tx->sta || test_sta_flags(tx->sta, WLAN_STA_SHORT_PREAMBLE))) {
-               info->flags |= IEEE80211_TX_CTL_SHORT_PREAMBLE;
+       /*
+        * set up the RTS/CTS rate as the fastest basic rate
+        * that is not faster than the data rate
+        *
+        * XXX: Should this check all retry rates?
+        */
+       if (!(info->control.rates[0].flags & IEEE80211_TX_RC_MCS)) {
+               s8 baserate = 0;
+
+               rate = &sband->bitrates[info->control.rates[0].idx];
+
+               for (i = 0; i < sband->n_bitrates; i++) {
+                       /* must be a basic rate */
+                       if (!(tx->sdata->vif.bss_conf.basic_rates & BIT(i)))
+                               continue;
+                       /* must not be faster than the data rate */
+                       if (sband->bitrates[i].bitrate > rate->bitrate)
+                               continue;
+                       /* maximum */
+                       if (sband->bitrates[baserate].bitrate <
+                            sband->bitrates[i].bitrate)
+                               baserate = i;
+               }
+
+               info->control.rts_cts_rate_idx = baserate;
        }
 
-       if ((info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) ||
-           (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT)) {
-               struct ieee80211_rate *rate;
-               s8 baserate = -1;
-               int idx;
+       for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
+               /*
+                * make sure there's no valid rate following
+                * an invalid one, just in case drivers don't
+                * take the API seriously to stop at -1.
+                */
+               if (inval) {
+                       info->control.rates[i].idx = -1;
+                       continue;
+               }
+               if (info->control.rates[i].idx < 0) {
+                       inval = true;
+                       continue;
+               }
 
-               /* Do not use multiple retry rates when using RTS/CTS */
-               info->control.alt_retry_rate_idx = -1;
+               /*
+                * For now assume MCS is already set up correctly, this
+                * needs to be fixed.
+                */
+               if (info->control.rates[i].flags & IEEE80211_TX_RC_MCS) {
+                       WARN_ON(info->control.rates[i].idx > 76);
+                       continue;
+               }
 
-               /* Use min(data rate, max base rate) as CTS/RTS rate */
-               rate = &sband->bitrates[tx->rate_idx];
+               /* set up RTS protection if desired */
+               if (rts)
+                       info->control.rates[i].flags |=
+                               IEEE80211_TX_RC_USE_RTS_CTS;
 
-               for (idx = 0; idx < sband->n_bitrates; idx++) {
-                       if (sband->bitrates[idx].bitrate > rate->bitrate)
-                               continue;
-                       if (tx->sdata->basic_rates & BIT(idx) &&
-                           (baserate < 0 ||
-                            (sband->bitrates[baserate].bitrate
-                             < sband->bitrates[idx].bitrate)))
-                               baserate = idx;
+               /* RC is busted */
+               if (WARN_ON_ONCE(info->control.rates[i].idx >=
+                                sband->n_bitrates)) {
+                       info->control.rates[i].idx = -1;
+                       continue;
                }
 
-               if (baserate >= 0)
-                       info->control.rts_cts_rate_idx = baserate;
-               else
-                       info->control.rts_cts_rate_idx = 0;
+               rate = &sband->bitrates[info->control.rates[i].idx];
+
+               /* set up short preamble */
+               if (short_preamble &&
+                   rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
+                       info->control.rates[i].flags |=
+                               IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
+
+               /* set up G protection */
+               if (!rts && tx->sdata->vif.bss_conf.use_cts_prot &&
+                   rate->flags & IEEE80211_RATE_ERP_G)
+                       info->control.rates[i].flags |=
+                               IEEE80211_TX_RC_USE_CTS_PROTECT;
        }
 
+       return TX_CONTINUE;
+}
+
+static ieee80211_tx_result debug_noinline
+ieee80211_tx_h_misc(struct ieee80211_tx_data *tx)
+{
+       struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
+
        if (tx->sta)
-               info->control.aid = tx->sta->aid;
+               info->control.sta = &tx->sta->sta;
 
        return TX_CONTINUE;
 }
@@ -622,15 +635,32 @@ ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx)
        u8 *qc;
        int tid;
 
-       /* only for injected frames */
+       /*
+        * Packet injection may want to control the sequence
+        * number, if we have no matching interface then we
+        * neither assign one ourselves nor ask the driver to.
+        */
+       if (unlikely(!info->control.vif))
+               return TX_CONTINUE;
+
        if (unlikely(ieee80211_is_ctl(hdr->frame_control)))
                return TX_CONTINUE;
 
        if (ieee80211_hdrlen(hdr->frame_control) < 24)
                return TX_CONTINUE;
 
+       /*
+        * Anything but QoS data that has a sequence number field
+        * (is long enough) gets a sequence number from the global
+        * counter.
+        */
        if (!ieee80211_is_data_qos(hdr->frame_control)) {
+               /* driver should assign sequence number */
                info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
+               /* for pure STA mode without beacons, we can do it */
+               hdr->seq_ctrl = cpu_to_le16(tx->sdata->sequence_number);
+               tx->sdata->sequence_number += 0x10;
+               tx->sdata->sequence_number &= IEEE80211_SCTL_SEQ;
                return TX_CONTINUE;
        }
 
@@ -659,6 +689,7 @@ ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx)
 static ieee80211_tx_result debug_noinline
 ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
 {
+       struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
        struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
        size_t hdrlen, per_fragm, num_fragm, payload_len, left;
        struct sk_buff **frags, *first, *frag;
@@ -675,9 +706,7 @@ ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
         * This scenario is handled in __ieee80211_tx_prepare but extra
         * caution taken here as fragmented ampdu may cause Tx stop.
         */
-       if (WARN_ON(tx->flags & IEEE80211_TX_CTL_AMPDU ||
-                   skb_get_queue_mapping(tx->skb) >=
-                       ieee80211_num_regular_queues(&tx->local->hw)))
+       if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU))
                return TX_DROP;
 
        first = tx->skb;
@@ -711,20 +740,45 @@ ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
                                      IEEE80211_ENCRYPT_TAILROOM);
                if (!frag)
                        goto fail;
+
                /* Make sure that all fragments use the same priority so
                 * that they end up using the same TX queue */
                frag->priority = first->priority;
+
                skb_reserve(frag, tx->local->tx_headroom +
                                  IEEE80211_ENCRYPT_HEADROOM);
+
+               /* copy TX information */
+               info = IEEE80211_SKB_CB(frag);
+               memcpy(info, first->cb, sizeof(frag->cb));
+
+               /* copy/fill in 802.11 header */
                fhdr = (struct ieee80211_hdr *) skb_put(frag, hdrlen);
                memcpy(fhdr, first->data, hdrlen);
-               if (i == num_fragm - 2)
-                       fhdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREFRAGS);
                fhdr->seq_ctrl = cpu_to_le16(seq | ((i + 1) & IEEE80211_SCTL_FRAG));
+
+               if (i == num_fragm - 2) {
+                       /* clear MOREFRAGS bit for the last fragment */
+                       fhdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREFRAGS);
+               } else {
+                       /*
+                        * No multi-rate retries for fragmented frames, that
+                        * would completely throw off the NAV at other STAs.
+                        */
+                       info->control.rates[1].idx = -1;
+                       info->control.rates[2].idx = -1;
+                       info->control.rates[3].idx = -1;
+                       info->control.rates[4].idx = -1;
+                       BUILD_BUG_ON(IEEE80211_TX_MAX_RATES != 5);
+                       info->flags &= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE;
+               }
+
+               /* copy data */
                copylen = left > per_fragm ? per_fragm : left;
                memcpy(skb_put(frag, copylen), pos, copylen);
-               memcpy(frag->cb, first->cb, sizeof(frag->cb));
+
                skb_copy_queue_mapping(frag, first);
+
                frag->do_not_encrypt = first->do_not_encrypt;
 
                pos += copylen;
@@ -761,6 +815,8 @@ ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx)
                return ieee80211_crypto_tkip_encrypt(tx);
        case ALG_CCMP:
                return ieee80211_crypto_ccmp_encrypt(tx);
+       case ALG_AES_CMAC:
+               return ieee80211_crypto_aes_cmac_encrypt(tx);
        }
 
        /* not reached */
@@ -784,12 +840,10 @@ ieee80211_tx_h_calculate_duration(struct ieee80211_tx_data *tx)
                                              tx->extra_frag[0]->len);
 
        for (i = 0; i < tx->num_extra_frag; i++) {
-               if (i + 1 < tx->num_extra_frag) {
+               if (i + 1 < tx->num_extra_frag)
                        next_len = tx->extra_frag[i + 1]->len;
-               } else {
+               else
                        next_len = 0;
-                       tx->rate_idx = tx->last_frag_rate_idx;
-               }
 
                hdr = (struct ieee80211_hdr *)tx->extra_frag[i]->data;
                hdr->duration_id = ieee80211_duration(tx, 0, next_len);
@@ -842,12 +896,10 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx,
                (struct ieee80211_radiotap_header *) skb->data;
        struct ieee80211_supported_band *sband;
        int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len);
-       struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
 
        sband = tx->local->hw.wiphy->bands[tx->channel->band];
 
        skb->do_not_encrypt = 1;
-       info->flags |= IEEE80211_TX_CTL_INJECTED;
        tx->flags &= ~IEEE80211_TX_FRAGMENTED;
 
        /*
@@ -857,8 +909,6 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx,
         */
 
        while (!ret) {
-               int i, target_rate;
-
                ret = ieee80211_radiotap_iterator_next(&iterator);
 
                if (ret)
@@ -872,38 +922,6 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx,
                 * get_unaligned((type *)iterator.this_arg) to dereference
                 * iterator.this_arg for type "type" safely on all arches.
                */
-               case IEEE80211_RADIOTAP_RATE:
-                       /*
-                        * radiotap rate u8 is in 500kbps units eg, 0x02=1Mbps
-                        * ieee80211 rate int is in 100kbps units eg, 0x0a=1Mbps
-                        */
-                       target_rate = (*iterator.this_arg) * 5;
-                       for (i = 0; i < sband->n_bitrates; i++) {
-                               struct ieee80211_rate *r;
-
-                               r = &sband->bitrates[i];
-
-                               if (r->bitrate == target_rate) {
-                                       tx->rate_idx = i;
-                                       break;
-                               }
-                       }
-                       break;
-
-               case IEEE80211_RADIOTAP_ANTENNA:
-                       /*
-                        * radiotap uses 0 for 1st ant, mac80211 is 1 for
-                        * 1st ant
-                        */
-                       info->antenna_sel_tx = (*iterator.this_arg) + 1;
-                       break;
-
-#if 0
-               case IEEE80211_RADIOTAP_DBM_TX_POWER:
-                       control->power_level = *iterator.this_arg;
-                       break;
-#endif
-
                case IEEE80211_RADIOTAP_FLAGS:
                        if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) {
                                /*
@@ -961,7 +979,8 @@ __ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
        struct ieee80211_sub_if_data *sdata;
        struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
 
-       int hdrlen;
+       int hdrlen, tid;
+       u8 *qc, *state;
 
        memset(tx, 0, sizeof(*tx));
        tx->skb = skb;
@@ -969,8 +988,6 @@ __ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
        tx->local = local;
        tx->sdata = IEEE80211_DEV_TO_SUB_IF(dev);
        tx->channel = local->hw.conf.channel;
-       tx->rate_idx = -1;
-       tx->last_frag_rate_idx = -1;
        /*
         * Set this flag (used below to indicate "automatic fragmentation"),
         * it will be cleared/left by radiotap as desired.
@@ -979,7 +996,7 @@ __ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
 
        /* process and remove the injection radiotap header */
        sdata = IEEE80211_DEV_TO_SUB_IF(dev);
-       if (unlikely(sdata->vif.type == IEEE80211_IF_TYPE_MNTR)) {
+       if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED)) {
                if (__ieee80211_parse_tx_radiotap(tx, skb) == TX_DROP)
                        return TX_DROP;
 
@@ -994,6 +1011,15 @@ __ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
 
        tx->sta = sta_info_get(local, hdr->addr1);
 
+       if (tx->sta && ieee80211_is_data_qos(hdr->frame_control)) {
+               qc = ieee80211_get_qos_ctl(hdr);
+               tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
+
+               state = &tx->sta->ampdu_mlme.tid_state_tx[tid];
+               if (*state == HT_AGG_STATE_OPERATIONAL)
+                       info->flags |= IEEE80211_TX_CTL_AMPDU;
+       }
+
        if (is_multicast_ether_addr(hdr->addr1)) {
                tx->flags &= ~IEEE80211_TX_UNICAST;
                info->flags |= IEEE80211_TX_CTL_NO_ACK;
@@ -1005,7 +1031,6 @@ __ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
        if (tx->flags & IEEE80211_TX_FRAGMENTED) {
                if ((tx->flags & IEEE80211_TX_UNICAST) &&
                    skb->len + FCS_LEN > local->fragmentation_threshold &&
-                   !local->ops->set_frag_threshold &&
                    !(info->flags & IEEE80211_TX_CTL_AMPDU))
                        tx->flags |= IEEE80211_TX_FRAGMENTED;
                else
@@ -1030,14 +1055,14 @@ __ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
 /*
  * NB: @tx is uninitialised when passed in here
  */
-static int ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
-                               struct sk_buff *skb,
-                               struct net_device *mdev)
+static int ieee80211_tx_prepare(struct ieee80211_local *local,
+                               struct ieee80211_tx_data *tx,
+                               struct sk_buff *skb)
 {
        struct net_device *dev;
 
        dev = dev_get_by_index(&init_net, skb->iif);
-       if (unlikely(dev && !is_ieee80211_device(dev, mdev))) {
+       if (unlikely(dev && !is_ieee80211_device(local, dev))) {
                dev_put(dev);
                dev = NULL;
        }
@@ -1058,10 +1083,7 @@ static int __ieee80211_tx(struct ieee80211_local *local, struct sk_buff *skb,
        if (skb) {
                if (netif_subqueue_stopped(local->mdev, skb))
                        return IEEE80211_TX_AGAIN;
-               info =  IEEE80211_SKB_CB(skb);
 
-               ieee80211_dump_frame(wiphy_name(local->hw.wiphy),
-                                    "TX to low-level driver", skb);
                ret = local->ops->tx(local_to_hw(local), skb);
                if (ret)
                        return IEEE80211_TX_AGAIN;
@@ -1073,27 +1095,12 @@ static int __ieee80211_tx(struct ieee80211_local *local, struct sk_buff *skb,
                        if (!tx->extra_frag[i])
                                continue;
                        info = IEEE80211_SKB_CB(tx->extra_frag[i]);
-                       info->flags &= ~(IEEE80211_TX_CTL_USE_RTS_CTS |
-                                        IEEE80211_TX_CTL_USE_CTS_PROTECT |
-                                        IEEE80211_TX_CTL_CLEAR_PS_FILT |
+                       info->flags &= ~(IEEE80211_TX_CTL_CLEAR_PS_FILT |
                                         IEEE80211_TX_CTL_FIRST_FRAGMENT);
                        if (netif_subqueue_stopped(local->mdev,
                                                   tx->extra_frag[i]))
                                return IEEE80211_TX_FRAG_AGAIN;
-                       if (i == tx->num_extra_frag) {
-                               info->tx_rate_idx = tx->last_frag_rate_idx;
-
-                               if (tx->flags & IEEE80211_TX_PROBE_LAST_FRAG)
-                                       info->flags |=
-                                               IEEE80211_TX_CTL_RATE_CTRL_PROBE;
-                               else
-                                       info->flags &=
-                                               ~IEEE80211_TX_CTL_RATE_CTRL_PROBE;
-                       }
 
-                       ieee80211_dump_frame(wiphy_name(local->hw.wiphy),
-                                            "TX to low-level driver",
-                                            tx->extra_frag[i]);
                        ret = local->ops->tx(local_to_hw(local),
                                            tx->extra_frag[i]);
                        if (ret)
@@ -1201,7 +1208,7 @@ retry:
                 * queues, there's no reason for a driver to reject
                 * a frame there, warn and drop it.
                 */
-               if (WARN_ON(queue >= ieee80211_num_regular_queues(&local->hw)))
+               if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU))
                        goto drop;
 
                store = &local->pending_packet[queue];
@@ -1229,9 +1236,6 @@ retry:
                store->skb = skb;
                store->extra_frag = tx.extra_frag;
                store->num_extra_frag = tx.num_extra_frag;
-               store->last_frag_rate_idx = tx.last_frag_rate_idx;
-               store->last_frag_rate_ctrl_probe =
-                       !!(tx.flags & IEEE80211_TX_PROBE_LAST_FRAG);
        }
  out:
        rcu_read_unlock();
@@ -1289,20 +1293,26 @@ static int ieee80211_skb_resize(struct ieee80211_local *local,
        return 0;
 }
 
-int ieee80211_master_start_xmit(struct sk_buff *skb,
-                               struct net_device *dev)
+int ieee80211_master_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
+       struct ieee80211_master_priv *mpriv = netdev_priv(dev);
+       struct ieee80211_local *local = mpriv->local;
        struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
        struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
        struct net_device *odev = NULL;
        struct ieee80211_sub_if_data *osdata;
        int headroom;
        bool may_encrypt;
+       enum {
+               NOT_MONITOR,
+               FOUND_SDATA,
+               UNKNOWN_ADDRESS,
+       } monitor_iface = NOT_MONITOR;
        int ret;
 
        if (skb->iif)
                odev = dev_get_by_index(&init_net, skb->iif);
-       if (unlikely(odev && !is_ieee80211_device(odev, dev))) {
+       if (unlikely(odev && !is_ieee80211_device(local, odev))) {
                dev_put(odev);
                odev = NULL;
        }
@@ -1315,6 +1325,19 @@ int ieee80211_master_start_xmit(struct sk_buff *skb,
                return 0;
        }
 
+       if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
+           local->hw.conf.dynamic_ps_timeout > 0) {
+               if (local->hw.conf.flags & IEEE80211_CONF_PS) {
+                       ieee80211_stop_queues_by_reason(&local->hw,
+                                       IEEE80211_QUEUE_STOP_REASON_PS);
+                       queue_work(local->hw.workqueue,
+                                       &local->dynamic_ps_disable_work);
+               }
+
+               mod_timer(&local->dynamic_ps_timer, jiffies +
+                       msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
+       }
+
        memset(info, 0, sizeof(*info));
 
        info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
@@ -1323,15 +1346,57 @@ int ieee80211_master_start_xmit(struct sk_buff *skb,
 
        if (ieee80211_vif_is_mesh(&osdata->vif) &&
            ieee80211_is_data(hdr->frame_control)) {
-               if (ieee80211_is_data(hdr->frame_control)) {
-                       if (is_multicast_ether_addr(hdr->addr3))
-                               memcpy(hdr->addr1, hdr->addr3, ETH_ALEN);
-                       else
-                               if (mesh_nexthop_lookup(skb, osdata))
-                                       return  0;
-                       if (memcmp(odev->dev_addr, hdr->addr4, ETH_ALEN) != 0)
-                               IEEE80211_IFSTA_MESH_CTR_INC(&osdata->u.mesh,
-                                                            fwded_frames);
+               if (is_multicast_ether_addr(hdr->addr3))
+                       memcpy(hdr->addr1, hdr->addr3, ETH_ALEN);
+               else
+                       if (mesh_nexthop_lookup(skb, osdata)) {
+                               dev_put(odev);
+                               return 0;
+                       }
+               if (memcmp(odev->dev_addr, hdr->addr4, ETH_ALEN) != 0)
+                       IEEE80211_IFSTA_MESH_CTR_INC(&osdata->u.mesh,
+                                                           fwded_frames);
+       } else if (unlikely(osdata->vif.type == NL80211_IFTYPE_MONITOR)) {
+               struct ieee80211_sub_if_data *sdata;
+               int hdrlen;
+               u16 len_rthdr;
+
+               info->flags |= IEEE80211_TX_CTL_INJECTED;
+               monitor_iface = UNKNOWN_ADDRESS;
+
+               len_rthdr = ieee80211_get_radiotap_len(skb->data);
+               hdr = (struct ieee80211_hdr *)skb->data + len_rthdr;
+               hdrlen = ieee80211_hdrlen(hdr->frame_control);
+
+               /* check the header is complete in the frame */
+               if (likely(skb->len >= len_rthdr + hdrlen)) {
+                       /*
+                        * We process outgoing injected frames that have a
+                        * local address we handle as though they are our
+                        * own frames.
+                        * This code here isn't entirely correct, the local
+                        * MAC address is not necessarily enough to find
+                        * the interface to use; for that proper VLAN/WDS
+                        * support we will need a different mechanism.
+                        */
+
+                       rcu_read_lock();
+                       list_for_each_entry_rcu(sdata, &local->interfaces,
+                                               list) {
+                               if (!netif_running(sdata->dev))
+                                       continue;
+                               if (compare_ether_addr(sdata->dev->dev_addr,
+                                                      hdr->addr2)) {
+                                       dev_hold(sdata->dev);
+                                       dev_put(odev);
+                                       osdata = sdata;
+                                       odev = osdata->dev;
+                                       skb->iif = sdata->dev->ifindex;
+                                       monitor_iface = FOUND_SDATA;
+                                       break;
+                               }
+                       }
+                       rcu_read_unlock();
                }
        }
 
@@ -1349,7 +1414,12 @@ int ieee80211_master_start_xmit(struct sk_buff *skb,
                return 0;
        }
 
-       info->control.vif = &osdata->vif;
+       if (osdata->vif.type == NL80211_IFTYPE_AP_VLAN)
+               osdata = container_of(osdata->bss,
+                                     struct ieee80211_sub_if_data,
+                                     u.ap);
+       if (likely(monitor_iface != UNKNOWN_ADDRESS))
+               info->control.vif = &osdata->vif;
        ret = ieee80211_tx(odev, skb);
        dev_put(odev);
 
@@ -1429,8 +1499,8 @@ fail:
 int ieee80211_subif_start_xmit(struct sk_buff *skb,
                               struct net_device *dev)
 {
-       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
-       struct ieee80211_sub_if_data *sdata;
+       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+       struct ieee80211_local *local = sdata->local;
        int ret = 1, head_need;
        u16 ethertype, hdrlen,  meshhdrlen = 0;
        __le16 fc;
@@ -1442,7 +1512,6 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
        struct sta_info *sta;
        u32 sta_flags = 0;
 
-       sdata = IEEE80211_DEV_TO_SUB_IF(dev);
        if (unlikely(skb->len < ETH_HLEN)) {
                ret = 0;
                goto fail;
@@ -1457,8 +1526,8 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
        fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
 
        switch (sdata->vif.type) {
-       case IEEE80211_IF_TYPE_AP:
-       case IEEE80211_IF_TYPE_VLAN:
+       case NL80211_IFTYPE_AP:
+       case NL80211_IFTYPE_AP_VLAN:
                fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
                /* DA BSSID SA */
                memcpy(hdr.addr1, skb->data, ETH_ALEN);
@@ -1466,7 +1535,7 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
                memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
                hdrlen = 24;
                break;
-       case IEEE80211_IF_TYPE_WDS:
+       case NL80211_IFTYPE_WDS:
                fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
                /* RA TA DA SA */
                memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN);
@@ -1476,24 +1545,56 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
                hdrlen = 30;
                break;
 #ifdef CONFIG_MAC80211_MESH
-       case IEEE80211_IF_TYPE_MESH_POINT:
+       case NL80211_IFTYPE_MESH_POINT:
                fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
-               /* RA TA DA SA */
-               memset(hdr.addr1, 0, ETH_ALEN);
-               memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN);
-               memcpy(hdr.addr3, skb->data, ETH_ALEN);
-               memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
                if (!sdata->u.mesh.mshcfg.dot11MeshTTL) {
                        /* Do not send frames with mesh_ttl == 0 */
                        sdata->u.mesh.mshstats.dropped_frames_ttl++;
                        ret = 0;
                        goto fail;
                }
-               meshhdrlen = ieee80211_new_mesh_header(&mesh_hdr, sdata);
+               memset(&mesh_hdr, 0, sizeof(mesh_hdr));
+
+               if (compare_ether_addr(dev->dev_addr,
+                                         skb->data + ETH_ALEN) == 0) {
+                       /* RA TA DA SA */
+                       memset(hdr.addr1, 0, ETH_ALEN);
+                       memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN);
+                       memcpy(hdr.addr3, skb->data, ETH_ALEN);
+                       memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
+                       meshhdrlen = ieee80211_new_mesh_header(&mesh_hdr, sdata);
+               } else {
+                       /* packet from other interface */
+                       struct mesh_path *mppath;
+
+                       memset(hdr.addr1, 0, ETH_ALEN);
+                       memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN);
+                       memcpy(hdr.addr4, dev->dev_addr, ETH_ALEN);
+
+                       if (is_multicast_ether_addr(skb->data))
+                               memcpy(hdr.addr3, skb->data, ETH_ALEN);
+                       else {
+                               rcu_read_lock();
+                               mppath = mpp_path_lookup(skb->data, sdata);
+                               if (mppath)
+                                       memcpy(hdr.addr3, mppath->mpp, ETH_ALEN);
+                               else
+                                       memset(hdr.addr3, 0xff, ETH_ALEN);
+                               rcu_read_unlock();
+                       }
+
+                       mesh_hdr.flags |= MESH_FLAGS_AE_A5_A6;
+                       mesh_hdr.ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
+                       put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &mesh_hdr.seqnum);
+                       memcpy(mesh_hdr.eaddr1, skb->data, ETH_ALEN);
+                       memcpy(mesh_hdr.eaddr2, skb->data + ETH_ALEN, ETH_ALEN);
+                       sdata->u.mesh.mesh_seqnum++;
+                       meshhdrlen = 18;
+               }
                hdrlen = 30;
                break;
 #endif
-       case IEEE80211_IF_TYPE_STA:
+       case NL80211_IFTYPE_STATION:
                fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
                /* BSSID SA DA */
                memcpy(hdr.addr1, sdata->u.sta.bssid, ETH_ALEN);
@@ -1501,7 +1602,7 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
                memcpy(hdr.addr3, skb->data, ETH_ALEN);
                hdrlen = 24;
                break;
-       case IEEE80211_IF_TYPE_IBSS:
+       case NL80211_IFTYPE_ADHOC:
                /* DA SA BSSID */
                memcpy(hdr.addr1, skb->data, ETH_ALEN);
                memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
@@ -1544,12 +1645,10 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
                       compare_ether_addr(dev->dev_addr,
                                          skb->data + ETH_ALEN) == 0))) {
 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
-               DECLARE_MAC_BUF(mac);
-
                if (net_ratelimit())
-                       printk(KERN_DEBUG "%s: dropped frame to %s"
+                       printk(KERN_DEBUG "%s: dropped frame to %pM"
                               " (unauthorized port)\n", dev->name,
-                              print_mac(mac, hdr.addr1));
+                              hdr.addr1);
 #endif
 
                I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
@@ -1708,10 +1807,7 @@ void ieee80211_tx_pending(unsigned long data)
                store = &local->pending_packet[i];
                tx.extra_frag = store->extra_frag;
                tx.num_extra_frag = store->num_extra_frag;
-               tx.last_frag_rate_idx = store->last_frag_rate_idx;
                tx.flags = 0;
-               if (store->last_frag_rate_ctrl_probe)
-                       tx.flags |= IEEE80211_TX_PROBE_LAST_FRAG;
                ret = __ieee80211_tx(local, store->skb, &tx);
                if (ret) {
                        if (ret == IEEE80211_TX_FRAG_AGAIN)
@@ -1726,8 +1822,7 @@ void ieee80211_tx_pending(unsigned long data)
 
 /* functions for drivers to get certain frames */
 
-static void ieee80211_beacon_add_tim(struct ieee80211_local *local,
-                                    struct ieee80211_if_ap *bss,
+static void ieee80211_beacon_add_tim(struct ieee80211_if_ap *bss,
                                     struct sk_buff *skb,
                                     struct beacon_data *beacon)
 {
@@ -1795,14 +1890,11 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
        struct ieee80211_local *local = hw_to_local(hw);
        struct sk_buff *skb = NULL;
        struct ieee80211_tx_info *info;
-       struct net_device *bdev;
        struct ieee80211_sub_if_data *sdata = NULL;
        struct ieee80211_if_ap *ap = NULL;
        struct ieee80211_if_sta *ifsta = NULL;
-       struct rate_selection rsel;
        struct beacon_data *beacon;
        struct ieee80211_supported_band *sband;
-       int *num_beacons;
        enum ieee80211_band band = local->hw.conf.channel->band;
 
        sband = local->hw.wiphy->bands[band];
@@ -1810,9 +1902,8 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
        rcu_read_lock();
 
        sdata = vif_to_sdata(vif);
-       bdev = sdata->dev;
 
-       if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
+       if (sdata->vif.type == NL80211_IFTYPE_AP) {
                ap = &sdata->u.ap;
                beacon = rcu_dereference(ap->beacon);
                if (ap && beacon) {
@@ -1838,23 +1929,21 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
                         * of the tim bitmap in mac80211 and the driver.
                         */
                        if (local->tim_in_locked_section) {
-                               ieee80211_beacon_add_tim(local, ap, skb, beacon);
+                               ieee80211_beacon_add_tim(ap, skb, beacon);
                        } else {
                                unsigned long flags;
 
                                spin_lock_irqsave(&local->sta_lock, flags);
-                               ieee80211_beacon_add_tim(local, ap, skb, beacon);
+                               ieee80211_beacon_add_tim(ap, skb, beacon);
                                spin_unlock_irqrestore(&local->sta_lock, flags);
                        }
 
                        if (beacon->tail)
                                memcpy(skb_put(skb, beacon->tail_len),
                                       beacon->tail, beacon->tail_len);
-
-                       num_beacons = &ap->num_beacons;
                } else
                        goto out;
-       } else if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
+       } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
                struct ieee80211_hdr *hdr;
                ifsta = &sdata->u.sta;
 
@@ -1869,8 +1958,6 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
                hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
                                                 IEEE80211_STYPE_BEACON);
 
-               num_beacons = &ifsta->num_beacons;
-#ifdef CONFIG_MAC80211_MESH
        } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
                struct ieee80211_mgmt *mgmt;
                u8 *pos;
@@ -1898,9 +1985,6 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
                *pos++ = 0x0;
 
                mesh_mgmt_ies_add(skb, sdata);
-
-               num_beacons = &sdata->u.mesh.num_beacons;
-#endif
        } else {
                WARN_ON(1);
                goto out;
@@ -1911,34 +1995,23 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
        skb->do_not_encrypt = 1;
 
        info->band = band;
-       rate_control_get_rate(local->mdev, sband, skb, &rsel);
-
-       if (unlikely(rsel.rate_idx < 0)) {
-               if (net_ratelimit()) {
-                       printk(KERN_DEBUG "%s: ieee80211_beacon_get: "
-                              "no rate found\n",
-                              wiphy_name(local->hw.wiphy));
-               }
-               dev_kfree_skb_any(skb);
-               skb = NULL;
-               goto out;
-       }
+       /*
+        * XXX: For now, always use the lowest rate
+        */
+       info->control.rates[0].idx = 0;
+       info->control.rates[0].count = 1;
+       info->control.rates[1].idx = -1;
+       info->control.rates[2].idx = -1;
+       info->control.rates[3].idx = -1;
+       info->control.rates[4].idx = -1;
+       BUILD_BUG_ON(IEEE80211_TX_MAX_RATES != 5);
 
        info->control.vif = vif;
-       info->tx_rate_idx = rsel.rate_idx;
 
        info->flags |= IEEE80211_TX_CTL_NO_ACK;
        info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
        info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
-       if (sdata->bss_conf.use_short_preamble &&
-           sband->bitrates[rsel.rate_idx].flags & IEEE80211_RATE_SHORT_PREAMBLE)
-               info->flags |= IEEE80211_TX_CTL_SHORT_PREAMBLE;
-
-       info->antenna_sel_tx = local->hw.conf.antenna_sel_tx;
-       info->control.retry_limit = 1;
-
-       (*num_beacons)++;
-out:
+ out:
        rcu_read_unlock();
        return skb;
 }
@@ -1983,14 +2056,12 @@ ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
        struct sk_buff *skb = NULL;
        struct sta_info *sta;
        struct ieee80211_tx_data tx;
-       struct net_device *bdev;
        struct ieee80211_sub_if_data *sdata;
        struct ieee80211_if_ap *bss = NULL;
        struct beacon_data *beacon;
        struct ieee80211_tx_info *info;
 
        sdata = vif_to_sdata(vif);
-       bdev = sdata->dev;
        bss = &sdata->u.ap;
 
        if (!bss)
@@ -1999,7 +2070,7 @@ ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
        rcu_read_lock();
        beacon = rcu_dereference(bss->beacon);
 
-       if (sdata->vif.type != IEEE80211_IF_TYPE_AP || !beacon || !beacon->head)
+       if (sdata->vif.type != NL80211_IFTYPE_AP || !beacon || !beacon->head)
                goto out;
 
        if (bss->dtim_count != 0)
@@ -2021,7 +2092,7 @@ ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
                                cpu_to_le16(IEEE80211_FCTL_MOREDATA);
                }
 
-               if (!ieee80211_tx_prepare(&tx, skb, local->mdev))
+               if (!ieee80211_tx_prepare(local, &tx, skb))
                        break;
                dev_kfree_skb_any(skb);
        }