common: Add util APIs to find all the effecter IDs and PDRs
This util API is used to find all the effecter IDs based on
the pldm_entity given. Another util API is added to get all
the PDRs based on the entity type.
Change-Id: I4f5b0ca05dfbad641f1ecfbaec5ebf63f54e500d
Signed-off-by: Pavithra Barithaya <pavithrabarithaya07@gmail.com>
diff --git a/common/utils.cpp b/common/utils.cpp
index 80e1401..06ae48b 100644
--- a/common/utils.cpp
+++ b/common/utils.cpp
@@ -868,5 +868,47 @@
return sensorIDs;
}
+EffecterPDRs getStateEffecterPDRsByType(uint16_t entityType,
+ const pldm_pdr* repo)
+{
+ uint8_t* outData = nullptr;
+ uint32_t size{};
+ const pldm_pdr_record* record = nullptr;
+ EffecterPDRs pdrs;
+ if (repo)
+ {
+ while ((record = pldm_pdr_find_record_by_type(
+ repo, PLDM_STATE_EFFECTER_PDR, record, &outData, &size)))
+ {
+ auto pdr = new (outData) pldm_state_effecter_pdr;
+ if (pdr && pdr->entity_type == entityType)
+ {
+ pdrs.emplace_back(outData, outData + size);
+ }
+ }
+ }
+ return pdrs;
+}
+
+std::vector<pldm::pdr::EffecterID> findEffecterIds(
+ const pldm_pdr* pdrRepo, uint16_t entityType, uint16_t entityInstance,
+ uint16_t containerId)
+{
+ std::vector<uint16_t> effecterIDs;
+ auto pdrs = getStateEffecterPDRsByType(entityType, pdrRepo);
+ for (const auto& pdr : pdrs)
+ {
+ auto effecterPdr =
+ reinterpret_cast<const pldm_state_effecter_pdr*>(pdr.data());
+ if (effecterPdr && effecterPdr->entity_type == entityType &&
+ effecterPdr->entity_instance == entityInstance &&
+ effecterPdr->container_id == containerId)
+ {
+ effecterIDs.emplace_back(effecterPdr->effecter_id);
+ }
+ }
+ return effecterIDs;
+}
+
} // namespace utils
} // namespace pldm