// SPDX-License-Identifier: Apache-2.0 #include "pldm_utils.hpp" #include "dump_utils.hpp" #include "xyz/openbmc_project/Common/error.hpp" #include #include #include namespace phosphor { namespace dump { namespace pldm { using namespace phosphor::logging; using NotAllowed = sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed; using Reason = xyz::openbmc_project::Common::NotAllowed::REASON; int openPLDM() { auto fd = pldm_open(); if (fd < 0) { auto e = errno; log( fmt::format("pldm_open failed, errno({}), FD({})", e, fd).c_str()); elog(Reason("Required host dump action via pldm is not " "allowed due to pldm_open failed")); } return fd; } uint8_t getPLDMInstanceID(uint8_t eid) { constexpr auto pldmRequester = "xyz.openbmc_project.PLDM.Requester"; constexpr auto pldm = "/xyz/openbmc_project/pldm"; uint8_t instanceID = 0; try { auto bus = sdbusplus::bus::new_default(); auto service = phosphor::dump::getService(bus, pldm, pldmRequester); auto method = bus.new_method_call(service.c_str(), pldm, pldmRequester, "GetInstanceId"); method.append(eid); auto reply = bus.call(method); reply.read(instanceID); log( fmt::format("Got instanceId({}) from PLDM eid({})", instanceID, eid) .c_str()); } catch (const sdbusplus::exception::SdBusError& e) { log( fmt::format("Failed to get instance id error({})", e.what()) .c_str()); elog(Reason("Failure in communicating with pldm service, " "service may not be running")); } return instanceID; } } // namespace pldm } // namespace dump } // namespace phosphor