wlan: Add SAE auth timer

propagation from qcacld-3.0 to prima

Add changes related to SAE auth timer to handle SAE authentication.
Start SAE auth timer of duration LIM_AUTH_SAE_TIMER_MS when driver
wants to trigger SAE authentication. If SAE authentication is not
completed in LIM_AUTH_SAE_TIMER_MS, then report failure to
supplicant.

Change-Id: I09bc0e365b9e5e352d927972ba31e3ca4d0cf493
CRs-Fixed: 2533723
diff --git a/CORE/MAC/inc/aniGlobal.h b/CORE/MAC/inc/aniGlobal.h
index db919d5..8715388 100644
--- a/CORE/MAC/inc/aniGlobal.h
+++ b/CORE/MAC/inc/aniGlobal.h
@@ -244,6 +244,8 @@
      */
     TX_TIMER           gLimActiveToPassiveChannelTimer;
     TX_TIMER           g_lim_ap_ecsa_timer;
+    /* SAE authentication related timer */
+    TX_TIMER           sae_auth_timer;
 //********************TIMER SECTION ENDS**************************************************
 // ALL THE FIELDS BELOW THIS CAN BE ZEROED OUT in limInitialize
 //****************************************************************************************
diff --git a/CORE/MAC/src/include/sirParams.h b/CORE/MAC/src/include/sirParams.h
index 4057e37..552cdd7 100644
--- a/CORE/MAC/src/include/sirParams.h
+++ b/CORE/MAC/src/include/sirParams.h
@@ -927,6 +927,7 @@
 #define SIR_LIM_REASSOC_MBB_RSP_TIMEOUT   (SIR_LIM_TIMEOUT_MSG_START + 0x2A)
 #endif
 
+#define SIR_LIM_AUTH_SAE_TIMEOUT            (SIR_LIM_TIMEOUT_MSG_START + 0x2B)
 #define SIR_LIM_CONVERT_ACTIVE_CHANNEL_TO_PASSIVE (SIR_LIM_TIMEOUT_MSG_START + 0x2C)
 #define SIR_LIM_AUTH_RETRY_TIMEOUT            (SIR_LIM_TIMEOUT_MSG_START + 0x2D)
 #define SIR_LIM_SAP_ECSA_TIMEOUT            (SIR_LIM_TIMEOUT_MSG_START + 0x2E)
diff --git a/CORE/MAC/src/pe/lim/limProcessMessageQueue.c b/CORE/MAC/src/pe/lim/limProcessMessageQueue.c
index 6659903..d9e5639 100644
--- a/CORE/MAC/src/pe/lim/limProcessMessageQueue.c
+++ b/CORE/MAC/src/pe/lim/limProcessMessageQueue.c
@@ -2028,6 +2028,7 @@
 #ifdef WLAN_FEATURE_LFR_MBB
         case SIR_LIM_PREAUTH_MBB_RSP_TIMEOUT:
         case SIR_LIM_REASSOC_MBB_RSP_TIMEOUT:
+        case SIR_LIM_AUTH_SAE_TIMEOUT:
 #endif
             // These timeout messages are handled by MLM sub module
 
diff --git a/CORE/MAC/src/pe/lim/limProcessMlmReqMessages.c b/CORE/MAC/src/pe/lim/limProcessMlmReqMessages.c
index a8a4fd9..91615de 100644
--- a/CORE/MAC/src/pe/lim/limProcessMlmReqMessages.c
+++ b/CORE/MAC/src/pe/lim/limProcessMlmReqMessages.c
@@ -100,6 +100,49 @@
 #define IS_MLM_SCAN_REQ_BACKGROUND_SCAN_AGGRESSIVE(pMac)    (pMac->lim.gpLimMlmScanReq->backgroundScanMode == eSIR_AGGRESSIVE_BACKGROUND_SCAN)
 #define IS_MLM_SCAN_REQ_BACKGROUND_SCAN_NORMAL(pMac)        (pMac->lim.gpLimMlmScanReq->backgroundScanMode == eSIR_NORMAL_BACKGROUND_SCAN)
 
+ /**
+ * lim_process_sae_auth_timeout() - This function is called to process sae
+ * auth timeout
+ * @mac_ctx: Pointer to Global MAC structure
+ *
+ * @Return: None
+ */
+static void lim_process_sae_auth_timeout(tpAniSirGlobal mac_ctx)
+{
+    tpPESession session;
+
+    session = peFindSessionBySessionId(mac_ctx,
+                            mac_ctx->lim.limTimers.sae_auth_timer.sessionId);
+    if (session == NULL) {
+        limLog(mac_ctx, LOGE,
+               FL("Session does not exist for given session id"));
+        return;
+    }
+
+    limLog(mac_ctx, LOG1,
+           FL("SAE auth timeout sessionid %d mlmstate %X SmeState %X"),
+           session->peSessionId, session->limMlmState, session->limSmeState);
+
+    switch (session->limMlmState) {
+    case eLIM_MLM_WT_SAE_AUTH_STATE:
+        /*
+         * SAE authentication is not completed. Restore from
+         * auth state.
+         */
+        if (session->pePersona == VOS_STA_MODE)
+            limRestoreFromAuthState(mac_ctx, eSIR_SME_AUTH_TIMEOUT_RESULT_CODE,
+                                    eSIR_MAC_UNSPEC_FAILURE_REASON, session);
+        break;
+    default:
+        /* SAE authentication is timed out in unexpected state */
+        limLog(mac_ctx, LOGE,
+               FL("received unexpected SAE auth timeout in state %X"),
+                  session->limMlmState);
+        limPrintMlmState(mac_ctx, LOGE, session->limMlmState);
+	break;
+     }
+}
+
 /**
  * limProcessMlmReqMessages()
  *
@@ -180,6 +223,9 @@
         case LIM_MLM_ADDBA_REQ:             limProcessMlmAddBAReq( pMac, Msg->bodyptr ); break;
         case LIM_MLM_ADDBA_RSP:             limProcessMlmAddBARsp( pMac, Msg->bodyptr ); break;
         case LIM_MLM_DELBA_REQ:             limProcessMlmDelBAReq( pMac, Msg->bodyptr ); break;
+        case SIR_LIM_AUTH_SAE_TIMEOUT:
+            lim_process_sae_auth_timeout(pMac);
+            break;
         case LIM_MLM_TSPEC_REQ:                 
         default:
             break;
@@ -2506,7 +2552,7 @@
 
         if (VOS_STATUS_SUCCESS != vos_mq_post_message(VOS_MQ_ID_SME, &msg))
         {
-                limLog(mac_ctx, LOGE, "%s failed to post msg to self ",
+                limLog(mac_ctx, LOGE, FL("%s failed to post msg to self "),
                        __func__);
                 vos_mem_free((void *)sae_info);
                 status = VOS_STATUS_E_FAILURE;
@@ -2517,6 +2563,15 @@
         MTRACE(macTrace(mac_ctx, TRACE_CODE_MLM_STATE, session->peSessionId,
                         session->limMlmState));
 
+        mac_ctx->lim.limTimers.sae_auth_timer.sessionId = session->peSessionId;
+        /* Activate SAE auth timer */
+        MTRACE(macTrace(mac_ctx, TRACE_CODE_TIMER_ACTIVATE,
+                        session->peSessionId, eLIM_AUTH_SAE_TIMER));
+        if (tx_timer_activate(&mac_ctx->lim.limTimers.sae_auth_timer)
+            != TX_SUCCESS) {
+            limLog(mac_ctx, LOGE, FL("could not start Auth SAE timer"));
+        }
+
         return status;
 }
 #else
diff --git a/CORE/MAC/src/pe/lim/limTimerUtils.c b/CORE/MAC/src/pe/lim/limTimerUtils.c
index 5a5163a..f5bb4d3 100644
--- a/CORE/MAC/src/pe/lim/limTimerUtils.c
+++ b/CORE/MAC/src/pe/lim/limTimerUtils.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2017 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2012-2017, 2019 The Linux Foundation. All rights reserved.
  *
  * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  *
@@ -56,6 +56,11 @@
 #define LIM_JOIN_PROBE_REQ_TIMER_MS              200
 #define LIM_AUTH_RETRY_TIMER_MS              60
 
+/*
+ * SAE auth timer of 5secs. This is required for duration of entire SAE
+ * authentication.
+ */
+#define LIM_AUTH_SAE_TIMER_MS 5000
 
 //default beacon interval value used in HB timer interval calculation
 #define LIM_HB_TIMER_BEACON_INTERVAL             100
@@ -431,6 +436,18 @@
             goto err_timer;
         }
 
+       /*
+        * SAE auth timer of 5secs. This is required for duration of entire SAE
+        * authentication.
+        */
+       if ((tx_timer_create(&pMac->lim.limTimers.sae_auth_timer,
+             "SAE AUTH Timer", limTimerHandler, SIR_LIM_AUTH_SAE_TIMEOUT,
+             SYS_MS_TO_TICKS(LIM_AUTH_SAE_TIMER_MS), 0, TX_NO_ACTIVATE)) !=
+             TX_SUCCESS) {
+           limLog(pMac, LOGP, FL("could not create SAE AUTH Timer"));
+           goto err_timer;
+       }
+
         if (wlan_cfgGetInt(pMac, WNI_CFG_BACKGROUND_SCAN_PERIOD,
                       &cfgValue) != eSIR_SUCCESS)
         {
@@ -784,6 +801,7 @@
         tx_timer_delete(&pMac->lim.limTimers.gLimP2pSingleShotNoaInsertTimer);
         tx_timer_delete(&pMac->lim.limTimers.gLimActiveToPassiveChannelTimer);
         tx_timer_delete(&pMac->lim.limTimers.g_lim_ap_ecsa_timer);
+        tx_timer_delete(&pMac->lim.limTimers.sae_auth_timer);
 
         if(NULL != pMac->lim.gLimPreAuthTimerTable.pTable)
         {
@@ -1935,6 +1953,21 @@
                 limLog(pMac, LOGE, FL("Unable to change g_lim_ap_ecsa_timer timer"));
         }
 
+    case eLIM_AUTH_SAE_TIMER:
+        if (tx_timer_deactivate(&pMac->lim.limTimers.sae_auth_timer)
+            != TX_SUCCESS) {
+            limLog(pMac, LOGP, FL("Unable to deactivate SAE auth timer"));
+            return;
+        }
+        /* Change timer to reactivate it in future */
+        val = SYS_MS_TO_TICKS(LIM_AUTH_SAE_TIMER_MS);
+        if (tx_timer_change(&pMac->lim.limTimers.sae_auth_timer,
+            val, 0) != TX_SUCCESS) {
+            limLog(pMac, LOGP, FL("unable to change SAE auth timer"));
+            return;
+        }
+        break;
+
         break;
      default:
             // Invalid timerId. Log error
diff --git a/CORE/MAC/src/pe/lim/limTimerUtils.h b/CORE/MAC/src/pe/lim/limTimerUtils.h
index 2b10fdc..eb4e284 100644
--- a/CORE/MAC/src/pe/lim/limTimerUtils.h
+++ b/CORE/MAC/src/pe/lim/limTimerUtils.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2015, 2017 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2012-2015, 2017, 2019 The Linux Foundation. All rights reserved.
  *
  * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  *
@@ -81,7 +81,8 @@
     eLIM_AP_ECSA_TIMER,
 #ifdef WLAN_FEATURE_LFR_MBB
     eLIM_PREAUTH_MBB_RSP_TIMER,
-    eLIM_REASSOC_MBB_RSP_TIMER
+    eLIM_REASSOC_MBB_RSP_TIMER,
+    eLIM_AUTH_SAE_TIMER
 #endif
 };
 
diff --git a/CORE/MAC/src/pe/lim/limUtils.c b/CORE/MAC/src/pe/lim/limUtils.c
index e0f4560..a35cff5 100644
--- a/CORE/MAC/src/pe/lim/limUtils.c
+++ b/CORE/MAC/src/pe/lim/limUtils.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2018 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2019 The Linux Foundation. All rights reserved.
  *
  * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  *
@@ -1141,6 +1141,9 @@
         tx_timer_deactivate(&pMac->lim.limTimers.g_lim_ap_ecsa_timer);
         tx_timer_delete(&pMac->lim.limTimers.g_lim_ap_ecsa_timer);
 
+        tx_timer_deactivate(&pMac->lim.limTimers.sae_auth_timer);
+        tx_timer_delete(&pMac->lim.limTimers.sae_auth_timer);
+
         pMac->lim.gLimTimersCreated = 0;
     }
 
diff --git a/CORE/SYS/legacy/src/utils/src/macTrace.c b/CORE/SYS/legacy/src/utils/src/macTrace.c
index 69b2a52..46e4cc4 100644
--- a/CORE/SYS/legacy/src/utils/src/macTrace.c
+++ b/CORE/SYS/legacy/src/utils/src/macTrace.c
@@ -1001,6 +1001,7 @@
 
 #endif
 
+        CASE_RETURN_STRING(SIR_LIM_AUTH_SAE_TIMEOUT);
         CASE_RETURN_STRING(SIR_LIM_AUTH_RETRY_TIMEOUT);
         CASE_RETURN_STRING(SIR_LIM_SAP_ECSA_TIMEOUT);