qcacld-3.0: Combine LTE Coex & DNBS avoid freqs

Avoid frequency list can be generated due to LTE Coex and
Do_Not_Break_Stream.
Combine LTE Coex & DNBS avoid frequencies before sending the list to
application.

Change-Id: Ibafac2fcc160d029fc5643847a5647edf10db29d
CRs-Fixed: 2045120
diff --git a/core/hdd/src/wlan_hdd_cfg80211.c b/core/hdd/src/wlan_hdd_cfg80211.c
index d414051..eec23f5 100644
--- a/core/hdd/src/wlan_hdd_cfg80211.c
+++ b/core/hdd/src/wlan_hdd_cfg80211.c
@@ -761,6 +761,27 @@
 static void wlan_hdd_cfg80211_start_pending_acs(struct work_struct *work);
 #endif
 
+int wlan_hdd_merge_avoid_freqs(tHddAvoidFreqList *destFreqList,
+		tHddAvoidFreqList *srcFreqList)
+{
+	int i;
+	tHddAvoidFreqRange *avoidRange =
+	&destFreqList->avoidFreqRange[destFreqList->avoidFreqRangeCount];
+
+	destFreqList->avoidFreqRangeCount += srcFreqList->avoidFreqRangeCount;
+	if (destFreqList->avoidFreqRangeCount > HDD_MAX_AVOID_FREQ_RANGES) {
+		hdd_err("avoid freq overflow");
+		return -EINVAL;
+	}
+
+	for (i = 0; i < srcFreqList->avoidFreqRangeCount; i++) {
+		avoidRange->startFreq =
+			srcFreqList->avoidFreqRange[i].startFreq;
+		avoidRange->endFreq = srcFreqList->avoidFreqRange[i].endFreq;
+		avoidRange++;
+	}
+	return 0;
+}
 /*
  * FUNCTION: wlan_hdd_send_avoid_freq_event
  * This is called when wlan driver needs to send vendor specific
@@ -862,6 +883,16 @@
 	 * If channel passed is zero, clear the avoid_freq list in application.
 	 */
 	if (!op_chan) {
+#ifdef FEATURE_WLAN_CH_AVOID
+		mutex_lock(&pHddCtx->avoid_freq_lock);
+		qdf_mem_zero(&pHddCtx->dnbs_avoid_freq_list,
+				sizeof(tHddAvoidFreqList));
+		if (pHddCtx->coex_avoid_freq_list.avoidFreqRangeCount)
+			memcpy(&p2p_avoid_freq_list,
+			       &pHddCtx->coex_avoid_freq_list,
+			       sizeof(tHddAvoidFreqList));
+		mutex_unlock(&pHddCtx->avoid_freq_lock);
+#endif
 		ret = wlan_hdd_send_avoid_freq_event(pHddCtx,
 						     &p2p_avoid_freq_list);
 		if (ret)
@@ -925,7 +956,20 @@
 		p2p_avoid_freq_list.avoidFreqRange[0].endFreq =
 			wlan_chan_to_freq(chan);
 	}
-
+#ifdef FEATURE_WLAN_CH_AVOID
+	mutex_lock(&pHddCtx->avoid_freq_lock);
+	pHddCtx->dnbs_avoid_freq_list = p2p_avoid_freq_list;
+	if (pHddCtx->coex_avoid_freq_list.avoidFreqRangeCount) {
+		ret = wlan_hdd_merge_avoid_freqs(&p2p_avoid_freq_list,
+				&pHddCtx->coex_avoid_freq_list);
+		if (ret) {
+			mutex_unlock(&pHddCtx->avoid_freq_lock);
+			hdd_err("avoid freq merge failed");
+			return ret;
+		}
+	}
+	mutex_unlock(&pHddCtx->avoid_freq_lock);
+#endif
 	ret = wlan_hdd_send_avoid_freq_event(pHddCtx, &p2p_avoid_freq_list);
 	if (ret)
 		hdd_err("wlan_hdd_send_avoid_freq_event error:%d", ret);