OSDN Git Service

iwlwifi: mvm: Fix calculation of frame length
authorIlan Peer <ilan.peer@intel.com>
Sun, 19 Dec 2021 10:18:16 +0000 (12:18 +0200)
committerLuca Coelho <luciano.coelho@intel.com>
Tue, 21 Dec 2021 10:35:06 +0000 (12:35 +0200)
The RADA might include in the Rx frame the MIC and CRC bytes.
These bytes should be removed for non monitor interfaces and
should not be passed to mac80211.

Fix the Rx processing to remove the extra bytes on non monitor
cases.

Signed-off-by: Ilan Peer <ilan.peer@intel.com>
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
Link: https://lore.kernel.org/r/iwlwifi.20211219121514.098be12c801e.I1d81733d8a75b84c3b20eb6e0d14ab3405ca6a86@changeid
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c

index 5f73717..c8b20f2 100644 (file)
@@ -121,12 +121,39 @@ static int iwl_mvm_create_skb(struct iwl_mvm *mvm, struct sk_buff *skb,
        struct iwl_rx_mpdu_desc *desc = (void *)pkt->data;
        unsigned int headlen, fraglen, pad_len = 0;
        unsigned int hdrlen = ieee80211_hdrlen(hdr->frame_control);
+       u8 mic_crc_len = u8_get_bits(desc->mac_flags1,
+                                    IWL_RX_MPDU_MFLG1_MIC_CRC_LEN_MASK) << 1;
 
        if (desc->mac_flags2 & IWL_RX_MPDU_MFLG2_PAD) {
                len -= 2;
                pad_len = 2;
        }
 
+       /*
+        * For non monitor interface strip the bytes the RADA might not have
+        * removed. As monitor interface cannot exist with other interfaces
+        * this removal is safe.
+        */
+       if (mic_crc_len && !ieee80211_hw_check(mvm->hw, RX_INCLUDES_FCS)) {
+               u32 pkt_flags = le32_to_cpu(pkt->len_n_flags);
+
+               /*
+                * If RADA was not enabled then decryption was not performed so
+                * the MIC cannot be removed.
+                */
+               if (!(pkt_flags & FH_RSCSR_RADA_EN)) {
+                       if (WARN_ON(crypt_len > mic_crc_len))
+                               return -EINVAL;
+
+                       mic_crc_len -= crypt_len;
+               }
+
+               if (WARN_ON(mic_crc_len > len))
+                       return -EINVAL;
+
+               len -= mic_crc_len;
+       }
+
        /* If frame is small enough to fit in skb->head, pull it completely.
         * If not, only pull ieee80211_hdr (including crypto if present, and
         * an additional 8 bytes for SNAP/ethertype, see below) so that