Browse Source

qcacmn: NDP_END_REQ implementation

Add implementation of NDP_END_REQ.

Change-Id: Ifa0bdcdee09c15c68bb12c63ba1157c71650c5bc
CRs-Fixed: 2014795
Naveen Rawat 8 years ago
parent
commit
52e9bb6d6f

+ 265 - 0
os_if/linux/nan/src/os_if_nan.c

@@ -442,6 +442,61 @@ responder_req_failed:
 
 }
 
+/**
+ * os_if_nan_process_ndp_end_req() - NDP end request handler
+ * @psoc: pointer to psoc object
+ *
+ * @tb: parsed NL attribute list
+ * tb includes following vendor attributes:
+ * QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID
+ *
+ * Return: 0 on success or error code on failure
+ */
+static int os_if_nan_process_ndp_end_req(struct wlan_objmgr_psoc *psoc,
+					 struct nlattr **tb)
+{
+	int ret = 0;
+	QDF_STATUS status;
+	struct wlan_objmgr_vdev *nan_vdev;
+	struct nan_datapath_end_req req = {0};
+
+	if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]) {
+		cfg80211_err("Transaction ID is unavailable");
+		return -EINVAL;
+	}
+	req.transaction_id =
+		nla_get_u16(tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]);
+
+	if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID_ARRAY]) {
+		cfg80211_err("NDP instance ID array is unavailable");
+		return -EINVAL;
+	}
+
+	req.num_ndp_instances =
+		nla_len(tb[QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID_ARRAY]) /
+			sizeof(uint32_t);
+	if (0 >= req.num_ndp_instances) {
+		cfg80211_err("Num NDP instances is 0");
+		return -EINVAL;
+	}
+	req.ndp_ids = nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID_ARRAY]);
+
+	cfg80211_debug("sending ndp_end_req to SME, transaction_id: %d",
+		req.transaction_id);
+
+	nan_vdev = ucfg_nan_get_ndi_vdev(psoc, WLAN_NAN_ID);
+	if (!nan_vdev) {
+		cfg80211_err("NAN data interface is not available");
+		return -EINVAL;
+	}
+
+	status = ucfg_nan_req_processor(nan_vdev, &req, NDP_END_REQ);
+	ret = qdf_status_to_os_return(status);
+	wlan_objmgr_vdev_release_ref(nan_vdev, WLAN_NAN_ID);
+
+	return ret;
+}
+
 int os_if_nan_process_ndp_cmd(struct wlan_objmgr_psoc *psoc,
 			      const void *data, int data_len)
 {
@@ -489,6 +544,8 @@ int os_if_nan_process_ndp_cmd(struct wlan_objmgr_psoc *psoc,
 		return os_if_nan_process_ndp_initiator_req(psoc, tb);
 	case QCA_WLAN_VENDOR_ATTR_NDP_RESPONDER_REQUEST:
 		return os_if_nan_process_ndp_responder_req(psoc, tb);
+	case QCA_WLAN_VENDOR_ATTR_NDP_END_REQUEST:
+		return os_if_nan_process_ndp_end_req(psoc, tb);
 	default:
 		cfg80211_err("Unrecognized NDP vendor cmd %d", ndp_cmd_type);
 		return -EINVAL;
@@ -881,6 +938,169 @@ ndp_confirm_nla_failed:
 	kfree_skb(vendor_event);
 }
 
+/**
+ * os_if_ndp_end_rsp_handler() - NDP end response handler
+ * @vdev: pointer to vdev object
+ * @rsp_params: response parameters
+ *
+ * Following vendor event is sent to cfg80211:
+ * QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD =
+ *         QCA_WLAN_VENDOR_ATTR_NDP_END_RESPONSE(4 bytest)
+ * QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE (4 bytes)
+ * QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE (4 bytes)
+ * QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID (2 bytes)
+ *
+ * Return: none
+ */
+static void os_if_ndp_end_rsp_handler(struct wlan_objmgr_vdev *vdev,
+				struct nan_datapath_end_rsp_event *rsp)
+{
+	uint32_t data_len;
+	struct sk_buff *vendor_event;
+	struct wlan_objmgr_pdev *pdev = wlan_vdev_get_pdev(vdev);
+	struct pdev_osif_priv *os_priv = wlan_pdev_get_ospriv(pdev);
+
+	if (!rsp) {
+		cfg80211_err("Invalid ndp end response");
+		return;
+	}
+
+	data_len = NLMSG_HDRLEN + (4 * NLA_HDRLEN) + (3 * sizeof(uint32_t)) +
+		   sizeof(uint16_t);
+
+	vendor_event = cfg80211_vendor_event_alloc(os_priv->wiphy, NULL,
+				data_len, QCA_NL80211_VENDOR_SUBCMD_NDP_INDEX,
+				GFP_ATOMIC);
+	if (!vendor_event) {
+		cfg80211_err("cfg80211_vendor_event_alloc failed");
+		return;
+	}
+
+	if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD,
+			QCA_WLAN_VENDOR_ATTR_NDP_END_RESPONSE))
+		goto ndp_end_rsp_nla_failed;
+
+	if (nla_put_u32(vendor_event,
+			QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE,
+			rsp->status))
+		goto ndp_end_rsp_nla_failed;
+
+	if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE,
+			rsp->reason))
+		goto ndp_end_rsp_nla_failed;
+
+	if (nla_put_u16(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID,
+			rsp->transaction_id))
+		goto ndp_end_rsp_nla_failed;
+
+	cfg80211_debug("NDP End rsp sent, transaction id: %d, status: %d, reason: %d",
+	       rsp->transaction_id, rsp->status, rsp->reason);
+	cfg80211_vendor_event(vendor_event, GFP_ATOMIC);
+	return;
+
+ndp_end_rsp_nla_failed:
+	cfg80211_err("nla_put api failed");
+	kfree_skb(vendor_event);
+}
+
+/**
+ * os_if_ndp_end_ind_handler() - NDP end indication handler
+ * @vdev: pointer to vdev object
+ * @ind_params: indication parameters
+ *
+ * Following vendor event is sent to cfg80211:
+ * QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD =
+ *         QCA_WLAN_VENDOR_ATTR_NDP_END_IND (4 bytes)
+ * QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID_ARRAY (4 * num of NDP Instances)
+ *
+ * Return: none
+ */
+static void os_if_ndp_end_ind_handler(struct wlan_objmgr_vdev *vdev,
+			struct nan_datapath_end_indication_event *end_ind)
+{
+	QDF_STATUS status;
+	uint32_t data_len, i;
+	struct nan_callbacks cb_obj;
+	uint32_t *ndp_instance_array;
+	struct sk_buff *vendor_event;
+	struct wlan_objmgr_vdev *vdev_itr;
+	struct wlan_objmgr_psoc *psoc = wlan_vdev_get_psoc(vdev);
+	struct wlan_objmgr_pdev *pdev = wlan_vdev_get_pdev(vdev);
+	struct pdev_osif_priv *os_priv = wlan_pdev_get_ospriv(pdev);
+
+	status = ucfg_nan_get_callbacks(psoc, &cb_obj);
+	if (QDF_IS_STATUS_ERROR(status)) {
+		cfg80211_err("failed to get callbacks");
+		return;
+	}
+
+	if (!end_ind) {
+		cfg80211_err("Invalid ndp end indication");
+		return;
+	}
+
+	ndp_instance_array = qdf_mem_malloc(end_ind->num_ndp_ids *
+		sizeof(*ndp_instance_array));
+	if (!ndp_instance_array) {
+		cfg80211_err("Failed to allocate ndp_instance_array");
+		return;
+	}
+	for (i = 0; i < end_ind->num_ndp_ids; i++) {
+		int idx = 0;
+
+		ndp_instance_array[i] = end_ind->ndp_map[i].ndp_instance_id;
+		vdev_itr = wlan_objmgr_get_vdev_by_id_from_psoc(psoc,
+				end_ind->ndp_map[i].vdev_id, WLAN_NAN_ID);
+
+		if (vdev_itr == NULL) {
+			cfg80211_err("vdev not found for vdev_id: %d",
+				end_ind->ndp_map[i].vdev_id);
+			continue;
+		}
+
+		idx = cb_obj.get_peer_idx(wlan_vdev_get_id(vdev),
+				&end_ind->ndp_map[i].peer_ndi_mac_addr);
+		if (idx < 0) {
+			cfg80211_err("can't find addr: %pM in sta_ctx.",
+				&end_ind->ndp_map[i].peer_ndi_mac_addr);
+			continue;
+		}
+		/* save the value of active sessions on each peer */
+		ucfg_nan_set_active_ndp_sessions(vdev,
+				end_ind->ndp_map[i].num_active_ndp_sessions,
+				idx);
+	}
+
+	data_len = (sizeof(uint32_t)) + NLMSG_HDRLEN + (2 * NLA_HDRLEN) +
+			end_ind->num_ndp_ids * sizeof(*ndp_instance_array);
+
+	vendor_event = cfg80211_vendor_event_alloc(os_priv->wiphy, NULL,
+				data_len, QCA_NL80211_VENDOR_SUBCMD_NDP_INDEX,
+				GFP_ATOMIC);
+	if (!vendor_event) {
+		cfg80211_err("cfg80211_vendor_event_alloc failed");
+		return;
+	}
+
+	if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD,
+			QCA_WLAN_VENDOR_ATTR_NDP_END_IND))
+		goto ndp_end_ind_nla_failed;
+
+	if (nla_put(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID_ARRAY,
+			end_ind->num_ndp_ids * sizeof(*ndp_instance_array),
+			ndp_instance_array))
+		goto ndp_end_ind_nla_failed;
+
+	cfg80211_vendor_event(vendor_event, GFP_ATOMIC);
+	qdf_mem_free(ndp_instance_array);
+	return;
+
+ndp_end_ind_nla_failed:
+	cfg80211_err("nla_put api failed");
+	kfree_skb(vendor_event);
+	qdf_mem_free(ndp_instance_array);
+}
+
 /**
  * os_if_new_peer_ind_handler() - NDP new peer indication handler
  * @adapter: pointer to adapter context
@@ -925,6 +1145,42 @@ static void os_if_new_peer_ind_handler(struct wlan_objmgr_vdev *vdev,
 	cfg80211_debug("vdev_id: %d, num_peers: %d", vdev_id, active_peers);
 }
 
+/**
+ * os_if_peer_departed_ind_handler() - Handle NDP peer departed indication
+ * @adapter: pointer to adapter context
+ * @ind_params: indication parameters
+ *
+ * Return: none
+ */
+static void os_if_peer_departed_ind_handler(struct wlan_objmgr_vdev *vdev,
+			struct nan_datapath_peer_ind *peer_ind)
+{
+	QDF_STATUS status;
+	struct nan_callbacks cb_obj;
+	uint8_t vdev_id = wlan_vdev_get_id(vdev);
+	struct wlan_objmgr_psoc *psoc = wlan_vdev_get_psoc(vdev);
+	uint32_t active_peers = ucfg_nan_get_active_peers(vdev);
+
+	status = ucfg_nan_get_callbacks(psoc, &cb_obj);
+	if (QDF_IS_STATUS_ERROR(status)) {
+		cfg80211_err("failed to get callbacks");
+		return;
+	}
+
+	if (NULL == peer_ind) {
+		cfg80211_err("Invalid new NDP peer params");
+		return;
+	}
+	cfg80211_debug("session_id: %d, peer_mac: %pM, sta_id: %d",
+		peer_ind->session_id, peer_ind->peer_mac_addr.bytes,
+		peer_ind->sta_id);
+	active_peers--;
+	ucfg_nan_set_active_peers(vdev, active_peers);
+	cb_obj.peer_departed_ind(vdev_id, peer_ind->sta_id,
+				&peer_ind->peer_mac_addr,
+				(active_peers == 0 ? true : false));
+}
+
 /**
  * os_if_ndp_iface_create_rsp_handler() - NDP iface create response handler
  * @adapter: pointer to adapter context
@@ -1114,6 +1370,15 @@ void os_if_nan_event_handler(struct wlan_objmgr_psoc *psoc,
 	case NDP_RESPONDER_RSP:
 		os_if_ndp_responder_rsp_handler(vdev, msg);
 		break;
+	case NDP_END_RSP:
+		os_if_ndp_end_rsp_handler(vdev, msg);
+		break;
+	case NDP_END_IND:
+		os_if_ndp_end_ind_handler(vdev, msg);
+		break;
+	case NDP_PEER_DEPARTED:
+		os_if_peer_departed_ind_handler(vdev, msg);
+		break;
 	default:
 		break;
 	}

+ 300 - 0
target_if/nan/src/target_if_nan.c

@@ -22,6 +22,7 @@
 
 #include "../../../umac/nan/core/src/nan_main_i.h"
 #include "nan_public_structs.h"
+#include "nan_ucfg_api.h"
 #include "target_if_nan.h"
 #include "wmi_unified_api.h"
 #include "scheduler_api.h"
@@ -54,6 +55,16 @@ static QDF_STATUS target_if_nan_event_dispatcher(struct scheduler_msg *msg)
 		vdev = rsp->vdev;
 		break;
 	}
+	case NDP_END_RSP: {
+		struct nan_datapath_end_rsp_event *rsp = msg->bodyptr;
+		vdev = rsp->vdev;
+		break;
+	}
+	case NDP_END_IND: {
+		struct nan_datapath_end_indication_event *rsp = msg->bodyptr;
+		vdev = rsp->vdev;
+		break;
+	}
 	default:
 		target_if_err("invalid msg type %d", msg->type);
 		qdf_mem_free(msg->bodyptr);
@@ -730,6 +741,258 @@ static int target_if_ndp_responder_rsp_handler(ol_scn_t scn, uint8_t *data,
 	return 0;
 }
 
+static QDF_STATUS target_if_nan_ndp_end_req(struct nan_datapath_end_req *req)
+{
+	int ret;
+	uint16_t len;
+	wmi_buf_t buf;
+	QDF_STATUS status;
+	wmi_unified_t wmi_handle;
+	uint32_t ndp_end_req_len, i;
+	struct wlan_objmgr_psoc *psoc;
+	struct scheduler_msg msg = {0};
+	wmi_ndp_end_req *ndp_end_req_lst;
+	wmi_ndp_end_req_fixed_param *cmd;
+	struct wlan_lmac_if_nan_rx_ops *nan_rx_ops;
+	struct nan_datapath_end_rsp_event end_rsp = {0};
+
+	if (!req) {
+		target_if_err("req is null");
+		return QDF_STATUS_E_INVAL;
+	}
+
+	psoc = wlan_vdev_get_psoc(req->vdev);
+	if (!psoc) {
+		target_if_err("psoc is null.");
+		return QDF_STATUS_E_NULL_VALUE;
+	}
+
+	wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
+	if (!wmi_handle) {
+		target_if_err("wmi_handle is null.");
+		return QDF_STATUS_E_NULL_VALUE;
+	}
+
+	nan_rx_ops = target_if_nan_get_rx_ops(psoc);
+	if (!nan_rx_ops) {
+		target_if_err("nan_rx_ops is null.");
+		return QDF_STATUS_E_NULL_VALUE;
+	}
+
+	/* len of tlv following fixed param  */
+	ndp_end_req_len = sizeof(wmi_ndp_end_req) * req->num_ndp_instances;
+	/* above comes out to 4 byte alligned already, no need of padding */
+	len = sizeof(*cmd) + ndp_end_req_len + WMI_TLV_HDR_SIZE;
+	buf = wmi_buf_alloc(wmi_handle, len);
+	if (!buf) {
+		target_if_err("Malloc failed");
+		status = QDF_STATUS_E_NOMEM;
+		goto send_ndp_end_fail;
+	}
+	cmd = (wmi_ndp_end_req_fixed_param *) wmi_buf_data(buf);
+
+	WMITLV_SET_HDR(&cmd->tlv_header,
+		       WMITLV_TAG_STRUC_wmi_ndp_end_req_fixed_param,
+		       WMITLV_GET_STRUCT_TLVLEN(wmi_ndp_end_req_fixed_param));
+
+	cmd->transaction_id = req->transaction_id;
+
+	/* set tlv pointer to end of fixed param */
+	WMITLV_SET_HDR((uint8_t *)&cmd[1], WMITLV_TAG_ARRAY_STRUC,
+			ndp_end_req_len);
+
+	ndp_end_req_lst = (wmi_ndp_end_req *)((uint8_t *)&cmd[1] +
+						WMI_TLV_HDR_SIZE);
+	for (i = 0; i < req->num_ndp_instances; i++) {
+		WMITLV_SET_HDR(&ndp_end_req_lst[i],
+				WMITLV_TAG_ARRAY_FIXED_STRUC,
+				(sizeof(*ndp_end_req_lst) - WMI_TLV_HDR_SIZE));
+
+		ndp_end_req_lst[i].ndp_instance_id = req->ndp_ids[i];
+	}
+
+	target_if_debug("Sending WMI_NDP_END_REQ_CMDID to FW");
+	ret = wmi_unified_cmd_send(wmi_handle, buf, len,
+				   WMI_NDP_END_REQ_CMDID);
+	if (ret < 0) {
+		target_if_err("WMI_NDP_END_REQ_CMDID failed, ret: %d", ret);
+		wmi_buf_free(buf);
+		status = QDF_STATUS_E_FAILURE;
+		goto send_ndp_end_fail;
+	}
+	return QDF_STATUS_SUCCESS;
+
+send_ndp_end_fail:
+	end_rsp.vdev = req->vdev;
+	msg.type = NDP_END_RSP;
+	end_rsp.status = NAN_DATAPATH_RSP_STATUS_ERROR;
+	end_rsp.reason = NAN_DATAPATH_END_FAILED;
+	end_rsp.transaction_id = req->transaction_id;
+	msg.bodyptr = &end_rsp;
+
+	if (nan_rx_ops && nan_rx_ops->nan_event_rx)
+		nan_rx_ops->nan_event_rx(&msg);
+
+	return status;
+}
+
+static int target_if_ndp_end_rsp_handler(ol_scn_t scn, uint8_t *data,
+					 uint32_t data_len)
+{
+	int ret = 0;
+	QDF_STATUS status;
+	struct wlan_objmgr_psoc *psoc;
+	struct wlan_objmgr_vdev *vdev;
+	struct scheduler_msg msg = {0};
+	WMI_NDP_END_RSP_EVENTID_param_tlvs *event;
+	struct nan_datapath_end_rsp_event *end_rsp;
+	struct wlan_lmac_if_nan_rx_ops *nan_rx_ops;
+	wmi_ndp_end_rsp_event_fixed_param *fixed_params = NULL;
+
+	psoc = target_if_get_psoc_from_scn_hdl(scn);
+	if (!psoc) {
+		target_if_err("psoc is null");
+		return -EINVAL;
+	}
+
+	nan_rx_ops = target_if_nan_get_rx_ops(psoc);
+	/* process even here and call callback */
+	if (!nan_rx_ops || !nan_rx_ops->nan_event_rx) {
+		target_if_err("lmac callbacks not registered");
+		return -EINVAL;
+	}
+
+	event = (WMI_NDP_END_RSP_EVENTID_param_tlvs *) data;
+	fixed_params = (wmi_ndp_end_rsp_event_fixed_param *)event->fixed_param;
+	target_if_debug("WMI_NDP_END_RSP_EVENTID(0x%X) recieved. transaction_id: %d, rsp_status: %d, reason_code: %d",
+		 WMI_NDP_END_RSP_EVENTID, fixed_params->transaction_id,
+		 fixed_params->rsp_status, fixed_params->reason_code);
+
+	vdev = ucfg_nan_get_ndi_vdev(psoc, WLAN_NAN_ID);
+	if (!vdev) {
+		target_if_err("vdev is null");
+		return -EINVAL;
+	}
+
+	end_rsp = qdf_mem_malloc(sizeof(*end_rsp));
+	if (!end_rsp) {
+		target_if_err("malloc failed");
+		ret = -ENOMEM;
+		wlan_objmgr_vdev_release_ref(vdev, WLAN_NAN_ID);
+		goto send_ndp_end_rsp;
+	}
+
+	end_rsp->vdev = vdev;
+	end_rsp->transaction_id = fixed_params->transaction_id;
+	end_rsp->reason = fixed_params->reason_code;
+	end_rsp->status = fixed_params->rsp_status;
+
+send_ndp_end_rsp:
+	msg.bodyptr = end_rsp;
+	msg.type = NDP_END_RSP;
+	msg.callback = target_if_nan_event_dispatcher;
+	target_if_err("NDP_END_RSP sent: %d", msg.type);
+	status = scheduler_post_msg(QDF_MODULE_ID_TARGET_IF, &msg);
+	wlan_objmgr_vdev_release_ref(vdev, WLAN_NAN_ID);
+	if (QDF_IS_STATUS_ERROR(status)) {
+		target_if_err("failed to post msg, status: %d", status);
+		qdf_mem_free(end_rsp);
+		return -EINVAL;
+	}
+	return ret;
+}
+
+static int target_if_ndp_end_ind_handler(ol_scn_t scn, uint8_t *data,
+					 uint32_t data_len)
+{
+	int i, buf_size;
+	QDF_STATUS status;
+	struct scheduler_msg msg;
+	wmi_ndp_end_indication *ind;
+	struct qdf_mac_addr peer_addr;
+	struct wlan_objmgr_psoc *psoc;
+	struct wlan_objmgr_vdev *vdev;
+	struct wlan_lmac_if_nan_rx_ops *nan_rx_ops;
+	WMI_NDP_END_INDICATION_EVENTID_param_tlvs *event;
+	struct nan_datapath_end_indication_event *rsp;
+
+	psoc = target_if_get_psoc_from_scn_hdl(scn);
+	if (!psoc) {
+		target_if_err("psoc is null");
+		return -EINVAL;
+	}
+
+	nan_rx_ops = target_if_nan_get_rx_ops(psoc);
+	if (!nan_rx_ops || !nan_rx_ops->nan_event_rx) {
+		target_if_err("lmac callbacks not registered");
+		return -EINVAL;
+	}
+
+	event = (WMI_NDP_END_INDICATION_EVENTID_param_tlvs *) data;
+	if (event->num_ndp_end_indication_list == 0) {
+		target_if_err("Error: Event ignored, 0 ndp instances");
+		return -EINVAL;
+	}
+
+	vdev = ucfg_nan_get_ndi_vdev(psoc, WLAN_NAN_ID);
+	if (!vdev) {
+		target_if_err("vdev is null");
+		return -EINVAL;
+	}
+
+	target_if_debug("number of ndp instances = %d",
+			event->num_ndp_end_indication_list);
+	buf_size = sizeof(*rsp) + event->num_ndp_end_indication_list *
+			sizeof(rsp->ndp_map[0]);
+	rsp = qdf_mem_malloc(buf_size);
+	if (!rsp) {
+		target_if_err("Failed to allocate memory");
+		wlan_objmgr_vdev_release_ref(vdev, WLAN_NAN_ID);
+		return -ENOMEM;
+	}
+
+	rsp->vdev = vdev;
+	rsp->num_ndp_ids = event->num_ndp_end_indication_list;
+
+	ind = event->ndp_end_indication_list;
+	for (i = 0; i < rsp->num_ndp_ids; i++) {
+		WMI_MAC_ADDR_TO_CHAR_ARRAY(
+			&ind[i].peer_ndi_mac_addr,
+			peer_addr.bytes);
+		/* add mac address print - TBD */
+		target_if_debug(
+			"ind[%d]: type %d, reason_code %d, instance_id %d num_active %d ",
+			i, ind[i].type, ind[i].reason_code,
+			ind[i].ndp_instance_id, ind[i].num_active_ndps_on_peer);
+
+		/* Add each instance entry to the list */
+		rsp->ndp_map[i].ndp_instance_id =
+			ind[i].ndp_instance_id;
+		rsp->ndp_map[i].vdev_id = ind[i].vdev_id;
+		WMI_MAC_ADDR_TO_CHAR_ARRAY(&ind[i].peer_ndi_mac_addr,
+			rsp->ndp_map[i].peer_ndi_mac_addr.bytes);
+		rsp->ndp_map[i].num_active_ndp_sessions =
+			ind[i].num_active_ndps_on_peer;
+		rsp->ndp_map[i].type = ind[i].type;
+		rsp->ndp_map[i].reason_code =
+			ind[i].reason_code;
+	}
+
+	msg.type = NDP_END_IND;
+	msg.bodyptr = rsp;
+	msg.callback = target_if_nan_event_dispatcher;
+
+	target_if_err("NDP_END_IND sent: %d", msg.type);
+	status = scheduler_post_msg(QDF_MODULE_ID_TARGET_IF, &msg);
+	wlan_objmgr_vdev_release_ref(vdev, WLAN_NAN_ID);
+	if (QDF_IS_STATUS_ERROR(status)) {
+		target_if_err("failed to post msg, status: %d", status);
+		qdf_mem_free(rsp);
+		return -EINVAL;
+	}
+	return 0;
+}
+
 static QDF_STATUS target_if_nan_req(void *req, uint32_t req_type)
 {
 	/* send cmd to fw */
@@ -740,6 +1003,9 @@ static QDF_STATUS target_if_nan_req(void *req, uint32_t req_type)
 	case NDP_RESPONDER_REQ:
 		target_if_nan_ndp_responder_req(req);
 		break;
+	case NDP_END_REQ:
+		target_if_nan_ndp_end_req(req);
+		break;
 	default:
 		target_if_err("invalid req type");
 		break;
@@ -823,6 +1089,26 @@ QDF_STATUS target_if_nan_register_events(struct wlan_objmgr_psoc *psoc)
 		return QDF_STATUS_E_FAILURE;
 	}
 
+	ret = wmi_unified_register_event_handler(handle,
+		WMI_NDP_END_INDICATION_EVENTID,
+		target_if_ndp_end_ind_handler,
+		WMI_RX_UMAC_CTX);
+	if (ret) {
+		target_if_err("wmi event registration failed, ret: %d", ret);
+		target_if_nan_deregister_events(psoc);
+		return QDF_STATUS_E_FAILURE;
+	}
+
+	ret = wmi_unified_register_event_handler(handle,
+		WMI_NDP_END_RSP_EVENTID,
+		target_if_ndp_end_rsp_handler,
+		WMI_RX_UMAC_CTX);
+	if (ret) {
+		target_if_err("wmi event registration failed, ret: %d", ret);
+		target_if_nan_deregister_events(psoc);
+		return QDF_STATUS_E_FAILURE;
+	}
+
 	return QDF_STATUS_SUCCESS;
 }
 
@@ -859,6 +1145,20 @@ QDF_STATUS target_if_nan_deregister_events(struct wlan_objmgr_psoc *psoc)
 		status = ret;
 	}
 
+	ret = wmi_unified_unregister_event_handler(handle,
+				WMI_NDP_END_INDICATION_EVENTID);
+	if (ret) {
+		target_if_err("wmi event deregistration failed, ret: %d", ret);
+		status = ret;
+	}
+
+	ret = wmi_unified_unregister_event_handler(handle,
+				WMI_NDP_END_RSP_EVENTID);
+	if (ret) {
+		target_if_err("wmi event deregistration failed, ret: %d", ret);
+		status = ret;
+	}
+
 	if (status)
 		return QDF_STATUS_E_FAILURE;
 	else

+ 3 - 0
umac/nan/core/inc/nan_public_structs.h

@@ -497,6 +497,9 @@ struct nan_callbacks {
 	int (*get_peer_idx)(uint8_t, struct qdf_mac_addr *);
 	QDF_STATUS (*add_ndi_peer)(uint32_t, struct qdf_mac_addr);
 
+	void (*peer_departed_ind)(uint8_t, uint16_t, struct qdf_mac_addr *,
+				  bool);
+	void (*ndp_delete_peers)(struct peer_nan_datapath_map*, uint8_t);
 	void (*delete_peers_by_addr)(uint8_t, struct qdf_mac_addr);
 };
 

+ 59 - 1
umac/nan/core/src/nan_main.c

@@ -115,7 +115,6 @@ static void nan_req_incomplete(void *req, uint32_t cmdtype)
 static void nan_req_activated(void *in_req, uint32_t cmdtype)
 {
 	uint32_t req_type;
-	QDF_STATUS status;
 	struct wlan_objmgr_psoc *psoc;
 	struct wlan_objmgr_vdev *vdev;
 	struct wlan_lmac_if_nan_tx_ops *tx_ops;
@@ -413,6 +412,57 @@ static QDF_STATUS nan_handle_responder_rsp(
 	return QDF_STATUS_SUCCESS;
 }
 
+static QDF_STATUS nan_handle_ndp_end_rsp(
+			struct nan_datapath_end_rsp_event *rsp,
+			struct wlan_objmgr_vdev **vdev)
+{
+	struct wlan_objmgr_psoc *psoc;
+	struct nan_psoc_priv_obj *psoc_nan_obj;
+
+	*vdev = rsp->vdev;
+	psoc = wlan_vdev_get_psoc(rsp->vdev);
+	if (!psoc) {
+		nan_err("psoc is NULL");
+		return QDF_STATUS_E_NULL_VALUE;
+	}
+
+	psoc_nan_obj = nan_get_psoc_priv_obj(psoc);
+	if (!psoc_nan_obj) {
+		nan_err("psoc_nan_obj is NULL");
+		return QDF_STATUS_E_NULL_VALUE;
+	}
+
+	psoc_nan_obj->cb_obj.os_if_event_handler(psoc, rsp->vdev,
+						NDP_END_RSP, rsp);
+
+	return QDF_STATUS_SUCCESS;
+}
+
+static QDF_STATUS nan_handle_end_ind(
+				struct nan_datapath_end_indication_event *ind)
+{
+	struct wlan_objmgr_psoc *psoc;
+	struct nan_psoc_priv_obj *psoc_nan_obj;
+
+	psoc = wlan_vdev_get_psoc(ind->vdev);
+	if (!psoc) {
+		nan_err("psoc is NULL");
+		return QDF_STATUS_E_NULL_VALUE;
+	}
+
+	psoc_nan_obj = nan_get_psoc_priv_obj(psoc);
+	if (!psoc_nan_obj) {
+		nan_err("psoc_nan_obj is NULL");
+		return QDF_STATUS_E_NULL_VALUE;
+	}
+
+	psoc_nan_obj->cb_obj.ndp_delete_peers(ind->ndp_map, ind->num_ndp_ids);
+	psoc_nan_obj->cb_obj.os_if_event_handler(psoc, ind->vdev,
+						 NDP_END_IND, ind);
+
+	return QDF_STATUS_SUCCESS;
+}
+
 QDF_STATUS nan_event_handler(struct scheduler_msg *pe_msg)
 {
 	QDF_STATUS status = QDF_STATUS_SUCCESS;
@@ -448,6 +498,14 @@ QDF_STATUS nan_event_handler(struct scheduler_msg *pe_msg)
 		cmd.cmd_type = WLAN_SER_CMD_NDP_RESP_REQ;
 		wlan_serialization_remove_cmd(&cmd);
 		break;
+	case NDP_END_RSP:
+		nan_handle_ndp_end_rsp(pe_msg->bodyptr, &cmd.vdev);
+		cmd.cmd_type = WLAN_SER_CMD_NDP_DATA_END_INIT_REQ;
+		wlan_serialization_remove_cmd(&cmd);
+		break;
+	case NDP_END_IND:
+		nan_handle_end_ind(pe_msg->bodyptr);
+		break;
 	default:
 		nan_alert("Unhandled NDP event: %d", pe_msg->type);
 		status = QDF_STATUS_E_NOSUPPORT;

+ 39 - 0
umac/nan/dispatcher/src/nan_ucfg_api.c

@@ -440,6 +440,40 @@ free_resources:
 	return NULL;
 }
 
+static struct nan_datapath_end_req *ucfg_nan_copy_end_req(
+			struct wlan_objmgr_vdev *vdev,
+			struct nan_datapath_end_req *in_req)
+{
+	struct nan_datapath_end_req *req;
+
+	req = qdf_mem_malloc(sizeof(*req));
+	if (!req) {
+		nan_alert("malloc failed");
+		return NULL;
+	}
+
+	qdf_mem_copy(req, in_req, sizeof(*req));
+	if (in_req->num_ndp_instances) {
+		req->ndp_ids = qdf_mem_malloc(sizeof(uint32_t) *
+						in_req->num_ndp_instances);
+		if (!req->ndp_ids) {
+			nan_alert("malloc failed");
+			goto free_resources;
+		}
+		qdf_mem_copy(req->ndp_ids, in_req->ndp_ids,
+			     sizeof(uint32_t) * in_req->num_ndp_instances);
+	}
+
+	/* do not get ref here, rather take ref when request is activated */
+	req->vdev = vdev;
+	return req;
+
+free_resources:
+	qdf_mem_free(req->ndp_ids);
+	qdf_mem_free(req);
+	return NULL;
+}
+
 QDF_STATUS ucfg_nan_req_processor(struct wlan_objmgr_vdev *vdev,
 				  void *in_req, uint32_t req_type)
 {
@@ -459,6 +493,9 @@ QDF_STATUS ucfg_nan_req_processor(struct wlan_objmgr_vdev *vdev,
 	case NDP_RESPONDER_REQ:
 		req = ucfg_nan_copy_responder_req(vdev, in_req);
 		break;
+	case NDP_END_REQ:
+		req = ucfg_nan_copy_end_req(vdev, in_req);
+		break;
 	default:
 		nan_err("in correct message req type: %d", req_type);
 		return QDF_STATUS_E_INVAL;
@@ -522,6 +559,7 @@ int ucfg_nan_register_hdd_callbacks(struct wlan_objmgr_psoc *psoc,
 
 	psoc_obj->cb_obj.get_peer_idx = cb_obj->get_peer_idx;
 	psoc_obj->cb_obj.new_peer_ind = cb_obj->new_peer_ind;
+	psoc_obj->cb_obj.peer_departed_ind = cb_obj->peer_departed_ind;
 
 	return 0;
 }
@@ -537,6 +575,7 @@ int ucfg_nan_register_lim_callbacks(struct wlan_objmgr_psoc *psoc,
 	}
 
 	psoc_obj->cb_obj.add_ndi_peer = cb_obj->add_ndi_peer;
+	psoc_obj->cb_obj.ndp_delete_peers = cb_obj->ndp_delete_peers;
 	psoc_obj->cb_obj.delete_peers_by_addr = cb_obj->delete_peers_by_addr;
 
 	return 0;