libpldm: Add parent to pldm_entity_node structure

Add its own parent entity to the pldm_entity_node structure, and then
use pldm_entity_get_parent to get the entity's parent.

Also, add UTest code for it.

Tested: Built pldm daemon successfully and UTest passes.

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I067f82ad6d03f3cffd2ca24cd771274777901b61
diff --git a/libpldm/pdr.c b/libpldm/pdr.c
index 92ac843..65a2591 100644
--- a/libpldm/pdr.c
+++ b/libpldm/pdr.c
@@ -320,6 +320,7 @@
 
 typedef struct pldm_entity_node {
 	pldm_entity entity;
+	pldm_entity_node *parent;
 	pldm_entity_node *first_child;
 	pldm_entity_node *next_sibling;
 	uint8_t association_type;
@@ -382,6 +383,7 @@
 	       association_type == PLDM_ENTITY_ASSOCIAION_LOGICAL);
 	pldm_entity_node *node = malloc(sizeof(pldm_entity_node));
 	assert(node != NULL);
+	node->parent = NULL;
 	node->first_child = NULL;
 	node->next_sibling = NULL;
 	node->entity.entity_type = entity->entity_type;
@@ -395,6 +397,7 @@
 		node->entity.entity_container_id = 0;
 	} else if (parent != NULL && parent->first_child == NULL) {
 		parent->first_child = node;
+		node->parent = parent;
 		node->entity.entity_container_id = next_container_id(tree);
 	} else {
 		pldm_entity_node *start =
@@ -409,6 +412,7 @@
 			    prev->entity.entity_instance_num + 1;
 		}
 		prev->next_sibling = node;
+		node->parent = prev->parent;
 		node->next_sibling = next;
 		node->entity.entity_container_id =
 		    prev->entity.entity_container_id;
@@ -489,6 +493,13 @@
 	return node->first_child != NULL;
 }
 
+inline pldm_entity_node *pldm_entity_get_parent(pldm_entity_node *node)
+{
+	assert(node != NULL);
+
+	return node->parent;
+}
+
 uint8_t pldm_entity_get_num_children(pldm_entity_node *node,
 				     uint8_t association_type)
 {