blob: 67ad4821a45f70b0d565318cb40f8ec3db822d34 [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();
78 createOemPlatformHandler();
Kamalkumar Pateleb43d6c2024-05-01 06:11:31 -050079 createOemIbmUtilsHandler();
George Liua881c172021-06-21 18:28:11 +080080 codeUpdate->setOemPlatformHandler(oemPlatformHandler.get());
81 hostPDRHandler->setOemPlatformHandler(oemPlatformHandler.get());
Kamalkumar Pateleb43d6c2024-05-01 06:11:31 -050082 hostPDRHandler->setOemUtilsHandler(oemUtilsHandler.get());
George Liua881c172021-06-21 18:28:11 +080083 platformHandler->setOemPlatformHandler(oemPlatformHandler.get());
84 baseHandler->setOemPlatformHandler(oemPlatformHandler.get());
85
86 createOemIbmPlatformHandler();
87 oemIbmPlatformHandler->setPlatformHandler(platformHandler);
88
George Liub49b7d82021-02-08 14:10:17 +080089 createHostLampTestHandler();
90
George Liua881c172021-06-21 18:28:11 +080091 registerHandler();
92 }
93
94 private:
95 /** @brief Method for creating codeUpdate handler */
96 void createCodeUpdate()
97 {
98 codeUpdate = std::make_unique<pldm::responder::CodeUpdate>(dBusIntf);
99 codeUpdate->clearDirPath(LID_STAGING_DIR);
100 }
101
102 /** @brief Method for creating oemPlatformHandler
103 *
104 * This method also assigns the oemPlatformHandler to the below
105 * different handlers.
106 */
107 void createOemPlatformHandler()
108 {
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530109 oemPlatformHandler =
110 std::make_unique<responder::oem_ibm_platform::Handler>(
111 dBusIntf, codeUpdate.get(), mctp_fd, mctp_eid, instanceIdDb,
112 event, reqHandler);
George Liua881c172021-06-21 18:28:11 +0800113 }
114
115 /** @brief Method for creating oemIbmPlatformHandler */
116 void createOemIbmPlatformHandler()
117 {
118 oemIbmPlatformHandler =
119 dynamic_cast<pldm::responder::oem_ibm_platform::Handler*>(
120 oemPlatformHandler.get());
121 }
122
123 /** @brief Method for creating oemFruHandler */
124 void createOemFruHandler()
125 {
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530126 oemFruHandler = std::make_unique<responder::oem_ibm_fru::Handler>(repo);
George Liua881c172021-06-21 18:28:11 +0800127 }
128
Kamalkumar Pateleb43d6c2024-05-01 06:11:31 -0500129 /** @brief Method for creating oemIbmUtilsHandler */
130 void createOemIbmUtilsHandler()
131 {
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530132 oemUtilsHandler =
133 std::make_unique<responder::oem_ibm_utils::Handler>(dBusIntf);
Kamalkumar Pateleb43d6c2024-05-01 06:11:31 -0500134 }
135
George Liua881c172021-06-21 18:28:11 +0800136 /** @brief Method for creating oemIbmFruHandler */
137 void createOemIbmFruHandler()
138 {
139 oemIbmFruHandler = dynamic_cast<pldm::responder::oem_ibm_fru::Handler*>(
140 oemFruHandler.get());
141 }
142
George Liub49b7d82021-02-08 14:10:17 +0800143 void createHostLampTestHandler()
144 {
145 auto& bus = pldm::utils::DBusHandler::getBus();
146 hostLampTest = std::make_unique<pldm::led::HostLampTest>(
147 bus, "/xyz/openbmc_project/led/groups/host_lamp_test", mctp_eid,
148 instanceIdDb, repo, reqHandler);
149 }
150
George Liua881c172021-06-21 18:28:11 +0800151 /** @brief Method for registering PLDM OEM handler */
152 void registerHandler()
153 {
154 invoker.registerHandler(
155 PLDM_OEM, std::make_unique<pldm::responder::oem_ibm::Handler>(
156 oemPlatformHandler.get(), mctp_fd, mctp_eid,
157 &instanceIdDb, reqHandler));
158 }
159
160 private:
161 /** @brief D-Bus handler */
162 const pldm::utils::DBusHandler* dBusIntf;
163
164 /** @brief fd of MCTP communications socket */
165 int mctp_fd;
166
167 /** @brief MCTP EID of remote host firmware */
168 uint8_t mctp_eid;
169
170 /** @brief pointer to BMC's primary PDR repo */
171 pldm_pdr* repo;
172
173 /** @brief reference to an Instance ID database object, used to obtain PLDM
174 * instance IDs
175 */
176 pldm::InstanceIdDb& instanceIdDb;
177
178 /** @brief reference of main event loop of pldmd, primarily used to schedule
179 * work
180 */
181 sdeventplus::Event& event;
182
183 /** @brief Object to the invoker class*/
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530184 responder::Invoker& invoker;
George Liua881c172021-06-21 18:28:11 +0800185
186 /** @brief pointer to the requester class*/
187 requester::Handler<requester::Request>* reqHandler;
188
189 /** @brief pointer to the oem_ibm_handler class*/
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530190 std::unique_ptr<responder::oem_platform::Handler> oemPlatformHandler{};
George Liua881c172021-06-21 18:28:11 +0800191
192 /** @brief pointer to the oem_ibm_fru class*/
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530193 std::unique_ptr<responder::oem_fru::Handler> oemFruHandler{};
George Liua881c172021-06-21 18:28:11 +0800194
195 /** @brief pointer to the CodeUpdate class*/
196 std::unique_ptr<pldm::responder::CodeUpdate> codeUpdate{};
197
198 /** @brief oem IBM Platform handler*/
199 pldm::responder::oem_ibm_platform::Handler* oemIbmPlatformHandler = nullptr;
200
201 /** @brief oem IBM Fru handler*/
202 pldm::responder::oem_ibm_fru::Handler* oemIbmFruHandler = nullptr;
George Liub49b7d82021-02-08 14:10:17 +0800203
204 std::unique_ptr<pldm::led::HostLampTest> hostLampTest;
Kamalkumar Pateleb43d6c2024-05-01 06:11:31 -0500205
206 /** @brief oem IBM Utils handler*/
Pavithra Barithaya928e87f2024-07-31 14:11:52 +0530207 std::unique_ptr<responder::oem_utils::Handler> oemUtilsHandler;
George Liua881c172021-06-21 18:28:11 +0800208};
209
210} // namespace oem_ibm
211} // namespace pldm