wlan: Enqueue preauth in sme command queue.

Serial the preauth on the SME command queue. This maintains SMEs
"contract" wth PE for "one operation at a time".

Change-Id: I05bd439198d0d70969ad065b35ed090c8d323005
CR-Fixed: 406198
diff --git a/CORE/SME/inc/csrInternal.h b/CORE/SME/inc/csrInternal.h
index 5817543..a257881 100644
--- a/CORE/SME/inc/csrInternal.h
+++ b/CORE/SME/inc/csrInternal.h
@@ -168,6 +168,7 @@
     eCsrSmeIssuedFTReassoc,
     eCsrForcedDisassocSta,
     eCsrForcedDeauthSta,
+    eCsrPerformPreauth,
     
 }eCsrRoamReason;
 
diff --git a/CORE/SME/src/csr/csrApiRoam.c b/CORE/SME/src/csr/csrApiRoam.c
index d7e3907..a1fca78 100644
--- a/CORE/SME/src/csr/csrApiRoam.c
+++ b/CORE/SME/src/csr/csrApiRoam.c
@@ -261,6 +261,7 @@
 extern void SysProcessMmhMsg(tpAniSirGlobal pMac, tSirMsgQ* pMsg);
 extern void btampEstablishLogLinkHdlr(void* pMsg);
 static void csrSerDesUnpackDiassocRsp(tANI_U8 *pBuf, tSirSmeDisassocRsp *pRsp);
+void csrReinitPreauthCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand);
 
 //Initialize global variables
 static void csrRoamInitGlobals(tpAniSirGlobal pMac)
@@ -741,6 +742,12 @@
     
                 
                 
+void csrReleaseCommandPreauth(tpAniSirGlobal pMac, tSmeCmd *pCommand)
+{
+    csrReinitPreauthCmd(pMac, pCommand);
+    csrReleaseCommand( pMac, pCommand );
+}
+                
 void csrReleaseCommandRoam(tpAniSirGlobal pMac, tSmeCmd *pCommand)
 {
     csrReinitRoamCmd(pMac, pCommand);
@@ -3944,6 +3951,14 @@
        status = csrSendMBDeauthReqMsg( pMac, sessionId, pCommand->u.roamCmd.peerMac, 
                      pCommand->u.roamCmd.reason);
        break;
+#if 1
+       /*Varun*/
+    case eCsrPerformPreauth:
+        smsLog(pMac, LOGE, FL("Attempting FT PreAuth Req \n"));
+        status = csrRoamIssueFTPreauthReq(pMac, sessionId, 
+                pCommand->u.roamCmd.pLastRoamBss);
+       break;
+#endif
 
     default:
         csrRoamStateChange( pMac, eCSR_ROAMING_STATE_JOINING, sessionId );
@@ -3969,6 +3984,14 @@
     return (status);
 }
 
+void csrReinitPreauthCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand) 
+{
+    pCommand->u.roamCmd.pLastRoamBss = NULL;
+    pCommand->u.roamCmd.pRoamBssEntry = NULL;
+    //Because u.roamCmd is union and share with scanCmd and StatusChange
+    palZeroMemory(pMac->hHdd, &pCommand->u.roamCmd, sizeof(tRoamCmd));
+}
+
 void csrReinitRoamCmd(tpAniSirGlobal pMac, tSmeCmd *pCommand) 
 {
     if(pCommand->u.roamCmd.fReleaseBssList)
@@ -5474,6 +5497,74 @@
     return (status);
 }
 
+eHalStatus csrRoamEnqueuePreauth(tpAniSirGlobal pMac, tANI_U32 sessionId, tpSirBssDescription pBssDescription,
+                                eCsrRoamReason reason, tANI_BOOLEAN fImmediate)
+//                               , eCsrRoamReason reason, tANI_U32 roamId, tANI_BOOLEAN fImediate)
+{
+    eHalStatus status = eHAL_STATUS_SUCCESS;
+    tSmeCmd *pCommand;
+    
+    pCommand = csrGetCommandBuffer(pMac);
+    if(NULL == pCommand)
+    {
+        smsLog( pMac, LOGE, FL(" fail to get command buffer\n") );
+        status = eHAL_STATUS_RESOURCES;
+    }
+    else
+    {
+        if(pBssDescription)
+        {
+            //copy over the parameters we need later
+            pCommand->command = eSmeCommandRoam;
+            pCommand->sessionId = (tANI_U8)sessionId;
+            pCommand->u.roamCmd.roamReason = reason;
+            //this is the important parameter
+            //in this case we are using this field for the "next" BSS 
+            pCommand->u.roamCmd.pLastRoamBss = pBssDescription;
+            status = csrQueueSmeCommand(pMac, pCommand, fImmediate);
+            if( !HAL_STATUS_SUCCESS( status ) )
+            {
+                smsLog( pMac, LOGE, FL(" fail to enqueue preauth command, status = %d\n"), status );
+                csrReleaseCommandPreauth( pMac, pCommand );
+            }
+        }
+        else
+        {
+           //Return failure
+           status = eHAL_STATUS_RESOURCES;
+        }
+    }
+    return (status);
+}
+
+eHalStatus csrRoamDequeuePreauth(tpAniSirGlobal pMac)
+{
+    tListElem *pEntry;
+    tSmeCmd *pCommand;
+    pEntry = csrLLPeekHead( &pMac->sme.smeCmdActiveList, LL_ACCESS_LOCK );
+    if ( pEntry )
+    {
+        pCommand = GET_BASE_ADDR( pEntry, tSmeCmd, Link );
+        if ( (eSmeCommandRoam == pCommand->command) && 
+                (eCsrPerformPreauth == pCommand->u.roamCmd.roamReason))
+        {             
+            smsLog( pMac, LOGE, FL("DQ-Command = %d, Reason = %d \n"), 
+                    pCommand->command, pCommand->u.roamCmd.roamReason);
+            if (csrLLRemoveEntry( &pMac->sme.smeCmdActiveList, pEntry, LL_ACCESS_LOCK )) {
+                csrReleaseCommandPreauth( pMac, pCommand );
+            }
+        } else  {
+            smsLog( pMac, LOGE, FL("Command = %d, Reason = %d \n"), 
+                    pCommand->command, pCommand->u.roamCmd.roamReason);
+        }
+    }
+    else {
+        smsLog( pMac, LOGE, FL("pEntry NULL for eWNI_SME_FT_PRE_AUTH_RSP\n"));
+    }
+    smeProcessPendingQueue( pMac );
+    return eHAL_STATUS_SUCCESS;
+}
+
 eHalStatus csrRoamConnectWithBSSList(tpAniSirGlobal pMac, tANI_U32 sessionId, tCsrRoamProfile *pProfile, 
                                      tScanResultHandle hBssListIn, tANI_U32 *pRoamId)
 {
diff --git a/CORE/SME/src/csr/csrInsideApi.h b/CORE/SME/src/csr/csrInsideApi.h
index c38961e..1654d83 100644
--- a/CORE/SME/src/csr/csrInsideApi.h
+++ b/CORE/SME/src/csr/csrInsideApi.h
@@ -922,5 +922,10 @@
 eHalStatus csrGetDefaultCountryCodeFrmNv(tpAniSirGlobal pMac, tANI_U8 *pCountry);
 eHalStatus csrGetCurrentCountryCode(tpAniSirGlobal pMac, tANI_U8 *pCountry);
 
+
+eHalStatus csrRoamEnqueuePreauth(tpAniSirGlobal pMac, tANI_U32 sessionId, tpSirBssDescription pBssDescription,
+                                eCsrRoamReason reason, tANI_BOOLEAN fImmediate);
+eHalStatus csrRoamDequeuePreauth(tpAniSirGlobal pMac);
+
 #endif
 
diff --git a/CORE/SME/src/csr/csrNeighborRoam.c b/CORE/SME/src/csr/csrNeighborRoam.c
index ca8181b..7cf882b 100644
--- a/CORE/SME/src/csr/csrNeighborRoam.c
+++ b/CORE/SME/src/csr/csrNeighborRoam.c
@@ -259,6 +259,7 @@
     
     NEIGHBOR_ROAM_DEBUG(pMac, LOG2, FL("Deregistering UP event neighbor lookup callback with TL. RSSI = %d"), pNeighborRoamInfo->cfgParams.neighborLookupThreshold * (-1));
     /* Deregister reassoc callback. Ignore return status */
+    /*Varun TODO*/
     vosStatus = WLANTL_DeregRSSIIndicationCB(pMac->roam.gVosContext, (v_S7_t)pNeighborRoamInfo->cfgParams.neighborLookupThreshold * (-1),
                                                         WLANTL_HO_THRESHOLD_DOWN, 
                                                         csrNeighborRoamNeighborLookupUPCallback,
@@ -669,7 +670,8 @@
     }
     else
     {
-        status = csrRoamIssueFTPreauthReq(pMac, pNeighborRoamInfo->csrSessionId, pNeighborBssNode->pBssDescription); 
+        status = csrRoamEnqueuePreauth(pMac, pNeighborRoamInfo->csrSessionId, pNeighborBssNode->pBssDescription,
+                eCsrPerformPreauth, eANI_BOOLEAN_TRUE);
         if (eHAL_STATUS_SUCCESS != status)
         {
             smsLog(pMac, LOGE, FL("Send Preauth request to PE failed with status %d\n"), status);
@@ -684,7 +686,7 @@
     
     /* 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,
@@ -694,7 +696,7 @@
         smsLog(pMac, LOGE, FL("Preauth response wait timer start failed with status %d\n"), status);
         return status;
     }
-
+#endif
     
     return status;
 }
@@ -721,6 +723,8 @@
     tpCsrNeighborRoamControlInfo    pNeighborRoamInfo = &pMac->roam.neighborRoamInfo;
     eHalStatus  status = eHAL_STATUS_SUCCESS;
     tpCsrNeighborRoamBSSInfo pPreauthRspNode = NULL;
+    
+    csrRoamDequeuePreauth(pMac);
 
     // We can receive it in these 2 states.
     VOS_ASSERT((pNeighborRoamInfo->neighborRoamState == eCSR_NEIGHBOR_ROAM_STATE_PREAUTHENTICATING) ||
@@ -736,8 +740,10 @@
 
     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;
     }