xref: /openbmc/pldm/pldmd/oem_ibm.hpp (revision a31ceb91)
1 #pragma once
2 
3 #include "../oem/ibm/host-bmc/host_lamp_test.hpp"
4 #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"
7 #include "../oem/ibm/libpldmresponder/utils.hpp"
8 #include "common/utils.hpp"
9 #include "dbus_impl_requester.hpp"
10 #include "host-bmc/dbus_to_event_handler.hpp"
11 #include "invoker.hpp"
12 #include "libpldmresponder/base.hpp"
13 #include "libpldmresponder/fru.hpp"
14 #include "requester/request.hpp"
15 
16 #include <libpldm/pdr.h>
17 
18 namespace pldm
19 {
20 namespace oem_ibm
21 {
22 
23 using namespace pldm::state_sensor;
24 using 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  */
33 class 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      */
OemIBM(const pldm::utils::DBusHandler * dBusIntf,int mctp_fd,uint8_t mctp_eid,pldm_pdr * repo,pldm::InstanceIdDb & instanceIdDb,sdeventplus::Event & event,responder::Invoker & invoker,HostPDRHandler * hostPDRHandler,responder::platform::Handler * platformHandler,responder::fru::Handler * fruHandler,responder::base::Handler * baseHandler,pldm::requester::Handler<pldm::requester::Request> * reqHandler)58     explicit OemIBM(
59         const pldm::utils::DBusHandler* dBusIntf, int mctp_fd, uint8_t mctp_eid,
60         pldm_pdr* repo, pldm::InstanceIdDb& instanceIdDb,
61         sdeventplus::Event& event, responder::Invoker& invoker,
62         HostPDRHandler* hostPDRHandler,
63         responder::platform::Handler* platformHandler,
64         responder::fru::Handler* fruHandler,
65         responder::base::Handler* baseHandler,
66         pldm::requester::Handler<pldm::requester::Request>* reqHandler) :
67         dBusIntf(dBusIntf), mctp_fd(mctp_fd), mctp_eid(mctp_eid), repo(repo),
68         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         createSlotHandler();
79         createOemPlatformHandler();
80         createOemIbmUtilsHandler();
81         codeUpdate->setOemPlatformHandler(oemPlatformHandler.get());
82         hostPDRHandler->setOemPlatformHandler(oemPlatformHandler.get());
83         hostPDRHandler->setOemUtilsHandler(oemUtilsHandler.get());
84         platformHandler->setOemPlatformHandler(oemPlatformHandler.get());
85         baseHandler->setOemPlatformHandler(oemPlatformHandler.get());
86         slotHandler->setOemPlatformHandler(oemPlatformHandler.get());
87 
88         createOemIbmPlatformHandler();
89         oemIbmPlatformHandler->setPlatformHandler(platformHandler);
90 
91         createHostLampTestHandler();
92 
93         registerHandler();
94     }
95 
96   private:
97     /** @brief Method for creating codeUpdate handler */
createCodeUpdate()98     void createCodeUpdate()
99     {
100         codeUpdate = std::make_unique<pldm::responder::CodeUpdate>(dBusIntf);
101         codeUpdate->clearDirPath(LID_STAGING_DIR);
102     }
103 
104     /** @brief Method for creating slot handler */
createSlotHandler()105     void createSlotHandler()
106     {
107         slotHandler =
108             std::make_unique<pldm::responder::SlotHandler>(event, repo);
109     }
110 
111     /** @brief Method for creating oemPlatformHandler
112      *
113      *  This method also assigns the oemPlatformHandler to the below
114      *  different handlers.
115      */
createOemPlatformHandler()116     void createOemPlatformHandler()
117     {
118         oemPlatformHandler = std::make_unique<oem_ibm_platform::Handler>(
119             dBusIntf, codeUpdate.get(), slotHandler.get(), mctp_fd, mctp_eid,
120             instanceIdDb, event, reqHandler);
121     }
122 
123     /** @brief Method for creating oemIbmPlatformHandler */
createOemIbmPlatformHandler()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 */
createOemFruHandler()132     void createOemFruHandler()
133     {
134         oemFruHandler = std::make_unique<responder::oem_ibm_fru::Handler>(repo);
135     }
136 
137     /** @brief Method for creating oemIbmUtilsHandler */
createOemIbmUtilsHandler()138     void createOemIbmUtilsHandler()
139     {
140         oemUtilsHandler =
141             std::make_unique<responder::oem_ibm_utils::Handler>(dBusIntf);
142     }
143 
144     /** @brief Method for creating oemIbmFruHandler */
createOemIbmFruHandler()145     void createOemIbmFruHandler()
146     {
147         oemIbmFruHandler = dynamic_cast<pldm::responder::oem_ibm_fru::Handler*>(
148             oemFruHandler.get());
149     }
150 
createHostLampTestHandler()151     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 
159     /** @brief Method for registering PLDM OEM handler */
registerHandler()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*/
192     responder::Invoker& invoker;
193 
194     /** @brief pointer to the requester class*/
195     requester::Handler<requester::Request>* reqHandler;
196 
197     /** @brief pointer to the oem_ibm_handler class*/
198     std::unique_ptr<responder::oem_platform::Handler> oemPlatformHandler{};
199 
200     /** @brief pointer to the oem_ibm_fru class*/
201     std::unique_ptr<responder::oem_fru::Handler> oemFruHandler{};
202 
203     /** @brief pointer to the CodeUpdate class*/
204     std::unique_ptr<pldm::responder::CodeUpdate> codeUpdate{};
205 
206     /** @brief pointer to the SlotHanlder class*/
207     std::unique_ptr<pldm::responder::SlotHandler> slotHandler{};
208 
209     /** @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;
214 
215     std::unique_ptr<pldm::led::HostLampTest> hostLampTest;
216 
217     /** @brief oem IBM Utils handler*/
218     std::unique_ptr<responder::oem_utils::Handler> oemUtilsHandler;
219 };
220 
221 } // namespace oem_ibm
222 } // namespace pldm
223