1 // SPDX-License-Identifier: Apache-2.0 2 3 #include "pldm_utils.hpp" 4 5 #include "dump_utils.hpp" 6 #include "xyz/openbmc_project/Common/error.hpp" 7 8 #include <phosphor-logging/elog-errors.hpp> 9 #include <phosphor-logging/log.hpp> 10 11 namespace phosphor 12 { 13 namespace dump 14 { 15 namespace pldm 16 { 17 18 using namespace phosphor::logging; 19 using NotAllowed = sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed; 20 using Reason = xyz::openbmc_project::Common::NotAllowed::REASON; 21 22 int openPLDM() 23 { 24 auto fd = pldm_open(); 25 if (fd < 0) 26 { 27 auto e = errno; 28 log<level::ERR>("pldm_open failed", entry("ERRNO=%d", e), 29 entry("FD=%d\n", fd)); 30 elog<NotAllowed>(Reason("Required host dump action via pldm is not " 31 "allowed due to pldm_open failed")); 32 } 33 return fd; 34 } 35 36 uint8_t getPLDMInstanceID(uint8_t eid) 37 { 38 39 constexpr auto pldmRequester = "xyz.openbmc_project.PLDM.Requester"; 40 constexpr auto pldm = "/xyz/openbmc_project/pldm"; 41 42 auto bus = sdbusplus::bus::new_default(); 43 auto service = phosphor::dump::getService(bus, pldm, pldmRequester); 44 45 auto method = bus.new_method_call(service.c_str(), pldm, pldmRequester, 46 "GetInstanceId"); 47 method.append(eid); 48 auto reply = bus.call(method); 49 50 uint8_t instanceID = 0; 51 reply.read(instanceID); 52 53 return instanceID; 54 } 55 56 } // namespace pldm 57 } // namespace dump 58 } // namespace phosphor 59