pdr: Add pldm_entity_association_tree_delete_node() API

This API deletes the specific entity node from the entity
association tree. We must handle the parent children and sibling
relationship before we delete the node from the entity association
tree.

Change-Id: I326adba8316a15c6af0696cdd9bdf2be7e592452
Signed-off-by: Pavithra Barithaya <pavithrabarithaya07@gmail.com>
diff --git a/src/dsp/pdr.c b/src/dsp/pdr.c
index 69229d5..f8873b1 100644
--- a/src/dsp/pdr.c
+++ b/src/dsp/pdr.c
@@ -2346,3 +2346,44 @@
 	}
 	return rc;
 }
+
+LIBPLDM_ABI_TESTING
+int pldm_entity_association_tree_delete_node(pldm_entity_association_tree *tree,
+					     const pldm_entity *entity)
+{
+	if (!tree || !entity) {
+		return -EINVAL;
+	}
+	pldm_entity_node *node = NULL;
+	pldm_find_entity_ref_in_tree(tree, *entity, &node);
+	if (!node) {
+		return -ENOENT;
+	}
+
+	pldm_entity_node *parent = NULL;
+	pldm_find_entity_ref_in_tree(tree, node->parent, &parent);
+	if (!parent) {
+		return -ENOENT;
+	}
+
+	pldm_entity_node *curr = parent->first_child;
+	pldm_entity_node *prev = NULL;
+	while (curr != NULL) {
+		if (pldm_entity_cmp(entity, &curr->entity)) {
+			if (curr == parent->first_child) {
+				parent->first_child = curr->next_sibling;
+			} else {
+				if (prev) {
+					prev->next_sibling = curr->next_sibling;
+				}
+			}
+			curr->next_sibling = NULL;
+
+			entity_association_tree_destroy(node);
+			break;
+		}
+		prev = curr;
+		curr = curr->next_sibling;
+	}
+	return 0;
+}