blob: fbc7ba746a3b2ba13519bf730247e2db48e93de4 [file] [log] [blame]
Patrick Williams70a47ba2021-09-02 09:53:31 -05001#include "platform_oem_ibm.hpp"
2
3#include "libpldm/platform_oem_ibm.h"
4#include "libpldm/requester/pldm.h"
5
6#include "common/utils.hpp"
7#include "libpldmresponder/pdr.hpp"
8
9#include <iostream>
10
11namespace pldm
12{
13namespace responder
14{
15namespace platform
16{
Patrick Williams70a47ba2021-09-02 09:53:31 -050017int sendBiosAttributeUpdateEvent(
18 uint8_t eid, dbus_api::Requester* requester,
19 const std::vector<uint16_t>& handles,
20 pldm::requester::Handler<pldm::requester::Request>* handler)
21{
22 constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0";
23 constexpr auto hostStateInterface =
24 "xyz.openbmc_project.State.Boot.Progress";
25 constexpr auto hostStateProperty = "BootProgress";
26
27 try
28 {
29 auto propVal = pldm::utils::DBusHandler().getDbusPropertyVariant(
30 hostStatePath, hostStateProperty, hostStateInterface);
31 const auto& currHostState = std::get<std::string>(propVal);
32 if ((currHostState != "xyz.openbmc_project.State.Boot.Progress."
33 "ProgressStages.SystemInitComplete") &&
34 (currHostState != "xyz.openbmc_project.State.Boot.Progress."
35 "ProgressStages.OSRunning") &&
36 (currHostState != "xyz.openbmc_project.State.Boot.Progress."
Andrew Geisslerf2704dc2022-05-23 16:09:45 -040037 "ProgressStages.OSStart") &&
38 (currHostState != "xyz.openbmc_project.State.Boot.Progress."
39 "ProgressStages.SystemSetup"))
Patrick Williams70a47ba2021-09-02 09:53:31 -050040 {
41 return PLDM_SUCCESS;
42 }
43 }
Patrick Williams84b790c2022-07-22 19:26:56 -050044 catch (const sdbusplus::exception_t& e)
Patrick Williams70a47ba2021-09-02 09:53:31 -050045 {
46 std::cerr << "Error in getting current host state, continue ... \n";
47 }
48
49 auto instanceId = requester->getInstanceId(eid);
50
51 std::vector<uint8_t> requestMsg(
52 sizeof(pldm_msg_hdr) + sizeof(pldm_bios_attribute_update_event_req) -
53 1 + (handles.size() * sizeof(uint16_t)),
54 0);
55
56 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
57
58 auto rc = encode_bios_attribute_update_event_req(
Manojkiran Eda6a49bb02022-09-02 05:35:26 -050059 instanceId, PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION, TERMINUS_ID,
60 handles.size(), reinterpret_cast<const uint8_t*>(handles.data()),
Patrick Williams70a47ba2021-09-02 09:53:31 -050061 requestMsg.size() - sizeof(pldm_msg_hdr), request);
62 if (rc != PLDM_SUCCESS)
63 {
64 std::cerr << "Message encode failure 1. PLDM error code = " << std::hex
65 << std::showbase << rc << "\n";
66 requester->markFree(eid, instanceId);
67 return rc;
68 }
69
Patrick Williams70a47ba2021-09-02 09:53:31 -050070 auto platformEventMessageResponseHandler = [](mctp_eid_t /*eid*/,
71 const pldm_msg* response,
72 size_t respMsgLen) {
73 if (response == nullptr || !respMsgLen)
74 {
75 std::cerr
76 << "Failed to receive response for platform event message \n";
77 return;
78 }
79 uint8_t completionCode{};
80 uint8_t status{};
81 auto rc = decode_platform_event_message_resp(response, respMsgLen,
82 &completionCode, &status);
83 if (rc || completionCode)
84 {
85 std::cerr << "Failed to decode_platform_event_message_resp: "
86 << "rc=" << rc
87 << ", cc=" << static_cast<unsigned>(completionCode)
88 << std::endl;
89 }
90 };
91 rc = handler->registerRequest(
92 eid, instanceId, PLDM_PLATFORM, PLDM_PLATFORM_EVENT_MESSAGE,
93 std::move(requestMsg), std::move(platformEventMessageResponseHandler));
94 if (rc)
95 {
96 std::cerr << "Failed to send the platform event message \n";
97 }
98
99 return rc;
100}
101
102} // namespace platform
103
104} // namespace responder
105
106} // namespace pldm