wlan: Sessionization of PMC/PMM module messages

Sessionization of  PMC/PMM module messages for:
UAPSD, WOWL, HostOffload, Set packet filter, Clear packet filter
Host changes to support SLM SESSIONIZATION

Change-Id: Ie4f5554a9fd78df7641e8c9496444d40f6eddd31
CR-Fixed: 382845, 400362, 402982, 402585
diff --git a/CORE/SME/inc/csrInternal.h b/CORE/SME/inc/csrInternal.h
index 45f50a6..5817543 100644
--- a/CORE/SME/inc/csrInternal.h
+++ b/CORE/SME/inc/csrInternal.h
@@ -574,6 +574,8 @@
     tANI_BOOLEAN addTSWhenACMIsOff;
 
     tANI_BOOLEAN fValidateList;
+    //Remove this code once SLM_Sessionization is supported 
+    //BMPS_WORKAROUND_NOT_NEEDED
     tANI_BOOLEAN doBMPSWorkaround;
 
     //To enable/disable scanning 2.4Ghz channels twice on a single scan request from HDD
@@ -1220,6 +1222,8 @@
 tANI_BOOLEAN csrRoamIsCCXAssoc(tpAniSirGlobal pMac);
 #endif
 
+//Remove this code once SLM_Sessionization is supported 
+//BMPS_WORKAROUND_NOT_NEEDED
 void csrDisconnectAllActiveSessions(tpAniSirGlobal pMac);
 
 #ifdef FEATURE_WLAN_LFR
diff --git a/CORE/SME/inc/pmcApi.h b/CORE/SME/inc/pmcApi.h
index 185cc3c..50df344 100644
--- a/CORE/SME/inc/pmcApi.h
+++ b/CORE/SME/inc/pmcApi.h
@@ -390,17 +390,15 @@
 
 
 extern eHalStatus pmcWowlAddBcastPattern (
-
    tHalHandle hHal, 
-
-   tpSirWowlAddBcastPtrn pattern);
+   tpSirWowlAddBcastPtrn pattern, 
+   tANI_U8  sessionId);
 
 
 extern eHalStatus pmcWowlDelBcastPattern (
-
    tHalHandle hHal, 
-
-   tpSirWowlDelBcastPtrn pattern);
+   tpSirWowlDelBcastPtrn pattern,
+   tANI_U8 sessionId);
 
 
 extern eHalStatus pmcEnterWowl ( 
@@ -415,13 +413,13 @@
 
     void *wakeReasonIndCBContext,
 #endif // WLAN_WAKEUP_EVENTS
-    tpSirSmeWowlEnterParams wowlEnterParams);
+    tpSirSmeWowlEnterParams wowlEnterParams, tANI_U8 sessionId);
 
 extern eHalStatus pmcExitWowl (tHalHandle hHal);
 
 
 extern eHalStatus pmcSetHostOffload (tHalHandle hHal, tpSirHostOffloadReq pRequest,
-                                          tANI_U8 *bssId);
+                                          tANI_U8 sessionId);
 
 /* ---------------------------------------------------------------------------
     \fn pmcSetKeepAlive
@@ -432,7 +430,7 @@
             eHAL_STATUS_FAILURE  Cannot set the keepalive.
             eHAL_STATUS_SUCCESS  Request accepted. 
   ---------------------------------------------------------------------------*/
-extern eHalStatus pmcSetKeepAlive (tHalHandle hHal, tpSirKeepAliveReq pRequest, tANI_U8 *bssId);
+extern eHalStatus pmcSetKeepAlive (tHalHandle hHal, tpSirKeepAliveReq pRequest, tANI_U8 sessionId);
 
 extern tANI_BOOLEAN pmcValidateConnectState( tHalHandle hHal );
 
@@ -451,7 +449,8 @@
 // Packet Coalescing Filter Match Count Callback declaration
 typedef void(*FilterMatchCountCallback)(void *callbackContext,
                                         tpSirRcvFltPktMatchRsp pRcvFltPktMatchRsp);
-extern eHalStatus pmcGetFilterMatchCount(tHalHandle hHal, FilterMatchCountCallback callbackRoutine, void *callbackContext);
+extern eHalStatus pmcGetFilterMatchCount(tHalHandle hHal, FilterMatchCountCallback callbackRoutine, 
+                                                void *callbackContext, tANI_U8 sessionId);
 #endif // WLAN_FEATURE_PACKET_FILTERING
 
 #ifdef WLAN_FEATURE_GTK_OFFLOAD
@@ -467,7 +466,7 @@
             eHAL_STATUS_FAILURE  Cannot set the offload.
             eHAL_STATUS_SUCCESS  Request accepted. 
   ---------------------------------------------------------------------------*/
-extern eHalStatus pmcSetGTKOffload (tHalHandle hHal, tpSirGtkOffloadParams pGtkOffload);
+extern eHalStatus pmcSetGTKOffload (tHalHandle hHal, tpSirGtkOffloadParams pGtkOffload, tANI_U8 sessionId);
 
 /* ---------------------------------------------------------------------------
     \fn pmcGetGTKOffload
diff --git a/CORE/SME/inc/smeInside.h b/CORE/SME/inc/smeInside.h
index 1c2b361..dbf55cb 100644
--- a/CORE/SME/inc/smeInside.h
+++ b/CORE/SME/inc/smeInside.h
@@ -186,11 +186,12 @@
     \brief  Set the host offload feature.
     \param  hHal - The handle returned by macOpen.
     \param  pRequest - Pointer to the offload request.
+    \param  sessionId .  Session index of the session
     \return eHalStatus
             eHAL_STATUS_FAILURE  Cannot set the offload.
             eHAL_STATUS_SUCCESS  Request accepted. 
   ---------------------------------------------------------------------------*/
-eHalStatus pmcSetNSOffload (tHalHandle hHal, tpSirHostOffloadReq pRequest, tANI_U8 *bssId);
+eHalStatus pmcSetNSOffload (tHalHandle hHal, tpSirHostOffloadReq pRequest, tANI_U8 sessionId);
 #endif //WLAN_NS_OFFLOAD
 
 #ifdef FEATURE_WLAN_SCAN_PNO
diff --git a/CORE/SME/inc/sme_Api.h b/CORE/SME/inc/sme_Api.h
index 9fdd4d9..de34a14 100644
--- a/CORE/SME/inc/sme_Api.h
+++ b/CORE/SME/inc/sme_Api.h
@@ -1106,7 +1106,8 @@
   ---------------------------------------------------------------------------*/
 extern eHalStatus sme_WowlAddBcastPattern (
    tHalHandle hHal, 
-   tpSirWowlAddBcastPtrn pattern);
+   tpSirWowlAddBcastPtrn pattern,
+   tANI_U8 sessionId);
 
 /* ---------------------------------------------------------------------------
     \fn sme_WowlDelBcastPattern
@@ -1119,7 +1120,8 @@
   ---------------------------------------------------------------------------*/
 extern eHalStatus sme_WowlDelBcastPattern (
    tHalHandle hHal, 
-   tpSirWowlDelBcastPtrn pattern);
+   tpSirWowlDelBcastPtrn pattern,
+   tANI_U8   sessionId);
 
 /* ---------------------------------------------------------------------------
     \fn sme_EnterWowl
@@ -1163,7 +1165,7 @@
     void (*wakeReasonIndCB) (void *callbackContext, tpSirWakeReasonInd pWakeReasonInd),
     void *wakeReasonIndCBContext,
 #endif // WLAN_WAKEUP_EVENTS
-    tpSirSmeWowlEnterParams wowlEnterParams);
+    tpSirSmeWowlEnterParams wowlEnterParams, tANI_U8 sessionId);
 
 /* ---------------------------------------------------------------------------
     \fn sme_ExitWowl
@@ -1953,7 +1955,8 @@
   ---------------------------------------------------------------------------*/
 eHalStatus sme_GetFilterMatchCount(tHalHandle hHal, 
                                    FilterMatchCountCallback callbackRoutine, 
-                                   void *callbackContext );
+                                   void *callbackContext,
+                                   tANI_U8 sessionId);
 
 /* ---------------------------------------------------------------------------
     \fn sme_ReceiveFilterClearFilter
@@ -2020,7 +2023,7 @@
     \param  pRequest -  Pointer to the GTK offload request.
     \return eHalStatus
   ---------------------------------------------------------------------------*/
-eHalStatus sme_SetGTKOffload (tHalHandle hHal, tpSirGtkOffloadParams pRequest);
+eHalStatus sme_SetGTKOffload (tHalHandle hHal, tpSirGtkOffloadParams pRequest, tANI_U8 sessionId);
 
 /* ---------------------------------------------------------------------------
     \fn sme_GetGTKOffload
@@ -2029,7 +2032,8 @@
     \param  pRequest -  Pointer to the GTK offload response.
     \return eHalStatus
   ---------------------------------------------------------------------------*/
-eHalStatus sme_GetGTKOffload (tHalHandle hHal, GTKOffloadGetInfoCallback callbackRoutine, void *callbackContext );
+eHalStatus sme_GetGTKOffload (tHalHandle hHal, GTKOffloadGetInfoCallback callbackRoutine, 
+                                    void *callbackContext, tANI_U8 sessionId);
 #endif // WLAN_FEATURE_GTK_OFFLOAD
 
 #ifdef WLAN_WAKEUP_EVENTS
diff --git a/CORE/SME/src/csr/csrApiRoam.c b/CORE/SME/src/csr/csrApiRoam.c
index 56e0e4b..d7e3907 100644
--- a/CORE/SME/src/csr/csrApiRoam.c
+++ b/CORE/SME/src/csr/csrApiRoam.c
@@ -934,6 +934,8 @@
     pMac->roam.configParam.addTSWhenACMIsOff = 0;
     pMac->roam.configParam.fScanTwice = eANI_BOOLEAN_FALSE;
 
+    //Remove this code once SLM_Sessionization is supported 
+    //BMPS_WORKAROUND_NOT_NEEDED
     pMac->roam.configParam.doBMPSWorkaround = 0;
 
 }
@@ -1275,6 +1277,8 @@
          * will automatically connect back and resume BMPS since resume BMPS is not working when moving from concurrent to
          * single session
          */
+        //Remove this code once SLM_Sessionization is supported 
+        //BMPS_WORKAROUND_NOT_NEEDED
         pMac->roam.configParam.doBMPSWorkaround = 0;
 
 #ifdef WLAN_FEATURE_11AC
@@ -4609,7 +4613,9 @@
                 if( pSession->bRefAssocStartCnt > 0 )
                 {
                     pSession->bRefAssocStartCnt--;
-                    if(!IS_SLM_SESSIONIZATION_SUPPORTED_BY_FW && ( csrIsConcurrentSessionRunning( pMac )))
+                    //Remove this code once SLM_Sessionization is supported 
+                    //BMPS_WORKAROUND_NOT_NEEDED
+                    if(!IS_FEATURE_SUPPORTED_BY_FW(SLM_SESSIONIZATION) && ( csrIsConcurrentSessionRunning( pMac )))
                     {
                        pMac->roam.configParam.doBMPSWorkaround = 1;
                     }
@@ -4819,7 +4825,9 @@
 #ifdef WLAN_SOFTAP_FEATURE
                 roamInfo.staId = (tANI_U8)pSmeStartBssRsp->staId;
 #endif
-                if(!IS_SLM_SESSIONIZATION_SUPPORTED_BY_FW &&
+                 //Remove this code once SLM_Sessionization is supported 
+                 //BMPS_WORKAROUND_NOT_NEEDED
+                if(!IS_FEATURE_SUPPORTED_BY_FW(SLM_SESSIONIZATION) &&
                    ( csrIsConcurrentSessionRunning( pMac )))
                 {
                    pMac->roam.configParam.doBMPSWorkaround = 1;
@@ -12926,8 +12934,10 @@
    /* Indicate the neighbor roal algorithm about the disconnect indication */
    csrNeighborRoamIndicateDisconnect(pMac, sessionId);
 #endif
-   
-    if(!IS_SLM_SESSIONIZATION_SUPPORTED_BY_FW && 
+
+    //Remove this code once SLM_Sessionization is supported 
+    //BMPS_WORKAROUND_NOT_NEEDED
+    if(!IS_FEATURE_SUPPORTED_BY_FW(SLM_SESSIONIZATION) && 
         csrIsInfraApStarted( pMac ) &&  
         pMac->roam.configParam.doBMPSWorkaround)
    {
diff --git a/CORE/SME/src/csr/csrUtil.c b/CORE/SME/src/csr/csrUtil.c
index 78e0472..971c24d 100644
--- a/CORE/SME/src/csr/csrUtil.c
+++ b/CORE/SME/src/csr/csrUtil.c
@@ -6269,6 +6269,9 @@
  * are some issues seen with BMPS resume during this transition and this is a workaround which will allow the Infra STA session to
  * disconnect and auto connect back and enter BMPS this giving the same effect as resuming BMPS
  */
+ 
+//Remove this code once SLM_Sessionization is supported 
+//BMPS_WORKAROUND_NOT_NEEDED
 void csrDisconnectAllActiveSessions(tpAniSirGlobal pMac)
 {
     tANI_U8 i;
diff --git a/CORE/SME/src/pmc/pmc.c b/CORE/SME/src/pmc/pmc.c
index bcc0749..ee0ae09 100644
--- a/CORE/SME/src/pmc/pmc.c
+++ b/CORE/SME/src/pmc/pmc.c
@@ -2505,7 +2505,9 @@
       return eHAL_STATUS_PMC_NOT_NOW;
    }
 
-    if(!IS_SLM_SESSIONIZATION_SUPPORTED_BY_FW)
+    //Remove this code once SLM_Sessionization is supported 
+    //BMPS_WORKAROUND_NOT_NEEDED
+    if(!IS_FEATURE_SUPPORTED_BY_FW(SLM_SESSIONIZATION))
     {
         smsLog(pMac, LOG1, FL("doBMPSWorkaround %u\n"), pMac->roam.configParam.doBMPSWorkaround);
         if (pMac->roam.configParam.doBMPSWorkaround)
diff --git a/CORE/SME/src/pmc/pmcApi.c b/CORE/SME/src/pmc/pmcApi.c
index ec5c705..40d44df 100644
--- a/CORE/SME/src/pmc/pmcApi.c
+++ b/CORE/SME/src/pmc/pmcApi.c
@@ -2093,9 +2093,11 @@
   ---------------------------------------------------------------------------*/
 eHalStatus pmcWowlAddBcastPattern (
     tHalHandle hHal, 
-    tpSirWowlAddBcastPtrn pattern)
+    tpSirWowlAddBcastPtrn pattern,
+    tANI_U8 sessionId)
 {
     tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
+    tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
 
 #ifdef FEATURE_WLAN_DIAG_SUPPORT
     vos_log_powersave_wow_add_ptrn_pkt_type *log_ptr = NULL;
@@ -2110,6 +2112,12 @@
         return eHAL_STATUS_FAILURE;
     }
 
+    if( pSession == NULL)
+    {
+        smsLog(pMac, LOGE, FL("Session not found \n"));
+        return eHAL_STATUS_FAILURE;
+    }
+
 #ifdef FEATURE_WLAN_DIAG_SUPPORT
     if( log_ptr )
     {
@@ -2141,8 +2149,15 @@
     }
     if( pMac->pmc.pmcState == IMPS || pMac->pmc.pmcState == REQUEST_IMPS )
     {
+        eHalStatus status;
+        if( !csrIsConnStateConnectedInfra (pMac, sessionId ))
+        {
+            smsLog(pMac, LOGE, FL("Ignoring the indication as we are not connected\n"));
+            return eHAL_STATUS_FAILURE;
+        }
+        vos_mem_copy(pattern->bssId, pSession->connectedProfile.bssid, sizeof(tSirMacAddr));
         //Wake up the chip first
-        eHalStatus status = pmcDeferMsg( pMac, eWNI_PMC_WOWL_ADD_BCAST_PTRN, 
+        status = pmcDeferMsg( pMac, eWNI_PMC_WOWL_ADD_BCAST_PTRN, 
                                     pattern, sizeof(tSirWowlAddBcastPtrn) );
 
         if( eHAL_STATUS_PMC_PENDING == status )
@@ -2181,9 +2196,11 @@
   ---------------------------------------------------------------------------*/
 eHalStatus pmcWowlDelBcastPattern (
     tHalHandle hHal, 
-    tpSirWowlDelBcastPtrn pattern)
+    tpSirWowlDelBcastPtrn pattern,
+    tANI_U8  sessionId)
 {
     tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
+    tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
 
 #ifdef FEATURE_WLAN_DIAG_SUPPORT    
     WLAN_VOS_DIAG_EVENT_DEF(wowRequest, vos_event_wlan_powersave_wow_payload_type);
@@ -2197,6 +2214,12 @@
 
     smsLog(pMac, LOG2, "PMC: entering pmcWowlDelBcastPattern");
 
+    if( NULL == pSession )
+    {
+        smsLog(pMac, LOGE, FL("Session not found \n"));
+        return eHAL_STATUS_FAILURE;
+    }
+
     if(pattern->ucPatternId >= SIR_WOWL_BCAST_MAX_NUM_PATTERNS )
     {
         smsLog(pMac, LOGE, FL("Pattern Id must range from 0 to %d\n"), 
@@ -2213,8 +2236,16 @@
 
     if( pMac->pmc.pmcState == IMPS || pMac->pmc.pmcState == REQUEST_IMPS )
     {
+        eHalStatus status;
+        if( !csrIsConnStateConnectedInfra (pMac, sessionId ))
+        {
+            smsLog(pMac, LOGE, FL("Ignoring the indication as we are not connected\n"));
+            return eHAL_STATUS_FAILURE;
+        }
+
+        vos_mem_copy(pattern->bssId, pSession->connectedProfile.bssid, sizeof(tSirMacAddr));
         //Wake up the chip first
-        eHalStatus status = pmcDeferMsg( pMac, eWNI_PMC_WOWL_DEL_BCAST_PTRN, 
+        status = pmcDeferMsg( pMac, eWNI_PMC_WOWL_DEL_BCAST_PTRN, 
                                     pattern, sizeof(tSirWowlDelBcastPtrn) );
 
         if( eHAL_STATUS_PMC_PENDING == status )
@@ -2285,9 +2316,10 @@
     void (*wakeReasonIndCB) (void *callbackContext, tpSirWakeReasonInd pWakeReasonInd),
     void *wakeReasonIndCBContext,
 #endif // WLAN_WAKEUP_EVENTS
-    tpSirSmeWowlEnterParams wowlEnterParams)
+    tpSirSmeWowlEnterParams wowlEnterParams, tANI_U8 sessionId)
 {
    tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
+   tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
 
 #ifdef FEATURE_WLAN_DIAG_SUPPORT    
    WLAN_VOS_DIAG_EVENT_DEF(wowRequest, vos_event_wlan_powersave_wow_payload_type);
@@ -2306,11 +2338,25 @@
    {
        wowRequest.wow_type |= 2;
    }
-
    WLAN_VOS_DIAG_EVENT_REPORT(&wowRequest, EVENT_WLAN_POWERSAVE_WOW);
 #endif
 
-   smsLog(pMac, LOG2, "PMC: entering pmcEnterWowl\n");
+   smsLog(pMac, LOG2, FL("PMC: entering pmcEnterWowl\n"));
+
+   if( NULL == pSession )
+   {
+       smsLog(pMac, LOGE, FL("Session not found \n"));
+       return eHAL_STATUS_FAILURE;
+   }
+
+   if( !csrIsConnStateConnectedInfra (pMac, sessionId ))
+   {
+       smsLog(pMac, LOGE, FL("Ignoring the indication as we are not connected\n"));
+       return eHAL_STATUS_FAILURE;
+   }
+
+   vos_mem_copy(wowlEnterParams->bssId, pSession->connectedProfile.bssid, 
+               sizeof(tSirMacAddr));
 
    if( !PMC_IS_READY(pMac) )
    {
@@ -2428,21 +2474,13 @@
             eHAL_STATUS_FAILURE  Cannot set the offload.
             eHAL_STATUS_SUCCESS  Request accepted. 
   ---------------------------------------------------------------------------*/
-eHalStatus pmcSetHostOffload (tHalHandle hHal, tpSirHostOffloadReq pRequest, tANI_U8 *bssId)
+eHalStatus pmcSetHostOffload (tHalHandle hHal, tpSirHostOffloadReq pRequest, 
+                                   tANI_U8 sessionId)
 {
     tpSirHostOffloadReq pRequestBuf;
     vos_msg_t msg;
-    tpPESession     psessionEntry;
-    tANI_U8   sessionId;
     tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
-
-    if((psessionEntry = peFindSessionByBssid( pMac, bssId,&sessionId)) == NULL )
-    {
-        VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, "%s: Unable to find"
-        "the psessionEntry for bssid : 0x%x:0x%x:0x%x:0x%x:0x%x:0x%x", 
-        __FUNCTION__,bssId[5],bssId[4],bssId[3],bssId[2],bssId[1],bssId[0]);
-        return eHAL_STATUS_FAILURE;
-    }
+    tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
 
     VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, "%s: IP address = %d.%d.%d.%d", __FUNCTION__,
         pRequest->params.hostIpv4Addr[0], pRequest->params.hostIpv4Addr[1],
@@ -2454,9 +2492,22 @@
         VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, "%s: Not able to allocate memory for host offload request", __FUNCTION__);
         return eHAL_STATUS_FAILED_ALLOC;
     }
-    vos_mem_copy(pRequestBuf, pRequest, sizeof(tSirHostOffloadReq));
 
-    pRequestBuf->bssIdx = psessionEntry->bssIdx;
+    if(NULL == pSession )
+    {
+        VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, "%s: SESSION not Found\n", __FUNCTION__);
+        return eHAL_STATUS_FAILURE;
+    }
+
+    if( !csrIsConnStateConnectedInfra (pMac, sessionId ))
+    {
+        smsLog(pMac, LOGE, FL("Ignoring the indication as we are not connected\n"));
+        return eHAL_STATUS_FAILURE;
+    }
+
+    vos_mem_copy(pRequest->bssId, pSession->connectedProfile.bssid, sizeof(tSirMacAddr));
+
+    vos_mem_copy(pRequestBuf, pRequest, sizeof(tSirHostOffloadReq));
 
     msg.type = WDA_SET_HOST_OFFLOAD;
     msg.reserved = 0;
@@ -2480,20 +2531,12 @@
             eHAL_STATUS_FAILURE  Cannot set the keepalive.
             eHAL_STATUS_SUCCESS  Request accepted. 
   ---------------------------------------------------------------------------*/
-eHalStatus pmcSetKeepAlive (tHalHandle hHal, tpSirKeepAliveReq pRequest, tANI_U8 *bssId)
+eHalStatus pmcSetKeepAlive (tHalHandle hHal, tpSirKeepAliveReq pRequest, tANI_U8 sessionId)
 {
     tpSirKeepAliveReq pRequestBuf;
     vos_msg_t msg;
-    tpPESession     psessionEntry;
-    tANI_U8   sessionId;
     tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
-    if((psessionEntry = peFindSessionByBssid( pMac, bssId,&sessionId)) == NULL )
-    {
-        VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, "%s: Unable to find"
-        "the psessionEntry for bssid : 0x%x:0x%x:0x%x:0x%x:0x%x:0x%x", 
-        __FUNCTION__,bssId[5],bssId[4],bssId[3],bssId[2],bssId[1],bssId[0]);
-        return eHAL_STATUS_FAILURE;
-    }
+    tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
 
     VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO_LOW, "%s: "
                   "WDA_SET_KEEP_ALIVE message", __FUNCTION__);
@@ -2506,9 +2549,23 @@
                   __FUNCTION__);
         return eHAL_STATUS_FAILED_ALLOC;
     }
-    vos_mem_copy(pRequestBuf, pRequest, sizeof(tSirKeepAliveReq));
+    if(pSession == NULL )
+    {
+        VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, "%s: "
+           " Session not Found", __FUNCTION__);
+        vos_mem_free(pRequestBuf);
+        return eHAL_STATUS_FAILURE;
+    }
 
-    pRequestBuf->bssIdx = psessionEntry->bssIdx;
+    if( !csrIsConnStateConnectedInfra (pMac, sessionId ))
+    {
+        smsLog(pMac, LOGE, FL("Ignoring the indication as we are not connected\n"));
+        vos_mem_free(pRequestBuf);
+        return eHAL_STATUS_FAILURE;
+    }
+
+    vos_mem_copy(pRequest->bssId, pSession->connectedProfile.bssid, sizeof(tSirMacAddr));
+    vos_mem_copy(pRequestBuf, pRequest, sizeof(tSirKeepAliveReq));
 
     VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO_LOW, "buff TP %d "
               "input TP %d ", pRequestBuf->timePeriod, pRequest->timePeriod);
@@ -2540,22 +2597,29 @@
             eHAL_STATUS_FAILURE  Cannot set the offload.
             eHAL_STATUS_SUCCESS  Request accepted. 
   ---------------------------------------------------------------------------*/
-eHalStatus pmcSetNSOffload (tHalHandle hHal, tpSirHostOffloadReq pRequest, tANI_U8 *bssId)
+eHalStatus pmcSetNSOffload (tHalHandle hHal, tpSirHostOffloadReq pRequest, 
+                                 tANI_U8 sessionId)
 {
+    tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
     tpSirHostOffloadReq pRequestBuf;
     vos_msg_t msg;
     int i;
-    tpPESession     psessionEntry;
-    tANI_U8   sessionId;
-    tpAniSirGlobal pMac = PMAC_STRUCT(hHal);
-    if((psessionEntry = peFindSessionByBssid( pMac, bssId,&sessionId)) == NULL )
+    tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
+
+    if( NULL == pSession )
     {
-        VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, "%s: Unable to find"
-        "the psessionEntry for bssid : 0x%x:0x%x:0x%x:0x%x:0x%x:0x%x", 
-        __FUNCTION__,bssId[5],bssId[4],bssId[3],bssId[2],bssId[1],bssId[0]);
+        smsLog(pMac, LOGE, FL("Session not found \n"));
         return eHAL_STATUS_FAILURE;
     }
 
+    if( !csrIsConnStateConnectedInfra (pMac, sessionId ))
+    {
+        smsLog(pMac, LOGE, FL("Ignoring the indication as we are not connected\n"));
+        return eHAL_STATUS_FAILURE;
+    }
+    vos_mem_copy(pRequest->bssId, pSession->connectedProfile.bssid, 
+                sizeof(tSirMacAddr));
+
     pRequestBuf = vos_mem_malloc(sizeof(tSirHostOffloadReq));
     if (NULL == pRequestBuf)
     {
@@ -2564,8 +2628,6 @@
     }
     vos_mem_copy(pRequestBuf, pRequest, sizeof(tSirHostOffloadReq));
 
-    pRequestBuf->bssIdx = psessionEntry->bssIdx;
-
     msg.type = WDA_SET_NS_OFFLOAD;
     msg.reserved = 0;
     msg.bodyptr = pRequestBuf;
@@ -3015,12 +3077,14 @@
 (
     tHalHandle hHal, 
     FilterMatchCountCallback callbackRoutine, 
-    void *callbackContext
+    void *callbackContext,
+    tANI_U8  sessionId
 )
 {
     tpSirRcvFltPktMatchRsp  pRequestBuf;
     vos_msg_t               msg;
     tpAniSirGlobal          pMac = PMAC_STRUCT(hHal);
+    tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
 
     VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, 
         "%s: filterId = %d", __FUNCTION__);
@@ -3033,6 +3097,20 @@
                   "memory for Get PC Filter Match Count request", __FUNCTION__);
         return eHAL_STATUS_FAILED_ALLOC;
     }
+    if(NULL == pSession )
+    {
+        VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, 
+                  "%s: Session not found ", __FUNCTION__);
+        return eHAL_STATUS_FAILURE;
+    }
+
+    if( !csrIsConnStateConnectedInfra (pMac, sessionId ))
+    {
+        smsLog(pMac, LOGE, FL("Ignoring the indication as we are not connected\n"));
+        return eHAL_STATUS_FAILURE;
+    }
+
+    vos_mem_copy(pRequestBuf->bssId, pSession->connectedProfile.bssid, sizeof(tSirMacAddr)); 
 
     msg.type = WDA_PACKET_COALESCING_FILTER_MATCH_COUNT_REQ;
     msg.reserved = 0;
@@ -3073,11 +3151,14 @@
             eHAL_STATUS_FAILURE  Cannot set the offload.
             eHAL_STATUS_SUCCESS  Request accepted. 
   ---------------------------------------------------------------------------*/
-eHalStatus pmcSetGTKOffload (tHalHandle hHal, tpSirGtkOffloadParams pGtkOffload)
+eHalStatus pmcSetGTKOffload (tHalHandle hHal, tpSirGtkOffloadParams pGtkOffload, 
+                                  tANI_U8 sessionId)
 {
     tpSirGtkOffloadParams pRequestBuf;
     vos_msg_t msg;
     int i;
+    tpAniSirGlobal   pMac = PMAC_STRUCT(hHal);
+    tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
 
     VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: KeyReplayCounter: %d", 
                 __FUNCTION__, pGtkOffload->ullKeyReplayCounter);
@@ -3089,9 +3170,23 @@
                   "memory for GTK offload request", __FUNCTION__);
         return eHAL_STATUS_FAILED_ALLOC;
     }
+    if(NULL == pSession )
+    {
+        VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, 
+                  "%s: Session not found ", __FUNCTION__);
+        return eHAL_STATUS_FAILURE;
+    }
+
+    if( !csrIsConnStateConnectedInfra (pMac, sessionId ))
+    {
+        smsLog(pMac, LOGE, FL("Ignoring the indication as we are not connected\n"));
+        return eHAL_STATUS_FAILURE;
+    }
+
+    vos_mem_copy(pGtkOffload->bssId, pSession->connectedProfile.bssid, sizeof(tSirMacAddr)); 
 
     vos_mem_copy(pRequestBuf, pGtkOffload, sizeof(tSirGtkOffloadParams));
-        
+
     msg.type = WDA_GTK_OFFLOAD_REQ;
     msg.reserved = 0;
     msg.bodyptr = pRequestBuf;
@@ -3115,11 +3210,13 @@
             eHAL_STATUS_FAILURE  Cannot set the offload.
             eHAL_STATUS_SUCCESS  Request accepted. 
   ---------------------------------------------------------------------------*/
-eHalStatus pmcGetGTKOffload(tHalHandle hHal, GTKOffloadGetInfoCallback callbackRoutine, void *callbackContext)
+eHalStatus pmcGetGTKOffload(tHalHandle hHal, GTKOffloadGetInfoCallback callbackRoutine, 
+                                  void *callbackContext, tANI_U8 sessionId)
 {
     tpSirGtkOffloadGetInfoRspParams  pRequestBuf;
     vos_msg_t               msg;
     tpAniSirGlobal          pMac = PMAC_STRUCT(hHal);
+    tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
 
     VOS_TRACE( VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_INFO, "%s: filterId = %d", 
                 __FUNCTION__);
@@ -3132,6 +3229,20 @@
         return eHAL_STATUS_FAILED_ALLOC;
     }
 
+    if(NULL == pSession )
+    {
+        VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, 
+                  "%s: Session not found ", __FUNCTION__);
+        return eHAL_STATUS_FAILURE;
+    }
+
+    if( !csrIsConnStateConnectedInfra (pMac, sessionId ))
+    {
+        smsLog(pMac, LOGE, FL("Ignoring the indication as we are not connected\n"));
+        return eHAL_STATUS_FAILURE;
+    }
+    vos_mem_copy(pRequestBuf->bssId, pSession->connectedProfile.bssid, sizeof(tSirMacAddr)); 
+
     msg.type = WDA_GTK_OFFLOAD_GETINFO_REQ;
     msg.reserved = 0;
     msg.bodyptr = pRequestBuf;
diff --git a/CORE/SME/src/pmc/pmcLogDump.c b/CORE/SME/src/pmc/pmcLogDump.c
index bb8a077..1aacbb6 100644
--- a/CORE/SME/src/pmc/pmcLogDump.c
+++ b/CORE/SME/src/pmc/pmcLogDump.c
@@ -212,8 +212,10 @@
     tSirSmeWowlEnterParams wowlEnterParams;
     tSirRetStatus status;
     tANI_U32 length;
-    (void) arg3; (void) arg4;
-    
+    tANI_U8  sessionId = 0;
+
+    (void) arg4;
+
     palZeroMemory(pMac->hHdd, &wowlEnterParams, sizeof(tSirSmeWowlEnterParams));
 
     if (arg1 == 0 && arg2 == 0)
@@ -243,12 +245,20 @@
       wowlEnterParams.ucPatternFilteringEnable = 1;
     }
 
+    if(arg3 == CSR_ROAM_SESSION_MAX )
+    {
+        smsLog(pMac, LOGE, "Enter valid sessionId\n");
+        return p;
+    }
     pMac->pmc.bmpsEnabled = TRUE;
     pMac->pmc.wowlEnabled = TRUE;
+
+    sessionId = (tANI_U8 ) arg3;
 #ifdef WLAN_WAKEUP_EVENTS
-    (void)sme_EnterWowl(pMac, dump_pmc_callbackRoutine, pMac, dump_pmc_callbackRoutine2, pMac, &wowlEnterParams);
+    (void)sme_EnterWowl(pMac, dump_pmc_callbackRoutine, pMac, dump_pmc_callbackRoutine2, pMac, 
+                        &wowlEnterParams, sessionId);
 #else // WLAN_WAKEUP_EVENTS
-    (void)sme_EnterWowl(pMac, dump_pmc_callbackRoutine, pMac, &wowlEnterParams);
+    (void)sme_EnterWowl(pMac, dump_pmc_callbackRoutine, pMac, &wowlEnterParams, sessionId);
 #endif // WLAN_WAKEUP_EVENTS
     return p;
 }
@@ -265,11 +275,12 @@
 dump_pmc_remove_ptrn( tpAniSirGlobal pMac, tANI_U32 arg1, tANI_U32 arg2, tANI_U32 arg3, tANI_U32 arg4, char *p)
 {
     tSirWowlDelBcastPtrn delPattern;
-    (void) arg2; (void) arg3; (void) arg4;
-
+    tANI_U8  sessionId = 0;
+    (void) arg3; (void) arg4;
+ 
     palZeroMemory(pMac->hHdd, &delPattern, sizeof(tSirWowlDelBcastPtrn));
 
-    if(arg1 <= 7)
+    if((arg1 <= 7) || (arg2 == CSR_ROAM_SESSION_MAX))
     {
         delPattern.ucPatternId = (tANI_U8)arg1;
     }
@@ -279,7 +290,8 @@
         return p;
     }
 
-    (void)pmcWowlDelBcastPattern(pMac, &delPattern);
+    sessionId = (tANI_U8 ) arg2;
+    (void)pmcWowlDelBcastPattern(pMac, &delPattern, sessionId);
     return p;
 }
 
@@ -313,28 +325,37 @@
     tSirWowlAddBcastPtrn addPattern;
     tSirWowlDelBcastPtrn delPattern;
     tSirSmeWowlEnterParams wowlEnterParams;
+    tANI_U8            sessionId = 0;
 
     smeRsp.statusCode = eSIR_SME_SUCCESS;
     palZeroMemory(pMac->hHdd, &addPattern, sizeof(tSirWowlAddBcastPtrn));
     palZeroMemory(pMac->hHdd, &delPattern, sizeof(tSirWowlDelBcastPtrn));
     palZeroMemory(pMac->hHdd, &wowlEnterParams, sizeof(tSirSmeWowlEnterParams));
 
-    (void) arg1; (void) arg2; (void) arg3; (void) arg4;
+    (void) arg2; (void) arg3; (void) arg4;
 
+    if(arg1 == CSR_ROAM_SESSION_MAX)
+    {
+        smsLog(pMac, LOGE, "dump_pmc_test_Wowl: Invalid sessionId\n");
+        return p;
+    }
+
+    sessionId = (tANI_U8 ) arg1;
     //Add pattern
-    sme_WowlAddBcastPattern(pMac, &addPattern);
+    sme_WowlAddBcastPattern(pMac, &addPattern, sessionId);
 
     //Delete pattern
-    sme_WowlDelBcastPattern(pMac, &delPattern);
+    sme_WowlDelBcastPattern(pMac, &delPattern, sessionId);
 
     //Force the device into BMPS
     pMac->pmc.pmcState = BMPS;
 
     //Enter Wowl
 #ifdef WLAN_WAKEUP_EVENTS
-    sme_EnterWowl(pMac, dump_pmc_callbackRoutine, pMac, dump_pmc_callbackRoutine2, pMac, &wowlEnterParams);
+    sme_EnterWowl(pMac, dump_pmc_callbackRoutine, pMac, dump_pmc_callbackRoutine2, pMac, 
+                   &wowlEnterParams, sessionId);
 #else // WLAN_WAKEUP_EVENTS
-    sme_EnterWowl(pMac, dump_pmc_callbackRoutine, pMac, &wowlEnterParams);
+    sme_EnterWowl(pMac, dump_pmc_callbackRoutine, pMac, &wowlEnterParams, sessionId);
 #endif // WLAN_WAKEUP_EVENTS
     smeRsp.messageType = eWNI_PMC_ENTER_WOWL_RSP;
     pmcMessageProcessor(pMac, &smeRsp);
@@ -369,11 +390,11 @@
     {912,   "PMC: Request Full Power",  dump_pmc_request_full_power},
     //Unit Test Related
     {913,   "PMC: Test UAPSD",          dump_pmc_test_uapsd},
-    {914,   "PMC: Test WOWL",           dump_pmc_test_Wowl},
+    {914,   "PMC: Test WOWL : Syntax :dump 914 <sessionId>",           dump_pmc_test_Wowl},
     // WoWL Related
-    {915,   "PMC: Enter WoWL: Syntax: dump 915 <enable_magic_pkt> <enable_ptrn_match>",  dump_pmc_enter_wowl},
+    {915,   "PMC: Enter WoWL: Syntax: dump 915 <enable_magic_pkt> <enable_ptrn_match> <sessionId>",  dump_pmc_enter_wowl},
     {916,   "PMC: Exit WoWL",  dump_pmc_exit_wowl},
-    {917,   "PMC: Remove a pattern: Syntax: dump 917 <pattern_id(0-7)>",  dump_pmc_remove_ptrn},
+    {917,   "PMC: Remove a pattern: Syntax: dump 917 <pattern_id(0-7) <sessionId>>",  dump_pmc_remove_ptrn},
     {918,   "PMC: Enable BMPS",         dump_pmc_enable_bmps},
     {919,   "PMC: Disable BMPS",        dump_pmc_disable_bmps}
 };
diff --git a/CORE/SME/src/sme_common/sme_Api.c b/CORE/SME/src/sme_common/sme_Api.c
index 4db224c..9d67f9e 100644
--- a/CORE/SME/src/sme_common/sme_Api.c
+++ b/CORE/SME/src/sme_common/sme_Api.c
@@ -3409,14 +3409,15 @@
   ---------------------------------------------------------------------------*/
 eHalStatus sme_WowlAddBcastPattern (
    tHalHandle hHal,
-   tpSirWowlAddBcastPtrn pattern)
+   tpSirWowlAddBcastPtrn pattern,
+   tANI_U8    sessionId)
 {
     eHalStatus status = eHAL_STATUS_FAILURE;
     tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
     status = sme_AcquireGlobalLock( &pMac->sme );
     if ( HAL_STATUS_SUCCESS( status ) )
     {
-       status = pmcWowlAddBcastPattern (hHal, pattern);
+       status = pmcWowlAddBcastPattern (hHal, pattern, sessionId);
        sme_ReleaseGlobalLock( &pMac->sme );
     }
 
@@ -3434,14 +3435,15 @@
   ---------------------------------------------------------------------------*/
 eHalStatus sme_WowlDelBcastPattern (
    tHalHandle hHal,
-   tpSirWowlDelBcastPtrn pattern)
+   tpSirWowlDelBcastPtrn pattern,
+   tANI_U8  sessionId)
 {
     eHalStatus status = eHAL_STATUS_FAILURE;
     tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
     status = sme_AcquireGlobalLock( &pMac->sme );
     if ( HAL_STATUS_SUCCESS( status ) )
     {
-       status = pmcWowlDelBcastPattern (hHal, pattern);
+       status = pmcWowlDelBcastPattern (hHal, pattern, sessionId);
        sme_ReleaseGlobalLock( &pMac->sme );
     }
 
@@ -3486,7 +3488,7 @@
     void (*wakeIndicationCB) (void *callbackContext, tpSirWakeReasonInd pWakeReasonInd),
     void *wakeIndicationCBContext,
 #endif // WLAN_WAKEUP_EVENTS
-    tpSirSmeWowlEnterParams wowlEnterParams)
+    tpSirSmeWowlEnterParams wowlEnterParams, tANI_U8 sessionId)
 {
     eHalStatus status = eHAL_STATUS_FAILURE;
     tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
@@ -3497,10 +3499,9 @@
 #ifdef WLAN_WAKEUP_EVENTS
                               wakeIndicationCB, wakeIndicationCBContext, 
 #endif // WLAN_WAKEUP_EVENTS
-                              wowlEnterParams);
+                              wowlEnterParams, sessionId);
        sme_ReleaseGlobalLock( &pMac->sme );
     }
-
     return (status);
 }
 /* ---------------------------------------------------------------------------
@@ -5046,26 +5047,18 @@
 {
     tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
     eHalStatus status = eHAL_STATUS_FAILURE;
-    tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
-
-    if(pSession == NULL )
-    {
-        VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, "%s: "
-           "Unable to find the csrSession", __FUNCTION__);
-        return status;
-    }
 
     if ( eHAL_STATUS_SUCCESS == ( status = sme_AcquireGlobalLock( &pMac->sme ) ) )
     {
 #ifdef WLAN_NS_OFFLOAD
         if(SIR_IPV6_NS_OFFLOAD == pRequest->offloadType)
         {
-            status = pmcSetNSOffload( hHal, pRequest ,pSession->connectedProfile.bssid);
+            status = pmcSetNSOffload( hHal, pRequest, sessionId);
         }
         else
 #endif //WLAN_NS_OFFLOAD
         {
-            status = pmcSetHostOffload (hHal, pRequest, pSession->connectedProfile.bssid);
+            status = pmcSetHostOffload (hHal, pRequest, sessionId);
         }
         sme_ReleaseGlobalLock( &pMac->sme );
     }
@@ -5081,14 +5074,15 @@
     \param  pRequest -  Pointer to the GTK offload request.
     \return eHalStatus
   ---------------------------------------------------------------------------*/
-eHalStatus sme_SetGTKOffload (tHalHandle hHal, tpSirGtkOffloadParams pRequest)
+eHalStatus sme_SetGTKOffload (tHalHandle hHal, tpSirGtkOffloadParams pRequest, 
+                                    tANI_U8 sessionId)
 {
     tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
     eHalStatus status;
 
     if ( eHAL_STATUS_SUCCESS == ( status = sme_AcquireGlobalLock( &pMac->sme ) ) )
     {
-        status = pmcSetGTKOffload( hHal, pRequest );
+        status = pmcSetGTKOffload( hHal, pRequest, sessionId );
         sme_ReleaseGlobalLock( &pMac->sme );
     }
 
@@ -5102,14 +5096,15 @@
     \param  pRequest -  Pointer to the GTK offload response.
     \return eHalStatus
   ---------------------------------------------------------------------------*/
-eHalStatus sme_GetGTKOffload (tHalHandle hHal, GTKOffloadGetInfoCallback callbackRoutine, void *callbackContext )
+eHalStatus sme_GetGTKOffload (tHalHandle hHal, GTKOffloadGetInfoCallback callbackRoutine, 
+                                    void *callbackContext, tANI_U8 sessionId )
 {
     tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
     eHalStatus status;
 
     if ( eHAL_STATUS_SUCCESS == ( status = sme_AcquireGlobalLock( &pMac->sme ) ) )
     {
-        pmcGetGTKOffload(hHal, callbackRoutine, callbackContext);
+        pmcGetGTKOffload(hHal, callbackRoutine, callbackContext, sessionId);
         sme_ReleaseGlobalLock( &pMac->sme );
     }
 
@@ -5129,21 +5124,9 @@
 {
     tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
     eHalStatus status;
-    tCsrRoamSession *pSession = CSR_GET_SESSION( pMac, sessionId );
-
-    VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, "%s: "
-           "setting Keep alive in SME TP %d", __FUNCTION__,pRequest->timePeriod);
-
-    if(pSession == NULL )
-    {
-		VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, "%s: "
-           " Session not Found", __FUNCTION__);
-        return eHAL_STATUS_FAILURE;
-    }
-
     if ( eHAL_STATUS_SUCCESS == ( status = sme_AcquireGlobalLock( &pMac->sme ) ) )
     {
-        status = pmcSetKeepAlive (hHal, pRequest, pSession->connectedProfile.bssid);
+        status = pmcSetKeepAlive (hHal, pRequest, sessionId);
         sme_ReleaseGlobalLock( &pMac->sme );
     }
 
@@ -6059,6 +6042,14 @@
             "allocate memory for 8023 Multicast List request", __FUNCTION__);
         return eHAL_STATUS_FAILED_ALLOC;
     }
+    
+    if( !csrIsConnStateConnectedInfra (pMac, sessionId ))
+    {
+        VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, "%s: Ignoring the "
+                       "indication as we are not connected", __FUNCTION__);
+        vos_mem_free(pRequestBuf);
+        return eHAL_STATUS_FAILURE;
+    }
     vos_mem_copy(pRequestBuf, pMulticastAddrs, sizeof(tSirRcvFltMcAddrList));
 
     vos_mem_copy(pRequestBuf->selfMacAddr, pSession->selfMacAddr, sizeof(tSirMacAddr));
@@ -6097,18 +6088,35 @@
                       ((pRcvPktFilterCfg->numFieldParams - 1) * 
                       sizeof(tSirRcvPktFilterFieldParams));
     pRequestBuf = vos_mem_malloc(allocSize);
-    if ((NULL == pRequestBuf) || (NULL == pSession))
+
+    if (NULL == pRequestBuf)
     {
         VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, "%s: Not able to "
             "allocate memory for Receive Filter Set Filter request", __FUNCTION__);
         return eHAL_STATUS_FAILED_ALLOC;
     }
-    vos_mem_copy(pRequestBuf, pRcvPktFilterCfg, allocSize);
 
-    vos_mem_copy( pRequestBuf->selfMacAddr, pSession->selfMacAddr, sizeof(tSirMacAddr));
-    vos_mem_copy( pRequestBuf->bssId, pSession->connectedProfile.bssid, 
+    if( NULL == pSession )
+    {
+        VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, "%s: Session Not found ", __FUNCTION__);
+        vos_mem_free(pRequestBuf);
+        return eHAL_STATUS_FAILURE;
+    }
+
+    if( !csrIsConnStateConnectedInfra (pMac, sessionId ))
+    {
+        VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, "%s: Ignoring the "
+                       "indication as we are not connected", __FUNCTION__);
+        vos_mem_free(pRequestBuf);
+        return eHAL_STATUS_FAILURE;
+    }
+    
+    vos_mem_copy( pRcvPktFilterCfg->selfMacAddr, pSession->selfMacAddr, sizeof(tSirMacAddr));
+    vos_mem_copy( pRcvPktFilterCfg->bssId, pSession->connectedProfile.bssid, 
                           sizeof(tSirMacAddr));
 
+    vos_mem_copy(pRequestBuf, pRcvPktFilterCfg, allocSize);
+
     msg.type = WDA_RECEIVE_FILTER_SET_FILTER_REQ;
     msg.reserved = 0;
     msg.bodyptr = pRequestBuf;
@@ -6167,7 +6175,8 @@
 
 eHalStatus sme_GetFilterMatchCount(tHalHandle hHal, 
                                    FilterMatchCountCallback callbackRoutine,
-                                   void *callbackContext )
+                                   void *callbackContext, 
+                                   tANI_U8 sessionId)
 {
     tpAniSirGlobal pMac = PMAC_STRUCT( hHal );
     eHalStatus status;
@@ -6176,7 +6185,7 @@
 
     if ( eHAL_STATUS_SUCCESS == ( status = sme_AcquireGlobalLock( &pMac->sme)))
     {
-        pmcGetFilterMatchCount(hHal, callbackRoutine, callbackContext);
+        pmcGetFilterMatchCount(hHal, callbackRoutine, callbackContext, sessionId);
         sme_ReleaseGlobalLock( &pMac->sme );
     }
 
@@ -6197,19 +6206,35 @@
                pRcvFltPktClearParam->filterId);
   
     pRequestBuf = vos_mem_malloc(sizeof(tSirRcvFltPktClearParam));
-    if ((NULL == pRequestBuf) || (NULL == pSession))
+    if (NULL == pRequestBuf)
     {
         VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
             "%s: Not able to allocate memory for Receive Filter "
             "Clear Filter request", __FUNCTION__);
         return eHAL_STATUS_FAILED_ALLOC;
     }
-    vos_mem_copy(pRequestBuf, pRcvFltPktClearParam, sizeof(tSirRcvFltPktClearParam));
+    if( NULL == pSession )
+    {
+        VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR,
+            "%s: Session Not find ", __FUNCTION__);
+        vos_mem_free(pRequestBuf);
+        return eHAL_STATUS_FAILURE;
+    }
 
-    vos_mem_copy( pRequestBuf->selfMacAddr, pSession->selfMacAddr, sizeof(tSirMacAddr));
-    vos_mem_copy( pRequestBuf->bssId, pSession->connectedProfile.bssid, 
+    if( !csrIsConnStateConnectedInfra (pMac, sessionId ))
+    {
+        VOS_TRACE(VOS_MODULE_ID_SME, VOS_TRACE_LEVEL_ERROR, "%s: Ignoring the "
+                       "indication as we are not connected", __FUNCTION__);
+        vos_mem_free(pRequestBuf);
+        return eHAL_STATUS_FAILURE;
+    }
+
+    vos_mem_copy( pRcvFltPktClearParam->selfMacAddr, pSession->selfMacAddr, sizeof(tSirMacAddr));
+    vos_mem_copy( pRcvFltPktClearParam->bssId, pSession->connectedProfile.bssid, 
                           sizeof(tSirMacAddr));
 
+    vos_mem_copy(pRequestBuf, pRcvFltPktClearParam, sizeof(tSirRcvFltPktClearParam));
+
     msg.type = WDA_RECEIVE_FILTER_CLEAR_FILTER_REQ;
     msg.reserved = 0;
     msg.bodyptr = pRequestBuf;