blob: 1bd88f87fc197911be7154a6c202b3818427c38c [file] [log] [blame]
Deepak Kodihalli1b24f972019-02-01 04:09:13 -06001#pragma once
2
Sagar Srinivas79669c92021-04-28 15:43:30 -05003#include "libpldmresponder/platform.hpp"
Deepak Kodihalli1521f6d2020-06-16 08:51:02 -05004#include "pldmd/handler.hpp"
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -05005#include "requester/handler.hpp"
Deepak Kodihallibc669f12019-11-28 08:52:07 -06006
George Liuc453e162022-12-21 17:16:23 +08007#include <libpldm/base.h>
Deepak Kodihalli1b24f972019-02-01 04:09:13 -06008#include <stdint.h>
9
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050010#include <sdeventplus/source/event.hpp>
11
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060012#include <vector>
13
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050014using namespace pldm::responder;
15
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060016namespace pldm
17{
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060018namespace responder
19{
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050020namespace base
21{
Deepak Kodihallibc669f12019-11-28 08:52:07 -060022class Handler : public CmdHandler
23{
24 public:
Andrew Jefferya330b2f2023-05-04 14:55:37 +093025 Handler(uint8_t eid, pldm::InstanceIdDb& instanceIdDb,
26 sdeventplus::Event& event,
Sagar Srinivas79669c92021-04-28 15:43:30 -050027 pldm::responder::oem_platform::Handler* oemPlatformHandler,
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050028 pldm::requester::Handler<pldm::requester::Request>* handler) :
29 eid(eid),
Andrew Jefferya330b2f2023-05-04 14:55:37 +093030 instanceIdDb(instanceIdDb), event(event),
Sagar Srinivas79669c92021-04-28 15:43:30 -050031 oemPlatformHandler(oemPlatformHandler), handler(handler)
Deepak Kodihallibc669f12019-11-28 08:52:07 -060032 {
33 handlers.emplace(PLDM_GET_PLDM_TYPES,
34 [this](const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050035 return this->getPLDMTypes(request, payloadLength);
36 });
37 handlers.emplace(PLDM_GET_PLDM_COMMANDS,
38 [this](const pldm_msg* request, size_t payloadLength) {
Deepak Kodihallibc669f12019-11-28 08:52:07 -060039 return this->getPLDMCommands(request, payloadLength);
40 });
Patrick Williams6da4f912023-05-10 07:50:53 -050041 handlers.emplace(PLDM_GET_PLDM_VERSION,
42 [this](const pldm_msg* request, size_t payloadLength) {
Deepak Kodihallibc669f12019-11-28 08:52:07 -060043 return this->getPLDMVersion(request, payloadLength);
44 });
45 handlers.emplace(PLDM_GET_TID,
46 [this](const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050047 return this->getTID(request, payloadLength);
48 });
Deepak Kodihallibc669f12019-11-28 08:52:07 -060049 }
50
51 /** @brief Handler for getPLDMTypes
52 *
53 * @param[in] request - Request message payload
54 * @param[in] payload_length - Request message payload length
55 * @param[return] Response - PLDM Response message
56 */
57 Response getPLDMTypes(const pldm_msg* request, size_t payloadLength);
58
59 /** @brief Handler for getPLDMCommands
60 *
61 * @param[in] request - Request message payload
62 * @param[in] payload_length - Request message payload length
63 * @param[return] Response - PLDM Response message
64 */
65 Response getPLDMCommands(const pldm_msg* request, size_t payloadLength);
66
67 /** @brief Handler for getPLDMCommands
68 *
69 * @param[in] request - Request message payload
70 * @param[in] payload_length - Request message payload length
71 * @param[return] Response - PLDM Response message
72 */
73 Response getPLDMVersion(const pldm_msg* request, size_t payloadLength);
74
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050075 /** @brief _processSetEventReceiver does the actual work that needs
76 * to be carried out for setEventReceiver command. This is deferred
77 * after sending response for getTID command to the host
78 *
79 * @param[in] source - sdeventplus event source
80 */
81 void processSetEventReceiver(sdeventplus::source::EventBase& source);
82
Deepak Kodihallibc669f12019-11-28 08:52:07 -060083 /** @brief Handler for getTID
84 *
85 * @param[in] request - Request message payload
86 * @param[in] payload_length - Request message payload length
87 * @param[return] Response - PLDM Response message
88 */
89 Response getTID(const pldm_msg* request, size_t payloadLength);
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050090
91 private:
92 /** @brief MCTP EID of host firmware */
93 uint8_t eid;
94
Andrew Jefferya330b2f2023-05-04 14:55:37 +093095 /** @brief An instance ID database for allocating instance IDs. */
96 InstanceIdDb& instanceIdDb;
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050097
98 /** @brief reference of main event loop of pldmd, primarily used to schedule
99 * work
100 */
101 sdeventplus::Event& event;
102
Sagar Srinivas79669c92021-04-28 15:43:30 -0500103 /** @brief OEM platform handler */
104 pldm::responder::oem_platform::Handler* oemPlatformHandler;
105
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -0500106 /** @brief PLDM request handler */
107 pldm::requester::Handler<pldm::requester::Request>* handler;
108
109 /** @brief sdeventplus event source */
110 std::unique_ptr<sdeventplus::source::Defer> survEvent;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600111};
112
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500113} // namespace base
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600114} // namespace responder
115} // namespace pldm