hostap: convert usage of net/ieee80211.h to linux/ieee80211.h
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / hostap / hostap_80211_rx.c
index f106bc1585a45bbeacb1c1a6f2716e2ac8dfc1b0..7ba318e84dec16f0a7e88e8f1021165233b9e080 100644 (file)
@@ -1,5 +1,6 @@
 #include <linux/etherdevice.h>
-#include <net/ieee80211_crypt.h>
+#include <net/lib80211.h>
+#include <linux/if_arp.h>
 
 #include "hostap_80211.h"
 #include "hostap.h"
@@ -17,11 +18,10 @@ static unsigned char bridge_tunnel_header[] =
 void hostap_dump_rx_80211(const char *name, struct sk_buff *skb,
                          struct hostap_80211_rx_status *rx_stats)
 {
-       struct ieee80211_hdr_4addr *hdr;
+       struct ieee80211_hdr *hdr;
        u16 fc;
-       DECLARE_MAC_BUF(mac);
 
-       hdr = (struct ieee80211_hdr_4addr *) skb->data;
+       hdr = (struct ieee80211_hdr *) skb->data;
 
        printk(KERN_DEBUG "%s: RX signal=%d noise=%d rate=%d len=%d "
               "jiffies=%ld\n",
@@ -31,9 +31,10 @@ void hostap_dump_rx_80211(const char *name, struct sk_buff *skb,
        if (skb->len < 2)
                return;
 
-       fc = le16_to_cpu(hdr->frame_ctl);
+       fc = le16_to_cpu(hdr->frame_control);
        printk(KERN_DEBUG "   FC=0x%04x (type=%d:%d)%s%s",
-              fc, WLAN_FC_GET_TYPE(fc) >> 2, WLAN_FC_GET_STYPE(fc) >> 4,
+              fc, (fc & IEEE80211_FCTL_FTYPE) >> 2,
+              (fc & IEEE80211_FCTL_STYPE) >> 4,
               fc & IEEE80211_FCTL_TODS ? " [ToDS]" : "",
               fc & IEEE80211_FCTL_FROMDS ? " [FromDS]" : "");
 
@@ -43,13 +44,13 @@ void hostap_dump_rx_80211(const char *name, struct sk_buff *skb,
        }
 
        printk(" dur=0x%04x seq=0x%04x\n", le16_to_cpu(hdr->duration_id),
-              le16_to_cpu(hdr->seq_ctl));
+              le16_to_cpu(hdr->seq_ctrl));
 
-       printk(KERN_DEBUG "   A1=%s", print_mac(mac, hdr->addr1));
-       printk(" A2=%s", print_mac(mac, hdr->addr2));
-       printk(" A3=%s", print_mac(mac, hdr->addr3));
+       printk(KERN_DEBUG "   A1=%pM", hdr->addr1);
+       printk(" A2=%pM", hdr->addr2);
+       printk(" A3=%pM", hdr->addr3);
        if (skb->len >= 30)
-               printk(" A4=%s", print_mac(mac, hdr->addr4));
+               printk(" A4=%pM", hdr->addr4);
        printk("\n");
 }
 
@@ -64,11 +65,10 @@ int prism2_rx_80211(struct net_device *dev, struct sk_buff *skb,
        int hdrlen, phdrlen, head_need, tail_need;
        u16 fc;
        int prism_header, ret;
-       struct ieee80211_hdr_4addr *fhdr;
+       struct ieee80211_hdr *fhdr;
 
        iface = netdev_priv(dev);
        local = iface->local;
-       dev->last_rx = jiffies;
 
        if (dev->type == ARPHRD_IEEE80211_PRISM) {
                if (local->monitor_type == PRISM2_MONITOR_PRISM) {
@@ -86,8 +86,8 @@ int prism2_rx_80211(struct net_device *dev, struct sk_buff *skb,
                phdrlen = 0;
        }
 
-       fhdr = (struct ieee80211_hdr_4addr *) skb->data;
-       fc = le16_to_cpu(fhdr->frame_ctl);
+       fhdr = (struct ieee80211_hdr *) skb->data;
+       fc = le16_to_cpu(fhdr->frame_control);
 
        if (type == PRISM2_RX_MGMT && (fc & IEEE80211_FCTL_VERS)) {
                printk(KERN_DEBUG "%s: dropped management frame with header "
@@ -96,7 +96,7 @@ int prism2_rx_80211(struct net_device *dev, struct sk_buff *skb,
                return 0;
        }
 
-       hdrlen = hostap_80211_get_hdrlen(fc);
+       hdrlen = hostap_80211_get_hdrlen(fhdr->frame_control);
 
        /* check if there is enough room for extra data; if not, expand skb
         * buffer to be large enough for the changes */
@@ -195,7 +195,7 @@ hdr->f.status = s; hdr->f.len = l; hdr->f.data = d
        if (prism_header)
                skb_pull(skb, phdrlen);
        skb->pkt_type = PACKET_OTHERHOST;
-       skb->protocol = __constant_htons(ETH_P_802_2);
+       skb->protocol = cpu_to_be16(ETH_P_802_2);
        memset(skb->cb, 0, sizeof(skb->cb));
        netif_rx(skb);
 
@@ -249,21 +249,21 @@ prism2_frag_cache_find(local_info_t *local, unsigned int seq,
 
 /* Called only as a tasklet (software IRQ) */
 static struct sk_buff *
-prism2_frag_cache_get(local_info_t *local, struct ieee80211_hdr_4addr *hdr)
+prism2_frag_cache_get(local_info_t *local, struct ieee80211_hdr *hdr)
 {
        struct sk_buff *skb = NULL;
        u16 sc;
        unsigned int frag, seq;
        struct prism2_frag_entry *entry;
 
-       sc = le16_to_cpu(hdr->seq_ctl);
-       frag = WLAN_GET_SEQ_FRAG(sc);
-       seq = WLAN_GET_SEQ_SEQ(sc) >> 4;
+       sc = le16_to_cpu(hdr->seq_ctrl);
+       frag = sc & IEEE80211_SCTL_FRAG;
+       seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
 
        if (frag == 0) {
                /* Reserve enough space to fit maximum frame length */
                skb = dev_alloc_skb(local->dev->mtu +
-                                   sizeof(struct ieee80211_hdr_4addr) +
+                                   sizeof(struct ieee80211_hdr) +
                                    8 /* LLC */ +
                                    2 /* alignment */ +
                                    8 /* WEP */ + ETH_ALEN /* WDS */);
@@ -301,14 +301,14 @@ prism2_frag_cache_get(local_info_t *local, struct ieee80211_hdr_4addr *hdr)
 
 /* Called only as a tasklet (software IRQ) */
 static int prism2_frag_cache_invalidate(local_info_t *local,
-                                       struct ieee80211_hdr_4addr *hdr)
+                                       struct ieee80211_hdr *hdr)
 {
        u16 sc;
        unsigned int seq;
        struct prism2_frag_entry *entry;
 
-       sc = le16_to_cpu(hdr->seq_ctl);
-       seq = WLAN_GET_SEQ_SEQ(sc) >> 4;
+       sc = le16_to_cpu(hdr->seq_ctrl);
+       seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
 
        entry = prism2_frag_cache_find(local, seq, -1, hdr->addr2, hdr->addr1);
 
@@ -474,10 +474,8 @@ hostap_rx_frame_mgmt(local_info_t *local, struct sk_buff *skb,
                     struct hostap_80211_rx_status *rx_stats, u16 type,
                     u16 stype)
 {
-       if (local->iw_mode == IW_MODE_MASTER) {
-               hostap_update_sta_ps(local, (struct ieee80211_hdr_4addr *)
-                                    skb->data);
-       }
+       if (local->iw_mode == IW_MODE_MASTER)
+               hostap_update_sta_ps(local, (struct ieee80211_hdr *) skb->data);
 
        if (local->hostapd && type == IEEE80211_FTYPE_MGMT) {
                if (stype == IEEE80211_STYPE_BEACON &&
@@ -554,10 +552,9 @@ static struct net_device *prism2_rx_get_wds(local_info_t *local,
 
 
 static int
-hostap_rx_frame_wds(local_info_t *local, struct ieee80211_hdr_4addr *hdr,
-                   u16 fc, struct net_device **wds)
+hostap_rx_frame_wds(local_info_t *local, struct ieee80211_hdr *hdr, u16 fc,
+                   struct net_device **wds)
 {
-       DECLARE_MAC_BUF(mac);
        /* FIX: is this really supposed to accept WDS frames only in Master
         * mode? What about Repeater or Managed with WDS frames? */
        if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) !=
@@ -573,10 +570,10 @@ hostap_rx_frame_wds(local_info_t *local, struct ieee80211_hdr_4addr *hdr,
             hdr->addr1[4] != 0xff || hdr->addr1[5] != 0xff)) {
                /* RA (or BSSID) is not ours - drop */
                PDEBUG(DEBUG_EXTRA2, "%s: received WDS frame with "
-                      "not own or broadcast %s=%s\n",
+                      "not own or broadcast %s=%pM\n",
                       local->dev->name,
                       fc & IEEE80211_FCTL_FROMDS ? "RA" : "BSSID",
-                      print_mac(mac, hdr->addr1));
+                      hdr->addr1);
                return -1;
        }
 
@@ -589,8 +586,8 @@ hostap_rx_frame_wds(local_info_t *local, struct ieee80211_hdr_4addr *hdr,
                /* require that WDS link has been registered with TA or the
                 * frame is from current AP when using 'AP client mode' */
                PDEBUG(DEBUG_EXTRA, "%s: received WDS[4 addr] frame "
-                      "from unknown TA=%s\n",
-                      local->dev->name, print_mac(mac, hdr->addr2));
+                      "from unknown TA=%pM\n",
+                      local->dev->name, hdr->addr2);
                if (local->ap && local->ap->autom_ap_wds)
                        hostap_wds_link_oper(local, hdr->addr2, WDS_ADD);
                return -1;
@@ -614,14 +611,14 @@ static int hostap_is_eapol_frame(local_info_t *local, struct sk_buff *skb)
 {
        struct net_device *dev = local->dev;
        u16 fc, ethertype;
-       struct ieee80211_hdr_4addr *hdr;
+       struct ieee80211_hdr *hdr;
        u8 *pos;
 
        if (skb->len < 24)
                return 0;
 
-       hdr = (struct ieee80211_hdr_4addr *) skb->data;
-       fc = le16_to_cpu(hdr->frame_ctl);
+       hdr = (struct ieee80211_hdr *) skb->data;
+       fc = le16_to_cpu(hdr->frame_control);
 
        /* check that the frame is unicast frame to us */
        if ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
@@ -652,25 +649,23 @@ static int hostap_is_eapol_frame(local_info_t *local, struct sk_buff *skb)
 /* Called only as a tasklet (software IRQ) */
 static int
 hostap_rx_frame_decrypt(local_info_t *local, struct sk_buff *skb,
-                       struct ieee80211_crypt_data *crypt)
+                       struct lib80211_crypt_data *crypt)
 {
-       struct ieee80211_hdr_4addr *hdr;
+       struct ieee80211_hdr *hdr;
        int res, hdrlen;
 
        if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
                return 0;
 
-       hdr = (struct ieee80211_hdr_4addr *) skb->data;
-       hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
+       hdr = (struct ieee80211_hdr *) skb->data;
+       hdrlen = hostap_80211_get_hdrlen(hdr->frame_control);
 
        if (local->tkip_countermeasures &&
            strcmp(crypt->ops->name, "TKIP") == 0) {
                if (net_ratelimit()) {
                        printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
-                              "received packet from " MAC_FMT "\n",
-                              local->dev->name,
-                              hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
-                              hdr->addr2[3], hdr->addr2[4], hdr->addr2[5]);
+                              "received packet from %pM\n",
+                              local->dev->name, hdr->addr2);
                }
                return -1;
        }
@@ -679,12 +674,8 @@ hostap_rx_frame_decrypt(local_info_t *local, struct sk_buff *skb,
        res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
        atomic_dec(&crypt->refcnt);
        if (res < 0) {
-               printk(KERN_DEBUG "%s: decryption failed (SA=" MAC_FMT
-                      ") res=%d\n",
-                      local->dev->name,
-                      hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
-                      hdr->addr2[3], hdr->addr2[4], hdr->addr2[5],
-                      res);
+               printk(KERN_DEBUG "%s: decryption failed (SA=%pM) res=%d\n",
+                      local->dev->name, hdr->addr2, res);
                local->comm_tallies.rx_discards_wep_undecryptable++;
                return -1;
        }
@@ -696,25 +687,24 @@ hostap_rx_frame_decrypt(local_info_t *local, struct sk_buff *skb,
 /* Called only as a tasklet (software IRQ) */
 static int
 hostap_rx_frame_decrypt_msdu(local_info_t *local, struct sk_buff *skb,
-                            int keyidx, struct ieee80211_crypt_data *crypt)
+                            int keyidx, struct lib80211_crypt_data *crypt)
 {
-       struct ieee80211_hdr_4addr *hdr;
+       struct ieee80211_hdr *hdr;
        int res, hdrlen;
-       DECLARE_MAC_BUF(mac);
 
        if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
                return 0;
 
-       hdr = (struct ieee80211_hdr_4addr *) skb->data;
-       hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
+       hdr = (struct ieee80211_hdr *) skb->data;
+       hdrlen = hostap_80211_get_hdrlen(hdr->frame_control);
 
        atomic_inc(&crypt->refcnt);
        res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
        atomic_dec(&crypt->refcnt);
        if (res < 0) {
                printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
-                      " (SA=%s keyidx=%d)\n",
-                      local->dev->name, print_mac(mac, hdr->addr2), keyidx);
+                      " (SA=%pM keyidx=%d)\n",
+                      local->dev->name, hdr->addr2, keyidx);
                return -1;
        }
 
@@ -730,7 +720,7 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
 {
        struct hostap_interface *iface;
        local_info_t *local;
-       struct ieee80211_hdr_4addr *hdr;
+       struct ieee80211_hdr *hdr;
        size_t hdrlen;
        u16 fc, type, stype, sc;
        struct net_device *wds = NULL;
@@ -743,7 +733,7 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
        int from_assoc_ap = 0;
        u8 dst[ETH_ALEN];
        u8 src[ETH_ALEN];
-       struct ieee80211_crypt_data *crypt = NULL;
+       struct lib80211_crypt_data *crypt = NULL;
        void *sta = NULL;
        int keyidx = 0;
 
@@ -757,18 +747,18 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
        dev = local->ddev;
        iface = netdev_priv(dev);
 
-       hdr = (struct ieee80211_hdr_4addr *) skb->data;
+       hdr = (struct ieee80211_hdr *) skb->data;
        stats = hostap_get_stats(dev);
 
        if (skb->len < 10)
                goto rx_dropped;
 
-       fc = le16_to_cpu(hdr->frame_ctl);
-       type = WLAN_FC_GET_TYPE(fc);
-       stype = WLAN_FC_GET_STYPE(fc);
-       sc = le16_to_cpu(hdr->seq_ctl);
-       frag = WLAN_GET_SEQ_FRAG(sc);
-       hdrlen = hostap_80211_get_hdrlen(fc);
+       fc = le16_to_cpu(hdr->frame_control);
+       type = fc & IEEE80211_FCTL_FTYPE;
+       stype = fc & IEEE80211_FCTL_STYPE;
+       sc = le16_to_cpu(hdr->seq_ctrl);
+       frag = sc & IEEE80211_SCTL_FRAG;
+       hdrlen = hostap_80211_get_hdrlen(hdr->frame_control);
 
        /* Put this code here so that we avoid duplicating it in all
         * Rx paths. - Jean II */
@@ -795,7 +785,7 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
                int idx = 0;
                if (skb->len >= hdrlen + 3)
                        idx = skb->data[hdrlen + 3] >> 6;
-               crypt = local->crypt[idx];
+               crypt = local->crypt_info.crypt[idx];
                sta = NULL;
 
                /* Use station specific key to override default keys if the
@@ -822,10 +812,8 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
                         * frames silently instead of filling system log with
                         * these reports. */
                        printk(KERN_DEBUG "%s: WEP decryption failed (not set)"
-                              " (SA=" MAC_FMT ")\n",
-                              local->dev->name,
-                              hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
-                              hdr->addr2[3], hdr->addr2[4], hdr->addr2[5]);
+                              " (SA=%pM)\n",
+                              local->dev->name, hdr->addr2);
 #endif
                        local->comm_tallies.rx_discards_wep_undecryptable++;
                        goto rx_dropped;
@@ -839,9 +827,7 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
                    (keyidx = hostap_rx_frame_decrypt(local, skb, crypt)) < 0)
                {
                        printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth "
-                              "from " MAC_FMT "\n", dev->name,
-                              hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
-                              hdr->addr2[3], hdr->addr2[4], hdr->addr2[5]);
+                              "from %pM\n", dev->name, hdr->addr2);
                        /* TODO: could inform hostapd about this so that it
                         * could send auth failure report */
                        goto rx_dropped;
@@ -896,8 +882,6 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
                from_assoc_ap = 1;
        }
 
-       dev->last_rx = jiffies;
-
        if ((local->iw_mode == IW_MODE_MASTER ||
             local->iw_mode == IW_MODE_REPEAT) &&
            !from_assoc_ap) {
@@ -934,7 +918,7 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
        if (local->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
            (keyidx = hostap_rx_frame_decrypt(local, skb, crypt)) < 0)
                goto rx_dropped;
-       hdr = (struct ieee80211_hdr_4addr *) skb->data;
+       hdr = (struct ieee80211_hdr *) skb->data;
 
        /* skb: hdr + (possibly fragmented) plaintext payload */
 
@@ -947,7 +931,7 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
                        printk(KERN_DEBUG "%s: Rx cannot get skb from "
                               "fragment cache (morefrag=%d seq=%u frag=%u)\n",
                               dev->name, (fc & IEEE80211_FCTL_MOREFRAGS) != 0,
-                              WLAN_GET_SEQ_SEQ(sc) >> 4, frag);
+                              (sc & IEEE80211_SCTL_SEQ) >> 4, frag);
                        goto rx_dropped;
                }
 
@@ -988,7 +972,7 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
                /* this was the last fragment and the frame will be
                 * delivered, so remove skb from fragment cache */
                skb = frag_skb;
-               hdr = (struct ieee80211_hdr_4addr *) skb->data;
+               hdr = (struct ieee80211_hdr *) skb->data;
                prism2_frag_cache_invalidate(local, hdr);
        }
 
@@ -999,7 +983,7 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
            hostap_rx_frame_decrypt_msdu(local, skb, keyidx, crypt))
                goto rx_dropped;
 
-       hdr = (struct ieee80211_hdr_4addr *) skb->data;
+       hdr = (struct ieee80211_hdr *) skb->data;
        if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !local->open_wep) {
                if (local->ieee_802_1x &&
                    hostap_is_eapol_frame(local, skb)) {
@@ -1009,10 +993,8 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
                               "unencrypted EAPOL frame\n", local->dev->name);
                } else {
                        printk(KERN_DEBUG "%s: encryption configured, but RX "
-                              "frame not encrypted (SA=" MAC_FMT ")\n",
-                              local->dev->name,
-                              hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
-                              hdr->addr2[3], hdr->addr2[4], hdr->addr2[5]);
+                              "frame not encrypted (SA=%pM)\n",
+                              local->dev->name, hdr->addr2);
                        goto rx_dropped;
                }
        }
@@ -1021,10 +1003,8 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
            !hostap_is_eapol_frame(local, skb)) {
                if (net_ratelimit()) {
                        printk(KERN_DEBUG "%s: dropped unencrypted RX data "
-                              "frame from " MAC_FMT " (drop_unencrypted=1)\n",
-                              dev->name,
-                              hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
-                              hdr->addr2[3], hdr->addr2[4], hdr->addr2[5]);
+                              "frame from %pM (drop_unencrypted=1)\n",
+                              dev->name, hdr->addr2);
                }
                goto rx_dropped;
        }
@@ -1114,7 +1094,7 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
        if (skb2 != NULL) {
                /* send to wireless media */
                skb2->dev = dev;
-               skb2->protocol = __constant_htons(ETH_P_802_3);
+               skb2->protocol = cpu_to_be16(ETH_P_802_3);
                skb_reset_mac_header(skb2);
                skb_reset_network_header(skb2);
                /* skb2->network_header += ETH_HLEN; */