[WCNCR00146539] softap: Fix TGn 4.2.44 and 4.2.45 softap cert fail items

[Description]
Fix TGn 4.2.44 and 4.2.45 softap cert fail items
1. no HT cap and op IE in BCN with WEP mode
2. disallow TKIP with HT Rates to meet cert requirement
3. Clean the beacon update message buffer after allocated
   to avoid unexpected content.

Change-Id: I348e1946cf191a11b811ecd7a8f1977a32282100
Signed-off-by: Awk Jiang <awk.jiang@mediatek.com>
CR-Id: WCNCR00146539
Feature: softap
diff --git a/include/mgmt/p2p_func.h b/include/mgmt/p2p_func.h
index 4262bbd..53b97bd 100644
--- a/include/mgmt/p2p_func.h
+++ b/include/mgmt/p2p_func.h
@@ -221,6 +221,8 @@
 p2pFuncInitConnectionSettings(IN P_ADAPTER_T prAdapter, IN P_P2P_CONNECTION_SETTINGS_T prP2PConnSettings, IN BOOLEAN
 			      fgIsApMode);
 
+BOOLEAN p2pFuncParseCheckForTKIPInfoElem(IN PUINT_8 pucBuf);
+
 BOOLEAN p2pFuncParseCheckForP2PInfoElem(IN P_ADAPTER_T prAdapter, IN PUINT_8 pucBuf, OUT PUINT_8 pucOuiType);
 
 BOOLEAN
diff --git a/include/mgmt/p2p_role.h b/include/mgmt/p2p_role.h
index 6d288fc..751643a 100644
--- a/include/mgmt/p2p_role.h
+++ b/include/mgmt/p2p_role.h
@@ -107,6 +107,7 @@
 	PUINT_8 pucBcnHdr;
 	PUINT_8 pucBcnBody;
 	PUINT_8 pucAssocRespIE;
+	BOOLEAN fgIsWepCipher;
 	UINT_8 aucBuffer[1];	/* Header & Body & Extra IEs are put here. */
 } MSG_P2P_BEACON_UPDATE_T, *P_MSG_P2P_BEACON_UPDATE_T;
 
diff --git a/include/nic/adapter.h b/include/nic/adapter.h
index 4dd1c45..18dcf95 100644
--- a/include/nic/adapter.h
+++ b/include/nic/adapter.h
@@ -341,6 +341,7 @@
 				*/
 	BOOLEAN fgIsNetAbsent;	/* TRUE: BSS is absent, FALSE: BSS is present */
 
+	BOOLEAN fgIsWepCipherGroup;
 	UINT_32 u4RsnSelectedGroupCipher;
 	UINT_32 u4RsnSelectedPairwiseCipher;
 	UINT_32 u4RsnSelectedAKMSuite;
diff --git a/mgmt/assoc.c b/mgmt/assoc.c
index c6da3e3..72f3677 100644
--- a/mgmt/assoc.c
+++ b/mgmt/assoc.c
@@ -1110,6 +1110,7 @@
 	UINT_16 u2BSSBasicRateSet;
 	UINT_8 ucFixedFieldLength;
 	BOOLEAN fgIsUnknownBssBasicRate;
+	BOOLEAN fgIsHT = FALSE, fgIsTKIP = FALSE;
 	UINT_32 i;
 
 	ASSERT(prAdapter);
@@ -1202,6 +1203,7 @@
 			break;
 		case ELEM_ID_HT_CAP:
 			prStaRec->ucPhyTypeSet |= PHY_TYPE_BIT_HT;
+			fgIsHT = TRUE;
 			break;
 		case ELEM_ID_VHT_CAP:
 			prStaRec->ucPhyTypeSet |= PHY_TYPE_BIT_VHT;
@@ -1219,6 +1221,9 @@
 #endif
 			break;
 		case ELEM_ID_VENDOR:
+			if (p2pFuncParseCheckForTKIPInfoElem(pucIE))
+				fgIsTKIP = TRUE;
+
 #if CFG_ENABLE_WIFI_DIRECT
 			{
 				if ((prAdapter->fgIsP2PRegistered)) {
@@ -1356,6 +1361,9 @@
 	}
 #endif
 
+	if (fgIsHT && fgIsTKIP && prBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT)
+		u2StatusCode = STATUS_CODE_REQ_DECLINED;
+
 	*pu2StatusCode = u2StatusCode;
 
 	return WLAN_STATUS_SUCCESS;
diff --git a/mgmt/p2p_func.c b/mgmt/p2p_func.c
index 6100891..a9f2df7 100644
--- a/mgmt/p2p_func.c
+++ b/mgmt/p2p_func.c
@@ -2293,6 +2293,40 @@
 
 /*----------------------------------------------------------------------------*/
 /*!
+* @brief This function is used to check the TKIP IE
+*
+*
+* @return none
+*/
+/*----------------------------------------------------------------------------*/
+BOOLEAN p2pFuncParseCheckForTKIPInfoElem(IN PUINT_8 pucBuf)
+{
+	UINT_8 aucWfaOui[] = VENDOR_OUI_WFA;
+	P_WPA_INFO_ELEM_T prWpaIE = (P_WPA_INFO_ELEM_T) NULL;
+	UINT_32 u4GroupKeyCipher = 0;
+
+	if (pucBuf == NULL)
+		return FALSE;
+
+	prWpaIE = (P_WPA_INFO_ELEM_T) pucBuf;
+
+	if (prWpaIE->ucLength <= ELEM_MIN_LEN_WFA_OUI_TYPE_SUBTYPE)
+		return FALSE;
+
+	if (kalMemCmp(prWpaIE->aucOui, aucWfaOui, sizeof(aucWfaOui)))
+		return FALSE;
+
+	WLAN_GET_FIELD_32(&prWpaIE->u4GroupKeyCipherSuite, &u4GroupKeyCipher);
+
+	if (prWpaIE->ucOuiType == VENDOR_OUI_TYPE_WPA &&
+		u4GroupKeyCipher == WPA_CIPHER_SUITE_TKIP)
+		return TRUE;
+	else
+		return FALSE;
+}				/* p2pFuncParseCheckForP2PInfoElem */
+
+/*----------------------------------------------------------------------------*/
+/*!
 * @brief This function is used to check the P2P IE
 *
 *
diff --git a/mgmt/p2p_role_fsm.c b/mgmt/p2p_role_fsm.c
index 501d26e..d611c2b 100644
--- a/mgmt/p2p_role_fsm.c
+++ b/mgmt/p2p_role_fsm.c
@@ -2402,6 +2402,8 @@
 
 		prP2pBssInfo = GET_BSS_INFO_BY_INDEX(prAdapter, prRoleP2pFsmInfo->ucBssIndex);
 
+		prP2pBssInfo->fgIsWepCipherGroup = prBcnUpdateMsg->fgIsWepCipher;
+
 		prBcnUpdateInfo = &(prRoleP2pFsmInfo->rBeaconUpdateInfo);
 
 		p2pFuncBeaconUpdate(prAdapter,
diff --git a/mgmt/rlm.c b/mgmt/rlm.c
index b69d08e..790e8c6 100644
--- a/mgmt/rlm.c
+++ b/mgmt/rlm.c
@@ -293,7 +293,8 @@
 		ucPhyTypeSet = prBssInfo->ucPhyTypeSet;
 	}
 
-	if (RLM_NET_IS_11N(prBssInfo) && (ucPhyTypeSet & PHY_TYPE_SET_802_11N))
+	if (RLM_NET_IS_11N(prBssInfo) && (ucPhyTypeSet & PHY_TYPE_SET_802_11N) &&
+		(!prBssInfo->fgIsWepCipherGroup))
 		rlmFillHtCapIE(prAdapter, prBssInfo, prMsduInfo);
 }
 
@@ -373,7 +374,8 @@
 		ucPhyTypeSet = prBssInfo->ucPhyTypeSet;
 	}
 
-	if (RLM_NET_IS_11N(prBssInfo) && (ucPhyTypeSet & PHY_TYPE_SET_802_11N))
+	if (RLM_NET_IS_11N(prBssInfo) && (ucPhyTypeSet & PHY_TYPE_SET_802_11N) &&
+		(!prBssInfo->fgIsWepCipherGroup))
 		rlmFillHtOpIE(prAdapter, prBssInfo, prMsduInfo);
 }
 
diff --git a/os/linux/gl_p2p_cfg80211.c b/os/linux/gl_p2p_cfg80211.c
index a98d31a..564ae76 100644
--- a/os/linux/gl_p2p_cfg80211.c
+++ b/os/linux/gl_p2p_cfg80211.c
@@ -1293,6 +1293,12 @@
 			prP2pBcnUpdateMsg->pucBcnBody = NULL;
 		}
 
+		if ((settings->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP40) ||
+			(settings->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP104))
+			prP2pBcnUpdateMsg->fgIsWepCipher = TRUE;
+		else
+			prP2pBcnUpdateMsg->fgIsWepCipher = FALSE;
+
 		if (settings->beacon.assocresp_ies_len != 0 && settings->beacon.assocresp_ies != NULL) {
 			prP2pBcnUpdateMsg->pucAssocRespIE = pucBuffer;
 			kalMemCopy(pucBuffer, settings->beacon.assocresp_ies, settings->beacon.assocresp_ies_len);
@@ -1496,6 +1502,7 @@
 	RF_CHANNEL_INFO_T rRfChnlInfo;
 	P_BSS_INFO_T prBssInfo;
 	UINT_8 ucBssIndex;
+	UINT_32 u4Len;
 
 	do {
 		if ((wiphy == NULL) || (params == NULL))
@@ -1595,15 +1602,17 @@
 
 		/* Update beacon */
 		if ((params->beacon_csa.head_len != 0) || (params->beacon_csa.tail_len != 0)) {
+			u4Len = sizeof(MSG_P2P_BEACON_UPDATE_T) +
+				params->beacon_csa.head_len + params->beacon_csa.tail_len;
 			prP2pBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T) cnmMemAlloc(prGlueInfo->prAdapter,
-							RAM_TYPE_MSG, (sizeof(MSG_P2P_BEACON_UPDATE_T)
-							+ params->beacon_csa.head_len + params->beacon_csa.tail_len));
+				RAM_TYPE_MSG, u4Len);
 
 			if (prP2pBcnUpdateMsg == NULL) {
 				ASSERT(FALSE);
 				i4Rslt = -ENOMEM;
 				break;
 			}
+			kalMemZero(prP2pBcnUpdateMsg, u4Len);
 
 			prP2pBcnUpdateMsg->ucRoleIndex = ucRoleIdx;
 			prP2pBcnUpdateMsg->rMsgHdr.eMsgId = MID_MNY_P2P_BEACON_UPDATE;
@@ -1673,6 +1682,7 @@
 	P_MSG_P2P_BEACON_UPDATE_T prP2pBcnUpdateMsg = (P_MSG_P2P_BEACON_UPDATE_T) NULL;
 	PUINT_8 pucBuffer = (PUINT_8) NULL;
 	UINT_8 ucRoleIdx = 0;
+	UINT_32 u4Len = 0;
 
 	do {
 		if ((wiphy == NULL) || (info == NULL))
@@ -1685,17 +1695,20 @@
 			break;
 
 		if ((info->head_len != 0) || (info->tail_len != 0)) {
+			u4Len = sizeof(MSG_P2P_BEACON_UPDATE_T) +
+				info->head_len + info->tail_len +
+				info->assocresp_ies_len;
+
 			prP2pBcnUpdateMsg =
 			    (P_MSG_P2P_BEACON_UPDATE_T) cnmMemAlloc(prGlueInfo->prAdapter,
-								    RAM_TYPE_MSG, (sizeof(MSG_P2P_BEACON_UPDATE_T)
-										   + info->head_len + info->tail_len
-										   + info->assocresp_ies_len));
+					RAM_TYPE_MSG, u4Len);
 
 			if (prP2pBcnUpdateMsg == NULL) {
 				ASSERT(FALSE);
 				i4Rslt = -ENOMEM;
 				break;
 			}
+			kalMemZero(prP2pBcnUpdateMsg, u4Len);
 
 			prP2pBcnUpdateMsg->ucRoleIndex = ucRoleIdx;
 			prP2pBcnUpdateMsg->rMsgHdr.eMsgId = MID_MNY_P2P_BEACON_UPDATE;