[NET]: Introduce and use print_mac() and DECLARE_MAC_BUF()
[deliverable/linux.git] / net / mac80211 / tx.c
index 01e7a734f867fee994f5ee6e454ec7da0baf3c48..04b4fa9c69ea6ab9442e7177595fd573367c2c77 100644 (file)
@@ -17,6 +17,8 @@
 #include <linux/skbuff.h>
 #include <linux/etherdevice.h>
 #include <linux/bitmap.h>
+#include <linux/rcupdate.h>
+#include <net/net_namespace.h>
 #include <net/ieee80211_radiotap.h>
 #include <net/cfg80211.h>
 #include <net/mac80211.h>
@@ -52,6 +54,7 @@ static void ieee80211_dump_frame(const char *ifname, const char *title,
        const struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
        u16 fc;
        int hdrlen;
+       DECLARE_MAC_BUF(mac);
 
        printk(KERN_DEBUG "%s: %s (len=%d)", ifname, title, skb->len);
        if (skb->len < 4) {
@@ -67,13 +70,13 @@ static void ieee80211_dump_frame(const char *ifname, const char *title,
                printk(" FC=0x%04x DUR=0x%04x",
                       fc, le16_to_cpu(hdr->duration_id));
        if (hdrlen >= 10)
-               printk(" A1=" MAC_FMT, MAC_ARG(hdr->addr1));
+               printk(" A1=%s", print_mac(mac, hdr->addr1));
        if (hdrlen >= 16)
-               printk(" A2=" MAC_FMT, MAC_ARG(hdr->addr2));
+               printk(" A2=%s", print_mac(mac, hdr->addr2));
        if (hdrlen >= 24)
-               printk(" A3=" MAC_FMT, MAC_ARG(hdr->addr3));
+               printk(" A3=%s", print_mac(mac, hdr->addr3));
        if (hdrlen >= 30)
-               printk(" A4=" MAC_FMT, MAC_ARG(hdr->addr4));
+               printk(" A4=%s", print_mac(mac, hdr->addr4));
        printk("\n");
 }
 #else /* CONFIG_MAC80211_LOWTX_FRAME_DUMP */
@@ -173,7 +176,7 @@ static u16 ieee80211_duration(struct ieee80211_txrx_data *tx, int group_addr,
         * to closest integer */
 
        dur = ieee80211_frame_duration(local, 10, rate, erp,
-                                      tx->sdata->short_preamble);
+                      tx->sdata->flags & IEEE80211_SDATA_SHORT_PREAMBLE);
 
        if (next_frag_len) {
                /* Frame is fragmented: duration increases with time needed to
@@ -181,8 +184,9 @@ static u16 ieee80211_duration(struct ieee80211_txrx_data *tx, int group_addr,
                dur *= 2; /* ACK + SIFS */
                /* next fragment */
                dur += ieee80211_frame_duration(local, next_frag_len,
-                                               txrate->rate, erp,
-                                               tx->sdata->short_preamble);
+                               txrate->rate, erp,
+                               tx->sdata->flags &
+                                       IEEE80211_SDATA_SHORT_PREAMBLE);
        }
 
        return dur;
@@ -233,9 +237,10 @@ ieee80211_tx_h_check_assoc(struct ieee80211_txrx_data *tx)
                             tx->sdata->type != IEEE80211_IF_TYPE_IBSS &&
                             (tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) {
 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
+                       DECLARE_MAC_BUF(mac);
                        printk(KERN_DEBUG "%s: dropped data frame to not "
-                              "associated station " MAC_FMT "\n",
-                              tx->dev->name, MAC_ARG(hdr->addr1));
+                              "associated station %s\n",
+                              tx->dev->name, print_mac(mac, hdr->addr1));
 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
                        I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
                        return TXRX_DROP;
@@ -256,9 +261,10 @@ ieee80211_tx_h_check_assoc(struct ieee80211_txrx_data *tx)
        if (unlikely(!tx->u.tx.mgmt_interface && tx->sdata->ieee802_1x &&
                     !(sta_flags & WLAN_STA_AUTHORIZED))) {
 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
-               printk(KERN_DEBUG "%s: dropped frame to " MAC_FMT
+               DECLARE_MAC_BUF(mac);
+               printk(KERN_DEBUG "%s: dropped frame to %s"
                       " (unauthorized port)\n", tx->dev->name,
-                      MAC_ARG(hdr->addr1));
+                      print_mac(mac, hdr->addr1));
 #endif
                I802_DEBUG_INC(tx->local->tx_handlers_drop_unauth_port);
                return TXRX_DROP;
@@ -354,6 +360,7 @@ static inline ieee80211_txrx_result
 ieee80211_tx_h_unicast_ps_buf(struct ieee80211_txrx_data *tx)
 {
        struct sta_info *sta = tx->sta;
+       DECLARE_MAC_BUF(mac);
 
        if (unlikely(!sta ||
                     ((tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT &&
@@ -363,9 +370,9 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_txrx_data *tx)
        if (unlikely((sta->flags & WLAN_STA_PS) && !sta->pspoll)) {
                struct ieee80211_tx_packet_data *pkt_data;
 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
-               printk(KERN_DEBUG "STA " MAC_FMT " aid %d: PS buffer (entries "
+               printk(KERN_DEBUG "STA %s aid %d: PS buffer (entries "
                       "before %d)\n",
-                      MAC_ARG(sta->addr), sta->aid,
+                      print_mac(mac, sta->addr), sta->aid,
                       skb_queue_len(&sta->ps_tx_buf));
 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
                sta->flags |= WLAN_STA_TIM;
@@ -374,9 +381,9 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_txrx_data *tx)
                if (skb_queue_len(&sta->ps_tx_buf) >= STA_MAX_TX_BUFFER) {
                        struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf);
                        if (net_ratelimit()) {
-                               printk(KERN_DEBUG "%s: STA " MAC_FMT " TX "
+                               printk(KERN_DEBUG "%s: STA %s TX "
                                       "buffer full - dropping oldest frame\n",
-                                      tx->dev->name, MAC_ARG(sta->addr));
+                                      tx->dev->name, print_mac(mac, sta->addr));
                        }
                        dev_kfree_skb(old);
                } else
@@ -396,9 +403,9 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_txrx_data *tx)
        }
 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
        else if (unlikely(sta->flags & WLAN_STA_PS)) {
-               printk(KERN_DEBUG "%s: STA " MAC_FMT " in PS mode, but pspoll "
+               printk(KERN_DEBUG "%s: STA %s in PS mode, but pspoll "
                       "set -> send frame\n", tx->dev->name,
-                      MAC_ARG(sta->addr));
+                      print_mac(mac, sta->addr));
        }
 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
        sta->pspoll = 0;
@@ -425,23 +432,22 @@ ieee80211_tx_h_ps_buf(struct ieee80211_txrx_data *tx)
 static ieee80211_txrx_result
 ieee80211_tx_h_select_key(struct ieee80211_txrx_data *tx)
 {
-       if (tx->sta)
-               tx->u.tx.control->key_idx = tx->sta->key_idx_compression;
-       else
-               tx->u.tx.control->key_idx = HW_KEY_IDX_INVALID;
+       struct ieee80211_key *key;
 
        if (unlikely(tx->u.tx.control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT))
                tx->key = NULL;
-       else if (tx->sta && tx->sta->key)
-               tx->key = tx->sta->key;
-       else if (tx->sdata->default_key)
-               tx->key = tx->sdata->default_key;
+       else if (tx->sta && (key = rcu_dereference(tx->sta->key)))
+               tx->key = key;
+       else if ((key = rcu_dereference(tx->sdata->default_key)))
+               tx->key = key;
        else if (tx->sdata->drop_unencrypted &&
                 !(tx->sdata->eapol && ieee80211_is_eapol(tx->skb))) {
                I802_DEBUG_INC(tx->local->tx_handlers_drop_unencrypted);
                return TXRX_DROP;
-       } else
+       } else {
                tx->key = NULL;
+               tx->u.tx.control->flags |= IEEE80211_TXCTL_DO_NOT_ENCRYPT;
+       }
 
        if (tx->key) {
                tx->key->tx_rx_count++;
@@ -538,14 +544,13 @@ ieee80211_tx_h_fragment(struct ieee80211_txrx_data *tx)
 
 static int wep_encrypt_skb(struct ieee80211_txrx_data *tx, struct sk_buff *skb)
 {
-       if (tx->key->force_sw_encrypt) {
+       if (!(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) {
                if (ieee80211_wep_encrypt(tx->local, skb, tx->key))
                        return -1;
        } else {
-               tx->u.tx.control->key_idx = tx->key->hw_key_idx;
-               if (tx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV) {
-                       if (ieee80211_wep_add_iv(tx->local, skb, tx->key) ==
-                           NULL)
+               tx->u.tx.control->key_idx = tx->key->conf.hw_key_idx;
+               if (tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV) {
+                       if (!ieee80211_wep_add_iv(tx->local, skb, tx->key))
                                return -1;
                }
        }
@@ -560,7 +565,7 @@ ieee80211_tx_h_wep_encrypt(struct ieee80211_txrx_data *tx)
 
        fc = le16_to_cpu(hdr->frame_control);
 
-       if (!tx->key || tx->key->alg != ALG_WEP ||
+       if (!tx->key || tx->key->conf.alg != ALG_WEP ||
            ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
             ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
              (fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)))
@@ -613,7 +618,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_txrx_data *tx)
        if (!tx->u.tx.rate)
                return TXRX_DROP;
        if (tx->u.tx.mode->mode == MODE_IEEE80211G &&
-           tx->sdata->use_protection &&
+           (tx->sdata->flags & IEEE80211_SDATA_USE_PROTECTION) &&
            (tx->flags & IEEE80211_TXRXD_FRAGMENTED) && extra.nonerp) {
                tx->u.tx.last_frag_rate = tx->u.tx.rate;
                if (extra.probe)
@@ -670,7 +675,7 @@ ieee80211_tx_h_misc(struct ieee80211_txrx_data *tx)
        if (mode->mode == MODE_IEEE80211G &&
            (tx->u.tx.rate->flags & IEEE80211_RATE_ERP) &&
            (tx->flags & IEEE80211_TXRXD_TXUNICAST) &&
-           tx->sdata->use_protection &&
+           (tx->sdata->flags & IEEE80211_SDATA_USE_PROTECTION) &&
            !(control->flags & IEEE80211_TXCTL_USE_RTS_CTS))
                control->flags |= IEEE80211_TXCTL_USE_CTS_PROTECT;
 
@@ -679,7 +684,7 @@ ieee80211_tx_h_misc(struct ieee80211_txrx_data *tx)
         * available on the network at the current point in time. */
        if (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) &&
            (tx->u.tx.rate->flags & IEEE80211_RATE_PREAMBLE2) &&
-           tx->sdata->short_preamble &&
+           (tx->sdata->flags & IEEE80211_SDATA_SHORT_PREAMBLE) &&
            (!tx->sta || (tx->sta->flags & WLAN_STA_SHORT_PREAMBLE))) {
                tx->u.tx.control->tx_rate = tx->u.tx.rate->val2;
        }
@@ -723,6 +728,15 @@ ieee80211_tx_h_misc(struct ieee80211_txrx_data *tx)
                }
        }
 
+       /*
+        * Tell hardware to not encrypt when we had sw crypto.
+        * Because we use the same flag to internally indicate that
+        * no (software) encryption should be done, we have to set it
+        * after all crypto handlers.
+        */
+       if (tx->key && !(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
+               tx->u.tx.control->flags |= IEEE80211_TXCTL_DO_NOT_ENCRYPT;
+
        return TXRX_CONTINUE;
 }
 
@@ -745,8 +759,6 @@ ieee80211_tx_h_load_stats(struct ieee80211_txrx_data *tx)
         * 1 usec = 1/8 * (1080 / 10) = 13.5 */
 
        if (mode->mode == MODE_IEEE80211A ||
-           mode->mode == MODE_ATHEROS_TURBO ||
-           mode->mode == MODE_ATHEROS_TURBOG ||
            (mode->mode == MODE_IEEE80211G &&
             tx->u.tx.rate->flags & IEEE80211_RATE_ERP))
                hdrtime = CHAN_UTIL_HDR_SHORT;
@@ -834,7 +846,6 @@ __ieee80211_parse_tx_radiotap(
         */
 
        control->retry_limit = 1; /* no retry */
-       control->key_idx = -1; /* no encryption key */
        control->flags &= ~(IEEE80211_TXCTL_USE_RTS_CTS |
                            IEEE80211_TXCTL_USE_CTS_PROTECT);
        control->flags |= IEEE80211_TXCTL_DO_NOT_ENCRYPT |
@@ -952,8 +963,6 @@ __ieee80211_tx_prepare(struct ieee80211_txrx_data *tx,
        tx->dev = dev; /* use original interface */
        tx->local = local;
        tx->sdata = IEEE80211_DEV_TO_SUB_IF(dev);
-       tx->sta = sta_info_get(local, hdr->addr1);
-       tx->fc = le16_to_cpu(hdr->frame_control);
 
        /*
         * set defaults for things that can be set by
@@ -978,6 +987,8 @@ __ieee80211_tx_prepare(struct ieee80211_txrx_data *tx,
                res = TXRX_QUEUED; /* indication it was monitor packet */
        }
 
+       tx->sta = sta_info_get(local, hdr->addr1);
+       tx->fc = le16_to_cpu(hdr->frame_control);
        tx->u.tx.control = control;
        if (is_multicast_ether_addr(hdr->addr1)) {
                tx->flags &= ~IEEE80211_TXRXD_TXUNICAST;
@@ -1020,7 +1031,7 @@ static int inline ieee80211_tx_prepare(struct ieee80211_txrx_data *tx,
        struct net_device *dev;
 
        pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
-       dev = dev_get_by_index(pkt_data->ifindex);
+       dev = dev_get_by_index(&init_net, pkt_data->ifindex);
        if (unlikely(dev && !is_ieee80211_device(dev, mdev))) {
                dev_put(dev);
                dev = NULL;
@@ -1113,6 +1124,12 @@ static int ieee80211_tx(struct net_device *dev, struct sk_buff *skb,
                return 0;
        }
 
+       /*
+        * key references are protected using RCU and this requires that
+        * we are in a read-site RCU section during receive processing
+        */
+       rcu_read_lock();
+
        sta = tx.sta;
        tx.u.tx.mgmt_interface = mgmt;
        tx.u.tx.mode = local->hw.conf.mode;
@@ -1140,6 +1157,7 @@ static int ieee80211_tx(struct net_device *dev, struct sk_buff *skb,
 
        if (unlikely(res == TXRX_QUEUED)) {
                I802_DEBUG_INC(local->tx_handlers_queued);
+               rcu_read_unlock();
                return 0;
        }
 
@@ -1197,6 +1215,7 @@ retry:
                store->last_frag_rate_ctrl_probe =
                        !!(tx.flags & IEEE80211_TXRXD_TXPROBE_LAST_FRAG);
        }
+       rcu_read_unlock();
        return 0;
 
  drop:
@@ -1206,6 +1225,7 @@ retry:
                if (tx.u.tx.extra_frag[i])
                        dev_kfree_skb(tx.u.tx.extra_frag[i]);
        kfree(tx.u.tx.extra_frag);
+       rcu_read_unlock();
        return 0;
 }
 
@@ -1228,7 +1248,7 @@ int ieee80211_master_start_xmit(struct sk_buff *skb,
        memset(&control, 0, sizeof(struct ieee80211_tx_control));
 
        if (pkt_data->ifindex)
-               odev = dev_get_by_index(pkt_data->ifindex);
+               odev = dev_get_by_index(&init_net, pkt_data->ifindex);
        if (unlikely(odev && !is_ieee80211_device(odev, dev))) {
                dev_put(odev);
                odev = NULL;
@@ -1488,7 +1508,20 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
                nh_pos += encaps_len;
                h_pos += encaps_len;
        }
-       memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
+
+       if (fc & IEEE80211_STYPE_QOS_DATA) {
+               __le16 *qos_control;
+
+               qos_control = (__le16*) skb_push(skb, 2);
+               memcpy(skb_push(skb, hdrlen - 2), &hdr, hdrlen - 2);
+               /*
+                * Maybe we could actually set some fields here, for now just
+                * initialise to zero to indicate no special operation.
+                */
+               *qos_control = 0;
+       } else
+               memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
+
        nh_pos += hdrlen;
        h_pos += hdrlen;
 
@@ -1499,8 +1532,8 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
                pkt_data->flags |= IEEE80211_TXPD_MGMT_IFACE;
 
        skb->dev = local->mdev;
-       sdata->stats.tx_packets++;
-       sdata->stats.tx_bytes += skb->len;
+       dev->stats.tx_packets++;
+       dev->stats.tx_bytes += skb->len;
 
        /* Update skb pointers to various headers since this modified frame
         * is going to go through Linux networking code that may potentially
@@ -1573,8 +1606,8 @@ int ieee80211_mgmt_start_xmit(struct sk_buff *skb, struct net_device *dev)
        if (!(fc & IEEE80211_FCTL_PROTECTED))
                pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT;
 
-       sdata->stats.tx_packets++;
-       sdata->stats.tx_bytes += skb->len;
+       dev->stats.tx_packets++;
+       dev->stats.tx_bytes += skb->len;
 
        dev_queue_xmit(skb);
 
@@ -1724,7 +1757,7 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw, int if_id,
        u8 *b_head, *b_tail;
        int bh_len, bt_len;
 
-       bdev = dev_get_by_index(if_id);
+       bdev = dev_get_by_index(&init_net, if_id);
        if (bdev) {
                sdata = IEEE80211_DEV_TO_SUB_IF(bdev);
                ap = &sdata->u.ap;
@@ -1777,8 +1810,9 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw, int if_id,
                        return NULL;
                }
 
-               control->tx_rate = (sdata->short_preamble &&
-                                   (rate->flags & IEEE80211_RATE_PREAMBLE2)) ?
+               control->tx_rate =
+                       ((sdata->flags & IEEE80211_SDATA_SHORT_PREAMBLE) &&
+                       (rate->flags & IEEE80211_RATE_PREAMBLE2)) ?
                        rate->val2 : rate->val;
                control->antenna_sel_tx = local->hw.conf.antenna_sel_tx;
                control->power_level = local->hw.conf.power_level;
@@ -1837,7 +1871,7 @@ ieee80211_get_buffered_bc(struct ieee80211_hw *hw, int if_id,
        struct ieee80211_sub_if_data *sdata;
        struct ieee80211_if_ap *bss = NULL;
 
-       bdev = dev_get_by_index(if_id);
+       bdev = dev_get_by_index(&init_net, if_id);
        if (bdev) {
                sdata = IEEE80211_DEV_TO_SUB_IF(bdev);
                bss = &sdata->u.ap;
@@ -1871,6 +1905,7 @@ ieee80211_get_buffered_bc(struct ieee80211_hw *hw, int if_id,
        }
        sta = tx.sta;
        tx.flags |= IEEE80211_TXRXD_TXPS_BUFFERED;
+       tx.u.tx.mode = local->hw.conf.mode;
 
        for (handler = local->tx_handlers; *handler != NULL; handler++) {
                res = (*handler)(&tx);
This page took 0.03908 seconds and 5 git commands to generate.