qcacld-3.0: Update the scan result only upon finding an active session

Invalidate the scan entry if there is no active session and
do not inform it to the user space.

Change-Id: I134cceef0cfc54f68966d3287d92bdf6b35e33fc
CRs-Fixed: 1114216
diff --git a/core/sme/src/csr/csr_api_scan.c b/core/sme/src/csr/csr_api_scan.c
index 882be59..8c28622 100644
--- a/core/sme/src/csr/csr_api_scan.c
+++ b/core/sme/src/csr/csr_api_scan.c
@@ -53,6 +53,7 @@
 #include "cds_concurrency.h"
 #include "wlan_hdd_main.h"
 #include "pld_common.h"
+#include "csr_internal.h"
 
 #define MIN_CHN_TIME_TO_FIND_GO 100
 #define MAX_CHN_TIME_TO_FIND_GO 100
@@ -4635,6 +4636,25 @@
 	return fRet;
 }
 
+/**
+ * csr_scan_get_session_id() - Get session id
+ * @mac_ctx: Pointer to global mac
+ *
+ * This function returns a valid session id
+ *
+ * Return: session id
+ */
+static uint8_t csr_scan_get_session_id(tpAniSirGlobal mac_ctx)
+{
+	uint8_t i;
+
+	for (i = 0; i < CSR_ROAM_SESSION_MAX; i++)
+		if (CSR_IS_SESSION_VALID(mac_ctx, i))
+			return i;
+
+	return CSR_SESSION_ID_INVALID;
+}
+
 /* csr_scan_process_single_bssdescr() - Add a bssdescriptor to scan table
  *
  * @mac_ctx - MAC context
@@ -4662,6 +4682,7 @@
 	uint8_t cnt_channels = 0;
 	uint32_t len = sizeof(mac_ctx->roam.validChannelList);
 	tCsrRoamInfo *roam_info;
+	uint8_t session_id;
 
 	sms_log(mac_ctx, LOG4, "CSR: Processing single bssdescr");
 	if (QDF_IS_STATUS_SUCCESS(
@@ -4684,9 +4705,16 @@
 			qdf_mem_zero(roam_info, sizeof(*roam_info));
 			roam_info->pBssDesc = bssdescr;
 
-			csr_roam_call_callback(mac_ctx, 0, roam_info, 0,
-				eCSR_ROAM_UPDATE_SCAN_RESULT,
-				eCSR_ROAM_RESULT_NONE);
+			session_id = csr_scan_get_session_id(mac_ctx);
+			if (session_id == CSR_SESSION_ID_INVALID) {
+				if (ies != NULL)
+					qdf_mem_free(ies);
+				qdf_mem_free(roam_info);
+				return QDF_STATUS_E_INVAL;
+			}
+			csr_roam_call_callback(mac_ctx, session_id, roam_info,
+					       0, eCSR_ROAM_UPDATE_SCAN_RESULT,
+					       eCSR_ROAM_RESULT_NONE);
 			qdf_mem_free(roam_info);
 		} else {
 			sms_log(mac_ctx, LOG1, "qdf_mem_malloc failed");