blob: 35dc0581b40401db6c999b2b5de733d8a9a8c5ca [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
ArchanaKakanidcf77d62022-08-29 07:04:09 -05009#include <xyz/openbmc_project/Common/error.hpp>
10
Patrick Williams70a47ba2021-09-02 09:53:31 -050011#include <iostream>
12
13namespace pldm
14{
15namespace responder
16{
17namespace platform
18{
Patrick Williams70a47ba2021-09-02 09:53:31 -050019int sendBiosAttributeUpdateEvent(
20 uint8_t eid, dbus_api::Requester* requester,
21 const std::vector<uint16_t>& handles,
22 pldm::requester::Handler<pldm::requester::Request>* handler)
23{
24 constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0";
25 constexpr auto hostStateInterface =
26 "xyz.openbmc_project.State.Boot.Progress";
27 constexpr auto hostStateProperty = "BootProgress";
28
29 try
30 {
31 auto propVal = pldm::utils::DBusHandler().getDbusPropertyVariant(
32 hostStatePath, hostStateProperty, hostStateInterface);
33 const auto& currHostState = std::get<std::string>(propVal);
34 if ((currHostState != "xyz.openbmc_project.State.Boot.Progress."
35 "ProgressStages.SystemInitComplete") &&
36 (currHostState != "xyz.openbmc_project.State.Boot.Progress."
37 "ProgressStages.OSRunning") &&
38 (currHostState != "xyz.openbmc_project.State.Boot.Progress."
Andrew Geisslerf2704dc2022-05-23 16:09:45 -040039 "ProgressStages.OSStart") &&
40 (currHostState != "xyz.openbmc_project.State.Boot.Progress."
41 "ProgressStages.SystemSetup"))
Patrick Williams70a47ba2021-09-02 09:53:31 -050042 {
43 return PLDM_SUCCESS;
44 }
45 }
ArchanaKakanidcf77d62022-08-29 07:04:09 -050046 catch (
47 const sdbusplus::xyz::openbmc_project::Common::Error::ResourceNotFound&
48 e)
49 {
50 /* Exception is expected to happen in the case when state manager is
51 * started after pldm, this is expected to happen in reboot case
52 * where host is considered to be up. As host is up pldm is expected
53 * to send attribute update event to host so this is not an error
54 * case */
55 }
Patrick Williams84b790c2022-07-22 19:26:56 -050056 catch (const sdbusplus::exception_t& e)
Patrick Williams70a47ba2021-09-02 09:53:31 -050057 {
ArchanaKakanidcf77d62022-08-29 07:04:09 -050058 std::cerr << "Error in getting current host state, " << e.name()
59 << " Continue sending the bios attribute update event ... \n";
Patrick Williams70a47ba2021-09-02 09:53:31 -050060 }
61
62 auto instanceId = requester->getInstanceId(eid);
63
64 std::vector<uint8_t> requestMsg(
65 sizeof(pldm_msg_hdr) + sizeof(pldm_bios_attribute_update_event_req) -
66 1 + (handles.size() * sizeof(uint16_t)),
67 0);
68
69 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
70
71 auto rc = encode_bios_attribute_update_event_req(
Manojkiran Eda6a49bb02022-09-02 05:35:26 -050072 instanceId, PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION, TERMINUS_ID,
73 handles.size(), reinterpret_cast<const uint8_t*>(handles.data()),
Patrick Williams70a47ba2021-09-02 09:53:31 -050074 requestMsg.size() - sizeof(pldm_msg_hdr), request);
75 if (rc != PLDM_SUCCESS)
76 {
ArchanaKakanidcf77d62022-08-29 07:04:09 -050077 std::cerr
78 << "BIOS Attribute update event message encode failure. PLDM error code = "
79 << std::hex << std::showbase << rc << "\n";
Patrick Williams70a47ba2021-09-02 09:53:31 -050080 requester->markFree(eid, instanceId);
81 return rc;
82 }
83
Patrick Williams70a47ba2021-09-02 09:53:31 -050084 auto platformEventMessageResponseHandler = [](mctp_eid_t /*eid*/,
85 const pldm_msg* response,
86 size_t respMsgLen) {
87 if (response == nullptr || !respMsgLen)
88 {
89 std::cerr
ArchanaKakanidcf77d62022-08-29 07:04:09 -050090 << "Failed to receive response for BIOS Attribute update platform event message \n";
Patrick Williams70a47ba2021-09-02 09:53:31 -050091 return;
92 }
93 uint8_t completionCode{};
94 uint8_t status{};
95 auto rc = decode_platform_event_message_resp(response, respMsgLen,
96 &completionCode, &status);
97 if (rc || completionCode)
98 {
ArchanaKakanidcf77d62022-08-29 07:04:09 -050099 std::cerr
100 << "Failed to decode BIOS Attribute update platform_event_message_resp: "
101 << "rc=" << rc
102 << ", cc=" << static_cast<unsigned>(completionCode)
103 << std::endl;
Patrick Williams70a47ba2021-09-02 09:53:31 -0500104 }
105 };
106 rc = handler->registerRequest(
107 eid, instanceId, PLDM_PLATFORM, PLDM_PLATFORM_EVENT_MESSAGE,
108 std::move(requestMsg), std::move(platformEventMessageResponseHandler));
109 if (rc)
110 {
ArchanaKakanidcf77d62022-08-29 07:04:09 -0500111 std::cerr
112 << "Failed to send BIOS Attribute update the platform event message \n";
Patrick Williams70a47ba2021-09-02 09:53:31 -0500113 }
114
115 return rc;
116}
117
118} // namespace platform
119
120} // namespace responder
121
122} // namespace pldm