wlan: Fix for not able to turn off WLAN, when join request fails in WDI

1) Added the check in WDA if BSSID in setlink state in NULL and ASEERT.
2) Reset the WDA state when set link state comes when WDA is in
WDA_PRE_ASSOC_STATE.
3) Reset the pWDICtx->bAssociationInProgress to FALSE if the join
request fails.
4) Modified the logic in WDI_FindAssocSession() to check for BSSID only
if the session is in use.

Change-Id: I35e1fad2d2c2395034cba9ae65ba308d45e7fdc2
CR-Fixed: 409734
diff --git a/CORE/WDA/src/wlan_qct_wda.c b/CORE/WDA/src/wlan_qct_wda.c
index af40da8..44bcfa7 100644
--- a/CORE/WDA/src/wlan_qct_wda.c
+++ b/CORE/WDA/src/wlan_qct_wda.c
@@ -117,6 +117,12 @@
 #define WDA_MAX_RETRIES_TILL_RING_EMPTY  1000   /* MAX 10000 msec = 10 seconds wait */
 
 #define WDA_WAIT_MSEC_TILL_RING_EMPTY    10    /* 10 msec wait per cycle */
+#define WDA_IS_NULL_MAC_ADDRESS(mac_addr) \
+   ((mac_addr[0] == 0x00) && (mac_addr[1] == 0x00) && (mac_addr[2] == 0x00) &&\
+    (mac_addr[1] == 0x00) && (mac_addr[2] == 0x00) && (mac_addr[3] == 0x00))
+
+#define WDA_MAC_ADDR_ARRAY(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
+#define WDA_MAC_ADDRESS_STR "%02x:%02x:%02x:%02x:%02x:%02x"
 /* extern declarations */
 extern void vos_WDAComplete_cback(v_PVOID_t pVosContext);
 /* forward declarations */
@@ -1623,7 +1629,7 @@
                                            tSirVersionType *pVersion)
 {
    tWDA_CbContext *pWDA;
-   VOS_TRACE(VOS_MODULE_ID_WDA, VOS_TRACE_LEVEL_INFO,
+   VOS_TRACE(VOS_MODULE_ID_WDA, VOS_TRACE_LEVEL_INFO_LOW,
              "%s: Entered", __FUNCTION__);
    if ((NULL == pvosGCtx) || (NULL == pVersion))
    {
@@ -1652,7 +1658,7 @@
                                            tSirVersionType *pVersion)
 {
    tWDA_CbContext *pWDA;
-   VOS_TRACE(VOS_MODULE_ID_WDA, VOS_TRACE_LEVEL_INFO,
+   VOS_TRACE(VOS_MODULE_ID_WDA, VOS_TRACE_LEVEL_INFO_LOW,
              "%s: Entered", __FUNCTION__);
    if ((NULL == pvosGCtx) || (NULL == pVersion))
    {
@@ -2465,6 +2471,7 @@
       VOS_TRACE( VOS_MODULE_ID_WDA, VOS_TRACE_LEVEL_ERROR,
                            "%s: VOS MEM Alloc Failure", __FUNCTION__); 
       VOS_ASSERT(0);
+      vos_mem_free(joinReqParam);
       return VOS_STATUS_E_NOMEM;
    }
    pWdaParams = (tWDA_ReqParams *)vos_mem_malloc(sizeof(tWDA_ReqParams)) ;
@@ -2474,8 +2481,27 @@
                            "%s: VOS MEM Alloc Failure", __FUNCTION__); 
       VOS_ASSERT(0);
       vos_mem_free(wdiJoinReqParam);
+      vos_mem_free(joinReqParam);
       return VOS_STATUS_E_NOMEM;
    }
+
+   /*if the BSSID or self STA in pWDA is NULL, join request can't be processed*/
+   if(WDA_IS_NULL_MAC_ADDRESS(pWDA->macBSSID) || 
+      WDA_IS_NULL_MAC_ADDRESS(pWDA->macSTASelf))
+   {
+      VOS_TRACE( VOS_MODULE_ID_WDA, VOS_TRACE_LEVEL_FATAL,
+                 "%s: received join request when BSSID or self-STA is NULL "
+                 " BSSID:" WDA_MAC_ADDRESS_STR "Self-STA:" WDA_MAC_ADDRESS_STR,
+                 __FUNCTION__, WDA_MAC_ADDR_ARRAY(pWDA->macBSSID),
+                 WDA_MAC_ADDR_ARRAY(pWDA->macSTASelf)); 
+      VOS_ASSERT(0);
+      vos_mem_free(wdiJoinReqParam);
+      vos_mem_free(pWdaParams);
+      joinReqParam->status = eSIR_FAILURE ;
+      WDA_SendMsg(pWDA, WDA_SWITCH_CHANNEL_RSP, (void *)joinReqParam, 0) ;
+      return VOS_STATUS_E_INVAL;
+   }
+
    /* copy the BSSID for pWDA */
    vos_mem_copy(wdiJoinReqParam->wdiReqInfo.macBSSID, pWDA->macBSSID, 
                                              sizeof(tSirMacAddr)) ;
@@ -4540,10 +4566,30 @@
          * copy the BSSID into pWDA to use it in join request and return, 
          * No need to handle these messages.
          */
-         vos_mem_copy(pWDA->macBSSID,linkStateParams->bssid, 
+         if( !WDA_IS_NULL_MAC_ADDRESS(linkStateParams->bssid) )
+         {
+            vos_mem_copy(pWDA->macBSSID,linkStateParams->bssid, 
                                                    sizeof(tSirMacAddr));
-         vos_mem_copy(pWDA->macSTASelf,linkStateParams->selfMacAddr, 
+         }
+         else
+         {
+            VOS_TRACE( VOS_MODULE_ID_WDA, VOS_TRACE_LEVEL_FATAL,
+               "%s: BSSID in set link state is NULL ", __FUNCTION__);
+            VOS_ASSERT(0);
+         }
+
+         if( !WDA_IS_NULL_MAC_ADDRESS(linkStateParams->selfMacAddr) )
+         {
+            vos_mem_copy(pWDA->macSTASelf,linkStateParams->selfMacAddr, 
                                                    sizeof(tSirMacAddr));
+         }
+         else
+         {
+            VOS_TRACE( VOS_MODULE_ID_WDA, VOS_TRACE_LEVEL_FATAL,
+               "%s: self mac address in set link state is NULL ", __FUNCTION__);
+            VOS_ASSERT(0);
+         }
+
          /* UMAC is issuing the setlink state with PREASSOC twice (before set 
          *channel and after ) so reset the WDA state to ready when the second 
          * time UMAC issue the link state with PREASSOC 
@@ -4572,10 +4618,14 @@
             if (pWDA->wdaState == WDA_PRE_ASSOC_STATE)
             {
                pWDA->wdaState = WDA_READY_STATE;
+               /* Don't ignore the set link in this case*/
             }
-            VOS_TRACE( VOS_MODULE_ID_WDA, VOS_TRACE_LEVEL_ERROR,
+            else
+            {
+               VOS_TRACE( VOS_MODULE_ID_WDA, VOS_TRACE_LEVEL_ERROR,
                         "Set link state called when WDA is not in READY STATE " );
-            status = WDA_IGNORE_SET_LINK_STATE;
+               status = WDA_IGNORE_SET_LINK_STATE;
+            }
          }
          break;
    }