blob: 195e221ad4e88e0f8d78b8dceb82fe975f15558a [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"
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -05004#include "libpldm/platform.h"
George Liu6492f522020-06-16 10:34:05 +08005
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -05006#include "pldmd/dbus_impl_requester.hpp"
Deepak Kodihalli1521f6d2020-06-16 08:51:02 -05007#include "pldmd/handler.hpp"
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -05008#include "requester/handler.hpp"
Deepak Kodihallibc669f12019-11-28 08:52:07 -06009
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060010#include <stdint.h>
11
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050012#include <sdeventplus/source/event.hpp>
13
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060014#include <vector>
15
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050016using namespace pldm::dbus_api;
17using namespace pldm::responder;
18
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060019namespace pldm
20{
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060021namespace responder
22{
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050023namespace base
24{
Deepak Kodihallibc669f12019-11-28 08:52:07 -060025
26class Handler : public CmdHandler
27{
28 public:
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050029 Handler(uint8_t eid, Requester& requester, sdeventplus::Event& event,
30 pldm::requester::Handler<pldm::requester::Request>* handler) :
31 eid(eid),
32 requester(requester), event(event), 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
106 /** @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