xref: /openbmc/pldm/pldmd/oem_ibm.hpp (revision 6a7682ea)
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      */
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),
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();
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 
87         createOemIbmPlatformHandler();
88         oemIbmPlatformHandler->setPlatformHandler(platformHandler);
89 
90         createHostLampTestHandler();
91 
92         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     {
110         oemPlatformHandler =
111             std::make_unique<responder::oem_ibm_platform::Handler>(
112                 dBusIntf, codeUpdate.get(), mctp_fd, mctp_eid, instanceIdDb,
113                 event, reqHandler);
114     }
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     {
127         oemFruHandler = std::make_unique<responder::oem_ibm_fru::Handler>(repo);
128     }
129 
130     /** @brief Method for creating oemIbmUtilsHandler */
131     void createOemIbmUtilsHandler()
132     {
133         oemUtilsHandler =
134             std::make_unique<responder::oem_ibm_utils::Handler>(dBusIntf);
135     }
136 
137     /** @brief Method for creating oemIbmFruHandler */
138     void createOemIbmFruHandler()
139     {
140         oemIbmFruHandler = dynamic_cast<pldm::responder::oem_ibm_fru::Handler*>(
141             oemFruHandler.get());
142     }
143 
144     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 
152     /** @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*/
185     responder::Invoker& invoker;
186 
187     /** @brief pointer to the requester class*/
188     requester::Handler<requester::Request>* reqHandler;
189 
190     /** @brief pointer to the oem_ibm_handler class*/
191     std::unique_ptr<responder::oem_platform::Handler> oemPlatformHandler{};
192 
193     /** @brief pointer to the oem_ibm_fru class*/
194     std::unique_ptr<responder::oem_fru::Handler> oemFruHandler{};
195 
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;
204 
205     std::unique_ptr<pldm::led::HostLampTest> hostLampTest;
206 
207     /** @brief oem IBM Utils handler*/
208     std::unique_ptr<responder::oem_utils::Handler> oemUtilsHandler;
209 };
210 
211 } // namespace oem_ibm
212 } // namespace pldm
213