blob: 8063efbc675868258324e4d6832f2c8e04b019a6 [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) :
67 dBusIntf(dBusIntf),
68 mctp_fd(mctp_fd), mctp_eid(mctp_eid), repo(repo),
69 instanceIdDb(instanceIdDb), event(event), invoker(invoker),
70 reqHandler(reqHandler)
71 {
72 createOemFruHandler();
73 fruHandler->setOemFruHandler(oemFruHandler.get());
74
75 createOemIbmFruHandler();
76 oemIbmFruHandler->setIBMFruHandler(fruHandler);
77
78 createCodeUpdate();
79 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());
86
87 createOemIbmPlatformHandler();
88 oemIbmPlatformHandler->setPlatformHandler(platformHandler);
89
George Liub49b7d82021-02-08 14:10:17 +080090 createHostLampTestHandler();
91
George Liua881c172021-06-21 18:28:11 +080092 registerHandler();
93 }
94
95 private:
96 /** @brief Method for creating codeUpdate handler */
97 void createCodeUpdate()
98 {
99 codeUpdate = std::make_unique<pldm::responder::CodeUpdate>(dBusIntf);
100 codeUpdate->clearDirPath(LID_STAGING_DIR);
101 }
102
103 /** @brief Method for creating oemPlatformHandler
104 *
105 * This method also assigns the oemPlatformHandler to the below
106 * different handlers.
107 */
108 void createOemPlatformHandler()
109 {
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530110 oemPlatformHandler =
111 std::make_unique<responder::oem_ibm_platform::Handler>(
112 dBusIntf, codeUpdate.get(), mctp_fd, mctp_eid, instanceIdDb,
113 event, reqHandler);
George Liua881c172021-06-21 18:28:11 +0800114 }
115
116 /** @brief Method for creating oemIbmPlatformHandler */
117 void createOemIbmPlatformHandler()
118 {
119 oemIbmPlatformHandler =
120 dynamic_cast<pldm::responder::oem_ibm_platform::Handler*>(
121 oemPlatformHandler.get());
122 }
123
124 /** @brief Method for creating oemFruHandler */
125 void createOemFruHandler()
126 {
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530127 oemFruHandler = std::make_unique<responder::oem_ibm_fru::Handler>(repo);
George Liua881c172021-06-21 18:28:11 +0800128 }
129
Kamalkumar Pateleb43d6c2024-05-01 06:11:31 -0500130 /** @brief Method for creating oemIbmUtilsHandler */
131 void createOemIbmUtilsHandler()
132 {
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530133 oemUtilsHandler =
134 std::make_unique<responder::oem_ibm_utils::Handler>(dBusIntf);
Kamalkumar Pateleb43d6c2024-05-01 06:11:31 -0500135 }
136
George Liua881c172021-06-21 18:28:11 +0800137 /** @brief Method for creating oemIbmFruHandler */
138 void createOemIbmFruHandler()
139 {
140 oemIbmFruHandler = dynamic_cast<pldm::responder::oem_ibm_fru::Handler*>(
141 oemFruHandler.get());
142 }
143
George Liub49b7d82021-02-08 14:10:17 +0800144 void createHostLampTestHandler()
145 {
146 auto& bus = pldm::utils::DBusHandler::getBus();
147 hostLampTest = std::make_unique<pldm::led::HostLampTest>(
148 bus, "/xyz/openbmc_project/led/groups/host_lamp_test", mctp_eid,
149 instanceIdDb, repo, reqHandler);
150 }
151
George Liua881c172021-06-21 18:28:11 +0800152 /** @brief Method for registering PLDM OEM handler */
153 void registerHandler()
154 {
155 invoker.registerHandler(
156 PLDM_OEM, std::make_unique<pldm::responder::oem_ibm::Handler>(
157 oemPlatformHandler.get(), mctp_fd, mctp_eid,
158 &instanceIdDb, reqHandler));
159 }
160
161 private:
162 /** @brief D-Bus handler */
163 const pldm::utils::DBusHandler* dBusIntf;
164
165 /** @brief fd of MCTP communications socket */
166 int mctp_fd;
167
168 /** @brief MCTP EID of remote host firmware */
169 uint8_t mctp_eid;
170
171 /** @brief pointer to BMC's primary PDR repo */
172 pldm_pdr* repo;
173
174 /** @brief reference to an Instance ID database object, used to obtain PLDM
175 * instance IDs
176 */
177 pldm::InstanceIdDb& instanceIdDb;
178
179 /** @brief reference of main event loop of pldmd, primarily used to schedule
180 * work
181 */
182 sdeventplus::Event& event;
183
184 /** @brief Object to the invoker class*/
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530185 responder::Invoker& invoker;
George Liua881c172021-06-21 18:28:11 +0800186
187 /** @brief pointer to the requester class*/
188 requester::Handler<requester::Request>* reqHandler;
189
190 /** @brief pointer to the oem_ibm_handler class*/
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530191 std::unique_ptr<responder::oem_platform::Handler> oemPlatformHandler{};
George Liua881c172021-06-21 18:28:11 +0800192
193 /** @brief pointer to the oem_ibm_fru class*/
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530194 std::unique_ptr<responder::oem_fru::Handler> oemFruHandler{};
George Liua881c172021-06-21 18:28:11 +0800195
196 /** @brief pointer to the CodeUpdate class*/
197 std::unique_ptr<pldm::responder::CodeUpdate> codeUpdate{};
198
199 /** @brief oem IBM Platform handler*/
200 pldm::responder::oem_ibm_platform::Handler* oemIbmPlatformHandler = nullptr;
201
202 /** @brief oem IBM Fru handler*/
203 pldm::responder::oem_ibm_fru::Handler* oemIbmFruHandler = nullptr;
George Liub49b7d82021-02-08 14:10:17 +0800204
205 std::unique_ptr<pldm::led::HostLampTest> hostLampTest;
Kamalkumar Pateleb43d6c2024-05-01 06:11:31 -0500206
207 /** @brief oem IBM Utils handler*/
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530208 std::unique_ptr<responder::oem_utils::Handler> oemUtilsHandler;
George Liua881c172021-06-21 18:28:11 +0800209};
210
211} // namespace oem_ibm
212} // namespace pldm