Commit 130c7749 authored by Wen Gong's avatar Wen Gong Committed by Kalle Valo

ath10k: add PN replay protection for high latency devices

On high latency devices (SDIO, USB) ath10k did not do PN replay check, a data
frame with an invalid PN number was not discard as it should have been. So this
patch implements PN replay in ath10k. PN replay check for fragmented frames is
implemented in followup patch.

With low latency devices (PCI, AHB) hardware can store the data
frames's content to host memory directly and the firmware can fully reorder
data frames, and do PN replay check at the same time. But for high latency
devices all data frames will be received and stored in firmware's memory and it
is hard to do full reorder because of the memory size limitations in the
firmware. This is why the PN replay protections needs to be implemented in host
driver.

Tested on QCA6174 SDIO with firmware WLAN.RMH.4.4.1-00007-QCARMSWP-1.
Signed-off-by: default avatarWen Gong <wgong@codeaurora.org>
Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
parent 28ce53b6
...@@ -2061,9 +2061,91 @@ static int ath10k_htt_rx_handle_amsdu(struct ath10k_htt *htt) ...@@ -2061,9 +2061,91 @@ static int ath10k_htt_rx_handle_amsdu(struct ath10k_htt *htt)
return 0; return 0;
} }
static void ath10k_htt_rx_mpdu_desc_pn_hl(struct htt_hl_rx_desc *rx_desc,
union htt_rx_pn_t *pn,
int pn_len_bits)
{
switch (pn_len_bits) {
case 48:
pn->pn48 = __le32_to_cpu(rx_desc->pn_31_0) +
((u64)(__le32_to_cpu(rx_desc->u0.pn_63_32) & 0xFFFF) << 32);
break;
case 24:
pn->pn24 = __le32_to_cpu(rx_desc->pn_31_0);
break;
};
}
static bool ath10k_htt_rx_pn_cmp48(union htt_rx_pn_t *new_pn,
union htt_rx_pn_t *old_pn)
{
return ((new_pn->pn48 & 0xffffffffffffULL) <=
(old_pn->pn48 & 0xffffffffffffULL));
}
static bool ath10k_htt_rx_pn_check_replay_hl(struct ath10k *ar,
struct ath10k_peer *peer,
struct htt_rx_indication_hl *rx)
{
bool last_pn_valid, pn_invalid = false;
enum htt_txrx_sec_cast_type sec_index;
enum htt_security_types sec_type;
union htt_rx_pn_t new_pn = {0};
struct htt_hl_rx_desc *rx_desc;
union htt_rx_pn_t *last_pn;
u32 rx_desc_info, tid;
int num_mpdu_ranges;
lockdep_assert_held(&ar->data_lock);
if (!peer)
return false;
if (!(rx->fw_desc.flags & FW_RX_DESC_FLAGS_FIRST_MSDU))
return false;
num_mpdu_ranges = MS(__le32_to_cpu(rx->hdr.info1),
HTT_RX_INDICATION_INFO1_NUM_MPDU_RANGES);
rx_desc = (struct htt_hl_rx_desc *)&rx->mpdu_ranges[num_mpdu_ranges];
rx_desc_info = __le32_to_cpu(rx_desc->info);
if (!MS(rx_desc_info, HTT_RX_DESC_HL_INFO_ENCRYPTED))
return false;
tid = MS(rx->hdr.info0, HTT_RX_INDICATION_INFO0_EXT_TID);
last_pn_valid = peer->tids_last_pn_valid[tid];
last_pn = &peer->tids_last_pn[tid];
if (MS(rx_desc_info, HTT_RX_DESC_HL_INFO_MCAST_BCAST))
sec_index = HTT_TXRX_SEC_MCAST;
else
sec_index = HTT_TXRX_SEC_UCAST;
sec_type = peer->rx_pn[sec_index].sec_type;
ath10k_htt_rx_mpdu_desc_pn_hl(rx_desc, &new_pn, peer->rx_pn[sec_index].pn_len);
if (sec_type != HTT_SECURITY_AES_CCMP &&
sec_type != HTT_SECURITY_TKIP &&
sec_type != HTT_SECURITY_TKIP_NOMIC)
return false;
if (last_pn_valid)
pn_invalid = ath10k_htt_rx_pn_cmp48(&new_pn, last_pn);
else
peer->tids_last_pn_valid[tid] = 1;
if (!pn_invalid)
last_pn->pn48 = new_pn.pn48;
return pn_invalid;
}
static bool ath10k_htt_rx_proc_rx_ind_hl(struct ath10k_htt *htt, static bool ath10k_htt_rx_proc_rx_ind_hl(struct ath10k_htt *htt,
struct htt_rx_indication_hl *rx, struct htt_rx_indication_hl *rx,
struct sk_buff *skb) struct sk_buff *skb,
enum htt_rx_pn_check_type check_pn_type,
enum htt_rx_tkip_demic_type tkip_mic_type)
{ {
struct ath10k *ar = htt->ar; struct ath10k *ar = htt->ar;
struct ath10k_peer *peer; struct ath10k_peer *peer;
...@@ -2107,6 +2189,10 @@ static bool ath10k_htt_rx_proc_rx_ind_hl(struct ath10k_htt *htt, ...@@ -2107,6 +2189,10 @@ static bool ath10k_htt_rx_proc_rx_ind_hl(struct ath10k_htt *htt,
goto err; goto err;
} }
if (check_pn_type == HTT_RX_PN_CHECK &&
ath10k_htt_rx_pn_check_replay_hl(ar, peer, rx))
goto err;
/* Strip off all headers before the MAC header before delivery to /* Strip off all headers before the MAC header before delivery to
* mac80211 * mac80211
*/ */
...@@ -2114,6 +2200,7 @@ static bool ath10k_htt_rx_proc_rx_ind_hl(struct ath10k_htt *htt, ...@@ -2114,6 +2200,7 @@ static bool ath10k_htt_rx_proc_rx_ind_hl(struct ath10k_htt *htt,
sizeof(rx->ppdu) + sizeof(rx->prefix) + sizeof(rx->ppdu) + sizeof(rx->prefix) +
sizeof(rx->fw_desc) + sizeof(rx->fw_desc) +
sizeof(*mpdu_ranges) * num_mpdu_ranges + rx_desc_len; sizeof(*mpdu_ranges) * num_mpdu_ranges + rx_desc_len;
skb_pull(skb, tot_hdr_len); skb_pull(skb, tot_hdr_len);
hdr = (struct ieee80211_hdr *)skb->data; hdr = (struct ieee80211_hdr *)skb->data;
...@@ -2162,6 +2249,10 @@ static bool ath10k_htt_rx_proc_rx_ind_hl(struct ath10k_htt *htt, ...@@ -2162,6 +2249,10 @@ static bool ath10k_htt_rx_proc_rx_ind_hl(struct ath10k_htt *htt,
RX_FLAG_MMIC_STRIPPED; RX_FLAG_MMIC_STRIPPED;
} }
if (tkip_mic_type == HTT_RX_TKIP_MIC)
rx_status->flag &= ~RX_FLAG_IV_STRIPPED &
~RX_FLAG_MMIC_STRIPPED;
ieee80211_rx_ni(ar->hw, skb); ieee80211_rx_ni(ar->hw, skb);
/* We have delivered the skb to the upper layers (mac80211) so we /* We have delivered the skb to the upper layers (mac80211) so we
...@@ -3343,7 +3434,9 @@ bool ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb) ...@@ -3343,7 +3434,9 @@ bool ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb)
if (ar->bus_param.dev_type == ATH10K_DEV_TYPE_HL) if (ar->bus_param.dev_type == ATH10K_DEV_TYPE_HL)
return ath10k_htt_rx_proc_rx_ind_hl(htt, return ath10k_htt_rx_proc_rx_ind_hl(htt,
&resp->rx_ind_hl, &resp->rx_ind_hl,
skb); skb,
HTT_RX_PN_CHECK,
HTT_RX_NON_TKIP_MIC);
else else
ath10k_htt_rx_proc_rx_ind_ll(htt, &resp->rx_ind); ath10k_htt_rx_proc_rx_ind_ll(htt, &resp->rx_ind);
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment