blob: 0603b77bf3e4863610f69846581ea917c0962f5c [file] [log] [blame]
Deepak Kodihalli1b24f972019-02-01 04:09:13 -06001#pragma once
2
George Liu6492f522020-06-16 10:34:05 +08003#include "libpldm/base.h"
4
Sagar Srinivas79669c92021-04-28 15:43:30 -05005#include "libpldmresponder/platform.hpp"
Deepak Kodihalli1521f6d2020-06-16 08:51:02 -05006#include "pldmd/handler.hpp"
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -05007#include "requester/handler.hpp"
Deepak Kodihallibc669f12019-11-28 08:52:07 -06008
Deepak Kodihalli1b24f972019-02-01 04:09:13 -06009#include <stdint.h>
10
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050011#include <sdeventplus/source/event.hpp>
12
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060013#include <vector>
14
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050015using namespace pldm::dbus_api;
16using namespace pldm::responder;
17
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060018namespace pldm
19{
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060020namespace responder
21{
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050022namespace base
23{
Deepak Kodihallibc669f12019-11-28 08:52:07 -060024
25class Handler : public CmdHandler
26{
27 public:
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050028 Handler(uint8_t eid, Requester& requester, sdeventplus::Event& event,
Sagar Srinivas79669c92021-04-28 15:43:30 -050029 pldm::responder::oem_platform::Handler* oemPlatformHandler,
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050030 pldm::requester::Handler<pldm::requester::Request>* handler) :
31 eid(eid),
Sagar Srinivas79669c92021-04-28 15:43:30 -050032 requester(requester), event(event),
33 oemPlatformHandler(oemPlatformHandler), handler(handler)
Deepak Kodihallibc669f12019-11-28 08:52:07 -060034 {
35 handlers.emplace(PLDM_GET_PLDM_TYPES,
36 [this](const pldm_msg* request, size_t payloadLength) {
37 return this->getPLDMTypes(request, payloadLength);
38 });
39 handlers.emplace(PLDM_GET_PLDM_COMMANDS, [this](const pldm_msg* request,
40 size_t payloadLength) {
41 return this->getPLDMCommands(request, payloadLength);
42 });
43 handlers.emplace(PLDM_GET_PLDM_VERSION, [this](const pldm_msg* request,
44 size_t payloadLength) {
45 return this->getPLDMVersion(request, payloadLength);
46 });
47 handlers.emplace(PLDM_GET_TID,
48 [this](const pldm_msg* request, size_t payloadLength) {
49 return this->getTID(request, payloadLength);
50 });
51 }
52
53 /** @brief Handler for getPLDMTypes
54 *
55 * @param[in] request - Request message payload
56 * @param[in] payload_length - Request message payload length
57 * @param[return] Response - PLDM Response message
58 */
59 Response getPLDMTypes(const pldm_msg* request, size_t payloadLength);
60
61 /** @brief Handler for getPLDMCommands
62 *
63 * @param[in] request - Request message payload
64 * @param[in] payload_length - Request message payload length
65 * @param[return] Response - PLDM Response message
66 */
67 Response getPLDMCommands(const pldm_msg* request, size_t payloadLength);
68
69 /** @brief Handler for getPLDMCommands
70 *
71 * @param[in] request - Request message payload
72 * @param[in] payload_length - Request message payload length
73 * @param[return] Response - PLDM Response message
74 */
75 Response getPLDMVersion(const pldm_msg* request, size_t payloadLength);
76
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050077 /** @brief _processSetEventReceiver does the actual work that needs
78 * to be carried out for setEventReceiver command. This is deferred
79 * after sending response for getTID command to the host
80 *
81 * @param[in] source - sdeventplus event source
82 */
83 void processSetEventReceiver(sdeventplus::source::EventBase& source);
84
Deepak Kodihallibc669f12019-11-28 08:52:07 -060085 /** @brief Handler for getTID
86 *
87 * @param[in] request - Request message payload
88 * @param[in] payload_length - Request message payload length
89 * @param[return] Response - PLDM Response message
90 */
91 Response getTID(const pldm_msg* request, size_t payloadLength);
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050092
93 private:
94 /** @brief MCTP EID of host firmware */
95 uint8_t eid;
96
97 /** @brief reference to Requester object, primarily used to access API to
98 * obtain PLDM instance id.
99 */
100 Requester& requester;
101
102 /** @brief reference of main event loop of pldmd, primarily used to schedule
103 * work
104 */
105 sdeventplus::Event& event;
106
Sagar Srinivas79669c92021-04-28 15:43:30 -0500107 /** @brief OEM platform handler */
108 pldm::responder::oem_platform::Handler* oemPlatformHandler;
109
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -0500110 /** @brief PLDM request handler */
111 pldm::requester::Handler<pldm::requester::Request>* handler;
112
113 /** @brief sdeventplus event source */
114 std::unique_ptr<sdeventplus::source::Defer> survEvent;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600115};
116
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500117} // namespace base
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600118} // namespace responder
119} // namespace pldm