wlan: Fix race between STA connect and SAP channel switch

If SAP channel change is in progress and STA connect req is received
driver ends up sending two change channel req to firmware.
As WDA and WDI is not sessionized to handle two back to back channel
change req the ADD BSS req is dropped and no response for ADD BSS is
sent to LIM. This result in roam command timeout.

The fix adds logic to
- Flush channel change workqueue when STA connection is requested.
- Wait for channel change to complete when STA connection is requested
  OR SAP is turned off.
- Check for DFS channel of SAP if STA conenction fails as during
  connect driver flush the channel change workqueue.

Change-Id: I8b67538178ccd866a1a9430ed55a6fa8d5dbfd40
CRs-Fixed: 2204574
diff --git a/CORE/HDD/src/wlan_hdd_hostapd.c b/CORE/HDD/src/wlan_hdd_hostapd.c
index 87d3d6d..63e76bc 100644
--- a/CORE/HDD/src/wlan_hdd_hostapd.c
+++ b/CORE/HDD/src/wlan_hdd_hostapd.c
@@ -2471,11 +2471,25 @@
                 break;
             }
         case QCSAP_PARAM_SET_CHANNEL_CHANGE:
-            if ((WLAN_HDD_SOFTAP == pHostapdAdapter->device_mode) ||
-                (WLAN_HDD_P2P_GO == pHostapdAdapter->device_mode)) {
+            if (WLAN_HDD_SOFTAP == pHostapdAdapter->device_mode) {
+                ptSapContext sap_ctx;
+
+                sap_ctx = VOS_GET_SAP_CB(pVosContext);
+                if (!sap_ctx) {
+                    hddLog(LOGE, FL("sap_ctx is NULL"));
+                    return -EINVAL;
+                }
+                ret = wlansap_chk_n_set_chan_change_in_progress(sap_ctx);
+                if (ret)
+                    return ret;
+                INIT_COMPLETION(sap_ctx->ecsa_info.chan_switch_comp);
                 hddLog(LOG1, FL("ET Channel Change to new channel= %d"),
                        set_value);
                 ret = wlansap_set_channel_change(pVosContext, set_value, false);
+                if (ret) {
+                       wlansap_reset_chan_change_in_progress(sap_ctx);
+                       complete(&sap_ctx->ecsa_info.chan_switch_comp);
+                }
             } else {
                 hddLog(LOGE, FL("Channel %d Change Failed, Device in not in SAP/GO mode"),
                        set_value);