[WCNCR00166862] security: Refactor security detection code.

[Description]
Refactor security detection code for redundant code and naming rule.

Change-Id: Ib4db3472a9e7c9d184148676f103a1f3f6ef5b92
Signed-off-by: wayne.guo <wayne.guo@mediatek.com>
CR-Id: WCNCR00166862
Feature: security
diff --git a/include/nic/adapter.h b/include/nic/adapter.h
index 30645b4..ec504d4 100644
--- a/include/nic/adapter.h
+++ b/include/nic/adapter.h
@@ -485,7 +485,7 @@
 #endif
 
 #if CFG_SUPPORT_REPLAY_DETECTION
-	struct GL_DETECT_REPLAY_INFO prDetRplyInfo;
+	struct SEC_DETECT_REPLAY_INFO rDetRplyInfo;
 #endif
 
 };
diff --git a/nic/nic_cmd_event.c b/nic/nic_cmd_event.c
index 3f85b14..c14d1c8 100644
--- a/nic/nic_cmd_event.c
+++ b/nic/nic_cmd_event.c
@@ -3402,7 +3402,7 @@
 {
 	P_WIFI_CMD_T prWifiCmd = NULL;
 	P_CMD_802_11_KEY prCmdKey = NULL;
-	struct GL_DETECT_REPLAY_INFO *prDetRplyInfo = NULL;
+	struct SEC_DETECT_REPLAY_INFO *prDetRplyInfo = NULL;
 	UINT_8 ucBssIndex = 0;
 	P_BSS_INFO_T prBssInfo = NULL;
 
@@ -3422,7 +3422,7 @@
 	prBssInfo = GET_BSS_INFO_BY_INDEX(prAdapter, ucBssIndex);
 	ASSERT(prBssInfo);
 
-	prDetRplyInfo = &prBssInfo->prDetRplyInfo;
+	prDetRplyInfo = &prBssInfo->rDetRplyInfo;
 
 	if (pucEventBuf) {
 		prWifiCmd = (P_WIFI_CMD_T) (pucEventBuf);
diff --git a/nic/que_mgt.c b/nic/que_mgt.c
index e3c62a1..66ef697 100644
--- a/nic/que_mgt.c
+++ b/nic/que_mgt.c
@@ -5960,6 +5960,7 @@
 {
 	UINT_8 ucCount = 0;
 	UINT_64 u8Data = 0;
+	UINT_8 ucTmp = 0;
 
 	if (!pu8Rets) {
 		DBGLOG(QM, ERROR, "Please input valid pu8Rets\n");
@@ -5973,7 +5974,8 @@
 
 	*pu8Rets = 0;
 	for (; ucCount < uPNNum; ucCount++) {
-		u8Data = pucPN[ucCount] << 8*ucCount;
+		ucTmp = pucPN[ucCount];
+		u8Data = ucTmp << 8*ucCount;
 		*pu8Rets +=  u8Data;
 	}
 	return TRUE;
@@ -6008,7 +6010,7 @@
 	UINT_8 ucSecMode = CIPHER_SUITE_NONE;		/* CIPHER_SUITE_NONE~CIPHER_SUITE_GCMP */
 	P_GLUE_INFO_T prGlueInfo = NULL;
 	P_GL_WPA_INFO_T prWpaInfo = NULL;
-	struct GL_DETECT_REPLAY_INFO *prDetRplyInfo = NULL;
+	struct SEC_DETECT_REPLAY_INFO *prDetRplyInfo = NULL;
 	P_HW_MAC_RX_DESC_T prRxStatus = NULL;
 	UINT_8 ucBssIndex = 0;
 	P_BSS_INFO_T prBssInfo = NULL;
@@ -6023,6 +6025,9 @@
 
 	ASSERT(prBssInfo);
 
+	prGlueInfo = prAdapter->prGlueInfo;
+	prWpaInfo = &prGlueInfo->rWpaInfo;
+
 	/* BMC only need check CCMP and TKIP Cipher suite */
 	prRxStatus = prSwRfb->prRxStatus;
 	ucSecMode = HAL_RX_STATUS_GET_SEC_MODE(prRxStatus);
@@ -6044,9 +6049,7 @@
 		return TRUE;
 	}
 
-	prGlueInfo = prAdapter->prGlueInfo;
-	prWpaInfo = &prGlueInfo->rWpaInfo;
-	prDetRplyInfo = &prBssInfo->prDetRplyInfo;
+	prDetRplyInfo = &prBssInfo->rDetRplyInfo;
 
 	/* TODO : Need check fw rekey while fw rekey event. */
 	if (ucKeyID != prDetRplyInfo->ucCurKeyId) {
diff --git a/os/linux/gl_cfg80211.c b/os/linux/gl_cfg80211.c
index 2989bed..40152d1 100644
--- a/os/linux/gl_cfg80211.c
+++ b/os/linux/gl_cfg80211.c
@@ -189,7 +189,7 @@
 	UINT_8 tmp1[8], tmp2[8];
 #if CFG_SUPPORT_REPLAY_DETECTION
 	P_BSS_INFO_T prBssInfo = NULL;
-	struct GL_DETECT_REPLAY_INFO *prDetRplyInfo = NULL;
+	struct SEC_DETECT_REPLAY_INFO *prDetRplyInfo = NULL;
 	UINT_8 ucCheckZeroKey = 0;
 	UINT_8 i = 0;
 #endif
@@ -266,10 +266,12 @@
 	if (params->key) {
 
 #if CFG_SUPPORT_REPLAY_DETECTION
-		for (i = 0; i < params->key_len; i++)
-			ucCheckZeroKey += params->key[i];
+		for (i = 0; i < params->key_len; i++) {
+			if (params->key[i] == 0x00)
+				ucCheckZeroKey++;
+		}
 
-		if (ucCheckZeroKey == 0)
+		if (ucCheckZeroKey == params->key_len)
 			return 0;
 #endif
 
@@ -289,9 +291,8 @@
 
 #if CFG_SUPPORT_REPLAY_DETECTION
 	prBssInfo = GET_BSS_INFO_BY_INDEX(prGlueInfo->prAdapter, prGlueInfo->prAdapter->prAisBssInfo->ucBssIndex);
-	ASSERT(prBssInfo);
 
-	prDetRplyInfo = &prBssInfo->prDetRplyInfo;
+	prDetRplyInfo = &prBssInfo->rDetRplyInfo;
 
 	if ((!pairwise) && ((params->cipher == WLAN_CIPHER_SUITE_TKIP) || (params->cipher == WLAN_CIPHER_SUITE_CCMP))) {
 		if ((prDetRplyInfo->ucCurKeyId == key_index) &&
@@ -902,7 +903,7 @@
 	P_DOT11_RSNA_CONFIG_AUTHENTICATION_SUITES_ENTRY prEntry;
 #if CFG_SUPPORT_REPLAY_DETECTION
 	P_BSS_INFO_T prBssInfo = NULL;
-	struct GL_DETECT_REPLAY_INFO *prDetRplyInfo = NULL;
+	struct SEC_DETECT_REPLAY_INFO *prDetRplyInfo = NULL;
 #endif
 
 
@@ -934,14 +935,10 @@
 
 #if CFG_SUPPORT_REPLAY_DETECTION
 	/* reset Detect replay information */
-	prDetRplyInfo = &prGlueInfo->prDetRplyInfo;
-	kalMemZero(prDetRplyInfo, sizeof(struct GL_DETECT_REPLAY_INFO));
-
 	prBssInfo = GET_BSS_INFO_BY_INDEX(prGlueInfo->prAdapter, prGlueInfo->prAdapter->prAisBssInfo->ucBssIndex);
-	ASSERT(prBssInfo);
 
-	prDetRplyInfo = &prBssInfo->prDetRplyInfo;
-	kalMemZero(prDetRplyInfo, sizeof(struct GL_DETECT_REPLAY_INFO));
+	prDetRplyInfo = &prBssInfo->rDetRplyInfo;
+	kalMemZero(prDetRplyInfo, sizeof(struct SEC_DETECT_REPLAY_INFO));
 #endif
 
 
diff --git a/os/linux/gl_p2p_cfg80211.c b/os/linux/gl_p2p_cfg80211.c
index c632ea3..1df21c8 100644
--- a/os/linux/gl_p2p_cfg80211.c
+++ b/os/linux/gl_p2p_cfg80211.c
@@ -606,7 +606,7 @@
 	/* const UINT_8 aucZeroMacAddr[] = NULL_MAC_ADDR; */
 #if CFG_SUPPORT_REPLAY_DETECTION
 	P_BSS_INFO_T prBssInfo = NULL;
-	struct GL_DETECT_REPLAY_INFO *prDetRplyInfo = NULL;
+	struct SEC_DETECT_REPLAY_INFO *prDetRplyInfo = NULL;
 	UINT_8 ucCheckZeroKey = 0;
 	UINT_8 i = 0;
 #endif
@@ -691,10 +691,12 @@
 
 #if CFG_SUPPORT_REPLAY_DETECTION
 	if (params->key) {
-		for (i = 0; i < params->key_len; i++)
-			ucCheckZeroKey += params->key[i];
+		for (i = 0; i < params->key_len; i++) {
+			if (params->key[i] == 0x00)
+				ucCheckZeroKey++;
+		}
 
-		if (ucCheckZeroKey == 0)
+		if (ucCheckZeroKey == params->key_len)
 			return 0;
 	}
 #endif
@@ -707,8 +709,7 @@
 #if CFG_SUPPORT_REPLAY_DETECTION
 	prBssInfo = GET_BSS_INFO_BY_INDEX(prGlueInfo->prAdapter, rKey.ucBssIdx);
 
-	ASSERT(prBssInfo);
-	prDetRplyInfo = &prBssInfo->prDetRplyInfo;
+	prDetRplyInfo = &prBssInfo->rDetRplyInfo;
 
 	if ((!pairwise) && ((params->cipher == WLAN_CIPHER_SUITE_TKIP) || (params->cipher == WLAN_CIPHER_SUITE_CCMP))) {
 		if ((prDetRplyInfo->ucCurKeyId == key_index) &&
@@ -2476,7 +2477,7 @@
 #if CFG_SUPPORT_REPLAY_DETECTION
 	UINT_8 ucBssIndex = 0;
 	P_BSS_INFO_T prBssInfo = NULL;
-	struct GL_DETECT_REPLAY_INFO *prDetRplyInfo = NULL;
+	struct SEC_DETECT_REPLAY_INFO *prDetRplyInfo = NULL;
 #endif
 
 	do {
@@ -2546,8 +2547,8 @@
 
 		prBssInfo = GET_BSS_INFO_BY_INDEX(prGlueInfo->prAdapter, ucBssIndex);
 		ASSERT(prBssInfo);
-		prDetRplyInfo = &prBssInfo->prDetRplyInfo;
-		kalMemZero(prDetRplyInfo, sizeof(struct GL_DETECT_REPLAY_INFO));
+		prDetRplyInfo = &prBssInfo->rDetRplyInfo;
+		kalMemZero(prDetRplyInfo, sizeof(struct SEC_DETECT_REPLAY_INFO));
 #endif
 
 		i4Rslt = 0;
diff --git a/os/linux/include/gl_os.h b/os/linux/include/gl_os.h
index 267392e..2ddc544 100644
--- a/os/linux/include/gl_os.h
+++ b/os/linux/include/gl_os.h
@@ -311,15 +311,15 @@
 } GL_WPA_INFO_T, *P_GL_WPA_INFO_T;
 
 #if CFG_SUPPORT_REPLAY_DETECTION
-struct GL_REPLEY_PN_INFO {
+struct SEC_REPLEY_PN_INFO {
 	UINT_8 auPN[16];
 	BOOLEAN fgRekey;
 	BOOLEAN fgFirstPkt;
 };
-struct GL_DETECT_REPLAY_INFO {
+struct SEC_DETECT_REPLAY_INFO {
 	UINT_8 ucCurKeyId;
 	UINT_8 ucKeyType;
-	struct GL_REPLEY_PN_INFO arReplayPNInfo[4];
+	struct SEC_REPLEY_PN_INFO arReplayPNInfo[4];
 	UINT_32 u4KeyLength;
 	UINT_8 aucKeyMaterial[32];
 	BOOLEAN fgPairwiseInstalled;
@@ -477,10 +477,6 @@
 	/*! \brief wext wpa related information */
 	GL_WPA_INFO_T rWpaInfo;
 
-#if CFG_SUPPORT_REPLAY_DETECTION
-	struct GL_DETECT_REPLAY_INFO prDetRplyInfo;
-#endif
-
 	/* Pointer to ADAPTER_T - main data structure of internal protocol stack */
 	P_ADAPTER_T prAdapter;