Ramesh Iyyar | 3af5c32 | 2020-12-04 00:38:42 -0600 | [diff] [blame] | 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 | |
George Liu | 858fbb2 | 2021-07-01 12:25:44 +0800 | [diff] [blame] | 8 | #include <fmt/core.h> |
| 9 | |
Ramesh Iyyar | 3af5c32 | 2020-12-04 00:38:42 -0600 | [diff] [blame] | 10 | #include <phosphor-logging/elog-errors.hpp> |
| 11 | #include <phosphor-logging/log.hpp> |
| 12 | |
| 13 | namespace phosphor |
| 14 | { |
| 15 | namespace dump |
| 16 | { |
| 17 | namespace pldm |
| 18 | { |
| 19 | |
| 20 | using namespace phosphor::logging; |
| 21 | using NotAllowed = sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed; |
| 22 | using Reason = xyz::openbmc_project::Common::NotAllowed::REASON; |
| 23 | |
| 24 | int openPLDM() |
| 25 | { |
| 26 | auto fd = pldm_open(); |
| 27 | if (fd < 0) |
| 28 | { |
| 29 | auto e = errno; |
George Liu | 858fbb2 | 2021-07-01 12:25:44 +0800 | [diff] [blame] | 30 | log<level::ERR>( |
| 31 | fmt::format("pldm_open failed, errno({}), FD({})", e, fd).c_str()); |
Ramesh Iyyar | 3af5c32 | 2020-12-04 00:38:42 -0600 | [diff] [blame] | 32 | elog<NotAllowed>(Reason("Required host dump action via pldm is not " |
| 33 | "allowed due to pldm_open failed")); |
| 34 | } |
| 35 | return fd; |
| 36 | } |
| 37 | |
| 38 | uint8_t getPLDMInstanceID(uint8_t eid) |
| 39 | { |
| 40 | |
| 41 | constexpr auto pldmRequester = "xyz.openbmc_project.PLDM.Requester"; |
| 42 | constexpr auto pldm = "/xyz/openbmc_project/pldm"; |
Ramesh Iyyar | 3af5c32 | 2020-12-04 00:38:42 -0600 | [diff] [blame] | 43 | uint8_t instanceID = 0; |
Ramesh Iyyar | 3af5c32 | 2020-12-04 00:38:42 -0600 | [diff] [blame] | 44 | |
Dhruvaraj Subhashchandran | 9126ec0 | 2022-10-12 04:59:55 -0500 | [diff] [blame] | 45 | try |
| 46 | { |
| 47 | auto bus = sdbusplus::bus::new_default(); |
| 48 | auto service = phosphor::dump::getService(bus, pldm, pldmRequester); |
| 49 | |
| 50 | auto method = bus.new_method_call(service.c_str(), pldm, pldmRequester, |
| 51 | "GetInstanceId"); |
| 52 | method.append(eid); |
| 53 | auto reply = bus.call(method); |
| 54 | |
| 55 | reply.read(instanceID); |
| 56 | |
| 57 | log<level::INFO>( |
| 58 | fmt::format("Got instanceId({}) from PLDM eid({})", instanceID, eid) |
| 59 | .c_str()); |
| 60 | } |
| 61 | catch (const sdbusplus::exception::SdBusError& e) |
| 62 | { |
| 63 | log<level::ERR>( |
| 64 | fmt::format("Failed to get instance id error({})", e.what()) |
| 65 | .c_str()); |
| 66 | elog<NotAllowed>(Reason("Failure in communicating with pldm service, " |
| 67 | "service may not be running")); |
| 68 | } |
Ramesh Iyyar | 3af5c32 | 2020-12-04 00:38:42 -0600 | [diff] [blame] | 69 | return instanceID; |
| 70 | } |
| 71 | |
| 72 | } // namespace pldm |
| 73 | } // namespace dump |
| 74 | } // namespace phosphor |