blob: 4b7cec5c4c25a88e1f60967eea0ad0ed4bcf716f [file] [log] [blame]
Patrick Williams70a47ba2021-09-02 09:53:31 -05001#include "platform_oem_ibm.hpp"
2
Patrick Williams70a47ba2021-09-02 09:53:31 -05003#include "common/utils.hpp"
4#include "libpldmresponder/pdr.hpp"
5
George Liuc453e162022-12-21 17:16:23 +08006#include <libpldm/platform_oem_ibm.h>
7#include <libpldm/pldm.h>
8
Riya Dixit49cfb132023-03-02 04:26:53 -06009#include <phosphor-logging/lg2.hpp>
ArchanaKakanidcf77d62022-08-29 07:04:09 -050010#include <xyz/openbmc_project/Common/error.hpp>
11
Patrick Williams70a47ba2021-09-02 09:53:31 -050012#include <iostream>
13
Riya Dixit49cfb132023-03-02 04:26:53 -060014PHOSPHOR_LOG2_USING;
15
Patrick Williams70a47ba2021-09-02 09:53:31 -050016namespace pldm
17{
18namespace responder
19{
20namespace platform
21{
Patrick Williams70a47ba2021-09-02 09:53:31 -050022int sendBiosAttributeUpdateEvent(
23 uint8_t eid, dbus_api::Requester* requester,
24 const std::vector<uint16_t>& handles,
25 pldm::requester::Handler<pldm::requester::Request>* handler)
26{
27 constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0";
28 constexpr auto hostStateInterface =
29 "xyz.openbmc_project.State.Boot.Progress";
30 constexpr auto hostStateProperty = "BootProgress";
31
32 try
33 {
34 auto propVal = pldm::utils::DBusHandler().getDbusPropertyVariant(
35 hostStatePath, hostStateProperty, hostStateInterface);
36 const auto& currHostState = std::get<std::string>(propVal);
37 if ((currHostState != "xyz.openbmc_project.State.Boot.Progress."
38 "ProgressStages.SystemInitComplete") &&
39 (currHostState != "xyz.openbmc_project.State.Boot.Progress."
40 "ProgressStages.OSRunning") &&
41 (currHostState != "xyz.openbmc_project.State.Boot.Progress."
Andrew Geisslerf2704dc2022-05-23 16:09:45 -040042 "ProgressStages.SystemSetup"))
Patrick Williams70a47ba2021-09-02 09:53:31 -050043 {
44 return PLDM_SUCCESS;
45 }
46 }
ArchanaKakanidcf77d62022-08-29 07:04:09 -050047 catch (
48 const sdbusplus::xyz::openbmc_project::Common::Error::ResourceNotFound&
49 e)
50 {
51 /* Exception is expected to happen in the case when state manager is
52 * started after pldm, this is expected to happen in reboot case
53 * where host is considered to be up. As host is up pldm is expected
54 * to send attribute update event to host so this is not an error
55 * case */
56 }
Patrick Williams84b790c2022-07-22 19:26:56 -050057 catch (const sdbusplus::exception_t& e)
Patrick Williams70a47ba2021-09-02 09:53:31 -050058 {
Riya Dixit49cfb132023-03-02 04:26:53 -060059 error(
60 "Error in getting current host state, {EXCEP_NAME} Continue sending the bios attribute update event ...",
61 "EXCEP_NAME", e.name());
Patrick Williams70a47ba2021-09-02 09:53:31 -050062 }
63
64 auto instanceId = requester->getInstanceId(eid);
65
66 std::vector<uint8_t> requestMsg(
67 sizeof(pldm_msg_hdr) + sizeof(pldm_bios_attribute_update_event_req) -
68 1 + (handles.size() * sizeof(uint16_t)),
69 0);
70
71 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
72
73 auto rc = encode_bios_attribute_update_event_req(
Manojkiran Eda6a49bb02022-09-02 05:35:26 -050074 instanceId, PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION, TERMINUS_ID,
75 handles.size(), reinterpret_cast<const uint8_t*>(handles.data()),
Patrick Williams70a47ba2021-09-02 09:53:31 -050076 requestMsg.size() - sizeof(pldm_msg_hdr), request);
77 if (rc != PLDM_SUCCESS)
78 {
Riya Dixit49cfb132023-03-02 04:26:53 -060079 error(
80 "BIOS Attribute update event message encode failure. PLDM error code = {RC}",
81 "RC", lg2::hex, rc);
Patrick Williams70a47ba2021-09-02 09:53:31 -050082 requester->markFree(eid, instanceId);
83 return rc;
84 }
85
Patrick Williams70a47ba2021-09-02 09:53:31 -050086 auto platformEventMessageResponseHandler = [](mctp_eid_t /*eid*/,
87 const pldm_msg* response,
88 size_t respMsgLen) {
89 if (response == nullptr || !respMsgLen)
90 {
Riya Dixit49cfb132023-03-02 04:26:53 -060091 error("Failed to receive response for platform event message");
Patrick Williams70a47ba2021-09-02 09:53:31 -050092 return;
93 }
94 uint8_t completionCode{};
95 uint8_t status{};
96 auto rc = decode_platform_event_message_resp(response, respMsgLen,
97 &completionCode, &status);
98 if (rc || completionCode)
99 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600100 error(
101 "Failed to decode BIOS Attribute update platform_event_message_resp: rc = {RC}, cc= {CC}",
102 "RC", rc, "CC", static_cast<unsigned>(completionCode));
Patrick Williams70a47ba2021-09-02 09:53:31 -0500103 }
104 };
105 rc = handler->registerRequest(
106 eid, instanceId, PLDM_PLATFORM, PLDM_PLATFORM_EVENT_MESSAGE,
107 std::move(requestMsg), std::move(platformEventMessageResponseHandler));
108 if (rc)
109 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600110 error(
111 "Failed to send BIOS Attribute update the platform event message");
Patrick Williams70a47ba2021-09-02 09:53:31 -0500112 }
113
114 return rc;
115}
116
117} // namespace platform
118
119} // namespace responder
120
121} // namespace pldm