xref: /openbmc/pldm/libpldmresponder/base.hpp (revision c453e164)
1 #pragma once
2 
3 #include "libpldmresponder/platform.hpp"
4 #include "pldmd/handler.hpp"
5 #include "requester/handler.hpp"
6 
7 #include <libpldm/base.h>
8 #include <stdint.h>
9 
10 #include <sdeventplus/source/event.hpp>
11 
12 #include <vector>
13 
14 using namespace pldm::dbus_api;
15 using namespace pldm::responder;
16 
17 namespace pldm
18 {
19 namespace responder
20 {
21 namespace base
22 {
23 
24 class Handler : public CmdHandler
25 {
26   public:
27     Handler(uint8_t eid, Requester& requester, sdeventplus::Event& event,
28             pldm::responder::oem_platform::Handler* oemPlatformHandler,
29             pldm::requester::Handler<pldm::requester::Request>* handler) :
30         eid(eid),
31         requester(requester), event(event),
32         oemPlatformHandler(oemPlatformHandler), handler(handler)
33     {
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 
76     /** @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 
84     /** @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);
91 
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 OEM platform handler */
107     pldm::responder::oem_platform::Handler* oemPlatformHandler;
108 
109     /** @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;
114 };
115 
116 } // namespace base
117 } // namespace responder
118 } // namespace pldm
119