wlan: Dont allow Channel switch if link is already suspended

If channel change is received win non zero switch count, a timer
is started and actual channel is channged after timer expire.
It may happen that the scan has already started before this channel
switch timer expire.

There is no handling in timer callback to check if driver is
already in scan state and thus it may send finish scan req once
channel change is completed as link is in suspended state due to
scan in progress.
This leads to change in scan states and scan is stuck.

As part of the fix drop change channel req if link is in
suspended state.

CRs-Fixed: 916864
Change-Id: I288503eb1d570c2848d7fc64015d31d24b9887a1
diff --git a/CORE/MAC/src/pe/lim/limUtils.c b/CORE/MAC/src/pe/lim/limUtils.c
index 6fe7eb8..4b31cde 100644
--- a/CORE/MAC/src/pe/lim/limUtils.c
+++ b/CORE/MAC/src/pe/lim/limUtils.c
@@ -2606,19 +2606,6 @@
     channel = psessionEntry->gLimChannelSwitch.primaryChannel;
 
     /*
-     * If Lim allows Switch channel on same channel on which preauth
-     * is going on then LIM will not post resume link(WDA_FINISH_SCAN)
-     * during preauth rsp handling hence firmware may crash on ENTER/
-     * EXIT BMPS request.
-     */
-    if(pMac->ft.ftPEContext.pFTPreAuthReq)
-    {
-        limLog(pMac, LOGE,
-           FL("Avoid Switch Channel req during pre auth"));
-        return;
-    }
-
-    /*
      *  This potentially can create issues if the function tries to set
      * channel while device is in power-save, hence putting an extra check
      * to verify if the device is in power-save or not
@@ -2634,7 +2621,34 @@
 
     /* Channel-switch timeout has occurred. reset the state */
     psessionEntry->gLimSpecMgmt.dot11hChanSwState = eLIM_11H_CHANSW_END;
-    
+
+    /*
+     * If Lim allows Switch channel on same channel on which preauth
+     * is going on then LIM will not post resume link(WDA_FINISH_SCAN)
+     * during preauth rsp handling hence firmware may crash on ENTER/
+     * EXIT BMPS request.
+     */
+    if(pMac->ft.ftPEContext.pFTPreAuthReq)
+    {
+        limLog(pMac, LOGE,
+           FL("Avoid Switch Channel req during pre auth"));
+        return;
+    }
+    /* If link is already suspended mean some off
+     * channel operation or scan is in progress, Allowing
+     * Change channel here will lead to either Init Scan
+     * sent twice or missing Finish scan when change
+     * channel is completed, this may lead
+     * to driver in invalid state and crash.
+     */
+    if (limIsLinkSuspended(pMac))
+    {
+       limLog(pMac, LOGE, FL("Link is already suspended for "
+               "some other reason. Return here for sessionId:%d"),
+               pMac->lim.limTimers.gLimChannelSwitchTimer.sessionId);
+       return;
+    }
+
     /* Check if the AP is switching to a channel that we support.
      * Else, just don't bother to switch. Indicate HDD to look for a 
      * better AP to associate
@@ -2666,14 +2680,6 @@
             if ( isLimSessionOffChannel(pMac,
                 pMac->lim.limTimers.gLimChannelSwitchTimer.sessionId) )
             {
-                if (limIsLinkSuspended(pMac))
-                {
-                    limLog(pMac, LOGE, FL("Link is already suspended for "
-                        "some other reason. Return here for sessionId:%d"),
-                        pMac->lim.limTimers.gLimChannelSwitchTimer.sessionId);
-                    return;
-                }
-
                 limSuspendLink(pMac,
                     eSIR_DONT_CHECK_LINK_TRAFFIC_BEFORE_SCAN,
                     limProcessChannelSwitchSuspendLink,