Avoid redundant entity association PDRs after merge

currently bmc creates merged entity association PDRs for
host starting from the top level of bmc's entity tree
due to that bmc creates redundant entity association PDRs
which host has not sent.
This commit creates merged(remote) entity association PDRs
starting from the level Host has sent it's entity
association PDRs.

if bmc has:
system->chassis
chassis->motherboard
motherboard->memory and drive backplane
drive backplane -> slot

and host sends:
motherboard->processor

previously we would create following merged entity PDRs:
system->chassis
chassis->motherboard
motherboard->memory and processor and drive back plane
drive back plane -> slot

after the change bmc will create:
motherboard->memory and processor and drive back plane

since the other two are redundant

Change-Id: I900997e23a80b4874eef23bb203b369e0b8d757e
Signed-off-by: Sampa Misra <sampmisr@in.ibm.com>
diff --git a/host-bmc/host_pdr_handler.cpp b/host-bmc/host_pdr_handler.cpp
index f9d30b5..a2d4d17 100644
--- a/host-bmc/host_pdr_handler.cpp
+++ b/host-bmc/host_pdr_handler.cpp
@@ -207,13 +207,24 @@
             }
         }
     }
-    free(entities);
 
     if (merged)
     {
         // Update our PDR repo with the merged entity association PDRs
-        pldm_entity_association_pdr_add(entityTree, repo, true);
+        pldm_entity_node* node = nullptr;
+        pldm_find_entity_ref_in_tree(entityTree, entities[0], &node);
+        if (node == nullptr)
+        {
+            std::cerr
+                << "\ncould not find referrence of the entity in the tree \n";
+        }
+        else
+        {
+            pldm_entity_association_pdr_add_from_node(node, repo, &entities,
+                                                      numEntities, true);
+        }
     }
+    free(entities);
 }
 
 void HostPDRHandler::sendPDRRepositoryChgEvent(std::vector<uint8_t>&& pdrTypes,