wlan: Changes to support PMK caching for SAE

propagation from qcacld-3.0 to prima.

Add changes to support PMK caching for SAE authentication.

Change-Id: Id8f48a184fe40d1327b65235156d3798cfda585f
CRs-Fixed: 2531276
diff --git a/CORE/MAC/inc/sirApi.h b/CORE/MAC/inc/sirApi.h
index 7227be3..34b8c17 100644
--- a/CORE/MAC/inc/sirApi.h
+++ b/CORE/MAC/inc/sirApi.h
@@ -1147,6 +1147,7 @@
     tSirSupChnl         supportedChannels;
     bool force_24ghz_in_ht20;
     bool force_rsne_override;
+    bool sae_pmk_cached;
     tSirBssDescription  bssDescription;
     /*
      * WARNING: Pls make bssDescription as last variable in struct
diff --git a/CORE/MAC/src/pe/include/limSession.h b/CORE/MAC/src/pe/include/limSession.h
index 16b6bcc..49e99e0 100644
--- a/CORE/MAC/src/pe/include/limSession.h
+++ b/CORE/MAC/src/pe/include/limSession.h
@@ -372,6 +372,7 @@
     tDot11fIEVHTOperation vht_operation;
     bool force_24ghz_in_ht20;
     int8_t def_max_tx_pwr;
+    bool sae_pmk_cached;
 }tPESession, *tpPESession;
 
 #define LIM_MAX_ACTIVE_SESSIONS 4
diff --git a/CORE/MAC/src/pe/lim/limProcessAuthFrame.c b/CORE/MAC/src/pe/lim/limProcessAuthFrame.c
index 58583e0..08cc2c6 100644
--- a/CORE/MAC/src/pe/lim/limProcessAuthFrame.c
+++ b/CORE/MAC/src/pe/lim/limProcessAuthFrame.c
@@ -1196,18 +1196,28 @@
             if (pRxAuthFrameBody->authAlgoNumber !=
                 pMac->lim.gpLimMlmAuthReq->authType)
             {
-                /**
-                 * Received Authentication frame with an auth
-                 * algorithm other than one requested.
-                 * Wait until Authentication Failure Timeout.
+                /*
+                 * Auth algo is open in rx auth frame when auth type is SAE and
+                 * PMK is cached as driver sent auth algo as open in tx frame
+                 * as well.
                  */
-
-                // Log error
-                PELOGW(limLog(pMac, LOGW,
-                       FL("received Auth frame2 for unexpected auth algo number %d "
-                       MAC_ADDRESS_STR), pRxAuthFrameBody->authAlgoNumber,
-                       MAC_ADDR_ARRAY(pHdr->sa));)
-
+                if ((pMac->lim.gpLimMlmAuthReq->authType ==
+                     eSIR_AUTH_TYPE_SAE) && psessionEntry->sae_pmk_cached) {
+                     limLog(pMac, LOGW,
+                            FL("rx Auth frame2 auth algo %d in SAE PMK case"),
+                            pRxAuthFrameBody->authAlgoNumber);
+                } else {
+                    /**
+                     * Received Authentication frame with an auth
+                     * algorithm other than one requested.
+                     * Wait until Authentication Failure Timeout.
+                     */
+                    // Log error
+                    PELOGW(limLog(pMac, LOGW,
+                           FL("received Auth frame2 for unexpected auth algo num %d "
+                           MAC_ADDRESS_STR), pRxAuthFrameBody->authAlgoNumber,
+                           MAC_ADDR_ARRAY(pHdr->sa));)
+                }
                 break;
             }
 
diff --git a/CORE/MAC/src/pe/lim/limProcessMlmReqMessages.c b/CORE/MAC/src/pe/lim/limProcessMlmReqMessages.c
index 91615de..774812b 100644
--- a/CORE/MAC/src/pe/lim/limProcessMlmReqMessages.c
+++ b/CORE/MAC/src/pe/lim/limProcessMlmReqMessages.c
@@ -864,9 +864,15 @@
 {
         tSirMacAuthFrameBody    authFrameBody;
 
+        /* Mark auth algo as open when auth type is SAE and PMK is cached */
+        if ((pMac->lim.gpLimMlmAuthReq->authType == eSIR_AUTH_TYPE_SAE) &&
+             psessionEntry->sae_pmk_cached) {
+             authFrameBody.authAlgoNumber = eSIR_OPEN_SYSTEM;
+         } else {
+             authFrameBody.authAlgoNumber =
+                             (tANI_U8) pMac->lim.gpLimMlmAuthReq->authType;
+         }
         //Prepare & send Authentication frame
-        authFrameBody.authAlgoNumber =
-                        (tANI_U8) pMac->lim.gpLimMlmAuthReq->authType;
         authFrameBody.authTransactionSeqNumber = SIR_MAC_AUTH_FRAME_1;
         authFrameBody.authStatusCode = 0;
         pMac->authAckStatus = LIM_AUTH_ACK_NOT_RCD;
@@ -2728,7 +2734,8 @@
                                  pMac->lim.gpLimMlmAuthReq->peerMacAddr);
 
         psessionEntry->limPrevMlmState = psessionEntry->limMlmState;
-        if (pMac->lim.gpLimMlmAuthReq->authType == eSIR_AUTH_TYPE_SAE) {
+        if ((pMac->lim.gpLimMlmAuthReq->authType == eSIR_AUTH_TYPE_SAE) &&
+             !psessionEntry->sae_pmk_cached) {
             if (lim_process_mlm_auth_req_sae(pMac, psessionEntry) !=
                 VOS_STATUS_SUCCESS) {
                 mlmAuthCnf.resultCode = eSIR_SME_INVALID_PARAMETERS;
diff --git a/CORE/MAC/src/pe/lim/limProcessSmeReqMessages.c b/CORE/MAC/src/pe/lim/limProcessSmeReqMessages.c
index b224b6a..371e27f 100644
--- a/CORE/MAC/src/pe/lim/limProcessSmeReqMessages.c
+++ b/CORE/MAC/src/pe/lim/limProcessSmeReqMessages.c
@@ -1685,6 +1685,31 @@
                   sizeof(tSirDFSChannelList), 0);
 }
 
+#ifdef WLAN_FEATURE_SAE
+/**
+ * lim_update_sae_config()- This API update SAE session info to csr config
+ * from join request.
+ * @session: PE session
+ * @sme_join_req: pointer to join request
+ *
+ * Return: None
+ */
+static void lim_update_sae_config(tpPESession session,
+                                  tpSirSmeJoinReq sme_join_req)
+{
+    session->sae_pmk_cached = sme_join_req->sae_pmk_cached;
+
+    VOS_TRACE(VOS_MODULE_ID_PE, VOS_TRACE_LEVEL_DEBUG,
+              FL("pmk_cached %d for BSSID=" MAC_ADDRESS_STR),
+              session->sae_pmk_cached,
+              MAC_ADDR_ARRAY(sme_join_req->bssDescription.bssId));
+}
+#else
+static inline void lim_update_sae_config(tpPESession session,
+                                         tpSirSmeJoinReq sme_join_req)
+{}
+#endif
+
 /**
  * __limProcessSmeJoinReq()
  *
@@ -2003,6 +2028,8 @@
 #endif
         psessionEntry->txLdpcIniFeatureEnabled = pSmeJoinReq->txLdpcIniFeatureEnabled;
 
+        lim_update_sae_config(psessionEntry, pSmeJoinReq);
+
         if (psessionEntry->bssType == eSIR_INFRASTRUCTURE_MODE)
         {
             psessionEntry->limSystemRole = eLIM_STA_ROLE;
diff --git a/CORE/SME/src/csr/csrApiRoam.c b/CORE/SME/src/csr/csrApiRoam.c
index 6a0297a..d0332a7 100644
--- a/CORE/SME/src/csr/csrApiRoam.c
+++ b/CORE/SME/src/csr/csrApiRoam.c
@@ -13429,6 +13429,37 @@
     return( status );
 }
 
+#ifdef WLAN_FEATURE_SAE
+/*
+ * csr_update_sae_config: Copy SAE info to join request
+ * @profile: pointer to profile
+ * @csr_join_req: csr join request
+ *
+ * Return: None
+ */
+static void csr_update_sae_config(tSirSmeJoinReq *csr_join_req,
+                                  tpAniSirGlobal mac, tCsrRoamSession *session)
+{
+    tPmkidCacheInfo pmkid_cache;
+    uint32_t index;
+
+    vos_mem_copy(pmkid_cache.BSSID, csr_join_req->bssDescription.bssId,
+                 VOS_MAC_ADDR_SIZE);
+
+    csr_join_req->sae_pmk_cached =
+              csr_lookup_pmkid_using_bssid(mac, session, &pmkid_cache, &index);
+
+    VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_DEBUG,
+              "pmk_cached %d for BSSID=" MAC_ADDRESS_STR,
+              csr_join_req->sae_pmk_cached,
+              MAC_ADDR_ARRAY(csr_join_req->bssDescription.bssId));
+}
+#else
+static void csr_update_sae_config(tSirSmeJoinReq *csr_join_req,
+                                  tpAniSirGlobal mac, tCsrRoamSession *session)
+{ }
+#endif
+
 ////////////////////Mail box
 
 //pBuf is caller allocated memory point to &(tSirSmeJoinReq->rsnIE.rsnIEdata[ 0 ]) + pMsg->rsnIE.length;
@@ -14167,6 +14198,8 @@
         csrPrepareJoinReassocReqBuffer( pMac, pBssDescription, pBuf,
                 (tANI_U8)pProfile->uapsd_mask);
 
+        csr_update_sae_config(pMsg, pMac, pSession);
+
         status = palSendMBMessage(pMac->hHdd, pMsg );
         /* Memory allocated to pMsg will get free'd in palSendMBMessage */
         pMsg = NULL;
diff --git a/CORE/SME/src/csr/csrInsideApi.h b/CORE/SME/src/csr/csrInsideApi.h
index b8c9e44..7d80c89 100644
--- a/CORE/SME/src/csr/csrInsideApi.h
+++ b/CORE/SME/src/csr/csrInsideApi.h
@@ -1123,6 +1123,18 @@
 void csr_remove_bssid_from_scan_list(tpAniSirGlobal pMac,
        tSirMacAddr bssid);
 
+/**
+ * csr_lookup_pmkid_using_bssid() - lookup pmkid using bssid
+ * @mac: pointer to mac
+ * @session: sme session pointer
+ * @pmk_cache: pointer to pmk cache
+ * @index: index value needs to be seached
+ *
+ * Return: true if pmkid is found else false
+ */
+bool csr_lookup_pmkid_using_bssid(tpAniSirGlobal mac, tCsrRoamSession *session,
+                                  tPmkidCacheInfo *pmk_cache, uint32_t *index);
+
 #ifdef WLAN_FEATURE_AP_HT40_24G
 eHalStatus csrSetHT2040Mode(tpAniSirGlobal pMac, tANI_U32 sessionId, tANI_U8 cbMode);
 #endif
diff --git a/CORE/SME/src/csr/csrUtil.c b/CORE/SME/src/csr/csrUtil.c
index 40a1e5e..446de22 100644
--- a/CORE/SME/src/csr/csrUtil.c
+++ b/CORE/SME/src/csr/csrUtil.c
@@ -4126,16 +4126,7 @@
     return false;
 }
 
-/**
- * csr_lookup_pmkid_using_bssid() - lookup pmkid using bssid
- * @mac: pointer to mac
- * @session: sme session pointer
- * @pmk_cache: pointer to pmk cache
- * @index: index value needs to be seached
- *
- * Return: true if pmkid is found else false
- */
-static bool csr_lookup_pmkid_using_bssid(tpAniSirGlobal mac,
+bool csr_lookup_pmkid_using_bssid(tpAniSirGlobal mac,
                     tCsrRoamSession *session,
                     tPmkidCacheInfo *pmk_cache,
                     uint32_t *index)