qcacld-3.0: Do not make a PMF connection, if supplicant sets it as optional

qcacld-2.0 to qcacld-3.0 propagation

In earlier android builds PMF was not enabled by default in the supplicant
unlike the latest builds. So even if PMF is set as optional, driver was
mandating it. So if we try to roam to an AP which is not PMF capabale
driver would simply drop the connection.

To address this, allow non PMF connection if PMF is set as optional by the
supplicant and the AP is not capable.

CRs-Fixed: 1018482
Change-Id: Ideecb861dcc362f94a73b47d1a4766d621a38214
(cherry picked from commit ec4d9feff5461a575b2988b38428b89cf6337584)
(cherry picked from commit 54b657e08ac628616b8cf6cbddfb9204ecf28ce5)
diff --git a/core/sme/src/csr/csr_api_roam.c b/core/sme/src/csr/csr_api_roam.c
index 763946a..d4f0d1b 100644
--- a/core/sme/src/csr/csr_api_roam.c
+++ b/core/sme/src/csr/csr_api_roam.c
@@ -14028,6 +14028,11 @@
 		else
 			csr_join_req->MgmtEncryptionType = eSIR_ED_NONE;
 #endif
+		if (pProfile->MFPEnabled &&
+			 !(pProfile->MFPRequired) &&
+			 ((pIes->RSN.present) &&
+			 (!(pIes->RSN.RSN_Cap[0] >> 7) & 0x1)))
+			csr_join_req->MgmtEncryptionType = eSIR_ED_NONE;
 #ifdef FEATURE_WLAN_ESE
 		ese_config =  pMac->roam.configParam.isEseIniFeatureEnabled;
 #endif
diff --git a/core/sme/src/csr/csr_util.c b/core/sme/src/csr/csr_util.c
index 904d295..bbcecf0 100644
--- a/core/sme/src/csr/csr_util.c
+++ b/core/sme/src/csr/csr_util.c
@@ -2829,25 +2829,21 @@
 		/* Extracting MFPCapable bit from RSN Ie */
 		apProfileMFPCapable = (pRSNIe->RSN_Cap[0] >> 7) & 0x1;
 		apProfileMFPRequired = (pRSNIe->RSN_Cap[0] >> 6) & 0x1;
+
+		QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_INFO,
+			FL("pFilterMFPEnabled=%d pFilterMFPRequired=%d"
+			   "pFilterMFPCapable=%d apProfileMFPCapable=%d"
+			   "apProfileMFPRequired=%d"),
+			 *pFilterMFPEnabled, *pFilterMFPRequired,
+			 *pFilterMFPCapable, apProfileMFPCapable,
+			 apProfileMFPRequired);
+
 		if (*pFilterMFPEnabled && *pFilterMFPCapable
 		    && *pFilterMFPRequired && (apProfileMFPCapable == 0)) {
 			QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_INFO,
 				  "AP is not capable to make PMF connection");
 			return false;
-		} else if (*pFilterMFPEnabled && *pFilterMFPCapable &&
-			   !(*pFilterMFPRequired) &&
-				(apProfileMFPCapable == 0)) {
-			/*
-			 * This is tricky, because supplicant asked us to
-			 * make mandatory PMF connection eventhough PMF
-			 * connection is optional here.
-			 * so if AP is not capable of PMF then drop it.
-			 * Don't try to connect with it.
-			 */
-			QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_INFO,
-				  "we need PMF connection & AP isn't capable to make PMF connection");
-			return false;
-		} else if (!(*pFilterMFPCapable) &&
+		}  else if (!(*pFilterMFPCapable) &&
 			   apProfileMFPCapable && apProfileMFPRequired) {
 
 			/*
@@ -2858,11 +2854,6 @@
 			QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_INFO,
 				  "AP needs PMF connection and we are not capable of pmf connection");
 			return false;
-		} else if (!(*pFilterMFPEnabled) && *pFilterMFPCapable &&
-			   (apProfileMFPCapable == 1)) {
-			QDF_TRACE(QDF_MODULE_ID_SME, QDF_TRACE_LEVEL_INFO,
-				  "we don't need PMF connection even though both parties are capable");
-			return false;
 		}
 	}
 	return true;
@@ -3041,7 +3032,11 @@
 		}
 
 #ifdef WLAN_FEATURE_11W
-		if (pProfile->MFPEnabled) {
+		/* Advertise BIP in group cipher key management only if PMF is
+		 * enabled and AP is capable.
+		 */
+		if (pProfile->MFPEnabled &&
+			(RSNCapabilities.MFPCapable && pProfile->MFPCapable)) {
 			pGroupMgmtCipherSuite =
 				(uint8_t *) pPMK + sizeof(uint16_t) +
 				(pPMK->cPMKIDs * CSR_RSN_PMKID_SIZE);
@@ -3065,7 +3060,8 @@
 							       CSR_RSN_PMKID_SIZE));
 		}
 #ifdef WLAN_FEATURE_11W
-		if (pProfile->MFPEnabled) {
+		if (pProfile->MFPEnabled &&
+			(RSNCapabilities.MFPCapable && pProfile->MFPCapable)) {
 			if (0 == pPMK->cPMKIDs)
 				pRSNIe->IeHeader.Length += sizeof(uint16_t);
 			pRSNIe->IeHeader.Length += CSR_WPA_OUI_SIZE;