pdr: Add APIs for creating and locating remote PDRs

In the current state, the tree_find() and tree_add() utilities work by
replacing the existing container ID that comes from the remote
endpoints. But we need the remote container ID when we do the PDR
normalization (merging) in BMC.

Two boolean properties are introduced:

* is_remote: used to indicate if the entity is BMC owned or of remote
  endpoint owned.

* is_update_container_id: used to indicate if the container id of the
  entity needs to be updated or not.

We handle 3 different combinations,

1. Both are false - when it is the parent node in the tree
   example: - https://github.com/ibm-openbmc/pldm/blob/1050/
   libpldmresponder/pdr_state_sensor.hpp#L136

2. is_remote is false and update_container_id is true - when it is
   a BMC entity but we have a container id change needed.
   example: - https://github.com/ibm-openbmc/pldm/blob/1050/
   libpldmresponder/fru.cpp#L130

3. is_remote is true and update_container_id is false - In IBM
   PLDM stack talks to two different remote firmware implementations
   over PLDM, and we had a conflicting requirement to not merge the
   container ID from one endpoint but merge the container ID from
   another endpoint. Example: -https://github.com/ibm-openbmc/
   pldm/blob/1050/host-bmc/host_pdr_handler.cpp#L509

Change-Id: I8541b76aa46ba23172ffbc4d72e686909b7147fc
Signed-off-by: Pavithra Barithaya <pavithra.b@ibm.com>
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/include/libpldm/pdr.h b/include/libpldm/pdr.h
index 6a72028..7542624 100644
--- a/include/libpldm/pdr.h
+++ b/include/libpldm/pdr.h
@@ -242,7 +242,7 @@
  */
 pldm_entity_association_tree *pldm_entity_association_tree_init(void);
 
-/** @brief Add an entity into the entity association tree
+/** @brief Add a local entity into the entity association tree
  *
  *  @param[in/out] tree - opaque pointer acting as a handle to the tree
  *  @param[in/out] entity - pointer to the entity to be added. Input has the
@@ -262,6 +262,35 @@
 	uint16_t entity_instance_number, pldm_entity_node *parent,
 	uint8_t association_type);
 
+/** @brief Add an entity into the entity association tree based on remote field
+ *  set or unset.
+ *
+ *  @param[in/out] tree - opaque pointer acting as a handle to the tree
+ *  @param[in/out] entity - pointer to the entity to be added. Input has the
+ *                          entity type. On output, instance number and the
+ *                          container id are populated.
+ *  @param[in] entity_instance_number - entity instance number, we can use the
+ *                                      entity instance number of the entity by
+ *                                      default if its value is equal 0xFFFF.
+ *  @param[in] parent - pointer to the node that should be the parent of input
+ *                      entity. If this is NULL, then the entity is the root
+ *  @param[in] association_type - relation with the parent : logical or physical
+ *  @param[in] is_remote - used to denote whether we are adding a BMC entity to
+ *                         the tree or a host entity
+ *  @param[in] is_update_contanier_id - Used to determine whether need to update
+ *                                      contanier id.
+ *                                      true: should be changed
+ *                                      false: should not be changed
+ *  @param[in] container_id - container id of the entity added.
+ *
+ *  @return pldm_entity_node* - opaque pointer to added entity
+ */
+pldm_entity_node *pldm_entity_association_tree_add_entity(
+	pldm_entity_association_tree *tree, pldm_entity *entity,
+	uint16_t entity_instance_number, pldm_entity_node *parent,
+	uint8_t association_type, bool is_remote, bool is_update_container_id,
+	uint16_t container_id);
+
 /** @brief Visit and note each entity in the entity association tree
  *
  *  @param[in] tree - opaque pointer acting as a handle to the tree
@@ -377,6 +406,21 @@
 pldm_entity_association_tree_find(pldm_entity_association_tree *tree,
 				  pldm_entity *entity);
 
+/** @brief Find an entity in the entity association tree if remote
+ *
+ *  @param[in] tree - pointer to entity association tree
+ *  @param[in/out] entity - entity type and instance id set on input, container
+ *                          id set on output
+ *  @param[in] is_remote - variable to denote whether we are finding a host
+ *                         entity or a BMC entity
+ *
+ *  @return pldm_entity_node* pointer to entity if found, NULL otherwise
+ */
+pldm_entity_node *
+pldm_entity_association_tree_find_if_remote(pldm_entity_association_tree *tree,
+					    pldm_entity *entity,
+					    bool is_remote);
+
 /** @brief Create a copy of an existing entity association tree
  *
  *  @param[in] org_tree - pointer to source tree