blob: 600312527a32c591a936a36c83ce0ebde9c2a8b6 [file] [log] [blame]
George Liua881c172021-06-21 18:28:11 +08001#pragma once
2
George Liub49b7d82021-02-08 14:10:17 +08003#include "../oem/ibm/host-bmc/host_lamp_test.hpp"
George Liua881c172021-06-21 18:28:11 +08004#include "../oem/ibm/libpldmresponder/file_io.hpp"
5#include "../oem/ibm/libpldmresponder/fru_oem_ibm.hpp"
6#include "../oem/ibm/libpldmresponder/oem_ibm_handler.hpp"
Kamalkumar Pateleb43d6c2024-05-01 06:11:31 -05007#include "../oem/ibm/libpldmresponder/utils.hpp"
George Liua881c172021-06-21 18:28:11 +08008#include "common/utils.hpp"
9#include "dbus_impl_requester.hpp"
10#include "host-bmc/dbus_to_event_handler.hpp"
11#include "invoker.hpp"
Pavithra Barithaya928e87f2024-07-31 14:11:52 +053012#include "libpldmresponder/base.hpp"
George Liua881c172021-06-21 18:28:11 +080013#include "libpldmresponder/fru.hpp"
14#include "requester/request.hpp"
15
Andrew Jeffery41ca40d2024-06-19 16:52:21 +093016#include <libpldm/pdr.h>
17
George Liua881c172021-06-21 18:28:11 +080018namespace pldm
19{
20namespace oem_ibm
21{
22
23using namespace pldm::state_sensor;
24using namespace pldm::dbus_api;
25
26/**
27 * @class OemIBM
28 *
29 * @brief class for creating all the OEM IBM handlers
30 *
31 * Only in case of OEM_IBM this class object will be instantiated
32 */
33class OemIBM
34{
35 public:
36 OemIBM() = delete;
37 OemIBM(const Pdr&) = delete;
38 OemIBM& operator=(const OemIBM&) = delete;
39 OemIBM(OemIBM&&) = delete;
40 OemIBM& operator=(OemIBM&&) = delete;
41
42 public:
43 /** Constructs OemIBM object
44 *
45 * @param[in] dBusIntf - D-Bus handler
46 * @param[in] mctp_fd - fd of MCTP communications socket
47 * @param[in] mctp_eid - MCTP EID of remote host firmware
48 * @param[in] repo - pointer to BMC's primary PDR repo
49 * @param[in] instanceIdDb - pointer to an InstanceIdDb object
50 * @param[in] event - sd_event handler
51 * @param[in] invoker - invoker handler
52 * @param[in] hostPDRHandler - hostPDRHandler handler
53 * @param[in] platformHandler - platformHandler handler
54 * @param[in] fruHandler - fruHandler handler
55 * @param[in] baseHandler - baseHandler handler
56 * @param[in] reqHandler - reqHandler handler
57 */
58 explicit OemIBM(
59 const pldm::utils::DBusHandler* dBusIntf, int mctp_fd, uint8_t mctp_eid,
60 pldm_pdr* repo, pldm::InstanceIdDb& instanceIdDb,
Pavithra Barithaya928e87f2024-07-31 14:11:52 +053061 sdeventplus::Event& event, responder::Invoker& invoker,
62 HostPDRHandler* hostPDRHandler,
63 responder::platform::Handler* platformHandler,
64 responder::fru::Handler* fruHandler,
65 responder::base::Handler* baseHandler,
George Liua881c172021-06-21 18:28:11 +080066 pldm::requester::Handler<pldm::requester::Request>* reqHandler) :
Patrick Williams16c2a0a2024-08-16 15:20:59 -040067 dBusIntf(dBusIntf), mctp_fd(mctp_fd), mctp_eid(mctp_eid), repo(repo),
George Liua881c172021-06-21 18:28:11 +080068 instanceIdDb(instanceIdDb), event(event), invoker(invoker),
69 reqHandler(reqHandler)
70 {
71 createOemFruHandler();
72 fruHandler->setOemFruHandler(oemFruHandler.get());
73
74 createOemIbmFruHandler();
75 oemIbmFruHandler->setIBMFruHandler(fruHandler);
76
77 createCodeUpdate();
Manojkiran Edaa31ceb92021-07-22 09:19:02 +053078 createSlotHandler();
George Liua881c172021-06-21 18:28:11 +080079 createOemPlatformHandler();
Kamalkumar Pateleb43d6c2024-05-01 06:11:31 -050080 createOemIbmUtilsHandler();
George Liua881c172021-06-21 18:28:11 +080081 codeUpdate->setOemPlatformHandler(oemPlatformHandler.get());
82 hostPDRHandler->setOemPlatformHandler(oemPlatformHandler.get());
Kamalkumar Pateleb43d6c2024-05-01 06:11:31 -050083 hostPDRHandler->setOemUtilsHandler(oemUtilsHandler.get());
George Liua881c172021-06-21 18:28:11 +080084 platformHandler->setOemPlatformHandler(oemPlatformHandler.get());
85 baseHandler->setOemPlatformHandler(oemPlatformHandler.get());
Manojkiran Edaa31ceb92021-07-22 09:19:02 +053086 slotHandler->setOemPlatformHandler(oemPlatformHandler.get());
George Liua881c172021-06-21 18:28:11 +080087
88 createOemIbmPlatformHandler();
89 oemIbmPlatformHandler->setPlatformHandler(platformHandler);
90
George Liub49b7d82021-02-08 14:10:17 +080091 createHostLampTestHandler();
92
George Liua881c172021-06-21 18:28:11 +080093 registerHandler();
94 }
95
96 private:
97 /** @brief Method for creating codeUpdate handler */
98 void createCodeUpdate()
99 {
100 codeUpdate = std::make_unique<pldm::responder::CodeUpdate>(dBusIntf);
101 codeUpdate->clearDirPath(LID_STAGING_DIR);
102 }
103
Manojkiran Edaa31ceb92021-07-22 09:19:02 +0530104 /** @brief Method for creating slot handler */
105 void createSlotHandler()
106 {
107 slotHandler =
108 std::make_unique<pldm::responder::SlotHandler>(event, repo);
109 }
110
George Liua881c172021-06-21 18:28:11 +0800111 /** @brief Method for creating oemPlatformHandler
112 *
113 * This method also assigns the oemPlatformHandler to the below
114 * different handlers.
115 */
116 void createOemPlatformHandler()
117 {
Manojkiran Edaa31ceb92021-07-22 09:19:02 +0530118 oemPlatformHandler = std::make_unique<oem_ibm_platform::Handler>(
119 dBusIntf, codeUpdate.get(), slotHandler.get(), mctp_fd, mctp_eid,
120 instanceIdDb, event, reqHandler);
George Liua881c172021-06-21 18:28:11 +0800121 }
122
123 /** @brief Method for creating oemIbmPlatformHandler */
124 void createOemIbmPlatformHandler()
125 {
126 oemIbmPlatformHandler =
127 dynamic_cast<pldm::responder::oem_ibm_platform::Handler*>(
128 oemPlatformHandler.get());
129 }
130
131 /** @brief Method for creating oemFruHandler */
132 void createOemFruHandler()
133 {
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530134 oemFruHandler = std::make_unique<responder::oem_ibm_fru::Handler>(repo);
George Liua881c172021-06-21 18:28:11 +0800135 }
136
Kamalkumar Pateleb43d6c2024-05-01 06:11:31 -0500137 /** @brief Method for creating oemIbmUtilsHandler */
138 void createOemIbmUtilsHandler()
139 {
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530140 oemUtilsHandler =
141 std::make_unique<responder::oem_ibm_utils::Handler>(dBusIntf);
Kamalkumar Pateleb43d6c2024-05-01 06:11:31 -0500142 }
143
George Liua881c172021-06-21 18:28:11 +0800144 /** @brief Method for creating oemIbmFruHandler */
145 void createOemIbmFruHandler()
146 {
147 oemIbmFruHandler = dynamic_cast<pldm::responder::oem_ibm_fru::Handler*>(
148 oemFruHandler.get());
149 }
150
George Liub49b7d82021-02-08 14:10:17 +0800151 void createHostLampTestHandler()
152 {
153 auto& bus = pldm::utils::DBusHandler::getBus();
154 hostLampTest = std::make_unique<pldm::led::HostLampTest>(
155 bus, "/xyz/openbmc_project/led/groups/host_lamp_test", mctp_eid,
156 instanceIdDb, repo, reqHandler);
157 }
158
George Liua881c172021-06-21 18:28:11 +0800159 /** @brief Method for registering PLDM OEM handler */
160 void registerHandler()
161 {
162 invoker.registerHandler(
163 PLDM_OEM, std::make_unique<pldm::responder::oem_ibm::Handler>(
164 oemPlatformHandler.get(), mctp_fd, mctp_eid,
165 &instanceIdDb, reqHandler));
166 }
167
168 private:
169 /** @brief D-Bus handler */
170 const pldm::utils::DBusHandler* dBusIntf;
171
172 /** @brief fd of MCTP communications socket */
173 int mctp_fd;
174
175 /** @brief MCTP EID of remote host firmware */
176 uint8_t mctp_eid;
177
178 /** @brief pointer to BMC's primary PDR repo */
179 pldm_pdr* repo;
180
181 /** @brief reference to an Instance ID database object, used to obtain PLDM
182 * instance IDs
183 */
184 pldm::InstanceIdDb& instanceIdDb;
185
186 /** @brief reference of main event loop of pldmd, primarily used to schedule
187 * work
188 */
189 sdeventplus::Event& event;
190
191 /** @brief Object to the invoker class*/
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530192 responder::Invoker& invoker;
George Liua881c172021-06-21 18:28:11 +0800193
194 /** @brief pointer to the requester class*/
195 requester::Handler<requester::Request>* reqHandler;
196
197 /** @brief pointer to the oem_ibm_handler class*/
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530198 std::unique_ptr<responder::oem_platform::Handler> oemPlatformHandler{};
George Liua881c172021-06-21 18:28:11 +0800199
200 /** @brief pointer to the oem_ibm_fru class*/
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530201 std::unique_ptr<responder::oem_fru::Handler> oemFruHandler{};
George Liua881c172021-06-21 18:28:11 +0800202
203 /** @brief pointer to the CodeUpdate class*/
204 std::unique_ptr<pldm::responder::CodeUpdate> codeUpdate{};
205
Manojkiran Edaa31ceb92021-07-22 09:19:02 +0530206 /** @brief pointer to the SlotHanlder class*/
207 std::unique_ptr<pldm::responder::SlotHandler> slotHandler{};
208
George Liua881c172021-06-21 18:28:11 +0800209 /** @brief oem IBM Platform handler*/
210 pldm::responder::oem_ibm_platform::Handler* oemIbmPlatformHandler = nullptr;
211
212 /** @brief oem IBM Fru handler*/
213 pldm::responder::oem_ibm_fru::Handler* oemIbmFruHandler = nullptr;
George Liub49b7d82021-02-08 14:10:17 +0800214
215 std::unique_ptr<pldm::led::HostLampTest> hostLampTest;
Kamalkumar Pateleb43d6c2024-05-01 06:11:31 -0500216
217 /** @brief oem IBM Utils handler*/
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530218 std::unique_ptr<responder::oem_utils::Handler> oemUtilsHandler;
George Liua881c172021-06-21 18:28:11 +0800219};
220
221} // namespace oem_ibm
222} // namespace pldm