These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / staging / rtl8192e / rtllib_rx.c
index fe3e7e1..37343ec 100644 (file)
 #include "rtllib.h"
 #include "dot11d.h"
 
+static void rtllib_rx_mgt(struct rtllib_device *ieee, struct sk_buff *skb,
+                         struct rtllib_rx_stats *stats);
+
 static inline void rtllib_monitor_rx(struct rtllib_device *ieee,
-                               struct sk_buff *skb, struct rtllib_rx_stats *rx_status,
-                               size_t hdr_length)
+                                    struct sk_buff *skb,
+                                    struct rtllib_rx_stats *rx_status,
+                                    size_t hdr_length)
 {
        skb->dev = ieee->dev;
        skb_reset_mac_header(skb);
@@ -69,9 +73,9 @@ rtllib_frag_cache_find(struct rtllib_device *ieee, unsigned int seq,
                entry = &ieee->frag_cache[tid][i];
                if (entry->skb != NULL &&
                    time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
-                       RTLLIB_DEBUG_FRAG(
-                               "expiring fragment cache entry seq=%u last_frag=%u\n",
-                               entry->seq, entry->last_frag);
+                       netdev_dbg(ieee->dev,
+                                  "expiring fragment cache entry seq=%u last_frag=%u\n",
+                                  entry->seq, entry->last_frag);
                        dev_kfree_skb_any(entry->skb);
                        entry->skb = NULL;
                }
@@ -101,7 +105,8 @@ rtllib_frag_cache_get(struct rtllib_device *ieee,
        struct rtllib_hdr_4addrqos *hdr_4addrqos;
        u8 tid;
 
-       if (((fc & RTLLIB_FCTL_DSTODS) == RTLLIB_FCTL_DSTODS) && RTLLIB_QOS_HAS_SEQ(fc)) {
+       if (((fc & RTLLIB_FCTL_DSTODS) == RTLLIB_FCTL_DSTODS) &&
+           RTLLIB_QOS_HAS_SEQ(fc)) {
                hdr_4addrqos = (struct rtllib_hdr_4addrqos *)hdr;
                tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & RTLLIB_QCTL_TID;
                tid = UP2AC(tid);
@@ -123,7 +128,8 @@ rtllib_frag_cache_get(struct rtllib_device *ieee,
                                    2 /* alignment */ +
                                    8 /* WEP */ +
                                    ETH_ALEN /* WDS */ +
-                                   (RTLLIB_QOS_HAS_SEQ(fc) ? 2 : 0) /* QOS Control */);
+                                   /* QOS Control */
+                                   (RTLLIB_QOS_HAS_SEQ(fc) ? 2 : 0));
                if (skb == NULL)
                        return NULL;
 
@@ -139,8 +145,8 @@ rtllib_frag_cache_get(struct rtllib_device *ieee,
                entry->seq = seq;
                entry->last_frag = frag;
                entry->skb = skb;
-               memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
-               memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
+               ether_addr_copy(entry->src_addr, hdr->addr2);
+               ether_addr_copy(entry->dst_addr, hdr->addr1);
        } else {
                /* received a fragment of a frame for which the head fragment
                 * should have already been received
@@ -169,7 +175,8 @@ static int rtllib_frag_cache_invalidate(struct rtllib_device *ieee,
        struct rtllib_hdr_4addrqos *hdr_4addrqos;
        u8 tid;
 
-       if (((fc & RTLLIB_FCTL_DSTODS) == RTLLIB_FCTL_DSTODS) && RTLLIB_QOS_HAS_SEQ(fc)) {
+       if (((fc & RTLLIB_FCTL_DSTODS) == RTLLIB_FCTL_DSTODS) &&
+           RTLLIB_QOS_HAS_SEQ(fc)) {
                hdr_4addrqos = (struct rtllib_hdr_4addrqos *)hdr;
                tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & RTLLIB_QCTL_TID;
                tid = UP2AC(tid);
@@ -187,8 +194,9 @@ static int rtllib_frag_cache_invalidate(struct rtllib_device *ieee,
                                          hdr->addr1);
 
        if (entry == NULL) {
-               RTLLIB_DEBUG_FRAG(
-                       "could not invalidate fragment cache entry (seq=%u)\n", seq);
+               netdev_dbg(ieee->dev,
+                          "Couldn't invalidate fragment cache entry (seq=%u)\n",
+                          seq);
                return -1;
        }
 
@@ -290,7 +298,8 @@ rtllib_rx_frame_decrypt(struct rtllib_device *ieee, struct sk_buff *skb,
                return 0;
 
        if (ieee->hwsec_active) {
-               struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
+               struct cb_desc *tcb_desc = (struct cb_desc *)
+                                               (skb->cb + MAX_DEV_ADDR_SIZE);
 
                tcb_desc->bHwSec = 1;
 
@@ -305,12 +314,12 @@ rtllib_rx_frame_decrypt(struct rtllib_device *ieee, struct sk_buff *skb,
        res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
        atomic_dec(&crypt->refcnt);
        if (res < 0) {
-               RTLLIB_DEBUG_DROP(
-                       "decryption failed (SA= %pM) res=%d\n", hdr->addr2, res);
+               netdev_dbg(ieee->dev, "decryption failed (SA= %pM) res=%d\n",
+                          hdr->addr2, res);
                if (res == -2)
-                       RTLLIB_DEBUG_DROP("Decryption failed ICV mismatch (key %d)\n",
-                                            skb->data[hdrlen + 3] >> 6);
-               ieee->ieee_stats.rx_discards_undecryptable++;
+                       netdev_dbg(ieee->dev,
+                                  "Decryption failed ICV mismatch (key %d)\n",
+                                  skb->data[hdrlen + 3] >> 6);
                return -1;
        }
 
@@ -329,7 +338,8 @@ rtllib_rx_frame_decrypt_msdu(struct rtllib_device *ieee, struct sk_buff *skb,
        if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
                return 0;
        if (ieee->hwsec_active) {
-               struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
+               struct cb_desc *tcb_desc = (struct cb_desc *)
+                                               (skb->cb + MAX_DEV_ADDR_SIZE);
 
                tcb_desc->bHwSec = 1;
 
@@ -344,8 +354,9 @@ rtllib_rx_frame_decrypt_msdu(struct rtllib_device *ieee, struct sk_buff *skb,
        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= %pM keyidx=%d)\n",
-                      ieee->dev->name, hdr->addr2, keyidx);
+               netdev_dbg(ieee->dev,
+                          "MSDU decryption/MIC verification failed (SA= %pM keyidx=%d)\n",
+                          hdr->addr2, keyidx);
                return -1;
        }
 
@@ -368,7 +379,8 @@ static int is_duplicate_packet(struct rtllib_device *ieee,
        struct rtllib_hdr_4addrqos *hdr_4addrqos;
        u8 tid;
 
-       if (((fc & RTLLIB_FCTL_DSTODS) == RTLLIB_FCTL_DSTODS) && RTLLIB_QOS_HAS_SEQ(fc)) {
+       if (((fc & RTLLIB_FCTL_DSTODS) == RTLLIB_FCTL_DSTODS) &&
+           RTLLIB_QOS_HAS_SEQ(fc)) {
                hdr_4addrqos = (struct rtllib_hdr_4addrqos *)header;
                tid = le16_to_cpu(hdr_4addrqos->qos_ctl) & RTLLIB_QCTL_TID;
                tid = UP2AC(tid);
@@ -396,11 +408,12 @@ static int is_duplicate_packet(struct rtllib_device *ieee,
                                break;
                }
                if (p == &ieee->ibss_mac_hash[index]) {
-                       entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC);
+                       entry = kmalloc(sizeof(struct ieee_ibss_seq),
+                                       GFP_ATOMIC);
                        if (!entry)
                                return 0;
 
-                       memcpy(entry->mac, mac, ETH_ALEN);
+                       ether_addr_copy(entry->mac, mac);
                        entry->seq_num[tid] = seq;
                        entry->frag_num[tid] = frag;
                        entry->packet_time[tid] = jiffies;
@@ -466,10 +479,11 @@ static bool AddReorderEntry(struct rx_ts_record *pTS,
        return true;
 }
 
-void rtllib_indicate_packets(struct rtllib_device *ieee, struct rtllib_rxb **prxbIndicateArray, u8 index)
+void rtllib_indicate_packets(struct rtllib_device *ieee,
+                            struct rtllib_rxb **prxbIndicateArray, u8 index)
 {
        struct net_device_stats *stats = &ieee->stats;
-       u8 i = 0 , j = 0;
+       u8 i = 0, j = 0;
        u16 ethertype;
 
        for (j = 0; j < index; j++) {
@@ -481,9 +495,12 @@ void rtllib_indicate_packets(struct rtllib_device *ieee, struct rtllib_rxb **prx
                /* convert hdr + possible LLC headers into Ethernet header */
                        ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
                        if (sub_skb->len >= 8 &&
-                           ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
-                           ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
-                           memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
+                           ((memcmp(sub_skb->data, rfc1042_header,
+                                    SNAP_SIZE) == 0 &&
+                             ethertype != ETH_P_AARP &&
+                             ethertype != ETH_P_IPX) ||
+                           memcmp(sub_skb->data, bridge_tunnel_header,
+                                  SNAP_SIZE) == 0)) {
                                /* remove RFC1042 or Bridge-Tunnel encapsulation
                                 * and replace EtherType
                                 */
@@ -505,11 +522,13 @@ void rtllib_indicate_packets(struct rtllib_device *ieee, struct rtllib_rxb **prx
                                stats->rx_bytes += sub_skb->len;
 
                                memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
-                               sub_skb->protocol = eth_type_trans(sub_skb, ieee->dev);
+                               sub_skb->protocol = eth_type_trans(sub_skb,
+                                                                  ieee->dev);
                                sub_skb->dev = ieee->dev;
                                sub_skb->dev->stats.rx_packets++;
                                sub_skb->dev->stats.rx_bytes += sub_skb->len;
-                               sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
+                               /* 802.11 crc not sufficient */
+                               sub_skb->ip_summed = CHECKSUM_NONE;
                                ieee->last_rx_ps_time = jiffies;
                                netif_rx(sub_skb);
                        }
@@ -519,7 +538,8 @@ void rtllib_indicate_packets(struct rtllib_device *ieee, struct rtllib_rxb **prx
        }
 }
 
-void rtllib_FlushRxTsPendingPkts(struct rtllib_device *ieee,   struct rx_ts_record *pTS)
+void rtllib_FlushRxTsPendingPkts(struct rtllib_device *ieee,
+                                struct rx_ts_record *pTS)
 {
        struct rx_reorder_entry *pRxReorderEntry;
        u8 RfdCnt = 0;
@@ -533,14 +553,18 @@ void rtllib_FlushRxTsPendingPkts(struct rtllib_device *ieee,      struct rx_ts_record
                        break;
                }
 
-               pRxReorderEntry = (struct rx_reorder_entry *)list_entry(pTS->RxPendingPktList.prev, struct rx_reorder_entry, List);
-               RTLLIB_DEBUG(RTLLIB_DL_REORDER, "%s(): Indicate SeqNum %d!\n", __func__, pRxReorderEntry->SeqNum);
+               pRxReorderEntry = (struct rx_reorder_entry *)
+                                 list_entry(pTS->RxPendingPktList.prev,
+                                            struct rx_reorder_entry, List);
+               netdev_dbg(ieee->dev, "%s(): Indicate SeqNum %d!\n", __func__,
+                          pRxReorderEntry->SeqNum);
                list_del_init(&pRxReorderEntry->List);
 
                ieee->RfdArray[RfdCnt] = pRxReorderEntry->prxb;
 
                RfdCnt = RfdCnt + 1;
-               list_add_tail(&pRxReorderEntry->List, &ieee->RxReorder_Unused_List);
+               list_add_tail(&pRxReorderEntry->List,
+                             &ieee->RxReorder_Unused_List);
        }
        rtllib_indicate_packets(ieee, ieee->RfdArray, RfdCnt);
 
@@ -559,8 +583,9 @@ static void RxReorderIndicatePacket(struct rtllib_device *ieee,
        bool bMatchWinStart = false, bPktInBuf = false;
        unsigned long flags;
 
-       RTLLIB_DEBUG(RTLLIB_DL_REORDER, "%s(): Seq is %d, pTS->RxIndicateSeq is %d, WinSize is %d\n", __func__, SeqNum,
-                    pTS->RxIndicateSeq, WinSize);
+       netdev_dbg(ieee->dev,
+                  "%s(): Seq is %d, pTS->RxIndicateSeq is %d, WinSize is %d\n",
+                  __func__, SeqNum, pTS->RxIndicateSeq, WinSize);
 
        spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
 
@@ -571,8 +596,9 @@ static void RxReorderIndicatePacket(struct rtllib_device *ieee,
 
        /* Drop out the packet which SeqNum is smaller than WinStart */
        if (SN_LESS(SeqNum, pTS->RxIndicateSeq)) {
-               RTLLIB_DEBUG(RTLLIB_DL_REORDER, "Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
-                                pTS->RxIndicateSeq, SeqNum);
+               netdev_dbg(ieee->dev,
+                          "Packet Drop! IndicateSeq: %d, NewSeq: %d\n",
+                          pTS->RxIndicateSeq, SeqNum);
                pHTInfo->RxReorderDropCounter++;
                {
                        int i;
@@ -597,8 +623,11 @@ static void RxReorderIndicatePacket(struct rtllib_device *ieee,
                if (SeqNum >= (WinSize - 1))
                        pTS->RxIndicateSeq = SeqNum + 1 - WinSize;
                else
-                       pTS->RxIndicateSeq = 4095 - (WinSize - (SeqNum + 1)) + 1;
-               RTLLIB_DEBUG(RTLLIB_DL_REORDER, "Window Shift! IndicateSeq: %d, NewSeq: %d\n", pTS->RxIndicateSeq, SeqNum);
+                       pTS->RxIndicateSeq = 4095 -
+                                            (WinSize - (SeqNum + 1)) + 1;
+               netdev_dbg(ieee->dev,
+                          "Window Shift! IndicateSeq: %d, NewSeq: %d\n",
+                          pTS->RxIndicateSeq, SeqNum);
        }
 
        /* Indication process.
@@ -613,8 +642,9 @@ static void RxReorderIndicatePacket(struct rtllib_device *ieee,
         */
        if (bMatchWinStart) {
                /* Current packet is going to be indicated.*/
-               RTLLIB_DEBUG(RTLLIB_DL_REORDER, "Packets indication!! IndicateSeq: %d, NewSeq: %d\n",
-                               pTS->RxIndicateSeq, SeqNum);
+               netdev_dbg(ieee->dev,
+                          "Packets indication! IndicateSeq: %d, NewSeq: %d\n",
+                          pTS->RxIndicateSeq, SeqNum);
                ieee->prxbIndicateArray[0] = prxb;
                index = 1;
        } else {
@@ -625,28 +655,30 @@ static void RxReorderIndicatePacket(struct rtllib_device *ieee,
                                        struct rx_reorder_entry, List);
                        list_del_init(&pReorderEntry->List);
 
-                       /* Make a reorder entry and insert into a the packet list.*/
+                       /* Make a reorder entry and insert
+                        * into a the packet list.
+                        */
                        pReorderEntry->SeqNum = SeqNum;
                        pReorderEntry->prxb = prxb;
 
                        if (!AddReorderEntry(pTS, pReorderEntry)) {
-                               RTLLIB_DEBUG(RTLLIB_DL_REORDER,
-                                            "%s(): Duplicate packet is dropped!! IndicateSeq: %d, NewSeq: %d\n",
-                                           __func__, pTS->RxIndicateSeq,
-                                           SeqNum);
+                               int i;
+
+                               netdev_dbg(ieee->dev,
+                                          "%s(): Duplicate packet is dropped. IndicateSeq: %d, NewSeq: %d\n",
+                                          __func__, pTS->RxIndicateSeq,
+                                          SeqNum);
                                list_add_tail(&pReorderEntry->List,
-                                             &ieee->RxReorder_Unused_List); {
-                                       int i;
+                                             &ieee->RxReorder_Unused_List);
 
-                                       for (i = 0; i < prxb->nr_subframes; i++)
-                                               dev_kfree_skb(prxb->subframes[i]);
-                                       kfree(prxb);
-                                       prxb = NULL;
-                               }
+                               for (i = 0; i < prxb->nr_subframes; i++)
+                                       dev_kfree_skb(prxb->subframes[i]);
+                               kfree(prxb);
+                               prxb = NULL;
                        } else {
-                               RTLLIB_DEBUG(RTLLIB_DL_REORDER,
-                                        "Pkt insert into struct buffer!! IndicateSeq: %d, NewSeq: %d\n",
-                                        pTS->RxIndicateSeq, SeqNum);
+                               netdev_dbg(ieee->dev,
+                                          "Pkt insert into struct buffer. IndicateSeq: %d, NewSeq: %d\n",
+                                          pTS->RxIndicateSeq, SeqNum);
                        }
                } else {
                        /* Packets are dropped if there are not enough reorder
@@ -654,7 +686,9 @@ static void RxReorderIndicatePacket(struct rtllib_device *ieee,
                         * indicate all the packets in struct buffer and get
                         * reorder entries.
                         */
-                       RTLLIB_DEBUG(RTLLIB_DL_ERR, "RxReorderIndicatePacket(): There is no reorder entry!! Packet is dropped!!\n");
+                       netdev_err(ieee->dev,
+                                  "%s(): There is no reorder entry! Packet is dropped!\n",
+                                  __func__);
                        {
                                int i;
 
@@ -668,15 +702,20 @@ static void RxReorderIndicatePacket(struct rtllib_device *ieee,
 
        /* Check if there is any packet need indicate.*/
        while (!list_empty(&pTS->RxPendingPktList)) {
-               RTLLIB_DEBUG(RTLLIB_DL_REORDER, "%s(): start RREORDER indicate\n", __func__);
+               netdev_dbg(ieee->dev, "%s(): start RREORDER indicate\n",
+                          __func__);
 
-               pReorderEntry = (struct rx_reorder_entry *)list_entry(pTS->RxPendingPktList.prev,
-                                struct rx_reorder_entry, List);
+               pReorderEntry = (struct rx_reorder_entry *)
+                                       list_entry(pTS->RxPendingPktList.prev,
+                                                  struct rx_reorder_entry,
+                                                  List);
                if (SN_LESS(pReorderEntry->SeqNum, pTS->RxIndicateSeq) ||
-                               SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq)) {
+                   SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq)) {
                        /* This protect struct buffer from overflow. */
                        if (index >= REORDER_WIN_SIZE) {
-                               RTLLIB_DEBUG(RTLLIB_DL_ERR, "RxReorderIndicatePacket(): Buffer overflow!!\n");
+                               netdev_err(ieee->dev,
+                                          "%s(): Buffer overflow!\n",
+                                          __func__);
                                bPktInBuf = true;
                                break;
                        }
@@ -684,10 +723,12 @@ static void RxReorderIndicatePacket(struct rtllib_device *ieee,
                        list_del_init(&pReorderEntry->List);
 
                        if (SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
-                               pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) % 4096;
+                               pTS->RxIndicateSeq = (pTS->RxIndicateSeq + 1) %
+                                                    4096;
 
                        ieee->prxbIndicateArray[index] = pReorderEntry->prxb;
-                       RTLLIB_DEBUG(RTLLIB_DL_REORDER, "%s(): Indicate SeqNum %d!\n", __func__, pReorderEntry->SeqNum);
+                       netdev_dbg(ieee->dev, "%s(): Indicate SeqNum %d!\n",
+                                  __func__, pReorderEntry->SeqNum);
                        index++;
 
                        list_add_tail(&pReorderEntry->List,
@@ -707,7 +748,9 @@ static void RxReorderIndicatePacket(struct rtllib_device *ieee,
                pTS->RxTimeoutIndicateSeq = 0xffff;
 
                if (index > REORDER_WIN_SIZE) {
-                       RTLLIB_DEBUG(RTLLIB_DL_ERR, "RxReorderIndicatePacket(): Rx Reorder struct buffer full!!\n");
+                       netdev_err(ieee->dev,
+                                  "%s(): Rx Reorder struct buffer full!\n",
+                                  __func__);
                        spin_unlock_irqrestore(&(ieee->reorder_spinlock),
                                               flags);
                        return;
@@ -717,8 +760,7 @@ static void RxReorderIndicatePacket(struct rtllib_device *ieee,
        }
 
        if (bPktInBuf && pTS->RxTimeoutIndicateSeq == 0xffff) {
-               RTLLIB_DEBUG(RTLLIB_DL_REORDER, "%s(): SET rx timeout timer\n",
-                            __func__);
+               netdev_dbg(ieee->dev, "%s(): SET rx timeout timer\n", __func__);
                pTS->RxTimeoutIndicateSeq = pTS->RxIndicateSeq;
                mod_timer(&pTS->RxPktPendingTimer, jiffies +
                          msecs_to_jiffies(pHTInfo->RxReorderPendingTime));
@@ -834,7 +876,8 @@ static u8 parse_subframe(struct rtllib_device *ieee, struct sk_buff *skb,
                sub_skb->dev = ieee->dev;
                rxb->subframes[rxb->nr_subframes++] = sub_skb;
                if (rxb->nr_subframes >= MAX_SUBFRAME_COUNT) {
-                       RTLLIB_DEBUG_RX("ParseSubframe(): Too many Subframes! Packets dropped!\n");
+                       netdev_dbg(ieee->dev,
+                                  "ParseSubframe(): Too many Subframes! Packets dropped!\n");
                        break;
                }
                skb_pull(skb, nSubframe_Length);
@@ -896,7 +939,8 @@ static int rtllib_rx_check_duplicate(struct rtllib_device *ieee,
                !ieee->current_network.qos_data.active ||
                !IsDataFrame(skb->data) ||
                IsLegacyDataFrame(skb->data)) {
-               if (!((type == RTLLIB_FTYPE_MGMT) && (stype == RTLLIB_STYPE_BEACON))) {
+               if (!((type == RTLLIB_FTYPE_MGMT) &&
+                     (stype == RTLLIB_STYPE_BEACON))) {
                        if (is_duplicate_packet(ieee, hdr))
                                return -1;
                }
@@ -911,7 +955,8 @@ static int rtllib_rx_check_duplicate(struct rtllib_device *ieee,
                        pRxTS->RxLastFragNum = frag;
                        pRxTS->RxLastSeqNum = WLAN_GET_SEQ_SEQ(sc);
                } else {
-                       RTLLIB_DEBUG(RTLLIB_DL_ERR, "ERR!!%s(): No TS!! Skip the check!!\n", __func__);
+                       netdev_warn(ieee->dev, "%s(): No TS! Skip the check!\n",
+                                   __func__);
                        return -1;
                }
        }
@@ -927,24 +972,24 @@ static void rtllib_rx_extract_addr(struct rtllib_device *ieee,
 
        switch (fc & (RTLLIB_FCTL_FROMDS | RTLLIB_FCTL_TODS)) {
        case RTLLIB_FCTL_FROMDS:
-               memcpy(dst, hdr->addr1, ETH_ALEN);
-               memcpy(src, hdr->addr3, ETH_ALEN);
-               memcpy(bssid, hdr->addr2, ETH_ALEN);
+               ether_addr_copy(dst, hdr->addr1);
+               ether_addr_copy(src, hdr->addr3);
+               ether_addr_copy(bssid, hdr->addr2);
                break;
        case RTLLIB_FCTL_TODS:
-               memcpy(dst, hdr->addr3, ETH_ALEN);
-               memcpy(src, hdr->addr2, ETH_ALEN);
-               memcpy(bssid, hdr->addr1, ETH_ALEN);
+               ether_addr_copy(dst, hdr->addr3);
+               ether_addr_copy(src, hdr->addr2);
+               ether_addr_copy(bssid, hdr->addr1);
                break;
        case RTLLIB_FCTL_FROMDS | RTLLIB_FCTL_TODS:
-               memcpy(dst, hdr->addr3, ETH_ALEN);
-               memcpy(src, hdr->addr4, ETH_ALEN);
-               memcpy(bssid, ieee->current_network.bssid, ETH_ALEN);
+               ether_addr_copy(dst, hdr->addr3);
+               ether_addr_copy(src, hdr->addr4);
+               ether_addr_copy(bssid, ieee->current_network.bssid);
                break;
        case 0:
-               memcpy(dst, hdr->addr1, ETH_ALEN);
-               memcpy(src, hdr->addr2, ETH_ALEN);
-               memcpy(bssid, hdr->addr3, ETH_ALEN);
+               ether_addr_copy(dst, hdr->addr1);
+               ether_addr_copy(src, hdr->addr2);
+               ether_addr_copy(bssid, hdr->addr3);
                break;
        }
 }
@@ -984,9 +1029,9 @@ static int rtllib_rx_data_filter(struct rtllib_device *ieee, u16 fc,
                    stype != RTLLIB_STYPE_DATA_CFACKPOLL &&
                    stype != RTLLIB_STYPE_QOS_DATA) {
                        if (stype != RTLLIB_STYPE_NULLFUNC)
-                               RTLLIB_DEBUG_DROP(
-                                       "RX: dropped data frame with no data (type=0x%02x, subtype=0x%02x)\n",
-                                       type, stype);
+                               netdev_dbg(ieee->dev,
+                                          "RX: dropped data frame with no data (type=0x%02x, subtype=0x%02x)\n",
+                                          type, stype);
                        return -1;
                }
        }
@@ -998,7 +1043,8 @@ static int rtllib_rx_data_filter(struct rtllib_device *ieee, u16 fc,
 
                /* {broad,multi}cast packets to our BSS go through */
                if (is_multicast_ether_addr(dst)) {
-                       if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN))
+                       if (memcmp(bssid, ieee->current_network.bssid,
+                                  ETH_ALEN))
                                return -1;
                }
        }
@@ -1030,9 +1076,9 @@ static int rtllib_rx_get_crypt(struct rtllib_device *ieee, struct sk_buff *skb,
                         * frames silently instead of filling system log with
                         * these reports.
                         */
-                       RTLLIB_DEBUG_DROP("Decryption failed (not set) (SA= %pM)\n",
-                                            hdr->addr2);
-                       ieee->ieee_stats.rx_discards_undecryptable++;
+                       netdev_dbg(ieee->dev,
+                                  "Decryption failed (not set) (SA= %pM)\n",
+                                  hdr->addr2);
                        return -1;
                }
        }
@@ -1070,13 +1116,13 @@ static int rtllib_rx_decrypt(struct rtllib_device *ieee, struct sk_buff *skb,
                int flen;
                struct sk_buff *frag_skb = rtllib_frag_cache_get(ieee, hdr);
 
-               RTLLIB_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
+               netdev_dbg(ieee->dev, "Rx Fragment received (%u)\n", frag);
 
                if (!frag_skb) {
-                       RTLLIB_DEBUG(RTLLIB_DL_RX | RTLLIB_DL_FRAG,
-                                       "Rx cannot get skb from fragment cache (morefrag=%d seq=%u frag=%u)\n",
-                                       (fc & RTLLIB_FCTL_MOREFRAGS) != 0,
-                                       WLAN_GET_SEQ_SEQ(sc), frag);
+                       netdev_dbg(ieee->dev,
+                                  "Rx cannot get skb from fragment cache (morefrag=%d seq=%u frag=%u)\n",
+                                  (fc & RTLLIB_FCTL_MOREFRAGS) != 0,
+                                  WLAN_GET_SEQ_SEQ(sc), frag);
                        return -1;
                }
                flen = skb->len;
@@ -1141,29 +1187,29 @@ static int rtllib_rx_decrypt(struct rtllib_device *ieee, struct sk_buff *skb,
                         */
                        struct eapol *eap = (struct eapol *)(skb->data +
                                24);
-                       RTLLIB_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
-                                               eap_get_type(eap->type));
+                       netdev_dbg(ieee->dev,
+                                  "RX: IEEE 802.1X EAPOL frame: %s\n",
+                                  eap_get_type(eap->type));
                } else {
-                       RTLLIB_DEBUG_DROP(
-                               "encryption configured, but RX frame not encrypted (SA= %pM)\n",
-                               hdr->addr2);
+                       netdev_dbg(ieee->dev,
+                                  "encryption configured, but RX frame not encrypted (SA= %pM)\n",
+                                  hdr->addr2);
                        return -1;
                }
        }
 
        if (crypt && !(fc & RTLLIB_FCTL_WEP) &&
            rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
-                       struct eapol *eap = (struct eapol *)(skb->data +
-                               24);
-                       RTLLIB_DEBUG_EAP("RX: IEEE 802.1X EAPOL frame: %s\n",
-                                               eap_get_type(eap->type));
+               struct eapol *eap = (struct eapol *)(skb->data + 24);
+               netdev_dbg(ieee->dev, "RX: IEEE 802.1X EAPOL frame: %s\n",
+                          eap_get_type(eap->type));
        }
 
        if (crypt && !(fc & RTLLIB_FCTL_WEP) && !ieee->open_wep &&
            !rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
-               RTLLIB_DEBUG_DROP(
-                       "dropped unencrypted RX data frame from %pM (drop_unencrypted=1)\n",
-                       hdr->addr2);
+               netdev_dbg(ieee->dev,
+                          "dropped unencrypted RX data frame from %pM (drop_unencrypted=1)\n",
+                          hdr->addr2);
                return -1;
        }
 
@@ -1173,7 +1219,8 @@ static int rtllib_rx_decrypt(struct rtllib_device *ieee, struct sk_buff *skb,
        return 0;
 }
 
-static void rtllib_rx_check_leave_lps(struct rtllib_device *ieee, u8 unicast, u8 nr_subframes)
+static void rtllib_rx_check_leave_lps(struct rtllib_device *ieee, u8 unicast,
+                                     u8 nr_subframes)
 {
        if (unicast) {
 
@@ -1208,25 +1255,33 @@ static void rtllib_rx_indicate_pkt_legacy(struct rtllib_device *ieee,
                struct sk_buff *sub_skb = rxb->subframes[i];
 
                if (sub_skb) {
-                       /* convert hdr + possible LLC headers into Ethernet header */
+                       /* convert hdr + possible LLC headers
+                        * into Ethernet header
+                        */
                        ethertype = (sub_skb->data[6] << 8) | sub_skb->data[7];
                        if (sub_skb->len >= 8 &&
                                ((memcmp(sub_skb->data, rfc1042_header, SNAP_SIZE) == 0 &&
                                ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
                                memcmp(sub_skb->data, bridge_tunnel_header, SNAP_SIZE) == 0)) {
-                               /* remove RFC1042 or Bridge-Tunnel encapsulation and
-                                * replace EtherType
+                               /* remove RFC1042 or Bridge-Tunnel encapsulation
+                                * and replace EtherType
                                 */
                                skb_pull(sub_skb, SNAP_SIZE);
-                               memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
-                               memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
+                               ether_addr_copy(skb_push(sub_skb, ETH_ALEN),
+                                               src);
+                               ether_addr_copy(skb_push(sub_skb, ETH_ALEN),
+                                               dst);
                        } else {
                                u16 len;
-                               /* Leave Ethernet header part of hdr and full payload */
+                               /* Leave Ethernet header part of hdr
+                                * and full payload
+                                */
                                len = sub_skb->len;
                                memcpy(skb_push(sub_skb, 2), &len, 2);
-                               memcpy(skb_push(sub_skb, ETH_ALEN), src, ETH_ALEN);
-                               memcpy(skb_push(sub_skb, ETH_ALEN), dst, ETH_ALEN);
+                               ether_addr_copy(skb_push(sub_skb, ETH_ALEN),
+                                               src);
+                               ether_addr_copy(skb_push(sub_skb, ETH_ALEN),
+                                               dst);
                        }
 
                        ieee->stats.rx_packets++;
@@ -1241,7 +1296,8 @@ static void rtllib_rx_indicate_pkt_legacy(struct rtllib_device *ieee,
                        sub_skb->dev = dev;
                        sub_skb->dev->stats.rx_packets++;
                        sub_skb->dev->stats.rx_bytes += sub_skb->len;
-                       sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
+                       /* 802.11 crc not sufficient */
+                       sub_skb->ip_summed = CHECKSUM_NONE;
                        netif_rx(sub_skb);
                }
        }
@@ -1258,7 +1314,11 @@ static int rtllib_rx_InfraAdhoc(struct rtllib_device *ieee, struct sk_buff *skb,
        struct rx_ts_record *pTS = NULL;
        u16 fc, sc, SeqNum = 0;
        u8 type, stype, multicast = 0, unicast = 0, nr_subframes = 0, TID = 0;
-       u8 dst[ETH_ALEN], src[ETH_ALEN], bssid[ETH_ALEN] = {0}, *payload;
+       u8 *payload;
+       u8 dst[ETH_ALEN];
+       u8 src[ETH_ALEN];
+       u8 bssid[ETH_ALEN] = {0};
+
        size_t hdrlen = 0;
        bool bToOtherSTA = false;
        int ret = 0, i = 0;
@@ -1282,7 +1342,8 @@ static int rtllib_rx_InfraAdhoc(struct rtllib_device *ieee, struct sk_buff *skb,
        /*Filter pkt has too small length */
        hdrlen = rtllib_rx_get_hdrlen(ieee, skb, rx_stats);
        if (skb->len < hdrlen) {
-               netdev_info(dev, "%s():ERR!!! skb->len is smaller than hdrlen\n",
+               netdev_info(dev,
+                           "%s():ERR!!! skb->len is smaller than hdrlen\n",
                            __func__);
                goto rx_dropped;
        }
@@ -1327,10 +1388,13 @@ static int rtllib_rx_InfraAdhoc(struct rtllib_device *ieee, struct sk_buff *skb,
                goto rx_dropped;
 
        /* Send pspoll based on moredata */
-       if ((ieee->iw_mode == IW_MODE_INFRA)  && (ieee->sta_sleep == LPS_IS_SLEEP)
-               && (ieee->polling) && (!bToOtherSTA)) {
+       if ((ieee->iw_mode == IW_MODE_INFRA)  &&
+           (ieee->sta_sleep == LPS_IS_SLEEP) &&
+           (ieee->polling) && (!bToOtherSTA)) {
                if (WLAN_FC_MORE_DATA(fc)) {
-                       /* more data bit is set, let's request a new frame from the AP */
+                       /* more data bit is set, let's request a new frame
+                        * from the AP
+                        */
                        rtllib_sta_ps_send_pspoll_frame(ieee);
                } else {
                        ieee->polling =  false;
@@ -1356,7 +1420,8 @@ static int rtllib_rx_InfraAdhoc(struct rtllib_device *ieee, struct sk_buff *skb,
                && (!bToOtherSTA)) {
                TID = Frame_QoSTID(skb->data);
                SeqNum = WLAN_GET_SEQ_SEQ(sc);
-               GetTs(ieee, (struct ts_common_info **) &pTS, hdr->addr2, TID, RX_DIR, true);
+               GetTs(ieee, (struct ts_common_info **) &pTS, hdr->addr2, TID,
+                     RX_DIR, true);
                if (TID != 0 && TID != 3)
                        ieee->bis_any_nonbepkts = true;
        }
@@ -1371,7 +1436,9 @@ static int rtllib_rx_InfraAdhoc(struct rtllib_device *ieee, struct sk_buff *skb,
        /* to parse amsdu packets */
        /* qos data packets & reserved bit is 1 */
        if (parse_subframe(ieee, skb, rx_stats, rxb, src, dst) == 0) {
-               /* only to free rxb, and not submit the packets to upper layer */
+               /* only to free rxb, and not submit the packets
+                * to upper layer
+                */
                for (i = 0; i < rxb->nr_subframes; i++)
                        dev_kfree_skb(rxb->subframes[i]);
                kfree(rxb);
@@ -1393,7 +1460,8 @@ static int rtllib_rx_InfraAdhoc(struct rtllib_device *ieee, struct sk_buff *skb,
        }
 
        /* Indicate packets to upper layer or Rx Reorder */
-       if (ieee->pHTInfo->bCurRxReorderEnable == false || pTS == NULL || bToOtherSTA)
+       if (ieee->pHTInfo->bCurRxReorderEnable == false || pTS == NULL ||
+           bToOtherSTA)
                rtllib_rx_indicate_pkt_legacy(ieee, rx_stats, rxb, dst, src);
        else
                RxReorderIndicatePacket(ieee, rxb, pTS, SeqNum);
@@ -1462,7 +1530,7 @@ int rtllib_rx(struct rtllib_device *ieee, struct sk_buff *skb,
 {
        int ret = 0;
 
-       if ((NULL == ieee) || (NULL == skb) || (NULL == rx_stats)) {
+       if (!ieee || !skb || !rx_stats) {
                pr_info("%s: Input parameters NULL!\n", __func__);
                goto rx_dropped;
        }
@@ -1522,8 +1590,9 @@ static int rtllib_verify_qos_info(struct rtllib_qos_information_element
 
 /* Parse a QoS parameter element */
 static int rtllib_read_qos_param_element(struct rtllib_qos_parameter_info
-                                           *element_param, struct rtllib_info_element
-                                           *info_element)
+                                                       *element_param,
+                                        struct rtllib_info_element
+                                                       *info_element)
 {
        int ret = 0;
        u16 size = sizeof(struct rtllib_qos_parameter_info) - 2;
@@ -1545,10 +1614,10 @@ static int rtllib_read_qos_param_element(struct rtllib_qos_parameter_info
 }
 
 /* Parse a QoS information element */
-static int rtllib_read_qos_info_element(struct
-                                          rtllib_qos_information_element
-                                          *element_info, struct rtllib_info_element
-                                          *info_element)
+static int rtllib_read_qos_info_element(struct rtllib_qos_information_element
+                                                       *element_info,
+                                       struct rtllib_info_element
+                                                       *info_element)
 {
        int ret = 0;
        u16 size = sizeof(struct rtllib_qos_information_element) - 2;
@@ -1558,7 +1627,8 @@ static int rtllib_read_qos_info_element(struct
        if (info_element == NULL)
                return -1;
 
-       if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
+       if ((info_element->id == QOS_ELEMENT_ID) &&
+           (info_element->len == size)) {
                memcpy(element_info->qui, info_element->data,
                       info_element->len);
                element_info->elementID = info_element->id;
@@ -1568,14 +1638,14 @@ static int rtllib_read_qos_info_element(struct
 
        if (ret == 0)
                ret = rtllib_verify_qos_info(element_info,
-                                               QOS_OUI_INFO_SUB_TYPE);
+                                            QOS_OUI_INFO_SUB_TYPE);
        return ret;
 }
 
 
 /* Write QoS parameters from the ac parameters. */
 static int rtllib_qos_convert_ac_to_parameters(struct rtllib_qos_parameter_info *param_elm,
-               struct rtllib_qos_data *qos_data)
+                                              struct rtllib_qos_data *qos_data)
 {
        struct rtllib_qos_ac_parameter *ac_params;
        struct rtllib_qos_parameters *qos_param = &(qos_data->parameters);
@@ -1619,11 +1689,13 @@ static int rtllib_qos_convert_ac_to_parameters(struct rtllib_qos_parameter_info
                qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f;
 
                /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
-               qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2 : qos_param->aifs[aci];
+               qos_param->aifs[aci] = max_t(u8, qos_param->aifs[aci], 2);
 
-               qos_param->cw_min[aci] = cpu_to_le16(ac_params->ecw_min_max & 0x0F);
+               qos_param->cw_min[aci] = cpu_to_le16(ac_params->ecw_min_max &
+                                                    0x0F);
 
-               qos_param->cw_max[aci] = cpu_to_le16((ac_params->ecw_min_max & 0xF0) >> 4);
+               qos_param->cw_max[aci] = cpu_to_le16((ac_params->ecw_min_max &
+                                                     0xF0) >> 4);
 
                qos_param->flag[aci] =
                    (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
@@ -1636,9 +1708,10 @@ static int rtllib_qos_convert_ac_to_parameters(struct rtllib_qos_parameter_info
  * parameters element. check the information element length to decide
  * which type to read
  */
-static int rtllib_parse_qos_info_param_IE(struct rtllib_info_element
+static int rtllib_parse_qos_info_param_IE(struct rtllib_device *ieee,
+                                         struct rtllib_info_element
                                             *info_element,
-                                            struct rtllib_network *network)
+                                         struct rtllib_network *network)
 {
        int rc = 0;
        struct rtllib_qos_information_element qos_info_element;
@@ -1663,43 +1736,67 @@ static int rtllib_parse_qos_info_param_IE(struct rtllib_info_element
        }
 
        if (rc == 0) {
-               RTLLIB_DEBUG_QOS("QoS is supported\n");
+               netdev_dbg(ieee->dev, "QoS is supported\n");
                network->qos_data.supported = 1;
        }
        return rc;
 }
 
-#define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
-
 static const char *get_info_element_string(u16 id)
 {
        switch (id) {
-       MFIE_STRING(SSID);
-       MFIE_STRING(RATES);
-       MFIE_STRING(FH_SET);
-       MFIE_STRING(DS_SET);
-       MFIE_STRING(CF_SET);
-       MFIE_STRING(TIM);
-       MFIE_STRING(IBSS_SET);
-       MFIE_STRING(COUNTRY);
-       MFIE_STRING(HOP_PARAMS);
-       MFIE_STRING(HOP_TABLE);
-       MFIE_STRING(REQUEST);
-       MFIE_STRING(CHALLENGE);
-       MFIE_STRING(POWER_CONSTRAINT);
-       MFIE_STRING(POWER_CAPABILITY);
-       MFIE_STRING(TPC_REQUEST);
-       MFIE_STRING(TPC_REPORT);
-       MFIE_STRING(SUPP_CHANNELS);
-       MFIE_STRING(CSA);
-       MFIE_STRING(MEASURE_REQUEST);
-       MFIE_STRING(MEASURE_REPORT);
-       MFIE_STRING(QUIET);
-       MFIE_STRING(IBSS_DFS);
-       MFIE_STRING(RSN);
-       MFIE_STRING(RATES_EX);
-       MFIE_STRING(GENERIC);
-       MFIE_STRING(QOS_PARAMETER);
+       case MFIE_TYPE_SSID:
+               return "SSID";
+       case MFIE_TYPE_RATES:
+               return "RATES";
+       case MFIE_TYPE_FH_SET:
+               return "FH_SET";
+       case MFIE_TYPE_DS_SET:
+               return "DS_SET";
+       case MFIE_TYPE_CF_SET:
+               return "CF_SET";
+       case MFIE_TYPE_TIM:
+               return "TIM";
+       case MFIE_TYPE_IBSS_SET:
+               return "IBSS_SET";
+       case MFIE_TYPE_COUNTRY:
+               return "COUNTRY";
+       case MFIE_TYPE_HOP_PARAMS:
+               return "HOP_PARAMS";
+       case MFIE_TYPE_HOP_TABLE:
+               return "HOP_TABLE";
+       case MFIE_TYPE_REQUEST:
+               return "REQUEST";
+       case MFIE_TYPE_CHALLENGE:
+               return "CHALLENGE";
+       case MFIE_TYPE_POWER_CONSTRAINT:
+               return "POWER_CONSTRAINT";
+       case MFIE_TYPE_POWER_CAPABILITY:
+               return "POWER_CAPABILITY";
+       case MFIE_TYPE_TPC_REQUEST:
+               return "TPC_REQUEST";
+       case MFIE_TYPE_TPC_REPORT:
+               return "TPC_REPORT";
+       case MFIE_TYPE_SUPP_CHANNELS:
+               return "SUPP_CHANNELS";
+       case MFIE_TYPE_CSA:
+               return "CSA";
+       case MFIE_TYPE_MEASURE_REQUEST:
+               return "MEASURE_REQUEST";
+       case MFIE_TYPE_MEASURE_REPORT:
+               return "MEASURE_REPORT";
+       case MFIE_TYPE_QUIET:
+               return "QUIET";
+       case MFIE_TYPE_IBSS_DFS:
+               return "IBSS_DFS";
+       case MFIE_TYPE_RSN:
+               return "RSN";
+       case MFIE_TYPE_RATES_EX:
+               return "RATES_EX";
+       case MFIE_TYPE_GENERIC:
+               return "GENERIC";
+       case MFIE_TYPE_QOS_PARAMETER:
+               return "QOS_PARAMETER";
        default:
                return "UNKNOWN";
        }
@@ -1713,15 +1810,19 @@ static inline void rtllib_extract_country_ie(
 {
        if (IS_DOT11D_ENABLE(ieee)) {
                if (info_element->len != 0) {
-                       memcpy(network->CountryIeBuf, info_element->data, info_element->len);
+                       memcpy(network->CountryIeBuf, info_element->data,
+                              info_element->len);
                        network->CountryIeLen = info_element->len;
 
                        if (!IS_COUNTRY_IE_VALID(ieee)) {
-                               if (rtllib_act_scanning(ieee, false) && ieee->FirstIe_InScan)
+                               if (rtllib_act_scanning(ieee, false) &&
+                                   ieee->FirstIe_InScan)
                                        netdev_info(ieee->dev,
                                                    "Received beacon ContryIE, SSID: <%s>\n",
                                                    network->ssid);
-                               Dot11d_UpdateCountryIe(ieee, addr2, info_element->len, info_element->data);
+                               Dot11d_UpdateCountryIe(ieee, addr2,
+                                                      info_element->len,
+                                                      info_element->data);
                        }
                }
 
@@ -1731,6 +1832,234 @@ static inline void rtllib_extract_country_ie(
 
 }
 
+static void rtllib_parse_mife_generic(struct rtllib_device *ieee,
+                                     struct rtllib_info_element *info_element,
+                                     struct rtllib_network *network,
+                                     u16 *tmp_htcap_len,
+                                     u16 *tmp_htinfo_len)
+{
+       u16 ht_realtek_agg_len = 0;
+       u8  ht_realtek_agg_buf[MAX_IE_LEN];
+
+       if (!rtllib_parse_qos_info_param_IE(ieee, info_element, network))
+               return;
+       if (info_element->len >= 4 &&
+           info_element->data[0] == 0x00 &&
+           info_element->data[1] == 0x50 &&
+           info_element->data[2] == 0xf2 &&
+           info_element->data[3] == 0x01) {
+               network->wpa_ie_len = min(info_element->len + 2,
+                                         MAX_WPA_IE_LEN);
+               memcpy(network->wpa_ie, info_element, network->wpa_ie_len);
+               return;
+       }
+       if (info_element->len == 7 &&
+           info_element->data[0] == 0x00 &&
+           info_element->data[1] == 0xe0 &&
+           info_element->data[2] == 0x4c &&
+           info_element->data[3] == 0x01 &&
+           info_element->data[4] == 0x02)
+               network->Turbo_Enable = 1;
+
+       if (*tmp_htcap_len == 0) {
+               if (info_element->len >= 4 &&
+                   info_element->data[0] == 0x00 &&
+                   info_element->data[1] == 0x90 &&
+                   info_element->data[2] == 0x4c &&
+                   info_element->data[3] == 0x033) {
+                       *tmp_htcap_len = min_t(u8, info_element->len,
+                                              MAX_IE_LEN);
+                       if (*tmp_htcap_len != 0) {
+                               network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
+                               network->bssht.bdHTCapLen = min_t(u16, *tmp_htcap_len, sizeof(network->bssht.bdHTCapBuf));
+                               memcpy(network->bssht.bdHTCapBuf,
+                                      info_element->data,
+                                      network->bssht.bdHTCapLen);
+                       }
+               }
+               if (*tmp_htcap_len != 0) {
+                       network->bssht.bdSupportHT = true;
+                       network->bssht.bdHT1R = ((((struct ht_capab_ele *)(network->bssht.bdHTCapBuf))->MCS[1]) == 0);
+               } else {
+                       network->bssht.bdSupportHT = false;
+                       network->bssht.bdHT1R = false;
+               }
+       }
+
+
+       if (*tmp_htinfo_len == 0) {
+               if (info_element->len >= 4 &&
+                   info_element->data[0] == 0x00 &&
+                   info_element->data[1] == 0x90 &&
+                   info_element->data[2] == 0x4c &&
+                   info_element->data[3] == 0x034) {
+                       *tmp_htinfo_len = min_t(u8, info_element->len,
+                                               MAX_IE_LEN);
+                       if (*tmp_htinfo_len != 0) {
+                               network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
+                               network->bssht.bdHTInfoLen = min_t(u16, *tmp_htinfo_len, sizeof(network->bssht.bdHTInfoBuf));
+                               memcpy(network->bssht.bdHTInfoBuf,
+                                      info_element->data,
+                                      network->bssht.bdHTInfoLen);
+                       }
+
+               }
+       }
+
+       if (network->bssht.bdSupportHT) {
+               if (info_element->len >= 4 &&
+                   info_element->data[0] == 0x00 &&
+                   info_element->data[1] == 0xe0 &&
+                   info_element->data[2] == 0x4c &&
+                   info_element->data[3] == 0x02) {
+                       ht_realtek_agg_len = min_t(u8, info_element->len,
+                                                  MAX_IE_LEN);
+                       memcpy(ht_realtek_agg_buf, info_element->data,
+                              info_element->len);
+               }
+               if (ht_realtek_agg_len >= 5) {
+                       network->realtek_cap_exit = true;
+                       network->bssht.bdRT2RTAggregation = true;
+
+                       if ((ht_realtek_agg_buf[4] == 1) &&
+                           (ht_realtek_agg_buf[5] & 0x02))
+                               network->bssht.bdRT2RTLongSlotTime = true;
+
+                       if ((ht_realtek_agg_buf[4] == 1) &&
+                           (ht_realtek_agg_buf[5] & RT_HT_CAP_USE_92SE))
+                               network->bssht.RT2RT_HT_Mode |= RT_HT_CAP_USE_92SE;
+               }
+       }
+       if (ht_realtek_agg_len >= 5) {
+               if ((ht_realtek_agg_buf[5] & RT_HT_CAP_USE_SOFTAP))
+                       network->bssht.RT2RT_HT_Mode |= RT_HT_CAP_USE_SOFTAP;
+       }
+
+       if ((info_element->len >= 3 &&
+            info_element->data[0] == 0x00 &&
+            info_element->data[1] == 0x05 &&
+            info_element->data[2] == 0xb5) ||
+            (info_element->len >= 3 &&
+            info_element->data[0] == 0x00 &&
+            info_element->data[1] == 0x0a &&
+            info_element->data[2] == 0xf7) ||
+            (info_element->len >= 3 &&
+            info_element->data[0] == 0x00 &&
+            info_element->data[1] == 0x10 &&
+            info_element->data[2] == 0x18)) {
+               network->broadcom_cap_exist = true;
+       }
+       if (info_element->len >= 3 &&
+           info_element->data[0] == 0x00 &&
+           info_element->data[1] == 0x0c &&
+           info_element->data[2] == 0x43)
+               network->ralink_cap_exist = true;
+       if ((info_element->len >= 3 &&
+            info_element->data[0] == 0x00 &&
+            info_element->data[1] == 0x03 &&
+            info_element->data[2] == 0x7f) ||
+            (info_element->len >= 3 &&
+            info_element->data[0] == 0x00 &&
+            info_element->data[1] == 0x13 &&
+            info_element->data[2] == 0x74))
+               network->atheros_cap_exist = true;
+
+       if ((info_element->len >= 3 &&
+            info_element->data[0] == 0x00 &&
+            info_element->data[1] == 0x50 &&
+            info_element->data[2] == 0x43))
+               network->marvell_cap_exist = true;
+       if (info_element->len >= 3 &&
+           info_element->data[0] == 0x00 &&
+           info_element->data[1] == 0x40 &&
+           info_element->data[2] == 0x96)
+               network->cisco_cap_exist = true;
+
+
+       if (info_element->len >= 3 &&
+           info_element->data[0] == 0x00 &&
+           info_element->data[1] == 0x0a &&
+           info_element->data[2] == 0xf5)
+               network->airgo_cap_exist = true;
+
+       if (info_element->len > 4 &&
+           info_element->data[0] == 0x00 &&
+           info_element->data[1] == 0x40 &&
+           info_element->data[2] == 0x96 &&
+           info_element->data[3] == 0x01) {
+               if (info_element->len == 6) {
+                       memcpy(network->CcxRmState, &info_element[4], 2);
+                       if (network->CcxRmState[0] != 0)
+                               network->bCcxRmEnable = true;
+                       else
+                               network->bCcxRmEnable = false;
+                       network->MBssidMask = network->CcxRmState[1] & 0x07;
+                       if (network->MBssidMask != 0) {
+                               network->bMBssidValid = true;
+                               network->MBssidMask = 0xff <<
+                                                     (network->MBssidMask);
+                               ether_addr_copy(network->MBssid,
+                                               network->bssid);
+                               network->MBssid[5] &= network->MBssidMask;
+                       } else {
+                               network->bMBssidValid = false;
+                       }
+               } else {
+                       network->bCcxRmEnable = false;
+               }
+       }
+       if (info_element->len > 4  &&
+           info_element->data[0] == 0x00 &&
+           info_element->data[1] == 0x40 &&
+           info_element->data[2] == 0x96 &&
+           info_element->data[3] == 0x03) {
+               if (info_element->len == 5) {
+                       network->bWithCcxVerNum = true;
+                       network->BssCcxVerNumber = info_element->data[4];
+               } else {
+                       network->bWithCcxVerNum = false;
+                       network->BssCcxVerNumber = 0;
+               }
+       }
+       if (info_element->len > 4  &&
+           info_element->data[0] == 0x00 &&
+           info_element->data[1] == 0x50 &&
+           info_element->data[2] == 0xf2 &&
+           info_element->data[3] == 0x04) {
+               netdev_dbg(ieee->dev, "MFIE_TYPE_WZC: %d bytes\n",
+                          info_element->len);
+               network->wzc_ie_len = min(info_element->len+2, MAX_WZC_IE_LEN);
+               memcpy(network->wzc_ie, info_element, network->wzc_ie_len);
+       }
+}
+
+static void rtllib_parse_mfie_ht_cap(struct rtllib_info_element *info_element,
+                                    struct rtllib_network *network,
+                                    u16 *tmp_htcap_len)
+{
+       struct bss_ht *ht = &network->bssht;
+
+       *tmp_htcap_len = min_t(u8, info_element->len, MAX_IE_LEN);
+       if (*tmp_htcap_len != 0) {
+               ht->bdHTSpecVer = HT_SPEC_VER_EWC;
+               ht->bdHTCapLen = min_t(u16, *tmp_htcap_len,
+                                      sizeof(ht->bdHTCapBuf));
+               memcpy(ht->bdHTCapBuf, info_element->data, ht->bdHTCapLen);
+
+               ht->bdSupportHT = true;
+               ht->bdHT1R = ((((struct ht_capab_ele *)
+                               ht->bdHTCapBuf))->MCS[1]) == 0;
+
+               ht->bdBandWidth = (enum ht_channel_width)
+                                            (((struct ht_capab_ele *)
+                                            (ht->bdHTCapBuf))->ChlWidth);
+       } else {
+               ht->bdSupportHT = false;
+               ht->bdHT1R = false;
+               ht->bdBandWidth = HT_CHANNEL_WIDTH_20;
+       }
+}
+
 int rtllib_parse_info_param(struct rtllib_device *ieee,
                struct rtllib_info_element *info_element,
                u16 length,
@@ -1741,17 +2070,15 @@ int rtllib_parse_info_param(struct rtllib_device *ieee,
        short offset;
        u16     tmp_htcap_len = 0;
        u16     tmp_htinfo_len = 0;
-       u16 ht_realtek_agg_len = 0;
-       u8  ht_realtek_agg_buf[MAX_IE_LEN];
        char rates_str[64];
        char *p;
 
        while (length >= sizeof(*info_element)) {
                if (sizeof(*info_element) + info_element->len > length) {
-                       RTLLIB_DEBUG_MGMT("Info elem: parse failed: info_element->len + 2 > left : info_element->len+2=%zd left=%d, id=%d.\n",
-                                            info_element->len +
-                                            sizeof(*info_element),
-                                            length, info_element->id);
+                       netdev_dbg(ieee->dev,
+                                  "Info elem: parse failed: info_element->len + 2 > left : info_element->len+2=%zd left=%d, id=%d.\n",
+                                  info_element->len + sizeof(*info_element),
+                                  length, info_element->id);
                        /* We stop processing but don't return an error here
                         * because some misbehaviour APs break this rule. ie.
                         * Orinoco AP1000.
@@ -1769,13 +2096,14 @@ int rtllib_parse_info_param(struct rtllib_device *ieee,
 
                        network->ssid_len = min(info_element->len,
                                                (u8) IW_ESSID_MAX_SIZE);
-                       memcpy(network->ssid, info_element->data, network->ssid_len);
+                       memcpy(network->ssid, info_element->data,
+                              network->ssid_len);
                        if (network->ssid_len < IW_ESSID_MAX_SIZE)
                                memset(network->ssid + network->ssid_len, 0,
                                       IW_ESSID_MAX_SIZE - network->ssid_len);
 
-                       RTLLIB_DEBUG_MGMT("MFIE_TYPE_SSID: '%s' len=%d.\n",
-                                            network->ssid, network->ssid_len);
+                       netdev_dbg(ieee->dev, "MFIE_TYPE_SSID: '%s' len=%d.\n",
+                                  network->ssid, network->ssid_len);
                        break;
 
                case MFIE_TYPE_RATES:
@@ -1802,8 +2130,8 @@ int rtllib_parse_info_param(struct rtllib_device *ieee,
                                }
                        }
 
-                       RTLLIB_DEBUG_MGMT("MFIE_TYPE_RATES: '%s' (%d)\n",
-                                            rates_str, network->rates_len);
+                       netdev_dbg(ieee->dev, "MFIE_TYPE_RATES: '%s' (%d)\n",
+                                  rates_str, network->rates_len);
                        break;
 
                case MFIE_TYPE_RATES_EX:
@@ -1825,22 +2153,22 @@ int rtllib_parse_info_param(struct rtllib_device *ieee,
                                }
                        }
 
-                       RTLLIB_DEBUG_MGMT("MFIE_TYPE_RATES_EX: '%s' (%d)\n",
-                                            rates_str, network->rates_ex_len);
+                       netdev_dbg(ieee->dev, "MFIE_TYPE_RATES_EX: '%s' (%d)\n",
+                                  rates_str, network->rates_ex_len);
                        break;
 
                case MFIE_TYPE_DS_SET:
-                       RTLLIB_DEBUG_MGMT("MFIE_TYPE_DS_SET: %d\n",
-                                            info_element->data[0]);
+                       netdev_dbg(ieee->dev, "MFIE_TYPE_DS_SET: %d\n",
+                                  info_element->data[0]);
                        network->channel = info_element->data[0];
                        break;
 
                case MFIE_TYPE_FH_SET:
-                       RTLLIB_DEBUG_MGMT("MFIE_TYPE_FH_SET: ignored\n");
+                       netdev_dbg(ieee->dev, "MFIE_TYPE_FH_SET: ignored\n");
                        break;
 
                case MFIE_TYPE_CF_SET:
-                       RTLLIB_DEBUG_MGMT("MFIE_TYPE_CF_SET: ignored\n");
+                       netdev_dbg(ieee->dev, "MFIE_TYPE_CF_SET: ignored\n");
                        break;
 
                case MFIE_TYPE_TIM:
@@ -1879,217 +2207,31 @@ int rtllib_parse_info_param(struct rtllib_device *ieee,
                case MFIE_TYPE_ERP:
                        network->erp_value = info_element->data[0];
                        network->flags |= NETWORK_HAS_ERP_VALUE;
-                       RTLLIB_DEBUG_MGMT("MFIE_TYPE_ERP_SET: %d\n",
-                                            network->erp_value);
+                       netdev_dbg(ieee->dev, "MFIE_TYPE_ERP_SET: %d\n",
+                                  network->erp_value);
                        break;
                case MFIE_TYPE_IBSS_SET:
                        network->atim_window = info_element->data[0];
-                       RTLLIB_DEBUG_MGMT("MFIE_TYPE_IBSS_SET: %d\n",
-                                            network->atim_window);
+                       netdev_dbg(ieee->dev, "MFIE_TYPE_IBSS_SET: %d\n",
+                                  network->atim_window);
                        break;
 
                case MFIE_TYPE_CHALLENGE:
-                       RTLLIB_DEBUG_MGMT("MFIE_TYPE_CHALLENGE: ignored\n");
+                       netdev_dbg(ieee->dev, "MFIE_TYPE_CHALLENGE: ignored\n");
                        break;
 
                case MFIE_TYPE_GENERIC:
-                       RTLLIB_DEBUG_MGMT("MFIE_TYPE_GENERIC: %d bytes\n",
-                                            info_element->len);
-                       if (!rtllib_parse_qos_info_param_IE(info_element,
-                                                              network))
-                               break;
-                       if (info_element->len >= 4 &&
-                           info_element->data[0] == 0x00 &&
-                           info_element->data[1] == 0x50 &&
-                           info_element->data[2] == 0xf2 &&
-                           info_element->data[3] == 0x01) {
-                               network->wpa_ie_len = min(info_element->len + 2,
-                                                         MAX_WPA_IE_LEN);
-                               memcpy(network->wpa_ie, info_element,
-                                      network->wpa_ie_len);
-                               break;
-                       }
-                       if (info_element->len == 7 &&
-                           info_element->data[0] == 0x00 &&
-                           info_element->data[1] == 0xe0 &&
-                           info_element->data[2] == 0x4c &&
-                           info_element->data[3] == 0x01 &&
-                           info_element->data[4] == 0x02)
-                               network->Turbo_Enable = 1;
-
-                       if (tmp_htcap_len == 0) {
-                               if (info_element->len >= 4 &&
-                                  info_element->data[0] == 0x00 &&
-                                  info_element->data[1] == 0x90 &&
-                                  info_element->data[2] == 0x4c &&
-                                  info_element->data[3] == 0x033) {
-
-                                               tmp_htcap_len = min_t(u8, info_element->len, MAX_IE_LEN);
-                                               if (tmp_htcap_len != 0) {
-                                                       network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
-                                                       network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf) ?
-                                                               sizeof(network->bssht.bdHTCapBuf) : tmp_htcap_len;
-                                                       memcpy(network->bssht.bdHTCapBuf, info_element->data, network->bssht.bdHTCapLen);
-                                               }
-                               }
-                               if (tmp_htcap_len != 0) {
-                                       network->bssht.bdSupportHT = true;
-                                       network->bssht.bdHT1R = ((((struct ht_capab_ele *)(network->bssht.bdHTCapBuf))->MCS[1]) == 0);
-                               } else {
-                                       network->bssht.bdSupportHT = false;
-                                       network->bssht.bdHT1R = false;
-                               }
-                       }
-
-
-                       if (tmp_htinfo_len == 0) {
-                               if (info_element->len >= 4 &&
-                                   info_element->data[0] == 0x00 &&
-                                   info_element->data[1] == 0x90 &&
-                                   info_element->data[2] == 0x4c &&
-                                   info_element->data[3] == 0x034) {
-                                       tmp_htinfo_len = min_t(u8, info_element->len, MAX_IE_LEN);
-                                       if (tmp_htinfo_len != 0) {
-                                               network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
-                                               if (tmp_htinfo_len) {
-                                                       network->bssht.bdHTInfoLen = tmp_htinfo_len > sizeof(network->bssht.bdHTInfoBuf) ?
-                                                               sizeof(network->bssht.bdHTInfoBuf) : tmp_htinfo_len;
-                                                       memcpy(network->bssht.bdHTInfoBuf, info_element->data, network->bssht.bdHTInfoLen);
-                                               }
-
-                                       }
-
-                               }
-                       }
-
-                       if (ieee->aggregation) {
-                               if (network->bssht.bdSupportHT) {
-                                       if (info_element->len >= 4 &&
-                                           info_element->data[0] == 0x00 &&
-                                           info_element->data[1] == 0xe0 &&
-                                           info_element->data[2] == 0x4c &&
-                                           info_element->data[3] == 0x02) {
-                                               ht_realtek_agg_len = min_t(u8, info_element->len, MAX_IE_LEN);
-                                               memcpy(ht_realtek_agg_buf, info_element->data, info_element->len);
-                                       }
-                                       if (ht_realtek_agg_len >= 5) {
-                                               network->realtek_cap_exit = true;
-                                               network->bssht.bdRT2RTAggregation = true;
-
-                                               if ((ht_realtek_agg_buf[4] == 1) && (ht_realtek_agg_buf[5] & 0x02))
-                                                       network->bssht.bdRT2RTLongSlotTime = true;
-
-                                               if ((ht_realtek_agg_buf[4] == 1) && (ht_realtek_agg_buf[5] & RT_HT_CAP_USE_92SE))
-                                                       network->bssht.RT2RT_HT_Mode |= RT_HT_CAP_USE_92SE;
-                                       }
-                               }
-                               if (ht_realtek_agg_len >= 5) {
-                                       if ((ht_realtek_agg_buf[5] & RT_HT_CAP_USE_SOFTAP))
-                                               network->bssht.RT2RT_HT_Mode |= RT_HT_CAP_USE_SOFTAP;
-                               }
-                       }
+                       netdev_dbg(ieee->dev, "MFIE_TYPE_GENERIC: %d bytes\n",
+                                  info_element->len);
 
-                       if ((info_element->len >= 3 &&
-                            info_element->data[0] == 0x00 &&
-                            info_element->data[1] == 0x05 &&
-                            info_element->data[2] == 0xb5) ||
-                            (info_element->len >= 3 &&
-                            info_element->data[0] == 0x00 &&
-                            info_element->data[1] == 0x0a &&
-                            info_element->data[2] == 0xf7) ||
-                            (info_element->len >= 3 &&
-                            info_element->data[0] == 0x00 &&
-                            info_element->data[1] == 0x10 &&
-                            info_element->data[2] == 0x18)) {
-                               network->broadcom_cap_exist = true;
-                       }
-                       if (info_element->len >= 3 &&
-                           info_element->data[0] == 0x00 &&
-                           info_element->data[1] == 0x0c &&
-                           info_element->data[2] == 0x43)
-                               network->ralink_cap_exist = true;
-                       if ((info_element->len >= 3 &&
-                            info_element->data[0] == 0x00 &&
-                            info_element->data[1] == 0x03 &&
-                            info_element->data[2] == 0x7f) ||
-                            (info_element->len >= 3 &&
-                            info_element->data[0] == 0x00 &&
-                            info_element->data[1] == 0x13 &&
-                            info_element->data[2] == 0x74))
-                               network->atheros_cap_exist = true;
-
-                       if ((info_element->len >= 3 &&
-                            info_element->data[0] == 0x00 &&
-                            info_element->data[1] == 0x50 &&
-                            info_element->data[2] == 0x43))
-                               network->marvell_cap_exist = true;
-                       if (info_element->len >= 3 &&
-                           info_element->data[0] == 0x00 &&
-                           info_element->data[1] == 0x40 &&
-                           info_element->data[2] == 0x96)
-                               network->cisco_cap_exist = true;
-
-
-                       if (info_element->len >= 3 &&
-                           info_element->data[0] == 0x00 &&
-                           info_element->data[1] == 0x0a &&
-                           info_element->data[2] == 0xf5)
-                               network->airgo_cap_exist = true;
-
-                       if (info_element->len > 4 &&
-                           info_element->data[0] == 0x00 &&
-                           info_element->data[1] == 0x40 &&
-                           info_element->data[2] == 0x96 &&
-                           info_element->data[3] == 0x01) {
-                               if (info_element->len == 6) {
-                                       memcpy(network->CcxRmState, &info_element[4], 2);
-                                       if (network->CcxRmState[0] != 0)
-                                               network->bCcxRmEnable = true;
-                                       else
-                                               network->bCcxRmEnable = false;
-                                       network->MBssidMask = network->CcxRmState[1] & 0x07;
-                                       if (network->MBssidMask != 0) {
-                                               network->bMBssidValid = true;
-                                               network->MBssidMask = 0xff << (network->MBssidMask);
-                                               memcpy(network->MBssid, network->bssid, ETH_ALEN);
-                                               network->MBssid[5] &= network->MBssidMask;
-                                       } else {
-                                               network->bMBssidValid = false;
-                                       }
-                               } else {
-                                       network->bCcxRmEnable = false;
-                               }
-                       }
-                       if (info_element->len > 4  &&
-                           info_element->data[0] == 0x00 &&
-                           info_element->data[1] == 0x40 &&
-                           info_element->data[2] == 0x96 &&
-                           info_element->data[3] == 0x03) {
-                               if (info_element->len == 5) {
-                                       network->bWithCcxVerNum = true;
-                                       network->BssCcxVerNumber = info_element->data[4];
-                               } else {
-                                       network->bWithCcxVerNum = false;
-                                       network->BssCcxVerNumber = 0;
-                               }
-                       }
-                       if (info_element->len > 4  &&
-                           info_element->data[0] == 0x00 &&
-                           info_element->data[1] == 0x50 &&
-                           info_element->data[2] == 0xf2 &&
-                           info_element->data[3] == 0x04) {
-                               RTLLIB_DEBUG_MGMT("MFIE_TYPE_WZC: %d bytes\n",
-                                                    info_element->len);
-                               network->wzc_ie_len = min(info_element->len+2,
-                                                         MAX_WZC_IE_LEN);
-                               memcpy(network->wzc_ie, info_element,
-                                               network->wzc_ie_len);
-                       }
+                       rtllib_parse_mife_generic(ieee, info_element, network,
+                                                 &tmp_htcap_len,
+                                                 &tmp_htinfo_len);
                        break;
 
                case MFIE_TYPE_RSN:
-                       RTLLIB_DEBUG_MGMT("MFIE_TYPE_RSN: %d bytes\n",
-                                            info_element->len);
+                       netdev_dbg(ieee->dev, "MFIE_TYPE_RSN: %d bytes\n",
+                                  info_element->len);
                        network->rsn_ie_len = min(info_element->len + 2,
                                                  MAX_WPA_IE_LEN);
                        memcpy(network->rsn_ie, info_element,
@@ -2097,36 +2239,19 @@ int rtllib_parse_info_param(struct rtllib_device *ieee,
                        break;
 
                case MFIE_TYPE_HT_CAP:
-                       RTLLIB_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
-                                            info_element->len);
-                       tmp_htcap_len = min_t(u8, info_element->len, MAX_IE_LEN);
-                       if (tmp_htcap_len != 0) {
-                               network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
-                               network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf) ?
-                                       sizeof(network->bssht.bdHTCapBuf) : tmp_htcap_len;
-                               memcpy(network->bssht.bdHTCapBuf,
-                                      info_element->data,
-                                      network->bssht.bdHTCapLen);
+                       netdev_dbg(ieee->dev, "MFIE_TYPE_HT_CAP: %d bytes\n",
+                                  info_element->len);
 
-                               network->bssht.bdSupportHT = true;
-                               network->bssht.bdHT1R = ((((struct ht_capab_ele *)
-                                                       network->bssht.bdHTCapBuf))->MCS[1]) == 0;
-
-                               network->bssht.bdBandWidth = (enum ht_channel_width)
-                                                            (((struct ht_capab_ele *)
-                                                            (network->bssht.bdHTCapBuf))->ChlWidth);
-                       } else {
-                               network->bssht.bdSupportHT = false;
-                               network->bssht.bdHT1R = false;
-                               network->bssht.bdBandWidth = HT_CHANNEL_WIDTH_20;
-                       }
+                       rtllib_parse_mfie_ht_cap(info_element, network,
+                                                &tmp_htcap_len);
                        break;
 
 
                case MFIE_TYPE_HT_INFO:
-                       RTLLIB_DEBUG_SCAN("MFIE_TYPE_HT_INFO: %d bytes\n",
-                                            info_element->len);
-                       tmp_htinfo_len = min_t(u8, info_element->len, MAX_IE_LEN);
+                       netdev_dbg(ieee->dev, "MFIE_TYPE_HT_INFO: %d bytes\n",
+                                  info_element->len);
+                       tmp_htinfo_len = min_t(u8, info_element->len,
+                                              MAX_IE_LEN);
                        if (tmp_htinfo_len) {
                                network->bssht.bdHTSpecVer = HT_SPEC_VER_IEEE;
                                network->bssht.bdHTInfoLen = tmp_htinfo_len >
@@ -2140,8 +2265,8 @@ int rtllib_parse_info_param(struct rtllib_device *ieee,
                        break;
 
                case MFIE_TYPE_AIRONET:
-                       RTLLIB_DEBUG_SCAN("MFIE_TYPE_AIRONET: %d bytes\n",
-                                            info_element->len);
+                       netdev_dbg(ieee->dev, "MFIE_TYPE_AIRONET: %d bytes\n",
+                                  info_element->len);
                        if (info_element->len > IE_CISCO_FLAG_POSITION) {
                                network->bWithAironetIE = true;
 
@@ -2163,17 +2288,17 @@ int rtllib_parse_info_param(struct rtllib_device *ieee,
                        break;
 
                case MFIE_TYPE_COUNTRY:
-                       RTLLIB_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
-                                            info_element->len);
+                       netdev_dbg(ieee->dev, "MFIE_TYPE_COUNTRY: %d bytes\n",
+                                  info_element->len);
                        rtllib_extract_country_ie(ieee, info_element, network,
                                                  network->bssid);
                        break;
 /* TODO */
                default:
-                       RTLLIB_DEBUG_MGMT
-                           ("Unsupported info element: %s (%d)\n",
-                            get_info_element_string(info_element->id),
-                            info_element->id);
+                       netdev_dbg(ieee->dev,
+                                  "Unsupported info element: %s (%d)\n",
+                                  get_info_element_string(info_element->id),
+                                  info_element->id);
                        break;
                }
 
@@ -2211,7 +2336,7 @@ static inline int rtllib_network_init(
        memset(&network->qos_data, 0, sizeof(struct rtllib_qos_data));
 
        /* Pull out fixed field data */
-       memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
+       ether_addr_copy(network->bssid, beacon->header.addr3);
        network->capability = le16_to_cpu(beacon->capability);
        network->last_scanned = jiffies;
        network->time_stamp[0] = beacon->time_stamp[0];
@@ -2220,7 +2345,6 @@ static inline int rtllib_network_init(
        /* Where to pull this? beacon->listen_interval;*/
        network->listen_interval = 0x0A;
        network->rates_len = network->rates_ex_len = 0;
-       network->last_associate = 0;
        network->ssid_len = 0;
        network->hidden_ssid_len = 0;
        memset(network->hidden_ssid, 0, sizeof(network->hidden_ssid));
@@ -2271,10 +2395,9 @@ static inline int rtllib_network_init(
        }
 
        if (network->mode == 0) {
-               RTLLIB_DEBUG_SCAN("Filtered out '%s (%pM)' network.\n",
-                                    escape_essid(network->ssid,
-                                                 network->ssid_len),
-                                    network->bssid);
+               netdev_dbg(ieee->dev, "Filtered out '%s (%pM)' network.\n",
+                          escape_essid(network->ssid, network->ssid_len),
+                          network->bssid);
                return 1;
        }
 
@@ -2314,7 +2437,8 @@ static inline int is_same_network(struct rtllib_network *src,
 }
 
 
-static inline void update_network(struct rtllib_network *dst,
+static inline void update_network(struct rtllib_device *ieee,
+                                 struct rtllib_network *dst,
                                  struct rtllib_network *src)
 {
        int qos_active;
@@ -2388,17 +2512,16 @@ static inline void update_network(struct rtllib_network *dst,
                       sizeof(struct rtllib_qos_data));
        if (dst->qos_data.supported == 1) {
                if (dst->ssid_len)
-                       RTLLIB_DEBUG_QOS
-                               ("QoS the network %s is QoS supported\n",
-                               dst->ssid);
+                       netdev_dbg(ieee->dev,
+                                  "QoS the network %s is QoS supported\n",
+                                  dst->ssid);
                else
-                       RTLLIB_DEBUG_QOS
-                               ("QoS the network is QoS supported\n");
+                       netdev_dbg(ieee->dev,
+                                  "QoS the network is QoS supported\n");
        }
        dst->qos_data.active = qos_active;
        dst->qos_data.old_param_count = old_param;
 
-       /* dst->last_associate is not overwritten */
        dst->wmm_info = src->wmm_info;
        if (src->wmm_param[0].ac_aci_acm_aifsn ||
           src->wmm_param[1].ac_aci_acm_aifsn ||
@@ -2424,14 +2547,14 @@ static inline void update_network(struct rtllib_network *dst,
        dst->BssCcxVerNumber = src->BssCcxVerNumber;
 }
 
-static inline int is_beacon(__le16 fc)
+static inline int is_beacon(u16 fc)
 {
-       return (WLAN_FC_GET_STYPE(le16_to_cpu(fc)) == RTLLIB_STYPE_BEACON);
+       return (WLAN_FC_GET_STYPE(fc) == RTLLIB_STYPE_BEACON);
 }
 
 static int IsPassiveChannel(struct rtllib_device *rtllib, u8 channel)
 {
-       if (MAX_CHANNEL_NUMBER < channel) {
+       if (channel > MAX_CHANNEL_NUMBER) {
                netdev_info(rtllib->dev, "%s(): Invalid Channel\n", __func__);
                return 0;
        }
@@ -2444,7 +2567,7 @@ static int IsPassiveChannel(struct rtllib_device *rtllib, u8 channel)
 
 int rtllib_legal_channel(struct rtllib_device *rtllib, u8 channel)
 {
-       if (MAX_CHANNEL_NUMBER < channel) {
+       if (channel > MAX_CHANNEL_NUMBER) {
                netdev_info(rtllib->dev, "%s(): Invalid Channel\n", __func__);
                return 0;
        }
@@ -2467,40 +2590,37 @@ static inline void rtllib_process_probe_response(
        short renew;
        struct rtllib_network *network = kzalloc(sizeof(struct rtllib_network),
                                                 GFP_ATOMIC);
+       u16 frame_ctl = le16_to_cpu(beacon->header.frame_ctl);
 
        if (!network)
                return;
 
-       RTLLIB_DEBUG_SCAN(
-               "'%s' ( %pM ): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
-               escape_essid(info_element->data, info_element->len),
-               beacon->header.addr3,
-               (le16_to_cpu(beacon->capability) & (1<<0xf)) ? '1' : '0',
-               (le16_to_cpu(beacon->capability) & (1<<0xe)) ? '1' : '0',
-               (le16_to_cpu(beacon->capability) & (1<<0xd)) ? '1' : '0',
-               (le16_to_cpu(beacon->capability) & (1<<0xc)) ? '1' : '0',
-               (le16_to_cpu(beacon->capability) & (1<<0xb)) ? '1' : '0',
-               (le16_to_cpu(beacon->capability) & (1<<0xa)) ? '1' : '0',
-               (le16_to_cpu(beacon->capability) & (1<<0x9)) ? '1' : '0',
-               (le16_to_cpu(beacon->capability) & (1<<0x8)) ? '1' : '0',
-               (le16_to_cpu(beacon->capability) & (1<<0x7)) ? '1' : '0',
-               (le16_to_cpu(beacon->capability) & (1<<0x6)) ? '1' : '0',
-               (le16_to_cpu(beacon->capability) & (1<<0x5)) ? '1' : '0',
-               (le16_to_cpu(beacon->capability) & (1<<0x4)) ? '1' : '0',
-               (le16_to_cpu(beacon->capability) & (1<<0x3)) ? '1' : '0',
-               (le16_to_cpu(beacon->capability) & (1<<0x2)) ? '1' : '0',
-               (le16_to_cpu(beacon->capability) & (1<<0x1)) ? '1' : '0',
-               (le16_to_cpu(beacon->capability) & (1<<0x0)) ? '1' : '0');
+       netdev_dbg(ieee->dev,
+                  "'%s' ( %pM ): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
+                  escape_essid(info_element->data, info_element->len),
+                  beacon->header.addr3,
+                  (le16_to_cpu(beacon->capability) & (1<<0xf)) ? '1' : '0',
+                  (le16_to_cpu(beacon->capability) & (1<<0xe)) ? '1' : '0',
+                  (le16_to_cpu(beacon->capability) & (1<<0xd)) ? '1' : '0',
+                  (le16_to_cpu(beacon->capability) & (1<<0xc)) ? '1' : '0',
+                  (le16_to_cpu(beacon->capability) & (1<<0xb)) ? '1' : '0',
+                  (le16_to_cpu(beacon->capability) & (1<<0xa)) ? '1' : '0',
+                  (le16_to_cpu(beacon->capability) & (1<<0x9)) ? '1' : '0',
+                  (le16_to_cpu(beacon->capability) & (1<<0x8)) ? '1' : '0',
+                  (le16_to_cpu(beacon->capability) & (1<<0x7)) ? '1' : '0',
+                  (le16_to_cpu(beacon->capability) & (1<<0x6)) ? '1' : '0',
+                  (le16_to_cpu(beacon->capability) & (1<<0x5)) ? '1' : '0',
+                  (le16_to_cpu(beacon->capability) & (1<<0x4)) ? '1' : '0',
+                  (le16_to_cpu(beacon->capability) & (1<<0x3)) ? '1' : '0',
+                  (le16_to_cpu(beacon->capability) & (1<<0x2)) ? '1' : '0',
+                  (le16_to_cpu(beacon->capability) & (1<<0x1)) ? '1' : '0',
+                  (le16_to_cpu(beacon->capability) & (1<<0x0)) ? '1' : '0');
 
        if (rtllib_network_init(ieee, beacon, network, stats)) {
-               RTLLIB_DEBUG_SCAN("Dropped '%s' ( %pM) via %s.\n",
-                                 escape_essid(info_element->data,
-                                 info_element->len),
-                                 beacon->header.addr3,
-                                 WLAN_FC_GET_STYPE(
-                                         le16_to_cpu(beacon->header.frame_ctl)) ==
-                                 RTLLIB_STYPE_PROBE_RESP ?
-                                 "PROBE RESPONSE" : "BEACON");
+               netdev_dbg(ieee->dev, "Dropped '%s' ( %pM) via %s.\n",
+                          escape_essid(info_element->data, info_element->len),
+                          beacon->header.addr3,
+                          is_beacon(frame_ctl) ? "BEACON" : "PROBE RESPONSE");
                goto free_network;
        }
 
@@ -2508,8 +2628,7 @@ static inline void rtllib_process_probe_response(
        if (!rtllib_legal_channel(ieee, network->channel))
                goto free_network;
 
-       if (WLAN_FC_GET_STYPE(le16_to_cpu(beacon->header.frame_ctl)) ==
-           RTLLIB_STYPE_PROBE_RESP) {
+       if (WLAN_FC_GET_STYPE(frame_ctl) == RTLLIB_STYPE_PROBE_RESP) {
                if (IsPassiveChannel(ieee, network->channel)) {
                        netdev_info(ieee->dev,
                                    "GetScanInfo(): For Global Domain, filter probe response at channel(%d).\n",
@@ -2533,7 +2652,7 @@ static inline void rtllib_process_probe_response(
        spin_lock_irqsave(&ieee->lock, flags);
        if (is_same_network(&ieee->current_network, network,
           (network->ssid_len ? 1 : 0))) {
-               update_network(&ieee->current_network, network);
+               update_network(ieee, &ieee->current_network, network);
                if ((ieee->current_network.mode == IEEE_N_24G ||
                     ieee->current_network.mode == IEEE_G)
                     && ieee->current_network.berp_info_valid) {
@@ -2542,7 +2661,7 @@ static inline void rtllib_process_probe_response(
                        else
                                ieee->current_network.buseprotection = false;
                }
-               if (is_beacon(beacon->header.frame_ctl)) {
+               if (is_beacon(frame_ctl)) {
                        if (ieee->state >= RTLLIB_LINKED)
                                ieee->LinkDetectInfo.NumRecvBcnInPeriod++;
                }
@@ -2564,10 +2683,10 @@ static inline void rtllib_process_probe_response(
                        /* If there are no more slots, expire the oldest */
                        list_del(&oldest->list);
                        target = oldest;
-                       RTLLIB_DEBUG_SCAN("Expired '%s' ( %pM) from network list.\n",
-                                            escape_essid(target->ssid,
-                                                         target->ssid_len),
-                                            target->bssid);
+                       netdev_dbg(ieee->dev,
+                                  "Expired '%s' ( %pM) from network list.\n",
+                                  escape_essid(target->ssid, target->ssid_len),
+                                  target->bssid);
                } else {
                        /* Otherwise just pull from the free list */
                        target = list_entry(ieee->network_free_list.next,
@@ -2575,26 +2694,20 @@ static inline void rtllib_process_probe_response(
                        list_del(ieee->network_free_list.next);
                }
 
+               netdev_dbg(ieee->dev, "Adding '%s' ( %pM) via %s.\n",
+                          escape_essid(network->ssid, network->ssid_len),
+                          network->bssid,
+                          is_beacon(frame_ctl) ? "BEACON" : "PROBE RESPONSE");
 
-               RTLLIB_DEBUG_SCAN("Adding '%s' ( %pM) via %s.\n",
-                                 escape_essid(network->ssid,
-                                 network->ssid_len), network->bssid,
-                                 WLAN_FC_GET_STYPE(
-                                         le16_to_cpu(beacon->header.frame_ctl)) ==
-                                 RTLLIB_STYPE_PROBE_RESP ?
-                                 "PROBE RESPONSE" : "BEACON");
                memcpy(target, network, sizeof(*target));
                list_add_tail(&target->list, &ieee->network_list);
                if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE)
                        rtllib_softmac_new_net(ieee, network);
        } else {
-               RTLLIB_DEBUG_SCAN("Updating '%s' ( %pM) via %s.\n",
-                                 escape_essid(target->ssid,
-                                 target->ssid_len), target->bssid,
-                                 WLAN_FC_GET_STYPE(
-                                         le16_to_cpu(beacon->header.frame_ctl)) ==
-                                 RTLLIB_STYPE_PROBE_RESP ?
-                                 "PROBE RESPONSE" : "BEACON");
+               netdev_dbg(ieee->dev, "Updating '%s' ( %pM) via %s.\n",
+                          escape_essid(target->ssid, target->ssid_len),
+                          target->bssid,
+                          is_beacon(frame_ctl) ? "BEACON" : "PROBE RESPONSE");
 
                /* we have an entry and we are going to update it. But this
                 *  entry may be already expired. In this case we do the same
@@ -2609,13 +2722,13 @@ static inline void rtllib_process_probe_response(
                    network->ssid_len) == 0) &&
                    (ieee->state == RTLLIB_NOLINK))))
                        renew = 1;
-               update_network(target, network);
+               update_network(ieee, target, network);
                if (renew && (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE))
                        rtllib_softmac_new_net(ieee, network);
        }
 
        spin_unlock_irqrestore(&ieee->lock, flags);
-       if (is_beacon(beacon->header.frame_ctl) &&
+       if (is_beacon(frame_ctl) &&
            is_same_network(&ieee->current_network, network,
            (network->ssid_len ? 1 : 0)) &&
            (ieee->state == RTLLIB_LINKED)) {
@@ -2627,9 +2740,9 @@ free_network:
        kfree(network);
 }
 
-void rtllib_rx_mgt(struct rtllib_device *ieee,
-                     struct sk_buff *skb,
-                     struct rtllib_rx_stats *stats)
+static void rtllib_rx_mgt(struct rtllib_device *ieee,
+                         struct sk_buff *skb,
+                         struct rtllib_rx_stats *stats)
 {
        struct rtllib_hdr_4addr *header = (struct rtllib_hdr_4addr *)skb->data;
 
@@ -2642,9 +2755,8 @@ void rtllib_rx_mgt(struct rtllib_device *ieee,
        switch (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl))) {
 
        case RTLLIB_STYPE_BEACON:
-               RTLLIB_DEBUG_MGMT("received BEACON (%d)\n",
-                                 WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)));
-               RTLLIB_DEBUG_SCAN("Beacon\n");
+               netdev_dbg(ieee->dev, "received BEACON (%d)\n",
+                          WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)));
                rtllib_process_probe_response(
                                ieee, (struct rtllib_probe_response *)header,
                                stats);
@@ -2657,17 +2769,14 @@ void rtllib_rx_mgt(struct rtllib_device *ieee,
                break;
 
        case RTLLIB_STYPE_PROBE_RESP:
-               RTLLIB_DEBUG_MGMT("received PROBE RESPONSE (%d)\n",
-                       WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)));
-               RTLLIB_DEBUG_SCAN("Probe response\n");
+               netdev_dbg(ieee->dev, "received PROBE RESPONSE (%d)\n",
+                          WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)));
                rtllib_process_probe_response(ieee,
                              (struct rtllib_probe_response *)header, stats);
                break;
        case RTLLIB_STYPE_PROBE_REQ:
-               RTLLIB_DEBUG_MGMT("received PROBE RESQUEST (%d)\n",
-                                 WLAN_FC_GET_STYPE(
-                                         le16_to_cpu(header->frame_ctl)));
-               RTLLIB_DEBUG_SCAN("Probe request\n");
+               netdev_dbg(ieee->dev, "received PROBE RESQUEST (%d)\n",
+                          WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)));
                if ((ieee->softmac_features & IEEE_SOFTMAC_PROBERS) &&
                    ((ieee->iw_mode == IW_MODE_ADHOC ||
                    ieee->iw_mode == IW_MODE_MASTER) &&