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 | |
| 8 | #include <phosphor-logging/elog-errors.hpp> |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 9 | #include <phosphor-logging/lg2.hpp> |
Ramesh Iyyar | 3af5c32 | 2020-12-04 00:38:42 -0600 | [diff] [blame] | 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; |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 28 | lg2::error( |
| 29 | "pldm_open failed, errno: {ERRNO}, FD: FD", "ERRNO", e, "FD", |
| 30 | static_cast<std::underlying_type<pldm_requester_error_codes>::type>( |
| 31 | fd)); |
| 32 | elog<NotAllowed>( |
| 33 | Reason("Required host dump action via pldm is not allowed due " |
| 34 | "to pldm_open failed")); |
Ramesh Iyyar | 3af5c32 | 2020-12-04 00:38:42 -0600 | [diff] [blame] | 35 | } |
| 36 | return fd; |
| 37 | } |
| 38 | |
| 39 | uint8_t getPLDMInstanceID(uint8_t eid) |
| 40 | { |
Ramesh Iyyar | 3af5c32 | 2020-12-04 00:38:42 -0600 | [diff] [blame] | 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 | |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 57 | lg2::info("Got instanceId: {INSTANCE_ID} from PLDM eid: {EID}", |
| 58 | "INSTANCE_ID", instanceID, "EID", eid); |
Dhruvaraj Subhashchandran | 9126ec0 | 2022-10-12 04:59:55 -0500 | [diff] [blame] | 59 | } |
| 60 | catch (const sdbusplus::exception::SdBusError& e) |
| 61 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 62 | lg2::error("Failed to get instance id error: {ERROR}", "ERROR", e); |
Dhruvaraj Subhashchandran | 9126ec0 | 2022-10-12 04:59:55 -0500 | [diff] [blame] | 63 | elog<NotAllowed>(Reason("Failure in communicating with pldm service, " |
| 64 | "service may not be running")); |
| 65 | } |
Ramesh Iyyar | 3af5c32 | 2020-12-04 00:38:42 -0600 | [diff] [blame] | 66 | return instanceID; |
| 67 | } |
| 68 | |
| 69 | } // namespace pldm |
| 70 | } // namespace dump |
| 71 | } // namespace phosphor |