wlan: 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: 2154324
diff --git a/CORE/HDD/src/wlan_hdd_cfg80211.c b/CORE/HDD/src/wlan_hdd_cfg80211.c
index 48cb9e1..ec45a43 100644
--- a/CORE/HDD/src/wlan_hdd_cfg80211.c
+++ b/CORE/HDD/src/wlan_hdd_cfg80211.c
@@ -16252,6 +16252,7 @@
     hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
     long ret;
     eConnectionState prev_conn_state;
+    uint32_t wait_time = WLAN_WAIT_TIME_DISCONNECT;
 
     ENTER();
 
@@ -16309,7 +16310,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
@@ -16330,9 +16339,9 @@
         result = -EINVAL;
         goto disconnected;
     }
-    ret = wait_for_completion_timeout(
-                &pAdapter->disconnect_comp_var,
-                msecs_to_jiffies(WLAN_WAIT_TIME_DISCONNECT));
+wait_for_disconnect:
+    ret = wait_for_completion_timeout(&pAdapter->disconnect_comp_var,
+                                      msecs_to_jiffies(wait_time));
     if (!ret && (eHAL_STATUS_CMD_NOT_QUEUED != status))
     {
         hddLog(LOGE,