blob: 102458f9dba4a21c140e317ae8eac9050fa78252 [file] [log] [blame]
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +10001
Manojkiran Edaef773052021-07-29 09:29:28 +05302#include "common/flight_recorder.hpp"
Andrew Jeffery2abbce72023-10-18 10:17:35 +10303#include "common/instance_id.hpp"
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +10004#include "common/transport.hpp"
Deepak Kodihallid130e1a2020-06-17 05:55:32 -05005#include "common/utils.hpp"
Deepak Kodihalli4de4d002019-11-11 02:41:43 -06006#include "dbus_impl_requester.hpp"
Tom Josephfb3bc062021-08-17 07:48:11 -07007#include "fw-update/manager.hpp"
Deepak Kodihallibc669f12019-11-28 08:52:07 -06008#include "invoker.hpp"
Tom Joseph74f27c72021-05-16 07:58:53 -07009#include "requester/handler.hpp"
Tom Josephfb3bc062021-08-17 07:48:11 -070010#include "requester/mctp_endpoint_discovery.hpp"
Tom Joseph74f27c72021-05-16 07:58:53 -070011#include "requester/request.hpp"
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050012
13#include <err.h>
Jinu Joy Thomas75dd4422019-07-22 12:47:12 +053014#include <getopt.h>
George Liuc453e162022-12-21 17:16:23 +080015#include <libpldm/base.h>
16#include <libpldm/bios.h>
17#include <libpldm/pdr.h>
18#include <libpldm/platform.h>
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +100019#include <libpldm/transport.h>
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050020#include <poll.h>
21#include <stdlib.h>
22#include <sys/socket.h>
23#include <sys/types.h>
24#include <sys/un.h>
25#include <unistd.h>
26
Riya Dixit49cfb132023-03-02 04:26:53 -060027#include <phosphor-logging/lg2.hpp>
George Liu6492f522020-06-16 10:34:05 +080028#include <sdeventplus/event.hpp>
29#include <sdeventplus/source/io.hpp>
Manojkiran Edaef773052021-07-29 09:29:28 +053030#include <sdeventplus/source/signal.hpp>
31#include <stdplus/signal.hpp>
George Liu6492f522020-06-16 10:34:05 +080032
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050033#include <cstdio>
34#include <cstring>
Pavithra Barithaya51efaf82020-04-02 02:42:27 -050035#include <fstream>
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050036#include <iomanip>
37#include <iterator>
Deepak Kodihallic682fe22020-03-04 00:42:54 -060038#include <memory>
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +100039#include <ranges>
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050040#include <sstream>
Deepak Kodihallibc669f12019-11-28 08:52:07 -060041#include <stdexcept>
Jinu Joy Thomas75dd4422019-07-22 12:47:12 +053042#include <string>
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050043#include <vector>
44
Riya Dixit49cfb132023-03-02 04:26:53 -060045PHOSPHOR_LOG2_USING;
46
Tom Joseph02b4ee42021-05-02 22:44:36 -070047#ifdef LIBPLDMRESPONDER
48#include "dbus_impl_pdr.hpp"
49#include "host-bmc/dbus_to_event_handler.hpp"
50#include "host-bmc/dbus_to_host_effecters.hpp"
Tom Joseph20aa3e02021-08-17 04:44:19 -070051#include "host-bmc/host_condition.hpp"
Tom Joseph02b4ee42021-05-02 22:44:36 -070052#include "host-bmc/host_pdr_handler.hpp"
53#include "libpldmresponder/base.hpp"
54#include "libpldmresponder/bios.hpp"
55#include "libpldmresponder/fru.hpp"
56#include "libpldmresponder/oem_handler.hpp"
57#include "libpldmresponder/platform.hpp"
Kamalkumar Patel3c50c822024-01-30 07:14:40 -060058#include "libpldmresponder/platform_config.hpp"
Tom Joseph02b4ee42021-05-02 22:44:36 -070059#include "xyz/openbmc_project/PLDM/Event/server.hpp"
60#endif
61
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050062#ifdef OEM_IBM
George Liua881c172021-06-21 18:28:11 +080063#include "oem_ibm.hpp"
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050064#endif
65
66constexpr uint8_t MCTP_MSG_TYPE_PLDM = 1;
67
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050068using namespace pldm;
Deepak Kodihalli37998bf2019-11-11 04:06:53 -060069using namespace sdeventplus;
70using namespace sdeventplus::source;
Tom Joseph02b4ee42021-05-02 22:44:36 -070071using namespace pldm::responder;
72using namespace pldm::utils;
Manojkiran Edaef773052021-07-29 09:29:28 +053073using sdeventplus::source::Signal;
74using namespace pldm::flightrecorder;
75
76void interruptFlightRecorderCallBack(Signal& /*signal*/,
77 const struct signalfd_siginfo*)
78{
Riya Dixit49cfb132023-03-02 04:26:53 -060079 error("Received SIGUR1(10) Signal interrupt");
Manojkiran Edaef773052021-07-29 09:29:28 +053080 // obtain the flight recorder instance and dump the recorder
81 FlightRecorder::GetInstance().playRecorder();
82}
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050083
Archana Kakani62dd8ff2024-02-12 10:00:40 -060084void requestPLDMServiceName()
85{
86 auto& bus = pldm::utils::DBusHandler::getBus();
87 bus.request_name("xyz.openbmc_project.PLDM");
88}
89
Tom Joseph74f27c72021-05-16 07:58:53 -070090static std::optional<Response>
91 processRxMsg(const std::vector<uint8_t>& requestMsg, Invoker& invoker,
Tom Josephfb3bc062021-08-17 07:48:11 -070092 requester::Handler<requester::Request>& handler,
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +100093 fw_update::Manager* fwManager, pldm_tid_t tid)
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050094{
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +100095 uint8_t eid = tid;
96
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050097 pldm_header_info hdrFields{};
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +100098 auto hdr = reinterpret_cast<const pldm_msg_hdr*>(requestMsg.data());
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050099 if (PLDM_SUCCESS != unpack_pldm_header(hdr, &hdrFields))
100 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600101 error("Empty PLDM request header");
Tom Joseph74f27c72021-05-16 07:58:53 -0700102 return std::nullopt;
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500103 }
George Liub7095ff2021-06-14 16:01:57 +0800104
105 if (PLDM_RESPONSE != hdrFields.msg_type)
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500106 {
Tom Joseph74f27c72021-05-16 07:58:53 -0700107 Response response;
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500108 auto request = reinterpret_cast<const pldm_msg*>(hdr);
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000109 size_t requestLen = requestMsg.size() - sizeof(struct pldm_msg_hdr);
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600110 try
111 {
Tom Josephfb3bc062021-08-17 07:48:11 -0700112 if (hdrFields.pldm_type != PLDM_FWUP)
113 {
Delphine CC Chiud2e48992023-12-05 16:29:51 +0800114 response = invoker.handle(tid, hdrFields.pldm_type,
Patrick Williams6da4f912023-05-10 07:50:53 -0500115 hdrFields.command, request,
116 requestLen);
Tom Josephfb3bc062021-08-17 07:48:11 -0700117 }
118 else
119 {
120 response = fwManager->handleRequest(eid, hdrFields.command,
121 request, requestLen);
122 }
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600123 }
124 catch (const std::out_of_range& e)
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500125 {
126 uint8_t completion_code = PLDM_ERROR_UNSUPPORTED_PLDM_CMD;
127 response.resize(sizeof(pldm_msg_hdr));
128 auto responseHdr = reinterpret_cast<pldm_msg_hdr*>(response.data());
129 pldm_header_info header{};
130 header.msg_type = PLDM_RESPONSE;
131 header.instance = hdrFields.instance;
132 header.pldm_type = hdrFields.pldm_type;
133 header.command = hdrFields.command;
George Liub7095ff2021-06-14 16:01:57 +0800134 if (PLDM_SUCCESS != pack_pldm_header(&header, responseHdr))
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500135 {
Riya Dixit087a7512024-04-06 14:28:08 -0500136 error(
137 "Failed to add response header for processing Rx, error - {ERROR}",
138 "ERROR", e);
Tom Joseph74f27c72021-05-16 07:58:53 -0700139 return std::nullopt;
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500140 }
141 response.insert(response.end(), completion_code);
142 }
Tom Joseph74f27c72021-05-16 07:58:53 -0700143 return response;
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500144 }
Tom Joseph74f27c72021-05-16 07:58:53 -0700145 else if (PLDM_RESPONSE == hdrFields.msg_type)
Deepak Kodihalli4de4d002019-11-11 02:41:43 -0600146 {
Tom Joseph74f27c72021-05-16 07:58:53 -0700147 auto response = reinterpret_cast<const pldm_msg*>(hdr);
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000148 size_t responseLen = requestMsg.size() - sizeof(struct pldm_msg_hdr);
Tom Joseph74f27c72021-05-16 07:58:53 -0700149 handler.handleResponse(eid, hdrFields.instance, hdrFields.pldm_type,
150 hdrFields.command, response, responseLen);
Deepak Kodihalli4de4d002019-11-11 02:41:43 -0600151 }
Tom Joseph74f27c72021-05-16 07:58:53 -0700152 return std::nullopt;
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500153}
154
Jinu Joy Thomas75dd4422019-07-22 12:47:12 +0530155void optionUsage(void)
156{
Riya Dixit797f3382023-08-22 22:27:51 -0500157 info("Usage: pldmd [options]");
158 info("Options:");
159 info(" [--verbose] - would enable verbosity");
Jinu Joy Thomas75dd4422019-07-22 12:47:12 +0530160}
161
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500162int main(int argc, char** argv)
163{
Jinu Joy Thomas75dd4422019-07-22 12:47:12 +0530164 bool verbose = false;
Manojkiran Edaf25145f2022-09-10 01:43:39 -0500165 static struct option long_options[] = {{"verbose", no_argument, 0, 'v'},
166 {0, 0, 0, 0}};
Jinu Joy Thomas75dd4422019-07-22 12:47:12 +0530167
Manojkiran Edaf25145f2022-09-10 01:43:39 -0500168 auto argflag = getopt_long(argc, argv, "v", long_options, nullptr);
Jinu Joy Thomas75dd4422019-07-22 12:47:12 +0530169 switch (argflag)
170 {
171 case 'v':
Manojkiran Edaf25145f2022-09-10 01:43:39 -0500172 verbose = true;
Jinu Joy Thomas75dd4422019-07-22 12:47:12 +0530173 break;
Brad Bishopc80f3ef2021-10-07 16:34:13 -0400174 case -1:
Jinu Joy Thomas75dd4422019-07-22 12:47:12 +0530175 break;
Brad Bishopc80f3ef2021-10-07 16:34:13 -0400176 default:
Manojkiran Edaf25145f2022-09-10 01:43:39 -0500177 optionUsage();
Brad Bishopc80f3ef2021-10-07 16:34:13 -0400178 exit(EXIT_FAILURE);
Jinu Joy Thomas75dd4422019-07-22 12:47:12 +0530179 }
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000180 // Setup PLDM requester transport
181 auto hostEID = pldm::utils::readHostEID();
182 /* To maintain current behaviour until we have the infrastructure to find
183 * and use the correct TIDs */
184 pldm_tid_t TID = hostEID;
185 PldmTransport pldmTransport{};
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500186 auto event = Event::get_default();
Tom Joseph02b4ee42021-05-02 22:44:36 -0700187 auto& bus = pldm::utils::DBusHandler::getBus();
Patrick Williams84b790c2022-07-22 19:26:56 -0500188 sdbusplus::server::manager_t objManager(bus,
189 "/xyz/openbmc_project/software");
Andrew Jeffery7c1dc7e2023-04-28 14:52:16 +0930190
191 InstanceIdDb instanceIdDb;
192 dbus_api::Requester dbusImplReq(bus, "/xyz/openbmc_project/pldm",
193 instanceIdDb);
Patrick Williams705fa982023-09-27 02:32:20 -0500194 sdbusplus::server::manager_t inventoryManager(
George Liu682ee182020-12-25 15:24:33 +0800195 bus, "/xyz/openbmc_project/inventory");
Pavithra Barithaya319ebb32021-05-06 06:09:11 -0500196
Tom Joseph02b4ee42021-05-02 22:44:36 -0700197 Invoker invoker{};
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000198 requester::Handler<requester::Request> reqHandler(&pldmTransport, event,
199 instanceIdDb, verbose);
Manojkiran Eda9fffea22021-10-27 16:03:27 +0530200
Tom Joseph02b4ee42021-05-02 22:44:36 -0700201#ifdef LIBPLDMRESPONDER
202 using namespace pldm::state_sensor;
Tom Joseph20aa3e02021-08-17 04:44:19 -0700203 dbus_api::Host dbusImplHost(bus, "/xyz/openbmc_project/pldm");
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500204 std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)> pdrRepo(
205 pldm_pdr_init(), pldm_pdr_destroy);
Andrew Jefferyacb20292023-06-30 11:47:44 +0930206 if (!pdrRepo)
207 {
208 throw std::runtime_error("Failed to instantiate PDR repository");
209 }
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500210 std::unique_ptr<pldm_entity_association_tree,
211 decltype(&pldm_entity_association_tree_destroy)>
212 entityTree(pldm_entity_association_tree_init(),
213 pldm_entity_association_tree_destroy);
Andrew Jefferyabcd6ca2023-06-30 13:53:35 +0930214 if (!entityTree)
215 {
216 throw std::runtime_error(
217 "Failed to instantiate general PDR entity association tree");
218 }
Sampa Misrac073a202021-05-08 10:56:05 -0500219 std::unique_ptr<pldm_entity_association_tree,
220 decltype(&pldm_entity_association_tree_destroy)>
221 bmcEntityTree(pldm_entity_association_tree_init(),
222 pldm_entity_association_tree_destroy);
Andrew Jefferyabcd6ca2023-06-30 13:53:35 +0930223 if (!bmcEntityTree)
224 {
225 throw std::runtime_error(
226 "Failed to instantiate BMC PDR entity association tree");
227 }
Pavithra Barithaya319ebb32021-05-06 06:09:11 -0500228 std::shared_ptr<HostPDRHandler> hostPDRHandler;
Sampa Misrac0c60542020-07-01 02:34:25 -0500229 std::unique_ptr<pldm::host_effecters::HostEffecterParser>
230 hostEffecterParser;
George Liucae18662020-05-15 09:32:57 +0800231 std::unique_ptr<DbusToPLDMEvent> dbusToPLDMEventHandler;
Brad Bishopfc0d14d2021-10-12 19:34:20 -0400232 DBusHandler dbusHandler;
Kamalkumar Patel3c50c822024-01-30 07:14:40 -0600233 std::unique_ptr<platform_config::Handler> platformConfigHandler{};
234 platformConfigHandler = std::make_unique<platform_config::Handler>();
Pavithra Barithayaa410c652021-07-22 01:32:47 -0500235
Sagar Srinivas3687e2b2023-04-10 05:08:28 -0500236 if (hostEID)
237 {
238 hostPDRHandler = std::make_shared<HostPDRHandler>(
239 pldmTransport.getEventSource(), hostEID, event, pdrRepo.get(),
240 EVENTS_JSONS_DIR, entityTree.get(), bmcEntityTree.get(),
George Liua881c172021-06-21 18:28:11 +0800241 instanceIdDb, &reqHandler);
242
Sagar Srinivas3687e2b2023-04-10 05:08:28 -0500243 // HostFirmware interface needs access to hostPDR to know if host
244 // is running
245 dbusImplHost.setHostPdrObj(hostPDRHandler);
Sagar Srinivas11ce8d22022-07-28 11:32:34 -0500246
Sagar Srinivas3687e2b2023-04-10 05:08:28 -0500247 hostEffecterParser =
248 std::make_unique<pldm::host_effecters::HostEffecterParser>(
249 &instanceIdDb, pldmTransport.getEventSource(), pdrRepo.get(),
250 &dbusHandler, HOST_JSONS_DIR, &reqHandler);
251 dbusToPLDMEventHandler = std::make_unique<DbusToPLDMEvent>(
252 pldmTransport.getEventSource(), hostEID, instanceIdDb, &reqHandler);
253 }
Pavithra Barithayaa410c652021-07-22 01:32:47 -0500254
Tom Joseph33e9c7e2020-06-11 22:09:52 +0530255 auto fruHandler = std::make_unique<fru::Handler>(
Manojkiran Eda03b01ca2021-06-29 08:55:09 +0530256 FRU_JSONS_DIR, FRU_MASTER_JSON, pdrRepo.get(), entityTree.get(),
George Liua881c172021-06-21 18:28:11 +0800257 bmcEntityTree.get());
Pavithra Barithayaa410c652021-07-22 01:32:47 -0500258
Tom Joseph33e9c7e2020-06-11 22:09:52 +0530259 // FRU table is built lazily when a FRU command or Get PDR command is
260 // handled. To enable building FRU table, the FRU handler is passed to the
261 // Platform handler.
Sampa Misraaea5dde2020-08-31 08:33:47 -0500262 auto platformHandler = std::make_unique<platform::Handler>(
Sagar Srinivas90314a32023-10-17 10:38:03 -0500263 &dbusHandler, hostEID, &instanceIdDb, PDR_JSONS_DIR, pdrRepo.get(),
264 hostPDRHandler.get(), dbusToPLDMEventHandler.get(), fruHandler.get(),
George Liua881c172021-06-21 18:28:11 +0800265 platformConfigHandler.get(), &reqHandler, event, true);
Pavithra Barithayaa410c652021-07-22 01:32:47 -0500266
George Liua881c172021-06-21 18:28:11 +0800267 auto biosHandler = std::make_unique<bios::Handler>(
268 pldmTransport.getEventSource(), hostEID, &instanceIdDb, &reqHandler,
269 platformConfigHandler.get(), requestPLDMServiceName);
270
271 auto baseHandler = std::make_unique<base::Handler>(event);
272
273#ifdef OEM_IBM
274 pldm::oem_ibm::OemIBM oemIBM(&dbusHandler, pldmTransport.getEventSource(),
275 hostEID, pdrRepo.get(), instanceIdDb, event,
276 invoker, hostPDRHandler.get(),
277 platformHandler.get(), fruHandler.get(),
278 baseHandler.get(), &reqHandler);
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500279#endif
280
Sagar Srinivas11ce8d22022-07-28 11:32:34 -0500281 invoker.registerHandler(PLDM_BIOS, std::move(biosHandler));
Sampa Misraaea5dde2020-08-31 08:33:47 -0500282 invoker.registerHandler(PLDM_PLATFORM, std::move(platformHandler));
283 invoker.registerHandler(PLDM_FRU, std::move(fruHandler));
George Liua881c172021-06-21 18:28:11 +0800284 invoker.registerHandler(PLDM_BASE, std::move(baseHandler));
285
Tom Joseph02b4ee42021-05-02 22:44:36 -0700286 dbus_api::Pdr dbusImplPdr(bus, "/xyz/openbmc_project/pldm", pdrRepo.get());
287 sdbusplus::xyz::openbmc_project::PLDM::server::Event dbusImplEvent(
288 bus, "/xyz/openbmc_project/pldm");
Tom Joseph20aa3e02021-08-17 04:44:19 -0700289
Tom Joseph02b4ee42021-05-02 22:44:36 -0700290#endif
Sampa Misraaea5dde2020-08-31 08:33:47 -0500291
Tom Josephfb3bc062021-08-17 07:48:11 -0700292 std::unique_ptr<fw_update::Manager> fwManager =
Andrew Jefferya330b2f2023-05-04 14:55:37 +0930293 std::make_unique<fw_update::Manager>(event, reqHandler, instanceIdDb);
Tom Josephfb3bc062021-08-17 07:48:11 -0700294 std::unique_ptr<MctpDiscovery> mctpDiscoveryHandler =
Gilbert Chen44524a52022-02-14 12:12:25 +0000295 std::make_unique<MctpDiscovery>(
296 bus,
297 std::initializer_list<MctpDiscoveryHandlerIntf*>{fwManager.get()});
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000298 auto callback = [verbose, &invoker, &reqHandler, &fwManager, &pldmTransport,
299 TID](IO& io, int fd, uint32_t revents) mutable {
Deepak Kodihalli37998bf2019-11-11 04:06:53 -0600300 if (!(revents & EPOLLIN))
301 {
302 return;
303 }
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000304 if (fd < 0)
305 {
306 return;
307 }
Deepak Kodihalli37998bf2019-11-11 04:06:53 -0600308
309 int returnCode = 0;
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000310 void* requestMsg;
311 size_t recvDataLength;
312 returnCode = pldmTransport.recvMsg(TID, requestMsg, recvDataLength);
313
314 if (returnCode == PLDM_REQUESTER_SUCCESS)
315 {
316 std::vector<uint8_t> requestMsgVec(
317 static_cast<uint8_t*>(requestMsg),
318 static_cast<uint8_t*>(requestMsg) + recvDataLength);
319 FlightRecorder::GetInstance().saveRecord(requestMsgVec, false);
320 if (verbose)
321 {
322 printBuffer(Rx, requestMsgVec);
323 }
324 // process message and send response
325 auto response = processRxMsg(requestMsgVec, invoker, reqHandler,
326 fwManager.get(), TID);
327 if (response.has_value())
328 {
329 FlightRecorder::GetInstance().saveRecord(*response, true);
330 if (verbose)
331 {
332 printBuffer(Tx, *response);
333 }
334
335 returnCode = pldmTransport.sendMsg(TID, (*response).data(),
336 (*response).size());
337 if (returnCode != PLDM_REQUESTER_SUCCESS)
338 {
Riya Dixit087a7512024-04-06 14:28:08 -0500339 warning(
340 "Failed to send pldmTransport message for TID '{TID}', response code '{RETURN_CODE}'",
341 "TID", TID, "RETURN_CODE", returnCode);
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000342 }
343 }
344 }
345 // TODO check that we get here if mctp-demux dies?
346 else if (returnCode == PLDM_REQUESTER_RECV_FAIL)
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500347 {
Deepak Kodihalli23c52042020-09-01 03:04:32 -0500348 // MCTP daemon has closed the socket this daemon is connected to.
349 // This may or may not be an error scenario, in either case the
350 // recovery mechanism for this daemon is to restart, and hence exit
351 // the event loop, that will cause this daemon to exit with a
352 // failure code.
Riya Dixit087a7512024-04-06 14:28:08 -0500353 error(
354 "MCTP daemon closed the socket, IO exiting with response code '{RC}'",
355 "RC", returnCode);
Deepak Kodihalli23c52042020-09-01 03:04:32 -0500356 io.get_event().exit(0);
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500357 }
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500358 else
359 {
Riya Dixit087a7512024-04-06 14:28:08 -0500360 warning(
361 "Failed to receive PLDM request for pldmTransport, response code '{RETURN_CODE}'",
362 "RETURN_CODE", returnCode);
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500363 }
Thu Nguyenefacb6f2024-04-12 01:37:46 +0000364 /* Free requestMsg after using */
365 free(requestMsg);
Deepak Kodihalli37998bf2019-11-11 04:06:53 -0600366 };
367
Deepak Kodihalli4de4d002019-11-11 02:41:43 -0600368 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
Archana Kakani46f352e2024-03-17 08:21:08 -0500369#ifndef SYSTEM_SPECIFIC_BIOS_JSON
370 bus.request_name("xyz.openbmc_project.PLDM");
371#endif
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000372 IO io(event, pldmTransport.getEventSource(), EPOLLIN, std::move(callback));
Manojkiran Eda88bc7182021-09-08 18:37:30 +0530373#ifdef LIBPLDMRESPONDER
374 if (hostPDRHandler)
375 {
376 hostPDRHandler->setHostFirmwareCondition();
377 }
378#endif
Manojkiran Edaef773052021-07-29 09:29:28 +0530379 stdplus::signal::block(SIGUSR1);
380 sdeventplus::source::Signal sigUsr1(
381 event, SIGUSR1, std::bind_front(&interruptFlightRecorderCallBack));
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +1000382 int returnCode = event.loop();
Brad Bishop3a22b972021-10-07 17:01:58 -0400383 if (returnCode)
384 {
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500385 exit(EXIT_FAILURE);
386 }
Brad Bishop3a22b972021-10-07 17:01:58 -0400387
388 exit(EXIT_SUCCESS);
Jinu Joy Thomasf666db12019-05-29 05:22:31 -0500389}