qcacld-2.0: Wait for disconnect to complete, even if diconnect req is not queued

If SME is in disconnecting state disconnect from supplicant will not
get queued. Thus supplicant can start a connect req as soon
as HDD returns from disconnect req. If this connect req is processed
by HDD before the SME disconnect is indicated to HDD, it will cause
HDD/supplicant and SME out of sync.

This results into scan allowed even when SME is waiting for key.
SME will not allow scan until set key is completed, which may not
happened as HDD has indicated disconnect to supplicant after connect
was received by HDD.

To fix this wait for WLAN_WAIT_DISCONNECT_ALREADY_IN_PROGRESS time
in HDD for SME disconnect to get processed before returning.

Change-Id: I21f2c2e2f9b97fc50f9ac43bc5bbb5fd5188f3b7
CRs-Fixed: 2175203
diff --git a/CORE/HDD/inc/wlan_hdd_main.h b/CORE/HDD/inc/wlan_hdd_main.h
index c9db52a..ba12da3 100644
--- a/CORE/HDD/inc/wlan_hdd_main.h
+++ b/CORE/HDD/inc/wlan_hdd_main.h
@@ -109,6 +109,7 @@
 
 /** Maximum time(ms)to wait for disconnect to complete **/
 #define WLAN_WAIT_TIME_DISCONNECT  5000
+#define WLAN_WAIT_DISCONNECT_ALREADY_IN_PROGRESS  1000
 #define WLAN_WAIT_TIME_STATS       800
 #define WLAN_WAIT_TIME_POWER       800
 #define WLAN_WAIT_TIME_COUNTRY     1000
diff --git a/CORE/HDD/src/wlan_hdd_cfg80211.c b/CORE/HDD/src/wlan_hdd_cfg80211.c
index 03fd124..699f073 100644
--- a/CORE/HDD/src/wlan_hdd_cfg80211.c
+++ b/CORE/HDD/src/wlan_hdd_cfg80211.c
@@ -24203,6 +24203,7 @@
     hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(pAdapter);
     hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
     eConnectionState prev_conn_state;
+    uint32_t wait_time = WLAN_WAIT_TIME_DISCONNECT;
 
     ENTER();
 
@@ -24230,7 +24231,15 @@
         hddLog(LOG1,
                FL("status = %d, already disconnected"), status);
         result = 0;
-        goto disconnected;
+        /*
+         * Wait here instead of returning directly. This will block the
+         * next connect command and allow processing of the disconnect
+         * in SME else we might hit some race conditions leading to SME
+         * and HDD out of sync. As disconnect is already in progress,
+         * wait here for 1 sec instead of 5 sec.
+         */
+        wait_time = WLAN_WAIT_DISCONNECT_ALREADY_IN_PROGRESS;
+        goto wait_for_disconnect;
     }
     /*
      * Wait here instead of returning directly, this will block the next
@@ -24249,9 +24258,10 @@
         result = -EINVAL;
         goto disconnected;
     }
+wait_for_disconnect:
     rc = wait_for_completion_timeout(
                 &pAdapter->disconnect_comp_var,
-                msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
+                msecs_to_jiffies(wait_time));
 
     if (!rc && (eHAL_STATUS_CMD_NOT_QUEUED != status)) {
        hddLog(VOS_TRACE_LEVEL_ERROR,