wlan: Add changes to handle SAE status

propagation from qcacld-3.0 to prima.

After SAE auth completion, supplicant informs status to driver.
Add changes to handle SAE status that comes through vendor
command QCA_NL80211_VENDOR_SUBCMD_EXTERNAL_AUTH using attribute
QCA_ATTR_EXTERNAL_AUTH_STATUS.

Change-Id: I474cfe9ea049e684837133479f8b6697fef1f189
CRs-Fixed: 2531077
diff --git a/CORE/MAC/inc/sirApi.h b/CORE/MAC/inc/sirApi.h
index fd1fc1e..4d51fdb 100644
--- a/CORE/MAC/inc/sirApi.h
+++ b/CORE/MAC/inc/sirApi.h
@@ -6465,4 +6465,17 @@
     tSirMacSSid ssid;
 };
 
+/**
+ * struct sir_sae_msg - SAE msg used for message posting
+ * @message_type: message type
+ * @length: message length
+ * @session_id: SME session id
+ * @sae_status: SAE status, 0: Success, Non-zero: Failure.
+ */
+struct sir_sae_msg {
+    uint16_t message_type;
+    uint16_t length;
+    uint16_t session_id;
+    uint8_t sae_status;
+};
 #endif /* __SIR_API_H */
diff --git a/CORE/MAC/inc/wniApi.h b/CORE/MAC/inc/wniApi.h
index 9408712..67839eb 100644
--- a/CORE/MAC/inc/wniApi.h
+++ b/CORE/MAC/inc/wniApi.h
@@ -403,6 +403,7 @@
     eWNI_SME_STA_DEL_BA_REQ,
     eWNI_SME_TRIGGER_SAE,
     eWNI_SME_SEND_MGMT_FRAME_TX,
+    eWNI_SME_SEND_SAE_MSG,
     eWNI_SME_MSG_TYPES_END
 };
 
diff --git a/CORE/MAC/src/pe/lim/limProcessMessageQueue.c b/CORE/MAC/src/pe/lim/limProcessMessageQueue.c
index d9e5639..eb2c931 100644
--- a/CORE/MAC/src/pe/lim/limProcessMessageQueue.c
+++ b/CORE/MAC/src/pe/lim/limProcessMessageQueue.c
@@ -82,6 +82,7 @@
 #include "vos_types.h"
 #include "vos_packet.h"
 #include "vos_memory.h"
+#include "limSecurityUtils.h"
 
 /* This value corresponds to 500 ms */
 #define MAX_PROBEREQ_TIME 50
@@ -92,8 +93,69 @@
 
 #define CHECK_BIT(value, mask)    ((value) & (1 << (mask)))
 
+#define IEEE80211_STATUS_SUCCESS            0
+
 void limLogSessionStates(tpAniSirGlobal pMac);
 
+#ifdef WLAN_FEATURE_SAE
+/**
+ * lim_process_sae_msg() - Process SAE message
+ * @mac: Global MAC pointer
+ * @body: Buffer pointer
+ *
+ * Return: None
+ */
+static void lim_process_sae_msg(tpAniSirGlobal mac, struct sir_sae_msg *body)
+{
+    struct sir_sae_msg *sae_msg = body;
+    tpPESession session;
+
+    if (!sae_msg) {
+        limLog(mac, LOGE, FL("SAE msg is NULL"));
+        return;
+    }
+
+    session = pe_find_session_by_sme_session_id(mac, sae_msg->session_id);
+    if (session == NULL) {
+        limLog(mac, LOGE, FL("SAE:Unable to find session"));
+        return;
+    }
+
+    if (session->pePersona != VOS_STA_MODE) {
+        limLog(mac, LOGE, FL("SAE:Not supported in this mode %d"),
+               session->pePersona);
+        return;
+    }
+
+    limLog(mac, LOG1, FL("SAE:status %d limMlmState %d pePersona %d"),
+           sae_msg->sae_status, session->limMlmState,
+           session->pePersona);
+    switch (session->limMlmState) {
+    case eLIM_MLM_WT_SAE_AUTH_STATE:
+        /* SAE authentication is completed. Restore from auth state */
+        if (tx_timer_running(&mac->lim.limTimers.sae_auth_timer))
+            limDeactivateAndChangeTimer(mac, eLIM_AUTH_SAE_TIMER);
+        /* success */
+        if (sae_msg->sae_status == IEEE80211_STATUS_SUCCESS)
+            limRestoreFromAuthState(mac, eSIR_SME_SUCCESS,
+                                    eSIR_MAC_SUCCESS_STATUS, session);
+        else
+            limRestoreFromAuthState(mac, eSIR_SME_AUTH_REFUSED,
+                                    eSIR_MAC_UNSPEC_FAILURE_STATUS, session);
+       break;
+    default:
+       /* SAE msg is received in unexpected state */
+       limLog(mac, LOGE, FL("received SAE msg in state %X"),
+              session->limMlmState);
+       limPrintMlmState(mac, LOGE, session->limMlmState);
+       break;
+    }
+}
+#else
+static void lim_process_sae_msg(tpAniSirGlobal mac, struct sir_sae_msg *body)
+{}
+#endif
+
 /** -------------------------------------------------------------
 \fn defMsgDecision
 \brief The function decides whether to defer a message or not in limProcessMessage function
@@ -2560,6 +2622,11 @@
     case eWNI_SME_STA_DEL_BA_REQ:
         limStaDelBASession(pMac);
         break;
+    case eWNI_SME_SEND_SAE_MSG:
+        lim_process_sae_msg(pMac, limMsg->bodyptr);
+        vos_mem_free((v_VOID_t*)limMsg->bodyptr);
+        limMsg->bodyptr = NULL;
+        break;
     default:
         vos_mem_free((v_VOID_t*)limMsg->bodyptr);
         limMsg->bodyptr = NULL;
diff --git a/CORE/MAC/src/pe/lim/limSecurityUtils.c b/CORE/MAC/src/pe/lim/limSecurityUtils.c
index bffffb0..e364e73 100644
--- a/CORE/MAC/src/pe/lim/limSecurityUtils.c
+++ b/CORE/MAC/src/pe/lim/limSecurityUtils.c
@@ -518,10 +518,14 @@
      * retry is needed also cancel the auth rety timer
      */
     pMac->authAckStatus = LIM_AUTH_ACK_RCD_SUCCESS;
-    // 'Change' timer for future activations
-    limDeactivateAndChangeTimer(pMac, eLIM_AUTH_RETRY_TIMER);
-    // 'Change' timer for future activations
-    limDeactivateAndChangeTimer(pMac, eLIM_AUTH_FAIL_TIMER);
+    /* Auth retry and AUth failure timers are not started for SAE
+     * Change' timer for future activations
+     */
+    if (tx_timer_running(&pMac->lim.limTimers.gLimPeriodicAuthRetryTimer))
+        limDeactivateAndChangeTimer(pMac, eLIM_AUTH_RETRY_TIMER);
+    /* Change' timer for future activations */
+    if (tx_timer_running(&pMac->lim.limTimers.gLimAuthFailureTimer))
+        limDeactivateAndChangeTimer(pMac, eLIM_AUTH_FAIL_TIMER);
 
     #if 0
     if (wlan_cfgGetStr(pMac, WNI_CFG_BSSID, currentBssId, &cfg) != eSIR_SUCCESS)
diff --git a/CORE/SME/inc/sme_Api.h b/CORE/SME/inc/sme_Api.h
index 1ed8abd..68b1e92 100644
--- a/CORE/SME/inc/sme_Api.h
+++ b/CORE/SME/inc/sme_Api.h
@@ -4127,4 +4127,23 @@
 eHalStatus sme_send_mgmt_tx(tHalHandle hal, uint8_t session_id,
                                 const uint8_t *buf, uint32_t len);
 
+#ifdef WLAN_FEATURE_SAE
+/**
+ * sme_handle_sae_msg() - Sends SAE message received from supplicant
+ * @hal: The handle returned by mac_open
+ * @session_id: session id
+ * @sae_status: status of SAE authentication
+ *
+ * Return: HAL_STATUS
+ */
+eHalStatus sme_handle_sae_msg(tHalHandle hal, uint8_t session_id,
+                              uint8_t sae_status);
+#else
+static inline eHalStatus sme_handle_sae_msg(tHalHandle hal, uint8_t session_id,
+                                            uint8_t sae_status)
+{
+	return eHAL_STATUS_SUCCESS;
+}
+#endif
+
 #endif //#if !defined( __SME_API_H )
diff --git a/CORE/SME/src/sme_common/sme_Api.c b/CORE/SME/src/sme_common/sme_Api.c
index f7d81d4..142d289 100644
--- a/CORE/SME/src/sme_common/sme_Api.c
+++ b/CORE/SME/src/sme_common/sme_Api.c
@@ -15447,3 +15447,44 @@
 
     return status;
 }
+
+#ifdef WLAN_FEATURE_SAE
+eHalStatus sme_handle_sae_msg(tHalHandle hal, uint8_t session_id,
+                              uint8_t sae_status)
+{
+    eHalStatus hal_status = eHAL_STATUS_SUCCESS;
+    tpAniSirGlobal mac = PMAC_STRUCT(hal);
+    struct sir_sae_msg *sae_msg;
+    vos_msg_t vos_message;
+    VOS_STATUS vos_status = VOS_STATUS_SUCCESS;
+
+    hal_status = sme_AcquireGlobalLock(&mac->sme);
+    if (HAL_STATUS_SUCCESS(hal_status)) {
+        sae_msg = vos_mem_malloc(sizeof(*sae_msg));
+        if (!sae_msg) {
+            hal_status = eHAL_STATUS_FAILED_ALLOC;
+            VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
+                      "SAE: memory allocation failed");
+        } else {
+            sae_msg->message_type = eWNI_SME_SEND_SAE_MSG;
+            sae_msg->length = sizeof(*sae_msg);
+            sae_msg->session_id = session_id;
+            sae_msg->sae_status = sae_status;
+            vos_message.bodyptr = sae_msg;
+            vos_message.type =  eWNI_SME_SEND_SAE_MSG;
+            VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_DEBUG,
+                      "SAE: sae_status %d session_id %d", sae_msg->sae_status,
+                      sae_msg->session_id);
+
+            vos_status = vos_mq_post_message(VOS_MQ_ID_PE, &vos_message);
+            if (!VOS_IS_STATUS_SUCCESS(vos_status)) {
+                vos_mem_free(sae_msg);
+                hal_status = eHAL_STATUS_FAILURE;
+            }
+       }
+       sme_ReleaseGlobalLock(&mac->sme);
+}
+
+return hal_status;
+}
+#endif
diff --git a/CORE/SYS/legacy/src/utils/src/macTrace.c b/CORE/SYS/legacy/src/utils/src/macTrace.c
index 46e4cc4..981dd2d 100644
--- a/CORE/SYS/legacy/src/utils/src/macTrace.c
+++ b/CORE/SYS/legacy/src/utils/src/macTrace.c
@@ -588,6 +588,7 @@
         CASE_RETURN_STRING(eWNI_SME_ECSA_CHAN_CHANGE_RSP);
         CASE_RETURN_STRING(eWNI_SME_TRIGGER_SAE);
         CASE_RETURN_STRING(eWNI_SME_SEND_MGMT_FRAME_TX);
+        CASE_RETURN_STRING(eWNI_SME_SEND_SAE_MSG);
         default:
             return( (tANI_U8*)"UNKNOWN" );
             break;