qcacld-3.0: Handle request to delete NAN Data Interface (NDI)

qcacld-2.0 to qcacld-3.0 propagation

Add changes to handle request to delete NAN datapath interface.

Change-Id: I3efef6adf6c7a974d3e344a7609f8517cd1aa752
CRs-Fixed: 962367
diff --git a/core/mac/src/pe/lim/lim_process_sme_req_messages.c b/core/mac/src/pe/lim/lim_process_sme_req_messages.c
index 0d480b6..c8dfdf4 100644
--- a/core/mac/src/pe/lim/lim_process_sme_req_messages.c
+++ b/core/mac/src/pe/lim/lim_process_sme_req_messages.c
@@ -3435,34 +3435,39 @@
 	psessionEntry->smeSessionId = smesessionId;
 	psessionEntry->transactionId = smetransactionId;
 
-	/* BTAMP_STA and STA_IN_IBSS should NOT send Disassoc frame */
-	if (!LIM_IS_IBSS_ROLE(psessionEntry)) {
+	/* STA_IN_IBSS and NDI should NOT send Disassoc frame */
+	if (!LIM_IS_IBSS_ROLE(psessionEntry) &&
+	    !LIM_IS_NDI_ROLE(psessionEntry)) {
 		tSirMacAddr bcAddr = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
 		if (stopBssReq.reasonCode == eSIR_SME_MIC_COUNTER_MEASURES)
 			/* Send disassoc all stations associated thru TKIP */
 			__lim_counter_measures(pMac, psessionEntry);
 		else
 			lim_send_disassoc_mgmt_frame(pMac,
-						     eSIR_MAC_DEAUTH_LEAVING_BSS_REASON,
-						     bcAddr, psessionEntry, false);
+				eSIR_MAC_DEAUTH_LEAVING_BSS_REASON,
+				bcAddr, psessionEntry, false);
 	}
 
-	/* Free the buffer allocated in START_BSS_REQ */
-	qdf_mem_free(psessionEntry->addIeParams.probeRespData_buff);
-	psessionEntry->addIeParams.probeRespDataLen = 0;
-	psessionEntry->addIeParams.probeRespData_buff = NULL;
+	if (!LIM_IS_NDI_ROLE(psessionEntry)) {
+		/* Free the buffer allocated in START_BSS_REQ */
+		qdf_mem_free(psessionEntry->addIeParams.probeRespData_buff);
+		psessionEntry->addIeParams.probeRespDataLen = 0;
+		psessionEntry->addIeParams.probeRespData_buff = NULL;
 
-	qdf_mem_free(psessionEntry->addIeParams.assocRespData_buff);
-	psessionEntry->addIeParams.assocRespDataLen = 0;
-	psessionEntry->addIeParams.assocRespData_buff = NULL;
+		qdf_mem_free(psessionEntry->addIeParams.assocRespData_buff);
+		psessionEntry->addIeParams.assocRespDataLen = 0;
+		psessionEntry->addIeParams.assocRespData_buff = NULL;
 
-	qdf_mem_free(psessionEntry->addIeParams.probeRespBCNData_buff);
-	psessionEntry->addIeParams.probeRespBCNDataLen = 0;
-	psessionEntry->addIeParams.probeRespBCNData_buff = NULL;
+		qdf_mem_free(psessionEntry->addIeParams.probeRespBCNData_buff);
+		psessionEntry->addIeParams.probeRespBCNDataLen = 0;
+		psessionEntry->addIeParams.probeRespBCNData_buff = NULL;
 
-	/* lim_del_bss is also called as part of coalescing, when we send DEL BSS followed by Add Bss msg. */
-	pMac->lim.gLimIbssCoalescingHappened = false;
-
+		/*
+		 * lim_del_bss is also called as part of coalescing,
+		 * when we send DEL BSS followed by Add Bss msg.
+		 */
+		pMac->lim.gLimIbssCoalescingHappened = false;
+	}
 	for (i = 1; i < pMac->lim.gLimAssocStaLimit; i++) {
 		pStaDs =
 			dph_get_hash_entry(pMac, i, &psessionEntry->dph.dphHashTable);
diff --git a/core/mac/src/pe/lim/lim_send_sme_rsp_messages.c b/core/mac/src/pe/lim/lim_send_sme_rsp_messages.c
index 1f6947c..adb49fd 100644
--- a/core/mac/src/pe/lim/lim_send_sme_rsp_messages.c
+++ b/core/mac/src/pe/lim/lim_send_sme_rsp_messages.c
@@ -57,6 +57,7 @@
 #include "sir_api.h"
 #include "cds_regdomain.h"
 #include "lim_send_messages.h"
+#include "nan_datapath.h"
 
 static void lim_handle_join_rsp_status(tpAniSirGlobal mac_ctx,
 	tpPESession session_entry, tSirResultCodes result_code,
@@ -2249,12 +2250,12 @@
 			pDelBss->sessionId);
 		return;
 	}
-	if (LIM_IS_IBSS_ROLE(psessionEntry)) {
+	if (LIM_IS_IBSS_ROLE(psessionEntry))
 		lim_ibss_del_bss_rsp(pMac, MsgQ->bodyptr, psessionEntry);
-	} else if (LIM_IS_UNKNOWN_ROLE(psessionEntry)) {
+	else if (LIM_IS_UNKNOWN_ROLE(psessionEntry))
 		lim_process_sme_del_bss_rsp(pMac, MsgQ->bodyval, psessionEntry);
-	}
-
+	else if (LIM_IS_NDI_ROLE(psessionEntry))
+		lim_ndi_del_bss_rsp(pMac, MsgQ->bodyptr, psessionEntry);
 	else
 		lim_process_mlm_del_bss_rsp(pMac, MsgQ, psessionEntry);
 
diff --git a/core/mac/src/pe/nan/nan_datapath.c b/core/mac/src/pe/nan/nan_datapath.c
index 4d365f1..56144f9 100644
--- a/core/mac/src/pe/nan/nan_datapath.c
+++ b/core/mac/src/pe/nan/nan_datapath.c
@@ -27,6 +27,8 @@
 #include "lim_utils.h"
 #include "lim_api.h"
 #include "nan_datapath.h"
+#include "lim_types.h"
+#include "lim_send_messages.h"
 
 /**
  * handle_ndp_request_message() - Function to handle NDP requests from SME
@@ -97,3 +99,64 @@
 	qdf_mem_free(lim_msgq->bodyptr);
 	lim_msgq->bodyptr = NULL;
 }
+
+/**
+ * lim_ndi_del_bss_rsp() - Handler for DEL BSS resp for NDI interface
+ * @mac_ctx: handle to mac structure
+ * @msg: pointer to message
+ * @session_entry: session entry
+ *
+ * Return: None
+ */
+void lim_ndi_del_bss_rsp(tpAniSirGlobal  mac_ctx,
+			void *msg, tpPESession session_entry)
+{
+	tSirResultCodes rc = eSIR_SME_SUCCESS;
+	tpDeleteBssParams del_bss = (tpDeleteBssParams) msg;
+
+	SET_LIM_PROCESS_DEFD_MESGS(mac_ctx, true);
+	if (del_bss == NULL) {
+		lim_log(mac_ctx, LOGE,
+			FL("NDI: DEL_BSS_RSP with no body!"));
+		rc = eSIR_SME_STOP_BSS_FAILURE;
+		goto end;
+	}
+	session_entry =
+		pe_find_session_by_session_id(mac_ctx, del_bss->sessionId);
+	if (!session_entry) {
+		lim_log(mac_ctx, LOGE,
+			FL("Session Does not exist for given sessionID"));
+		goto end;
+	}
+
+	if (del_bss->status != QDF_STATUS_SUCCESS) {
+		lim_log(mac_ctx, LOGE,
+			FL("NDI: DEL_BSS_RSP error (%x) Bss %d "),
+			del_bss->status, del_bss->bssIdx);
+		rc = eSIR_SME_STOP_BSS_FAILURE;
+		goto end;
+	}
+
+	if (lim_set_link_state(mac_ctx, eSIR_LINK_IDLE_STATE,
+			session_entry->selfMacAddr,
+			session_entry->selfMacAddr, NULL, NULL)
+			!= eSIR_SUCCESS) {
+		lim_log(mac_ctx, LOGE,
+			FL("NDI: DEL_BSS_RSP setLinkState failed"));
+		goto end;
+	}
+
+	session_entry->limMlmState = eLIM_MLM_IDLE_STATE;
+
+end:
+	if (del_bss)
+		qdf_mem_free(del_bss);
+	/* Delete PE session once BSS is deleted */
+	if (NULL != session_entry) {
+		lim_send_sme_rsp(mac_ctx, eWNI_SME_STOP_BSS_RSP,
+			rc, session_entry->smeSessionId,
+			session_entry->transactionId);
+		pe_delete_session(mac_ctx, session_entry);
+		session_entry = NULL;
+	}
+}
diff --git a/core/mac/src/pe/nan/nan_datapath.h b/core/mac/src/pe/nan/nan_datapath.h
index 1def0d2..a51cdc4 100644
--- a/core/mac/src/pe/nan/nan_datapath.h
+++ b/core/mac/src/pe/nan/nan_datapath.h
@@ -109,6 +109,9 @@
 void lim_process_ndi_mlm_add_bss_rsp(tpAniSirGlobal mac_ctx,
 				     tpSirMsgQ lim_msg_q,
 				     tpPESession session_entry);
+/* Handler for DEL BSS resp for NDI interface */
+void lim_ndi_del_bss_rsp(tpAniSirGlobal  mac_ctx,
+			void *msg, tpPESession session_entry);
 #else
 /* Function to process NDP requests */
 static inline QDF_STATUS lim_handle_ndp_request_message(tpAniSirGlobal mac_ctx,
@@ -129,6 +132,10 @@
 						   tpPESession session_entry)
 {
 }
+static inline void lim_ndi_del_bss_rsp(tpAniSirGlobal mac_ctx,
+					void *msg, tpPESession session_entry)
+{
+}
 
 #endif /* WLAN_FEATURE_NAN_DATAPATH */