xref: /openbmc/pldm/pldmd/oem_ibm.hpp (revision 3e52d588)
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/fru.hpp"
13  #include "requester/request.hpp"
14  
15  #include <libpldm/pdr.h>
16  
17  namespace pldm
18  {
19  namespace oem_ibm
20  {
21  
22  using namespace pldm::state_sensor;
23  using namespace pldm::dbus_api;
24  
25  /**
26   * @class OemIBM
27   *
28   * @brief class for creating all the OEM IBM handlers
29   *
30   *  Only in case of OEM_IBM this class object will be instantiated
31   */
32  class OemIBM
33  {
34    public:
35      OemIBM() = delete;
36      OemIBM(const Pdr&) = delete;
37      OemIBM& operator=(const OemIBM&) = delete;
38      OemIBM(OemIBM&&) = delete;
39      OemIBM& operator=(OemIBM&&) = delete;
40  
41    public:
42      /** Constructs OemIBM object
43       *
44       * @param[in] dBusIntf - D-Bus handler
45       * @param[in] mctp_fd - fd of MCTP communications socket
46       * @param[in] mctp_eid - MCTP EID of remote host firmware
47       * @param[in] repo - pointer to BMC's primary PDR repo
48       * @param[in] instanceIdDb - pointer to an InstanceIdDb object
49       * @param[in] event - sd_event handler
50       * @param[in] invoker - invoker handler
51       * @param[in] hostPDRHandler - hostPDRHandler handler
52       * @param[in] platformHandler - platformHandler handler
53       * @param[in] fruHandler - fruHandler handler
54       * @param[in] baseHandler - baseHandler handler
55       * @param[in] reqHandler - reqHandler handler
56       */
57      explicit OemIBM(
58          const pldm::utils::DBusHandler* dBusIntf, int mctp_fd, uint8_t mctp_eid,
59          pldm_pdr* repo, pldm::InstanceIdDb& instanceIdDb,
60          sdeventplus::Event& event, Invoker& invoker,
61          HostPDRHandler* hostPDRHandler, platform::Handler* platformHandler,
62          fru::Handler* fruHandler, base::Handler* baseHandler,
63          pldm::requester::Handler<pldm::requester::Request>* reqHandler) :
64          dBusIntf(dBusIntf),
65          mctp_fd(mctp_fd), mctp_eid(mctp_eid), repo(repo),
66          instanceIdDb(instanceIdDb), event(event), invoker(invoker),
67          reqHandler(reqHandler)
68      {
69          createOemFruHandler();
70          fruHandler->setOemFruHandler(oemFruHandler.get());
71  
72          createOemIbmFruHandler();
73          oemIbmFruHandler->setIBMFruHandler(fruHandler);
74  
75          createCodeUpdate();
76          createOemPlatformHandler();
77          createOemIbmUtilsHandler();
78          codeUpdate->setOemPlatformHandler(oemPlatformHandler.get());
79          hostPDRHandler->setOemPlatformHandler(oemPlatformHandler.get());
80          hostPDRHandler->setOemUtilsHandler(oemUtilsHandler.get());
81          platformHandler->setOemPlatformHandler(oemPlatformHandler.get());
82          baseHandler->setOemPlatformHandler(oemPlatformHandler.get());
83  
84          createOemIbmPlatformHandler();
85          oemIbmPlatformHandler->setPlatformHandler(platformHandler);
86  
87          createHostLampTestHandler();
88  
89          registerHandler();
90      }
91  
92    private:
93      /** @brief Method for creating codeUpdate handler */
94      void createCodeUpdate()
95      {
96          codeUpdate = std::make_unique<pldm::responder::CodeUpdate>(dBusIntf);
97          codeUpdate->clearDirPath(LID_STAGING_DIR);
98      }
99  
100      /** @brief Method for creating oemPlatformHandler
101       *
102       *  This method also assigns the oemPlatformHandler to the below
103       *  different handlers.
104       */
105      void createOemPlatformHandler()
106      {
107          oemPlatformHandler = std::make_unique<oem_ibm_platform::Handler>(
108              dBusIntf, codeUpdate.get(), mctp_fd, mctp_eid, instanceIdDb, event,
109              reqHandler);
110      }
111  
112      /** @brief Method for creating oemIbmPlatformHandler */
113      void createOemIbmPlatformHandler()
114      {
115          oemIbmPlatformHandler =
116              dynamic_cast<pldm::responder::oem_ibm_platform::Handler*>(
117                  oemPlatformHandler.get());
118      }
119  
120      /** @brief Method for creating oemFruHandler */
121      void createOemFruHandler()
122      {
123          oemFruHandler = std::make_unique<oem_ibm_fru::Handler>(repo);
124      }
125  
126      /** @brief Method for creating oemIbmUtilsHandler */
127      void createOemIbmUtilsHandler()
128      {
129          oemUtilsHandler = std::make_unique<oem_ibm_utils::Handler>(dBusIntf);
130      }
131  
132      /** @brief Method for creating oemIbmFruHandler */
133      void createOemIbmFruHandler()
134      {
135          oemIbmFruHandler = dynamic_cast<pldm::responder::oem_ibm_fru::Handler*>(
136              oemFruHandler.get());
137      }
138  
139      void createHostLampTestHandler()
140      {
141          auto& bus = pldm::utils::DBusHandler::getBus();
142          hostLampTest = std::make_unique<pldm::led::HostLampTest>(
143              bus, "/xyz/openbmc_project/led/groups/host_lamp_test", mctp_eid,
144              instanceIdDb, repo, reqHandler);
145      }
146  
147      /** @brief Method for registering PLDM OEM handler */
148      void registerHandler()
149      {
150          invoker.registerHandler(
151              PLDM_OEM, std::make_unique<pldm::responder::oem_ibm::Handler>(
152                            oemPlatformHandler.get(), mctp_fd, mctp_eid,
153                            &instanceIdDb, reqHandler));
154      }
155  
156    private:
157      /** @brief D-Bus handler */
158      const pldm::utils::DBusHandler* dBusIntf;
159  
160      /** @brief fd of MCTP communications socket */
161      int mctp_fd;
162  
163      /** @brief MCTP EID of remote host firmware */
164      uint8_t mctp_eid;
165  
166      /** @brief pointer to BMC's primary PDR repo */
167      pldm_pdr* repo;
168  
169      /** @brief reference to an Instance ID database object, used to obtain PLDM
170       * instance IDs
171       */
172      pldm::InstanceIdDb& instanceIdDb;
173  
174      /** @brief reference of main event loop of pldmd, primarily used to schedule
175       *  work
176       */
177      sdeventplus::Event& event;
178  
179      /** @brief Object to the invoker class*/
180      Invoker& invoker;
181  
182      /** @brief pointer to the requester class*/
183      requester::Handler<requester::Request>* reqHandler;
184  
185      /** @brief pointer to the oem_ibm_handler class*/
186      std::unique_ptr<oem_platform::Handler> oemPlatformHandler{};
187  
188      /** @brief pointer to the oem_ibm_fru class*/
189      std::unique_ptr<oem_fru::Handler> oemFruHandler{};
190  
191      /** @brief pointer to the CodeUpdate class*/
192      std::unique_ptr<pldm::responder::CodeUpdate> codeUpdate{};
193  
194      /** @brief oem IBM Platform handler*/
195      pldm::responder::oem_ibm_platform::Handler* oemIbmPlatformHandler = nullptr;
196  
197      /** @brief oem IBM Fru handler*/
198      pldm::responder::oem_ibm_fru::Handler* oemIbmFruHandler = nullptr;
199  
200      std::unique_ptr<pldm::led::HostLampTest> hostLampTest;
201  
202      /** @brief oem IBM Utils handler*/
203      std::unique_ptr<oem_utils::Handler> oemUtilsHandler;
204  };
205  
206  } // namespace oem_ibm
207  } // namespace pldm
208