wlan: do not retry pre-auth after response with status 17.

Infrastructure APs use status code 17 to indicate that they are
unable to handle additional associations. During roam, we continue
to retry auth (unnecessarily) three times even after receiving an
auth response with status 17. Evidently, all three retry attempts
fail with the same status code 17.

Fix this by passing correct reason code from PE layer to SME
so that auth request is not retried upon receipt of a response
with status code 17.

CRs-Fixed: 454620
Change-Id: I295bced54c55b96cc4c7bc3c812c339eb807536c
diff --git a/CORE/MAC/src/pe/include/limFT.h b/CORE/MAC/src/pe/include/limFT.h
index 74188d1..ba5fa0d 100644
--- a/CORE/MAC/src/pe/include/limFT.h
+++ b/CORE/MAC/src/pe/include/limFT.h
@@ -44,8 +44,8 @@
   
    Macros and Function prototypes FT and 802.11R purposes 
 
-   Copyright 2010 (c) Qualcomm, Incorporated.  All Rights Reserved.
-   Qualcomm Confidential and Proprietary.
+   Copyright 2010 (c) Qualcomm Technologies, Inc.  All Rights Reserved.
+   Qualcomm Technologies Confidential and Proprietary.
   
   ========================================================================*/
 
@@ -72,10 +72,10 @@
 void        limPerformPostFTPreAuth(tpAniSirGlobal pMac, eHalStatus status, tANI_U32 *data, 
                 tpPESession psessionEntry);
 void        limFTResumeLinkCb(tpAniSirGlobal pMac, eHalStatus status, tANI_U32 *data);
-void        limPostFTPreAuthRsp(tpAniSirGlobal pMac, eHalStatus status,
+void        limPostFTPreAuthRsp(tpAniSirGlobal pMac, tSirRetStatus status,
                 tANI_U8 *auth_rsp, tANI_U16  auth_rsp_length,
                 tpPESession psessionEntry);
-void        limHandleFTPreAuthRsp(tpAniSirGlobal pMac, eHalStatus status,
+void        limHandleFTPreAuthRsp(tpAniSirGlobal pMac, tSirRetStatus status,
                 tANI_U8 *auth_rsp, tANI_U16  auth_rsp_len,
                 tpPESession psessionEntry);
 void        limProcessMlmFTReassocReq(tpAniSirGlobal pMac, tANI_U32 *pMsgBuf,
diff --git a/CORE/MAC/src/pe/include/limFTDefs.h b/CORE/MAC/src/pe/include/limFTDefs.h
index 43aca33..2b34866 100644
--- a/CORE/MAC/src/pe/include/limFTDefs.h
+++ b/CORE/MAC/src/pe/include/limFTDefs.h
@@ -44,10 +44,9 @@
   
    Macros and Function prototypes FT and 802.11R purposes 
 
-   Copyright 2010 (c) Qualcomm, Incorporated.  All Rights Reserved.
-   
-   Qualcomm Confidential and Proprietary.
-  
+   Copyright 2010 (c) Qualcomm Technologies, Inc.  All Rights Reserved.
+   Qualcomm Technologies Confidential and Proprietary.
+
   ========================================================================*/
 
 #ifndef __LIMFTDEFS_H__
@@ -89,15 +88,15 @@
   ------------------------------------------------------------------------*/
 typedef struct sSirFTPreAuthRsp
 {
-   tANI_U16    messageType;      // eWNI_SME_FT_PRE_AUTH_RSP
-   tANI_U16    length;
-   tANI_U8     smeSessionId;
-   tSirMacAddr preAuthbssId;     // BSSID to preauth to
-   tANI_U8     status;
-   tANI_U16    ft_ies_length;
-   tANI_U8     ft_ies[MAX_FTIE_SIZE];
-   tANI_U16    ric_ies_length;
-   tANI_U8     ric_ies[MAX_FTIE_SIZE];
+   tANI_U16         messageType;      // eWNI_SME_FT_PRE_AUTH_RSP
+   tANI_U16         length;
+   tANI_U8          smeSessionId;
+   tSirMacAddr      preAuthbssId;     // BSSID to preauth to
+   tSirRetStatus    status;
+   tANI_U16         ft_ies_length;
+   tANI_U8          ft_ies[MAX_FTIE_SIZE];
+   tANI_U16         ric_ies_length;
+   tANI_U8          ric_ies[MAX_FTIE_SIZE];
 } tSirFTPreAuthRsp, *tpSirFTPreAuthRsp;
 
 /*-------------------------------------------------------------------------- 
@@ -117,7 +116,7 @@
 {
     tpSirFTPreAuthReq pFTPreAuthReq;                      // Saved FT Pre Auth Req
     void              *psavedsessionEntry;                
-    tANI_U8           ftPreAuthStatus;
+    tSirRetStatus     ftPreAuthStatus;
     tANI_U16          saved_auth_rsp_length;
     tANI_U8           saved_auth_rsp[MAX_FTIE_SIZE];
 
diff --git a/CORE/MAC/src/pe/lim/limFT.c b/CORE/MAC/src/pe/lim/limFT.c
index f1837a7..a35329d 100644
--- a/CORE/MAC/src/pe/lim/limFT.c
+++ b/CORE/MAC/src/pe/lim/limFT.c
@@ -893,7 +893,7 @@
  *  Will post pre auth response to SME.
  *
  *------------------------------------------------------------------*/
-void limPostFTPreAuthRsp(tpAniSirGlobal pMac, eHalStatus status,
+void limPostFTPreAuthRsp(tpAniSirGlobal pMac, tSirRetStatus status,
     tANI_U8 *auth_rsp, tANI_U16  auth_rsp_length,
     tpPESession psessionEntry)
 {
@@ -956,7 +956,7 @@
     mmhMsg.bodyval = 0;
 
 #if defined WLAN_FEATURE_VOWIFI_11R_DEBUG
-    PELOGE(limLog( pMac, LOGE, "Posted Auth Rsp to SME with status of %d\n", status);)
+    PELOGE(limLog( pMac, LOGE, "Posted Auth Rsp to SME with status of 0x%x", status);)
 #endif
     limSysProcessMmhMsgApi(pMac, &mmhMsg,  ePROT);
 }
@@ -970,7 +970,7 @@
  * FTIEs which will be required for Reassoc Req.
  *
  *------------------------------------------------------------------*/
-void limHandleFTPreAuthRsp(tpAniSirGlobal pMac, eHalStatus status,
+void limHandleFTPreAuthRsp(tpAniSirGlobal pMac, tSirRetStatus status,
     tANI_U8 *auth_rsp, tANI_U16  auth_rsp_length,
     tpPESession psessionEntry)
 {
diff --git a/CORE/MAC/src/pe/lim/limProcessAuthFrame.c b/CORE/MAC/src/pe/lim/limProcessAuthFrame.c
old mode 100644
new mode 100755
index f665e31..232fd23
--- a/CORE/MAC/src/pe/lim/limProcessAuthFrame.c
+++ b/CORE/MAC/src/pe/lim/limProcessAuthFrame.c
@@ -1707,7 +1707,7 @@
  * is received we will have a session in progress. !!!!!
  *----------------------------------------------------------------------
  */
-int limProcessAuthFrameNoSession(tpAniSirGlobal pMac, tANI_U8 *pBd, void *body)
+tSirRetStatus limProcessAuthFrameNoSession(tpAniSirGlobal pMac, tANI_U8 *pBd, void *body)
 {
     tpSirMacMgmtHdr pHdr;
     tpPESession psessionEntry = NULL;
@@ -1715,7 +1715,7 @@
     tANI_U16  frameLen;
     tSirMacAuthFrameBody rxAuthFrame;
     tSirMacAuthFrameBody *pRxAuthFrameBody = NULL;
-    int ret_status = eSIR_FAILURE;
+    tSirRetStatus ret_status = eSIR_FAILURE;
 
     pHdr = WDA_GET_RX_MAC_HEADER(pBd);
     pBody = WDA_GET_RX_MPDU_DATA(pBd);
@@ -1828,9 +1828,11 @@
             if (pRxAuthFrameBody->authStatusCode != eSIR_MAC_SUCCESS_STATUS)
             {
 #ifdef WLAN_FEATURE_VOWIFI_11R_DEBUG
-                PELOGE(limLog( pMac, LOGE, "Auth status code received is  %d\n", 
-                    (tANI_U32) pRxAuthFrameBody->authStatusCode);)
+                PELOGE(limLog( pMac, LOGE, "Auth status code received is %d",
+                    (tANI_U32) pRxAuthFrameBody->authStatusCode););
 #endif
+                if (eSIR_MAC_MAX_ASSOC_STA_REACHED_STATUS == pRxAuthFrameBody->authStatusCode)
+                    ret_status = eSIR_LIM_MAX_STA_REACHED_ERROR;
             }
             else 
             {
diff --git a/CORE/MAC/src/pe/lim/limTypes.h b/CORE/MAC/src/pe/lim/limTypes.h
index ac92ed1..a7c9ead 100644
--- a/CORE/MAC/src/pe/lim/limTypes.h
+++ b/CORE/MAC/src/pe/lim/limTypes.h
@@ -703,7 +703,7 @@
 // Process Auth frame when we have a session in progress.
 void limProcessAuthFrame(tpAniSirGlobal, tANI_U8 *,tpPESession);
 #ifdef WLAN_FEATURE_VOWIFI_11R
-int limProcessAuthFrameNoSession(tpAniSirGlobal pMac, tANI_U8 *, void *body);
+tSirRetStatus limProcessAuthFrameNoSession(tpAniSirGlobal pMac, tANI_U8 *, void *body);
 #endif
 
 void limProcessAssocReqFrame(tpAniSirGlobal, tANI_U8 *, tANI_U8, tpPESession);
diff --git a/CORE/SME/inc/csrNeighborRoam.h b/CORE/SME/inc/csrNeighborRoam.h
index 9ea3a7e..1c3ff4d 100644
--- a/CORE/SME/inc/csrNeighborRoam.h
+++ b/CORE/SME/inc/csrNeighborRoam.h
@@ -129,8 +129,6 @@
     tANI_BOOLEAN                preauthRspPending;
     tANI_BOOLEAN                neighborRptPending;
     tANI_U8                     currentNeighborRptRetryNum;
-    tPalTimerHandle             preAuthRspWaitTimer; //This timer is used for preauth response
-    tCsrTimerInfo               preAuthRspWaitTimerInfo;
     tCsrPreauthFailListInfo     preAuthFailList;
     tANI_U32                    neighborReportTimeout;
     tANI_U32                    PEPreauthRespTimeout;
@@ -215,7 +213,7 @@
 VOS_STATUS csrNeighborRoamTransitionToPreauthDone(tpAniSirGlobal pMac);
 eHalStatus csrNeighborRoamPrepareScanProfileFilter(tpAniSirGlobal pMac, tCsrScanResultFilter *pScanFilter);
 void csrNeighborRoamGetHandoffAPInfo(tpAniSirGlobal pMac, tpCsrNeighborRoamBSSInfo pHandoffNode);
-eHalStatus csrNeighborRoamPreauthRspHandler(tpAniSirGlobal pMac, VOS_STATUS vosStatus);
+eHalStatus csrNeighborRoamPreauthRspHandler(tpAniSirGlobal pMac, tSirRetStatus limStatus);
 #ifdef WLAN_FEATURE_VOWIFI_11R
 tANI_BOOLEAN csrNeighborRoamIs11rAssoc(tpAniSirGlobal pMac);
 #endif
diff --git a/CORE/SME/src/csr/csrApiRoam.c b/CORE/SME/src/csr/csrApiRoam.c
index 8053307..c3eeee9 100755
--- a/CORE/SME/src/csr/csrApiRoam.c
+++ b/CORE/SME/src/csr/csrApiRoam.c
@@ -14970,10 +14970,10 @@
 #endif
 
 #if defined WLAN_FEATURE_VOWIFI_11R_DEBUG
-    smsLog( pMac, LOGE, FL("Preauth response status code %d"), pFTPreAuthRsp->status); 
+    smsLog( pMac, LOGE, FL("Preauth response status code 0x%x"), pFTPreAuthRsp->status);
 #endif
 #ifdef WLAN_FEATURE_NEIGHBOR_ROAMING
-    status = csrNeighborRoamPreauthRspHandler(pMac, (VOS_STATUS)pFTPreAuthRsp->status);
+    status = csrNeighborRoamPreauthRspHandler(pMac, pFTPreAuthRsp->status);
     if (status != eHAL_STATUS_SUCCESS) {
         /*
          * Bail out if pre-auth was not even processed.
diff --git a/CORE/SME/src/csr/csrNeighborRoam.c b/CORE/SME/src/csr/csrNeighborRoam.c
index c060251..7e8addd 100644
--- a/CORE/SME/src/csr/csrNeighborRoam.c
+++ b/CORE/SME/src/csr/csrNeighborRoam.c
@@ -438,9 +438,6 @@
 
 #if  defined (WLAN_FEATURE_VOWIFI_11R) || defined (FEATURE_WLAN_CCX) || defined(FEATURE_WLAN_LFR)
         pNeighborRoamInfo->is11rAssoc = eANI_BOOLEAN_FALSE;
-        pNeighborRoamInfo->FTRoamInfo.preAuthRspWaitTimerInfo.pMac = pMac;
-        pNeighborRoamInfo->FTRoamInfo.preAuthRspWaitTimerInfo.sessionId = 
-                CSR_SESSION_ID_INVALID;
         /* Purge pre-auth fail list */
         csrNeighborRoamPurgePreauthFailedList(pMac);
 #endif
@@ -453,7 +450,6 @@
         pNeighborRoamInfo->FTRoamInfo.neighborRptPending = eANI_BOOLEAN_FALSE;
         pNeighborRoamInfo->FTRoamInfo.numBssFromNeighborReport = 0;
         vos_mem_zero(pNeighborRoamInfo->FTRoamInfo.neighboReportBssInfo, sizeof(tCsrNeighborReportBssInfo) * MAX_BSS_IN_NEIGHBOR_RPT);
-        palTimerStop(pMac->hHdd, pNeighborRoamInfo->FTRoamInfo.preAuthRspWaitTimer);
 #endif
 }
 
@@ -556,7 +552,6 @@
     pNeighborRoamInfo->FTRoamInfo.numBssFromNeighborReport = 0;
     pNeighborRoamInfo->FTRoamInfo.preauthRspPending = 0;
     vos_mem_zero(pNeighborRoamInfo->FTRoamInfo.neighboReportBssInfo, sizeof(tCsrNeighborReportBssInfo) * MAX_BSS_IN_NEIGHBOR_RPT);
-    palTimerStop(pMac->hHdd, pNeighborRoamInfo->FTRoamInfo.preAuthRspWaitTimer);
 #endif
 }
 
@@ -802,17 +797,6 @@
     
     /* Transition the state to preauthenticating */
     CSR_NEIGHBOR_ROAM_STATE_TRANSITION(eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING)
-#if 0    
-    /* Start the preauth rsp timer */
-    status = palTimerStart(pMac->hHdd, pNeighborRoamInfo->FTRoamInfo.preAuthRspWaitTimer, 
-                   CSR_NEIGHBOR_ROAM_PREAUTH_RSP_WAIT_MULTIPLIER * pNeighborRoamInfo->cfgParams.neighborScanPeriod * PAL_TIMER_TO_MS_UNIT,
-                   eANI_BOOLEAN_FALSE);
-    if (eHAL_STATUS_SUCCESS != status)
-    {
-        smsLog(pMac, LOGE, FL("Preauth response wait timer start failed with status %d\n"), status);
-        return status;
-    }
-#endif
     
     return status;
 }
@@ -829,16 +813,18 @@
             roamable AP list, transition to REPORT_SCAN state
 
     \param  pMac - The handle returned by macOpen.
-            vosStatus - VOS_STATUS_SUCCESS/FAILURE/TIMEOUT status from PE
+            limStatus - eSIR_SUCCESS/eSIR_FAILURE/eSIR_LIM_MAX_STA_REACHED_ERROR/
+                     eSIT_LIM_AUTH_RSP_TIMEOUT status from PE
 
     \return eHAL_STATUS_SUCCESS on success (i.e. pre-auth processed),
             eHAL_STATUS_FAILURE otherwise
 
 ---------------------------------------------------------------------------*/
-eHalStatus csrNeighborRoamPreauthRspHandler(tpAniSirGlobal pMac, VOS_STATUS vosStatus)
+eHalStatus csrNeighborRoamPreauthRspHandler(tpAniSirGlobal pMac, tSirRetStatus limStatus)
 {
     tpCsrNeighborRoamControlInfo    pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
     eHalStatus  status = eHAL_STATUS_SUCCESS;
+    VOS_STATUS  vosStatus = VOS_STATUS_SUCCESS;
     eHalStatus  preauthProcessed = eHAL_STATUS_SUCCESS;
     tpCsrNeighborRoamBSSInfo pPreauthRspNode = NULL;
 
@@ -867,20 +853,13 @@
         goto DEQ_PREAUTH;
     }
 
-    if (VOS_STATUS_E_TIMEOUT != vosStatus)
-    {
-#if 0
-        /* This means we got the response from PE. Hence stop the timer */
-        status = palTimerStop(pMac->hHdd, pNeighborRoamInfo->FTRoamInfo.preAuthRspWaitTimer);
-#endif
-        pNeighborRoamInfo->FTRoamInfo.preauthRspPending = eANI_BOOLEAN_FALSE;
-    }
+    pNeighborRoamInfo->FTRoamInfo.preauthRspPending = eANI_BOOLEAN_FALSE;
 
-    if (VOS_STATUS_SUCCESS == vosStatus)
+    if (eSIR_SUCCESS == limStatus)
     {
         pPreauthRspNode = csrNeighborRoamGetRoamableAPListNextEntry(pMac, &pNeighborRoamInfo->roamableAPList, NULL);
     }
-    if ((VOS_STATUS_SUCCESS == vosStatus) && (NULL != pPreauthRspNode))
+    if ((eSIR_SUCCESS == limStatus) && (NULL != pPreauthRspNode))
     {
         NEIGHBOR_ROAM_DEBUG(pMac, LOGE, FL("Preauth completed successfully after %d tries\n"), pNeighborRoamInfo->FTRoamInfo.numPreAuthRetries);
 
@@ -909,10 +888,13 @@
         tpCsrNeighborRoamBSSInfo    pNeighborBssNode = NULL;
         tListElem                   *pEntry;
 
-        smsLog(pMac, LOGE, FL("Preauth failed retry number %d, status = %d\n"), pNeighborRoamInfo->FTRoamInfo.numPreAuthRetries, vosStatus);
+        smsLog(pMac, LOGE, FL("Preauth failed retry number %d, status = 0x%x"),
+               pNeighborRoamInfo->FTRoamInfo.numPreAuthRetries, limStatus);
         
         /* Preauth failed. Add the bssId to the preAuth failed list MAC Address. Also remove the AP from roamable AP list */
-        if (pNeighborRoamInfo->FTRoamInfo.numPreAuthRetries >=  CSR_NEIGHBOR_ROAM_MAX_NUM_PREAUTH_RETRIES)
+        if ((pNeighborRoamInfo->FTRoamInfo.numPreAuthRetries >=
+             CSR_NEIGHBOR_ROAM_MAX_NUM_PREAUTH_RETRIES) ||
+            (eSIR_LIM_MAX_STA_REACHED_ERROR == limStatus))
         {
             /* We are going to remove the node as it fails for more than MAX tries. Reset this count to 0 */
             pNeighborRoamInfo->FTRoamInfo.numPreAuthRetries = 0;
@@ -3275,8 +3257,6 @@
             if ( init_ft_flag == TRUE )
             {
                 /* Initialize all the data structures needed for the 11r FT Preauth */
-                pNeighborRoamInfo->FTRoamInfo.preAuthRspWaitTimerInfo.pMac = pMac;
-                pNeighborRoamInfo->FTRoamInfo.preAuthRspWaitTimerInfo.sessionId = sessionId;
                 pNeighborRoamInfo->FTRoamInfo.currentNeighborRptRetryNum = 0;
                 csrNeighborRoamPurgePreauthFailedList(pMac);
 
@@ -3309,30 +3289,6 @@
 #ifdef WLAN_FEATURE_VOWIFI_11R
 /* ---------------------------------------------------------------------------
 
-    \fn csrNeighborRoamPreAuthResponseWaitTimerHandler
-
-    \brief  If this function is invoked, that means the preauthentication response 
-            is timed out from the PE. Preauth rsp handler is called with status as 
-            TIMEOUT
-
-    \param  context - CSR Timer info which holds pMac and session ID
-
-    \return VOID
-
----------------------------------------------------------------------------*/
-void csrNeighborRoamPreAuthResponseWaitTimerHandler(void *context)
-{
-    tCsrTimerInfo *pTimerInfo = (tCsrTimerInfo *)context;
-    tpAniSirGlobal pMac = (tpAniSirGlobal)pTimerInfo->pMac;
-    tpCsrNeighborRoamControlInfo    pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
-
-    pNeighborRoamInfo->FTRoamInfo.preauthRspPending = eANI_BOOLEAN_FALSE;
-
-    csrNeighborRoamPreauthRspHandler(pMac, VOS_STATUS_E_TIMEOUT);
-}
-
-/* ---------------------------------------------------------------------------
-
     \fn csrNeighborRoamPurgePreauthFailedList
 
     \brief  This function purges all the MAC addresses in the pre-auth fail list
@@ -3378,17 +3334,6 @@
     pFTRoamInfo->neighborRptPending = eANI_BOOLEAN_FALSE;
     pFTRoamInfo->preauthRspPending = eANI_BOOLEAN_FALSE;
     
-    pFTRoamInfo->preAuthRspWaitTimerInfo.pMac = pMac;
-    pFTRoamInfo->preAuthRspWaitTimerInfo.sessionId = CSR_SESSION_ID_INVALID;
-    status = palTimerAlloc(pMac->hHdd, &pFTRoamInfo->preAuthRspWaitTimer, 
-                    csrNeighborRoamPreAuthResponseWaitTimerHandler, (void *)&pFTRoamInfo->preAuthRspWaitTimerInfo);
-
-    if (eHAL_STATUS_SUCCESS != status)
-    {
-        smsLog(pMac, LOGE, FL("Response wait Timer allocation failed"));
-        return eHAL_STATUS_RESOURCES;
-    }
-    
     pMac->roam.neighborRoamInfo.FTRoamInfo.currentNeighborRptRetryNum = 0;
     pMac->roam.neighborRoamInfo.FTRoamInfo.numBssFromNeighborReport = 0;
     vos_mem_zero(pMac->roam.neighborRoamInfo.FTRoamInfo.neighboReportBssInfo, 
@@ -3399,7 +3344,6 @@
     if (eHAL_STATUS_SUCCESS != status)
     {
         smsLog(pMac, LOGE, FL("LL Open of preauth done AP List failed"));
-        palTimerFree(pMac->hHdd, pFTRoamInfo->preAuthRspWaitTimer);
         return eHAL_STATUS_RESOURCES;
     }
     return status;
@@ -3578,9 +3522,6 @@
 #endif
 #ifdef WLAN_FEATURE_VOWIFI_11R
     pMac->roam.neighborRoamInfo.FTRoamInfo.currentNeighborRptRetryNum = 0;
-    palTimerFree(pMac->hHdd, pMac->roam.neighborRoamInfo.FTRoamInfo.preAuthRspWaitTimer);
-    pMac->roam.neighborRoamInfo.FTRoamInfo.preAuthRspWaitTimerInfo.pMac = NULL;
-    pMac->roam.neighborRoamInfo.FTRoamInfo.preAuthRspWaitTimerInfo.sessionId = CSR_SESSION_ID_INVALID;
     pMac->roam.neighborRoamInfo.FTRoamInfo.numBssFromNeighborReport = 0;
     vos_mem_zero(pMac->roam.neighborRoamInfo.FTRoamInfo.neighboReportBssInfo, 
                             sizeof(tCsrNeighborReportBssInfo) * MAX_BSS_IN_NEIGHBOR_RPT);
@@ -3806,7 +3747,8 @@
 }
 
 /* ---------------------------------------------------------------------------
-    \brief  This function returns TRUE if preauth is completed
+    \brief  This function returns TRUE if background scan triggered by
+            LFR is in progress.
 
     \param  halHandle - The handle from HDD context.