blob: 8ec7923995685ccfce77e788ae4bd0008944dab8 [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::dbus_api;
15using namespace pldm::responder;
16
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060017namespace pldm
18{
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060019namespace responder
20{
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050021namespace base
22{
Deepak Kodihallibc669f12019-11-28 08:52:07 -060023
24class Handler : public CmdHandler
25{
26 public:
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050027 Handler(uint8_t eid, Requester& requester, sdeventplus::Event& event,
Sagar Srinivas79669c92021-04-28 15:43:30 -050028 pldm::responder::oem_platform::Handler* oemPlatformHandler,
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050029 pldm::requester::Handler<pldm::requester::Request>* handler) :
30 eid(eid),
Sagar Srinivas79669c92021-04-28 15:43:30 -050031 requester(requester), event(event),
32 oemPlatformHandler(oemPlatformHandler), handler(handler)
Deepak Kodihallibc669f12019-11-28 08:52:07 -060033 {
34 handlers.emplace(PLDM_GET_PLDM_TYPES,
35 [this](const pldm_msg* request, size_t payloadLength) {
36 return this->getPLDMTypes(request, payloadLength);
37 });
38 handlers.emplace(PLDM_GET_PLDM_COMMANDS, [this](const pldm_msg* request,
39 size_t payloadLength) {
40 return this->getPLDMCommands(request, payloadLength);
41 });
42 handlers.emplace(PLDM_GET_PLDM_VERSION, [this](const pldm_msg* request,
43 size_t payloadLength) {
44 return this->getPLDMVersion(request, payloadLength);
45 });
46 handlers.emplace(PLDM_GET_TID,
47 [this](const pldm_msg* request, size_t payloadLength) {
48 return this->getTID(request, payloadLength);
49 });
50 }
51
52 /** @brief Handler for getPLDMTypes
53 *
54 * @param[in] request - Request message payload
55 * @param[in] payload_length - Request message payload length
56 * @param[return] Response - PLDM Response message
57 */
58 Response getPLDMTypes(const pldm_msg* request, size_t payloadLength);
59
60 /** @brief Handler for getPLDMCommands
61 *
62 * @param[in] request - Request message payload
63 * @param[in] payload_length - Request message payload length
64 * @param[return] Response - PLDM Response message
65 */
66 Response getPLDMCommands(const pldm_msg* request, size_t payloadLength);
67
68 /** @brief Handler for getPLDMCommands
69 *
70 * @param[in] request - Request message payload
71 * @param[in] payload_length - Request message payload length
72 * @param[return] Response - PLDM Response message
73 */
74 Response getPLDMVersion(const pldm_msg* request, size_t payloadLength);
75
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050076 /** @brief _processSetEventReceiver does the actual work that needs
77 * to be carried out for setEventReceiver command. This is deferred
78 * after sending response for getTID command to the host
79 *
80 * @param[in] source - sdeventplus event source
81 */
82 void processSetEventReceiver(sdeventplus::source::EventBase& source);
83
Deepak Kodihallibc669f12019-11-28 08:52:07 -060084 /** @brief Handler for getTID
85 *
86 * @param[in] request - Request message payload
87 * @param[in] payload_length - Request message payload length
88 * @param[return] Response - PLDM Response message
89 */
90 Response getTID(const pldm_msg* request, size_t payloadLength);
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050091
92 private:
93 /** @brief MCTP EID of host firmware */
94 uint8_t eid;
95
96 /** @brief reference to Requester object, primarily used to access API to
97 * obtain PLDM instance id.
98 */
99 Requester& requester;
100
101 /** @brief reference of main event loop of pldmd, primarily used to schedule
102 * work
103 */
104 sdeventplus::Event& event;
105
Sagar Srinivas79669c92021-04-28 15:43:30 -0500106 /** @brief OEM platform handler */
107 pldm::responder::oem_platform::Handler* oemPlatformHandler;
108
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -0500109 /** @brief PLDM request handler */
110 pldm::requester::Handler<pldm::requester::Request>* handler;
111
112 /** @brief sdeventplus event source */
113 std::unique_ptr<sdeventplus::source::Defer> survEvent;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600114};
115
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500116} // namespace base
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600117} // namespace responder
118} // namespace pldm