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