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), 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 createOemPlatformHandler(); 79 createOemIbmUtilsHandler(); 80 codeUpdate->setOemPlatformHandler(oemPlatformHandler.get()); 81 hostPDRHandler->setOemPlatformHandler(oemPlatformHandler.get()); 82 hostPDRHandler->setOemUtilsHandler(oemUtilsHandler.get()); 83 platformHandler->setOemPlatformHandler(oemPlatformHandler.get()); 84 baseHandler->setOemPlatformHandler(oemPlatformHandler.get()); 85 86 createOemIbmPlatformHandler(); 87 oemIbmPlatformHandler->setPlatformHandler(platformHandler); 88 89 createHostLampTestHandler(); 90 91 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 { 109 oemPlatformHandler = 110 std::make_unique<responder::oem_ibm_platform::Handler>( 111 dBusIntf, codeUpdate.get(), mctp_fd, mctp_eid, instanceIdDb, 112 event, reqHandler); 113 } 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 { 126 oemFruHandler = std::make_unique<responder::oem_ibm_fru::Handler>(repo); 127 } 128 129 /** @brief Method for creating oemIbmUtilsHandler */ 130 void createOemIbmUtilsHandler() 131 { 132 oemUtilsHandler = 133 std::make_unique<responder::oem_ibm_utils::Handler>(dBusIntf); 134 } 135 136 /** @brief Method for creating oemIbmFruHandler */ 137 void createOemIbmFruHandler() 138 { 139 oemIbmFruHandler = dynamic_cast<pldm::responder::oem_ibm_fru::Handler*>( 140 oemFruHandler.get()); 141 } 142 143 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 151 /** @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*/ 184 responder::Invoker& invoker; 185 186 /** @brief pointer to the requester class*/ 187 requester::Handler<requester::Request>* reqHandler; 188 189 /** @brief pointer to the oem_ibm_handler class*/ 190 std::unique_ptr<responder::oem_platform::Handler> oemPlatformHandler{}; 191 192 /** @brief pointer to the oem_ibm_fru class*/ 193 std::unique_ptr<responder::oem_fru::Handler> oemFruHandler{}; 194 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; 203 204 std::unique_ptr<pldm::led::HostLampTest> hostLampTest; 205 206 /** @brief oem IBM Utils handler*/ 207 std::unique_ptr<responder::oem_utils::Handler> oemUtilsHandler; 208 }; 209 210 } // namespace oem_ibm 211 } // namespace pldm 212