Add functions useful for pldm requests
Added functions for getting state effector PDRs,
state sensor PDRs and MCTP instances.
Signed-off-by: Ben Tyner <ben.tyner@ibm.com>
Change-Id: If7f0675c55c68cb10402d50e4a2d2f3e7f4a793b
diff --git a/util/dbus.cpp b/util/dbus.cpp
index 585a07d..f9370d4 100644
--- a/util/dbus.cpp
+++ b/util/dbus.cpp
@@ -6,16 +6,16 @@
namespace util
{
-
namespace dbus
{
-
//------------------------------------------------------------------------------
constexpr auto objectMapperService = "xyz.openbmc_project.ObjectMapper";
constexpr auto objectMapperPath = "/xyz/openbmc_project/object_mapper";
constexpr auto objectMapperInterface = "xyz.openbmc_project.ObjectMapper";
+constexpr uint8_t terminusIdZero = 0;
+
/** @brief Find the path and service that implements the given interface */
int find(const std::string& i_interface, std::string& o_path,
std::string& o_service)
@@ -428,6 +428,107 @@
return machineType;
}
-} // namespace dbus
+/** @brief Get list of state effecter PDRs */
+bool getStateEffecterPdrs(std::vector<std::vector<uint8_t>>& pdrList,
+ uint16_t stateSetId)
+{
+ constexpr auto service = "xyz.openbmc_project.PLDM";
+ constexpr auto path = "/xyz/openbmc_project/pldm";
+ constexpr auto interface = "xyz.openbmc_project.PLDM.PDR";
+ constexpr auto function = "FindStateEffecterPDR";
+ constexpr uint16_t PLDM_ENTITY_PROC = 135;
+
+ try
+ {
+ // create dbus method
+ auto bus = sdbusplus::bus::new_default();
+ sdbusplus::message_t method =
+ bus.new_method_call(service, path, interface, function);
+
+ // append additional method data
+ method.append(terminusIdZero, PLDM_ENTITY_PROC, stateSetId);
+
+ // request PDRs
+ auto reply = bus.call(method);
+ reply.read(pdrList);
+ }
+ catch (const sdbusplus::exception_t& e)
+ {
+ trace::err("failed to find state effecter PDRs");
+ trace::err(e.what());
+ return false;
+ }
+
+ return true;
+}
+
+/** @brief Get list of state sensor PDRs */
+bool getStateSensorPdrs(std::vector<std::vector<uint8_t>>& pdrList,
+ uint16_t stateSetId)
+{
+ constexpr auto service = "xyz.openbmc_project.PLDM";
+ constexpr auto path = "/xyz/openbmc_project/pldm";
+ constexpr auto interface = "xyz.openbmc_project.PLDM.PDR";
+ constexpr auto function = "FindStateSensorPDR";
+
+ constexpr uint16_t PLDM_ENTITY_PROC = 135;
+
+ try
+ {
+ // create dbus method
+ auto bus = sdbusplus::bus::new_default();
+ sdbusplus::message_t method =
+ bus.new_method_call(service, path, interface, function);
+
+ // append additional method data
+ method.append(terminusIdZero, PLDM_ENTITY_PROC, stateSetId);
+
+ // request PDRs
+ auto reply = bus.call(method);
+ reply.read(pdrList);
+ }
+ catch (const sdbusplus::exception_t& e)
+ {
+ trace::err("failed to find state sensor PDRs");
+ trace::err(e.what());
+ return false;
+ }
+
+ return true;
+}
+
+/** @brief Get MCTP instance associated with endpoint */
+bool getMctpInstance(uint8_t& mctpInstance, uint8_t Eid)
+{
+ constexpr auto service = "xyz.openbmc_project.PLDM";
+ constexpr auto path = "/xyz/openbmc_project/pldm";
+ constexpr auto interface = "xyz.openbmc_project.PLDM.Requester";
+ constexpr auto function = "GetInstanceId";
+
+ try
+ {
+ // create dbus method
+ auto bus = sdbusplus::bus::new_default();
+ sdbusplus::message_t method =
+ bus.new_method_call(service, path, interface, function);
+
+ // append endpoint ID
+ method.append(Eid);
+
+ // request MCTP instance ID
+ auto reply = bus.call(method);
+ reply.read(mctpInstance);
+ }
+ catch (const sdbusplus::exception_t& e)
+ {
+ trace::err("get MCTP instance exception");
+ trace::err(e.what());
+ return false;
+ }
+
+ return true;
+}
+
+} // namespace dbus
} // namespace util
diff --git a/util/dbus.hpp b/util/dbus.hpp
index d8510ac..39041e2 100644
--- a/util/dbus.hpp
+++ b/util/dbus.hpp
@@ -9,10 +9,8 @@
namespace util
{
-
namespace dbus
{
-
using DBusValue = std::variant<std::string, bool, std::vector<uint8_t>,
std::vector<std::string>>;
using DBusProperty = std::string;
@@ -151,6 +149,35 @@
*/
MachineType getMachineType();
-} // namespace dbus
+/** @brief Get list of state sensor PDRs
+ *
+ * @param[out] pdrList - list of PDRs
+ * @param[in] stateSetId - ID of the state set of interest
+ *
+ * @return true if successful otherwise false
+ */
+bool getStateSensorPdrs(std::vector<std::vector<uint8_t>>& pdrList,
+ uint16_t stateSetId);
+/** @brief Get list of state effecter PDRs
+ *
+ * @param[out] pdrList - list of PDRs
+ * @param[in] stateSetId - ID of the state set of interest
+ *
+ * @return true if successful otherwise false
+ */
+bool getStateEffecterPdrs(std::vector<std::vector<uint8_t>>& pdrList,
+ uint16_t stateSetId);
+
+/**
+ * @brief Get MCTP instance ID associated with endpoint
+ *
+ * @param[out] mctpInstance - instance of MCTP
+ * @param[in] Eid - MCTP enpoint ID
+ *
+ * @return True on success otherwise False
+ */
+bool getMctpInstance(uint8_t& mctpInstance, uint8_t Eid);
+
+} // namespace dbus
} // namespace util