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::responder; 15 16 namespace pldm 17 { 18 namespace responder 19 { 20 namespace base 21 { 22 class Handler : public CmdHandler 23 { 24 public: 25 Handler(uint8_t eid, pldm::InstanceIdDb& instanceIdDb, 26 sdeventplus::Event& event, 27 pldm::responder::oem_platform::Handler* oemPlatformHandler, 28 pldm::requester::Handler<pldm::requester::Request>* handler) : 29 eid(eid), 30 instanceIdDb(instanceIdDb), event(event), 31 oemPlatformHandler(oemPlatformHandler), handler(handler) 32 { 33 handlers.emplace(PLDM_GET_PLDM_TYPES, 34 [this](const pldm_msg* request, size_t payloadLength) { 35 return this->getPLDMTypes(request, payloadLength); 36 }); 37 handlers.emplace(PLDM_GET_PLDM_COMMANDS, 38 [this](const pldm_msg* request, size_t payloadLength) { 39 return this->getPLDMCommands(request, payloadLength); 40 }); 41 handlers.emplace(PLDM_GET_PLDM_VERSION, 42 [this](const pldm_msg* request, size_t payloadLength) { 43 return this->getPLDMVersion(request, payloadLength); 44 }); 45 handlers.emplace(PLDM_GET_TID, 46 [this](const pldm_msg* request, size_t payloadLength) { 47 return this->getTID(request, payloadLength); 48 }); 49 } 50 51 /** @brief Handler for getPLDMTypes 52 * 53 * @param[in] request - Request message payload 54 * @param[in] payload_length - Request message payload length 55 * @param[return] Response - PLDM Response message 56 */ 57 Response getPLDMTypes(const pldm_msg* request, size_t payloadLength); 58 59 /** @brief Handler for getPLDMCommands 60 * 61 * @param[in] request - Request message payload 62 * @param[in] payload_length - Request message payload length 63 * @param[return] Response - PLDM Response message 64 */ 65 Response getPLDMCommands(const pldm_msg* request, size_t payloadLength); 66 67 /** @brief Handler for getPLDMCommands 68 * 69 * @param[in] request - Request message payload 70 * @param[in] payload_length - Request message payload length 71 * @param[return] Response - PLDM Response message 72 */ 73 Response getPLDMVersion(const pldm_msg* request, size_t payloadLength); 74 75 /** @brief _processSetEventReceiver does the actual work that needs 76 * to be carried out for setEventReceiver command. This is deferred 77 * after sending response for getTID command to the host 78 * 79 * @param[in] source - sdeventplus event source 80 */ 81 void processSetEventReceiver(sdeventplus::source::EventBase& source); 82 83 /** @brief Handler for getTID 84 * 85 * @param[in] request - Request message payload 86 * @param[in] payload_length - Request message payload length 87 * @param[return] Response - PLDM Response message 88 */ 89 Response getTID(const pldm_msg* request, size_t payloadLength); 90 91 private: 92 /** @brief MCTP EID of host firmware */ 93 uint8_t eid; 94 95 /** @brief An instance ID database for allocating instance IDs. */ 96 InstanceIdDb& instanceIdDb; 97 98 /** @brief reference of main event loop of pldmd, primarily used to schedule 99 * work 100 */ 101 sdeventplus::Event& event; 102 103 /** @brief OEM platform handler */ 104 pldm::responder::oem_platform::Handler* oemPlatformHandler; 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; 111 }; 112 113 } // namespace base 114 } // namespace responder 115 } // namespace pldm 116