wlan: Stop STA if connection in progress and SAP Stop is received

In STA+SAP concurrency, when the STA connection is in progress or set_key
is in progress, the set_hw_mode command to SME is queued and would be
processed only after the connection is complete. Meanwhile, when a stop
SAP is received and SAP Dissassociate STA is triggered from HDD, the
command is queued in SME and cannot be processed until STA connection
is done. The add_key command from the supplicant is also stuck as the
previous stop_ap command is in progress leading to a deadlock. When the
AP sends deauth to the STA due to 4 Way Handshake failure, the STA is
reset and then the stop SAP command proceeds, followed by another
connection for the STA.

Disconnect STA interface first if connection or key exchange is in progress
and then stop SAP interface to prevent this deadlock condition.

Change-Id: I23ad1fc96882abeaae2d1b051659ea6d24b07428
CRs-Fixed: 2260693
diff --git a/CORE/HDD/src/wlan_hdd_cfg80211.c b/CORE/HDD/src/wlan_hdd_cfg80211.c
index 10a69e1..28a17b5 100644
--- a/CORE/HDD/src/wlan_hdd_cfg80211.c
+++ b/CORE/HDD/src/wlan_hdd_cfg80211.c
@@ -11815,6 +11815,7 @@
 #endif
 {
     hdd_adapter_t *pAdapter =  WLAN_HDD_GET_PRIV_PTR(dev);
+    hdd_adapter_t  *staAdapter = NULL;
     hdd_context_t  *pHddCtx    = NULL;
     hdd_scaninfo_t *pScanInfo  = NULL;
     VOS_STATUS status;
@@ -11845,6 +11846,18 @@
            __func__, hdd_device_modetoString(pAdapter->device_mode),
                                              pAdapter->device_mode);
 
+    /*
+     * if a sta connection is in progress in another adapter, disconnect
+     * the sta and complete the sap operation. sta will reconnect
+     * after sap stop is done.
+     */
+    staAdapter = hdd_get_sta_connection_in_progress(pHddCtx);
+    if (staAdapter) {
+        hddLog(LOG1, FL("disconnecting sta with session id: %d"),
+               staAdapter->sessionId);
+        wlan_hdd_disconnect(staAdapter, eCSR_DISCONNECT_REASON_DEAUTH);
+    }
+
     ret = wlan_hdd_scan_abort(pAdapter);
 
     if (ret < 0)