blob: e46b32c98029910a1843a24da57f52acea09eebd [file] [log] [blame]
Deepak Kodihalli1b24f972019-02-01 04:09:13 -06001#pragma once
2
Sagar Srinivas79669c92021-04-28 15:43:30 -05003#include "libpldmresponder/platform.hpp"
Deepak Kodihallibc669f12019-11-28 08:52:07 -06004
George Liuc453e162022-12-21 17:16:23 +08005#include <libpldm/base.h>
Deepak Kodihalli1b24f972019-02-01 04:09:13 -06006
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -05007#include <sdeventplus/source/event.hpp>
8
Pavithra Barithayab3b84b42024-08-23 11:43:57 +05309#include <cstdint>
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060010#include <vector>
11
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050012using namespace pldm::responder;
13
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060014namespace pldm
15{
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060016namespace responder
17{
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050018namespace base
19{
Deepak Kodihallibc669f12019-11-28 08:52:07 -060020class Handler : public CmdHandler
21{
22 public:
George Liua881c172021-06-21 18:28:11 +080023 Handler(sdeventplus::Event& event) : event(event)
Deepak Kodihallibc669f12019-11-28 08:52:07 -060024 {
Delphine CC Chiud2e48992023-12-05 16:29:51 +080025 handlers.emplace(
26 PLDM_GET_PLDM_TYPES,
27 [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
Patrick Williams16c2a0a2024-08-16 15:20:59 -040028 return this->getPLDMTypes(request, payloadLength);
29 });
Delphine CC Chiud2e48992023-12-05 16:29:51 +080030 handlers.emplace(
31 PLDM_GET_PLDM_COMMANDS,
32 [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
Patrick Williams16c2a0a2024-08-16 15:20:59 -040033 return this->getPLDMCommands(request, payloadLength);
34 });
Delphine CC Chiud2e48992023-12-05 16:29:51 +080035 handlers.emplace(
36 PLDM_GET_PLDM_VERSION,
37 [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
Patrick Williams16c2a0a2024-08-16 15:20:59 -040038 return this->getPLDMVersion(request, payloadLength);
39 });
Delphine CC Chiud2e48992023-12-05 16:29:51 +080040 handlers.emplace(
41 PLDM_GET_TID,
42 [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
Patrick Williams16c2a0a2024-08-16 15:20:59 -040043 return this->getTID(request, payloadLength);
44 });
Deepak Kodihallibc669f12019-11-28 08:52:07 -060045 }
46
47 /** @brief Handler for getPLDMTypes
48 *
49 * @param[in] request - Request message payload
50 * @param[in] payload_length - Request message payload length
51 * @param[return] Response - PLDM Response message
52 */
53 Response getPLDMTypes(const pldm_msg* request, size_t payloadLength);
54
55 /** @brief Handler for getPLDMCommands
56 *
57 * @param[in] request - Request message payload
58 * @param[in] payload_length - Request message payload length
59 * @param[return] Response - PLDM Response message
60 */
61 Response getPLDMCommands(const pldm_msg* request, size_t payloadLength);
62
63 /** @brief Handler for getPLDMCommands
64 *
65 * @param[in] request - Request message payload
66 * @param[in] payload_length - Request message payload length
67 * @param[return] Response - PLDM Response message
68 */
69 Response getPLDMVersion(const pldm_msg* request, size_t payloadLength);
70
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050071 /** @brief _processSetEventReceiver does the actual work that needs
72 * to be carried out for setEventReceiver command. This is deferred
73 * after sending response for getTID command to the host
74 *
75 * @param[in] source - sdeventplus event source
76 */
Sagar Srinivas90314a32023-10-17 10:38:03 -050077 void _processSetEventReceiver(sdeventplus::source::EventBase& source);
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050078
Deepak Kodihallibc669f12019-11-28 08:52:07 -060079 /** @brief Handler for getTID
80 *
81 * @param[in] request - Request message payload
82 * @param[in] payload_length - Request message payload length
83 * @param[return] Response - PLDM Response message
84 */
85 Response getTID(const pldm_msg* request, size_t payloadLength);
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050086
George Liua881c172021-06-21 18:28:11 +080087 /* @brief Method to set the oem platform handler in base handler class
88 *
89 * @param[in] handler - oem platform handler
90 */
91 inline void
92 setOemPlatformHandler(pldm::responder::oem_platform::Handler* handler)
93 {
94 oemPlatformHandler = handler;
95 }
96
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050097 private:
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -050098 /** @brief reference of main event loop of pldmd, primarily used to schedule
99 * work
100 */
101 sdeventplus::Event& event;
102
Sagar Srinivas79669c92021-04-28 15:43:30 -0500103 /** @brief OEM platform handler */
George Liua881c172021-06-21 18:28:11 +0800104 pldm::responder::oem_platform::Handler* oemPlatformHandler = nullptr;
Sagar Srinivas79669c92021-04-28 15:43:30 -0500105
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -0500106 /** @brief sdeventplus event source */
107 std::unique_ptr<sdeventplus::source::Defer> survEvent;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600108};
109
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500110} // namespace base
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600111} // namespace responder
112} // namespace pldm