qcacld-3.0: Avoid beacon parsing on channels not in scan list for ACS

When STA is already up on some 2.4Ghz channel and SAP needs to be started
on some 5Ghz channel through ACS, scan channel list contains only 5Ghz
channels. But scan results contains beacons on STA 2.4Ghz channel as well
which is getting parsed contributing to bsscount and rssi on that 2.4Ghz
channel which should not be the scenario as bsscount should be 0 and rssi
should be -100 on this 2.4Ghz channel as it is not present in the scan
channel list sent by HOST to fw.

Give max weight to those channles in the sap_compute_weight
but take the effect of those channels on the channels
present in the ACS scan list.

Change-Id: I51d14aa1bb9b280c6c4d9d0085de86cc7339a4f5
CRs-Fixed: 2290744
diff --git a/core/sap/src/sap_ch_select.c b/core/sap/src/sap_ch_select.c
index 8e650c4..16f780d 100644
--- a/core/sap/src/sap_ch_select.c
+++ b/core/sap/src/sap_ch_select.c
@@ -1530,15 +1530,14 @@
 	int8_t rssi = 0;
 	uint8_t chn_num = 0;
 	uint8_t channel_id = 0;
-	uint8_t i;
-	bool found = false;
-
 	tCsrScanResultInfo *pScanResult;
 	tSapSpectChInfo *pSpectCh = pSpectInfoParams->pSpectCh;
 	uint32_t operatingBand;
 	uint16_t channelWidth;
 	uint16_t secondaryChannelOffset;
 	uint16_t centerFreq;
+	uint8_t i;
+	bool found;
 	uint16_t centerFreq_2 = 0;
 	uint16_t vhtSupport;
 	uint32_t ieLen = 0;
@@ -1605,22 +1604,6 @@
 				channel_id =
 				      pScanResult->BssDescriptor.channelId;
 
-			/*
-			 * Check if channel is present in scan channel list or
-			 * not. If not present, then continue as no need to
-			 * process the beacon on this channel.
-			 */
-			for (i = 0; i < sap_ctx->num_of_channel; i++) {
-				if (channel_id ==
-				    sap_ctx->channelList[i]) {
-					found = true;
-					break;
-				}
-			}
-
-			if (!found)
-				continue;
-
 			if (pSpectCh && (channel_id == pSpectCh->chNum)) {
 				if (pSpectCh->rssiAgr <
 				    pScanResult->BssDescriptor.rssi)
@@ -1714,12 +1697,38 @@
 		if (pSpectCh->weight == SAP_ACS_WEIGHT_MAX)
 			goto debug_info;
 
-		pSpectCh->weight =
-			SAPDFS_NORMALISE_1000 *
-			(sapweight_rssi_count(sap_ctx, rssi,
-			 pSpectCh->bssCount) + sap_weight_channel_status(
-			 sap_ctx, sap_get_channel_status(pMac,
+		/* There may be channels in scanlist, which were not sent to
+		 * FW for scanning as part of ACS scan list, but they do have an
+		 * effect on the neighbouring channels, so they help to find a
+		 * suitable channel, but there weight should be max as they were
+		 * and not meant to be included in the ACS scan results.
+		 * So just assign RSSI as -100, bsscount as 0, and weight as max
+		 * to them, so that they always stay low in sorting of best
+		 * channles which were included in ACS scan list
+		 */
+		found = false;
+		for (i = 0; i < sap_ctx->num_of_channel; i++) {
+			if (pSpectCh->chNum == sap_ctx->channelList[i]) {
+			/* Scan channel was included in ACS scan list */
+				found = true;
+				break;
+			}
+		}
+
+		if (found)
+			pSpectCh->weight =
+				SAPDFS_NORMALISE_1000 *
+				(sapweight_rssi_count(sap_ctx, rssi,
+				pSpectCh->bssCount) + sap_weight_channel_status(
+				sap_ctx, sap_get_channel_status(pMac,
 							 pSpectCh->chNum)));
+		else {
+			pSpectCh->weight = SAP_ACS_WEIGHT_MAX;
+			pSpectCh->rssiAgr = SOFTAP_MIN_RSSI;
+			rssi = SOFTAP_MIN_RSSI;
+			pSpectCh->bssCount = SOFTAP_MIN_COUNT;
+		}
+
 		if (pSpectCh->weight > SAP_ACS_WEIGHT_MAX)
 			pSpectCh->weight = SAP_ACS_WEIGHT_MAX;
 		pSpectCh->weight_copy = pSpectCh->weight;